Hi,
I made a function using libsndfile that should encode RAW PCM 16-bit file to OGG Vorbis file.Function that checks format says that something is wrong with parameters but when i tried to check what's wrong in this function manually i haven't found what's wrong.Could you tell me what's wrong here.
Here's my code.
static void encodeOgg (const char *infilename, const char *outfilename, int filetype)
{ static SAMPLE buffer [BUFFER_LEN];
SNDFILE *infile, *outfile;
SF_INFO sfinfo,sf_in;
int readcount;
fflush (stdout);
sf_in.samplerate=SAMPLE_RATE;
sf_in.channels=NUM_CHANNELS;
sf_in.format=SF_FORMAT_RAW | SF_FORMAT_PCM_16;
if (! (infile = sf_open (infilename, SFM_READ, &sf_in))){
error("Could not open input file");
exit (1);
}
sfinfo.samplerate=SAMPLE_RATE;
sfinfo.channels=NUM_CHANNELS;
sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS;
if (! sf_format_check (&sfinfo)){
sf_close (infile);
error("Invalid encoding\n");
exit (1);
}
if (! (outfile = sf_open (outfilename, SFM_WRITE, &sfinfo))){
error("Error : could not open output file");
exit (1);
}
while ((readcount = sf_read_short (infile, buffer, BUFFER_LEN)) > 0)
{
sf_write_short (outfile, buffer, readcount);
}
sf_close (infile);
sf_close (outfile);
return;
}