📄 frame.c
字号:
hEncoder->overlapBuff[channel],
MOVERLAPPED);
if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
for (k = 0; k < 8; k++) {
specFilter(hEncoder->freqBuff[channel]+k*BLOCK_LEN_SHORT,
sampleRate, bandWidth, BLOCK_LEN_SHORT);
}
} else {
specFilter(hEncoder->freqBuff[channel], sampleRate,
bandWidth, BLOCK_LEN_LONG);
}
}
/* TMP:建立sfb补偿表和其他的数据*/
for (channel = 0; channel < numChannels; channel++) {
channelInfo[channel].msInfo.is_present = 0;
if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
coderInfo[channel].max_sfb = hEncoder->srInfo->num_cb_short;
coderInfo[channel].nr_of_sfb = hEncoder->srInfo->num_cb_short;
coderInfo[channel].num_window_groups = 1;
coderInfo[channel].window_group_length[0] = 8;
coderInfo[channel].window_group_length[1] = 0;
coderInfo[channel].window_group_length[2] = 0;
coderInfo[channel].window_group_length[3] = 0;
coderInfo[channel].window_group_length[4] = 0;
coderInfo[channel].window_group_length[5] = 0;
coderInfo[channel].window_group_length[6] = 0;
coderInfo[channel].window_group_length[7] = 0;
offset = 0;
for (sb = 0; sb < coderInfo[channel].nr_of_sfb; sb++) {
coderInfo[channel].sfb_offset[sb] = offset;
offset += hEncoder->srInfo->cb_width_short[sb];
}
coderInfo[channel].sfb_offset[coderInfo[channel].nr_of_sfb] = offset;
} else {
coderInfo[channel].max_sfb = hEncoder->srInfo->num_cb_long;
coderInfo[channel].nr_of_sfb = hEncoder->srInfo->num_cb_long;
coderInfo[channel].num_window_groups = 1;
coderInfo[channel].window_group_length[0] = 1;
offset = 0;
for (sb = 0; sb < coderInfo[channel].nr_of_sfb; sb++) {
coderInfo[channel].sfb_offset[sb] = offset;
offset += hEncoder->srInfo->cb_width_long[sb];
}
coderInfo[channel].sfb_offset[coderInfo[channel].nr_of_sfb] = offset;
}
}
/* 完成TNS分析并进行滤波*/
for (channel = 0; channel < numChannels; channel++) {
if ((!channelInfo[channel].lfe) && (useTns)) {
TnsEncode(&(coderInfo[channel].tnsInfo),
coderInfo[channel].max_sfb,
coderInfo[channel].max_sfb,
coderInfo[channel].block_type,
coderInfo[channel].sfb_offset,
hEncoder->freqBuff[channel]);
} else {
coderInfo[channel].tnsInfo.tnsDataPresent = 0; /* 对于LFE不应用TNS */
}
}
for(channel = 0; channel < numChannels; channel++)
{
if((coderInfo[channel].tnsInfo.tnsDataPresent != 0) && (useTns))
tnsInfo_for_LTP = &(coderInfo[channel].tnsInfo);
else
tnsInfo_for_LTP = NULL;
if(channelInfo[channel].present && (!channelInfo[channel].lfe) &&
(coderInfo[channel].block_type != ONLY_SHORT_WINDOW) &&
(mpegVersion == MPEG4) && (aacObjectType == LTP))
{
LtpEncode(hEncoder,
&coderInfo[channel],
&(coderInfo[channel].ltpInfo),
tnsInfo_for_LTP,
hEncoder->freqBuff[channel],
hEncoder->ltpTimeBuff[channel]);
} else {
coderInfo[channel].ltpInfo.global_pred_flag = 0;
}
}
for(channel = 0; channel < numChannels; channel++)
{
if ((aacObjectType == MAIN) && (!channelInfo[channel].lfe)) {
int numPredBands = min(coderInfo[channel].max_pred_sfb, coderInfo[channel].nr_of_sfb);
PredCalcPrediction(hEncoder->freqBuff[channel],
coderInfo[channel].requantFreq,
coderInfo[channel].block_type,
numPredBands,
(coderInfo[channel].block_type==ONLY_SHORT_WINDOW)?
hEncoder->srInfo->cb_width_short:hEncoder->srInfo->cb_width_long,
coderInfo,
channelInfo,
channel);
} else {
coderInfo[channel].pred_global_flag = 0;
}
}
MSEncode(coderInfo, channelInfo, hEncoder->freqBuff, numChannels, allowMidside);
/* 进行量化并完成信号的编码*/
bitsToUse = (int)(bitRate*FRAME_LEN/sampleRate+0.5);
for (channel = 0; channel < numChannels; channel++) {
if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
AACQuantize(&coderInfo[channel], &hEncoder->psyInfo[channel],
&channelInfo[channel], hEncoder->srInfo->cb_width_short,
hEncoder->srInfo->num_cb_short, hEncoder->freqBuff[channel], bitsToUse);
} else {
AACQuantize(&coderInfo[channel], &hEncoder->psyInfo[channel],
&channelInfo[channel], hEncoder->srInfo->cb_width_long,
hEncoder->srInfo->num_cb_long, hEncoder->freqBuff[channel], bitsToUse);
}
}
MSReconstruct(coderInfo, channelInfo, numChannels);
for (channel = 0; channel < numChannels; channel++)
{
/* 如果是短窗滤波,信号重建不需要应用预测*/
if ((coderInfo[channel].block_type == ONLY_SHORT_WINDOW)) {
int sind;
for (sind = 0; sind < 1024; sind++) {
coderInfo[channel].requantFreq[sind] = 0.0;
}
} else {
if((coderInfo[channel].tnsInfo.tnsDataPresent != 0) && (useTns))
tnsDecInfo = &(coderInfo[channel].tnsInfo);
else
tnsDecInfo = NULL;
if ((!channelInfo[channel].lfe) && (aacObjectType == LTP))
{ /* 对于LFE信道不需要应用重建技术*/
LtpReconstruct(&coderInfo[channel], &(coderInfo[channel].ltpInfo),
coderInfo[channel].requantFreq);
if(tnsDecInfo != NULL)
TnsDecodeFilterOnly(&(coderInfo[channel].tnsInfo), coderInfo[channel].nr_of_sfb,
coderInfo[channel].max_sfb, coderInfo[channel].block_type,
coderInfo[channel].sfb_offset, coderInfo[channel].requantFreq);
IFilterBank(hEncoder, &coderInfo[channel],
coderInfo[channel].requantFreq,
coderInfo[channel].ltpInfo.time_buffer,
coderInfo[channel].ltpInfo.ltp_overlap_buffer,
MOVERLAPPED);
LtpUpdate(&(coderInfo[channel].ltpInfo),
coderInfo[channel].ltpInfo.time_buffer,
coderInfo[channel].ltpInfo.ltp_overlap_buffer,
BLOCK_LEN_LONG);
}
}
}
/*写入AAC比特流 */
bitStream = OpenBitStream(bufferSize, outputBuffer);
WriteBitstream(hEncoder, coderInfo, channelInfo, bitStream, numChannels);
/*关闭比特流,并返回实际写入的字节数目*/
frameBytes = CloseBitStream(bitStream);
#ifdef _DEBUG
printf("%4d %4d\n", hEncoder->frameNum-1, frameBytes);
#endif
return frameBytes;
}
/* Scalefactorband data table */
static SR_INFO srInfo[12+1] =
{
{ 96000, 41, 12,
{
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
8, 8, 8, 8, 8, 12, 12, 12, 12, 12, 16, 16, 24, 28,
36, 44, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
},{
4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 36
}
}, { 88200, 41, 12,
{
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
8, 8, 8, 8, 8, 12, 12, 12, 12, 12, 16, 16, 24, 28,
36, 44, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
},{
4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 36
}
}, { 64000, 47, 12,
{
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
8, 8, 8, 8, 12, 12, 12, 16, 16, 16, 20, 24, 24, 28,
36, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
40, 40, 40, 40, 40
},{
4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 32
}
}, { 48000, 49, 14,
{
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 96
}, {
4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16
}
}, { 44100, 49, 14,
{
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 96
}, {
4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16
}
}, { 32000, 51, 14,
{
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8,
8, 8, 8, 12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28,
28, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32
},{
4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16
}
}, { 24000, 47, 15,
{
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 12, 12, 12, 12, 16, 16, 16, 20, 20, 24, 24, 28, 28, 32,
36, 36, 40, 44, 48, 52, 52, 64, 64, 64, 64, 64
}, {
4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 20
}
}, { 22050, 47, 15,
{
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 12, 12, 12, 12, 16, 16, 16, 20, 20, 24, 24, 28, 28, 32,
36, 36, 40, 44, 48, 52, 52, 64, 64, 64, 64, 64
}, {
4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 20
}
}, { 16000, 43, 15,
{
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12,
12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24,
24, 28, 28, 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64, 64
}, {
4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 20
}
}, { 12000, 43, 15,
{
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12,
12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24,
24, 28, 28, 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64, 64
}, {
4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 20
}
}, { 11025, 43, 15,
{
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12,
12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24,
24, 28, 28, 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64, 64
}, {
4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 20
}
}, { 8000, 40, 15,
{
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 16,
16, 16, 16, 16, 16, 16, 20, 20, 20, 20, 24, 24, 24, 28,
28, 32, 36, 36, 40, 44, 48, 52, 56, 60, 64, 80
}, {
4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 12, 16, 20, 20
}
},
{ -1 }
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -