diff --git a/lib_com/options.h b/lib_com/options.h index b5063ecf3954295412f94ce99af490a76d7883cf..e53bac6a6f78546fa901f225b7143aa8f9aaabe0 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -175,9 +175,10 @@ #define FIX_GET_DELAY_RETURN /* Issue 223: change return data type in function get_delay() */ #define NTT_REDUC_COMP_POC /* NTT Contribution 10: Complexity reduction of phase spectrum in stereo downmix*/ #define FIX_ISM_DECODER_PRINTOUT /* Issue 229: fix ISM decoder printout */ +#define FIX_ITD_CNG /* Eri: Fix for CNG ITD */ +#define FIX_VBR_COMPLEXITY /* Issue 234: fix extremely high complexity numbers for IVAS EVS mode */ -#define FIX_ITD_CNG /* Eri: Fix for CNG ITD */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_com/wi.c b/lib_com/wi.c index e63c0a4b92ef176ea7329058bb4ca61e357821bf..b0d16671b043d4e02e175df858bc9018af7df377 100644 --- a/lib_com/wi.c +++ b/lib_com/wi.c @@ -42,6 +42,10 @@ #include "rom_com.h" #include "wmops.h" +#ifdef FIX_VBR_COMPLEXITY +#define WMC_TOOL_MAN +#endif + /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ @@ -73,13 +77,18 @@ ivas_error DTFS_new( int16_t i; DTFS_STRUCTURE *dtfs = NULL; - dtfs = (DTFS_STRUCTURE *) count_malloc( sizeof( DTFS_STRUCTURE ) ); + dtfs = (DTFS_STRUCTURE *) dynamic_malloc( sizeof( DTFS_STRUCTURE ) ); if ( dtfs == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTFS (SC-VBR) structure\n" ) ); } +#ifdef FIX_VBR_COMPLEXITY + MOVE( 2 ); + LOOP( 1 ); + MOVE( 2 ); +#endif dtfs->lag = 0; dtfs->nH = 0; dtfs->nH_4kHz = 0; @@ -110,6 +119,26 @@ void DTFS_copy( ) { int16_t k; +#ifdef FIX_VBR_COMPLEXITY + LOOP( 1 ); + for ( k = 0; k < MAXLAG_WI; k++ ) + { + MOVE( 1 ); + Xout->a[k] = Xinp.a[k]; + } + LOOP( 1 ); + for ( k = 0; k < MAXLAG_WI; k++ ) + { + MOVE( 1 ); + Xout->b[k] = Xinp.b[k]; + } + MOVE( 1 ); + Xout->lag = Xinp.lag; + Xout->nH = Xinp.nH; + Xout->nH_4kHz = Xinp.nH_4kHz; + Xout->upper_cut_off_freq_of_interest = Xinp.upper_cut_off_freq_of_interest; + Xout->upper_cut_off_freq = Xinp.upper_cut_off_freq; +#else for ( k = 0; k < MAXLAG_WI; k++ ) { Xout->a[k] = Xinp.a[k]; @@ -123,6 +152,7 @@ void DTFS_copy( Xout->nH_4kHz = Xinp.nH_4kHz; Xout->upper_cut_off_freq_of_interest = Xinp.upper_cut_off_freq_of_interest; Xout->upper_cut_off_freq = Xinp.upper_cut_off_freq; +#endif return; } @@ -142,6 +172,34 @@ void DTFS_sub( ) { int16_t i; + +#ifdef FIX_VBR_COMPLEXITY + MULT( 1 ); + LOOP( 1 ); + for ( i = 0; i <= X1.lag / 2; i++ ) + { + MOVE( 1 ); + MULT( 1 ); + tmp->a[i] = X1.a[i]; + MOVE( 1 ); + tmp->b[i] = X1.b[i]; + } + MULT( 1 ); + LOOP( 1 ); + for ( i = 0; i <= X2.lag / 2; i++ ) + { + MAC( 1 ); + tmp->a[i] -= X2.a[i]; + ADD( 1 ); + tmp->b[i] -= X2.b[i]; + } + MOVE( 1 ); + tmp->lag = max( X1.lag, X2.lag ); + tmp->nH = max( X1.nH, X2.nH ); + tmp->nH_4kHz = max( X1.nH_4kHz, X2.nH_4kHz ); + tmp->upper_cut_off_freq_of_interest = X1.upper_cut_off_freq_of_interest; + tmp->upper_cut_off_freq = X1.upper_cut_off_freq; +#else for ( i = 0; i <= X1.lag / 2; i++ ) { tmp->a[i] = X1.a[i]; @@ -157,6 +215,7 @@ void DTFS_sub( tmp->nH_4kHz = max( X1.nH_4kHz, X2.nH_4kHz ); tmp->upper_cut_off_freq_of_interest = X1.upper_cut_off_freq_of_interest; tmp->upper_cut_off_freq = X1.upper_cut_off_freq; +#endif return; } @@ -181,6 +240,43 @@ static void DTFS_fast_fs_inv( N = X1_DTFS->lag; } +#ifdef FIX_VBR_COMPLEXITY + /* Populate the dbuf array */ + dbuf[1] = X1_DTFS->a[0]; + dbuf[2] = 0.0; + for ( i = 1; i < M_2; i++ ) + { + MAC( 1 ); + dbuf[2 * i + 1] = X1_DTFS->a[i] * N_2; + MAC( 1 ); + dbuf[2 * i + 2] = X1_DTFS->b[i] * N_2; + } + + if ( N_2 != M_2 ) + { + dbuf[2 * i + 1] = X1_DTFS->a[i] * N_2; + dbuf[2 * i + 2] = X1_DTFS->b[i] * N_2; + i++; + } + + /* Zero-padding in the frequency domain */ + for ( ; i < N_2; i++ ) + { + MOVE( 1 ); + MAC( 2 ); + dbuf[2 * i + 1] = dbuf[2 * i + 2] = 0.0; + } + + FUNC( 3 ); + realft( dbuf, N_2, -1 ); + + for ( i = 1; i <= N; i++ ) + { + MULT( 1 ); + ADD( 1 ); + out[i - 1] = dbuf[i] / N_2; + } +#else /* Populate the dbuf array */ dbuf[1] = X1_DTFS->a[0]; dbuf[2] = 0.0; @@ -209,6 +305,7 @@ static void DTFS_fast_fs_inv( { out[i - 1] = dbuf[i] / N_2; } +#endif return; } @@ -236,6 +333,95 @@ static float DTFS_alignment_weight( float pwf = 0.7f, tmplpc[M + 1]; DTFS_STRUCTURE X1_DTFS; +#ifdef FIX_VBR_COMPLEXITY + FUNC( 2 ); + DTFS_copy( &X1_DTFS, refX1_DTFS ); + FUNC( 2 ); + DTFS_adjustLag( &X1_DTFS, X2_DTFS.lag ); + FUNC( 3 ); + ADD( 1 ); + DTFS_poleFilter( &X1_DTFS, LPC1, M + 1 ); + MOVE( 1 ); + tmp = 1.0; + LOOP( 1 ); + for ( k = 0, tmp = 1.0; k < M + 1; k++ ) + { + MOVE( 1 ); + MULT( 2 ); + tmplpc[k] = LPC1[k] * ( tmp *= pwf ); + } + + + FUNC( 3 ); + DTFS_zeroFilter( &X1_DTFS, tmplpc, M + 1 ); + FUNC( 3 ); + DTFS_poleFilter( &X2_DTFS, LPC2, M + 1 ); + MOVE( 1 ); + LOOP( 1 ); + for ( k = 0, tmp = 1.0; k < M + 1; k++ ) + { + /* can be stored as a table */ + MULT( 1 ); + tmplpc[k] = LPC2[k] * ( tmp *= pwf ); + } + FUNC( 3 ); + DTFS_zeroFilter( &X2_DTFS, tmplpc, M + 1 ); + MOVE( 1 ); + ADD( 1 ); + maxcorr = (float) -HUGE_VAL; + MOVE( 1 ); + fshift = Eshift; + MOVE( 1 ); + MULT( 1 ); + Adiff = max( 6, 0.15f * X2_DTFS.lag ); + LOGIC( 1 ); + if ( X2_DTFS.lag < 60 ) + { + MOVE( 1 ); + diff = 0.25; + } + else + { + MOVE( 1 ); + diff = 0.5; + } + ADD( 1 ); + ADD( 1 ); + LOOP( 1 ); + for ( n = Eshift - Adiff; n <= Eshift + Adiff; n += diff ) + { + MOVE( 2 ); + ADD( 1 ); + corr = tmp = 0.0f; + /* bit-exact optimization - PI2/X2_DTFS.lag should be counted as a single divide */ + MULT( 1 ); + tmp1 = (float) ( PI2 * n / X2_DTFS.lag ); + ADD( 1 ); + LOOP( 1 ); + for ( k = 0; k <= min( X2_DTFS.lag >> 1, X2_DTFS.nH_4kHz ); k++, tmp += tmp1 ) + { + /* Not counting math function cos and sin since they will be implemented as look-up tables */ + MAC( 1 ); + ADD( 1 ); + corr += (float) ( ( X1_DTFS.a[k] * X2_DTFS.a[k] + X1_DTFS.b[k] * X2_DTFS.b[k] ) * cos( tmp ) ); + MAC( 1 ); + ADD( 1 ); + corr += (float) ( ( X1_DTFS.b[k] * X2_DTFS.a[k] - X1_DTFS.a[k] * X2_DTFS.b[k] ) * sin( tmp ) ); + } + MOVE( 1 ); + MAC( 2 ); + ABS( 1 ); + wcorr = (float) ( corr * ( 1.0f - 0.01f * fabs( n - Eshift ) ) ); + LOGIC( 1 ); + if ( wcorr > maxcorr ) + { + MOVE( 1 ); + fshift = n; + MOVE( 1 ); + maxcorr = wcorr; + } + } +#else DTFS_copy( &X1_DTFS, refX1_DTFS ); DTFS_adjustLag( &X1_DTFS, X2_DTFS.lag ); DTFS_poleFilter( &X1_DTFS, LPC1, M + 1 ); @@ -283,6 +469,7 @@ static float DTFS_alignment_weight( maxcorr = wcorr; } } +#endif return fshift; } @@ -303,6 +490,53 @@ float DTFS_alignment_full( int16_t k; float maxcorr, corr, tmp, tmp1, fshift, n, diff; +#ifdef FIX_VBR_COMPLEXITY + LOGIC( 1 ); + if ( X1_DTFS.lag < X2_DTFS.lag ) + { + FUNC( 2 ); + DTFS_zeroPadd( X2_DTFS.lag, &X1_DTFS ); + } + + MOVE( 1 ); + ADD( 1 ); + maxcorr = (float) -HUGE_VAL; + /* bit-exact optimization - 1/num_steps can be constant => should be counted as a multiply */ + MOVE( 1 ); + MULT( 1 ); + diff = (float) X2_DTFS.lag / num_steps; + + LOOP( 1 ); + for ( fshift = n = 0.0; n < (float) X2_DTFS.lag; n += diff ) + { + MOVE( 2 ); + corr = tmp = 0.0f; + MOVE( 1 ); + MULT( 2 ); + tmp1 = (float) ( PI2 * n / X2_DTFS.lag ); + ADD( 1 ); + + LOOP( 1 ); + for ( k = 0; k <= min( X2_DTFS.lag >> 1, X2_DTFS.nH_4kHz ); k++, tmp += tmp1 ) + + { + MAC( 1 ); + ADD( 2 ); + corr += (float) ( ( X1_DTFS.a[k] * X2_DTFS.a[k] + X1_DTFS.b[k] * X2_DTFS.b[k] ) * cos( tmp ) ); + MAC( 1 ); + ADD( 1 ); + corr += (float) ( ( X1_DTFS.b[k] * X2_DTFS.a[k] - X1_DTFS.a[k] * X2_DTFS.b[k] ) * sin( tmp ) ); + } + LOGIC( 1 ); + if ( corr > maxcorr ) + { + MOVE( 1 ); + fshift = n; + MOVE( 1 ); + maxcorr = corr; + } + } +#else if ( X1_DTFS.lag < X2_DTFS.lag ) { DTFS_zeroPadd( X2_DTFS.lag, &X1_DTFS ); @@ -329,6 +563,7 @@ float DTFS_alignment_full( maxcorr = corr; } } +#endif return fshift; } @@ -350,12 +585,30 @@ void DTFS_phaseShift( { int16_t k; float tmp, tmp2 = 0.0f; + +#ifdef FIX_VBR_COMPLEXITY + ADD( 1 ); + LOOP( 1 ); + for ( k = 0; k <= min( X->lag >> 1, X->nH ); k++, tmp2 += ph ) + { + MOVE( 1 ); + ADD( 1 ); + tmp = X->a[k]; + MOVE( 1 ); + MAC( 1 ); + X->a[k] = (float) ( tmp * cos( tmp2 ) - X->b[k] * sin( tmp2 ) ); + MOVE( 1 ); + MAC( 1 ); + X->b[k] = (float) ( tmp * sin( tmp2 ) + X->b[k] * cos( tmp2 ) ); + } +#else for ( k = 0; k <= min( X->lag >> 1, X->nH ); k++, tmp2 += ph ) { tmp = X->a[k]; X->a[k] = (float) ( tmp * cos( tmp2 ) - X->b[k] * sin( tmp2 ) ); X->b[k] = (float) ( tmp * sin( tmp2 ) + X->b[k] * cos( tmp2 ) ); } +#endif return; } @@ -375,6 +628,34 @@ void DTFS_zeroPadd( int16_t i; float diff; +#ifdef FIX_VBR_COMPLEXITY + LOGIC( 1 ); + if ( N == X->lag ) + { + return; + } + ADD( 1 ); + LOOP( 1 ); + for ( i = ( X->lag >> 1 ) + 1; i <= N >> 1; i++ ) + { + MOVE( 2 ); + X->a[i] = X->b[i] = 0.0; + } + MOVE( 1 ); + X->lag = N; + /* recompute nH for new lag */ + X->nH = (int16_t) floor( X->upper_cut_off_freq / ( 12800.0 / X->lag ) ); + MOVE( 1 ); + MULT( 1 ); + diff = 12800.0f / X->lag; + MULT( 1 ); + ADD( 1 ); + LOGIC( 1 ); + if ( X->upper_cut_off_freq - ( diff * X->nH ) >= diff ) + { + X->nH++; + } +#else if ( N == X->lag ) { return; @@ -391,6 +672,7 @@ void DTFS_zeroPadd( { X->nH++; } +#endif return; } @@ -436,6 +718,102 @@ void DTFS_to_fs( X->sampling_rate = INT_FS_16k; } +#ifdef FIX_VBR_COMPLEXITY + X->lag = N; + MOVE( 1 ); + MULT( 1 ); + nH_band = (int16_t) floor( X->upper_cut_off_freq / ( 12800.0 / X->lag ) ); + + nH_4kHz = (int16_t) floor( 4000 / ( 12800.0 / X->lag ) ); + MOVE( 1 ); + MULT( 1 ); + diff = 12800.0f / X->lag; + MULT( 1 ); + ADD( 1 ); + LOGIC( 1 ); + if ( X->upper_cut_off_freq - ( diff * nH_band ) >= diff ) + { + nH_band++; + } + if ( 4000 - ( diff * nH_4kHz ) >= diff ) + { + nH_4kHz++; + } + /* Number of harmonics excluding the ones at 0 and at pi */ + MOVE( 1 ); + MULT( 1 ); + ADD( 1 ); + nH = ( N - 1 ) >> 1; + /* The DC component */ + X->a[0] = 0.0; + X->b[0] = 0.0; + LOOP( 1 ); + for ( n = 0; n < N; n++ ) + { + ADD( 1 ); + X->a[0] += x[n]; + } + MULT( 1 ); + X->a[0] /= N; + + /* Strictly set the DC componet to zero */ + MOVE( 1 ); + X->a[0] = 0.0; + + /* The harmonics excluding the one at pi */ + LOOP( 1 ); + for ( k = 1; k <= nH; k++ ) + { + X->a[k] = x[0]; + X->b[k] = 0.0; + MOVE( 2 ); + MULT( 1 ); + sum = tmp = (float) ( PI2 * k / N ); + LOOP( 1 ); + for ( n = 1; n < N; n++, sum += tmp ) + { + ADD( 1 ); + X->a[k] += (float) ( x[n] * cos( sum ) ); + ADD( 1 ); + X->b[k] += (float) ( x[n] * sin( sum ) ); + } + MULT( 2 ); + X->a[k] *= ( 2.0f / N ); + MULT( 2 ); + X->b[k] *= ( 2.0f / N ); + } + + /* The harmonic at 'pi' */ + LOGIC( 1 ); + if ( N % 2 == 0 ) + { + MOVE( 1 ); + X->a[k] = 0.0; + MOVE( 1 ); + tmp = 1.0; + LOOP( 1 ); + for ( n = 0; n < N; n++, tmp *= -1.0 ) + { + ADD( 1 ); + X->a[k] += x[n] * tmp; + } + MULT( 1 ); + X->a[k] /= N; + MOVE( 1 ); + X->b[k] = 0.0; + } + ADD( 1 ); + LOOP( 1 ); + for ( k = nH_band + 1; k <= min( ( X->lag >> 1 ), ( MAXLAG_WI - 1 ) ); k++ ) + { + MOVE( 1 ); + X->a[k] = 0.0; + MOVE( 1 ); + X->b[k] = 0.0; + } + X->nH = nH_band; + X->nH_4kHz = nH_4kHz; +#else X->lag = N; nH_band = (int16_t) floor( X->upper_cut_off_freq / ( 12800.0 / X->lag ) ); @@ -497,6 +875,7 @@ void DTFS_to_fs( } X->nH = nH_band; X->nH_4kHz = nH_4kHz; +#endif return; } @@ -518,6 +897,25 @@ void DTFS_fs_inv( float phase, tmp; int16_t k, n; +#ifdef FIX_VBR_COMPLEXITY + LOOP( 1 ); + for ( n = 0; n < N; n++ ) + { + MOVE( 1 ); + x[n] = X->a[0]; + MOVE( 2 ); + MAC( 1 ); + tmp = phase = (float) ( PI2 * n / X->lag + ph0 ); + ADD( 1 ); + LOOP( 1 ); + for ( k = 1; k <= min( X->lag >> 1, X->nH ); k++, tmp += phase ) + { + MAC( 1 ); + ADD( 1 ); + x[n] += (float) ( X->a[k] * cos( tmp ) + X->b[k] * sin( tmp ) ); + } + } +#else for ( n = 0; n < N; n++ ) { x[n] = X->a[0]; @@ -527,6 +925,7 @@ void DTFS_fs_inv( x[n] += (float) ( X->a[k] * cos( tmp ) + X->b[k] * sin( tmp ) ); } } +#endif return; } @@ -577,12 +976,21 @@ static void DTFS_transform( IVAS_ERROR( error, "Error creating DTFS structure 3" ); } +#ifdef FIX_VBR_COMPLEXITY + FUNC( 2 ); DTFS_copy( tmp1_dtfs, X ); + FUNC( 2 ); DTFS_copy( tmp2_dtfs, X2 ); + FUNC( 3 ); DTFS_fast_fs_inv( tmp1_dtfs, x1_256, 256 ); + FUNC( 3 ); DTFS_fast_fs_inv( tmp2_dtfs, x2_256, 256 ); - + MOVE( 1 ); + MAC( 1 ); + ADD( 1 ); + LOG( 1 ); tmp = (float) ( log( 1.0 - WI_THRESHLD ) / ( X.lag - N ) ); + LOOP( 1 ); for ( i = 0; i < N; i++ ) { if ( FR_flag == 0 ) @@ -591,11 +999,13 @@ static void DTFS_transform( if ( N - WI_SAMPLE_THLD > X.lag ) { /* pre-computed and stored in a table */ + MOVE( 1 ); w = (float) ( 1.0 - exp( -( i + 1 ) * tmp ) ); } else { /* can be a look-up table */ + MOVE( 1 ); w = (float) ( i + 1 ) / N; } } @@ -618,23 +1028,30 @@ static void DTFS_transform( w = (float) ( i + 1 ) / N1; } else - { w = 1.0; - } } } /* add sinc interpolation of two time domain waveforms at appropriate phase position */ - j = ( LL_OS * 10 + (int16_t) rint_new( phase[i] * LL_OS / PI2 ) ) % LL_OS; + MULT( 1 ); + DIV( 1 ); + FUNC( 1 ); + ADD( 1 ); + j = ( LL_OS * 10 + (int) rint_new( phase[i] * LL_OS / PI2 ) ) % LL_OS; if ( j < 0 ) { j = 0; } + MOVE( 1 ); + DIV( 1 ); k = j % WARP_OS_RATE; + MOVE( 1 ); + MULT( 1 ); l1 = j / WARP_OS_RATE; + MOVE( 2 ); set_f( x_r_fx, 0.0f, L_FRAME ); @@ -652,9 +1069,12 @@ static void DTFS_transform( x_r_fx[m] = x1_256[m] * temp_w + x2_256[m] * w; } + LOOP( 1 ); for ( j1 = 0, sum1 = sum2 = 0.0; j1 < OSLENGTH; j1++ ) { /* mult or div by constants should be done once outside the loop */ + DIV( 1 ); + ADD( 1 ); m = ( 1000 * LL + l1 - OSLENGTH / 2 + j1 ) % LL; if ( m < 0 ) @@ -667,32 +1087,161 @@ static void DTFS_transform( out[i] = sum1; } +#else + DTFS_copy( tmp1_dtfs, X ); + DTFS_copy( tmp2_dtfs, X2 ); + DTFS_fast_fs_inv( tmp1_dtfs, x1_256, 256 ); + DTFS_fast_fs_inv( tmp2_dtfs, x2_256, 256 ); - count_free( tmp1_dtfs ); - count_free( tmp2_dtfs ); - count_free( tmp3_dtfs ); - - return; -} - - -/*-------------------------------------------------------------------* - * DTFS_zeroFilter() - * - * DTFS zero filter response. - *-------------------------------------------------------------------*/ - -void DTFS_zeroFilter( - DTFS_STRUCTURE *X, /* i/o: DTFS to zeroFilter inplace */ - const float *LPC, /* i : LPCs */ - const int16_t N /* i : LPC order */ -) -{ - float tmp, tmp1, tmp2, sum1, sum2; - int16_t k, n; - - tmp1 = (float) ( PI2 / X->lag ); - for ( k = 0; k <= min( X->lag >> 1, X->nH ); k++ ) + tmp = (float) ( log( 1.0 - WI_THRESHLD ) / ( X.lag - N ) ); + for ( i = 0; i < N; i++ ) + { + if ( FR_flag == 0 ) + { + /* should not be counted inside the loop */ + if ( N - WI_SAMPLE_THLD > X.lag ) + { + /* pre-computed and stored in a table */ + w = (float) ( 1.0 - exp( -( i + 1 ) * tmp ) ); + } + else + { + /* can be a look-up table */ + w = (float) ( i + 1 ) / N; + } + } + else + { + if ( nrg_flag ) + { + w = (float) ( i + 1 ) / N; + } + else + { + if ( N <= tmp2_dtfs->lag ) + { + N = tmp2_dtfs->lag + 1; + } + + N1 = N - tmp2_dtfs->lag; + if ( i < N1 ) + { + w = (float) ( i + 1 ) / N1; + } + else + { + w = 1.0; + } + } + } + + /* add sinc interpolation of two time domain waveforms at + appropriate phase position */ + j = ( LL_OS * 10 + (int16_t) rint_new( phase[i] * LL_OS / PI2 ) ) % LL_OS; + + if ( j < 0 ) + { + j = 0; + } + + k = j % WARP_OS_RATE; + l1 = j / WARP_OS_RATE; + + set_f( x_r_fx, 0.0f, L_FRAME ); + + temp_w = ( 1 - w ); + + for ( j1 = 0; j1 < 12; j1++ ) + { + m = ( 1000 * LL + l1 - OSLENGTH / 2 + j1 ) % LL; + + if ( m < 0 ) + { + m = 0; + } + + x_r_fx[m] = x1_256[m] * temp_w + x2_256[m] * w; + } + + for ( j1 = 0, sum1 = sum2 = 0.0; j1 < OSLENGTH; j1++ ) + { + /* mult or div by constants should be done once outside the loop */ + m = ( 1000 * LL + l1 - OSLENGTH / 2 + j1 ) % LL; + + if ( m < 0 ) + { + m = 0; + } + + sum1 += x_r_fx[m] * sinc[k][j1]; + } + + out[i] = sum1; + } +#endif + + dynamic_free( tmp1_dtfs ); + dynamic_free( tmp2_dtfs ); + dynamic_free( tmp3_dtfs ); + + return; +} + + +/*-------------------------------------------------------------------* + * DTFS_zeroFilter() + * + * DTFS zero filter response. + *-------------------------------------------------------------------*/ + +void DTFS_zeroFilter( + DTFS_STRUCTURE *X, /* i/o: DTFS to zeroFilter inplace */ + const float *LPC, /* i : LPCs */ + const int16_t N /* i : LPC order */ +) +{ + float tmp, tmp1, tmp2, sum1, sum2; + int16_t k, n; + +#ifdef FIX_VBR_COMPLEXITY + MOVE( 1 ); + MULT( 1 ); + tmp1 = (float) ( PI2 / X->lag ); + LOOP( 1 ); + for ( k = 0; k <= min( X->lag >> 1, X->nH ); k++ ) + { + MOVE( 2 ); + MULT( 1 ); + tmp = tmp2 = k * tmp1; + /* Calculate sum1 and sum2 */ + MOVE( 1 ); + sum1 = 1.0; + MOVE( 1 ); + sum2 = 0.0; + ADD( 1 ); + LOOP( 1 ); + for ( n = 0; n < N; n++, tmp2 += tmp ) + { + MULT( 1 ); + ADD( 2 ); + sum1 += (float) ( LPC[n] * cos( tmp2 ) ); + MULT( 1 ); + ADD( 1 ); + sum2 += (float) ( LPC[n] * sin( tmp2 ) ); + } + /* Calculate the circular convolution */ + MOVE( 1 ); + tmp = X->a[k]; + MOVE( 1 ); + MAC( 1 ); + X->a[k] = tmp * sum1 - X->b[k] * sum2; + MOVE( 1 ); + MAC( 1 ); + X->b[k] = X->b[k] * sum1 + tmp * sum2; + } +#else + tmp1 = (float) ( PI2 / X->lag ); + for ( k = 0; k <= min( X->lag >> 1, X->nH ); k++ ) { tmp = tmp2 = k * tmp1; /* Calculate sum1 and sum2 */ @@ -708,6 +1257,7 @@ void DTFS_zeroFilter( X->a[k] = tmp * sum1 - X->b[k] * sum2; X->b[k] = X->b[k] * sum1 + tmp * sum2; } +#endif return; } @@ -728,6 +1278,45 @@ void DTFS_poleFilter( float tmp, tmp1, tmp2, sum1, sum2; int16_t k, n; +#ifdef FIX_VBR_COMPLEXITY + MOVE( 1 ); + MULT( 1 ); + tmp1 = (float) ( PI2 / X->lag ); + LOOP( 1 ); + for ( k = 0; k <= min( X->lag >> 1, X->nH ); k++ ) + { + MOVE( 2 ); + MULT( 1 ); + tmp = tmp2 = k * tmp1; + /* Calculate sum1 and sum2 */ + MOVE( 1 ); + sum1 = 1.0; + MOVE( 1 ); + sum2 = 0.0; + ADD( 1 ); + LOOP( 1 ); + for ( n = 0; n < N; n++, tmp2 += tmp ) + { + MULT( 1 ); + ADD( 2 ); + sum1 += (float) ( LPC[n] * cos( tmp2 ) ); + MULT( 1 ); + ADD( 1 ); + sum2 += (float) ( LPC[n] * sin( tmp2 ) ); + } + /* Calculate the circular convolution */ + MOVE( 1 ); + tmp = X->a[k]; + MAC( 1 ); + tmp2 = sum1 * sum1 + sum2 * sum2; + MAC( 1 ); + DIV( 1 ); + X->a[k] = ( tmp * sum1 + X->b[k] * sum2 ) / tmp2; + MAC( 1 ); + ADD( 1 ); + X->b[k] = ( -tmp * sum2 + X->b[k] * sum1 ) / tmp2; + } +#else tmp1 = (float) ( PI2 / X->lag ); for ( k = 0; k <= min( X->lag >> 1, X->nH ); k++ ) { @@ -746,6 +1335,7 @@ void DTFS_poleFilter( X->a[k] = ( tmp * sum1 + X->b[k] * sum2 ) / tmp2; X->b[k] = ( -tmp * sum2 + X->b[k] * sum1 ) / tmp2; } +#endif return; } @@ -765,6 +1355,28 @@ static float DTFS_setEngy( int16_t k; float en1, tmp; +#ifdef FIX_VBR_COMPLEXITY + FUNC( 1 ); + MOVE( 1 ); + en1 = DTFS_getEngy( *X_DTFS ); + LOGIC( 1 ); + if ( en1 == 0.0 ) + { + return 0.0; + } + MOVE( 1 ); + DIV( 1 ); + SQRT( 1 ); + tmp = (float) sqrt( en2 / en1 ); + LOOP( 1 ); + for ( k = 0; k <= min( X_DTFS->lag >> 1, X_DTFS->nH ); k++ ) + { + MULT( 1 ); + X_DTFS->a[k] *= tmp; + MULT( 1 ); + X_DTFS->b[k] *= tmp; + } +#else en1 = DTFS_getEngy( *X_DTFS ); if ( en1 == 0.0 ) { @@ -776,6 +1388,7 @@ static float DTFS_setEngy( X_DTFS->a[k] *= tmp; X_DTFS->b[k] *= tmp; } +#endif return en1; } @@ -795,6 +1408,58 @@ void DTFS_adjustLag( int16_t k; float en, diff; +#ifdef FIX_VBR_COMPLEXITY + LOGIC( 1 ); + if ( N == X_DTFS->lag ) + { + return; + } + + LOGIC( 1 ); + if ( N > X_DTFS->lag ) + { + + FUNC( 2 ); + DTFS_zeroPadd( N, X_DTFS ); + } + else + { + FUNC( 1 ); + MOVE( 1 ); + en = DTFS_getEngy( *X_DTFS ); + ADD( 1 ); + LOOP( 1 ); + for ( k = ( N >> 1 ) + 1; k <= min( X_DTFS->lag >> 1, X_DTFS->nH ); k++ ) + { + MOVE( 1 ); + X_DTFS->a[k] = 0.0; + MOVE( 1 ); + X_DTFS->b[k] = 0.0; + } + FUNC( 2 ); + DTFS_setEngy( X_DTFS, en ); + MOVE( 1 ); + X_DTFS->lag = N; + /* recompute nH for new lag */ + X_DTFS->nH = (int16_t) floor( X_DTFS->upper_cut_off_freq / ( 12800.0 / X_DTFS->lag ) ); + + X_DTFS->nH_4kHz = (int16_t) floor( 4000.0 / ( 12800.0 / X_DTFS->lag ) ); + MOVE( 1 ); + MULT( 1 ); + diff = 12800.0f / X_DTFS->lag; + MULT( 1 ); + ADD( 1 ); + LOGIC( 1 ); + if ( X_DTFS->upper_cut_off_freq - ( diff * X_DTFS->nH ) >= diff ) + { + X_DTFS->nH++; + } + if ( 4000.0 - ( diff * X_DTFS->nH_4kHz ) >= diff ) + { + X_DTFS->nH_4kHz++; + } + } +#else if ( N == X_DTFS->lag ) { return; @@ -828,6 +1493,7 @@ void DTFS_adjustLag( X_DTFS->nH_4kHz++; } } +#endif return; } @@ -847,6 +1513,27 @@ float DTFS_getEngy( float en; en = 0.0f; +#ifdef FIX_VBR_COMPLEXITY + LOOP( 1 ); + for ( k = 1; k <= min( ( X.lag - 1 ) >> 1, X.nH ); k++ ) + { + MAC( 1 ); + ADD( 1 ); + en += X.a[k] * X.a[k] + X.b[k] * X.b[k]; + } + MULT( 1 ); + en /= 2.0; + MULT( 1 ); + ADD( 1 ); + en += X.a[0] * X.a[0]; + LOGIC( 1 ); + if ( X.lag % 2 == 0 ) + { + MAC( 1 ); + ADD( 1 ); + en += X.a[k] * X.a[k] + X.b[k] * X.b[k]; + } +#else for ( k = 1; k <= min( ( X.lag - 1 ) >> 1, X.nH ); k++ ) { en += X.a[k] * X.a[k] + X.b[k] * X.b[k]; @@ -857,6 +1544,7 @@ float DTFS_getEngy( { en += X.a[k] * X.a[k] + X.b[k] * X.b[k]; } +#endif return en; } @@ -875,6 +1563,31 @@ void DTFS_car2pol( int16_t k; float tmp; +#ifdef FIX_VBR_COMPLEXITY + LOOP( 1 ); + for ( k = 1; k <= min( ( X->lag - 1 ) >> 1, X->nH ); k++ ) + { + MOVE( 1 ); + tmp = X->a[k]; + MOVE( 1 ); + FUNC( 2 ); + MULT( 1 ); + X->a[k] = (float) ( 0.5f * sqrt( tmp * tmp + X->b[k] * X->b[k] ) ); + MOVE( 1 ); + X->b[k] = (float) atan2( X->b[k], tmp ); + } + LOGIC( 1 ); + if ( X->lag % 2 == 0 ) + { + MOVE( 1 ); + tmp = X->a[k]; + FUNC( 2 ); + MOVE( 1 ); + X->a[k] = (float) sqrt( tmp * tmp + X->b[k] * X->b[k] ); + MOVE( 1 ); + X->b[k] = (float) atan2( X->b[k], tmp ); + } +#else for ( k = 1; k <= min( ( X->lag - 1 ) >> 1, X->nH ); k++ ) { tmp = X->a[k]; @@ -888,6 +1601,7 @@ void DTFS_car2pol( X->a[k] = (float) sqrt( tmp * tmp + X->b[k] * X->b[k] ); X->b[k] = (float) atan2( X->b[k], tmp ); } +#endif return; } @@ -906,6 +1620,32 @@ void DTFS_pol2car( int16_t k; float tmp; +#ifdef FIX_VBR_COMPLEXITY + LOOP( 1 ); + for ( k = 1; k <= min( ( X->lag - 1 ) >> 1, X->nH ); k++ ) + { + MOVE( 1 ); + tmp = X->b[k]; + MOVE( 1 ); + MULT( 2 ); + X->b[k] = (float) ( 2.0f * X->a[k] * sin( tmp ) ); + MOVE( 1 ); + MULT( 2 ); + X->a[k] = (float) ( 2.0f * X->a[k] * cos( tmp ) ); + } + LOGIC( 1 ); + if ( X->lag % 2 == 0 ) + { + MOVE( 1 ); + tmp = X->b[k]; + MOVE( 1 ); + MULT( 1 ); + X->b[k] = (float) ( X->a[k] * sin( tmp ) ); + MOVE( 1 ); + MULT( 1 ); + X->a[k] = (float) ( X->a[k] * cos( tmp ) ); + } +#else for ( k = 1; k <= min( ( X->lag - 1 ) >> 1, X->nH ); k++ ) { tmp = X->b[k]; @@ -919,6 +1659,7 @@ void DTFS_pol2car( X->b[k] = (float) ( X->a[k] * sin( tmp ) ); X->a[k] = (float) ( X->a[k] * cos( tmp ) ); } +#endif return; } @@ -947,11 +1688,20 @@ float DTFS_setEngyHarm( en1 = 0.0f; count = 0; + +#ifdef FIX_VBR_COMPLEXITY + LOGIC( 1 ); if ( f1 == 0.0 ) { + MULT( 1 ); + ADD( 1 ); en1 += X->a[0] * X->a[0]; count++; } + MOVE( 1 ); + ADD( 1 ); + ADD( 1 ); + LOOP( 1 ); for ( k = 1, tmp = diff; k <= min( ( X->lag - 1 ) >> 1, X->nH ); k++, tmp += diff ) { if ( X->a[k] < EPSILON ) @@ -959,8 +1709,11 @@ float DTFS_setEngyHarm( X->a[k] = 0; } + LOGIC( 1 ); if ( tmp > f1 && tmp <= f2 ) { + MULT( 1 ); + ADD( 1 ); en1 += X->a[k] * X->a[k]; count++; } @@ -971,6 +1724,8 @@ float DTFS_setEngyHarm( count = 1; } + + DIV( 1 ); en1 /= count; if ( en2 < 0.0 ) @@ -978,41 +1733,108 @@ float DTFS_setEngyHarm( en2 = 0.0; } + LOGIC( 1 ); if ( en1 > 0.0 ) { + MOVE( 1 ); + DIV( 1 ); + SQRT( 1 ); factor = (float) sqrt( en2 / en1 ); } else { + MOVE( 1 ); factor = 0.0f; } + LOGIC( 1 ); if ( g1 == 0.0 ) { + MULT( 1 ); X->a[k] *= factor; } + MOVE( 1 ); + ADD( 1 ); + ADD( 1 ); + LOOP( 1 ); for ( k = 1, tmp = diff; k <= min( ( X->lag - 1 ) >> 1, X->nH ); k++, tmp += diff ) { + ADD( 1 ); + ADD( 1 ); + LOGIC( 1 ); if ( tmp > g1 && tmp <= g2 ) { + MULT( 1 ); X->a[k] *= factor; } } +#else + if ( f1 == 0.0 ) + { + en1 += X->a[0] * X->a[0]; + count++; + } + for ( k = 1, tmp = diff; k <= min( ( X->lag - 1 ) >> 1, X->nH ); k++, tmp += diff ) + { + if ( X->a[k] < EPSILON ) + { + X->a[k] = 0; + } - return (float) ( en1 + 1e-20 ); -} + if ( tmp > f1 && tmp <= f2 ) + { + en1 += X->a[k] * X->a[k]; + count++; + } + } + if ( count <= 0.0 ) + { + count = 1; + } -/*-------------------------------------------------------------------* - * cubicPhase() - * - * Compute coefficients of cubic phase function - *-------------------------------------------------------------------*/ + en1 /= count; -static void cubicPhase( - float ph1, /* i : phase offset */ - float ph2, /* i : phase 2 */ - const float L1, /* i : previous lag */ - const float L2, /* i : current lag */ + if ( en2 < 0.0 ) + { + en2 = 0.0; + } + + if ( en1 > 0.0 ) + { + factor = (float) sqrt( en2 / en1 ); + } + else + { + factor = 0.0f; + } + if ( g1 == 0.0 ) + { + X->a[k] *= factor; + } + for ( k = 1, tmp = diff; k <= min( ( X->lag - 1 ) >> 1, X->nH ); k++, tmp += diff ) + { + if ( tmp > g1 && tmp <= g2 ) + { + X->a[k] *= factor; + } + } +#endif + + return (float) ( en1 + 1e-20 ); +} + + +/*-------------------------------------------------------------------* + * cubicPhase() + * + * Compute coefficients of cubic phase function + *-------------------------------------------------------------------*/ + +static void cubicPhase( + float ph1, /* i : phase offset */ + float ph2, /* i : phase 2 */ + const float L1, /* i : previous lag */ + const float L2, /* i : current lag */ int16_t N, /* i : input length */ float *phOut /* o : cubic phase output */ ) @@ -1021,6 +1843,75 @@ static void cubicPhase( int16_t n; double diff; +#ifdef FIX_VBR_COMPLEXITY + ADD( 1 ); + N -= (int16_t) L2; + + if ( N <= 0 ) + { + N = 1; + } + + /* Computation of the coefficients of the cubic phase function */ + MOVE( 1 ); + DIV( 1 ); + f1 = (float) ( PI2 / L1 ); + MOVE( 1 ); + DIV( 1 ); + f2 = (float) ( PI2 / L2 ); + MOVE( 1 ); + DIV( 1 ); + ph1 = (float) fmod( (double) ( ph1 ), PI2 ); + MOVE( 1 ); + DIV( 1 ); + ph2 = (float) fmod( (double) ( ph2 ), PI2 ); + MOVE( 1 ); + coef[3] = ph1; + MOVE( 1 ); + coef[2] = f1; + MOVE( 1 ); + MAC( 1 ); + ADD( 1 ); + FUNC( 1 ); + ADD( 1 ); + factor = (float) ( anint( ( ph1 - ph2 + 0.5 * N * ( f2 + f1 ) ) / PI2 ) ); + MOVE( 1 ); + ADD( 1 ); + c1 = f2 - f1; + MOVE( 1 ); + MAC( 1 ); + ADD( 2 ); + c2 = (float) ( ph2 - ph1 - N * f1 + PI2 * factor ); + MOVE( 1 ); + MAC( 1 ); + DIV( 1 ); + coef[0] = ( N * c1 - 2 * c2 ) / ( N * N * N ); + MOVE( 1 ); + MULT( 4 ); + DIV( 1 ); + ADD( 1 ); + coef[1] = ( c1 - 3 * N * N * coef[0] ) / ( 2 * N ); + /* Computation of the phase value at each sample point */ + MOVE( 1 ); + phOut[0] = ph1; + LOOP( 1 ); + for ( n = 1; n < N; n++ ) + { + MOVE( 1 ); + phOut[n] = _POLY3( n, coef ); + } + MOVE( 1 ); + MULT( 1 ); + diff = (float) ( PI2 / L2 ); + ADD( 1 ); + LOOP( 1 ); + for ( ; n < N + (int) L2; n++ ) + { + MOVE( 1 ); + ADD( 2 ); + phOut[n] = (float) ( phOut[n - 1] + diff ); + } +#else N -= (int16_t) L2; if ( N <= 0 ) @@ -1052,6 +1943,7 @@ static void cubicPhase( { phOut[n] = (float) ( phOut[n - 1] + diff ); } +#endif return; } @@ -1085,6 +1977,57 @@ void DTFS_to_erb( erb = &( erb_WB[0] ); } +#ifdef FIX_VBR_COMPLEXITY + LOOP( 1 ); + for ( i = 0; i < num_erb; i++ ) + { + MOVE( 1 ); + count[i] = 0; + MOVE( 1 ); + out[i] = 0.0; + } + MOVE( 1 ); + MULT( 1 ); + diff = 12800.0f / X.lag; + MOVE( 2 ); + ADD( 1 ); + LOOP( 1 ); + for ( i = j = 0, freq = 0.0; i <= min( X.lag >> 1, X.nH ); i++, freq += diff ) + { + if ( !( freq <= erb[num_erb] ) ) + { + freq = erb[num_erb]; + } + + LOOP( 1 ); + for ( ; j < num_erb; j++ ) + { + LOGIC( 1 ); + if ( freq < erb[j + 1] ) + { + if ( X.a[i] < 0.0f ) + { + X.a[i] = 0.0f; + } + + ADD( 1 ); + out[j] += X.a[i]; + count[j]++; + break; + } + } + } + LOOP( 1 ); + for ( i = 0; i < num_erb; i++ ) + { + LOGIC( 1 ); + if ( count[i] > 1 ) + { + DIV( 1 ); + out[i] /= count[i]; + } + } +#else for ( i = 0; i < num_erb; i++ ) { count[i] = 0; @@ -1120,6 +2063,7 @@ void DTFS_to_erb( out[i] /= count[i]; } } +#endif return; } @@ -1155,6 +2099,68 @@ void erb_slot( upper_cut_off_freq = 6400; erb = &( erb_WB[0] ); } + +#ifdef FIX_VBR_COMPLEXITY + MOVE( 1 ); + MULT( 1 ); + nH_band = (int16_t) floor( upper_cut_off_freq / ( 12800.0 / lag ) ); + + LOOP( 1 ); + for ( i = 0; i < num_erb; i++ ) + { + MOVE( 1 ); + out[i] = 0; + MOVE( 1 ); + mfreq[i] = 0.0; + } + MOVE( 1 ); + MULT( 1 ); + diff = 12800.0f / lag; + MULT( 1 ); + ADD( 1 ); + LOGIC( 1 ); + if ( upper_cut_off_freq - ( diff * nH_band ) >= diff ) + { + nH_band++; + } + MOVE( 2 ); + ADD( 1 ); + LOOP( 1 ); + for ( i = j = 0, freq = 0.0; i <= min( lag >> 1, nH_band ); i++, freq += diff ) + { + + if ( !( freq <= erb[num_erb] ) ) + { + freq = erb[num_erb]; + } + + MOVE( 1 ); + freq = min( freq, upper_cut_off_freq ); + + LOOP( 1 ); + for ( ; j < num_erb; j++ ) + { + LOGIC( 1 ); + if ( freq < erb[j + 1] ) + { + ADD( 1 ); + mfreq[j] += freq; + out[j]++; + break; + } + } + } + LOOP( 1 ); + for ( j = 0; j < num_erb; j++ ) + { + LOGIC( 1 ); + if ( out[j] > 1 ) + { + DIV( 1 ); + mfreq[j] /= out[j]; + } + } +#else nH_band = (int16_t) floor( upper_cut_off_freq / ( 12800.0 / lag ) ); for ( i = 0; i < num_erb; i++ ) @@ -1195,6 +2201,7 @@ void erb_slot( mfreq[j] /= out[j]; } } +#endif return; } @@ -1232,6 +2239,80 @@ void DTFS_erb_inv( erb = &( erb_WB[0] ); } +#ifdef FIX_VBR_COMPLEXITY + MOVE( 1 ); + f[m] = 0.0; + MOVE( 1 ); + amp[m] = 0.0; + m++; + LOOP( 1 ); + for ( i = 0; i < num_erb; i++ ) + { + LOGIC( 1 ); + if ( slot[i] != 0 ) + { + MOVE( 1 ); + f[m] = mfreq[i]; + MOVE( 1 ); + amp[m] = in[i]; + m++; + } + } + MOVE( 1 ); + f[m] = upper_cut_off_freq; + MOVE( 1 ); + amp[m] = 0.0; + m++; + + MOVE( 1 ); + MULT( 1 ); + diff = 12800.0f / X->lag; + + MOVE( 2 ); + ADD( 1 ); + LOOP( 1 ); + for ( i = 0, j = 1, freq = 0.0; i <= min( X->lag >> 1, X->nH ); i++, freq += diff ) + { + if ( !( freq <= erb[num_erb] ) ) + { + freq = erb[num_erb]; + } + + if ( !( m <= num_erb + 2 ) ) + { + m = num_erb + 2; + } + + LOGIC( 1 ); + if ( freq > upper_cut_off_freq ) + { + MOVE( 1 ); + freq = upper_cut_off_freq; + } + LOOP( 1 ); + for ( ; j < m; j++ ) + { + LOGIC( 1 ); + if ( freq <= f[j] ) + { + MOVE( 1 ); + MAC( 2 ); + ADD( 1 ); + X->a[i] = amp[j] * ( freq - f[j - 1] ) + amp[j - 1] * ( f[j] - freq ); + LOGIC( 1 ); + if ( f[j] != f[j - 1] ) + { + DIV( 1 ); + ADD( 1 ); + X->a[i] /= ( f[j] - f[j - 1] ); + } + break; + } + } + + X->a[0] = 0.0f; + } +#else f[m] = 0.0; amp[m] = 0.0; m++; @@ -1273,85 +2354,355 @@ void DTFS_erb_inv( X->a[i] = amp[j] * ( freq - f[j - 1] ) + amp[j - 1] * ( f[j] - freq ); if ( f[j] != f[j - 1] ) { - X->a[i] /= ( f[j] - f[j - 1] ); + X->a[i] /= ( f[j] - f[j - 1] ); + } + break; + } + } + + X->a[0] = 0.0f; + } +#endif + + return; +} + + +/*-------------------------------------------------------------------* + * LPCPowSpect() + * + * LPC power spectrum + *-------------------------------------------------------------------*/ + +static void LPCPowSpect( + const float *freq, /* i : ERB frequencies */ + const int16_t Nf, /* i : Number of ERBs */ + const float *LPC, /* i : LPC coefficients */ + const int16_t Np, /* i : Number of LPCs */ + float *out /* o : LPC power spectrum */ +) +{ + float w, tmp, Re, Im; + int16_t i, k; + +#ifdef FIX_VBR_COMPLEXITY + LOOP( 1 ); + for ( k = 0; k < Nf; k++ ) + { + MOVE( 1 ); + Re = 1.0; + MOVE( 1 ); + Im = 0.0; + /* Note that freq ranges between [0 UPPER_CUT_OFF_FREQ] */ + MOVE( 1 ); + MULT( 2 ); + tmp = (float) ( freq[k] / 12800.0f * PI2 ); + MOVE( 1 ); + ADD( 1 ); + LOOP( 1 ); + for ( i = 0, w = tmp; i < Np; i++, w += tmp ) + { + MULT( 1 ); + ADD( 2 ); + Re += (float) ( LPC[i] * cos( w ) ); + MULT( 1 ); + ADD( 1 ); + Im -= (float) ( LPC[i] * sin( w ) ); + } + MOVE( 1 ); + MAC( 1 ); + DIV( 1 ); + out[k] = 1.0f / ( Re * Re + Im * Im ); + } +#else + for ( k = 0; k < Nf; k++ ) + { + Re = 1.0; + Im = 0.0; + /* Note that freq ranges between [0 UPPER_CUT_OFF_FREQ] */ + tmp = (float) ( freq[k] / 12800.0f * PI2 ); + for ( i = 0, w = tmp; i < Np; i++, w += tmp ) + { + Re += (float) ( LPC[i] * cos( w ) ); + Im -= (float) ( LPC[i] * sin( w ) ); + } + out[k] = 1.0f / ( Re * Re + Im * Im ); + } +#endif + + return; +} + + +/*-------------------------------------------------------------------* + * erb_diff() + * + * ERB difference + *-------------------------------------------------------------------*/ + +void erb_diff( + const float *prev_erb, /* i : previous ERB */ + const int16_t pl, /* i : previous lag */ + const float *curr_erb, /* i : current ERB */ + const int16_t l, /* i : current lag */ + const float *curr_lsp, /* i : current LSP coefficients */ + float *out, /* o : ERB difference */ + int16_t *index, /* i : ERB index */ + const int16_t num_erb /* i : Number of ERBs */ +) +{ + int16_t i, j; + int16_t pslot[NUM_ERB_WB], cslot[NUM_ERB_WB], mmseindex; + float tmp, tmp1, t_prev_erb[NUM_ERB_WB], LPC[M + 1], mfreq[NUM_ERB_WB], PowSpect[NUM_ERB_WB], mmse; + const float( *AmpCB1 )[10] = 0; + + if ( num_erb == NUM_ERB_NB ) + { + AmpCB1 = AmpCB1_NB; + } + else if ( num_erb == NUM_ERB_WB ) + { + AmpCB1 = AmpCB1_WB; + } + +#ifdef FIX_VBR_COMPLEXITY + FUNC( 3 ); + erb_slot( l, cslot, mfreq, num_erb ); + FUNC( 3 ); + erb_slot( pl, pslot, t_prev_erb, num_erb ); + MOVE( 1 ); + ADD( 1 ); + LOOP( 1 ); + for ( i = 0, tmp = 1.0f; i < M + 1; i++ ) + { + MOVE( 1 ); + MULT( 2 ); + ADD( 1 ); + LPC[i] = curr_lsp[i] * ( tmp *= 0.78f ); + } + FUNC( 5 ); + ADD( 1 ); + LPCPowSpect( mfreq, num_erb, LPC, M + 1, PowSpect ); + + LOOP( 1 ); + for ( i = 0; i < num_erb; i++ ) + { + MOVE( 1 ); + t_prev_erb[i] = prev_erb[i]; + } + + LOGIC( 1 ); + if ( pl > l ) + { + MOVE( 1 ); + tmp = t_prev_erb[0]; + LOOP( 1 ); + for ( i = 0; i < num_erb; i++ ) + { + if ( pslot[i] < 0 ) + { + pslot[i] = 0; + } + + LOGIC( 1 ); + if ( pslot[i] != 0 ) + { + MOVE( 1 ); + tmp = t_prev_erb[i]; + } + else + { + MOVE( 1 ); + t_prev_erb[i] = tmp; + } + } + } + else if ( l > pl ) + { + MOVE( 1 ); + tmp = t_prev_erb[num_erb - 1]; + ADD( 1 ); + LOOP( 1 ); + for ( i = num_erb - 1; i >= 0; i-- ) + { + LOGIC( 1 ); + if ( pslot[i] != 0 ) + { + MOVE( 1 ); + tmp = t_prev_erb[i]; + } + else + { + MOVE( 1 ); + t_prev_erb[i] = tmp; + } + } + } + + LOOP( 1 ); + for ( i = 0; i < num_erb; i++ ) + { + MOVE( 1 ); + ADD( 1 ); + out[i] = curr_erb[i] - t_prev_erb[i]; + } + + /* First Band Amplitude Search */ + MOVE( 1 ); + mmse = (float) HUGE_VAL; + MOVE( 1 ); + mmseindex = -1; + LOOP( 1 ); + for ( j = 0; j < ERB_CBSIZE1; j++ ) + { + MOVE( 1 ); + tmp = 0.0; + LOOP( 1 ); + for ( i = 1; i < 11; i++ ) + { + LOGIC( 1 ); + if ( cslot[i] != 0 ) + { + ADD( 1 ); + LOGIC( 1 ); + if ( AmpCB1[j][i - 1] < -t_prev_erb[i] ) + { + MOVE( 1 ); + MULT( 1 ); + MULT( 1 ); + tmp1 = PowSpect[i] * SQR( curr_erb[i] ); + } + else + { + MOVE( 1 ); + MAC( 1 ); + MULT( 1 ); + tmp1 = (float) ( PowSpect[i] * SQR( out[i] - AmpCB1[j][i - 1] ) ); } - break; + LOGIC( 1 ); + if ( AmpCB1[j][i - 1] < out[i] ) + { + MULT( 1 ); + tmp1 *= 0.9f; + } + ADD( 1 ); + tmp += tmp1; } } - X->a[0] = 0.0f; + LOGIC( 1 ); + if ( tmp < mmse ) + { + MOVE( 1 ); + mmse = tmp; + MOVE( 1 ); + mmseindex = j; + } } - return; -} - - -/*-------------------------------------------------------------------* - * LPCPowSpect() - * - * LPC power spectrum - *-------------------------------------------------------------------*/ - -static void LPCPowSpect( - const float *freq, /* i : ERB frequencies */ - const int16_t Nf, /* i : Number of ERBs */ - const float *LPC, /* i : LPC coefficients */ - const int16_t Np, /* i : Number of LPCs */ - float *out /* o : LPC power spectrum */ -) -{ - float w, tmp, Re, Im; - int16_t i, k; - - for ( k = 0; k < Nf; k++ ) + if ( !( mmseindex < ERB_CBSIZE1 && mmseindex >= 0 ) ) { - Re = 1.0; - Im = 0.0; - /* Note that freq ranges between [0 UPPER_CUT_OFF_FREQ] */ - tmp = (float) ( freq[k] / 12800.0f * PI2 ); - for ( i = 0, w = tmp; i < Np; i++, w += tmp ) - { - Re += (float) ( LPC[i] * cos( w ) ); - Im -= (float) ( LPC[i] * sin( w ) ); - } - out[k] = 1.0f / ( Re * Re + Im * Im ); + mmseindex = 0; } - return; -} + MOVE( 1 ); + index[0] = mmseindex; + /* Second Band Amplitude Search */ + MOVE( 1 ); + mmse = (float) HUGE_VAL; + MOVE( 1 ); + mmseindex = -1; + LOOP( 1 ); + for ( j = 0; j < ERB_CBSIZE2; j++ ) + { + MOVE( 1 ); + tmp = 0.0; + for ( i = 11; i < num_erb; i++ ) + { + if ( num_erb == NUM_ERB_NB ) + { + LOGIC( 1 ); + if ( cslot[i] != 0 ) + { + ADD( 1 ); + LOGIC( 1 ); + if ( AmpCB2_NB[j][i - 11] < -t_prev_erb[i] ) + { + MOVE( 1 ); + MULT( 1 ); + MULT( 1 ); + tmp1 = PowSpect[i] * SQR( curr_erb[i] ); + } + else + { + MOVE( 1 ); + MAC( 1 ); + MULT( 1 ); + tmp1 = (float) ( PowSpect[i] * SQR( out[i] - AmpCB2_NB[j][i - 11] ) ); + } -/*-------------------------------------------------------------------* - * erb_diff() - * - * ERB difference - *-------------------------------------------------------------------*/ + LOGIC( 1 ); + if ( AmpCB2_NB[j][i - 11] < out[i] ) + { + MULT( 1 ); + tmp1 *= 0.9f; + } + ADD( 1 ); + tmp += tmp1; + } + } + else if ( num_erb == NUM_ERB_WB ) + { + if ( cslot[i] != 0 ) + { + ADD( 1 ); + LOGIC( 1 ); + if ( AmpCB2_WB[j][i - 11] < -t_prev_erb[i] ) + { + MOVE( 1 ); + MULT( 1 ); + MULT( 1 ); + tmp1 = PowSpect[i] * SQR( curr_erb[i] ); + } + else + { + MOVE( 1 ); + MAC( 1 ); + MULT( 1 ); + tmp1 = (float) ( PowSpect[i] * SQR( out[i] - AmpCB2_WB[j][i - 11] ) ); + } -void erb_diff( - const float *prev_erb, /* i : previous ERB */ - const int16_t pl, /* i : previous lag */ - const float *curr_erb, /* i : current ERB */ - const int16_t l, /* i : current lag */ - const float *curr_lsp, /* i : current LSP coefficients */ - float *out, /* o : ERB difference */ - int16_t *index, /* i : ERB index */ - const int16_t num_erb /* i : Number of ERBs */ -) -{ - int16_t i, j; - int16_t pslot[NUM_ERB_WB], cslot[NUM_ERB_WB], mmseindex; - float tmp, tmp1, t_prev_erb[NUM_ERB_WB], LPC[M + 1], mfreq[NUM_ERB_WB], PowSpect[NUM_ERB_WB], mmse; - const float( *AmpCB1 )[10] = 0; + LOGIC( 1 ); + if ( AmpCB2_WB[j][i - 11] < out[i] ) + { + MULT( 1 ); + tmp1 *= 0.9f; + } + ADD( 1 ); + tmp += tmp1; + } + } + } - if ( num_erb == NUM_ERB_NB ) - { - AmpCB1 = AmpCB1_NB; + LOGIC( 1 ); + if ( tmp < mmse ) + { + MOVE( 1 ); + mmse = tmp; + MOVE( 1 ); + mmseindex = j; + } } - else if ( num_erb == NUM_ERB_WB ) + + if ( !( mmseindex < ERB_CBSIZE2 && mmseindex >= 0 ) ) { - AmpCB1 = AmpCB1_WB; + mmseindex = 0; } + MOVE( 1 ); + index[1] = mmseindex; +#else erb_slot( l, cslot, mfreq, num_erb ); erb_slot( pl, pslot, t_prev_erb, num_erb ); for ( i = 0, tmp = 1.0f; i < M + 1; i++ ) @@ -1509,6 +2860,7 @@ void erb_diff( } index[1] = mmseindex; +#endif return; } @@ -1540,6 +2892,115 @@ void erb_add( { AmpCB1 = AmpCB1_WB; } + +#ifdef FIX_VBR_COMPLEXITY + FUNC( 3 ); + erb_slot( l, cslot, t_prev_erb, num_erb ); + FUNC( 3 ); + erb_slot( pl, pslot, t_prev_erb, num_erb ); + + LOOP( 1 ); + for ( i = 0; i < num_erb; i++ ) + { + MOVE( 1 ); + t_prev_erb[i] = prev_erb[i]; + } + + LOGIC( 1 ); + if ( pl > l ) + { + MOVE( 1 ); + tmp = t_prev_erb[0]; + LOOP( 1 ); + for ( i = 0; i < num_erb; i++ ) + { + if ( !( pslot[i] >= 0 ) ) + { + pslot[i] = 0; + } + + LOGIC( 1 ); + if ( pslot[i] != 0 ) + { + MOVE( 1 ); + tmp = t_prev_erb[i]; + } + else + { + MOVE( 1 ); + t_prev_erb[i] = tmp; + } + } + } + else if ( l > pl ) + { + MOVE( 1 ); + tmp = t_prev_erb[num_erb - 1]; + ADD( 1 ); + LOOP( 1 ); + for ( i = num_erb - 1; i >= 0; i-- ) + { + LOGIC( 1 ); + if ( pslot[i] != 0 ) + { + MOVE( 1 ); + tmp = t_prev_erb[i]; + } + else + { + MOVE( 1 ); + t_prev_erb[i] = tmp; + } + } + } + + LOOP( 1 ); + for ( i = 1; i < 11; i++ ) + { + LOGIC( 1 ); + if ( cslot[i] != 0 ) + { + MOVE( 1 ); + ADD( 1 ); + curr_erb[i] = (float) ( AmpCB1[index[0]][i - 1] + t_prev_erb[i] ); + MOVE( 1 ); + curr_erb[i] = max( 0.0f, curr_erb[i] ); + } + else + { + MOVE( 1 ); + curr_erb[i] = 0.0; + } + } + LOOP( 1 ); + for ( i = 11; i < ( num_erb - 2 ); i++ ) + { + LOGIC( 1 ); + if ( cslot[i] != 0 ) + { + MOVE( 1 ); + if ( num_erb == NUM_ERB_NB ) + { + ADD( 1 ); + curr_erb[i] = (float) ( AmpCB2_NB[index[1]][i - 11] + t_prev_erb[i] ); + MOVE( 1 ); + curr_erb[i] = max( 0.0f, curr_erb[i] ); + } + else if ( num_erb == NUM_ERB_WB ) + { + ADD( 1 ); + curr_erb[i] = (float) ( AmpCB2_WB[index[1]][i - 11] + t_prev_erb[i] ); + MOVE( 1 ); + curr_erb[i] = max( 0.0f, curr_erb[i] ); + } + } + else + { + MOVE( 1 ); + curr_erb[i] = 0.0f; + } + } +#else erb_slot( l, cslot, t_prev_erb, num_erb ); erb_slot( pl, pslot, t_prev_erb, num_erb ); @@ -1616,10 +3077,12 @@ void erb_add( curr_erb[i] = 0.0f; } } +#endif return; } + /*-------------------------------------------------------------------* * WIsyn() * @@ -1643,7 +3106,7 @@ ivas_error WIsyn( error = IVAS_ERR_OK; - if ( ( phase = (float *) count_malloc( N * sizeof( float ) ) ) == NULL ) + if ( ( phase = (float *) dynamic_malloc( N * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for WI structure\n" ) ); } @@ -1653,6 +3116,78 @@ ivas_error WIsyn( return IVAS_ERROR( error, "Error creating new DTFS structure\n" ); } +#ifdef FIX_VBR_COMPLEXITY + FUNC( 2 ); + DTFS_copy( CURRCW_DTFS, *CURRCW_DTFS_out ); + + /* Calculating the expected alignment shift */ + MOVE( 1 ); + MULT( 2 ); + INDIRECT( 1 ); + INDIRECT( 1 ); + alignment = (float) ( *ph_offset / PI2 * PREVCW.lag ); + LOGIC( 1 ); + if ( flag == 1 ) + { + MULT( 1 ); + alignment *= I; + } + /* Calculating the expected alignment shift */ + MOVE( 1 ); + DIV( 1 ); + ADD( 2 ); + DIV( 1 ); + tmp = (float) fmod( ( N % ( ( PREVCW.lag + CURRCW_DTFS->lag ) >> 1 ) + alignment ), CURRCW_DTFS->lag ); + + /* Compute the alignment shift */ + if ( FR_flag == 0 ) + { + FUNC( 5 ); + MOVE( 1 ); + alignment = DTFS_alignment_weight( PREVCW, *CURRCW_DTFS, tmp, curr_lpc, curr_lpc ); + } + else /* FR case */ + { + FUNC( 5 ); + MOVE( 1 ); + alignment = DTFS_alignment_full( PREVCW, *CURRCW_DTFS, CURRCW_DTFS->lag * 2 ); + } + + MOVE( 1 ); + MULT( 2 ); + tmp = (float) ( PI2 * alignment / CURRCW_DTFS->lag ); + FUNC( 2 ); + DTFS_phaseShift( CURRCW_DTFS, tmp ); + FUNC( 2 ); + MULT( 2 ); + DTFS_phaseShift( CURRCW_DTFS_out, (float) ( PI2 * alignment / CURRCW_DTFS->lag ) ); + + /* Compute the cubic phase track and transform to 1-D signal */ + FUNC( 6 ); + cubicPhase( *ph_offset, tmp, (float) PREVCW.lag, (float) CURRCW_DTFS->lag, N, phase ); + + if ( FR_flag == 0 ) + { + FUNC( 6 ); + DTFS_transform( PREVCW, *CURRCW_DTFS, phase, out, N, 0 ); + } + else + { + FUNC( 6 ); + DTFS_transform( PREVCW, *CURRCW_DTFS, phase, out, N, 1 ); + } + + /* Adjust the phase offset and wrap it between 0 and 2pi */ + LOGIC( 1 ); + if ( flag == 2 ) + { + MULT( 1 ); + tmp *= I; + } + MOVE( 1 ); + DIV( 1 ); + *ph_offset = (float) fmod( (double) ( tmp ), PI2 ); +#else DTFS_copy( CURRCW_DTFS, *CURRCW_DTFS_out ); /* Calculating the expected alignment shift */ @@ -1696,9 +3231,14 @@ ivas_error WIsyn( tmp *= I; } *ph_offset = (float) fmod( (double) ( tmp ), PI2 ); +#endif - count_free( phase ); - count_free( CURRCW_DTFS ); + dynamic_free( phase ); + dynamic_free( CURRCW_DTFS ); return error; } + +#ifdef FIX_VBR_COMPLEXITY +#undef WMC_TOOL_MAN +#endif diff --git a/lib_dec/dec_gen_voic.c b/lib_dec/dec_gen_voic.c index ba8f0424ea7bd145711f4812ad5739294e4881b2..0151abcbbadea0969723513e05fbf9dcc7422c01 100644 --- a/lib_dec/dec_gen_voic.c +++ b/lib_dec/dec_gen_voic.c @@ -285,8 +285,8 @@ ivas_error decod_gen_voic( } } - count_free( PREVP ); - count_free( CURRP ); + dynamic_free( PREVP ); + dynamic_free( CURRP ); } } diff --git a/lib_dec/ppp_dec.c b/lib_dec/ppp_dec.c index 24ad0146a0f3ef1f7819d3fbccb2c77935de3657..3de25cf680f9c710c892cfb5e0420814fddd08c3 100644 --- a/lib_dec/ppp_dec.c +++ b/lib_dec/ppp_dec.c @@ -177,7 +177,7 @@ ivas_error ppp_quarter_decoder( tmp = (float) get_next_indice( st, 3 ); DTFS_phaseShift( CURRCW_Q_DTFS, (float) ( PI2 * ( tmp - 3 ) / CURRCW_Q_DTFS->lag ) ); - count_free( PREVDTFS ); + dynamic_free( PREVDTFS ); return error; } diff --git a/lib_dec/voiced_dec.c b/lib_dec/voiced_dec.c index 08d58ffc7df0e364884823865f0c2652aea2fba3..cda7120103a7b8cfc7af14c0ce154c6527837cac 100644 --- a/lib_dec/voiced_dec.c +++ b/lib_dec/voiced_dec.c @@ -233,9 +233,9 @@ ivas_error ppp_voiced_decoder( mvr2r( dtfs_temp->a, hSC_VBR->dtfs_dec_a, MAXLAG_WI ); mvr2r( dtfs_temp->b, hSC_VBR->dtfs_dec_b, MAXLAG_WI ); - count_free( TMPDTFS ); - count_free( CURRP_Q_D ); - count_free( dtfs_temp ); + dynamic_free( TMPDTFS ); + dynamic_free( CURRP_Q_D ); + dynamic_free( dtfs_temp ); return error; } diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index b863944b57afca08eac72862eee77b85a415478e..dc3247cbfbc11b84261bf67742331e48b6196540 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -438,6 +438,7 @@ ivas_error ivas_core_enc( dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "extl_brate", n, id, ENC ) ); dbgwrite( &st->coder_type, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type", n, id, ENC ) ); + dbgwrite( &st->coder_type_raw, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type_raw", n, id, ENC ) ); dbgwrite( &st->clas, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "clas", n, id, ENC ) ); dbgwrite( &st->cng_type, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "cng_type", n, id, ENC ) ); dbgwrite( &st->L_frame, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "L_frame", n, id, ENC ) ); diff --git a/lib_enc/ppp_enc.c b/lib_enc/ppp_enc.c index 887be74fd573e906e6a16abac4735b1f05ee5ac0..f2c6f4e2bd183a7ac9f43fcf72e5361e4877997f 100644 --- a/lib_enc/ppp_enc.c +++ b/lib_enc/ppp_enc.c @@ -355,11 +355,12 @@ ivas_error ppp_quarter_encoder( push_indice( hBstr, IND_GLOBAL_ALIGNMENT, (int16_t) ( tmp + 3 ), 3 ); - count_free( PREVDTFS ); + dynamic_free( PREVDTFS ); return error; } + /*-------------------------------------------------------------------* * set_ppp_mode() * diff --git a/lib_enc/voiced_enc.c b/lib_enc/voiced_enc.c index 55ee77a47668ae71b05fc1f03d6b0c8363935909..d67ecbbce248d2cc60f4e841b34156f80ac49cc0 100644 --- a/lib_enc/voiced_enc.c +++ b/lib_enc/voiced_enc.c @@ -554,12 +554,12 @@ ivas_error ppp_voiced_encoder( { hSC_VBR->bump_up = 1; - count_free( CURRP_NQ ); - count_free( TMPDTFS ); - count_free( TMPDTFS2 ); - count_free( TMPDTFS3 ); - count_free( CURRP_Q_E ); - count_free( dtfs_temp ); + dynamic_free( CURRP_NQ ); + dynamic_free( TMPDTFS ); + dynamic_free( TMPDTFS2 ); + dynamic_free( TMPDTFS3 ); + dynamic_free( CURRP_Q_E ); + dynamic_free( dtfs_temp ); return error; } @@ -580,12 +580,13 @@ ivas_error ppp_voiced_encoder( { hSC_VBR->bump_up = 1; - count_free( CURRP_NQ ); - count_free( TMPDTFS ); - count_free( TMPDTFS2 ); - count_free( TMPDTFS3 ); - count_free( CURRP_Q_E ); - count_free( dtfs_temp ); + dynamic_free( CURRP_NQ ); + dynamic_free( TMPDTFS ); + dynamic_free( TMPDTFS2 ); + dynamic_free( TMPDTFS3 ); + dynamic_free( CURRP_Q_E ); + dynamic_free( dtfs_temp ); + return error; } @@ -607,12 +608,12 @@ ivas_error ppp_voiced_encoder( { hSC_VBR->bump_up = 1; - count_free( CURRP_NQ ); - count_free( TMPDTFS ); - count_free( TMPDTFS2 ); - count_free( TMPDTFS3 ); - count_free( CURRP_Q_E ); - count_free( dtfs_temp ); + dynamic_free( CURRP_NQ ); + dynamic_free( TMPDTFS ); + dynamic_free( TMPDTFS2 ); + dynamic_free( TMPDTFS3 ); + dynamic_free( CURRP_Q_E ); + dynamic_free( dtfs_temp ); return error; } @@ -748,12 +749,12 @@ ivas_error ppp_voiced_encoder( { hSC_VBR->bump_up = 1; - count_free( CURRP_NQ ); - count_free( TMPDTFS ); - count_free( TMPDTFS2 ); - count_free( TMPDTFS3 ); - count_free( CURRP_Q_E ); - count_free( dtfs_temp ); + dynamic_free( CURRP_NQ ); + dynamic_free( TMPDTFS ); + dynamic_free( TMPDTFS2 ); + dynamic_free( TMPDTFS3 ); + dynamic_free( CURRP_Q_E ); + dynamic_free( dtfs_temp ); return error; } @@ -779,12 +780,12 @@ ivas_error ppp_voiced_encoder( { hSC_VBR->bump_up = 1; - count_free( CURRP_NQ ); - count_free( TMPDTFS ); - count_free( TMPDTFS2 ); - count_free( TMPDTFS3 ); - count_free( CURRP_Q_E ); - count_free( dtfs_temp ); + dynamic_free( CURRP_NQ ); + dynamic_free( TMPDTFS ); + dynamic_free( TMPDTFS2 ); + dynamic_free( TMPDTFS3 ); + dynamic_free( CURRP_Q_E ); + dynamic_free( dtfs_temp ); return error; } @@ -800,12 +801,12 @@ ivas_error ppp_voiced_encoder( if ( hSC_VBR->bump_up == 1 ) { - count_free( CURRP_NQ ); - count_free( TMPDTFS ); - count_free( TMPDTFS2 ); - count_free( TMPDTFS3 ); - count_free( CURRP_Q_E ); - count_free( dtfs_temp ); + dynamic_free( CURRP_NQ ); + dynamic_free( TMPDTFS ); + dynamic_free( TMPDTFS2 ); + dynamic_free( TMPDTFS3 ); + dynamic_free( CURRP_Q_E ); + dynamic_free( dtfs_temp ); return error; } @@ -815,12 +816,12 @@ ivas_error ppp_voiced_encoder( { hSC_VBR->bump_up = 1; - count_free( CURRP_NQ ); - count_free( TMPDTFS ); - count_free( TMPDTFS2 ); - count_free( TMPDTFS3 ); - count_free( CURRP_Q_E ); - count_free( dtfs_temp ); + dynamic_free( CURRP_NQ ); + dynamic_free( TMPDTFS ); + dynamic_free( TMPDTFS2 ); + dynamic_free( TMPDTFS3 ); + dynamic_free( CURRP_Q_E ); + dynamic_free( dtfs_temp ); return error; } @@ -834,12 +835,13 @@ ivas_error ppp_voiced_encoder( { if ( ( error = ppp_quarter_encoder( &flag, hBstr, CURRP_Q_E, TMPDTFS, dtfs_temp->lag, *CURRP_NQ, lpc2, &( hSC_VBR->lastLgainE ), &( hSC_VBR->lastHgainE ), &( hSC_VBR->lasterbE[0] ), *dtfs_temp ) ) != IVAS_ERR_OK ) { - count_free( CURRP_NQ ); - count_free( TMPDTFS ); - count_free( TMPDTFS2 ); - count_free( TMPDTFS3 ); - count_free( CURRP_Q_E ); - count_free( dtfs_temp ); + dynamic_free( CURRP_NQ ); + dynamic_free( TMPDTFS ); + dynamic_free( TMPDTFS2 ); + dynamic_free( TMPDTFS3 ); + dynamic_free( CURRP_Q_E ); + dynamic_free( dtfs_temp ); + return error; } } @@ -1025,12 +1027,12 @@ ivas_error ppp_voiced_encoder( { hSC_VBR->bump_up = 1; - count_free( CURRP_NQ ); - count_free( TMPDTFS ); - count_free( TMPDTFS2 ); - count_free( TMPDTFS3 ); - count_free( CURRP_Q_E ); - count_free( dtfs_temp ); + dynamic_free( CURRP_NQ ); + dynamic_free( TMPDTFS ); + dynamic_free( TMPDTFS2 ); + dynamic_free( TMPDTFS3 ); + dynamic_free( CURRP_Q_E ); + dynamic_free( dtfs_temp ); return error; } @@ -1045,12 +1047,12 @@ ivas_error ppp_voiced_encoder( PPP_MODE_E = 'B'; hSC_VBR->bump_up = 1; - count_free( CURRP_NQ ); - count_free( TMPDTFS ); - count_free( TMPDTFS2 ); - count_free( TMPDTFS3 ); - count_free( CURRP_Q_E ); - count_free( dtfs_temp ); + dynamic_free( CURRP_NQ ); + dynamic_free( TMPDTFS ); + dynamic_free( TMPDTFS2 ); + dynamic_free( TMPDTFS3 ); + dynamic_free( CURRP_Q_E ); + dynamic_free( dtfs_temp ); return error; } @@ -1082,12 +1084,12 @@ ivas_error ppp_voiced_encoder( mvr2r( dtfs_temp->a, hSC_VBR->dtfs_enc_a, MAXLAG_WI ); mvr2r( dtfs_temp->b, hSC_VBR->dtfs_enc_b, MAXLAG_WI ); - count_free( CURRP_NQ ); - count_free( TMPDTFS ); - count_free( TMPDTFS2 ); - count_free( TMPDTFS3 ); - count_free( CURRP_Q_E ); - count_free( dtfs_temp ); + dynamic_free( CURRP_NQ ); + dynamic_free( TMPDTFS ); + dynamic_free( TMPDTFS2 ); + dynamic_free( TMPDTFS3 ); + dynamic_free( CURRP_Q_E ); + dynamic_free( dtfs_temp ); return error; }