📄 sbrhuff.c
字号:
* Outputs: dequantized env scalefactors for left channel (before decoupling)
* dequantized env scalefactors for right channel (if coupling off)
* or raw decoded env scalefactors for right channel (if coupling on)
*
* Return: none
**************************************************************************************/
void DecodeSBREnvelope(BitStreamInfo *bsi, PSInfoSBR *psi, SBRGrid *sbrGrid, SBRFreq *sbrFreq, SBRChan *sbrChan, int ch)
{
int huffIndexTime, huffIndexFreq, env, envStartBits, band, nBands, sf, lastEnv;
int freqRes, freqResPrev, dShift, i;
if (psi->couplingFlag && ch) {
dShift = 1;
if (sbrGrid->ampResFrame) {
huffIndexTime = HuffTabSBR_tEnv30b;
huffIndexFreq = HuffTabSBR_fEnv30b;
envStartBits = 5;
} else {
huffIndexTime = HuffTabSBR_tEnv15b;
huffIndexFreq = HuffTabSBR_fEnv15b;
envStartBits = 6;
}
} else {
dShift = 0;
if (sbrGrid->ampResFrame) {
huffIndexTime = HuffTabSBR_tEnv30;
huffIndexFreq = HuffTabSBR_fEnv30;
envStartBits = 6;
} else {
huffIndexTime = HuffTabSBR_tEnv15;
huffIndexFreq = HuffTabSBR_fEnv15;
envStartBits = 7;
}
}
/* range of envDataQuant[] = [0, 127] (see comments in DequantizeEnvelope() for reference) */
for (env = 0; env < sbrGrid->numEnv; env++) {
nBands = (sbrGrid->freqRes[env] ? sbrFreq->nHigh : sbrFreq->nLow);
freqRes = (sbrGrid->freqRes[env]);
freqResPrev = (env == 0 ? sbrGrid->freqResPrev : sbrGrid->freqRes[env-1]);
lastEnv = (env == 0 ? sbrGrid->numEnvPrev-1 : env-1);
if (lastEnv < 0)
lastEnv = 0; /* first frame */
ASSERT(nBands <= MAX_QMF_BANDS);
if (sbrChan->deltaFlagEnv[env] == 0) {
/* delta coding in freq */
sf = GetBits(bsi, envStartBits) << dShift;
sbrChan->envDataQuant[env][0] = sf;
for (band = 1; band < nBands; band++) {
sf = DecodeOneSymbol(bsi, huffIndexFreq) << dShift;
sbrChan->envDataQuant[env][band] = sf + sbrChan->envDataQuant[env][band-1];
}
} else if (freqRes == freqResPrev) {
/* delta coding in time - same freq resolution for both frames */
for (band = 0; band < nBands; band++) {
sf = DecodeOneSymbol(bsi, huffIndexTime) << dShift;
sbrChan->envDataQuant[env][band] = sf + sbrChan->envDataQuant[lastEnv][band];
}
} else if (freqRes == 0 && freqResPrev == 1) {
/* delta coding in time - low freq resolution for new frame, high freq resolution for old frame */
for (band = 0; band < nBands; band++) {
sf = DecodeOneSymbol(bsi, huffIndexTime) << dShift;
sbrChan->envDataQuant[env][band] = sf;
for (i = 0; i < sbrFreq->nHigh; i++) {
if (sbrFreq->freqHigh[i] == sbrFreq->freqLow[band]) {
sbrChan->envDataQuant[env][band] += sbrChan->envDataQuant[lastEnv][i];
break;
}
}
}
} else if (freqRes == 1 && freqResPrev == 0) {
/* delta coding in time - high freq resolution for new frame, low freq resolution for old frame */
for (band = 0; band < nBands; band++) {
sf = DecodeOneSymbol(bsi, huffIndexTime) << dShift;
sbrChan->envDataQuant[env][band] = sf;
for (i = 0; i < sbrFreq->nLow; i++) {
if (sbrFreq->freqLow[i] <= sbrFreq->freqHigh[band] && sbrFreq->freqHigh[band] < sbrFreq->freqLow[i+1] ) {
sbrChan->envDataQuant[env][band] += sbrChan->envDataQuant[lastEnv][i];
break;
}
}
}
}
/* skip coupling channel */
if (ch != 1 || psi->couplingFlag != 1)
psi->envDataDequantScale[ch][env] = DequantizeEnvelope(nBands, sbrGrid->ampResFrame, sbrChan->envDataQuant[env], psi->envDataDequant[ch][env]);
}
sbrGrid->numEnvPrev = sbrGrid->numEnv;
sbrGrid->freqResPrev = sbrGrid->freqRes[sbrGrid->numEnv-1];
}
/**************************************************************************************
* Function: DecodeSBRNoise
*
* Description: decode delta Huffman coded noise scalefactors from bitstream
*
* Inputs: BitStreamInfo struct pointing to start of noise data
* initialized PSInfoSBR struct
* initialized SBRGrid struct for this channel
* initialized SBRFreq struct for this SCE/CPE block
* initialized SBRChan struct for this channel
* index of current channel (0 for SCE, 0 or 1 for CPE)
*
* Outputs: dequantized noise scalefactors for left channel (before decoupling)
* dequantized noise scalefactors for right channel (if coupling off)
* or raw decoded noise scalefactors for right channel (if coupling on)
*
* Return: none
**************************************************************************************/
void DecodeSBRNoise(BitStreamInfo *bsi, PSInfoSBR *psi, SBRGrid *sbrGrid, SBRFreq *sbrFreq, SBRChan *sbrChan, int ch)
{
int huffIndexTime, huffIndexFreq, noiseFloor, band, dShift, sf, lastNoiseFloor;
if (psi->couplingFlag && ch) {
dShift = 1;
huffIndexTime = HuffTabSBR_tNoise30b;
huffIndexFreq = HuffTabSBR_fNoise30b;
} else {
dShift = 0;
huffIndexTime = HuffTabSBR_tNoise30;
huffIndexFreq = HuffTabSBR_fNoise30;
}
for (noiseFloor = 0; noiseFloor < sbrGrid->numNoiseFloors; noiseFloor++) {
lastNoiseFloor = (noiseFloor == 0 ? sbrGrid->numNoiseFloorsPrev-1 : noiseFloor-1);
if (lastNoiseFloor < 0)
lastNoiseFloor = 0; /* first frame */
ASSERT(sbrFreq->numNoiseFloorBands <= MAX_QMF_BANDS);
if (sbrChan->deltaFlagNoise[noiseFloor] == 0) {
/* delta coding in freq */
sbrChan->noiseDataQuant[noiseFloor][0] = GetBits(bsi, 5) << dShift;
for (band = 1; band < sbrFreq->numNoiseFloorBands; band++) {
sf = DecodeOneSymbol(bsi, huffIndexFreq) << dShift;
sbrChan->noiseDataQuant[noiseFloor][band] = sf + sbrChan->noiseDataQuant[noiseFloor][band-1];
}
} else {
/* delta coding in time */
for (band = 0; band < sbrFreq->numNoiseFloorBands; band++) {
sf = DecodeOneSymbol(bsi, huffIndexTime) << dShift;
sbrChan->noiseDataQuant[noiseFloor][band] = sf + sbrChan->noiseDataQuant[lastNoiseFloor][band];
}
}
/* skip coupling channel */
if (ch != 1 || psi->couplingFlag != 1)
DequantizeNoise(sbrFreq->numNoiseFloorBands, sbrChan->noiseDataQuant[noiseFloor], psi->noiseDataDequant[ch][noiseFloor]);
}
sbrGrid->numNoiseFloorsPrev = sbrGrid->numNoiseFloors;
}
/* dqTabCouple[i] = 2 / (1 + 2^(12 - i)), format = Q30 */
static const int dqTabCouple[25] = {
0x0007ff80, 0x000ffe00, 0x001ff802, 0x003fe010, 0x007f8080, 0x00fe03f8, 0x01f81f82, 0x03e0f83e,
0x07878788, 0x0e38e38e, 0x1999999a, 0x2aaaaaab, 0x40000000, 0x55555555, 0x66666666, 0x71c71c72,
0x78787878, 0x7c1f07c2, 0x7e07e07e, 0x7f01fc08, 0x7f807f80, 0x7fc01ff0, 0x7fe007fe, 0x7ff00200,
0x7ff80080,
};
/**************************************************************************************
* Function: UncoupleSBREnvelope
*
* Description: scale dequantized envelope scalefactors according to channel
* coupling rules
*
* Inputs: initialized PSInfoSBR struct including
* dequantized envelope data for left channel
* initialized SBRGrid struct for this channel
* initialized SBRFreq struct for this SCE/CPE block
* initialized SBRChan struct for right channel including
* quantized envelope scalefactors
*
* Outputs: dequantized envelope data for left channel (after decoupling)
* dequantized envelope data for right channel (after decoupling)
*
* Return: none
**************************************************************************************/
void UncoupleSBREnvelope(PSInfoSBR *psi, SBRGrid *sbrGrid, SBRFreq *sbrFreq, SBRChan *sbrChanR)
{
int env, band, nBands, scalei, E_1;
scalei = (sbrGrid->ampResFrame ? 0 : 1);
for (env = 0; env < sbrGrid->numEnv; env++) {
nBands = (sbrGrid->freqRes[env] ? sbrFreq->nHigh : sbrFreq->nLow);
psi->envDataDequantScale[1][env] = psi->envDataDequantScale[0][env]; /* same scalefactor for L and R */
for (band = 0; band < nBands; band++) {
/* clip E_1 to [0, 24] (scalefactors approach 0 or 2) */
E_1 = sbrChanR->envDataQuant[env][band] >> scalei;
if (E_1 < 0) E_1 = 0;
if (E_1 > 24) E_1 = 24;
/* envDataDequant[0] has 1 GB, so << by 2 is okay */
psi->envDataDequant[1][env][band] = MULSHIFT32(psi->envDataDequant[0][env][band], dqTabCouple[24 - E_1]) << 2;
psi->envDataDequant[0][env][band] = MULSHIFT32(psi->envDataDequant[0][env][band], dqTabCouple[E_1]) << 2;
}
}
}
/**************************************************************************************
* Function: UncoupleSBRNoise
*
* Description: scale dequantized noise floor scalefactors according to channel
* coupling rules
*
* Inputs: initialized PSInfoSBR struct including
* dequantized noise data for left channel
* initialized SBRGrid struct for this channel
* initialized SBRFreq struct for this SCE/CPE block
* initialized SBRChan struct for this channel including
* quantized noise scalefactors
*
* Outputs: dequantized noise data for left channel (after decoupling)
* dequantized noise data for right channel (after decoupling)
*
* Return: none
**************************************************************************************/
void UncoupleSBRNoise(PSInfoSBR *psi, SBRGrid *sbrGrid, SBRFreq *sbrFreq, SBRChan *sbrChanR)
{
int noiseFloor, band, Q_1;
for (noiseFloor = 0; noiseFloor < sbrGrid->numNoiseFloors; noiseFloor++) {
for (band = 0; band < sbrFreq->numNoiseFloorBands; band++) {
/* Q_1 should be in range [0, 24] according to 4.6.18.3.6, but check to make sure */
Q_1 = sbrChanR->noiseDataQuant[noiseFloor][band];
if (Q_1 < 0) Q_1 = 0;
if (Q_1 > 24) Q_1 = 24;
/* noiseDataDequant[0] has 1 GB, so << by 2 is okay */
psi->noiseDataDequant[1][noiseFloor][band] = MULSHIFT32(psi->noiseDataDequant[0][noiseFloor][band], dqTabCouple[24 - Q_1]) << 2;
psi->noiseDataDequant[0][noiseFloor][band] = MULSHIFT32(psi->noiseDataDequant[0][noiseFloor][band], dqTabCouple[Q_1]) << 2;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -