本文主要是介绍c语言使用fdk_aac库对aac音频解码为pcm,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//示例为adts的aac流数据(adts数据可以每一包都可以独立解析不需要拼凑)
//解码数据的采样率同解码前的采样率,如果不满足需求,需要对数据进行重采样
#include <aacdecoder_lib.h>int m_fd = -1;
int m_fd2 = -1;void aac2pcm(){HANDLE_AACDECODER decoder = aacDecoder_Open(TT_MP4_ADTS , 1);if (!decoder) {printf("Failed to open AAC decoder"); return;} m_fd = fopen("./send.aac", "rb");m_fd2 = fopen("./recv.pcm", "wb");unsigned int size=1024;unsigned int valid;unsigned char* data=(unsigned char*)malloc(size);unsigned int decsize=8* 2048 * sizeof(INT_PCM);unsigned char* decdata=(unsigned char*)malloc(decsize);int frameCnt=0;do{ int len = fread(data, 1,size, m_fd);valid=len;AAC_DECODER_ERROR err=aacDecoder_Fill(decoder, &data, &size, &valid);//往aac内部缓存中填数据if (err != AAC_DEC_OK) {printf("Failed to fill AAC decoder: %d\n", err);break;}while(1){ //一定要加循环,一次有可能解码不完导致数据丢失err = aacDecoder_DecodeFrame(decoder, (INT_PCM *)decdata,decsize / sizeof(INT_PCM), 0);if(err != AAC_DEC_OK){printf("Failed to DecodeFrame: %d\n", err);break;}//获取解码后码流的信息CStreamInfo *info = aacDecoder_GetStreamInfo(decoder);printf("--------------------frameSize:%d ",info->frameSize );//输出解码数据大小printf("-------------------- sampleRate:%d ", info->sampleRate);//输出解码后采样率printf("-------------------- numChannels:%d ", info->numChannels);//通道数printf("-------------------- aacSampleRate:%d ", info->aacSampleRate);//输入aac数据采样率//int flen = convert_16khz_to_8khz(tmp,decdata,info->frameSize*2); 重采样需要可以到其他链接中获取fwrite(decdata,info->frameSize*2,1,m_fd2);frameCnt++;}}while(1);aacDecoder_Close(decoder);if(data)free(data);if(decdata)free(decdata);if(m_fd)fclose(m_fd);if(m_fd2)fclose(m_fd2);
}
}
这篇关于c语言使用fdk_aac库对aac音频解码为pcm的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!