unsigned char mp3buffer[LAME_MAXMP3BUFFER];
lame_t lame = lame_init();
lame_set_in_samplerate(lame, 44100);
lame_set_out_samplerate(lame, 44100);
lame_set_num_channels(lame, 1);
lame_set_mode(lame, MONO);
lame_set_quality(lame, 0);
lame_set_brate(lame, 128);
lame_init_params(lame);
int iread = 0;
int imp3 = 0;
do
{
iread = file.read((char *)buf, buf_size * sizeof(float));
if(iread > 0)
{
int current_pcm_size = iread / sizeof(float);
static float filtered_buffer[buf_size];
if(fstart > 0.0) // bandpass filtering
{
ippsFIR64f_32f(buf, filtered_buffer, current_pcm_size,
filter->pState);
}
else
{
memcpy(filtered_buffer, buf, iread);
}
imp3 = lame_encode_buffer_ieee_float(
lame, filtered_buffer, filtered_buffer,
current_pcm_size, mp3buffer, 0);
f_mp3.write((char *)mp3buffer, imp3);
m_pr += iread;
emit signalProgress(m_pr);
qApp->processEvents();
}
} while(iread > 0 && dlg->isVisible());
imp3 = lame_encode_flush(lame, mp3buffer, sizeof(mp3buffer));
if(imp3 >= 0)
{
f_mp3.write((char *)mp3buffer, imp3);
}
f_mp3.flush();
lame_close(lame);
此代码基于前端文件中的编码器示例lame_main.c
我经常收到这个错误:
这是一个致命错误。它有多种可能的原因:90% LAME 使用有缺陷的 gcc 版本编译,使用了高级优化 9% 您的系统超频 1% LAME 编码库存在缺陷内部缓冲区不一致。flushbits <> ResvSizebit 库错误
系统:Ubuntu 14.04.1,gcc(Ubuntu 4.8.2-19ubuntu1)4.8.2,未超频的PC