Question

I used the code below to convert sound files to ogg vorbis, but i don't found on the documentation of libsndfile how to set the bitrate of the output file, which is always set to 128 kb/s. Is possible to change the bitrate of the output file generated by libsndfile?

#include <sndfile.hh>

#define BUFFER_LEN 4096

void convert(char *infilename, char *outfilename)
{
    static double data[BUFFER_LEN];
    SNDFILE *infile, *outfile;
    SF_INFO sfinfo;
    int readcount;

    infile = sf_open(infilename, SFM_READ, &sfinfo);
    sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS;
    outfile = sf_open(outfilename, SFM_WRITE, &sfinfo);

    while ((readcount = sf_read_double(infile, data, BUFFER_LEN)))
    {
        sf_write_double(outfile, data, readcount);
    }

    sf_close(infile);
    sf_close(outfile);
}
Was it helpful?

Solution

With libsndfile there is no way to set a specific bitrate. Setting a specific constant bit rate it usually a bad idea anyway as the constant bitrate is likely to be too low for some parts of the sonf and too high for other parts.

With libsndfile you can however set various compression levels which always use variable bitrate. See : http://www.mega-nerd.com/libsndfile/command.html#SFC_SET_VBR_ENCODING_QUALITY

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top