⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 layeriii.cpp

📁 完整的MP3播放器源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                tmp2o = i0p12   - pDblIn[4+1]*0.34729635533386f - pDblIn[8+1]*1.8793852415718f      + pDblIn[16+1]*1.532088886238f;
                tmp3o = i0p12   - pDblIn[4+1]*1.532088886238f   + pDblIn[8+1]*0.34729635533386f     - pDblIn[16+1]*1.8793852415718f;
                tmp4o = (pDblIn[0+1] - pDblIn[4+1]                   + pDblIn[8+1] - pDblIn[12+1]            + pDblIn[16+1])*0.707106781f; // Twiddled
                
                // 4 points on even indices
                double i6_ = pDblIn[6+1]*1.732050808f;  // Sqrt[3]
                
                tmp0_o = pDblIn[2+1]*1.9696155060244f  + i6_ + pDblIn[10+1]*1.2855752193731f  + pDblIn[14+1]*0.68404028665134f;
                tmp1_o = (pDblIn[2+1]                        - pDblIn[10+1]                   - pDblIn[14+1])*1.732050808f;
                tmp2_o = pDblIn[2+1]*1.2855752193731f  - i6_ - pDblIn[10+1]*0.68404028665134f + pDblIn[14+1]*1.9696155060244f;
                tmp3_o = pDblIn[2+1]*0.68404028665134f - i6_ + pDblIn[10+1]*1.9696155060244f  - pDblIn[14+1]*1.2855752193731f;
            }
            
            // Twiddle factors on odd indices
            // and
            // Butterflies on 9 point IDCT's
            // and
            // twiddle factors for 36 point IDCT
            
            double e, o;
            e = tmp0 + tmp0_; o = (tmp0o + tmp0_o)*0.501909918f; tmp[0] = e + o;    tmp[17] = e - o;
            e = tmp1 + tmp1_; o = (tmp1o + tmp1_o)*0.517638090f; tmp[1] = e + o;    tmp[16] = e - o;
            e = tmp2 + tmp2_; o = (tmp2o + tmp2_o)*0.551688959f; tmp[2] = e + o;    tmp[15] = e - o;
            e = tmp3 + tmp3_; o = (tmp3o + tmp3_o)*0.610387294f; tmp[3] = e + o;    tmp[14] = e - o;
            tmp[4] = tmp4 + tmp4o; tmp[13] = tmp4 - tmp4o;
            e = tmp3 - tmp3_; o = (tmp3o - tmp3_o)*0.871723397f; tmp[5] = e + o;    tmp[12] = e - o;
            e = tmp2 - tmp2_; o = (tmp2o - tmp2_o)*1.183100792f; tmp[6] = e + o;    tmp[11] = e - o;
            e = tmp1 - tmp1_; o = (tmp1o - tmp1_o)*1.931851653f; tmp[7] = e + o;    tmp[10] = e - o;
            e = tmp0 - tmp0_; o = (tmp0o - tmp0_o)*5.736856623f; tmp[8] = e + o;    tmp[9] =  e - o;
        }
        
        // end 36 point IDCT */
        
        // shift to modified IDCT
        win_bt = dblWin[nBlockType];
        
        pDblOut[0] =-tmp[9]  * win_bt[0];
        pDblOut[1] =-tmp[10] * win_bt[1];
        pDblOut[2] =-tmp[11] * win_bt[2];
        pDblOut[3] =-tmp[12] * win_bt[3];
        pDblOut[4] =-tmp[13] * win_bt[4];
        pDblOut[5] =-tmp[14] * win_bt[5];
        pDblOut[6] =-tmp[15] * win_bt[6];
        pDblOut[7] =-tmp[16] * win_bt[7];
        pDblOut[8] =-tmp[17] * win_bt[8];
        
        pDblOut[9] = tmp[17] * win_bt[9];
        pDblOut[10]= tmp[16] * win_bt[10];
        pDblOut[11]= tmp[15] * win_bt[11];
        pDblOut[12]= tmp[14] * win_bt[12];
        pDblOut[13]= tmp[13] * win_bt[13];
        pDblOut[14]= tmp[12] * win_bt[14];
        pDblOut[15]= tmp[11] * win_bt[15];
        pDblOut[16]= tmp[10] * win_bt[16];
        pDblOut[17]= tmp[9]  * win_bt[17];
        pDblOut[18]= tmp[8]  * win_bt[18];
        pDblOut[19]= tmp[7]  * win_bt[19];
        pDblOut[20]= tmp[6]  * win_bt[20];
        pDblOut[21]= tmp[5]  * win_bt[21];
        pDblOut[22]= tmp[4]  * win_bt[22];
        pDblOut[23]= tmp[3]  * win_bt[23];
        pDblOut[24]= tmp[2]  * win_bt[24];
        pDblOut[25]= tmp[1]  * win_bt[25];
        pDblOut[26]= tmp[0]  * win_bt[26];
        
        pDblOut[27]= tmp[0]  * win_bt[27];
        pDblOut[28]= tmp[1]  * win_bt[28];
        pDblOut[29]= tmp[2]  * win_bt[29];
        pDblOut[30]= tmp[3]  * win_bt[30];
        pDblOut[31]= tmp[4]  * win_bt[31];
        pDblOut[32]= tmp[5]  * win_bt[32];
        pDblOut[33]= tmp[6]  * win_bt[33];
        pDblOut[34]= tmp[7]  * win_bt[34];
        pDblOut[35]= tmp[8]  * win_bt[35];
    }
}

