本文介绍了是否有任何LAME C ++ wraper \\控制简化(纯code在Linux上的Mac和Win工作)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想创建简单的PCM为mp3 C ++项目。我想它使用LAME。我爱LAME,但它是真的biiig。所以我需要某种形式的开源的纯code工作用纯跛脚code的工作流程控制简化。这么说来,我给它与PCM和DEST的文件中。呼叫类似

So I want to create simple pcm to mp3 C++ project. I want it to use LAME. I love LAME but It is realy biiig. 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(PCM的,文件与MP3,44100,16,MP3,VBR文件);

矿石4这样的事 - 5线(例如ofcourse应该存在),我有vhat我需要它要轻,操作简单,powerfool,开源,跨平台

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

有没有这样的事?!?

推荐答案

拉梅真的不是很难使用,虽然有很多的可选配置功能,如果你需要他们。这需要略多于4-5线连接code文件,但并不多。这里是一个工作的例子我拼凑(只是基本功能,没有错误检查):

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 ++ wraper \\控制简化(纯code在Linux上的Mac和Win工作)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 01:05