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

📄 mpc_dec.cpp

📁 betaplayer的源码 tcpmp的老版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
#include "stdafx.h"
/* added SeekTable from previous version by Picard 12/04/2004 */
/* change calloc to malloc and memset (wince2.xx doesn't have calloc) by Picard 01/02/2005 */
voidMPC_decoder::RESET_Synthesis ( void ){    Reset_V ();}voidMPC_decoder::RESET_Y ( void ){    memset ( Y_L, 0, sizeof Y_L );    memset ( Y_R, 0, sizeof Y_R );}voidMPC_decoder::RESET_Globals ( void ){    Reset_BitstreamDecode ();    DecodedFrames  = 0;    StreamVersion  = 0;    MS_used        = 0;    memset ( Y_L             , 0, sizeof Y_L              );    memset ( Y_R             , 0, sizeof Y_R              );    memset ( SCF_Index_L     , 0, sizeof SCF_Index_L      );    memset ( SCF_Index_R     , 0, sizeof SCF_Index_R      );    memset ( Res_L           , 0, sizeof Res_L            );    memset ( Res_R           , 0, sizeof Res_R            );    memset ( SCFI_L          , 0, sizeof SCFI_L           );    memset ( SCFI_R          , 0, sizeof SCFI_R           );    memset ( DSCF_Flag_L     , 0, sizeof DSCF_Flag_L      );    memset ( DSCF_Flag_R     , 0, sizeof DSCF_Flag_R      );    memset ( DSCF_Reference_L, 0, sizeof DSCF_Reference_L );    memset ( DSCF_Reference_R, 0, sizeof DSCF_Reference_R );    memset ( Q               , 0, sizeof Q                );    memset ( MS_Flag         , 0, sizeof MS_Flag          );}mpc_uint32_tMPC_decoder::decode_internal ( MPC_SAMPLE_FORMAT *buffer ){	mpc_uint32_t output_frame_length = FrameLength;	mpc_uint32_t  FrameBitCnt = 0;	if ( DecodedFrames >= OverallFrames )		return (mpc_uint32_t)(-1);                           // end of file -> abort decoding	// read jump-info for validity check of frame	FwdJumpInfo  = Bitstream_read (20);	SeekTable [DecodedFrames] = 20 + FwdJumpInfo;       // ...
	ActDecodePos = (Zaehler << 5) + pos;	// decode data and check for validity of frame	FrameBitCnt = BitsRead ();	switch ( StreamVersion ) {	case 0x04:	case 0x05:	case 0x06:		Lese_Bitstrom_SV6 ();		break;	case 0x07:	case 0x17:		Lese_Bitstrom_SV7 ();		break;	default:		return (mpc_uint32_t)(-1);	}	FrameWasValid = BitsRead() - FrameBitCnt == FwdJumpInfo;	// synthesize signal	Requantisierung ( Max_Band );	//if ( EQ_activated && PluginSettings.EQbyMPC )	//    perform_EQ ();	Synthese_Filter_float ( buffer );	DecodedFrames++;	// cut off first SynthDelay zero-samples	if ( DecodedFrames == OverallFrames  &&  StreamVersion >= 6 )	{        // reconstruct exact filelength		mpc_int32_t  mod_block   = Bitstream_read (11);		mpc_int32_t  FilterDecay;		if (mod_block == 0) mod_block = 1152;                    // Encoder bugfix		FilterDecay = (mod_block + SynthDelay) % FrameLength;		// additional FilterDecay samples are needed for decay of synthesis filter		if ( SynthDelay + mod_block >= FrameLength ) {			// **********************************************************************			// Rhoades 4/16/2002			// Commented out are blocks of code which cause gapless playback to fail.			// Temporary fix...			// **********************************************************************			if ( ! TrueGaplessPresent ) {				RESET_Y ();			} else {				//if ( FrameLength != LastValidSamples ) {					Bitstream_read (20);					Lese_Bitstrom_SV7 ();					Requantisierung ( Max_Band );					//FilterDecay = LastValidSamples;				//}				//else {					//FilterDecay = 0;				//}			}			Synthese_Filter_float ( buffer + 2304 );			output_frame_length = FrameLength + FilterDecay;		}		else {                              // there are only FilterDecay samples needed for this frame			output_frame_length = FilterDecay;		}	}	if ( samples_to_skip ) {		if (output_frame_length < samples_to_skip)		{			samples_to_skip -= output_frame_length;			output_frame_length = 0;		}		else		{			output_frame_length -= samples_to_skip;			memmove ( buffer, buffer + samples_to_skip * 2, output_frame_length * 2 * sizeof (MPC_SAMPLE_FORMAT) );			samples_to_skip = 0;		}	}	return output_frame_length;}mpc_uint32_t MPC_decoder::Decode ( MPC_SAMPLE_FORMAT *buffer, mpc_uint32_t * vbr_update_acc, mpc_uint32_t * vbr_update_bits ){	for(;;)	{        //const mpc_int32_t MaxBrokenFrames = 0; // PluginSettings.MaxBrokenFrames        mpc_uint32_t RING = Zaehler;		mpc_int32_t vbr_ring = (RING << 5) + pos;        mpc_uint32_t valid_samples = decode_internal ( buffer );        if ( valid_samples == (mpc_uint32_t)(-1) ) return 0;        /**************** ERROR CONCEALMENT *****************/        if ( FrameWasValid == 0 ) {                                   // error occurred in bitstream            return (mpc_uint32_t)(-1);        } else		{			if (vbr_update_acc && vbr_update_bits)			{				(*vbr_update_acc) ++;				vbr_ring = (Zaehler << 5) + pos - vbr_ring;				if (vbr_ring < 0) vbr_ring += 524288;				(*vbr_update_bits) += vbr_ring;			}		}		UpdateBuffer ( RING );		if (valid_samples > 0) return valid_samples;	}}voidMPC_decoder::Requantisierung ( const mpc_int32_t Last_Band ){    mpc_int32_t     Band;    mpc_int32_t     n;    MPC_SAMPLE_FORMAT facL;    MPC_SAMPLE_FORMAT facR;    MPC_SAMPLE_FORMAT templ;    MPC_SAMPLE_FORMAT tempr;    MPC_SAMPLE_FORMAT* YL;    MPC_SAMPLE_FORMAT* YR;    mpc_int32_t*    L;    mpc_int32_t*    R;#ifdef MPC_FIXED_POINT#if MPC_FIXED_POINT_FRACTPART == 14#define MPC_MULTIPLY_SCF(CcVal, SCF_idx) \	MPC_MULTIPLY_EX(CcVal,SCF[SCF_idx],SCF_shift[SCF_idx])#else#error FIXME, Cc table is in 18.14 format#endif#else#define MPC_MULTIPLY_SCF(CcVal, SCF_idx) \	MPC_MULTIPLY(CcVal,SCF[SCF_idx])#endif    // requantization and scaling of subband-samples    for ( Band = 0; Band <= Last_Band; Band++ ) {   // setting pointers        YL = Y_L [0] + Band;        YR = Y_R [0] + Band;        L  = Q [Band].L;        R  = Q [Band].R;        /************************** MS-coded **************************/        if ( MS_Flag [Band] ) {            if ( Res_L [Band] ) {                if ( Res_R [Band] ) {    // M!=0, S!=0                    facL = MPC_MULTIPLY_SCF( Cc[Res_L[Band]] , (unsigned char)SCF_Index_L[Band][0]);                    facR = MPC_MULTIPLY_SCF( Cc[Res_R[Band]] , (unsigned char)SCF_Index_R[Band][0]);                    for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) {                        *YL   = (templ = MPC_MULTIPLY_FLOAT_INT(facL,*L++))+(tempr = MPC_MULTIPLY_FLOAT_INT(facR,*R++));                        *YR   = templ - tempr;                    }                    facL = MPC_MULTIPLY_SCF( Cc[Res_L[Band]] , (unsigned char)SCF_Index_L[Band][1]);                    facR = MPC_MULTIPLY_SCF( Cc[Res_R[Band]] , (unsigned char)SCF_Index_R[Band][1]);                    for ( ; n < 24; n++, YL += 32, YR += 32 ) {                        *YL   = (templ = MPC_MULTIPLY_FLOAT_INT(facL,*L++))+(tempr = MPC_MULTIPLY_FLOAT_INT(facR,*R++));                        *YR   = templ - tempr;                    }                    facL = MPC_MULTIPLY_SCF( Cc[Res_L[Band]] , (unsigned char)SCF_Index_L[Band][2]);                    facR = MPC_MULTIPLY_SCF( Cc[Res_R[Band]] , (unsigned char)SCF_Index_R[Band][2]);                    for ( ; n < 36; n++, YL += 32, YR += 32 ) {                        *YL   = (templ = MPC_MULTIPLY_FLOAT_INT(facL,*L++))+(tempr = MPC_MULTIPLY_FLOAT_INT(facR,*R++));                        *YR   = templ - tempr;                    }                } else {    // M!=0, S==0                    facL = MPC_MULTIPLY_SCF( Cc[Res_L[Band]] , (unsigned char)SCF_Index_L[Band][0]);                    for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) {						*YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);                    }                    facL = MPC_MULTIPLY_SCF( Cc[Res_L[Band]] , (unsigned char)SCF_Index_L[Band][1]);                    for ( ; n < 24; n++, YL += 32, YR += 32 ) {                        *YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);                    }                    facL = MPC_MULTIPLY_SCF( Cc[Res_L[Band]] , (unsigned char)SCF_Index_L[Band][2]);                    for ( ; n < 36; n++, YL += 32, YR += 32 ) {                        *YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);                    }                }            } else {                if (Res_R[Band])    // M==0, S!=0                {                    facR = MPC_MULTIPLY_SCF( Cc[Res_R[Band]] , (unsigned char)SCF_Index_R[Band][0]);                    for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) {                        *YR = - (*YL = MPC_MULTIPLY_FLOAT_INT(facR,*(R++)));                    }                    facR = MPC_MULTIPLY_SCF( Cc[Res_R[Band]] , (unsigned char)SCF_Index_R[Band][1]);                    for ( ; n < 24; n++, YL += 32, YR += 32 ) {                        *YR = - (*YL = MPC_MULTIPLY_FLOAT_INT(facR,*(R++)));                    }                    facR = MPC_MULTIPLY_SCF( Cc[Res_R[Band]] , (unsigned char)SCF_Index_R[Band][2]);                    for ( ; n < 36; n++, YL += 32, YR += 32 ) {                        *YR = - (*YL = MPC_MULTIPLY_FLOAT_INT(facR,*(R++)));                    }                } else {    // M==0, S==0                    for ( n = 0; n < 36; n++, YL += 32, YR += 32 ) {                        *YR = *YL = 0;                    }                }            }        }        /************************** LR-coded **************************/        else {            if ( Res_L [Band] ) {                if ( Res_R [Band] ) {    // L!=0, R!=0                    facL = MPC_MULTIPLY_SCF( Cc[Res_L[Band]] , (unsigned char)SCF_Index_L[Band][0]);                    facR = MPC_MULTIPLY_SCF( Cc[Res_R[Band]] , (unsigned char)SCF_Index_R[Band][0]);                    for (n = 0; n < 12; n++, YL += 32, YR += 32 ) {                        *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);                        *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++);                    }                    facL = MPC_MULTIPLY_SCF( Cc[Res_L[Band]] , (unsigned char)SCF_Index_L[Band][1]);                    facR = MPC_MULTIPLY_SCF( Cc[Res_R[Band]] , (unsigned char)SCF_Index_R[Band][1]);                    for (; n < 24; n++, YL += 32, YR += 32 ) {                        *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);                        *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++);                    }                    facL = MPC_MULTIPLY_SCF( Cc[Res_L[Band]] , (unsigned char)SCF_Index_L[Band][2]);                    facR = MPC_MULTIPLY_SCF( Cc[Res_R[Band]] , (unsigned char)SCF_Index_R[Band][2]);                    for (; n < 36; n++, YL += 32, YR += 32 ) {                        *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);                        *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++);                    }                } else {     // L!=0, R==0                    facL = MPC_MULTIPLY_SCF( Cc[Res_L[Band]] , (unsigned char)SCF_Index_L[Band][0]);                    for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) {                        *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);                        *YR = 0;                    }                    facL = MPC_MULTIPLY_SCF( Cc[Res_L[Band]] , (unsigned char)SCF_Index_L[Band][1]);                    for ( ; n < 24; n++, YL += 32, YR += 32 ) {                        *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);                        *YR = 0;                    }                    facL = MPC_MULTIPLY_SCF( Cc[Res_L[Band]] , (unsigned char)SCF_Index_L[Band][2]);                    for ( ; n < 36; n++, YL += 32, YR += 32 ) {                        *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);                        *YR = 0;                    }                }            }            else {                if ( Res_R [Band] ) {    // L==0, R!=0                    facR = MPC_MULTIPLY_SCF( Cc[Res_R[Band]] , (unsigned char)SCF_Index_R[Band][0]);                    for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) {                        *YL = 0;                        *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++);                    }                    facR = MPC_MULTIPLY_SCF( Cc[Res_R[Band]] , (unsigned char)SCF_Index_R[Band][1]);                    for ( ; n < 24; n++, YL += 32, YR += 32 ) {                        *YL = 0;                        *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++);                    }                    facR = MPC_MULTIPLY_SCF( Cc[Res_R[Band]] , (unsigned char)SCF_Index_R[Band][2]);                    for ( ; n < 36; n++, YL += 32, YR += 32 ) {                        *YL = 0;                        *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++);                    }                } else {    // L==0, R==0                    for ( n = 0; n < 36; n++, YL += 32, YR += 32 ) {                        *YR = *YL = 0;                    }                }            }        }    }}/****************************************** SV 6 ******************************************/voidMPC_decoder::Lese_Bitstrom_SV6 ( void ){    mpc_int32_t n,k;    mpc_int32_t Max_used_Band=0;    HuffmanTyp *Table;    const HuffmanTyp *x1;    const HuffmanTyp *x2;    mpc_int32_t *L;    mpc_int32_t *R;    mpc_int32_t *ResL = Res_L;    mpc_int32_t *ResR = Res_R;    /************************ HEADER **************************/    ResL = Res_L;    ResR = Res_R;    for (n=0; n<=Max_Band; ++n, ++ResL, ++ResR)    {        if      (n<11)           Table = Region_A;        else if (n>=11 && n<=22) Table = Region_B;        else /*if (n>=23)*/      Table = Region_C;

⌨️ 快捷键说明

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