本文介绍了是否有任何LAME C ++包装程序/简化程序(在Linux Mac上运行,并且可以从纯代码运行Win)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个简单的pcm到mp3 C ++项目.我希望它使用LAME.我爱LAME,但它真的很大.因此,我需要使用纯代码和纯la脚代码工作流简化程序的某种OpenSource.可以这么说,我给它带PCM和DEST文件的文件.呼叫类似的内容:

I want to create simple pcm to mp3 C++ project. I want it to use LAME. I love LAME but it's really big. so I need some kind of OpenSource working from pure code with pure lame code workflow simplifier. So to say I give it File with PCM and DEST file. Call something like:

LameSimple.ToMP3(file with PCM, File with MP3 , 44100, 16, MP3, VBR);

在4-5行中进行此类处理(当然应该有示例),我需要什么?它应该是轻便,简单,功能强大,开源,跨平台的.

ore such thing in 4 - 5 lines (examples of course should exist) and I have vhat I needed It should be light, simple, powerfool, opensource, crossplatform.

有这样的事情吗?

推荐答案

虽然确实有很多可选配置功能(如果需要),它们确实并不难使用.编码文件只需要4-5行多一点,但不多得多.这是我一起工作的一个示例(只是基本功能,没有错误检查):

Lame really isn't difficult to use, although there are a lot of optional configuration functions if you need them. It takes slightly more than 4-5 lines to encode a file, but not much more. Here is a working example I knocked together (just the basic functionality, no error checking):

#include <stdio.h>
#include <lame/lame.h>

int main(void)
{
    int read, write;

    FILE *pcm = fopen("file.pcm", "rb");
    FILE *mp3 = fopen("file.mp3", "wb");

    const int PCM_SIZE = 8192;
    const int MP3_SIZE = 8192;

    short int pcm_buffer[PCM_SIZE*2];
    unsigned char mp3_buffer[MP3_SIZE];

    lame_t lame = lame_init();
    lame_set_in_samplerate(lame, 44100);
    lame_set_VBR(lame, vbr_default);
    lame_init_params(lame);

    do {
        read = fread(pcm_buffer, 2*sizeof(short int), PCM_SIZE, pcm);
        if (read == 0)
            write = lame_encode_flush(lame, mp3_buffer, MP3_SIZE);
        else
            write = lame_encode_buffer_interleaved(lame, pcm_buffer, read, mp3_buffer, MP3_SIZE);
        fwrite(mp3_buffer, write, 1, mp3);
    } while (read != 0);

    lame_close(lame);
    fclose(mp3);
    fclose(pcm);

    return 0;
}

这篇关于是否有任何LAME C ++包装程序/简化程序(在Linux Mac上运行,并且可以从纯代码运行Win)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 07:32