This procedure is illustrated in src/examples/fishsound-decode.c. Note that this example additionally:
Hence this example code demonstrates all that is needed to decode Ogg FLAC, Speex or Ogg Vorbis files:
 
 
 
 
 
 
#include "config.h"
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#include <oggz/oggz.h>
#include <sndfile.h>
 
static char * infilename, * outfilename;
static int begun = 0;
static SNDFILE * sndfile;
 
static long decode_serialno = -1;
 
static int
open_output (int samplerate, int channels)
{
  SF_INFO sfinfo;
 
  sfinfo.channels = channels;
  sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
 
  sndfile = sf_open (outfilename, SFM_WRITE, &sfinfo);
 
  return 0;
}
 
static int
decoded_float (
FishSound * fsound, 
float ** pcm, 
long frames, 
void * user_data)
{
  if (!begun) {
    begun = 1;
  }
 
  sf_writef_float (sndfile, (float *)pcm, frames);
 
  return 0;
}
 
static int
read_packet (OGGZ * oggz, oggz_packet * ozp, long serialno, void * user_data)
{
  ogg_packet *op = &ozp->op;
 
  
  if (decode_serialno == -1 && op->b_o_s && op->bytes >= 8) {
      decode_serialno = serialno;
  }
 
  
  if (serialno == decode_serialno) {
  }
 
  return 0;
}
 
int
main (int argc, char ** argv)
{
  OGGZ * oggz;
  long n;
 
  if (argc < 3) {
    printf ("usage: %s infilename outfilename\n", argv[0]);
    printf ("*** FishSound example program. ***\n");
    printf ("Decodes an Ogg FLAC, Speex or Ogg Vorbis file producing a PCM wav file.\n");
    exit (1);
  }
 
  infilename = argv[1];
  outfilename = argv[2];
 
 
 
 
  if ((oggz = oggz_open ((char *) infilename, OGGZ_READ)) == NULL) {
    printf ("unable to open file %s\n", infilename);
    exit (1);
  }
 
  oggz_set_read_callback (oggz, -1, read_packet, fsound);
 
  while ((n = oggz_read (oggz, 1024)) > 0);
 
  oggz_close (oggz);
 
  
  sf_close (sndfile);
 
  exit (0);
}
 
@ FISH_SOUND_GET_INFO
Retrieve the FishSoundInfo.
Definition: constants.h:82
@ FISH_SOUND_DECODE
Decode.
Definition: constants.h:43
@ FISH_SOUND_UNKNOWN
Unknown.
Definition: constants.h:52
long fish_sound_decode(FishSound *fsound, unsigned char *buf, long bytes)
Decode a block of compressed data.
int fish_sound_set_decoded_float_ilv(FishSound *fsound, FishSoundDecoded_FloatIlv decoded, void *user_data)
Set the callback for libfishsound to call when it has a block of decoded PCM audio ready,...
int fish_sound_set_interleave(FishSound *fsound, int interleave)
DEPRECATED FUNCTION.
int fish_sound_delete(FishSound *fsound)
Delete a FishSound object.
int fish_sound_identify(unsigned char *buf, long bytes)
Identify a codec based on the first few bytes of data.
int fish_sound_command(FishSound *fsound, int command, void *data, int datasize)
Command interface.
FishSound * fish_sound_new(int mode, FishSoundInfo *fsinfo)
Instantiate a new FishSound* handle.
int fish_sound_prepare_truncation(FishSound *fsound, long next_granulepos, int next_eos)
Prepare truncation details for the next block of data.
void * FishSound
An opaque handle to a FishSound.
Definition: fishsound.h:433
Info about a particular encoder/decoder instance.
Definition: fishsound.h:404
int samplerate
Sample rate of audio data in Hz.
Definition: fishsound.h:406
int channels
Count of channels.
Definition: fishsound.h:409