layeriii.cpp

来自「完整的MP3播放器源码」· C++ 代码 · 共 2,031 行 · 第 1/5 页

CPP
2,031
字号
					} 
				} 
			}
		} 
		else 
		{ // if (pGRLOCAL->wndSwitchFlag ...
			dw		= 31;
			ss	= 17;
			sb	= 0;
			while (dw >= 0) 
			{
				if (m_cubeRo[1][dw][ss] != 0.0f) 
				{
					sb = (dw<<4) + (dw<<1) + ss;
					dw = -1;
				} 
				else 
				{
					ss--;
					if (ss < 0) 
					{
						dw--;
						ss = 17;
					}
				}
			}
			dw = 0;
			while (sfBandIndex[m_nFreqIdx].l[dw] <= sb)
				  dw++;
			nSfb	= dw;
			dw		= sfBandIndex[m_nFreqIdx].l[dw];

			for (; nSfb<21; nSfb++) 
			{
				sb =	sfBandIndex[m_nFreqIdx].l[nSfb+1] - 
							sfBandIndex[m_nFreqIdx].l[nSfb];
				for (; sb > 0; sb--) {
					dwIsPos[dw] = m_sCALEF[1].l[nSfb];
					if (dwIsPos[dw] != 7)
					   if (bLayerVers)
					   IStereoKValues(dwIsPos[dw], dwIoType, dw);
					else
						dRatio[dw] = TAN12[dwIsPos[dw]];
					dw++;
				}
			}
			nSfb = sfBandIndex[m_nFreqIdx].l[20];
			for (sb = 576 - sfBandIndex[m_nFreqIdx].l[21]; (sb > 0) && (dw<576); sb--)
			{
				dwIsPos[dw] = dwIsPos[nSfb]; // error here : dw >=576
            
				if (bLayerVers) {
					m_theKArray[0][dw] = m_theKArray[0][nSfb];
					m_theKArray[1][dw] = m_theKArray[1][nSfb];
					} else {
					dRatio[dw] = dRatio[nSfb];
				}
				dw++;
			} // if (pGRLOCAL->mixedBlockFlag)
		} // if (pGRLOCAL->wndSwitchFlag ...
	} // if (bIStereo)

	dw = 0;
	for(sb=0;sb<32;sb++)
	   for(ss=0;ss<18;ss++) 
		{
			if (dwIsPos[dw] == 7) 
			{
				if (bStereoMs) 
				{
					m_cubeLr[0][sb][ss] = (m_cubeRo[0][sb][ss]+
												m_cubeRo[1][sb][ss]) 
												* 0.707106781f;
					m_cubeLr[1][sb][ss] = (m_cubeRo[0][sb][ss]-
												m_cubeRo[1][sb][ss]) 
												* 0.707106781f;
				} 
				else 
				{
					m_cubeLr[0][sb][ss] = m_cubeRo[0][sb][ss];
					m_cubeLr[1][sb][ss] = m_cubeRo[1][sb][ss];
				}
			}
			else if (bIStereo) 
			{
        
				if (bLayerVers) 
				{
					m_cubeLr[0][sb][ss] = m_cubeRo[0][sb][ss] * 
													m_theKArray[0][dw];
					m_cubeLr[1][sb][ss] = m_cubeRo[0][sb][ss] * 
													m_theKArray[1][dw];
					} else {
					m_cubeLr[1][sb][ss] = m_cubeRo[0][sb][ss] / 
													(double) (1 + dRatio[dw]);
					m_cubeLr[0][sb][ss] = m_cubeLr[1][sb][ss] * 
													dRatio[dw];
				}
			}
			else 
			{
				TRACE("Error Stereo processing");
				ASSERT(0);
			}
		dw++;
	}

    }
    return 0;
}

///////////////////////////////////////////////////////////////////////////////
//
void CLayerIII::AntiAlias(DWORD dwCh, DWORD dwGr)
{
    int			iSb18, ss, sb18lim;
    STR_GRINFO *pGRLOCAL = &(m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr]);
    
    // 31 alias-reduction operations between each pair of sub-bands
    // with 8 butterflies between each pair
    if  (pGRLOCAL->wndSwitchFlag && 
		(pGRLOCAL->nBlockType == 2) &&
        !pGRLOCAL->mixedBlockFlag )
        return;
    
    if (pGRLOCAL->wndSwitchFlag && 
		pGRLOCAL->mixedBlockFlag &&
       (pGRLOCAL->nBlockType == 2)) 
	{
        sb18lim = 18;
    } 
	else 
	{
        sb18lim = 558;
    }
    
    for (iSb18=0; iSb18 < sb18lim; iSb18+=18) 
	{
        for (ss=0;ss<8;ss++) 
		{
            int iDx1 = iSb18 + 17 - ss;
            int iDx2 = iSb18 + 18 + ss;
            double dBu = m_dOutArr[iDx1];
            double dBd = m_dOutArr[iDx2];
            m_dOutArr[iDx1] = (dBu * cs[ss]) - (dBd * ca[ss]);
            m_dOutArr[iDx2] = (dBd * cs[ss]) + (dBu * ca[ss]);
        }
    }

}

