首页 > 代码库 > 交叉编译faac共享库

交叉编译faac共享库

作者:咕唧咕唧liukun321

来自:http://blog.csdn.net/liukun321


     Advanced Audio Coding。一种专为声音数据设计的文件压缩格式,与Mp3不同,它采用了全新的算法进行编码,更加高效,具有更高的性价比。利用AAC格式,可使人感觉声音质量没有明显降低的前提下,更加小巧。

     FAAC是在嵌入式系统中常用的AAC音频编码开源库,关于AAC音频格式可以看一下这篇博文作简单了解:AAC音频编码格式简析


FAAC开源工程源码下载链接:FAAC源码下载

得到FAAC工程源码后首先执行 configure获得Makefile,并指定目标平台和交叉工具链

./configure--target=arm-linux--host=arm-none-linux-gnueabi

编译:

make

安装:

make install

最终会在指定安装目录获得如下动态及静态库:

libfaac.a                         

libfaac.la                        

libfaac.so                       

libfaac.so.0                      

libfaac.so.0.0.0  

将获得的动态链接库放入开发板/usr/lib目录即可

 

下面顺带附上一个将PCM 16bit 原始音频数据编码成AAC格式音频数据的C++类,下面的代码是从一个项目中抽取的,没有单独测试,仅做参考:

class AudioProcess {
public:
	
	AudioProcess (void)
		{
			
			nSampleRate = RATE;  // 采样率
			nChannels = CHANNELS;         // 声道数
			nPCMBitSize = SIZE; 
			nInputSamples = 0;
			nMaxOutputBytes = 0;
			AACDecoderInitFlag = 0;
			DecoderHandle = 0;
			ADTSFrameInBuf = NULL;
			PCMData = http://www.mamicode.com/NULL;"white-space:pre">	int AACEncoderDestory();
};


int AudioProcess ::AACEncoderInit()
{
	   	hEncoder = faacEncOpen(nSampleRate, nChannels, &nInputSamples, &nMaxOutputBytes);
	    if(hEncoder == NULL)
	    {
	        printf("[ERROR] Failed to call faacEncOpen()\n");
	        return -1;
	    }
	    printf("nInputSamples = %d\n",nInputSamples);
	    nPCMBufferSize = nInputSamples * nPCMBitSize / 8;
	    pbPCMBuffer = new BYTE [nPCMBufferSize];
	    pbAACBuffer = new BYTE [nMaxOutputBytes];

	    //  Get current encoding configuration
	    pConfiguration = faacEncGetCurrentConfiguration(hEncoder);
	    pConfiguration->inputFormat = FAAC_INPUT_16BIT;//_16BIT;
		pConfiguration->mpegVersion = MPEG4;
		 pConfiguration->version = MPEG4;  // 1
		 pConfiguration->outputFormat =1;// ADTS_STREAM;
	
	 	 pConfiguration->aacObjectType = 2;//LOW;
	 	 pConfiguration->useTns = 0;//DEFAULT_TNS;
	  	 pConfiguration->shortctl =  0;//SHORTCTL_NORMAL;
	 	 pConfiguration->allowMidside = 1 ;
	   
	    //  Set encoding configuration
	    nRet = faacEncSetConfiguration(hEncoder, pConfiguration);
	    faacEncGetDecoderSpecificInfo(hEncoder,&(ppBuffer), &(pSizeOfDecoderSpecificInfo));
}

int AudioProcess ::AACEncoding()
{
	
	
        // 输入样本数,用实际读入字节数计算,一般只有读到文件尾时才不是				//nPCMBufferSize/(nPCMBitSize/8);
		 nBytesRead = length;
		nInputSamples = nBytesRead / (nPCMBitSize / 8);
		printf("nInputSamples = %d\n",nInputSamples);
		
        //Encode
        nRet = faacEncEncode(hEncoder, (int*) pbPCMBuffer, nInputSamples, pbAACBuffer,nMaxOutputBytes);
	 	OutAACBuffer = pbAACBuffer;
	 	OutAACLength = nRet;
        
	return nRet;
}

void AudioProcess::AACEncoderDestroy()
{	
		nRet = faacEncClose(hEncoder);
		delete[] pbPCMBuffer;
		delete[] pbAACBuffer;
			
}