ogg parameters problem libsndfile |
ogg parameters problem libsndfile |
Jan 15 2013, 19:34
Post
#1
|
|
|
Group: Members Posts: 3 Joined: 7-January 13 Member No.: 105674 |
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. 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; } |
|
|
|
![]() |
Jan 29 2013, 18:35
Post
#2
|
|
|
Group: Members Posts: 42 Joined: 27-November 11 Member No.: 95439 |
Possible problem 1: Your sfinfo structure is not initialized. The fields that you don't set explicitly may contain anything at all. You should always call something like
CODE memset(&sfinfo, 0, sizeof(sfinfo)); before using such a structure.Possible problem 2: Vorbis support was introduced in libsndfile 1.0.18. Do you use at least this version? Possible problem 3: Your code snippet doesn't show the actual values for the number of channels and for the sample rate. Perhaps they are invalid (e.g., the number of channels must not be 0). Here is a minimal complete program: CODE #include <stdio.h> #include <sndfile.h> int main(void) { SF_INFO sfinfo; memset(&sfinfo, 0, sizeof(sfinfo)); sfinfo.samplerate = 48000; sfinfo.channels = 3; sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS; if (sf_format_check(&sfinfo)) printf("OK\n"); return 0; } For me, it prints "OK". Try it on your system (first as-is, then with your values for sample rate and number of channels). |
|
|
|
hub2 ogg parameters problem libsndfile Jan 15 2013, 19:34
db1989 QUOTE (chi @ Jan 29 2013, 17:35) Possible... Jan 29 2013, 19:01
chi QUOTE (db1989 @ Jan 29 2013, 20:01) In C,... Jan 30 2013, 15:07![]() ![]() |
|
Lo-Fi Version | Time is now: 19th May 2013 - 08:35 |