This procedure is illustrated in src/examples/fishsound-encode.c. Note that this example additionally:
Hence this example code demonstrates all that is needed to encode Ogg FLAC, Speex and Ogg Vorbis files:
#include "config.h"
#include "fs_compat.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <oggz/oggz.h>
#include <sndfile.h>
#define ENCODE_BLOCK_SIZE (1152)
long serialno;
int b_o_s = 1;
static int
encoded (
FishSound * fsound,
unsigned char * buf,
long bytes,
void * user_data)
{
OGGZ * oggz = (OGGZ *)user_data;
ogg_packet op;
int err;
op.packet = buf;
op.bytes = bytes;
op.b_o_s = b_o_s;
op.e_o_s = 0;
op.packetno = -1;
err = oggz_write_feed (oggz, &op, serialno, 0, NULL);
if (err) printf ("err: %d\n", err);
b_o_s = 0;
return 0;
}
int
main (int argc, char ** argv)
{
OGGZ * oggz;
SNDFILE * sndfile;
SF_INFO sfinfo;
char * infilename, * outfilename;
char * ext = NULL;
float pcm[2048];
if (argc < 3) {
printf ("usage: %s infile outfile\n", argv[0]);
printf ("*** FishSound example program. ***\n");
printf ("Opens a PCM audio file and encodes it to an Ogg FLAC, Speex or Ogg Vorbis file.\n");
exit (1);
}
infilename = argv[1];
outfilename = argv[2];
sndfile = sf_open (infilename, SFM_READ, &sfinfo);
if ((oggz = oggz_open (outfilename, OGGZ_WRITE)) == NULL) {
printf ("unable to open file %s\n", outfilename);
exit (1);
}
serialno = oggz_serialno_new (oggz);
ext = strrchr (outfilename, '.');
if (ext && !strncasecmp (ext, ".spx", 4))
else if (ext && !strncasecmp (ext, ".oga", 4))
else
while (sf_readf_float (sndfile, pcm, ENCODE_BLOCK_SIZE) > 0) {
oggz_run (oggz);
}
oggz_run (oggz);
oggz_close (oggz);
sf_close (sndfile);
exit (0);
}
@ FISH_SOUND_ENCODE
Encode.
Definition constants.h:46
@ FISH_SOUND_VORBIS
Vorbis.
Definition constants.h:55
@ FISH_SOUND_FLAC
Flac.
Definition constants.h:61
@ FISH_SOUND_SPEEX
Speex.
Definition constants.h:58
long fish_sound_encode(FishSound *fsound, float **pcm, long frames)
DEPRECATED FUNCTION.
int fish_sound_set_interleave(FishSound *fsound, int interleave)
DEPRECATED FUNCTION.
int fish_sound_set_encoded_callback(FishSound *fsound, FishSoundEncoded encoded, void *user_data)
Set the callback for libfishsound to call when it has a block of encoded data ready.
int fish_sound_delete(FishSound *fsound)
Delete a FishSound object.
FishSound * fish_sound_new(int mode, FishSoundInfo *fsinfo)
Instantiate a new FishSound* handle.
void * FishSound
An opaque handle to a FishSound.
Definition fishsound.h:433
long fish_sound_flush(FishSound *fsound)
Flush any internally buffered data, forcing encode.
long fish_sound_get_frameno(FishSound *fsound)
Query the current frame number of a FishSound object.
Info about a particular encoder/decoder instance.
Definition fishsound.h:404
int format
FISH_SOUND_VORBIS, FISH_SOUND_SPEEX, FISH_SOUND_FLAC etc.
Definition fishsound.h:412
int samplerate
Sample rate of audio data in Hz.
Definition fishsound.h:406
int channels
Count of channels.
Definition fishsound.h:409