c語言使用fdk_aac實現(xiàn)aac音頻解碼為pcm
示例為adts的aac流數(shù)據(jù)(adts數(shù)據(jù)可以每一包都可以獨(dú)立解析不需要拼湊)
解碼數(shù)據(jù)的采樣率同解碼前的采樣率,如果不滿足需求,需要對數(shù)據(jù)進(jìn)行重采樣
#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內(nèi)部緩存中填數(shù)據(jù)
if (err != AAC_DEC_OK) {
printf("Failed to fill AAC decoder: %d\n", err);
break;
}
while(1){ //一定要加循環(huán),一次有可能解碼不完導(dǎo)致數(shù)據(jù)丟失
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 );//輸出解碼數(shù)據(jù)大小
printf("-------------------- sampleRate:%d ", info->sampleRate);//輸出解碼后采樣率
printf("-------------------- numChannels:%d ", info->numChannels);//通道數(shù)
printf("-------------------- aacSampleRate:%d ", info->aacSampleRate);//輸入aac數(shù)據(jù)采樣率
//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);
}
}
到此這篇關(guān)于c語言使用fdk_aac實現(xiàn)aac音頻解碼為pcm的文章就介紹到這了,更多相關(guān)c語言音頻解碼內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Qt基礎(chǔ)開發(fā)之Qt多線程類QThread與Qt定時器類QTimer的詳細(xì)方法與實例
這篇文章主要介紹了Qt基礎(chǔ)開發(fā)之Qt多線程類QThread與Qt定時器類QTimer的詳細(xì)方法與實例,需要的朋友可以參考下2020-03-03
Qt5+QMediaPlayer實現(xiàn)音樂播放器的示例代碼
這篇文章主要為大家詳細(xì)介紹了如何利用Qt5和QMediaPlayer實現(xiàn)簡易的音樂播放器,文中的示例代碼講解詳細(xì),具有一定的借鑒價值,需要的可以參考一下2022-12-12
C語言使用函數(shù)實現(xiàn)字符串部分復(fù)制問題
這篇文章主要介紹了C語言使用函數(shù)實現(xiàn)字符串部分復(fù)制問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-11-11

