使用C中的libmad库将24 khz mp3音频转换为16 khz wav?

时间:2017-12-05 12:09:14

标签: audio mp3 decoding

我在C中编写了一个小应用程序,它从基于云的语音引擎接收mp3音频数据,并以16 khz的采样率将其转换为pcm数据(wav格式)。我使用libmad解码mp3数据,但我没有找到从24 khz到16 khz下采样的选项。我们可以使用libmad执行此操作,还是需要另一个单独的库来实现此目的?任何与此相关的信息都会有所帮助。谢谢,

〜Reev

1 个答案:

答案 0 :(得分:0)

lamehelper库可用于此... 使用此网站可以帮助您: https://www.codeproject.com/Articles/656543/The-LAME-wrapper-An-audio-converter

您的代码应该看起来像这样 -

#include "lameHelper.h"
struct settings_t //make a struct to store settings
{
    char* title;
    char* artist;
    char* album;
    char* comment;
    char* year;
    char* track;
    char* genre;
    char* albumart;

    encode_channel_e channels;
    bitrate_e abr_bitrate;
    bitrate_e cbr_bitrate;
    int quality;
    encode_mode_e enc_mode;
    samplerate_e resample_frequency; // This is what you are going to need
    samplerate_e in_samplerate;

    //The constructor: used to set default values
    settings_t();
};

int main()
{
    settings_t settings;
    settings.enc_mode = EM_ABR;
    settings.abr_bitrate = BR_128kbps;//If you are going to use ABR encode mode @ 128kbps
    settings.album = "The Album";//Setting the album (id3 tag)
    settings.albumart = "c:/.../art.jpg";//Setting the albumart
    settings.track = "01";//Setting the track

    //..and various other settings

    lameHelper lhHandle;
    lhHandle.encode("c:/.../song.mp3", "c:/.../song.wav", settings);

    return 0;
}