forked from EasyDarwin/EasyAACEncoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPcmToAac.cpp
More file actions
77 lines (58 loc) · 1.93 KB
/
Copy pathPcmToAac.cpp
File metadata and controls
77 lines (58 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "PcmToAac.h"
#include "outDebug.h"
PcmToAac::PcmToAac(void)
{
m_nInputSamples=0;
m_nMaxOutputBytes=0;
m_nPCMBitSize = 16;
}
PcmToAac::~PcmToAac(void)
{
if (NULL != hEncoder)
{
/*Close FAAC engine*/
faacEncClose(hEncoder);
}
}
bool PcmToAac::Init(InAudioInfo* info)
{
unsigned int objectType = LOW;
unsigned int mpegVersion = MPEG2;
static unsigned int useTns = 0; //#define DEFAULT_TNS 0
//TODO: config this
unsigned int nChannels = /*1*/info->Channel();
m_nPCMBitSize = /*16*/ info->PCMBitSize();
unsigned long nInputSamples = 0;
unsigned long nSampleRate = /*8000*/info->Samplerate();
unsigned long nMaxOutputBytes = 0;
/*open FAAC engine*/
hEncoder = faacEncOpen(nSampleRate, nChannels, &nInputSamples, &nMaxOutputBytes);
if (hEncoder == NULL)
{
if(AAC_DEBUG) printf("%s:[%d] failed to call faacEncOpen !\n", __FUNCTION__, __LINE__);
//return -1;
return false;
}
m_nInputSamples = nInputSamples;
m_nMaxOutputBytes = nMaxOutputBytes;
/*get current encoding configuration*/
pConfiguration = faacEncGetCurrentConfiguration(hEncoder);
pConfiguration->inputFormat = FAAC_INPUT_16BIT;
/*0 - raw; 1 - ADTS*/
pConfiguration->outputFormat = 1;
pConfiguration->useTns = useTns;
pConfiguration->aacObjectType = objectType;
pConfiguration->mpegVersion = mpegVersion;
/*set encoding configuretion*/
faacEncSetConfiguration(hEncoder, pConfiguration);
return true;
}
int PcmToAac::Encode(int32_t * pbPCMBuffer, unsigned int nPCMBufferSize, unsigned char * pbAACBuffer, unsigned int nMaxOutputBytes)
{
unsigned int nPCMBitSize = GetPCMBitSize();
unsigned int nInputSamples = (nPCMBufferSize / (nPCMBitSize / 8));
if(AAC_DEBUG) printf("%s:[%d] G711A -> PCM faacEncEncode....\n", __FUNCTION__, __LINE__);
int nRet = faacEncEncode(hEncoder, (int*) pbPCMBuffer, nInputSamples, pbAACBuffer, nMaxOutputBytes);
if(AAC_DEBUG) printf("%s:[%d] G711A -> PCM faacEncEncode\n", __FUNCTION__, __LINE__);
return nRet;
}