【已解决】FDK AAC 噪音求指导
2 E币
成为会员,免费下载资料
文件大小:13.75 MB
上传者:justchen
时间:2018-07-30 16:23:17
下载量:173
本帖最后由 ezreal_cs 于 2018-7-30 18:44 编辑
海思采用的是 I2S输入 48K 16位立体声.相关配置如下
[code]stAioAttr.enSamplerate = AUDIO_SAMPLE_RATE_48000;
stAioAttr.enBitwidth = AUDIO_BIT_WIDTH_16;
stAioAttr.enWorkmode = AIO_MODE_I2S_SLAVE;
stAioAttr.enSoundmode = AUDIO_SOUND_MODE_STEREO;
stAioAttr.u32EXFlag = 0;
stAioAttr.u32FrmNum = 30;
stAioAttr.u32PtNumPerFrm = SAMPLE_AUDIO_PTNUMPERFRM; //320
stAioAttr.u32ClkChnCnt = 2;
stAioAttr.u32ChnCnt = 2;
stAioAttr.u32ClkSel = 0;[/code]
获取音频数据并保存为文件的代码如下:
[code]for(i=0; i
fwrite(stFrame.pVirAddr[0]+i, 1 ,2 , fileFD);
fwrite(stFrame.pVirAddr[1]+i, 1 ,2 , fileFD);
}[/code]
此时获取到的PCM文件在PC上播放正常,左右声道都很正确,, (附件中的 xxx.pcm 文件).
然后将获取到的音频数据 进行FDK AAC编码后在声音稍大些的时候会有爆音. 无论是海思芯片上还是PC上都试过,效果一样.
FDK AAC相关代码 照搬[url]https://github.com/mstorsjo/fdk-aac/blob/master/aac-enc.c[/url]修改而来.
[code]while (1) {
AACENC_BufDesc in_buf = { 0 }, out_buf = { 0 };
AACENC_InArgs in_args = { 0 };
AACENC_OutArgs out_args = { 0 };
int in_identifier = IN_AUDIO_DATA;
int in_size, in_elem_size;
int out_identifier = OUT_BITSTREAM_DATA;
int out_size, out_elem_size;
int read, i;
void *in_ptr, *out_ptr;
uint8_t outbuf[20480];
AACENC_ERROR err;
//read = wav_read_data(wav, input_buf, input_size);
read = fread( input_buf, 1, 640, inFd );
if( read <= 0 )
{
printf("xxxxx文件读完了!!!\n");
exit(-1);
}
for (i = 0; i < read/2; i++) {
const uint8_t* in = &input_buf[2*i];
convert_buf = in[0] | (in[1] << 8);
}
if (read <= 0) {
in_args.numInSamples = -1;
} else {
in_ptr = convert_buf;
in_size = read;
in_elem_size = 2;
in_args.numInSamples = read/2;
in_buf.numBufs = 1;
in_buf.bufs = &in_ptr;
in_buf.bufferIdentifiers = &in_identifier;
in_buf.bufSizes = &in_size;
in_buf.bufElSizes = &in_elem_size;
}
out_ptr = outbuf;
out_size = sizeof(outbuf);
out_elem_size = 1;
out_buf.numBufs = 1;
out_buf.bufs = &out_ptr;
out_buf.bufferIdentifiers = &out_identifier;
out_buf.bufSizes = &out_size;
out_buf.bufElSizes = &out_elem_size;
if ((err = aacEncEncode(_encoder, &in_buf, &out_buf, &in_args, &out_args)) != AACENC_OK) {
if (err == AACENC_ENCODE_EOF)
break;
fprintf(stderr, "Encoding failed\n");
return;
}
if (out_args.numOutBytes == 0)
continue;
fwrite(outbuf, 1, out_args.numOutBytes, outFd);
}[/code]
尝试改过 fdk-aac的AACENC_BufDesc 结构配置,以即初始化的配置.. 但都不行
求大神指点下了.. 附件是我的工程代码, CMAKE写的, (fdk-aac 是用的静态库 ubuntu 16.04 64bit)
直接
[code]cmake .
make[/code]
可以生成 pcmToAAC 文件, 运行会读取 xxx.pcm文件并编码生成 xxx.aac.
不知道哪位大神调过FDK AAC,望指点.
[attach]7559[/attach]
海思采用的是 I2S输入 48K 16位立体声.相关配置如下
[code]stAioAttr.enSamplerate = AUDIO_SAMPLE_RATE_48000;
stAioAttr.enBitwidth = AUDIO_BIT_WIDTH_16;
stAioAttr.enWorkmode = AIO_MODE_I2S_SLAVE;
stAioAttr.enSoundmode = AUDIO_SOUND_MODE_STEREO;
stAioAttr.u32EXFlag = 0;
stAioAttr.u32FrmNum = 30;
stAioAttr.u32PtNumPerFrm = SAMPLE_AUDIO_PTNUMPERFRM; //320
stAioAttr.u32ClkChnCnt = 2;
stAioAttr.u32ChnCnt = 2;
stAioAttr.u32ClkSel = 0;[/code]
获取音频数据并保存为文件的代码如下:
[code]for(i=0; i
fwrite(stFrame.pVirAddr[1]+i, 1 ,2 , fileFD);
}[/code]
此时获取到的PCM文件在PC上播放正常,左右声道都很正确,, (附件中的 xxx.pcm 文件).
然后将获取到的音频数据 进行FDK AAC编码后在声音稍大些的时候会有爆音. 无论是海思芯片上还是PC上都试过,效果一样.
FDK AAC相关代码 照搬[url]https://github.com/mstorsjo/fdk-aac/blob/master/aac-enc.c[/url]修改而来.
[code]while (1) {
AACENC_BufDesc in_buf = { 0 }, out_buf = { 0 };
AACENC_InArgs in_args = { 0 };
AACENC_OutArgs out_args = { 0 };
int in_identifier = IN_AUDIO_DATA;
int in_size, in_elem_size;
int out_identifier = OUT_BITSTREAM_DATA;
int out_size, out_elem_size;
int read, i;
void *in_ptr, *out_ptr;
uint8_t outbuf[20480];
AACENC_ERROR err;
//read = wav_read_data(wav, input_buf, input_size);
read = fread( input_buf, 1, 640, inFd );
if( read <= 0 )
{
printf("xxxxx文件读完了!!!\n");
exit(-1);
}
for (i = 0; i < read/2; i++) {
const uint8_t* in = &input_buf[2*i];
convert_buf = in[0] | (in[1] << 8);
}
if (read <= 0) {
in_args.numInSamples = -1;
} else {
in_ptr = convert_buf;
in_size = read;
in_elem_size = 2;
in_args.numInSamples = read/2;
in_buf.numBufs = 1;
in_buf.bufs = &in_ptr;
in_buf.bufferIdentifiers = &in_identifier;
in_buf.bufSizes = &in_size;
in_buf.bufElSizes = &in_elem_size;
}
out_ptr = outbuf;
out_size = sizeof(outbuf);
out_elem_size = 1;
out_buf.numBufs = 1;
out_buf.bufs = &out_ptr;
out_buf.bufferIdentifiers = &out_identifier;
out_buf.bufSizes = &out_size;
out_buf.bufElSizes = &out_elem_size;
if ((err = aacEncEncode(_encoder, &in_buf, &out_buf, &in_args, &out_args)) != AACENC_OK) {
if (err == AACENC_ENCODE_EOF)
break;
fprintf(stderr, "Encoding failed\n");
return;
}
if (out_args.numOutBytes == 0)
continue;
fwrite(outbuf, 1, out_args.numOutBytes, outFd);
}[/code]
尝试改过 fdk-aac的AACENC_BufDesc 结构配置,以即初始化的配置.. 但都不行
求大神指点下了.. 附件是我的工程代码, CMAKE写的, (fdk-aac 是用的静态库 ubuntu 16.04 64bit)
直接
[code]cmake .
make[/code]
可以生成 pcmToAAC 文件, 运行会读取 xxx.pcm文件并编码生成 xxx.aac.
不知道哪位大神调过FDK AAC,望指点.
[attach]7559[/attach]
展开》
折叠》