码迷,mamicode.com
首页 > 其他好文 > 详细

交叉编译faac共享库

时间:2014-07-21 23:27:49      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   os   

作者:咕唧咕唧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 = NULL;
			ppBuffer = NULL;
			
		}// var init

		~AudioProcess(void)
		{
		
		}// var init
	
private:
	ULONG nInputSamples ;
	ULONG nMaxOutputBytes ;
	faacEncHandle hEncoder;
	faacEncConfigurationPtr pConfiguration;
	BYTE* pbAACBuffer;
	int nRet;
public:
	int OutAACLength;
	
	ULONG nSampleRate;  // 采样率
	UINT nChannels;         // 声道数
	UINT nPCMBitSize; 
	unsigned char* ppBuffer;
	unsigned long pSizeOfDecoderSpecificInfo;
	int nBytesRead;
	int nPCMBufferSize;
	int nAACBufferSize;
	BYTE* pbPCMBuffer;
	
	BYTE* OutAACBuffer;
public:	
	int AACEncoderInit();
	int AACEncoding();
	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;
			
}


交叉编译faac共享库,布布扣,bubuko.com

交叉编译faac共享库

标签:des   style   blog   http   color   os   

原文地址:http://blog.csdn.net/liukun321/article/details/38022237

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!