📄 mpegsub.c
字号:
SUB_TYPE *buf0, *buf1; SUB_TYPE *buf_ptr; INT16 b_offset = mpegsub->b_offset[ channel ]; MPEGAUD_FRACT_TYPE *bb = &mpegsub->bb[ channel ][ 0 ]; if( b_offset & 1 ) { // Odd buf0 = &bb[ MPA_HANNING_SIZE + b_offset ]; buf1 = &bb[ b_offset ]; buf_ptr = &bb[ MPA_HANNING_SIZE ]; } else { // Even buf0 = &bb[ b_offset ]; buf1 = &bb[ MPA_HANNING_SIZE + b_offset ]; buf_ptr = &bb[ 0 ]; }#if defined(ASM_OPTIMIZE) || defined(COLDFIRE_ASM_2)#ifdef MPEGAUD_INT// MPEGSUBB_filter_band( bandPtr, buf0, buf1 ); MPEGSUBB_filter_band( bandPtr, buf0, buf1, mpegsub->freq_div ); // #6#else// MPEGSUBF_filter_band( bandPtr, buf0, buf1 ); MPEGSUBF_filter_band( bandPtr, buf0, buf1, mpegsub->freq_div ); // #6#endif#else fast_dct( bandPtr, buf0, buf1, mpegsub->freq_div );#endif#if defined(ASM_OPTIMIZE) || defined(COLDFIRE_ASM_2)#ifdef MPEGAUD_INT// MPEGSUBB_window_band( buf_ptr, samples, b_offset ); MPEGSUBB_window_band( buf_ptr, samples, mpegsub->scaled_dewindow /* #7 */, b_offset, mpegsub->w_begin, mpegsub->w_width, mpegsub->freq_div, mpegsub->scaled_shift /* #7 */ ); // #6#else// MPEGSUBF_window_band( buf_ptr, samples, b_offset ); MPEGSUBF_window_band( buf_ptr, samples, mpegsub->scaled_dewindow /* #7 */, b_offset, mpegsub->w_begin, mpegsub->w_width, mpegsub->freq_div ); // #6#endif#else { INT16 start, top, cnt0, cnt1, off0, off1, offd; INT16 *samp; register SUB_DCT_TYPE sum; register const SUB_TYPE *dewindow; register INT16 j;// #7 Begin#ifdef MPEGAUD_INT INT32 dew_shift = mpegsub->scaled_shift + SUB_BAND_BITS - 16 + SUB_OUT_BITS - 15;#endif// #7 End samp = samples; start = (mpegsub->w_begin + b_offset) & 15; top = start + mpegsub->w_width; if( top > 16 ) top = 16; cnt1 = top - start; // From start to ... cnt0 = mpegsub->w_width - cnt1; // From 0 to ... off1 = mpegsub->freq_div*16 - cnt1; off0 = mpegsub->freq_div*16 - cnt0; offd = mpegsub->freq_div*16 - mpegsub->w_width; buf1 = &buf_ptr[ start ]; buf0 = &buf_ptr[ 0 ];// dewindow = &MPT_dewindow[ mpegsub->w_begin ]; // #7 Removed dewindow = &(mpegsub->scaled_dewindow[ mpegsub->w_begin ]); // #7 Scaled dewindow j = mpegsub->pcm_count; // #3 Begin: NEW_WIN#define MULTS sum = MULT_DEW( *dewindow++, *buf1++ )#define MULT0 sum += MULT_DEW( *dewindow++, *buf1++ )#define MULT1 sum += MULT_DEW( *dewindow++, *buf0++ )#ifdef DETECT_CLIP#define STORE buf1 += off1; buf0 += off0; dewindow += offd;\ sum = SCALE_DEW( sum );\ if( sum > (SUB_TYPE)32767 ) sum = (SUB_TYPE)32767;\ else if( sum < (SUB_TYPE)-32768 ) sum = (SUB_TYPE)-32768;\ *samp++ = (INT16)sum;#else#define STORE buf1 += off1; buf0 += off0; dewindow += offd;\ sum = SCALE_DEW( sum );\ *samp++ = (INT16)sum;#endif if( mpegsub->w_width <= 4 ) { switch( cnt0 ) { case 0: while( j-- ) { MULTS; MULT0; MULT0; MULT0; STORE; } break; case 1: while( j-- ) { MULTS; MULT0; MULT0; MULT1; STORE; } break; case 2: while( j-- ) { MULTS; MULT0; MULT1; MULT1; STORE; } break; case 3: while( j-- ) { MULTS; MULT1; MULT1; MULT1; STORE; } break; } } else if( mpegsub->w_width <= 8 ) { switch( cnt0 ) { case 0: while( j-- ) { MULTS; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; STORE; } break; case 1: while( j-- ) { MULTS; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT1; STORE; } break; case 2: while( j-- ) { MULTS; MULT0; MULT0; MULT0; MULT0; MULT0; MULT1; MULT1; STORE; } break; case 3: while( j-- ) { MULTS; MULT0; MULT0; MULT0; MULT0; MULT1; MULT1; MULT1; STORE; } break; case 4: while( j-- ) { MULTS; MULT0; MULT0; MULT0; MULT1; MULT1; MULT1; MULT1; STORE; } break; case 5: while( j-- ) { MULTS; MULT0; MULT0; MULT1; MULT1; MULT1; MULT1; MULT1; STORE; } break; case 6: while( j-- ) { MULTS; MULT0; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; STORE; } break; case 7: while( j-- ) { MULTS; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; STORE; } break; } } else { switch( cnt0 ) { case 0: while( j-- ) { MULTS; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; STORE; } break; case 1: while( j-- ) { MULTS; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT1; STORE; } break; case 2: while( j-- ) { MULTS; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT1; MULT1; STORE; } break; case 3: while( j-- ) { MULTS; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT1; MULT1; MULT1; STORE; } break; case 4: while( j-- ) { MULTS; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT1; MULT1; MULT1; MULT1; STORE; } break; case 5: while( j-- ) { MULTS; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT1; MULT1; MULT1; MULT1; MULT1; STORE; } break; case 6: while( j-- ) { MULTS; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; STORE; } break; case 7: while( j-- ) { MULTS; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; STORE; } break; case 8: while( j-- ) { MULTS; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; STORE; } break; case 9: while( j-- ) { MULTS; MULT0; MULT0; MULT0; MULT0; MULT0; MULT0; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; STORE; } break; case 10: while( j-- ) { MULTS; MULT0; MULT0; MULT0; MULT0; MULT0; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; STORE; } break; case 11: while( j-- ) { MULTS; MULT0; MULT0; MULT0; MULT0; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; STORE; } break; case 12: while( j-- ) { MULTS; MULT0; MULT0; MULT0; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; STORE; } break; case 13: while( j-- ) { MULTS; MULT0; MULT0; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; STORE; } break; case 14: while( j-- ) { MULTS; MULT0; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; STORE; } break; case 15: while( j-- ) { MULTS; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; MULT1; STORE; } break; } } // #3 End }#endif // ASM_OPTIMIZE mpegsub->b_offset[ channel ] = (b_offset - 1) & 15; return mpegsub->pcm_count;}int MPEGSUB_reset( MPEGSUB *mpegsub )/*----------------------------------- Reset the MPEGSUB module*/{ INT16 ch; if( !mpegsub ) return -1; // Reset sub band buffer memset( mpegsub->bb, 0, MPA_MAX_CHANNELS * 2 * MPA_HANNING_SIZE * sizeof( MPEGAUD_FRACT_TYPE ) ); // Reset offsets for( ch=0; ch<MPA_MAX_CHANNELS; ch++ ) { mpegsub->b_offset[ ch ] = 0; } return 0;} /* MPEGSUB_reset */// #7 Beginint MPEGSUB_scale( MPEGSUB *mpegsub, INT32 scale_percent ) {/*-------------------------------------------------------- Set the scale of the output of synthesis filter input: scale_percent = scale in % (100 is nominal value) return 0 if Ok*/ INT16 i; if( mpegsub->scale_percent == scale_percent ) return 0; if( scale_percent <= 0 ) return -1; if( scale_percent > 10000 ) return -2;#ifdef MPEGAUD_INT { INT32 s, c; s = MPEGTAB_DEW_BITS; c = scale_percent; while( (c <= 50) && (s < 17) ) { c <<= 1; s++; } while( (c > 100) && (s > 2) ) { c >>= 1; s--; } if( s == 2 ) c = 100; // Limit max scale mpegsub->scaled_shift = s; c <<= 14; c /= 100; for( i=0; i<MPA_HANNING_SIZE; i++ ) { mpegsub->scaled_dewindow[ i ] = (MPEGTAB_DEW_TYPE)(((INT32)MPT_dewindow[ i ] * c)>>14); } }#else { REAL coeff; coeff = (REAL)(scale_percent) * (MPA_SCALE * 0.01); for( i=0; i<MPA_HANNING_SIZE; i++ ) { mpegsub->scaled_dewindow[ i ] = MPT_dewindow[ i ] * coeff; } }#endif mpegsub->scale_percent = scale_percent; return 0;}// #7 Endvoid MPEGSUB_close( MPEGSUB *mpegsub )/*------------------------------------ Close the MPEGSUB module*/{ if( !mpegsub ) return; free( mpegsub );} /* MPEGSUB_close */MPEGSUB *MPEGSUB_open( INT16 freq_div, INT16 quality )/*---------------------------------------------------- Open the MPEGSUB module*/{ MPEGSUB *mpegsub; mpegsub = (MPEGSUB *)malloc( sizeof(MPEGSUB) ); if( !mpegsub ) return NULL; (void)MPEGSUB_reset( mpegsub ); mpegsub->scale_percent = 0; // #7 MPEGSUB_scale( mpegsub, 100 ); // #7 switch( freq_div ) { case 2: mpegsub->pcm_count = MPA_SBLIMIT>>1; break; case 4: mpegsub->pcm_count = MPA_SBLIMIT>>2; break; default: mpegsub->pcm_count = MPA_SBLIMIT; freq_div = 1; break; } switch( quality ) { case 0: mpegsub->w_begin = 6; mpegsub->w_width = 4; break; case 1: mpegsub->w_begin = 4; mpegsub->w_width = 8; break; default: mpegsub->w_begin = 0; mpegsub->w_width = 16; quality = 2; break; } mpegsub->freq_div = freq_div; mpegsub->quality = quality;#if defined(ASM_OPTIMIZE) || defined(COLDFIRE_ASM_2)#ifdef MPEGAUD_INT// MPEGSUBB_config( freq_div, quality, 0 ); #6#else// MPEGSUBF_config( freq_div, quality, 0 ); #6#endif#endif return mpegsub;} /* MPEGSUB_open */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -