📄 layeriii.cpp
字号:
}
return TRUE;
}
void CLayerIII::GetScaleFact(DWORD dwCh, DWORD dwGr)
{
int nSfb, nWnd;
STR_GRINFO* pGRLOCAL = &(m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr]);
int nscaleFact = pGRLOCAL->scaleFactCompress;
int nLenLeft = slen[0][nscaleFact];
int nLenRight = slen[1][nscaleFact];
if (pGRLOCAL->wndSwitchFlag && (pGRLOCAL->nBlockType == 2)) {
if (pGRLOCAL->mixedBlockFlag)
{ // MIXED
for (nSfb = 0; nSfb < 8; nSfb++)
m_sCALEF[dwCh].l[nSfb] = GetBits(
slen[0][pGRLOCAL->scaleFactCompress]);
for (nSfb = 3; nSfb < 6; nSfb++)
for (nWnd=0; nWnd<3; nWnd++)
m_sCALEF[dwCh].s[nWnd][nSfb] = GetBits(
slen[0][pGRLOCAL->scaleFactCompress]);
for (nSfb = 6; nSfb < 12; nSfb++)
for (nWnd=0; nWnd<3; nWnd++)
m_sCALEF[dwCh].s[nWnd][nSfb] = GetBits(
slen[1][pGRLOCAL->scaleFactCompress]);
for (nSfb=12,nWnd=0; nWnd<3; nWnd++)
m_sCALEF[dwCh].s[nWnd][nSfb] = 0;
} else { // SHORT
m_sCALEF[dwCh].s[0][0] = GetBits(nLenLeft);
m_sCALEF[dwCh].s[1][0] = GetBits(nLenLeft);
m_sCALEF[dwCh].s[2][0] = GetBits(nLenLeft);
m_sCALEF[dwCh].s[0][1] = GetBits(nLenLeft);
m_sCALEF[dwCh].s[1][1] = GetBits(nLenLeft);
m_sCALEF[dwCh].s[2][1] = GetBits(nLenLeft);
m_sCALEF[dwCh].s[0][2] = GetBits(nLenLeft);
m_sCALEF[dwCh].s[1][2] = GetBits(nLenLeft);
m_sCALEF[dwCh].s[2][2] = GetBits(nLenLeft);
m_sCALEF[dwCh].s[0][3] = GetBits(nLenLeft);
m_sCALEF[dwCh].s[1][3] = GetBits(nLenLeft);
m_sCALEF[dwCh].s[2][3] = GetBits(nLenLeft);
m_sCALEF[dwCh].s[0][4] = GetBits(nLenLeft);
m_sCALEF[dwCh].s[1][4] = GetBits(nLenLeft);
m_sCALEF[dwCh].s[2][4] = GetBits(nLenLeft);
m_sCALEF[dwCh].s[0][5] = GetBits(nLenLeft);
m_sCALEF[dwCh].s[1][5] = GetBits(nLenLeft);
m_sCALEF[dwCh].s[2][5] = GetBits(nLenLeft);
m_sCALEF[dwCh].s[0][6] = GetBits(nLenRight);
m_sCALEF[dwCh].s[1][6] = GetBits(nLenRight);
m_sCALEF[dwCh].s[2][6] = GetBits(nLenRight);
m_sCALEF[dwCh].s[0][7] = GetBits(nLenRight);
m_sCALEF[dwCh].s[1][7] = GetBits(nLenRight);
m_sCALEF[dwCh].s[2][7] = GetBits(nLenRight);
m_sCALEF[dwCh].s[0][8] = GetBits(nLenRight);
m_sCALEF[dwCh].s[1][8] = GetBits(nLenRight);
m_sCALEF[dwCh].s[2][8] = GetBits(nLenRight);
m_sCALEF[dwCh].s[0][9] = GetBits(nLenRight);
m_sCALEF[dwCh].s[1][9] = GetBits(nLenRight);
m_sCALEF[dwCh].s[2][9] = GetBits(nLenRight);
m_sCALEF[dwCh].s[0][10] = GetBits(nLenRight);
m_sCALEF[dwCh].s[1][10] = GetBits(nLenRight);
m_sCALEF[dwCh].s[2][10] = GetBits(nLenRight);
m_sCALEF[dwCh].s[0][11] = GetBits(nLenRight);
m_sCALEF[dwCh].s[1][11] = GetBits(nLenRight);
m_sCALEF[dwCh].s[2][11] = GetBits(nLenRight);
m_sCALEF[dwCh].s[0][12] = 0;
m_sCALEF[dwCh].s[1][12] = 0;
m_sCALEF[dwCh].s[2][12] = 0;
} // SHORT
} else { // LONG types 0,1,3
if ((m_SIDEINF.sArrCH[dwCh].arrScfSi[0] == 0) || (dwGr == 0)) {
m_sCALEF[dwCh].l[0] = GetBits(nLenLeft);
m_sCALEF[dwCh].l[1] = GetBits(nLenLeft);
m_sCALEF[dwCh].l[2] = GetBits(nLenLeft);
m_sCALEF[dwCh].l[3] = GetBits(nLenLeft);
m_sCALEF[dwCh].l[4] = GetBits(nLenLeft);
m_sCALEF[dwCh].l[5] = GetBits(nLenLeft);
}
if ((m_SIDEINF.sArrCH[dwCh].arrScfSi[1] == 0) || (dwGr == 0)) {
m_sCALEF[dwCh].l[6] = GetBits(nLenLeft);
m_sCALEF[dwCh].l[7] = GetBits(nLenLeft);
m_sCALEF[dwCh].l[8] = GetBits(nLenLeft);
m_sCALEF[dwCh].l[9] = GetBits(nLenLeft);
m_sCALEF[dwCh].l[10] = GetBits(nLenLeft);
}
if ((m_SIDEINF.sArrCH[dwCh].arrScfSi[2] == 0) || (dwGr == 0)) {
m_sCALEF[dwCh].l[11] = GetBits(nLenRight);
m_sCALEF[dwCh].l[12] = GetBits(nLenRight);
m_sCALEF[dwCh].l[13] = GetBits(nLenRight);
m_sCALEF[dwCh].l[14] = GetBits(nLenRight);
m_sCALEF[dwCh].l[15] = GetBits(nLenRight);
}
if ((m_SIDEINF.sArrCH[dwCh].arrScfSi[3] == 0) || (dwGr == 0)) {
m_sCALEF[dwCh].l[16] = GetBits(nLenRight);
m_sCALEF[dwCh].l[17] = GetBits(nLenRight);
m_sCALEF[dwCh].l[18] = GetBits(nLenRight);
m_sCALEF[dwCh].l[19] = GetBits(nLenRight);
m_sCALEF[dwCh].l[20] = GetBits(nLenRight);
}
m_sCALEF[dwCh].l[21] = 0;
m_sCALEF[dwCh].l[22] = 0;
}
}
///////////////////////////////////////////////////////////////////////////////
//
void CLayerIII::GetLSFScaleData(DWORD dwCh, DWORD dwGr)
{
DWORD newLength[4];
DWORD scFctComp, scFctCompInt;
int nBlkType, nBlkNr;
DWORD dwExtensionMode = m_dwExtensionMode;
STR_GRINFO *pGRLOCAL = &(m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr]);
scFctComp = pGRLOCAL->scaleFactCompress;
if (pGRLOCAL->nBlockType == 2)
{
if (pGRLOCAL->mixedBlockFlag == 0)
nBlkType = 1;
else if (pGRLOCAL->mixedBlockFlag == 1)
nBlkType = 2;
else
nBlkType = 0;
} else
{
nBlkType = 0;
}
if(!(((dwExtensionMode == 1) || (dwExtensionMode == 3)) && (dwCh == 1)))
{
if(scFctComp < 400)
{
newLength[0] = (scFctComp >> 4) / 5 ;
newLength[1] = (scFctComp >> 4) % 5 ;
newLength[2] = (scFctComp & 0xF) >> 2 ;
newLength[3] = (scFctComp & 3);
m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr].preflag = 0;
nBlkNr = 0;
}
else if (scFctComp < 500)
{
newLength[0] = ((scFctComp - 400) >> 2) / 5 ;
newLength[1] = ((scFctComp - 400) >> 2) % 5 ;
newLength[2] = (scFctComp - 400 ) & 3 ;
newLength[3] = 0;
m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr].preflag = 0;
nBlkNr = 1;
}
else if (scFctComp < 512)
{
newLength[0] = (scFctComp - 500 ) / 3 ;
newLength[1] = (scFctComp - 500) % 3 ;
newLength[2] = 0;
newLength[3] = 0;
m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr].preflag = 1;
nBlkNr = 2;
}
}
if((((dwExtensionMode == 1) || (dwExtensionMode == 3)) && (dwCh == 1)))
{
scFctCompInt = scFctComp >> 1;
if (scFctCompInt < 180)
{
newLength[0] = scFctCompInt / 36 ;
newLength[1] = (scFctCompInt % 36 ) / 6 ;
newLength[2] = (scFctCompInt % 36) % 6;
newLength[3] = 0;
m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr].preflag = 0;
nBlkNr = 3;
}
else if (scFctCompInt < 244)
{
newLength[0] = ((scFctCompInt - 180 ) & 0x3F) >> 4 ;
newLength[1] = ((scFctCompInt - 180) & 0xF) >> 2 ;
newLength[2] = (scFctCompInt - 180 ) & 3 ;
newLength[3] = 0;
m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr].preflag = 0;
nBlkNr = 4;
}
else if (scFctCompInt < 255)
{
newLength[0] = (scFctCompInt - 244 ) / 3 ;
newLength[1] = (scFctCompInt - 244 ) % 3 ;
newLength[2] = 0 ;
newLength[3] = 0;
m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr].preflag = 0;
nBlkNr = 5;
}
}
ZeroMemory(m_dwScale,sizeof(m_dwScale)); // why 45, not 54?
int m = 0;
for (DWORD dw=0; dw<4;dw++)
{
for (DWORD j = 0; j < nr_of_nSfb_block[nBlkNr][nBlkType][dw];j++)
{
m_dwScale[m] = (newLength[dw] == 0) ? 0 : GetBits(newLength[dw]);
m++;
}
}
}
///////////////////////////////////////////////////////////////////////////////
//
void CLayerIII::GetLSFScaleFactor(DWORD dwCh, DWORD dwGr)
{
DWORD m = 0;
DWORD nSfb, nWnd;
STR_GRINFO *pGRLOCAL = &(m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr]);
GetLSFScaleData(dwCh, dwGr);
if (pGRLOCAL->wndSwitchFlag && (pGRLOCAL->nBlockType == 2))
{
if (pGRLOCAL->mixedBlockFlag)
{ // MIXED
for (nSfb = 0; nSfb < 8; nSfb++)
{
m_sCALEF[dwCh].l[nSfb] = m_dwScale[m];
m++;
}
for (nSfb = 3; nSfb < 12; nSfb++)
{
for (nWnd=0; nWnd<3; nWnd++)
{
m_sCALEF[dwCh].s[nWnd][nSfb] = m_dwScale[m];
m++;
}
}
for (nWnd=0; nWnd<3; nWnd++)
m_sCALEF[dwCh].s[nWnd][12] = 0;
}
else
{ // SHORT
for (nSfb = 0; nSfb < 12; nSfb++)
{
for (nWnd=0; nWnd<3; nWnd++)
{
m_sCALEF[dwCh].s[nWnd][nSfb] = m_dwScale[m];
m++;
}
}
for (nWnd=0; nWnd < 3; nWnd++)
m_sCALEF[dwCh].s[nWnd][12] = 0;
}
}
else
{ // LONG types 0,1,3
for (nSfb = 0; nSfb < 21; nSfb++)
{
m_sCALEF[dwCh].l[nSfb] = m_dwScale[m];
m++;
}
m_sCALEF[dwCh].l[21] = 0; // Jeff
m_sCALEF[dwCh].l[22] = 0;
}
}
///////////////////////////////////////////////////////////////////////////////
//
void CLayerIII::HuffmanDecode(DWORD dwCh, DWORD dwGr)
{
int x, y;
int v, w;
int part2_3_end = m_nPart2Start + m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr].p23Len;
int num_bits;
int region1Start;
int region2Start;
int mIndex;
struct sHUFDECTAB *pHfDecTab;
// Find region boundary for short block case
if ( (m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr].wndSwitchFlag) &&
(m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr].nBlockType == 2) )
{
// Region2.
region1Start = 36; // nSfb[9/3]*3=36
region2Start = 576; // No Region2 for short block case
}
else
{ // Find region boundary for long block case
region1Start = sfBandIndex[m_nFreqIdx].l[m_SIDEINF.sArrCH[dwCh].
sArrGRINF[dwGr].region0Count + 1];
region2Start = sfBandIndex[m_nFreqIdx].l[m_SIDEINF.sArrCH[dwCh].
sArrGRINF[dwGr].region0Count +
m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr].
region1Count + 2]; /* MI */
}
mIndex = 0;
// Read bigvalues area
for (int dw=0; dw < (m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr].bigVal<<1); dw+=2)
{
if (dw < (int)region1Start)
pHfDecTab = &ht[m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr].arrSelect[0]];
else if (dw < (int)region2Start)
pHfDecTab = &ht[m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr].arrSelect[1]];
else
pHfDecTab = &ht[m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr].arrSelect[2]];
HuffmanDec(pHfDecTab, &x, &y, &v, &w);
m_nArray[mIndex++] = x;
m_nArray[mIndex++] = y;
}
// Read count1 area
pHfDecTab = &ht[m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr].countTblSelect+32];
num_bits = GetReadBits();
while ((num_bits < part2_3_end) && (mIndex < 576))
{
HuffmanDec(pHfDecTab, &x, &y, &v, &w);
m_nArray[mIndex++] = v;
m_nArray[mIndex++] = w;
m_nArray[mIndex++] = x;
m_nArray[mIndex++] = y;
num_bits = GetReadBits();
}
if (num_bits > part2_3_end)
{
GoBackBits(num_bits - part2_3_end);
mIndex-=4;
}
num_bits = GetReadBits();
// Dismiss stuffing bits
if (num_bits < part2_3_end)
GetBits(part2_3_end - num_bits);
// Zero pDblOut rest
if (mIndex < 576)
m_arrNonZero[dwCh] = mIndex;
else
m_arrNonZero[dwCh] = 576;
if(mIndex < 576)
ZeroMemory(m_nArray+mIndex,(576-mIndex)*sizeof(int));
}
///////////////////////////////////////////////////////////////////////////////
//
void CLayerIII::DeqSample(double dbRectArr[32][18], DWORD dwCh, DWORD dwGr)
{
int nCountb PURE;
int nextCbBound, nBeginCb, nWidthCb;
int mIndex=0, tIndex, j;
double dblGain;
double* pDblRectArr = &dbRectArr[0][0];
STR_GRINFO *pGRLOCAL = &(m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr]);
// choose correct scalefactor band per block type, initalize boundary
if (pGRLOCAL->wndSwitchFlag && (pGRLOCAL->nBlockType == 2) )
{
if (pGRLOCAL->mixedBlockFlag)
nextCbBound=sfBandIndex[m_nFreqIdx].l[1]; // LONG blocks: 0,1,3
else
{
nWidthCb = sfBandIndex[m_nFreqIdx].s[1];
nextCbBound = (nWidthCb << 2) - nWidthCb;
nBeginCb = 0;
}
}
else
{
nextCbBound=sfBandIndex[m_nFreqIdx].l[1]; // LONG blocks: 0,1,3
}
// Compute overall (global) scaling.
dblGain = (double) pow(2.0 , (0.25 * (pGRLOCAL->glbGain - 210.0)));
for (j=0; j<m_arrNonZero[dwCh]; j++)
{
if (m_nArray[j] == 0)
{
pDblRectArr[j] = 0.0f;
}
else
{
int abv = m_nArray[j];
if (m_nArray[j] > 0)
pDblRectArr[j] = dblGain * t_43[abv];
else
pDblRectArr[j] = -dblGain * t_43[-abv];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -