Commit 7c160985 authored by banban's avatar banban

调用libfaac将pcm转码aac

parents
File added
/*
* FAAC - Freeware Advanced Audio Coder
* Copyright (C) 2001 Menno Bakker
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: faac.h,v 1.36 2009/01/25 18:50:32 menno Exp $
*/
#ifndef _FAAC_H_
#define _FAAC_H_
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#if defined(_WIN32) && !defined(__MINGW32__)
# ifndef FAACAPI
# define FAACAPI __stdcall
# endif
#else
# ifndef FAACAPI
# define FAACAPI
# endif
#endif
#pragma pack(push, 1)
typedef struct {
void *ptr;
char *name;
}
psymodellist_t;
#include "faaccfg.h"
typedef void *faacEncHandle;
#ifndef HAVE_INT32_T
typedef signed int int32_t;
#endif
/*
Allows an application to get FAAC version info. This is intended
purely for informative purposes.
Returns FAAC_CFG_VERSION.
*/
int FAACAPI faacEncGetVersion(char **faac_id_string,
char **faac_copyright_string);
faacEncConfigurationPtr FAACAPI
faacEncGetCurrentConfiguration(faacEncHandle hEncoder);
int FAACAPI faacEncSetConfiguration(faacEncHandle hEncoder,
faacEncConfigurationPtr config);
faacEncHandle FAACAPI faacEncOpen(unsigned long sampleRate,
unsigned int numChannels,
unsigned long *inputSamples,
unsigned long *maxOutputBytes);
int FAACAPI faacEncGetDecoderSpecificInfo(faacEncHandle hEncoder, unsigned char **ppBuffer,
unsigned long *pSizeOfDecoderSpecificInfo);
int FAACAPI faacEncEncode(faacEncHandle hEncoder, int32_t * inputBuffer, unsigned int samplesInput,
unsigned char *outputBuffer,
unsigned int bufferSize);
int FAACAPI faacEncClose(faacEncHandle hEncoder);
#pragma pack(pop)
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _FAAC_H_ */
/*
* FAAC - Freeware Advanced Audio Coder
* Copyright (C) 2001 Menno Bakker
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: faaccfg.h,v 1.3 2004/07/04 12:12:05 corrados Exp $
*/
#ifndef _FAACCFG_H_
#define _FAACCFG_H_
#define FAAC_CFG_VERSION 104
/* MPEG ID's */
#define MPEG2 1
#define MPEG4 0
/* AAC object types */
#define MAIN 1
#define LOW 2
#define SSR 3
#define LTP 4
/* Input Formats */
#define FAAC_INPUT_NULL 0
#define FAAC_INPUT_16BIT 1
#define FAAC_INPUT_24BIT 2
#define FAAC_INPUT_32BIT 3
#define FAAC_INPUT_FLOAT 4
#define SHORTCTL_NORMAL 0
#define SHORTCTL_NOSHORT 1
#define SHORTCTL_NOLONG 2
#pragma pack(push, 1)
typedef struct faacEncConfiguration
{
/* config version */
int version;
/* library version */
char *name;
/* copyright string */
char *copyright;
/* MPEG version, 2 or 4 */
unsigned int mpegVersion;
/* AAC object type */
unsigned int aacObjectType;
/* Allow mid/side coding */
unsigned int allowMidside;
/* Use one of the channels as LFE channel */
unsigned int useLfe;
/* Use Temporal Noise Shaping */
unsigned int useTns;
/* bitrate / channel of AAC file */
unsigned long bitRate;
/* AAC file frequency bandwidth */
unsigned int bandWidth;
/* Quantizer quality */
unsigned long quantqual;
/* Bitstream output format (0 = Raw; 1 = ADTS) */
unsigned int outputFormat;
/* psychoacoustic model list */
psymodellist_t *psymodellist;
/* selected index in psymodellist */
unsigned int psymodelidx;
/*
PCM Sample Input Format
0 FAAC_INPUT_NULL invalid, signifies a misconfigured config
1 FAAC_INPUT_16BIT native endian 16bit
2 FAAC_INPUT_24BIT native endian 24bit in 24 bits (not implemented)
3 FAAC_INPUT_32BIT native endian 24bit in 32 bits (DEFAULT)
4 FAAC_INPUT_FLOAT 32bit floating point
*/
unsigned int inputFormat;
/* block type enforcing (SHORTCTL_NORMAL/SHORTCTL_NOSHORT/SHORTCTL_NOLONG) */
int shortctl;
/*
Channel Remapping
Default 0, 1, 2, 3 ... 63 (64 is MAX_CHANNELS in coder.h)
WAVE 4.0 2, 0, 1, 3
WAVE 5.0 2, 0, 1, 3, 4
WAVE 5.1 2, 0, 1, 4, 5, 3
AIFF 5.1 2, 0, 3, 1, 4, 5
*/
int channel_map[64];
} faacEncConfiguration, *faacEncConfigurationPtr;
#pragma pack(pop)
#endif /* _FAACCFG_H_ */
File added
File added
File added
File added
库:libfaac
版本:v1.28
下载地址:http://www.audiocoding.com/
\ No newline at end of file
File added

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libfaac", "libfaac\libfaac.vcxproj", "{9CC48C6E-92EB-4814-AD37-97AB3622AB65}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pcmToAAC", "pcmToAAC\pcmToAAC.vcxproj", "{C476BAC1-30E1-43D3-B908-A46406FDE579}"
ProjectSection(ProjectDependencies) = postProject
{9CC48C6E-92EB-4814-AD37-97AB3622AB65} = {9CC48C6E-92EB-4814-AD37-97AB3622AB65}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9CC48C6E-92EB-4814-AD37-97AB3622AB65}.Debug|Win32.ActiveCfg = Debug|Win32
{9CC48C6E-92EB-4814-AD37-97AB3622AB65}.Debug|Win32.Build.0 = Debug|Win32
{9CC48C6E-92EB-4814-AD37-97AB3622AB65}.Debug|x64.ActiveCfg = Debug|x64
{9CC48C6E-92EB-4814-AD37-97AB3622AB65}.Debug|x64.Build.0 = Debug|x64
{9CC48C6E-92EB-4814-AD37-97AB3622AB65}.Release|Win32.ActiveCfg = Release|Win32
{9CC48C6E-92EB-4814-AD37-97AB3622AB65}.Release|Win32.Build.0 = Release|Win32
{9CC48C6E-92EB-4814-AD37-97AB3622AB65}.Release|x64.ActiveCfg = Release|x64
{9CC48C6E-92EB-4814-AD37-97AB3622AB65}.Release|x64.Build.0 = Release|x64
{C476BAC1-30E1-43D3-B908-A46406FDE579}.Debug|Win32.ActiveCfg = Debug|Win32
{C476BAC1-30E1-43D3-B908-A46406FDE579}.Debug|Win32.Build.0 = Debug|Win32
{C476BAC1-30E1-43D3-B908-A46406FDE579}.Debug|x64.ActiveCfg = Debug|x64
{C476BAC1-30E1-43D3-B908-A46406FDE579}.Debug|x64.Build.0 = Debug|x64
{C476BAC1-30E1-43D3-B908-A46406FDE579}.Release|Win32.ActiveCfg = Release|Win32
{C476BAC1-30E1-43D3-B908-A46406FDE579}.Release|Win32.Build.0 = Release|Win32
{C476BAC1-30E1-43D3-B908-A46406FDE579}.Release|x64.ActiveCfg = Release|x64
{C476BAC1-30E1-43D3-B908-A46406FDE579}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
#include "AacEnc.h"
#include <stdlib.h>
#include <memory.h>
#include <stdio.h>
#ifndef max
#define max(a, b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
CAacEnc::CAacEnc(unsigned long nSampleRate = SAMPLE_RATE_DEF, unsigned long nChannels = 2, unsigned int nSampleBitCount = SAMPLE_BITS_DEF)
: m_IListener(NULL)
, m_nSampleRate(max(1, nSampleRate))
, m_nChannels(max(1, nChannels))
, m_nSampleBitCount(max(1, nSampleBitCount))
, m_nInputSamples(0)
, m_nMaxOutputBytes(0)
, m_pPcmInBuf(NULL)
, m_pAacOutBuf(NULL)
, m_phEnc(NULL)
, m_ppConfig(NULL)
, m_nPcmSamples(0)
{
m_strCopyRight[0] = '\0';
m_phEnc = new faacEncHandle;
m_ppConfig = new faacEncConfigurationPtr;
if (!m_phEnc|| !m_ppConfig)
return;
*m_phEnc=NULL;
*m_ppConfig=NULL;
OpenEncoder(nSampleRate, nChannels, nSampleBitCount);
}
CAacEnc::~CAacEnc()
{
ReleaseAll();
}
void CAacEnc::ReleaseAll()
{
CloseEncoder();
if (m_phEnc) {
delete m_phEnc;
m_phEnc = NULL;
}
if (m_ppConfig) {
delete m_ppConfig;
m_ppConfig = NULL;
}
}
bool CAacEnc::OpenEncoder(unsigned long nSampleRate = SAMPLE_RATE_DEF, unsigned long nChannels = 2, unsigned int nSampleBitCount = SAMPLE_BITS_DEF)
{
bool bRet = false;
if (m_phEnc&& *m_phEnc)
return bRet;
m_nSampleRate= max(1, nSampleRate);
m_nChannels = max(1, nChannels);
m_nSampleBitCount = max(1, nSampleBitCount);
do {
// (1)Open FAAC engine
*m_phEnc = faacEncOpen(m_nSampleRate, m_nChannels, &m_nInputSamples, &m_nMaxOutputBytes);
if (!*m_phEnc)
break;
const int nPCMBufferSize = m_nInputSamples * m_nSampleBitCount / 8;
m_pPcmInBuf = new unsigned char[nPCMBufferSize];
if (!m_pPcmInBuf)
break;
m_pAacOutBuf = new unsigned char[m_nMaxOutputBytes];
if (!m_pAacOutBuf)
break;
// (2.1) Get current encoding configuration
*m_ppConfig = faacEncGetCurrentConfiguration(*m_phEnc);
if(!*m_ppConfig)
break;
//设置编码配置信息
/* PCM Sample Input Format
0 FAAC_INPUT_NULL invalid, signifies a misconfigured config
1 FAAC_INPUT_16BIT native endian 16bit
2 FAAC_INPUT_24BIT native endian 24bit in 24 bits (not implemented)
3 FAAC_INPUT_32BIT native endian 24bit in 32 bits (DEFAULT)
4 FAAC_INPUT_FLOAT 32bit floating point
*/
(*m_ppConfig)->inputFormat = FAAC_INPUT_16BIT;
// 0 = Raw; 1 = ADTS
(*m_ppConfig)->outputFormat = 1;
(*m_ppConfig)->aacObjectType = LOW; //设置AAC类型
// (*m_ppConfig)->useLfe = 0; //是否允许一个声道为低频通道
// (*m_ppConfig)->useTns = 1; //是否使用瞬时噪声定形滤波器(具体作用不是很清楚)
// (*m_ppConfig)->allowMidside = 0; //是否允许midSide coding (在MPEG-2 AAC 系统中,M/S(Mid/Side) Stereo coding被提供在多声道信号中,每个声道对(channel pair)的组合,也就是每个通道对,是对称地排列在人耳听觉的左右两边,其方式简单,且对位串不会引起较显著的负担。 一般其在左右声道数据相似度大时常被用到,并需记载每一频带的四种能量临界组合,分别为左、右、左右声道音频合并(L+R)及相减(L-R)的两种新的能量。一般,若所转换的Sid声道的能量较小时,M/S Stereo coding 可以节省此通道的位数,而将多余的位应用于另一个所转换的声道,即Mid 声道,进而可提高此编码效率。)
// (2.2) Set encoding configuration
(void)faacEncSetConfiguration(*m_phEnc, *m_ppConfig);
bRet = true;
} while (false);
if (!bRet) {
CloseEncoder();
}
return bRet;
}
void CAacEnc::CloseEncoder()
{
if (!m_phEnc|| !*m_phEnc)
return;
(void)Flush();
(void)faacEncClose(*m_phEnc);
*m_phEnc = NULL;
if (m_pPcmInBuf) {
delete[] m_pPcmInBuf;
m_pPcmInBuf = NULL;
}
if (m_pAacOutBuf) {
delete[] m_pAacOutBuf;
m_pAacOutBuf = NULL;
}
}
// 数据填入缓存,每2048字节送编码,不足2048的暂存于缓存与下次调用或Flush补上的静音数据一起编码。
bool CAacEnc::Encode(unsigned char* inPcmBuffer, unsigned long inPcmBytes/*=441*2*sizeof(short)*/)
{//第9次
bool bRet=false;
unsigned long inSamples= inPcmBytes / (m_nSampleBitCount / 8);//2B;
if (inSamples == 0)
return bRet;
unsigned long nAllSample = m_nPcmSamples/*=1764*/ + inSamples/*=441*/;
// if(nAllSample>=2*m_nInputSamples)//临时防止多次编码outBytesOfAacBuffer溢出
// return bRet;
if(inSamples==0|| !m_phEnc|| !*m_phEnc)
return bRet;
unsigned long inRemain=inSamples;
int outBytesOfAacBuffer=0;
//m_nMaxOutputBytes*nAllSample/m_nInputSamples;//?
bRet=true;
for(; nAllSample>=m_nInputSamples/*=2048*/; nAllSample-=m_nInputSamples){
unsigned long nCopy = min(inRemain, m_nInputSamples - m_nPcmSamples);//284
memcpy(m_pPcmInBuf + m_nPcmSamples * sizeof(short), inPcmBuffer+(inSamples-inRemain)*sizeof(short), nCopy * sizeof(short));
inRemain-=nCopy;//598
outBytesOfAacBuffer=faacEncEncode(*m_phEnc, (int*)m_pPcmInBuf/*inBuf*/, m_nInputSamples/*固定2048*/, m_pAacOutBuf/*outBuf*/, m_nMaxOutputBytes);
m_nPcmSamples=0;
if(0==outBytesOfAacBuffer){
continue;
}else if(outBytesOfAacBuffer<0){
bRet=false;
break;
}else{//outBytesOfAacBuffer > 0
if (m_IListener) {
bRet = m_IListener->OnData(m_pAacOutBuf, outBytesOfAacBuffer);
if(!bRet)
break;
}
}
}
if(bRet&& inRemain!=0){
memcpy(m_pPcmInBuf+m_nPcmSamples * sizeof(short), inPcmBuffer+(inSamples-inRemain)*sizeof(short), inRemain * sizeof(short));
m_nPcmSamples+=inRemain;
}
return bRet;//多次编码输出后大于m_nMaxOutputBytes会溢出
}
//编码器起始是会缓存3-4个2048个样本,所以编码结束时用Flush取出尾部剩余的数据,直到返回值<=0才算完成
bool CAacEnc::Flush()
{
int outBytesOfAacBuffer;
if(0!=m_nPcmSamples){//缓冲中还有不足2048的数据时,用静音包补满2048字节,完成本帧编码。
if(m_nPcmSamples>m_nInputSamples){
m_nPcmSamples=0;
return false;
}
//不补静音包,只送剩余数据,不足2048个采样的部分,编码器会自行补齐静音包:
outBytesOfAacBuffer = faacEncEncode(*m_phEnc, (int*)m_pPcmInBuf/*inBuf*/, m_nPcmSamples/*只送剩余数据*/, m_pAacOutBuf/*outBuf*/, m_nMaxOutputBytes);
// unsigned char* p = m_pPcmInBuf + m_nPcmSamples * sizeof(short);
// memset(p, 0, (m_nInputSamples - m_nPcmSamples) * sizeof(short));//补静音包
// outBytesOfAacBuffer = faacEncEncode(*m_phEnc, (int*)m_pPcmInBuf/*inBuf*/, m_nInputSamples/*固定2048*/, m_pAacOutBuf/*outBuf*/, m_nMaxOutputBytes);
m_nPcmSamples = 0;
if(outBytesOfAacBuffer<0) {
return false;
} else if(0==outBytesOfAacBuffer) {
return true;//返回true,不调用OnData()
}
} else {
//输入长度为零的数据,获取解码器的残余数据,直到返回<=0才算结束。
outBytesOfAacBuffer = faacEncEncode(*m_phEnc, NULL/*inBuf*/, 0/*零长度*/, m_pAacOutBuf/*outBuf*/, m_nMaxOutputBytes);
if(outBytesOfAacBuffer <= 0)
return false;
}
//outBytesOfAacBuffer>0
if (m_IListener)
return m_IListener->OnData(m_pAacOutBuf, outBytesOfAacBuffer);
return true;
}
const char* CAacEnc::GetCopyRight()
{
char* verId = NULL;
char* copyRight = NULL;
(void)faacEncGetVersion(&verId, &copyRight);
sprintf(m_strCopyRight, "faac v%s\n%s\n", verId, copyRight);
return m_strCopyRight;
}
void CAacEnc::AddEventListener(IAacEncListener* IListener)
{
m_IListener=IListener;
}
#ifndef CLASS_4321B8861C16_CAACENC
#define CLASS_4321B8861C16_CAACENC
#include "faac.h"
class IAacEncListener
{
public:
virtual bool OnData(unsigned char* outAacBuffer, unsigned long outBufferBytes) = 0;//{ return true; }
};
class CAacEnc {
public:
#define SAMPLE_RATE_DEF (44100)
#define SAMPLE_BITS_DEF (16)
#define MAX_COPYRIGHT_STR (260)
CAacEnc(unsigned long nSampleRate, unsigned long nChannels, unsigned int nSampleBitCount);
~CAacEnc();
const char* GetCopyRight();
bool OpenEncoder(unsigned long nSampleRate, unsigned long nChannels, unsigned int nSampleBitCount);
bool Encode(unsigned char* inPcmBuffer, unsigned long inPcmBytes);
/** Flush()的调用示例:
while (true) {
iRet = oAacEnc.Flush(&pbAACBuffer);
if (iRet <= 0)//返回非正值才算结束
break;
printf("Last remaining data.", pbAACBuffer)
}
*/
bool Flush();
void CloseEncoder();
protected:
IAacEncListener* m_IListener;
char m_strCopyRight[MAX_COPYRIGHT_STR];
unsigned long m_nSampleRate; // 设置输出aac采样率
unsigned int m_nChannels; // 设置输出aac声道数
unsigned int m_nSampleBitCount; // 设置输出aac单样本位数
unsigned long m_nInputSamples;
unsigned long m_nMaxOutputBytes;
unsigned char* m_pPcmInBuf;
unsigned long m_nPcmSamples;
unsigned char* m_pAacOutBuf;
faacEncHandle* m_phEnc;
faacEncConfigurationPtr* m_ppConfig;
void ReleaseAll();
public:
void AddEventListener(IAacEncListener* IListener);
};
#endif // !CLASS_4321B8861C16_CAACENC
#include "AacEncListener.h"
#include <io.h>
#include <string.h>
CAacEncListener::CAacEncListener(const char* strFile)
: m_fp(NULL)
{
if(strFile&& 0!=strlen(strFile))
m_fp=fopen(strFile, "wb");//AAC file for output
}
CAacEncListener::~CAacEncListener()
{
if(m_fp){
fclose(m_fp);
m_fp=NULL;
}
}
bool CAacEncListener::OnData(unsigned char* outAacBuffer, unsigned long outBufferBytes)
{
static long pkgId=0;
++pkgId;
if(0==outBufferBytes|| !outAacBuffer){
printf("%ld: error, 0 bytes\n", pkgId);
return true;
}
if(m_fp){
(void)fwrite(outAacBuffer, 1, outBufferBytes, m_fp);
//int fd = _fileno(m_fp); //获取文件描述符
//_commit(fd); //强制写硬盘
//printf("%ld: faac out %d\n", pkgId, outBufferBytes);
}
return true;
}
#ifndef CLASS_4321B8861C16_CMYAACENCLISTENER
#define CLASS_4321B8861C16_CMYAACENCLISTENER
#include "AacEnc.h"
#include <stdio.h>
class CAacEncListener: public IAacEncListener
{
public:
CAacEncListener(const char* strFile);
~CAacEncListener();
bool OnData(unsigned char* outAacBuffer, unsigned long outBufferBytes);
protected:
FILE* m_fp;
};
#endif // !CLASS_4321B8861C16_CMYAACENCLISTENER
// pcmToAAC.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <stdio.h>
#include "AacEnc.h"
#include "AacEncListener.h"
typedef unsigned long ULONG;
typedef unsigned int UINT;
typedef unsigned char BYTE;
typedef char _TCHAR;
int main(int argc, char* argv[])
{
#if 1
ULONG nSampleRate = 48000;//SAMPLE_RATE_DEF; // 设置输出aac采样率
UINT nChannels = 2; // 设置输出aac声道数
UINT nPCMBitSize = SAMPLE_BITS_DEF; // 设置输出aac单样本位数
ULONG nInputSamples = 0;
ULONG nMaxOutputBytes = 0;
unsigned long nBytesRead = -1;
int nPCMBufferSize = nChannels*nPCMBitSize/8;//sizeof(short)* nChannels * nSampleRate / 100;//10ms/1s*/
BYTE* pbPCMBuffer = new BYTE[nPCMBufferSize];
BYTE* pbAACBuffer = NULL;
if (argc < 3)
return -1;
FILE* fpIn = fopen(argv[1], "rb");// PCM file for input
if (fpIn == NULL) {
printf("[ERROR] Failed Read pcm.\n");
return -1;
}
CAacEnc oAacEnc(nSampleRate, nChannels, nPCMBitSize);
CAacEncListener oListener(argv[2]);
oAacEnc.AddEventListener(&oListener);
//printf("%s", oAacEnc.GetCopyRight());//获取libfaa版本信息
unsigned long lReadBytes=0;
int i=0;
bool bRet = true;
for(; bRet; i++){
// 读入的实际字节数,最大不会超过nPCMBufferSize,一般只有读到文件尾时才不是这个值
nBytesRead = (unsigned long)fread(pbPCMBuffer, 1, nPCMBufferSize, fpIn);
lReadBytes+=nBytesRead;
// (3) Encode
bRet=oAacEnc.Encode(pbPCMBuffer, nBytesRead);
}
while (bRet=oAacEnc.Flush());
delete[] pbPCMBuffer;
fclose(fpIn);
printf("%lu bytes Completed.\nPress any key to exit.\n", lReadBytes);
getchar();
return 0;
#else
ULONG nSampleRate = 44100; // 设置输出aac采样率
UINT nChannels = 2; // 设置输出aac声道数
UINT nPCMBitSize = 16; // 设置输出aac单样本位数
ULONG nInputSamples = 0;
ULONG nMaxOutputBytes = 0;
int nRet = -1;
faacEncHandle hEncoder = NULL;
faacEncConfigurationPtr pConfiguration = NULL;
unsigned int nBytesRead = -1;
int nPCMBufferSize = 0;
BYTE* pbPCMBuffer = NULL;
BYTE* pbAACBuffer = NULL;
if (argc < 3)
return -1;
FILE* fpIn = fopen(argv[1], "rb");// PCM file for input
if (!fpIn) {
printf("[ERROR] Failed Read pcm.\n");
return -1;
}
FILE* fpOut = fopen(argv[2], "wb");// AAC file for output
do {
// (1) Open FAAC engine
hEncoder = faacEncOpen(nSampleRate, nChannels, &nInputSamples, &nMaxOutputBytes);
if (!hEncoder) {
break;
}
nPCMBufferSize = nInputSamples * nPCMBitSize / 8;
printf("--nInputSamples=%d--nPCMBitSize=%d-----nPCMBufferSize=%d ,nMaxOutputBytes=%d\n", nInputSamples, nPCMBitSize, nPCMBufferSize, nMaxOutputBytes);
//getchar();
pbPCMBuffer = new BYTE[nPCMBufferSize];
if (!pbPCMBuffer)
break;
pbAACBuffer = new BYTE[nMaxOutputBytes];
if (!pbAACBuffer)
break;
// (2.1) Get current encoding configuration
pConfiguration = faacEncGetCurrentConfiguration(hEncoder);
if (!pConfiguration)
break;
//设置编码配置信息
/* PCM Sample Input Format
0 FAAC_INPUT_NULL invalid, signifies a misconfigured config
1 FAAC_INPUT_16BIT native endian 16bit
2 FAAC_INPUT_24BIT native endian 24bit in 24 bits (not implemented)
3 FAAC_INPUT_32BIT native endian 24bit in 32 bits (DEFAULT)
4 FAAC_INPUT_FLOAT 32bit floating point
*/
pConfiguration->inputFormat = FAAC_INPUT_16BIT;
// 0 = Raw; 1 = ADTS
pConfiguration->outputFormat = 1;
pConfiguration->aacObjectType = LOW; //设置AAC类型
//pConfiguration->useLfe = 0; //是否允许一个声道为低频通道
//pConfiguration->useTns = 1; //是否使用瞬时噪声定形滤波器(具体作用不是很清楚)
//pConfiguration->allowMidside = 0; //是否允许midSide coding (在MPEG-2 AAC 系统中,M/S(Mid/Side) Stereo coding被提供在多声道信号中,每个声道对(channel pair)的组合,也就是每个通道对,是对称地排列在人耳听觉的左右两边,其方式简单,且对位串不会引起较显著的负担。 一般其在左右声道数据相似度大时常被用到,并需记载每一频带的四种能量临界组合,分别为左、右、左右声道音频合并(L+R)及相减(L-R)的两种新的能量。一般,若所转换的Sid声道的能量较小时,M/S Stereo coding 可以节省此通道的位数,而将多余的位应用于另一个所转换的声道,即Mid 声道,进而可提高此编码效率。)
// (2.2) Set encoding configuration
nRet = faacEncSetConfiguration(hEncoder, pConfiguration);
for (int i = 0; nBytesRead != 0; i++) {
// 读入的实际字节数,最大不会超过nPCMBufferSize,一般只有读到文件尾时才不是这个值
nBytesRead = (unsigned int)fread(pbPCMBuffer, 1, nPCMBufferSize, fpIn);
// 输入样本数,用实际读入字节数计算,一般只有读到文件尾时才不是nPCMBufferSize/(nPCMBitSize/8);
nInputSamples = nBytesRead / (nPCMBitSize / 8);
printf("%d: faacEncEncode nInputSamples %d\n", i, nInputSamples);
// (3) Encode
nRet = faacEncEncode(hEncoder, (int*)pbPCMBuffer/*inBuf*/, nInputSamples, pbAACBuffer/*outBuf*/, nMaxOutputBytes);
if (fpOut&& nRet > 0)
fwrite(pbAACBuffer, 1, nRet/*aacSize*/, fpOut);
printf("%d: faacEncEncode returns %d\n", i, nRet);
}
} while (false);
// (4) Close FAAC engine
if (hEncoder)
nRet = faacEncClose(hEncoder);
if (pbPCMBuffer)
delete[] pbPCMBuffer;
if (pbAACBuffer)
delete[] pbAACBuffer;
fclose(fpIn);
if (fpOut)
fclose(fpOut);
//getchar();
return 0;
#endif
}
#include "stdafx.h"
#include "PcmConvertAac.h"
CPcmConvertAac::CPcmConvertAac(unsigned long nSampleRate=44100, unsigned int nChannels=2, unsigned long nPCMBitSize=16)
: m_EncoderHandle(NULL)
, m_pConfiguration(NULL)
, m_AacBuffer(NULL)
, m_SampleRate(nSampleRate)
, m_Channels(nChannels)
, m_MaxOutputBytes(0)
, m_PCMBitSize(nPCMBitSize)
{
}
CPcmConvertAac::~CPcmConvertAac()
{
}
/** nPCMBufferSize 返回输入一组pcm数据所需要new空间大小
*/
void CPcmConvertAac::init_faac_encode(int* nPCMBufferSize)
{
unsigned long nMaxOutputBytes = 0;
unsigned long nInputSamples = 0;
m_EncoderHandle = faacEncOpen(m_SampleRate, m_Channels, &nInputSamples, &m_MaxOutputBytes);
m_pConfiguration = faacEncGetCurrentConfiguration(m_EncoderHandle);
m_pConfiguration->inputFormat = FAAC_INPUT_16BIT;
faacEncSetConfiguration(m_EncoderHandle, m_pConfiguration);
if(nPCMBufferSize)
*nPCMBufferSize = nInputSamples * m_PCMBitSize / 8;//
printf("--m_MaxOutputBytes=%d-----nInputSamples=%d----m_PCMBitSize=%d\n", m_MaxOutputBytes, nInputSamples, m_PCMBitSize);
//unsigned char* pbPCMBuffer = new unsigned char[nPCMBufferSize];
m_AacBuffer = new unsigned char[m_MaxOutputBytes];
return;
}
/** pbPCMBuffer 输入一帧pcmBuffer
* @nBytesRead pcmBuffer一帧尺寸 pcmBuffer size 4096
* @nAacSize 返回编码后一帧aac大小
* @return 返回pcm编码aac
*/
unsigned char* CPcmConvertAac::encode(int* pbPCMBuffer, int nBytesRead, int* nAacSize)
{
if (!m_EncoderHandle || !pbPCMBuffer || nBytesRead <= 0 || !m_AacBuffer) {
return NULL;
}
unsigned long nInputSamples = nBytesRead / (m_PCMBitSize / 8);// 4096 / (16 / 8)
int aacSize = faacEncEncode(m_EncoderHandle, pbPCMBuffer, nInputSamples, m_AacBuffer, m_MaxOutputBytes);
*nAacSize = aacSize;
return m_AacBuffer;
}
void CPcmConvertAac::encode_destroy() {
if (m_AacBuffer) {
delete[] m_AacBuffer;
m_AacBuffer = NULL;
}
if (m_EncoderHandle)
faacEncClose(m_EncoderHandle);
}
#ifndef _PCM_CONVERT_AAC_
#define _PCM_CONVERT_AAC_
#include "faac.h"
class CPcmConvertAac
{
public:
CPcmConvertAac(unsigned long m_SampleRate, unsigned int m_Channels, unsigned long nPCMBitSize);
~CPcmConvertAac();
protected:
faacEncHandle m_EncoderHandle;
faacEncConfigurationPtr m_pConfiguration;
unsigned char* m_AacBuffer;//输出aacBuf
unsigned long m_SampleRate; // 设置输出aac采样率
unsigned int m_Channels; // 设置输出aac声道数
unsigned int m_PCMBitSize; //
unsigned long* m_InputSamples;
unsigned long m_MaxOutputBytes;
public:
void init_faac_encode(int* nPCMBufferSiz);
unsigned char* encode(int* pbPCMBuffer, int nBytesRead, int* nAacSize);
void encode_destroy();
};
#endif // _PCM_CONVERT_AAC_
/*
* FAAC - Freeware Advanced Audio Coder
* Copyright (C) 2001 Menno Bakker
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: faac.h,v 1.36 2009/01/25 18:50:32 menno Exp $
*/
#ifndef _FAAC_H_
#define _FAAC_H_
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#if defined(_WIN32) && !defined(__MINGW32__)
# ifndef FAACAPI
# define FAACAPI __stdcall
# endif
#else
# ifndef FAACAPI
# define FAACAPI
# endif
#endif
#pragma pack(push, 1)
typedef struct {
void *ptr;
char *name;
}
psymodellist_t;
#include "faaccfg.h"
typedef void *faacEncHandle;
#ifndef HAVE_INT32_T
typedef signed int int32_t;
#endif
/*
Allows an application to get FAAC version info. This is intended
purely for informative purposes.
Returns FAAC_CFG_VERSION.
*/
int FAACAPI faacEncGetVersion(char **faac_id_string,
char **faac_copyright_string);
faacEncConfigurationPtr FAACAPI
faacEncGetCurrentConfiguration(faacEncHandle hEncoder);
int FAACAPI faacEncSetConfiguration(faacEncHandle hEncoder,
faacEncConfigurationPtr config);
faacEncHandle FAACAPI faacEncOpen(unsigned long sampleRate,
unsigned int numChannels,
unsigned long *inputSamples,
unsigned long *maxOutputBytes);
int FAACAPI faacEncGetDecoderSpecificInfo(faacEncHandle hEncoder, unsigned char **ppBuffer,
unsigned long *pSizeOfDecoderSpecificInfo);
int FAACAPI faacEncEncode(faacEncHandle hEncoder, int32_t * inputBuffer, unsigned int samplesInput,
unsigned char *outputBuffer,
unsigned int bufferSize);
int FAACAPI faacEncClose(faacEncHandle hEncoder);
#pragma pack(pop)
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _FAAC_H_ */
/*
* FAAC - Freeware Advanced Audio Coder
* Copyright (C) 2001 Menno Bakker
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: faaccfg.h,v 1.3 2004/07/04 12:12:05 corrados Exp $
*/
#ifndef _FAACCFG_H_
#define _FAACCFG_H_
#define FAAC_CFG_VERSION 104
/* MPEG ID's */
#define MPEG2 1
#define MPEG4 0
/* AAC object types */
#define MAIN 1
#define LOW 2
#define SSR 3
#define LTP 4
/* Input Formats */
#define FAAC_INPUT_NULL 0
#define FAAC_INPUT_16BIT 1
#define FAAC_INPUT_24BIT 2
#define FAAC_INPUT_32BIT 3
#define FAAC_INPUT_FLOAT 4
#define SHORTCTL_NORMAL 0
#define SHORTCTL_NOSHORT 1
#define SHORTCTL_NOLONG 2
#pragma pack(push, 1)
typedef struct faacEncConfiguration
{
/* config version */
int version;
/* library version */
char *name;
/* copyright string */
char *copyright;
/* MPEG version, 2 or 4 */
unsigned int mpegVersion;
/* AAC object type */
unsigned int aacObjectType;
/* Allow mid/side coding */
unsigned int allowMidside;
/* Use one of the channels as LFE channel */
unsigned int useLfe;
/* Use Temporal Noise Shaping */
unsigned int useTns;
/* bitrate / channel of AAC file */
unsigned long bitRate;
/* AAC file frequency bandwidth */
unsigned int bandWidth;
/* Quantizer quality */
unsigned long quantqual;
/* Bitstream output format (0 = Raw; 1 = ADTS) */
unsigned int outputFormat;
/* psychoacoustic model list */
psymodellist_t *psymodellist;
/* selected index in psymodellist */
unsigned int psymodelidx;
/*
PCM Sample Input Format
0 FAAC_INPUT_NULL invalid, signifies a misconfigured config
1 FAAC_INPUT_16BIT native endian 16bit
2 FAAC_INPUT_24BIT native endian 24bit in 24 bits (not implemented)
3 FAAC_INPUT_32BIT native endian 24bit in 32 bits (DEFAULT)
4 FAAC_INPUT_FLOAT 32bit floating point
*/
unsigned int inputFormat;
/* block type enforcing (SHORTCTL_NORMAL/SHORTCTL_NOSHORT/SHORTCTL_NOLONG) */
int shortctl;
/*
Channel Remapping
Default 0, 1, 2, 3 ... 63 (64 is MAX_CHANNELS in coder.h)
WAVE 4.0 2, 0, 1, 3
WAVE 5.0 2, 0, 1, 3, 4
WAVE 5.1 2, 0, 1, 4, 5, 3
AIFF 5.1 2, 0, 3, 1, 4, 5
*/
int channel_map[64];
} faacEncConfiguration, *faacEncConfigurationPtr;
#pragma pack(pop)
#endif /* _FAACCFG_H_ */
// pcmToAAC.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <stdio.h>
#include "PcmConvertAac.h"
typedef unsigned long ULONG;
typedef unsigned int UINT;
typedef unsigned char BYTE;
typedef char _TCHAR;
// unsigned long nSampleRate = 44100; // 设置输出aac采样率
// unsigned int nChannels = 2; // 设置输出aac声道数
// unsigned int nPCMBitSize = 16; // 设置输出aac单样本位数
CPcmConvertAac m_PcmConvertAac(44100, 2, 16);
int main(int argc, char* argv[])
{
#if 0
int nBytesRead = 0;
int nPCMBufferSize = 0;
unsigned char* pbPCMBuffer = NULL;
unsigned char* pbAACBuffer = NULL;
FILE* fpIn = NULL;
FILE* fpOut = NULL;
do {
fpIn = fopen("./audio48.pcm", "rb");// PCM file for input
if (fpIn == NULL) {
printf("[ERROR] Failed Read pcm.\n");
break;
}
fpOut = fopen("./audio48.aac", "wb");// AAC file for output
if (fpIn == NULL) {
printf("[ERROR] Failed write aac.\n");
break;
}
m_PcmConvertAac.init_faac_encode(&nPCMBufferSize);
printf("-----nPCMBufferSize=%d\n", nPCMBufferSize);
pbPCMBuffer = new unsigned char[nPCMBufferSize];
while (true) {
// 读入的实际字节数,最大不会超过nPCMBufferSize,一般只有读到文件尾时才不是这个值
nBytesRead = fread(pbPCMBuffer, 1, nPCMBufferSize, fpIn);
if (nBytesRead <= 0) {
break;
}
int aacSize = 0;
pbAACBuffer = m_PcmConvertAac.encode((int*)pbPCMBuffer, nBytesRead, &aacSize);
if (!pbAACBuffer || aacSize <= 0) {
printf("pbAACBuffer is NULL aacSize=%d, nBytesRead=%d\n", aacSize, nBytesRead);
}
fwrite(pbAACBuffer, 1, aacSize, fpOut);
printf("faacEncEncode returns aacSize=%d, nBytesRead=%d\n", aacSize, nBytesRead);
}
// (4) Close FAAC engine
m_PcmConvertAac.encode_destroy();
if (pbPCMBuffer) {
delete[] pbPCMBuffer;
pbPCMBuffer = NULL;
}
// if (pbAACBuffer) {
// delete[] pbAACBuffer;
// pbAACBuffer = NULL;
// }
} while (0);
if(fpIn)
fclose(fpIn);
if(fpOut)
fclose(fpOut);
return 0;
#else
ULONG nSampleRate = 441000; // 设置输出aac采样率
UINT nChannels = 2; // 设置输出aac声道数
UINT nPCMBitSize = 16; // 设置输出aac单样本位数
ULONG nInputSamples = 0;
ULONG nMaxOutputBytes = 0;
int nRet;
faacEncHandle hEncoder;
faacEncConfigurationPtr pConfiguration;
int nBytesRead;
int nPCMBufferSize;
BYTE* pbPCMBuffer;
BYTE* pbAACBuffer;
if(argc<3)
return -1;
FILE* fpIn = fopen(argv[1], "rb");// PCM file for input
if (fpIn == NULL) {
printf("[ERROR] Failed Read pcm.\n");
return -1;
}
FILE* fpOut = fopen(argv[2], "wb");// AAC file for output
if (fpIn == NULL) {
printf("[ERROR] Failed write aac.\n");
return -1;
}
char* verId=NULL;
char* copyRight=NULL;
(void)faacEncGetVersion(&verId, &copyRight);
printf("faac v%s\n%s\n", verId, copyRight);
// (1) Open FAAC engine
hEncoder = faacEncOpen(nSampleRate, nChannels, &nInputSamples, &nMaxOutputBytes);
if (hEncoder == NULL)
{
printf("[ERROR] Failed to call faacEncOpen()\n");
return -1;
}
nPCMBufferSize = nInputSamples * nPCMBitSize / 8;
printf("--nInputSamples=%d--nPCMBitSize=%d-----nPCMBufferSize=%d ,nMaxOutputBytes=%d\n", nInputSamples, nPCMBitSize, nPCMBufferSize, nMaxOutputBytes);
//getchar();
pbPCMBuffer = new BYTE[nPCMBufferSize];
pbAACBuffer = new BYTE[nMaxOutputBytes];
// (2.1) Get current encoding configuration
pConfiguration = faacEncGetCurrentConfiguration(hEncoder);
//设置编码配置信息
/* PCM Sample Input Format
0 FAAC_INPUT_NULL invalid, signifies a misconfigured config
1 FAAC_INPUT_16BIT native endian 16bit
2 FAAC_INPUT_24BIT native endian 24bit in 24 bits (not implemented)
3 FAAC_INPUT_32BIT native endian 24bit in 32 bits (DEFAULT)
4 FAAC_INPUT_FLOAT 32bit floating point
*/
pConfiguration->inputFormat = FAAC_INPUT_16BIT;
// 0 = Raw; 1 = ADTS
pConfiguration->outputFormat = 1;
// (2.2) Set encoding configuration
nRet = faacEncSetConfiguration(hEncoder, pConfiguration);
for (int i = 0; 1; i++)
{
// 读入的实际字节数,最大不会超过nPCMBufferSize,一般只有读到文件尾时才不是这个值
nBytesRead = fread(pbPCMBuffer, 1, nPCMBufferSize, fpIn);
// 输入样本数,用实际读入字节数计算,一般只有读到文件尾时才不是nPCMBufferSize/(nPCMBitSize/8);
nInputSamples = nBytesRead / (nPCMBitSize / 8);
printf("%d: faacEncEncode nInputSamples %d\n", i, nInputSamples);
// (3) Encode
nRet = faacEncEncode(hEncoder, (int*)pbPCMBuffer/*inBuf*/, nInputSamples, pbAACBuffer/*outBuf*/, nMaxOutputBytes);
fwrite(pbAACBuffer, 1, nRet/*aacSize*/, fpOut);
printf("%d: faacEncEncode returns %d\n", i, nRet);
if (nBytesRead <= 0)
{
break;
}
}
// (4) Close FAAC engine
nRet = faacEncClose(hEncoder);
delete[] pbPCMBuffer;
delete[] pbAACBuffer;
fclose(fpIn);
fclose(fpOut);
//getchar();
return 0;
#endif
}
#pragma once
#ifndef _PCMTOAAC_H_
#define _PCMTOAAC_H_
#endif /* _PCMTOAAC_H_ */
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{C476BAC1-30E1-43D3-B908-A46406FDE579}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>pcmToAAC</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)bin\</OutDir>
<IntDir>$(SolutionDir)obj\pcmToAAC\$(Platform)_$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)bin\</OutDir>
<IntDir>$(SolutionDir)obj\pcmToAAC\$(Platform)_$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\</OutDir>
<IntDir>$(SolutionDir)obj\pcmToAAC\$(Platform)_$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\</OutDir>
<IntDir>$(SolutionDir)obj\pcmToAAC\$(Platform)_$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>../include;</AdditionalIncludeDirectories>
<AssemblerListingLocation>$(SolutionDir)obj\pcmToAAC\$(Platform)_$(Configuration)\</AssemblerListingLocation>
<ObjectFileName>$(SolutionDir)obj\pcmToAAC\$(Platform)_$(Configuration)\</ObjectFileName>
<PrecompiledHeaderOutputFile>$(SolutionDir)obj\pcmToAAC\$(Platform)_$(Configuration)\$(TargetName).pch</PrecompiledHeaderOutputFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libfaac.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\lib\x64_Debug</AdditionalLibraryDirectories>
<OutputFile>$(TargetPath)</OutputFile>
<ProgramDatabaseFile>..\bin\$(TargetName).pdb</ProgramDatabaseFile>
<IgnoreSpecificDefaultLibraries>LIBCMTD</IgnoreSpecificDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>../include;</AdditionalIncludeDirectories>
<AssemblerListingLocation>$(SolutionDir)obj\pcmToAAC\$(Platform)_$(Configuration)\</AssemblerListingLocation>
<ObjectFileName>$(SolutionDir)obj\pcmToAAC\$(Platform)_$(Configuration)\</ObjectFileName>
<PrecompiledHeaderOutputFile>$(SolutionDir)obj\pcmToAAC\$(Platform)_$(Configuration)\$(TargetName).pch</PrecompiledHeaderOutputFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libfaac.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\lib\Win32_Debug</AdditionalLibraryDirectories>
<OutputFile>$(TargetPath)</OutputFile>
<ProgramDatabaseFile>..\bin\$(TargetName).pdb</ProgramDatabaseFile>
<IgnoreSpecificDefaultLibraries>LIBCMTD</IgnoreSpecificDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>../include;</AdditionalIncludeDirectories>
<AssemblerListingLocation>$(SolutionDir)obj\pcmToAAC\$(Platform)_$(Configuration)\</AssemblerListingLocation>
<ObjectFileName>$(SolutionDir)obj\pcmToAAC\$(Platform)_$(Configuration)\</ObjectFileName>
<PrecompiledHeaderOutputFile>$(SolutionDir)obj\pcmToAAC\$(Platform)_$(Configuration)\$(TargetName).pch</PrecompiledHeaderOutputFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libfaac.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\lib\x64_Release</AdditionalLibraryDirectories>
<OutputFile>$(TargetPath)</OutputFile>
<ProgramDatabaseFile>..\bin\$(TargetName).pdb</ProgramDatabaseFile>
<IgnoreSpecificDefaultLibraries>LIBCMT</IgnoreSpecificDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>../include;</AdditionalIncludeDirectories>
<AssemblerListingLocation>$(SolutionDir)obj\pcmToAAC\$(Platform)_$(Configuration)\</AssemblerListingLocation>
<ObjectFileName>$(SolutionDir)obj\pcmToAAC\$(Platform)_$(Configuration)\</ObjectFileName>
<PrecompiledHeaderOutputFile>$(SolutionDir)obj\pcmToAAC\$(Platform)_$(Configuration)\$(TargetName).pch</PrecompiledHeaderOutputFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libfaac.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\lib\Win32_Release</AdditionalLibraryDirectories>
<OutputFile>$(TargetPath)</OutputFile>
<ProgramDatabaseFile>..\bin\$(TargetName).pdb</ProgramDatabaseFile>
<IgnoreSpecificDefaultLibraries>LIBCMT</IgnoreSpecificDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="AacEnc.h" />
<ClInclude Include="AacEncListener.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="AacEnc.cpp" />
<ClCompile Include="Demo.cpp" />
<ClCompile Include="AacEncListener.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Demo.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="AacEnc.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="AacEncListener.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="AacEnc.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="AacEncListener.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerWorkingDirectory>..\bin</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>./CarelessWhisper-48.pcm ./out.aac</LocalDebuggerCommandArguments>
<LocalDebuggerCommand>$(TargetPath)</LocalDebuggerCommand>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerWorkingDirectory>..\bin</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>./Faded_16bit_Stereo_48K.pcm ./out.aac</LocalDebuggerCommandArguments>
<LocalDebuggerCommand>$(TargetPath)</LocalDebuggerCommand>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerWorkingDirectory>..\bin</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>./Faded_16bit_Stereo_48K.pcm ./out.aac</LocalDebuggerCommandArguments>
<LocalDebuggerCommand>$(TargetPath)</LocalDebuggerCommand>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerWorkingDirectory>..\bin</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>./Faded_16bit_Stereo_48K.pcm ./out.aac</LocalDebuggerCommandArguments>
<LocalDebuggerCommand>$(TargetPath)</LocalDebuggerCommand>
</PropertyGroup>
</Project>
\ No newline at end of file
// stdafx.cpp : 只包括标准包含文件的源文件
// pcmToAAC.pch 将作为预编译头
// stdafx.obj 将包含预编译类型信息
#include "stdafx.h"
// TODO: 在 STDAFX.H 中引用任何所需的附加头文件,
//而不是在此文件中引用
// stdafx.h : 标准系统包含文件的包含文件,
// 或是经常使用但不常更改的
// 特定于项目的包含文件
//
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
// TODO: 在此处引用程序需要的其他头文件
#pragma once
// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。
// 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将
// 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。
#include <SDKDDKVer.h>
库:libfaac
版本:v1.28
下载地址:http://www.audiocoding.com/
注意:libfaac将pcm转aac,编码faacEncEncode的输入采样InputSamples,需满足2048字节,否则编码失败。
CAacEnc::Encode处理大于或小于2048字节的兼容。
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment