Welcome Guest ( Log In | Register )

ogg parameters problem libsndfile
post Jan 15 2013, 19:34
Post #1

Group: Members
Posts: 3
Joined: 7-January 13
Member No.: 105674

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.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.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);
Go to the top of the page
+Quote Post
Start new topic
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
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:
#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))
    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

Posts in this topic

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: 27th November 2015 - 09:05