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, ogg_packet * op, long serialno, void * user_data)
{
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);
}