DWORD CLayerIII::Bits(int nBits)
{

	DWORD	dwRetVal = 0;										
    DWORD	nSumBits = m_nBitsOffset + nBits;			// update the bits index
	DWORD	dwMask   = 0xFFFFFFFF >> (32 - nBits );		// build the mask
	DWORD*  ptoDW    = (DWORD*)m_pbyWalk;
	DWORD	dwValue  = *ptoDW;						// extract the pointed value
    
    if (nSumBits <= 32)
    {
        dwRetVal = (dwValue >> (32 - nSumBits)) & dwMask;
        if ((m_nBitsOffset += nBits) == 32)
        {
            m_nBitsOffset = 0;
			m_pbyWalk+=4;
        }
    }
    else
	{	// walk half a long and get them
		dwRetVal = MAKELONG(HIWORD(*(ptoDW+1)),LOWORD(*(ptoDW)));
		m_pbyWalk+=4;
		m_nBitsOffset	= nSumBits - 32;
		dwRetVal >>= 48 - nSumBits; 
		dwRetVal &= dwMask;
	}

	return dwRetVal;
}



int CLayerIII::HuffmanDec(sHUFDECTAB *h, int *x, int *y, int *v,
                     int *w)
{
	
    DWORD level;
    int point = 0;
    int error = 1;
    level     = 0x80000000;
    
    if (h->val == NULL) return 2;
    
    /* table 0 needs no bits */
        if ( h->treelen == 0)
    {  *x = *y = 0;
        return 0;
    }
    
    /* Lookup in Huffman table. */
        
    do {
        if (h->val[point][0]==0) {   /*end of tree*/
               *x = h->val[point][1] >> 4;
            *y = h->val[point][1] & 0xf;
            
            error = 0;
            break;
        }
        if (GetFastOneBit()) {
            while (h->val[point][1] >= 250) point += h->val[point][1];
            point += h->val[point][1];
        }
        else {
            while (h->val[point][0] >= 250) point += h->val[point][0];
            point += h->val[point][0];
        }
        level >>= 1;
    } while (level  || (point < (int)ht->treelen) );
    
    // Check for error.
    
    /*  if (error) { // set x and y to a medium value as a simple concealment
        printf("Illegal Huffman code in data.\n");
        *x = (h->xlen-1 << 1);
        *y = (h->ylen-1 << 1);
    } */
    
    /* Process sign encodings for quadruples tables. */
        
    if (h->tablename[0] == '3'
       && (h->tablename[1] == '2' || h->tablename[1] == '3')) {
        *v = (*y>>3) & 1;
        *w = (*y>>2) & 1;
        *x = (*y>>1) & 1;
        *y = *y & 1;
        
        /* v, w, x and y are reversed in the bitstream.
            switch them around to make test bistream work. */
            
        if (*v)
           if (GetFastOneBit()) *v = -*v;
        if (*w)
           if (GetFastOneBit()) *w = -*w;
        if (*x)
           if (GetFastOneBit()) *x = -*x;
        if (*y)
           if (GetFastOneBit()) *y = -*y;
        } else {
        
        // Process sign and escape encodings for dual tables.
        
        // x and y are reversed in the test bitstream.
        // Reverse x and y here to make test bitstream work.
        
        if (h->linbits)
           if ((h->xlen-1) == (DWORD)*x)
           *x += GetBits(h->linbits);
        if (*x)
           if (GetFastOneBit()) *x = -*x;
        if (h->linbits)
           if ((h->ylen-1) == (DWORD)*y)
           *y += GetBits(h->linbits);
        if (*y)
           if (GetFastOneBit()) *y = -*y;
    }
    
    return error;
}




//////////////////////////////////////////////////////////////////////////////////////
// the dbScale scales the calculated float pcm m_tdbSubSamples to short values
// (raw pcm m_tdbSubSamples are in [-1.0, 1.0], if no violations occur)
SynthesisFilter::SynthesisFilter(DWORD nChn):m_nCan(nChn),m_countIn(0),m_lastband(-1)
{

    Reset();
}

//////////////////////////////////////////////////////////////////////////////////////
//
void SynthesisFilter::Reset()
{
	ZeroMemory(m_tableA,sizeof(m_tableA));
	ZeroMemory(m_tableB,sizeof(m_tableB));
	ZeroMemory(m_tdbSubSamples,sizeof(m_tdbSubSamples));
    m_pToTable		= m_tableA;
    m_nWriteIndex	= 15;
    for(int i=0;i<40;i++)
		m_gain[i]=1.0f;
}

//////////////////////////////////////////////////////////////////////////////////////
//	Eliminated the old kilometric asignments lists (we have fast computers now)
//

void SynthesisFilter::CompNewTable()
{
// new V[0-15] and V[33-48] of Figure 3-A.2 in ISO DIS 11172-3
    double	tdbNewTbl[32];         
    double	dbTemp1[16];
    double	dbTmp2[16];
	int		j = 0;

    double *pDbl1 = m_tdbSubSamples;
	while(j<16)
	{
		dbTemp1[j] = pDbl1[j] + pDbl1[31-j];
		j++;
	}
    j = 0;
	while(j<8)
	{
		dbTmp2[j] = dbTemp1[j] + dbTemp1[15-j];
		j++;
	}
	while(j<16)
	{
		dbTmp2[j] = (dbTemp1[j-8] - dbTemp1[23-j]) * dbCosTable[j+8];
		j++;
	}
	
    for(j = 0 ; j< 4 ;j++)
	{
		dbTemp1[j] = dbTmp2[j] + dbTmp2[7-j];
		dbTemp1[j+8] = dbTmp2[j+8] + dbTmp2[15-j];
		dbTemp1[j+4] = (dbTmp2[j] - dbTmp2[7-j]) * dbCosTable[24+j];
		dbTemp1[j+12] = (dbTmp2[j+8] - dbTmp2[15-j]) * dbCosTable[24+j];// cos1_16;
	}
    
	for(j = 0 ; j < 2 ;j++)
	{
		dbTmp2[j] = dbTemp1[j] + dbTemp1[3-j];
		dbTmp2[4+j] = dbTemp1[4+j] + dbTemp1[7-j];
		dbTmp2[8+j] = dbTemp1[8+j] + dbTemp1[11-j];
		dbTmp2[12+j] = dbTemp1[12+j] + dbTemp1[15-j];
		dbTmp2[2+j] = (dbTemp1[j] - dbTemp1[3-j]) * dbCosTable[28+j];//cos1_8;
		dbTmp2[6+j] = (dbTemp1[4+j] - dbTemp1[7-j]) * dbCosTable[28+j];
		dbTmp2[10+j] = (dbTemp1[8+j] - dbTemp1[11-j]) * dbCosTable[28+j];
		dbTmp2[14+j] = (dbTemp1[12+j] - dbTemp1[15-j]) * dbCosTable[28+j];
	}

	for(j = 0; j < 16 ;j+=2)
	{
        dbTemp1[j]   = dbTmp2[j] + dbTmp2[j+1];
        dbTemp1[j+1] = (dbTmp2[j] - dbTmp2[j+1]) * dbCosTable[30];
	}

    double dbTEmp;
    tdbNewTbl[19] = -(tdbNewTbl[4] = (tdbNewTbl[12] = dbTemp1[7]) + dbTemp1[5]) - dbTemp1[6];
    tdbNewTbl[27] = -dbTemp1[6] - dbTemp1[7] - dbTemp1[4];
    tdbNewTbl[6] = (tdbNewTbl[10] = (tdbNewTbl[14] = dbTemp1[15]) + dbTemp1[11]) + dbTemp1[13];
    tdbNewTbl[17] = -(tdbNewTbl[2] = dbTemp1[15] + dbTemp1[13] + dbTemp1[9]) - dbTemp1[14];
    tdbNewTbl[21] = (dbTEmp = -dbTemp1[14] - dbTemp1[15] - dbTemp1[10] - dbTemp1[11]) - dbTemp1[13];
    tdbNewTbl[29] = -dbTemp1[14] - dbTemp1[15] - dbTemp1[12] - dbTemp1[8];
    tdbNewTbl[25] = dbTEmp - dbTemp1[12];
    tdbNewTbl[31] = -dbTemp1[0];
    tdbNewTbl[0] = dbTemp1[1];
    tdbNewTbl[23] = -(tdbNewTbl[8] = dbTemp1[3]) - dbTemp1[2];
        
    pDbl1 = m_tdbSubSamples;
	
	for(j = 0 ;j < 16 ; j++)
	{
		dbTemp1[j] = (pDbl1[j] - pDbl1[31-j]) * dbCosTable[j];
	}

	for(j = 0 ;j < 8 ; j++)
	{
		dbTmp2[j] = dbTemp1[j] + dbTemp1[15-j];
		dbTmp2[j+8] = (dbTemp1[j] - dbTemp1[15-j]) * dbCosTable[j+16];
	}

	for(j = 0 ;j < 4 ; j++)
	{
		dbTemp1[j] = dbTmp2[j] + dbTmp2[7-j];
		dbTemp1[8+j] = dbTmp2[8+j] + dbTmp2[15-j];
		dbTemp1[4+j] = (dbTmp2[j] - dbTmp2[7-j]) * dbCosTable[j+24];
		dbTemp1[12+j] = (dbTmp2[8+j] - dbTmp2[15-j]) * dbCosTable[j+24];
	}

	for(j = 0 ; j < 2 ;j++)
	{
		dbTmp2[j] = dbTemp1[j] + dbTemp1[3-j];
		dbTmp2[4+j] = dbTemp1[4+j] + dbTemp1[7-j];
		dbTmp2[8+j] = dbTemp1[8+j] + dbTemp1[11-j];
		dbTmp2[12+j] = dbTemp1[12+j] + dbTemp1[15-j];
		dbTmp2[2+j] = (dbTemp1[j] - dbTemp1[3-j]) * dbCosTable[28+j];//cos1_8;
		dbTmp2[6+j] = (dbTemp1[4+j] - dbTemp1[7-j]) * dbCosTable[28+j];
		dbTmp2[10+j] = (dbTemp1[8+j] - dbTemp1[11-j]) * dbCosTable[28+j];
		dbTmp2[14+j] = (dbTemp1[12+j] - dbTemp1[15-j]) * dbCosTable[28+j];
	}

	for(j = 0; j < 16 ;j+=2)
	{
        dbTemp1[j]   = dbTmp2[j] + dbTmp2[j+1];
        dbTemp1[j+1] = (dbTmp2[j] - dbTmp2[j+1]) * dbCosTable[30];
	}

	// manually doing something that a compiler should handle sucks
	// coding like this is hard to read
	double dbDbTmp2Val;
	tdbNewTbl[5] = (tdbNewTbl[11] = (tdbNewTbl[13] = (tdbNewTbl[15] = dbTemp1[15]) + dbTemp1[7]) + dbTemp1[11])
			   + dbTemp1[5] + dbTemp1[13];
	tdbNewTbl[7] = (tdbNewTbl[9] = dbTemp1[15] + dbTemp1[11] + dbTemp1[3]) + dbTemp1[13];
	tdbNewTbl[16] = -(tdbNewTbl[1] = (dbTEmp = dbTemp1[13] + dbTemp1[15] + dbTemp1[9]) + dbTemp1[1]) - dbTemp1[14];
	tdbNewTbl[18] = -(tdbNewTbl[3] = dbTEmp + dbTemp1[5] + dbTemp1[7]) - dbTemp1[6] - dbTemp1[14];

	tdbNewTbl[22] = (dbTEmp = -dbTemp1[10] - dbTemp1[11] - dbTemp1[14] - dbTemp1[15])
				   - dbTemp1[13] - dbTemp1[2] - dbTemp1[3];
	tdbNewTbl[20] = dbTEmp - dbTemp1[13] - dbTemp1[5] - dbTemp1[6] - dbTemp1[7];
	tdbNewTbl[24] = dbTEmp - dbTemp1[12] - dbTemp1[2] - dbTemp1[3];
	tdbNewTbl[26] = dbTEmp - dbTemp1[12] - (dbDbTmp2Val = dbTemp1[4] + dbTemp1[6] + dbTemp1[7]);
	tdbNewTbl[30] = (dbTEmp = -dbTemp1[8] - dbTemp1[12] - dbTemp1[14] - dbTemp1[15]) - dbTemp1[0];
	tdbNewTbl[28] = dbTEmp - dbDbTmp2Val;
    
	// insert V[0-15] (== tdbNewTbl[0-15]) into actual v:
	double *pDblA = tdbNewTbl;
	double *pDblB = m_pToTable + m_nWriteIndex;
	for(j=0;j<16;j++)
		pDblB[j*16] = pDblA[j];
	pDblB[256] = 0.0f;

	for(j=1;j<16;j++)
	{
		pDblB[256+(16*j)] = -pDblA[16-j];
	}
	pDblB = (m_pToTable == m_tableA ? m_tableB : m_tableA) + 
			m_nWriteIndex;
	pDblB[0] = -pDblA[0];

	for(j=1;j < 17;j++)
		pDblB[j*16] = pDblA[j+15];
	// insert V[49-63] (== tdbNewTbl[30-16]) into other v:
	for(j=1;j<16;j++)
	{
		pDblB[256+(16*j)] = pDblA[31-j];
	}

}

///////////////////////////////////////////////////////////////////////////////
//
void CLayerIII::GoBackBits(int nBits)
{
    m_PlayedBits -= nBits;
    m_restBits   += nBits;
    while(m_restBits >= 8) 
	{
        m_restBits -= 8;
        m_playedOctets--;
    }
}

///////////////////////////////////////////////////////////////////////////////
//
void CLayerIII::GoBackOctets(int nOctets)
{
	m_PlayedBits		 -= (nOctets*8);
    m_playedOctets		 -= nOctets;
}


///////////////////////////////////////////////////////////////////////////////
//
//
DWORD CLayerIII::GetBits(DWORD nBits)
{

	m_PlayedBits += nBits;
   	DWORD	dwRetVal = 0;
	int		contor = nBits;
	while

⌨️ 快捷键说明

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