📄 noiseless.c
字号:
* Outputs: updated PulseInfo struct
*
* Return: none
**************************************************************************************/
static void DecodePulseInfo(BitStreamInfo *bsi, PulseInfo *pi)
{
int i;
pi->numPulse = GetBits(bsi, 2) + 1; /* add 1 here */
pi->startSFB = GetBits(bsi, 6);
for (i = 0; i < pi->numPulse; i++) {
pi->offset[i] = GetBits(bsi, 5);
pi->amp[i] = GetBits(bsi, 4);
}
}
/**************************************************************************************
* Function: DecodeTNSInfo
*
* Description: decode TNS filter information
*
* Inputs: BitStreamInfo struct pointing to start of TNS info
* (14496-3, table 4.4.27)
* window sequence (short or long blocks)
*
* Outputs: updated TNSInfo struct
* buffer of decoded (signed) TNS filter coefficients
*
* Return: none
**************************************************************************************/
static void DecodeTNSInfo(BitStreamInfo *bsi, int winSequence, TNSInfo *ti, signed char *tnsCoef)
{
int i, w, f, coefBits, compress;
signed char c, s, n;
signed char sgnMask[3] = { 0x02, 0x04, 0x08};
signed char negMask[3] = {~0x03, ~0x07, ~0x0f};
unsigned char *filtLength, *filtOrder, *filtDir;
filtLength = ti->length;
filtOrder = ti->order;
filtDir = ti->dir;
if (winSequence == 2) {
/* short blocks */
for (w = 0; w < NWINDOWS_SHORT; w++) {
ti->numFilt[w] = GetBits(bsi, 1);
if (ti->numFilt[w]) {
ti->coefRes[w] = GetBits(bsi, 1) + 3;
*filtLength = GetBits(bsi, 4);
*filtOrder = GetBits(bsi, 3);
if (*filtOrder) {
*filtDir++ = GetBits(bsi, 1);
compress = GetBits(bsi, 1);
coefBits = (int)ti->coefRes[w] - compress; /* 2, 3, or 4 */
s = sgnMask[coefBits - 2];
n = negMask[coefBits - 2];
for (i = 0; i < *filtOrder; i++) {
c = GetBits(bsi, coefBits);
if (c & s) c |= n;
*tnsCoef++ = c;
}
}
filtLength++;
filtOrder++;
}
}
} else {
/* long blocks */
ti->numFilt[0] = GetBits(bsi, 2);
if (ti->numFilt[0])
ti->coefRes[0] = GetBits(bsi, 1) + 3;
for (f = 0; f < ti->numFilt[0]; f++) {
*filtLength = GetBits(bsi, 6);
*filtOrder = GetBits(bsi, 5);
if (*filtOrder) {
*filtDir++ = GetBits(bsi, 1);
compress = GetBits(bsi, 1);
coefBits = (int)ti->coefRes[0] - compress; /* 2, 3, or 4 */
s = sgnMask[coefBits - 2];
n = negMask[coefBits - 2];
for (i = 0; i < *filtOrder; i++) {
c = GetBits(bsi, coefBits);
if (c & s) c |= n;
*tnsCoef++ = c;
}
}
filtLength++;
filtOrder++;
}
}
}
/* bitstream field lengths for gain control data:
* gainBits[winSequence][0] = maxWindow (how many gain windows there are)
* gainBits[winSequence][1] = locBitsZero (bits for alocCode if window == 0)
* gainBits[winSequence][2] = locBits (bits for alocCode if window != 0)
*/
static const unsigned char gainBits[4][3] = {
{1, 5, 5}, /* long */
{2, 4, 2}, /* start */
{8, 2, 2}, /* short */
{2, 4, 5}, /* stop */
};
/**************************************************************************************
* Function: DecodeGainControlInfo
*
* Description: decode gain control information (SSR profile only)
*
* Inputs: BitStreamInfo struct pointing to start of gain control info
* (14496-3, table 4.4.12)
* window sequence (short or long blocks)
*
* Outputs: updated GainControlInfo struct
*
* Return: none
**************************************************************************************/
static void DecodeGainControlInfo(BitStreamInfo *bsi, int winSequence, GainControlInfo *gi)
{
int bd, wd, ad;
int locBits, locBitsZero, maxWin;
gi->maxBand = GetBits(bsi, 2);
maxWin = (int)gainBits[winSequence][0];
locBitsZero = (int)gainBits[winSequence][1];
locBits = (int)gainBits[winSequence][2];
for (bd = 1; bd <= gi->maxBand; bd++) {
for (wd = 0; wd < maxWin; wd++) {
gi->adjNum[bd][wd] = GetBits(bsi, 3);
for (ad = 0; ad < gi->adjNum[bd][wd]; ad++) {
gi->alevCode[bd][wd][ad] = GetBits(bsi, 4);
gi->alocCode[bd][wd][ad] = GetBits(bsi, (wd == 0 ? locBitsZero : locBits));
}
}
}
}
/**************************************************************************************
* Function: DecodeICS
*
* Description: decode individual channel stream
*
* Inputs: platform specific info struct
* BitStreamInfo struct pointing to start of individual channel stream
* (14496-3, table 4.4.24)
* index of current channel
*
* Outputs: updated section data, scale factor data, pulse data, TNS data,
* and gain control data
*
* Return: none
**************************************************************************************/
static void DecodeICS(PSInfoBase *psi, BitStreamInfo *bsi, int ch)
{
int globalGain;
ICSInfo *icsInfo;
PulseInfo *pi;
TNSInfo *ti;
GainControlInfo *gi;
icsInfo = (ch == 1 && psi->commonWin == 1) ? &(psi->icsInfo[0]) : &(psi->icsInfo[ch]);
globalGain = GetBits(bsi, 8);
if (!psi->commonWin)
DecodeICSInfo(bsi, icsInfo, psi->sampRateIdx);
DecodeSectionData(bsi, icsInfo->winSequence, icsInfo->numWinGroup, icsInfo->maxSFB, psi->sfbCodeBook[ch]);
DecodeScaleFactors(bsi, icsInfo->numWinGroup, icsInfo->maxSFB, globalGain, psi->sfbCodeBook[ch], psi->scaleFactors[ch]);
pi = &psi->pulseInfo[ch];
pi->pulseDataPresent = GetBits(bsi, 1);
if (pi->pulseDataPresent)
DecodePulseInfo(bsi, pi);
ti = &psi->tnsInfo[ch];
ti->tnsDataPresent = GetBits(bsi, 1);
if (ti->tnsDataPresent)
DecodeTNSInfo(bsi, icsInfo->winSequence, ti, ti->coef);
gi = &psi->gainControlInfo[ch];
gi->gainControlDataPresent = GetBits(bsi, 1);
if (gi->gainControlDataPresent)
DecodeGainControlInfo(bsi, icsInfo->winSequence, gi);
}
/**************************************************************************************
* Function: DecodeNoiselessData
*
* Description: decode noiseless data (side info and transform coefficients)
*
* Inputs: valid AACDecInfo struct
* double pointer to buffer pointing to start of individual channel stream
* (14496-3, table 4.4.24)
* pointer to bit offset
* pointer to number of valid bits remaining in buf
* index of current channel
*
* Outputs: updated global gain, section data, scale factor data, pulse data,
* TNS data, gain control data, and spectral data
*
* Return: 0 if successful, error code (< 0) if error
**************************************************************************************/
int DecodeNoiselessData(AACDecInfo *aacDecInfo, unsigned char **buf, int *bitOffset, int *bitsAvail, int ch)
{
int bitsUsed;
BitStreamInfo bsi;
PSInfoBase *psi;
ICSInfo *icsInfo;
/* validate pointers */
if (!aacDecInfo || !aacDecInfo->psInfoBase)
return ERR_AAC_NULL_POINTER;
psi = (PSInfoBase *)(aacDecInfo->psInfoBase);
icsInfo = (ch == 1 && psi->commonWin == 1) ? &(psi->icsInfo[0]) : &(psi->icsInfo[ch]);
SetBitstreamPointer(&bsi, (*bitsAvail+7) >> 3, *buf);
GetBits(&bsi, *bitOffset);
DecodeICS(psi, &bsi, ch);
if (icsInfo->winSequence == 2)
DecodeSpectrumShort(psi, &bsi, ch);
else
DecodeSpectrumLong(psi, &bsi, ch);
bitsUsed = CalcBitsUsed(&bsi, *buf, *bitOffset);
*buf += ((bitsUsed + *bitOffset) >> 3);
*bitOffset = ((bitsUsed + *bitOffset) & 0x07);
*bitsAvail -= bitsUsed;
aacDecInfo->sbDeinterleaveReqd[ch] = 0;
aacDecInfo->tnsUsed |= psi->tnsInfo[ch].tnsDataPresent; /* set flag if TNS used for any channel */
return ERR_AAC_NONE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -