IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
ogg parameters problem libsndfile
hub2
post 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;
}
Go to the top of the page
+Quote Post
chi
post Jan 29 2013, 18:35
Post #2





Group: Members
Posts: 45
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).
Go to the top of the page
+Quote Post
db1989
post Jan 29 2013, 19:01
Post #3





Group: Super Moderator
Posts: 5275
Joined: 23-June 06
Member No.: 32180



QUOTE (chi @ Jan 29 2013, 17:35) *
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

I canít determine which language this is, and please correct me if Iím wrong as Iím far from an expert, but as I understand it:
ē In C, you can simply use struct MyStructType myStruct = {0};
ē In C++, structures are initialised to zeroes or the equivalent empty data by default when using the default constructor.
Again, AFAIK.
Go to the top of the page
+Quote Post
chi
post Jan 30 2013, 15:07
Post #4





Group: Members
Posts: 45
Joined: 27-November 11
Member No.: 95439



QUOTE (db1989 @ Jan 29 2013, 20:01) *
In C, you can simply use struct MyStructType myStruct = {0};


Thatís right. I used the memset method here because it is the style preferred by libsndfileís author, and used in the accompanying programs. (I am aware of the theoretical portability issues.)

However, the point here is that hub2ís code does not initialize the struct via either method. This is a bug. It may or may not cause his/her current problem.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 24th July 2014 - 14:15