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

交叉编译faac共享库

时间:2017-05-25 18:18:34      阅读:557      评论:0      收藏:0      [点我收藏+]

标签:嵌入   lang   init   div   inpu   var   blank   数据   共享   

作者:咕唧咕唧liukun321

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


     Advanced Audio Coding。一种专为声音数据设计的文件压缩格式,与Mp3不同,它採用了全新的算法进行编码。更加高效,具有更高的性价比

利用AAC格式,可使人感觉声音质量没有明显减少的前提下。更加小巧。

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


FAAC开源project源代码下载链接:FAAC源代码下载

得到FAACproject源代码后首先运行 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共享库

标签:嵌入   lang   init   div   inpu   var   blank   数据   共享   

原文地址:http://www.cnblogs.com/brucemengbm/p/6905203.html

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