///////////////////////////////////////////////////////////////////////////////
//
void CLayerIII::Hibrid(DWORD dwCh, DWORD dwGr)
{
        double		dOurRaw[36];
    DWORD		dwBt		PURE;	
    int			iSb18		PURE;
    double*		pdTsOut		PURE;
    double*		pdPrvBlok	PURE;
	STR_GRINFO*	pGRLOCAL = &(m_SIDEINF.sArrCH[dwCh].sArrGRINF[dwGr]);
    
    for(iSb18=0; iSb18<576; iSb18+=18) 
	{
        
        dwBt = (pGRLOCAL->wndSwitchFlag && pGRLOCAL->mixedBlockFlag &&
					(iSb18 < 36)) ? 0 : pGRLOCAL->nBlockType;
        
        pdTsOut = m_dOutArr + iSb18;
        
        InvMdcdt(pdTsOut, dOurRaw, dwBt);
        
        pdPrvBlok = &m_PreBlkArr[dwCh][iSb18];
        pdTsOut[0]   = dOurRaw[0]  + pdPrvBlok[0];
        pdPrvBlok[0]  = dOurRaw[18];
        pdTsOut[1]   = dOurRaw[1]  + pdPrvBlok[1];
        pdPrvBlok[1]  = dOurRaw[19];
        pdTsOut[2]   = dOurRaw[2]  + pdPrvBlok[2];
        pdPrvBlok[2]  = dOurRaw[20];
        pdTsOut[3]   = dOurRaw[3]  + pdPrvBlok[3];
        pdPrvBlok[3]  = dOurRaw[21];
        pdTsOut[4]   = dOurRaw[4]  + pdPrvBlok[4];
        pdPrvBlok[4]  = dOurRaw[22];
        pdTsOut[5]   = dOurRaw[5]  + pdPrvBlok[5];
        pdPrvBlok[5]  = dOurRaw[23];
        pdTsOut[6]   = dOurRaw[6]  + pdPrvBlok[6];
        pdPrvBlok[6]  = dOurRaw[24];
        pdTsOut[7]   = dOurRaw[7]  + pdPrvBlok[7];
        pdPrvBlok[7]  = dOurRaw[25];
        pdTsOut[8]   = dOurRaw[8]  + pdPrvBlok[8];
        pdPrvBlok[8]  = dOurRaw[26];
        pdTsOut[9]   = dOurRaw[9]  + pdPrvBlok[9];
        pdPrvBlok[9]  = dOurRaw[27];
        pdTsOut[10]  = dOurRaw[10] + pdPrvBlok[10];
        pdPrvBlok[10] = dOurRaw[28];
        pdTsOut[11]  = dOurRaw[11] + pdPrvBlok[11];
        pdPrvBlok[11] = dOurRaw[29];
        pdTsOut[12]  = dOurRaw[12] + pdPrvBlok[12];
        pdPrvBlok[12] = dOurRaw[30];
        pdTsOut[13]  = dOurRaw[13] + pdPrvBlok[13];
        pdPrvBlok[13] = dOurRaw[31];
        pdTsOut[14]  = dOurRaw[14] + pdPrvBlok[14];
        pdPrvBlok[14] = dOurRaw[32];
        pdTsOut[15]  = dOurRaw[15] + pdPrvBlok[15];
        pdPrvBlok[15] = dOurRaw[33];
        pdTsOut[16]  = dOurRaw[16] + pdPrvBlok[16];
        pdPrvBlok[16] = dOurRaw[34];
        pdTsOut[17]  = dOurRaw[17] + pdPrvBlok[17];
        pdPrvBlok[17] = dOurRaw[35];
    }

}




void CLayerIII::InvMdcdt(double *pDblIn, double *pDblOut, int nBlockType)
{
    double    tmp[18];
    double    *win_bt;
    int   dw;
    
    if(nBlockType == 2)
    {
        /*
        for(int p=0;p<36;p+=9) 
        {
            pDblOut[p]   = pDblOut[p+1] = pDblOut[p+2] = pDblOut[p+3] =
                pDblOut[p+4] = pDblOut[p+5] = pDblOut[p+6] = pDblOut[p+7] =
                pDblOut[p+8] = 0.0f;
        }
        */
        ZeroMemory(pDblOut,sizeof(double)*36);
        
        int six_i = 0;
        
        for(dw=0;dw<3;dw++)
        {
            
            // 12 point IMDCT
            
            // Begin 12 point IDCT
            
            // Input aliasing for 12 pt IDCT
            pDblIn[15+dw] += pDblIn[12+dw]; 
            pDblIn[12+dw] += pDblIn[9+dw]; 
            pDblIn[9+dw]  +=  pDblIn[6+dw];
            pDblIn[6+dw]  += pDblIn[3+dw];  
            pDblIn[3+dw]  += pDblIn[0+dw];
            
            // Input aliasing on odd indices (for 6 point IDCT)
            pDblIn[15+dw] += pDblIn[9+dw];  pDblIn[9+dw]  += pDblIn[3+dw];
            
            // 3 point IDCT on even indices
            
            {
                double  pp1, pp2, sum;
                pp2 = pDblIn[12+dw] * 0.500000000f;
                pp1 = pDblIn[ 6+dw] * 0.866025403f;
                sum = pDblIn[0+dw] + pp2;
                tmp[1] = pDblIn[0+dw] - pDblIn[12+dw];
                tmp[0] = sum + pp1;
                tmp[2] = sum - pp1;
                
                // End 3 point IDCT on even indices
                
                // 3 point IDCT on odd indices (for 6 point IDCT)
                
                pp2 = pDblIn[15+dw] * 0.500000000f;
                pp1 = pDblIn[ 9+dw] * 0.866025403f;
                sum = pDblIn[ 3+dw] + pp2;
                tmp[4] = pDblIn[3+dw] - pDblIn[15+dw];
                tmp[5] = sum + pp1;
                tmp[3] = sum - pp1;
            }
            
            // End 3 point IDCT on odd indices
            
            // Twiddle factors on odd indices (for 6 point IDCT)
            
            tmp[3] *= 1.931851653f;
            tmp[4] *= 0.707106781f;
            tmp[5] *= 0.517638090f;
            
            // Output butterflies on 2 3 point IDCT's (for 6 point IDCT)
            
            {
                double save = tmp[0];
                tmp[0] += tmp[5];
                tmp[5] = save - tmp[5];
                save = tmp[1];
                tmp[1] += tmp[4];
                tmp[4] = save - tmp[4];
                save = tmp[2];
                tmp[2] += tmp[3];
                tmp[3] = save - tmp[3];
            }
            
            // End 6 point IDCT
            
            // Twiddle factors on indices (for 12 point IDCT)
            
            tmp[0]  *=  0.504314480f;
            tmp[1]  *=  0.541196100f;
            tmp[2]  *=  0.630236207f;
            tmp[3]  *=  0.821339815f;
            tmp[4]  *=  1.306562965f;
            tmp[5]  *=  3.830648788f;
            
            // End 12 point IDCT
            
            // Shift to 12 point modified IDCT, multiply by nWnd type 2
            tmp[8]  = -tmp[0] * 0.793353340f;
            tmp[9]  = -tmp[0] * 0.608761429f;
            tmp[7]  = -tmp[1] * 0.923879532f;
            tmp[10] = -tmp[1] * 0.382683432f;
            tmp[6]  = -tmp[2] * 0.991444861f;
            tmp[11] = -tmp[2] * 0.130526192f;
            
            tmp[0]  =  tmp[3];
            tmp[1]  =  tmp[4] * 0.382683432f;
            tmp[2]  =  tmp[5] * 0.608761429f;
            
            tmp[3]  = -tmp[5] * 0.793353340f;
            tmp[4]  = -tmp[4] * 0.923879532f;
            tmp[5]  = -tmp[0] * 0.991444861f;
            
            tmp[0] *= 0.130526192f;
            
            pDblOut[six_i + 6]  += tmp[0];
            pDblOut[six_i + 7]  += tmp[1];
            pDblOut[six_i + 8]  += tmp[2];
            pDblOut[six_i + 9]  += tmp[3];
            pDblOut[six_i + 10] += tmp[4];
            pDblOut[six_i + 11] += tmp[5];
            pDblOut[six_i + 12] += tmp[6];
            pDblOut[six_i + 13] += tmp[7];
            pDblOut[six_i + 14] += tmp[8];
            pDblOut[six_i + 15] += tmp[9];
            pDblOut[six_i + 16] += tmp[10];
            pDblOut[six_i + 17] += tmp[11];
            
            six_i += 6;
        }
        
        } else {
        
        
        // 36 point IDCT
        
        // input aliasing for 36 point IDCT
        pDblIn[17]+=pDblIn[16]; pDblIn[16]+=pDblIn[15]; pDblIn[15]+=pDblIn[14]; pDblIn[14]+=pDblIn[13];
        pDblIn[13]+=pDblIn[12]; pDblIn[12]+=pDblIn[11]; pDblIn[11]+=pDblIn[10]; pDblIn[10]+=pDblIn[9];
        pDblIn[9] +=pDblIn[8];  pDblIn[8] +=pDblIn[7];  pDblIn[7] +=pDblIn[6];  pDblIn[6] +=pDblIn[5];
        pDblIn[5] +=pDblIn[4];  pDblIn[4] +=pDblIn[3];  pDblIn[3] +=pDblIn[2];  pDblIn[2] +=pDblIn[1];
        pDblIn[1] +=pDblIn[0];
        
        // 18 point IDCT for odd indices
        
        // input aliasing for 18 point IDCT
        pDblIn[17]+=pDblIn[15]; pDblIn[15]+=pDblIn[13]; pDblIn[13]+=pDblIn[11]; pDblIn[11]+=pDblIn[9];
        pDblIn[9] +=pDblIn[7];  pDblIn[7] +=pDblIn[5];  pDblIn[5] +=pDblIn[3];  pDblIn[3] +=pDblIn[1];
        
        {
            double tmp0,tmp1,tmp2,tmp3,tmp4,tmp0_,tmp1_,tmp2_,tmp3_;
            double tmp0o,tmp1o,tmp2o,tmp3o,tmp4o,tmp0_o,tmp1_o,tmp2_o,tmp3_o;
            
            // Fast 9 Point Inverse Discrete Cosine Transform
            //
            // By  Francois-Raymond Boyer
            //         mailto:boyerf@iro.umontdouble.ca
            //         http://www.iro.umontdouble.ca/~boyerf
            //
            // The code has been optimized for Intel processors
            //  (takes a lot of time to convert float to and from iternal FPU representation)
            //
            // It is a simple "factorization" of the IDCT matrix.
            
            // 9 point IDCT on even indices
            {
                // 5 points on odd indices (not doubley an IDCT)
                double i0 = pDblIn[0]+pDblIn[0];
                double i0p12 = i0 + pDblIn[12];
                
                tmp0 = i0p12 + pDblIn[4]*1.8793852415718f  + pDblIn[8]*1.532088886238f   + pDblIn[16]*0.34729635533386f;
                tmp1 = i0    + pDblIn[4]                   - pDblIn[8] - pDblIn[12] - pDblIn[12] - pDblIn[16];
                tmp2 = i0p12 - pDblIn[4]*0.34729635533386f - pDblIn[8]*1.8793852415718f  + pDblIn[16]*1.532088886238f;
                tmp3 = i0p12 - pDblIn[4]*1.532088886238f   + pDblIn[8]*0.34729635533386f - pDblIn[16]*1.8793852415718f;
                tmp4 = pDblIn[0] - pDblIn[4]                   + pDblIn[8] - pDblIn[12]          + pDblIn[16];
                
                // 4 points on even indices
                double i6_ = pDblIn[6]*1.732050808f;  // Sqrt[3]
                
                tmp0_ = pDblIn[2]*1.9696155060244f  + i6_ + pDblIn[10]*1.2855752193731f  + pDblIn[14]*0.68404028665134f;
                tmp1_ = (pDblIn[2]                        - pDblIn[10]                   - pDblIn[14])*1.732050808f;
                tmp2_ = pDblIn[2]*1.2855752193731f  - i6_ - pDblIn[10]*0.68404028665134f + pDblIn[14]*1.9696155060244f;
                tmp3_ = pDblIn[2]*0.68404028665134f - i6_ + pDblIn[10]*1.9696155060244f  - pDblIn[14]*1.2855752193731f;
            }
            
            // 9 point IDCT on odd indices
            {
                // 5 points on odd indices (not doubley an IDCT)
                double i0 = pDblIn[0+1]+pDblIn[0+1];
                double i0p12 = i0 + pDblIn[12+1];
                
                tmp0o = i0p12   + pDblIn[4+1]*1.8793852415718f  + pDblIn[8+1]*1.532088886238f       + pDblIn[16+1]*0.34729635533386f;
                tmp1o = i0      + pDblIn[4+1]                   - pDblIn[8+1] - pDblIn[12+1] - pDblIn[12+1] - pDblIn[16+1];

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?