diff --git a/apps/decoder.c b/apps/decoder.c index 294446883e1379a87de8462147db3f9533c52bc6..f37b0acec923ef1cf9b8c9999b8c79318933d15d 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2962,10 +2962,8 @@ static ivas_error decodeVoIP( *phIvasDec = hIvasDec; /* Update for main()' s free */ ivasRtp.restartNeeded = false; -#ifdef FIX_1525_UNINIT_FORMAT_SWITCHING_DEC bitstreamReadDone = false; parametersAvailableForEditing = false; -#endif } /* reference vector */ @@ -3215,10 +3213,8 @@ static ivas_error decodeVoIP( } *phIvasDec = hIvasDec; /* Update for main()' s free */ -#ifdef FIX_1525_UNINIT_FORMAT_SWITCHING_DEC bitstreamReadDone = false; parametersAvailableForEditing = false; -#endif } /* Placeholder for memory reallocation */ @@ -3982,13 +3978,6 @@ static ivas_error restartDecoder( } } -#ifndef FIX_1525_UNINIT_FORMAT_SWITCHING_DEC - if ( ( error = IVAS_DEC_PrintConfig( hIvasDec, 1, arg->voipMode ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_PrintConfig failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } -#endif /* ISAR frame size is set from command line, not renderer config file. * This will be ignored if output format is not split rendering. */ if ( renderConfig != NULL ) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 3dfe624dcb2bc15e95390b02dbe3c02ab9da3b54..0ea787913f26b9509610e01b0983c969669f8ef2 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -166,9 +166,6 @@ void initFdCngCom( set16_fx( hFdCngCom->coherence_fx, 16384 /* 0.5 in Q15 */, MDCT_ST_DTX_NUM_COHERENCE_BANDS ); -#ifndef FIX_BASOP_REMOVE_SYNTH2_FX - set32_fx( hFdCngCom->olapBufferSynth2_fx, 0, FFTLEN ); -#endif set32_fx( hFdCngCom->exc_cng_32fx, 0, L_FRAME16k ); set16_fx( hFdCngCom->exc_cng, 0, L_FRAME16k ); diff --git a/lib_com/fft_fx.c b/lib_com/fft_fx.c index 97fef62e561de5286b4cdce624a393e7d7c33d80..4fbb39a5e37a4aae074bc28eec326d1bdfcf7f34 100644 --- a/lib_com/fft_fx.c +++ b/lib_com/fft_fx.c @@ -2791,504 +2791,6 @@ void DoRTFTn_fx_ivas( return; } -#ifndef HQ_ALIGN_DUPLICATED_CODE -void fft3_fx_ivas( - const Word32 X[], // Qx - Word32 Y[], // Qx - const Word16 n // Q0 -) -{ - Word32 Z[PH_ECU_SPEC_SIZE]; - Word32 *Z0, *Z1, *Z2; - Word32 *z0, *z1, *z2; - const Word32 *x; - const Word16 *t_sin = sincos_t_rad3_fx; // Q15 - Word16 m, step, order; - Word16 i, j; - Word16 c1_ind, s1_ind, c2_ind, s2_ind; - Word16 c1_step, s1_step, c2_step, s2_step; - Word32 *RY, *IY, *RZ0, *IZ0, *RZ1, *IZ1, *RZ2, *IZ2; - - /* Determine the order of the transform, the length of decimated */ - /* transforms m, and the step for the sine and cosine tables. */ - SWITCH( n ) - { - case 1536: - order = 9; - move16(); - m = 512; - move16(); - step = 1; - move16(); - BREAK; - case 384: - order = 7; - move16(); - m = 128; - move16(); - step = 4; - move16(); - BREAK; - default: - order = 9; - move16(); - m = 512; - move16(); - step = 1; - move16(); - } - - /* Compose decimated sequences X[3i], X[3i+1],X[3i+2] */ - /* compute their FFT of length m. */ - Z0 = &Z[0]; - z0 = &Z0[0]; - Z1 = &Z0[m]; - z1 = &Z1[0]; /* Z1 = &Z[ m]; */ - Z2 = &Z1[m]; - z2 = &Z2[0]; /* Z2 = &Z[2m]; */ - x = &X[0]; - FOR( i = 0; i < n / 3; i++ ) - { - *z0++ = *x++; /* Z0[i] = X[3i]; */ - move32(); - *z1++ = *x++; /* Z1[i] = X[3i+1]; */ - move32(); - *z2++ = *x++; /* Z2[i] = X[3i+2]; */ - move32(); - } - - fft_rel_fx32( &Z0[0], m, order ); - fft_rel_fx32( &Z1[0], m, order ); - fft_rel_fx32( &Z2[0], m, order ); - - /* Butterflies of order 3. */ - /* pointer initialization */ - RY = &Y[0]; // Qx - IY = &Y[n]; // Qx - RZ0 = &Z0[0]; - IZ0 = &Z0[m]; - RZ1 = &Z1[0]; - IZ1 = &Z1[m]; - RZ2 = &Z2[0]; - IZ2 = &Z2[m]; - - c1_step = negate( step ); - s1_step = step; - move16(); - c2_step = negate( shl( step, 1 ) ); - s2_step = shl( step, 1 ); - c1_ind = add( T_SIN_PI_2, c1_step ); - s1_ind = s1_step; - move16(); - c2_ind = add( T_SIN_PI_2, c2_step ); - s2_ind = s2_step; - move16(); - - /* special case: i = 0 */ - RY[0] = L_add( RZ0[0], L_add( RZ1[0], RZ2[0] ) ); - move32(); - - /* first 3/12 */ - FOR( i = 1; i < ( 3 * ( m >> 3 ) ); ( i++, c1_ind = ( c1_ind + c1_step ), s1_ind = ( s1_ind + s1_step ), c2_ind = ( c2_ind + c2_step ), s2_ind = ( s2_ind + s2_step ) ) ) - { - RY[i] = L_add( RZ0[i], L_add( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), - L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), - L_add( Mpy_32_16_1( RZ2[i], t_sin[c2_ind] ), - Mpy_32_16_1( IZ2[-i], t_sin[s2_ind] ) ) ) ) ); // Qx - move32(); - IY[-i] = L_sub( IZ0[-i], L_add( L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), - Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ) ), - L_sub( Mpy_32_16_1( RZ2[i], t_sin[s2_ind] ), - Mpy_32_16_1( IZ2[-i], t_sin[c2_ind] ) ) ) ); // Qx - move32(); - } - - /* next 1/12 */ - FOR( ; i < 4 * m / 8; ( i++, c1_ind = ( c1_ind + c1_step ), s1_ind = ( s1_ind + s1_step ), c2_ind = ( c2_ind - c2_step ), s2_ind = ( s2_ind - s2_step ) ) ) - { - RY[i] = L_add( RZ0[i], L_sub( L_add( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), - Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ) ), - L_sub( Mpy_32_16_1( RZ2[i], t_sin[c2_ind] ), - Mpy_32_16_1( IZ2[-i], t_sin[s2_ind] ) ) ) ); // Qx - move32(); - IY[-i] = L_sub( IZ0[-i], L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), - L_sub( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), - L_add( Mpy_32_16_1( RZ2[i], t_sin[s2_ind] ), - Mpy_32_16_1( IZ2[-i], t_sin[c2_ind] ) ) ) ) ); // Qx - move32(); - } - - /* special case: i = m/2 i.e. 1/3 */ - RY[i] = L_add( RZ0[i], - L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), - Mpy_32_16_1( RZ2[i], t_sin[c2_ind] ) ) ); // Qx - move32(); - IY[-i] = L_negate( L_add( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), - Mpy_32_16_1( RZ2[i], t_sin[s2_ind] ) ) ); // Qx - move32(); - i = add( i, 1 ); - - c1_ind = add( c1_ind, c1_step ); - s1_ind = add( s1_ind, s1_step ); - c2_ind = sub( c2_ind, c2_step ); - s2_ind = sub( s2_ind, s2_step ); - - /* next 2/12 */ - FOR( j = i - 2; i < 6 * m / 8; ( i++, j--, c1_ind = ( c1_ind + c1_step ), s1_ind = ( s1_ind + s1_step ), c2_ind = ( c2_ind - c2_step ), s2_ind = ( s2_ind - s2_step ) ) ) - { - RY[i] = L_add( RZ0[j], L_sub( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), - L_add( Mpy_32_16_1( IZ1[-j], t_sin[s1_ind] ), - L_add( Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ), - Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ) ); // Qx - move32(); - - IY[-i] = L_negate( L_add( IZ0[-j], L_add( Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ), - L_add( Mpy_32_16_1( IZ1[-j], t_sin[c1_ind] ), - L_sub( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), - Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ) ) ); // Qx - move32(); - } - - /*--------------------------half--------------------------*/ - /* next 2/12 */ - FOR( ; i < 8 * m / 8; ( i++, j--, c1_ind = ( c1_ind - c1_step ), s1_ind = ( s1_ind - s1_step ), c2_ind = ( c2_ind + c2_step ), s2_ind = ( s2_ind + s2_step ) ) ) - { - RY[i] = L_sub( RZ0[j], L_add( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), - L_add( Mpy_32_16_1( IZ1[-j], t_sin[s1_ind] ), - L_sub( Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ), - Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ) ); // Qx - move32(); - IY[-i] = L_negate( L_add( IZ0[-j], L_sub( Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ), - L_add( Mpy_32_16_1( IZ1[-j], t_sin[c1_ind] ), - L_add( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), - Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ) ) ); // Qx - move32(); - } - - /* special case: i = m, i.e 2/3 */ - RY[i] = L_sub( RZ0[j], L_add( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), - Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ) ) ); // Qx - move32(); - IY[-i] = L_sub( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), - Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ) ); // Qx - move32(); - i = add( i, 1 ); - c1_ind = sub( c1_ind, c1_step ), s1_ind = sub( s1_ind, s1_step ), c2_ind = add( c2_ind, c2_step ), s2_ind = add( s2_ind, s2_step ); - - /* next 1/12 */ - FOR( j = 1; i < ( 9 * ( m >> 3 ) ); ( i++, j++, c1_ind = ( c1_ind - c1_step ), s1_ind = ( s1_ind - s1_step ), c2_ind = ( c2_ind + c2_step ), s2_ind = ( s2_ind + s2_step ) ) ) - { - RY[i] = L_sub( RZ0[j], L_sub( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), - L_sub( Mpy_32_16_1( IZ1[-j], t_sin[s1_ind] ), - L_add( Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ), - Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ) ); // Qx - move32(); - IY[-i] = L_sub( IZ0[-j], L_add( Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ), - L_sub( Mpy_32_16_1( IZ1[-j], t_sin[c1_ind] ), - L_sub( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), - Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ) ); // Qx - move32(); - } - - /* last 3/12 */ - FOR( ; i < 12 * m / 8; ( i++, j++, c1_ind = ( c1_ind - c1_step ), s1_ind = ( s1_ind - s1_step ), c2_ind = ( c2_ind - c2_step ), s2_ind = ( s2_ind - s2_step ) ) ) - { - RY[i] = L_sub( RZ0[j], L_sub( L_sub( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), - Mpy_32_16_1( IZ1[-j], t_sin[s1_ind] ) ), - L_sub( Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ), - Mpy_32_16_1( IZ2[-j], t_sin[s2_ind] ) ) ) ); // Qx - move32(); - IY[-i] = L_sub( IZ0[-j], L_sub( L_add( Mpy_32_16_1( RZ1[j], t_sin[s1_ind] ), - Mpy_32_16_1( IZ1[-j], t_sin[c1_ind] ) ), - L_add( Mpy_32_16_1( RZ2[j], t_sin[s2_ind] ), - Mpy_32_16_1( IZ2[-j], t_sin[c2_ind] ) ) ) ); // Qx - move32(); - } - - /* special case: i = 3*m/2 */ - RY[i] = L_sub( RZ0[j], L_sub( Mpy_32_16_1( RZ1[j], t_sin[c1_ind] ), - Mpy_32_16_1( RZ2[j], t_sin[c2_ind] ) ) ); // Qx - move32(); - - return; -} - -void ifft3_fx_ivas( - const Word32 Z[], // Qx - Word32 X[], - const Word16 n ) -{ - Word32 Y[PH_ECU_SPEC_SIZE]; - const Word16 *t_sin = sincos_t_rad3_fx; // Q15 - Word16 m, step, step2, order; - Word16 i; - Word16 c0_ind, s0_ind, c1_ind, s1_ind, c2_ind, s2_ind; - Word16 scale; - const Word32 *RZ0, *IZ0, *RZ1, *IZ1, *RZ2, *IZ2; - Word32 *RY0, *IY0, *RY1, *IY1, *RY2, *IY2, *y0, *y1, *y2; - - /* Determine the order of the transform, the length of decimated */ - /* transforms m, and the step for the sine and cosine tables. */ - SWITCH( n ) - { - case 1536: - order = 9; - move16(); - m = 512; - move16(); - step = 1; - move16(); - BREAK; - case 384: - order = 7; - move16(); - m = 128; - move16(); - step = 4; - move16(); - BREAK; - default: - order = 9; - move16(); - m = 512; - move16(); - step = 1; - move16(); - } - - /* pointer initialization */ - RY0 = &Y[0]; - IY0 = &RY0[m]; - RY1 = &RY0[m]; - IY1 = &RY1[m]; - RY2 = &RY1[m]; - IY2 = &RY2[m]; - - RZ0 = &Z[0]; // Qx - RZ1 = RZ0 + m; - RZ2 = RZ0 + sub( shr( n, 1 ), shr( m, 1 ) ); - IZ0 = &Z[n]; - IZ1 = IZ0 - m; - IZ2 = IZ0 - sub( shr( n, 1 ), shr( m, 1 ) ); - - /* Inverse butterflies of order 3. */ - - /* Construction of Y0 */ - RY0[0] = L_add( RZ0[0], L_add( RZ1[0], RZ2[0] ) ); - move32(); - FOR( i = 1; i < m / 2; i++ ) - { - RY0[i] = L_add( RZ0[i], L_add( RZ1[i], RZ2[-i] ) ); - move32(); - IY0[-i] = L_add( IZ0[-i], L_sub( IZ1[-i], IZ2[i] ) ); - move32(); - } - - /* m/2 */ - RY0[i] = L_add( RZ0[i], L_add( RZ1[i], RZ2[-i] ) ); - move32(); - - /* Construction of Y1 */ - c0_ind = T_SIN_PI_2; - s0_ind = 0; - c1_ind = T_SIN_PI_2 * 1 / 3; - s1_ind = T_SIN_PI_2 * 2 / 3; - c2_ind = T_SIN_PI_2 * 1 / 3; - s2_ind = T_SIN_PI_2 * 2 / 3; - - RY1[0] = L_sub( Mpy_32_16_1( RZ0[0], t_sin[c0_ind] ), - L_add( Mpy_32_16_1( RZ1[0], t_sin[c1_ind] ), - L_add( Mpy_32_16_1( RZ2[0], t_sin[c2_ind] ), - L_add( Mpy_32_16_1( IZ1[0], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[0], t_sin[s2_ind] ) ) ) ) ); // Qx - move32(); - - c0_ind = sub( c0_ind, step ); - s0_ind = add( s0_ind, step ); - c1_ind = add( c1_ind, step ); - s1_ind = sub( s1_ind, step ); - c2_ind = sub( c2_ind, step ); - s2_ind = add( s2_ind, step ); - FOR( i = 1; i < m / 4; ( i++, c0_ind = ( c0_ind - step ), s0_ind = ( s0_ind + step ), c1_ind = ( c1_ind + step ), s1_ind = ( s1_ind - step ), c2_ind = ( c2_ind - step ), s2_ind = ( s2_ind + step ) ) ) - { - RY1[i] = L_sub( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), - L_add( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), - L_add( Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ), - L_add( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ), - L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ) ); // Qx - move32(); - IY1[-i] = L_add( L_sub( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), - Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ) ), - L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), - L_add( Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ), - L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), - Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ); // Qx - move32(); - } - - FOR( ; i < m / 2; ( i++, c0_ind = ( c0_ind - step ), s0_ind = ( s0_ind + step ), c1_ind = ( c1_ind + step ), s1_ind = ( s1_ind - step ), c2_ind = ( c2_ind + step ), s2_ind = ( s2_ind - step ) ) ) - { - RY1[i] = L_sub( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), - L_add( L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), - Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ) ), - L_add( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ), - L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); // Qx - move32(); - IY1[-i] = L_sub( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), - L_sub( L_add( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), - Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ) ), - L_add( Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ), - L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), - Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ); // Qx - move32(); - } - - /* m/2 */ - RY1[i] = L_sub( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), - L_add( L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), - Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ) ), - L_add( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ), - L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); // Qx - move32(); - - /* Construction of Y2 */ - c0_ind = T_SIN_PI_2; - move16(); - s0_ind = 0; - move16(); - c1_ind = T_SIN_PI_2 * 1 / 3; - move16(); - s1_ind = T_SIN_PI_2 * 2 / 3; - move16(); - c2_ind = T_SIN_PI_2 * 1 / 3; - move16(); - s2_ind = T_SIN_PI_2 * 2 / 3; - move16(); - step2 = shl( step, 1 ); - RY2[0] = L_sub( Mpy_32_16_1( RZ0[0], t_sin[c0_ind] ), - L_sub( L_add( Mpy_32_16_1( RZ1[0], t_sin[c1_ind] ), - Mpy_32_16_1( RZ2[0], t_sin[c2_ind] ) ), - L_add( Mpy_32_16_1( IZ1[0], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[0], t_sin[s2_ind] ) ) ) ); // Qx - move32(); - - c0_ind = sub( c0_ind, step2 ); - s0_ind = add( s0_ind, step2 ); - c1_ind = sub( c1_ind, step2 ); - s1_ind = add( s1_ind, step2 ); - c2_ind = add( c2_ind, step2 ); - s2_ind = sub( s2_ind, step2 ); - FOR( i = 1; i < m / 8; ( i++, c0_ind = ( c0_ind - step2 ), s0_ind = ( s0_ind + step2 ), c1_ind = ( c1_ind - step2 ), s1_ind = ( s1_ind + step2 ), c2_ind = ( c2_ind + step2 ), s2_ind = ( s2_ind - step2 ) ) ) - { - RY2[i] = L_sub( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), - L_add( L_add( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), - Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ) ), - L_sub( Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ), - L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); // Qx - move32(); - IY2[-i] = L_add( L_sub( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), - Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ) ), - L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), - L_sub( Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ), - L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), - Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ); // Qx - move32(); - } - - FOR( ; i < m / 4; ( i++, c0_ind = ( c0_ind - step2 ), s0_ind = ( s0_ind + step2 ), c1_ind = ( c1_ind + step2 ), s1_ind = ( s1_ind - step2 ), c2_ind = ( c2_ind + step2 ), s2_ind = ( s2_ind - step2 ) ) ) - { - RY2[i] = L_add( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), - L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), - L_sub( L_add( Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ), - Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ) ), - L_add( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ) ); // Qx - move32(); - IY2[-i] = L_add( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), - L_add( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), - L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), - L_sub( Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ), - L_sub( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), - Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ) ) ); // Qx - move32(); - } - - FOR( ; i < ( 3 * ( m >> 3 ) ); ( i++, c0_ind = ( c0_ind - step2 ), s0_ind = ( s0_ind + step2 ), c1_ind = ( c1_ind + step2 ), s1_ind = ( s1_ind - step2 ), c2_ind = ( c2_ind - step2 ), s2_ind = ( s2_ind + step2 ) ) ) - { - RY2[i] = L_sub( L_add( Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ), - Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ) ), - L_sub( L_add( Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ), - Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ) ), - L_sub( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ); // Qx - move32(); - IY2[-i] = L_sub( L_add( Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ), - L_add( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), - L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), - Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ) ) ) ), - L_add( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), - Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ); // Qx - move32(); - } - - FOR( ; i < m / 2; ( i++, c0_ind = ( c0_ind + step2 ), s0_ind = ( s0_ind - step2 ), c1_ind = ( c1_ind + step2 ), s1_ind = ( s1_ind - step2 ), c2_ind = ( c2_ind - step2 ), s2_ind = ( s2_ind + step2 ) ) ) - { - RY2[i] = L_sub( L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), - Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ) ), - L_sub( L_add( Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ), - Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ) ), - L_sub( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ); // Qx - move32(); - IY2[-i] = L_add( L_sub( Mpy_32_16_1( IZ1[-i], t_sin[c1_ind] ), - Mpy_32_16_1( IZ0[-i], t_sin[c0_ind] ) ), - L_sub( L_add( Mpy_32_16_1( IZ2[i], t_sin[c2_ind] ), - Mpy_32_16_1( RZ0[i], t_sin[s0_ind] ) ), - L_add( Mpy_32_16_1( RZ1[i], t_sin[s1_ind] ), - Mpy_32_16_1( RZ2[-i], t_sin[s2_ind] ) ) ) ); // Qx - move32(); - } - - /* m/2 */ - RY2[i] = L_sub( L_sub( Mpy_32_16_1( RZ1[i], t_sin[c1_ind] ), - Mpy_32_16_1( RZ0[i], t_sin[c0_ind] ) ), - L_sub( L_add( Mpy_32_16_1( RZ2[-i], t_sin[c2_ind] ), - Mpy_32_16_1( IZ0[-i], t_sin[s0_ind] ) ), - L_sub( Mpy_32_16_1( IZ1[-i], t_sin[s1_ind] ), - Mpy_32_16_1( IZ2[i], t_sin[s2_ind] ) ) ) ); // Qx - move32(); - - /* Compute the inverse FFT for all 3 blocks. */ - ifft_rel_fx32( RY0, m, order ); - ifft_rel_fx32( RY1, m, order ); - ifft_rel_fx32( RY2, m, order ); - - y0 = RY0; - y1 = RY1; - y2 = RY2; - - /* Interlacing and scaling, scale = 1/3 */ - scale = extract_l( 0x2AAB /*(1/3).Q15*/ ); - FOR( i = 0; i < n; ) - { - X[i] = Mpy_32_16_1( ( *y0++ ), scale ); // Qx - move32(); - i = add( i, 1 ); - X[i] = Mpy_32_16_1( ( *y1++ ), scale ); // Qx - move32(); - i = add( i, 1 ); - X[i] = Mpy_32_16_1( ( *y2++ ), scale ); // Qx - move32(); - i = add( i, 1 ); - } - - return; -} -#endif static void rfft_post( const Word16 *sine_table, // Q15 diff --git a/lib_com/gs_bitallocation_fx.c b/lib_com/gs_bitallocation_fx.c index d9b9899e4c0add43009764e971bdbd5f5742aa33..67dde91377b1b4cbaf0a159f29e7b211209895c2 100644 --- a/lib_com/gs_bitallocation_fx.c +++ b/lib_com/gs_bitallocation_fx.c @@ -77,11 +77,7 @@ static Word32 Find_bit_frac_fx( const Word16 nb_band, const Word16 remaining_bit /* _ None */ /*==================================================================================*/ -#ifdef FIX_2467_RENAME_GSC_FUNCTION void bands_and_bit_alloc_fx( -#else -void bands_and_bit_alloc_ivas_fx( -#endif const Word16 cor_strong_limit, /* i : HF correlation */ const Word16 noise_lev, /* i : dwn scaling factor */ const Word32 core_brate, /* i : core bit rate */ diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index 2c2f5a6c3867a438bf60da94af6ad41a45111011..1128ec0c67cf77be5f872d391132f8ec7e31275c 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -2329,7 +2329,7 @@ void enforce_zero_for_min_envelope_fx( return; } -#ifdef HQ_ALIGN_DUPLICATED_CODE + /*--------------------------------------------------------------------------* * apply_envelope() * @@ -2344,22 +2344,6 @@ void apply_envelope_enc_fx( const Word16 *sfm_end, /* i : Sub band end indices Q0 */ Word32 *coeff_out /* o : scaled spectrum Q12 */ ) -#else -/*--------------------------------------------------------------------------* - * apply_envelope() - * - * Apply spectral envelope with envelope adjustments - *--------------------------------------------------------------------------*/ - -void apply_envelope_enc_ivas_fx( - const Word16 *coeff, /* i/o: Coded/noisefilled normalized spectrum Q12 */ - const Word16 *norm, /* i : Envelope Q0 */ - const Word16 num_sfm, /* i : Total number of bands Q0 */ - const Word16 *sfm_start, /* i : Sub band start indices Q0 */ - const Word16 *sfm_end, /* i : Sub band end indices Q0 */ - Word32 *coeff_out /* o : coded/noisefilled spectrum Q12 */ -) -#endif { Word16 i; Word16 sfm; @@ -2385,19 +2369,11 @@ void apply_envelope_enc_ivas_fx( } -#ifdef HQ_ALIGN_DUPLICATED_CODE /*--------------------------------------------------------------------------* * apply_envelope_fx() * * Apply spectral envelope with envelope adjustments *--------------------------------------------------------------------------*/ -#else -/*--------------------------------------------------------------------------* - * apply_envelope() - * - * Apply spectral envelope with envelope adjustments - *--------------------------------------------------------------------------*/ -#endif void apply_envelope_fx( const Word16 *coeff, /* i/o: Coded/noisefilled normalized spectrum Q12 */ diff --git a/lib_com/igf_base_fx.c b/lib_com/igf_base_fx.c index 61dd12c0f0db60d3290e754a7a8aa85e7d7213c7..7b46451c3f567d2c8151fe2bafcb5513fc780b03 100644 --- a/lib_com/igf_base_fx.c +++ b/lib_com/igf_base_fx.c @@ -15,9 +15,10 @@ /**********************************************************************/ /* returns an int val, multiplied with transFac **************************************************************************/ -Word16 IGF_ApplyTransFac( /**< out: Q0 | multiplication factor */ - const Word16 val, /**< in: Q15 | input value for multiplication, Q15 */ - const Word16 transFac /**< in: Q14 | multiplicator for variable val, Q14: 1.25f=0x5000, 1.0f=0x4000, 0.5f=0x2000 */ +/**< out: Q0 | multiplication factor */ +Word16 IGF_ApplyTransFac( + const Word16 val, /**< in: Q15 | input value for multiplication, Q15 */ + const Word16 transFac /**< in: Q14 | multiplicator for variable val, Q14: 1.25f=0x5000, 1.0f=0x4000, 0.5f=0x2000 */ ) { Word16 ret; @@ -381,522 +382,11 @@ Word16 IGF_MapBitRateToIndex( return bitRateIndex; /*Q0*/ } -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/**********************************************************************/ /* -IGF grid setup -**************************************************************************/ -static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< out: | IGF grid handle */ - Word16 bitRateIndex, /**< in: Q0 | IGF bitrate index */ - Word32 sampleRate, /**< in: | sample rate */ - Word16 frameLength, /**< in: | frame length */ - Word16 transFac, /**< in: Q14 |transFac */ - Word16 igfMinFq /**< in: | IGF minimum frequency indicating lower start frequency for copy up */ -) -{ - Word16 t; - Word16 sfb; - const Word16 *swb_offset; - Word16 swb_offset_len; - Word16 bandwidth; - Word16 wrp_sfb; - Word16 tmp1; - Word16 tmp2; - Word32 L_tmp1; - Word32 L_tmp2; - - swb_offset = NULL; - swb_offset_len = 0; - move16(); - - SWITCH( bitRateIndex ) - { - case IGF_BITRATE_WB_9600: - case IGF_BITRATE_SWB_9600: - case IGF_BITRATE_RF_WB_13200: - case IGF_BITRATE_RF_SWB_13200: - case IGF_BITRATE_SWB_13200: - case IGF_BITRATE_SWB_16400: - case IGF_BITRATE_SWB_24400: - case IGF_BITRATE_SWB_32000: - case IGF_BITRATE_SWB_48000: - swb_offset = &swb_offset_LB_new[bitRateIndex][1]; - swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; /*Q0*/ - move16(); - Copy( &igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2 ); - BREAK; - case IGF_BITRATE_FB_16400: - case IGF_BITRATE_FB_24400: - case IGF_BITRATE_FB_32000: - swb_offset = &swb_offset_LB_new[bitRateIndex][1]; - swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; /*Q0*/ - move16(); - Copy( &igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2 ); - BREAK; - case IGF_BITRATE_FB_48000: - case IGF_BITRATE_FB_96000: - case IGF_BITRATE_FB_128000: - swb_offset = &swb_offset_LB_new[bitRateIndex][1]; - swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; /*Q0*/ - move16(); - Copy( &igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2 ); - BREAK; - case IGF_BITRATE_UNKNOWN: - default: - assert( 0 ); - } - - FOR( sfb = 0; sfb < swb_offset_len; sfb++ ) - { - hGrid->swb_offset[sfb] = IGF_ApplyTransFac( swb_offset[sfb], transFac ); /*Q0*/ - move16(); - } - - hGrid->infoIsRefined = 0; - move16(); - frameLength = IGF_ApplyTransFac( frameLength, transFac ); /*Q0*/ - tmp2 = norm_s( frameLength ); - bandwidth = shl( frameLength, tmp2 ); /*tmp2*/ - hGrid->swb_offset_len = extract_l( L_shr( sampleRate, 2 ) ); /*-1*/ - move16(); - tmp1 = sub( norm_s( hGrid->swb_offset_len ), 1 ); - hGrid->swb_offset_len = shl( hGrid->swb_offset_len, tmp1 ); /*tmp1-1*/ - move16(); - bandwidth = div_s( hGrid->swb_offset_len, bandwidth ); /*15 + tmp1-1-tmp2*/ - tmp2 = sub( add( tmp2, 1 ), tmp1 ); - bandwidth = shr( bandwidth, sub( 15, tmp2 ) ); /*Q0*/ - - - hGrid->swb_offset_len = swb_offset_len; /*Q0*/ - move16(); - hGrid->startSfb = 0; - move16(); - hGrid->stopSfb = sub( hGrid->swb_offset_len, 1 ); /*Q0*/ - move16(); - hGrid->startLine = hGrid->swb_offset[hGrid->startSfb]; /*Q0*/ - move16(); - hGrid->stopLine = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ - move16(); - hGrid->startFrequency = imult1616( bandwidth, hGrid->startLine ); /*Q0*/ - move16(); - hGrid->stopFrequency = imult1616( bandwidth, hGrid->stopLine ); /*Q0*/ - move16(); - - L_tmp1 = L_mult0( igfMinFq, frameLength ); /*Q0*/ - tmp1 = sub( norm_l( L_tmp1 ), 1 ); - L_tmp1 = L_shl( L_tmp1, tmp1 ); /*tmp1*/ - - tmp2 = norm_l( sampleRate ); - L_tmp2 = L_shl( sampleRate, tmp2 ); /*tmp2*/ - tmp1 = add( WORD16_BITS - 1, sub( tmp1, add( tmp2, 1 ) ) ); /* takes into account sampleRate >> 1 */ - - hGrid->minSrcSubband = div_s( extract_h( L_tmp1 ), extract_h( L_tmp2 ) ); /*tmp1*/ - hGrid->minSrcSubband = shr( hGrid->minSrcSubband, tmp1 ); /*Q0*/ - move16(); - move16(); - - - hGrid->minSrcSubband = add( hGrid->minSrcSubband, s_and( hGrid->minSrcSubband, 1 ) ); - move16(); - hGrid->minSrcFrequency = imult1616( bandwidth, hGrid->minSrcSubband ); - move16(); - hGrid->infoGranuleLen = frameLength; /*Q0*/ - move16(); - hGrid->infoTransFac = transFac; /*Q14*/ - move16(); - - hGrid->sfbWrap[0] = 0; - move16(); - hGrid->tile[0] = hGrid->startLine; /*Q0*/ - move16(); - - - /*************************************************************************/ - SWITCH( bitRateIndex ) - { - /* SWB 13200 */ - case IGF_BITRATE_WB_9600: - hGrid->nTiles = 2; - move16(); - wrp_sfb = 2; - move16(); - - /*1st*/ - hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/ - move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/ - move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ - move16(); - - /*2nd*/ - hGrid->sfbWrap[1 + 1] = hGrid->stopSfb; /*Q0*/ - move16(); - hGrid->sbWrap[1] = hGrid->minSrcSubband; /*Q0*/ - move16(); - hGrid->tile[1 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ - move16(); - BREAK; - - case IGF_BITRATE_RF_WB_13200: - hGrid->nTiles = 2; - move16(); - wrp_sfb = 2; - move16(); - - /*1st*/ - hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/ - move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/ - move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ - move16(); - - /*2nd*/ - hGrid->sfbWrap[1 + 1] = hGrid->stopSfb; /*Q0*/ - move16(); - hGrid->sbWrap[1] = hGrid->minSrcSubband; /*Q0*/ - move16(); - hGrid->tile[1 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ - move16(); - - BREAK; - case IGF_BITRATE_SWB_9600: - hGrid->nTiles = 3; - move16(); - wrp_sfb = 1; - move16(); - - /*1st*/ - hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/ - move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/ - move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ - move16(); - - /*2nd*/ - wrp_sfb = 2; - move16(); - hGrid->sfbWrap[1 + 1] = wrp_sfb; /*Q0*/ - move16(); - hGrid->sbWrap[1] = hGrid->minSrcSubband + IGF_ApplyTransFac( 32, transFac ); /*Q0*/ - move16(); - hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ - move16(); - - /*3rd*/ - hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; /*Q0*/ - move16(); - hGrid->sbWrap[2] = hGrid->minSrcSubband + IGF_ApplyTransFac( 46, transFac ); /*Q0*/ - move16(); - hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ - move16(); - - BREAK; - case IGF_BITRATE_RF_SWB_13200: - hGrid->nTiles = 3; - move16(); - wrp_sfb = 1; - move16(); - - /*1st*/ - hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/ - move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/ - move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ - move16(); - - /*2nd*/ - wrp_sfb = 2; - move16(); - hGrid->sfbWrap[1 + 1] = wrp_sfb; /*Q0*/ - move16(); - hGrid->sbWrap[1] = hGrid->minSrcSubband + IGF_ApplyTransFac( 32, transFac ); /*Q0*/ - move16(); - hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ - move16(); - - /*3rd*/ - hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; /*Q0*/ - move16(); - hGrid->sbWrap[2] = hGrid->minSrcSubband + IGF_ApplyTransFac( 46, transFac ); /*Q0*/ - move16(); - hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ - move16(); - - BREAK; - - case IGF_BITRATE_SWB_13200: - hGrid->nTiles = 2; - move16(); - wrp_sfb = 4; - move16(); - - /*1st*/ - hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/ - move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/ - move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ - move16(); - - /*2nd*/ - hGrid->sfbWrap[1 + 1] = hGrid->stopSfb; /*Q0*/ - move16(); - hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 32, transFac ) ); /*Q0*/ - move16(); - hGrid->tile[1 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ - move16(); - BREAK; - - case IGF_BITRATE_SWB_16400: - hGrid->nTiles = 3; - move16(); - wrp_sfb = 4; - move16(); - - /*1st*/ - hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/ - move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/ - move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ - move16(); - - /*2nd*/ - hGrid->sfbWrap[1 + 1] = 6; - move16(); - hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 48, transFac ) ); /*Q0*/ - move16(); - hGrid->tile[1 + 1] = hGrid->swb_offset[6]; /*Q0*/ - move16(); - - /*3nd*/ - hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; /*Q0*/ - move16(); - hGrid->sbWrap[2] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 64, transFac ) ); /*Q0*/ - move16(); - hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ - move16(); - BREAK; - - case IGF_BITRATE_SWB_24400: - case IGF_BITRATE_SWB_32000: - hGrid->nTiles = 3; - move16(); - wrp_sfb = 4; - move16(); - - /*1st*/ - hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/ - move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/ - move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ - move16(); - - /*2nd*/ - hGrid->sfbWrap[1 + 1] = 7; - move16(); - hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 32, transFac ) ); /*Q0*/ - move16(); - hGrid->tile[1 + 1] = hGrid->swb_offset[7]; /*Q0*/ - move16(); - - /*3nd*/ - hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; /*Q0*/ - move16(); - hGrid->sbWrap[2] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 64, transFac ) ); /*Q0*/ - move16(); - hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ - move16(); - BREAK; - case IGF_BITRATE_SWB_48000: - hGrid->nTiles = 1; - move16(); - wrp_sfb = hGrid->stopSfb; - move16(); - - /*1st*/ - hGrid->sfbWrap[0 + 1] = hGrid->stopSfb; /*Q0*/ - move16(); - hGrid->sbWrap[0] = sub( shl( hGrid->startLine, 1 ), hGrid->stopLine ); /*Q0*/ - move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ - move16(); - - BREAK; - case IGF_BITRATE_FB_16400: - hGrid->nTiles = 3; - move16(); - wrp_sfb = 4; - move16(); - - /*1st*/ - hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/ - move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/ - move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ - move16(); - wrp_sfb = 7; - move16(); - - /*2nd*/ - hGrid->sfbWrap[1 + 1] = wrp_sfb; /*Q0*/ - move16(); - hGrid->sbWrap[1] = hGrid->minSrcSubband; /*Q0*/ - move16(); - hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ - move16(); - - /*3nd*/ - hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; /*Q0*/ - move16(); - hGrid->sbWrap[2] = hGrid->minSrcSubband; /*Q0*/ - move16(); - hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ - move16(); - - BREAK; - - case IGF_BITRATE_FB_24400: - case IGF_BITRATE_FB_32000: - hGrid->nTiles = 4; - move16(); - wrp_sfb = 4; - move16(); - - /*1st*/ - hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/ - move16(); - hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/ - move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ - move16(); - wrp_sfb = 6; - move16(); - - /*2nd*/ - hGrid->sfbWrap[1 + 1] = wrp_sfb; /*Q0*/ - move16(); - hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 32, transFac ) ); /*Q0*/ - move16(); - hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ - move16(); - wrp_sfb = 9; - move16(); - - /*3nd*/ - hGrid->sfbWrap[2 + 1] = wrp_sfb; /*Q0*/ - move16(); - hGrid->sbWrap[2] = hGrid->minSrcSubband; /*Q0*/ - move16(); - hGrid->tile[2 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/ - move16(); - - /*4nd*/ - hGrid->sfbWrap[3 + 1] = hGrid->stopSfb; /*Q0*/ - move16(); - hGrid->sbWrap[3] = add( hGrid->minSrcSubband, sub( hGrid->swb_offset[9], hGrid->swb_offset[8] ) ); /*Q0*/ - move16(); - hGrid->tile[3 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ - move16(); - BREAK; - case IGF_BITRATE_FB_48000: - case IGF_BITRATE_FB_96000: - case IGF_BITRATE_FB_128000: - hGrid->nTiles = 1; - move16(); - - /*1st*/ - hGrid->sfbWrap[0 + 1] = hGrid->stopSfb; /*Q0*/ - move16(); - hGrid->sbWrap[0] = sub( shl( hGrid->startLine, 1 ), hGrid->stopLine ); /*Q0*/ - move16(); - hGrid->tile[0 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/ - move16(); - - BREAK; - default: - assert( 0 ); - } /*switch*/ - - /*************************************************************************/ - /*************************************************************************/ - - - /* adapt level envelope: */ - SWITCH( bitRateIndex ) - { - case IGF_BITRATE_RF_WB_13200: - case IGF_BITRATE_WB_9600: - hGrid->gFactor = 13107 /*0.80f Q14*/; - move16(); - hGrid->fFactor = 11469 /*0.70f Q14*/; - move16(); - hGrid->lFactor = 9830 /*0.60f Q14*/; - move16(); - BREAK; - case IGF_BITRATE_SWB_13200: - case IGF_BITRATE_FB_16400: - case IGF_BITRATE_SWB_16400: - hGrid->gFactor = 15237 /*0.93f Q14*/; - move16(); - hGrid->fFactor = 3277 /*0.20f Q14*/; - move16(); - hGrid->lFactor = 13926 /*0.85f Q14*/; - move16(); - BREAK; - case IGF_BITRATE_FB_24400: - case IGF_BITRATE_SWB_24400: - case IGF_BITRATE_FB_32000: - case IGF_BITRATE_SWB_32000: - hGrid->gFactor = 15811 /*0.965f Q14*/; - move16(); - hGrid->fFactor = 3277 /*0.20f Q14*/; - move16(); - hGrid->lFactor = 13926 /*0.85f Q14*/; - move16(); - BREAK; - case IGF_BITRATE_FB_48000: - case IGF_BITRATE_SWB_48000: - hGrid->gFactor = 16384 /*1.00f Q14*/; - move16(); - hGrid->fFactor = 3277 /*0.20f Q14*/; - move16(); - hGrid->lFactor = 16384 /*1.00f Q14*/; - move16(); - BREAK; - case IGF_BITRATE_SWB_9600: - case IGF_BITRATE_RF_SWB_13200: - default: - hGrid->gFactor = 16384 /*1.00f Q14*/; - move16(); - hGrid->fFactor = 0 /*0.00f Q14*/; - move16(); - hGrid->lFactor = 16384 /*1.00f Q14*/; - move16(); - } - FOR( t = add( hGrid->nTiles, 1 ); t < IGF_MAX_TILES; t++ ) - { - hGrid->tile[t] = 0; - move16(); - hGrid->sbWrap[t - 1] = 0; - move16(); - hGrid->sfbWrap[t] = 0; - move16(); - } -} -static void IGF_gridSetUp_ivas_fx( -#else /**********************************************************************/ /* IGF grid setup **************************************************************************/ static void IGF_gridSetUp( -#endif H_IGF_GRID hGrid, /* o : IGF grid handle */ Word16 bitRateIndex, /* i : IGF bitrate index */ const Word32 sampleRate, /* i : sample rate */ @@ -1112,13 +602,14 @@ static void IGF_gridSetUp( /**********************************************************************/ /* calculates energy per sfb via power spectrum **************************************************************************/ -void IGFCommonFuncsCalcSfbEnergyPowerSpec( const Word16 startSfb, /**< in: Q0 | start sfb index */ - const Word16 stopSfb, /**< in: Q0 | stop sfb index */ - const Word16 *swb_offset, /**< in: Q0 | IGF swb offset table */ - Word32 *pPowerSpectrum, /**< in: Q31 | power spectrum */ - Word16 *pPowerSpectrum_exp, /**< in: | Exponent of PowerSpectrum */ - Word32 *sfbEnergy, /**< out:Q31 | SFB energies , will be initialized inside this function */ - Word16 *sfbEnergy_exp /**< out: | Exponent of PowerSpectrum */ +void IGFCommonFuncsCalcSfbEnergyPowerSpec( + const Word16 startSfb, /**< in: Q0 | start sfb index */ + const Word16 stopSfb, /**< in: Q0 | stop sfb index */ + const Word16 *swb_offset, /**< in: Q0 | IGF swb offset table */ + Word32 *pPowerSpectrum, /**< in: Q31 | power spectrum */ + Word16 *pPowerSpectrum_exp, /**< in: | Exponent of PowerSpectrum */ + Word32 *sfbEnergy, /**< out:Q31 | SFB energies , will be initialized inside this function */ + Word16 *sfbEnergy_exp /**< out: | Exponent of PowerSpectrum */ ) { Word16 /*Q0*/ sfb; @@ -1149,18 +640,15 @@ void IGFCommonFuncsCalcSfbEnergyPowerSpec( const Word16 startSfb, /**< in /**********************************************************************/ /* calculate the MDCT square spectrum in the IGF range **************************************************************************/ -void IGFCommonFuncsMDCTSquareSpec( const Word16 sqrtBgn, /**< in: Q0 | start MDCT subband index */ - const Word16 sqrtEnd, /**< in: Q0 | stop MDCT subband index */ - const Word32 *mdctSpec, /**< in: | MDCT spectrum to square */ - const Word16 mdctSpec_e, /**< in: | exponent of mdctSpectrum */ - Word32 *mdctSquareSpec, /**< out: | MDCT square spectrum */ - Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - Word16 indexOffset, /**< in: Q0 | index offset */ - const Word16 element_mode /**< in: | IVAS element mode type */ -#else - Word16 indexOffset /**< in: Q0 | index offset */ -#endif +void IGFCommonFuncsMDCTSquareSpec( + const Word16 sqrtBgn, /**< in: Q0 | start MDCT subband index */ + const Word16 sqrtEnd, /**< in: Q0 | stop MDCT subband index */ + const Word32 *mdctSpec, /**< in: | MDCT spectrum to square */ + const Word16 mdctSpec_e, /**< in: | exponent of mdctSpectrum */ + Word32 *mdctSquareSpec, /**< out: | MDCT square spectrum */ + Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ + Word16 indexOffset, /**< in: Q0 | index offset */ + const Word16 element_mode /**< in: | IVAS element mode type */ ) { Word16 i; @@ -1182,7 +670,6 @@ void IGFCommonFuncsMDCTSquareSpec( const Word16 sqrtBgn, /**< in FOR( i = sqrtBgn; i < sqrtEnd; i++ ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IF( EQ_16( element_mode, EVS_MONO ) ) { tmp = round_fx_sat( L_shl_sat( mdctSpec[i], s1 ) ); /*(15 - mdctSpec_e)+ S1*/ @@ -1191,53 +678,11 @@ void IGFCommonFuncsMDCTSquareSpec( const Word16 sqrtBgn, /**< in { tmp = extract_h( L_shl( mdctSpec[i], s1 ) ); /*(15 - mdctSpec_e)+ S1*/ } -#else - tmp = round_fx_sat( L_shl_sat( mdctSpec[i], s1 ) ); /*(15 - mdctSpec_e)+ S1*/ -#endif mdctSquareSpec[j++] = L_mult0( tmp, tmp ); /*31 - mdctSquareSpec_e*/ move32(); } } -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/**********************************************************************/ /* -calculate the MDCT square spectrum in the IGF range (for IVAS) -**************************************************************************/ -void IGFCommonFuncsMDCTSquareSpec_ivas( const Word16 sqrtBgn, /**< in: Q0 | start MDCT subband index */ - const Word16 sqrtEnd, /**< in: Q0 | stop MDCT subband index */ - const Word32 *mdctSpec, /**< in: | MDCT spectrum to square */ - const Word16 mdctSpec_e, /**< in: | exponent of mdctSpectrum */ - Word32 *mdctSquareSpec, /**< out: | MDCT square spectrum */ - Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ - Word16 indexOffset /**< in: Q0 | index offset */ -) -{ - Word16 i; - Word16 j; - Word16 s1; - Word16 tmp; - - - /* get headroom, only in IGF range */ - s1 = getScaleFactor32( mdctSpec + sqrtBgn, sub( sqrtEnd, sqrtBgn ) ); - - /* set new exponent */ - *mdctSquareSpec_e = add( shl( sub( mdctSpec_e, s1 ), 1 ), 1 ); - move16(); - - /* MDCT square spectrum: MDCT^2 */ - j = add( sqrtBgn, indexOffset ); /* handle indexOffset with care, otherwise memory overruns may occur! */ - - - FOR( i = sqrtBgn; i < sqrtEnd; i++ ) - { - tmp = extract_h( L_shl( mdctSpec[i], s1 ) ); /*(15 - mdctSpec_e)+ S1*/ - mdctSquareSpec[j++] = L_mult0( tmp, tmp ); /*31 - mdctSquareSpec_e*/ - move32(); - } -} -#endif - /**********************************************************************/ /* changes the IGF configuration @@ -1323,88 +768,7 @@ Word16 IGFCommonFuncsIGFConfiguration( return retValue; } -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -Word16 IGFCommonFuncsIGFConfiguration_ivas_fx( - const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 element_mode, /* i : element mode */ - H_IGF_INFO hIGFInfo, /* o : IGF info handle */ - const Word16 rf_mode /* i : flag to signal the RF mode */ -) -{ - H_IGF_GRID hGrid; - Word16 retValue; - Word32 sampleRate; - Word16 frameLength; - Word16 igfMinFq; - Word16 maxHopsize; - - retValue = 0; /* bitrate index is unknown -> error! */ - move16(); - - /* interface call for reading in settings */ - hIGFInfo->bitRateIndex = IGF_MapBitRateToIndex( total_brate, bwidth, element_mode, rf_mode ); /*Q0*/ - - IF( NE_16( hIGFInfo->bitRateIndex, IGF_BITRATE_UNKNOWN ) ) - { - retValue = 1; /* no error */ - move16(); - - /* mapping to local values */ - sampleRate = igfMode[hIGFInfo->bitRateIndex].sampleRate; /*Q0*/ - move32(); - frameLength = igfMode[hIGFInfo->bitRateIndex].frameLength; /*Q0*/ - move16(); - igfMinFq = igfMode[hIGFInfo->bitRateIndex].igfMinFq; /*Q0*/ - move16(); - maxHopsize = igfMode[hIGFInfo->bitRateIndex].maxHopsize; /*Q0*/ - move16(); - /* basic information */ - hIGFInfo->sampleRate = sampleRate; /*Q0*/ - move32(); - hIGFInfo->frameLength = frameLength; /*Q0*/ - move16(); - hIGFInfo->maxHopsize = maxHopsize; /*Q0*/ - move16(); - hIGFInfo->nfSeedBuf[0] = 0; - move16(); - hIGFInfo->nfSeedBuf[1] = 0; - move16(); - hIGFInfo->nfSeed = &hIGFInfo->nfSeedBuf[0]; - move16(); - - /* set up regular IGF grid for TCX 20 (transfac = 1.f) */ - hGrid = &hIGFInfo->grid[IGF_GRID_LB_NORM]; - IGF_gridSetUp_ivas_fx( hGrid, - hIGFInfo->bitRateIndex, - sampleRate, - frameLength, - 16384 /*1 Q14*/, - igfMinFq ); - - /* set up IGF grid for CELP->TCX 20 transitions (transfac = 1.25) */ - hGrid = &hIGFInfo->grid[IGF_GRID_LB_TRAN]; - IGF_gridSetUp_ivas_fx( hGrid, - hIGFInfo->bitRateIndex, - sampleRate, - frameLength, - 20480 /*1.25 Q14*/, - igfMinFq ); - - /* set up IGF grid for TCX 10 (transfac = 0.5) */ - hGrid = &hIGFInfo->grid[IGF_GRID_LB_SHORT]; - IGF_gridSetUp_ivas_fx( hGrid, - hIGFInfo->bitRateIndex, - sampleRate, - frameLength, - 8192 /*0.50f Q14*/, - igfMinFq ); - } - - return retValue; /*Q0*/ -} -#endif /**********************************************************************/ /* selects cumulative frequency tables and offsets for the IGF SCF arithmetic coder diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index fa59284789eac7bc06cbb4e4c5c9f7cbc0de5d19..17d4ba062813a1586791e833f16142a798425d83 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1425,14 +1425,6 @@ void mdct_read_IGF_bits_fx( Decoder_State *st0 /* i : pointer to handle where bitstream is read */ ); -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -void IGFDecReadData_ivas_fx( - const IGF_DEC_INSTANCE_HANDLE hInstance, /* i : instance handle of IGF Deccoder */ - Decoder_State *st, /* i : decoder state */ - const Word16 igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 isIndepFrame /* i : if 1: arith dec force reset, if 0: no reset */ -); -#endif void stereo_tca_init_dec_fx( STEREO_TCA_DEC_HANDLE hStereoTCA /* i/o: Stereo TCA handle for Fixed */ ); @@ -1697,29 +1689,6 @@ void TonalMDCTConceal_Detect_ivas_fx( Word16 element_mode ); - -#ifndef HARMONIZE_FUNC -void ivas_DetectTonalComponents_fx( - Word16 indexOfTonalPeak[], - Word16 lowerIndex[], - Word16 upperIndex[], - Word16 *pNumIndexes, - const Word32 lastPitchLag, - const Word32 currentPitchLag, - const Word16 lastMDCTSpectrum[], - const Word16 lastMDCTSpectrum_exp, - const Word16 scaleFactors[], - const Word16 scaleFactors_exp[], - const Word16 scaleFactors_max_e, - const Word32 secondLastPowerSpectrum[], - const Word16 secondLastPowerSpectrum_e, - const Word16 nSamples, - const Word16 nSamplesCore, - Word16 floorPowerSpectrum, /* i : lower limit for power spectrum bins */ - const PsychoacousticParameters *psychParamsCurrent, - Word16 element_mode -); -#endif ivas_error stereo_dft_dec_create_fx( STEREO_DFT_DEC_DATA_HANDLE *hStereoDft, /* i/o: decoder DFT stereo handle */ const Word32 element_brate, /* i : element bitrate */ @@ -2541,15 +2510,6 @@ void ivas_param_mc_metadata_open_fx( HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* o : handle for the Parametric MC parameter coding state */ ); -#ifndef HQ_ALIGN_DUPLICATED_CODE -Word16 mdct_classifier_ivas_fx( - Encoder_State *st, /* i/o: Encoder state variable */ - const Word16 *fft_buff, /* i : FFT spectrum from fft_rel */ - const Word32 enerBuffer[], /* i : energy buffer */ - Word16 enerBuffer_exp, /* i : energy buffer exponent */ - const Word32 brate /* i : current brate, IVAS: nominal bitrate, EVS: st->total_brate */ -); -#endif /*----------------------------------------------------------------------------------* * Range Coder prototypes diff --git a/lib_com/options.h b/lib_com/options.h index 40df8a614498156405900a7c127de36e16c39298..10649419f741d49c9a83d1b6616ef9696e5edebb 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -54,7 +54,7 @@ /*#define WMOPS_PER_FRAME*/ /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ /*#define WMOPS_DETAIL*/ /* Output detailed complexity printout for every function. Increases runtime overhead */ /*#define WMOPS_WC_FRAME_ANALYSIS*/ /* Output detailed complexity analysis for the worst-case frame */ -/*define MEM_COUNT_DETAILS*/ /* Output detailed memory analysis for the worst-case frame (writes to the file "mem_analysis.csv") */ +/*#define MEM_COUNT_DETAILS*/ /* Output detailed memory analysis for the worst-case frame (writes to the file "mem_analysis.csv") */ #ifdef DEBUGGING /*#define DBG_BITSTREAM_ANALYSIS*/ /* Write bitstream with annotations to a text file */ @@ -84,37 +84,19 @@ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ #define HARM_HQ_CORE_KEEP_BE /* hack to keep all BE after HQ core functions harmonization; pending resolving issues #2450, #2451, #2452 */ -#define HQ_ALIGN_DUPLICATED_CODE /* Eri: Align duplicated code */ -#define FIX_2467_RENAME_GSC_FUNCTION /* VA: basop issue 2467: Removal of unused function/table and renaming of _ivas_fx versions to default ones. */ -#define HARMONIZE_FUNC /* VA: basop issue 2460: Remove duplicated code: various functions */ -#define FIX_FLOAT_1536_INIT_NO_PARAM_LPC /* FhG: make sure no_param_lpc is initialized in core_encode_twodiv() */ -#define FIX_BASOP_2871_INIT_Q_SYN_FACTOR /* FhG: make sure, st_fx->Q_syn_factor gets initialized during decoder startup */ -#define FIX_BASOP_2470_POWER_SPEC_E_INIT /* FhG: make sure powerSpec_e is always initialized in core_signal_analysis_high_bitrate_fx() */ -#define FIX_BASOP_2475_ASSERT_IN_MASA2_REND_TO_MONO /* Nokia: basop issue 2475: Fix MASA2 to MONO rendering within IVAS_rend */ -#define FIX_2346_DUPLICATED_IGF_FUNCTIONS /* FhG: basop issue 2346: Review potentially duplicated IGF functions */ -#define FIX_1525_UNINIT_FORMAT_SWITCHING_DEC /* VA: float issue 1525: fix reading of uninitialized memory in format switching at the decoder */ #define FIX_BASOP_2457_HARM_GEN /* FhG: harmonization of function generate_comfort_noise_dec_hf_ivas_fx()*/ -#define HARMONIZE_2446_CON_TCX_FX /* FhG: basop issue: 2446 harmonization of function con_tcx_fx() */ #define FIX_BASOP_2478_HARM_ENC_PRM_HM /* FhG: basop issue 2478: harmonize enc_prm_hm() and enc_prm_hm_ivas_fx() */ -#define FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC /* Nokia: Fix to convert non-converted binary operations */ -#define FIX_2455_HARMONIZE_generate_comfort_noise_enc /* FhG: harmonize generate_comfort_noise_enc and generate_comfort_noise_enc_ivas */ -#define FIX_2455_HARMONIZE_configureFdCngEnc /* FhG: harmonize generate_comfort_noise_enc and generate_comfort_noise_enc_ivas */ +#define FIX_2455_HARMONIZE_generate_comfort_noise_enc /* FhG: harmonize generate_comfort_noise_enc and generate_comfort_noise_enc_ivas */ +#define FIX_2455_HARMONIZE_configureFdCngEnc /* FhG: harmonize generate_comfort_noise_enc and generate_comfort_noise_enc_ivas */ + /* #################### End BE switches ################################## */ /* #################### Start NON-BE switches ############################ */ /* any switch which is non-be wrt. TS 26.251 V3.0 */ -#define FIX_2448_RENDERER_MSAN_ERROR /* FhG: basop issue 2448: fix MSAN error with MSA rendering */ -#define FIX_2471_REMOVE_POSSIBLE_OVRF /* VA: basop issue 2471: correcting undesired overflow */ -#define FIX_2465_Q_BWE_EXC /* VA: basop issue 2465: fix calculation of Q_bwe_exc in SWB TBE encoder */ -#define FIX_2436_CLDFBANAHANDLE_ADRESS /* FhG: cldfb handle pointer were handed over in faulty manner*/ -#define FIX_BASOP_2436_REUSED_CLDFB_IN_OMASA_SR /* FhG: basop issue 2436 (related to basop 2283): fix garbage output for >1 object OMASA with extrend as ISAR prerenderer */ -#define FIX_BASOP_2472_IGF_SP_AUD_DEC_CHAN /* FhG: always use channel 1 for sp_aud_decision0[] being passed to ProcessIGF_ivas_fx() */ -#define FIX_BASOP_REMOVE_SYNTH2_FX /* FhG: Replace 32bit olapBufferSynth2_fx with 16bit olapBufferSynth2 buffer */ -#define FIX_FLOAT_1528_5MS_REND_ISM_META_DELAY_COMPENSATION /* Nokia: float issue 1528: Fixes incorrect compensation for ISM metadata delay in 5ms TD rendering */ #define FIX_2398_PRECISSION_ORIENTATION_TRACKING /* FhG: use refinement of Sqrt32 within certain functions*/ -#define FIX_2462_PARCOR_FIX /* VA: issue 2462: Fix bug in calculating parcor coefficient in Calc_rc0_h() */ + /* ##################### End NON-BE switches ########################### */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 00c0cd9ab79f16f2f2dbaff94b4d1fd9a26558dd..de383d0a7a6919950b97eea9f34fc0025ffad88d 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -668,7 +668,6 @@ void enforce_zero_for_min_envelope_fx( const Word16 *sfm_end /* i : Sub band end indices Q0 */ ); -#ifdef HQ_ALIGN_DUPLICATED_CODE void apply_envelope_enc_fx( const Word16 *coeff, /* i : Normalized spectrum Q12 */ const Word16 *norm, /* i : Envelope Q0 */ @@ -677,16 +676,6 @@ void apply_envelope_enc_fx( const Word16 *sfm_end, /* i : Sub band end indices Q0 */ Word32 *coeff_out /* o : scaled spectrum Q12 */ ); -#else -void apply_envelope_enc_ivas_fx( - const Word16 *coeff, /* i/o: Coded/noisefilled normalized spectrum Q12 */ - const Word16 *norm, /* i : Envelope Q0 */ - const Word16 num_sfm, /* i : Total number of bands Q0 */ - const Word16 *sfm_start, /* i : Sub band start indices Q0 */ - const Word16 *sfm_end, /* i : Sub band end indices Q0 */ - Word32 *coeff_out /* o : coded/noisefilled spectrum Q12 */ -); -#endif void apply_envelope_fx( const Word16 *coeff, /* i : Coded/noisefilled normalized spectrum Q12 */ @@ -2230,20 +2219,7 @@ void E_UTIL_synthesis_fx( const Word16 update, const Word16 m ); -#ifndef HARMONIZE_FUNC -void synth_mem_updt2( - const Word16 L_frame, /* i : frame length */ - const Word16 last_L_frame, /* i : frame length */ - Word16 old_exc[], /* i/o: excitation buffer */ - Word16 mem_syn_r[], /* i/o: synthesis filter memory */ - Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ - Word16 mem_syn[], /* o : synthesis filter memory for find_target */ - const Word16 dec /* i : flag for decoder indication */ -); -void ivas_synth_mem_updt2_fx( -#else void synth_mem_updt2_fx( -#endif const Word16 L_frame, /* i : frame length */ const Word16 last_L_frame, /* i : frame length */ Word16 old_exc[], /* i/o: excitation buffer */ @@ -4180,16 +4156,6 @@ void ifft3_fx( const Word16[], Word16[], const Word16 ); -#ifndef HQ_ALIGN_DUPLICATED_CODE -void fft3_fx_ivas( - const Word32 X[], - Word32 Y[], - const Word16 n ); -void ifft3_fx_ivas( - const Word32 X[], - Word32 Y[], - const Word16 n ); -#endif void r_fft_fx_lc( const Word16 *phs_tbl, /* i : Table of phase */ @@ -4442,29 +4408,6 @@ void longshr( Word16 bits, Word16 len ); -#ifndef FIX_2467_RENAME_GSC_FUNCTION -void bands_and_bit_alloc_fx( - const Word16 cor_strong_limit, /* i : HF correlation */ - const Word16 noise_lev, /* i : dwn scaling factor */ - const Word32 core_brate, /* i : core bit rate */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - Word16 *bit, /* i/o: Number of bit allowed for frequency quantization */ - const Word16 *Ener_per_bd_iQ, /* i/o: Quantized energy vector */ - Word16 *max_ener_band, /* o : Sorted order */ - Word16 *out_bits_per_bands, /* i/o: Number of bit allowed per allowed subband Q3 */ - Word16 *nb_subbands, /* o : Number of subband allowed */ - const Word16 *exc_diff, /* i : Difference signal to quantize (encoder side only) */ - Word16 *concat_in, /* o : Concatened PVQ's i vector (encoder side only) */ - Word16 *pvq_len, /* o : Number of bin covered with the PVQ */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : i signal bandwidth */ - const Word16 GSC_noisy_speech, /* i : GSC noisy speech flag */ - const Word16 L_frame, /* i : frame length */ - const Word16 element_mode, /* i : element mode */ - const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ -); -#endif void fine_gain_pred_fx( const Word16 *sfm_start, /* i : Sub band start indices */ const Word16 *sfm_end, /* i : Sub band end indices */ @@ -5220,26 +5163,10 @@ void IGFCommonFuncsMDCTSquareSpec( const Word16 mdctSpec_e, /**< in: | exponent of mdctSpectrum */ Word32 *mdctSquareSpec, /**< out: | MDCT square spectrum */ Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS Word16 indexOffset, /**< in: Q0 | index offset */ const Word16 element_mode /**< in: | IVAS element mode type */ -#else - Word16 indexOffset /**< in: Q0 | index offset */ -#endif ); -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -void IGFCommonFuncsMDCTSquareSpec_ivas( - const Word16 sqrtBgn, /**< in: Q0 | start MDCT subband index */ - const Word16 sqrtEnd, /**< in: Q0 | stop MDCT subband index */ - const Word32 *mdctSpec, /**< in: | MDCT spectrum to square */ - const Word16 mdctSpec_e, /**< in: | exponent of mdctSpectrum */ - Word32 *mdctSquareSpec, /**< out: | MDCT square spectrum */ - Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ - Word16 indexOffset /**< in: Q0 | index offset */ -); -#endif - Word16 IGFCommonFuncsIGFConfiguration( const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ const Word16 bwidth, /* i : audio bandwidth */ @@ -5248,15 +5175,6 @@ Word16 IGFCommonFuncsIGFConfiguration( const Word16 rf_mode /* i : flag to signal the RF mode */ ); -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -Word16 IGFCommonFuncsIGFConfiguration_ivas_fx( - const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 element_mode, /* i : element mode */ - H_IGF_INFO hIGFInfo, /* o : IGF info handle */ - const Word16 rf_mode /* i : flag to signal the RF mode */ -); -#endif Word16 IGFCommonFuncsIGFGetCFTables_fx( const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ const Word16 bwidth, /* i : audio bandwidth */ @@ -5701,7 +5619,6 @@ void concealment_signal_tuning_fx( Word16 *outx_new_fx /*Qoutx_new_fx*/, const Word16 past_core ); -#ifdef HARMONIZE_FUNC void DetectTonalComponents_fx( Word16 indexOfTonalPeak[], Word16 lowerIndex[], @@ -5721,51 +5638,8 @@ void DetectTonalComponents_fx( Word16 floorPowerSpectrum, /* i : lower limit for power spectrum bins */ const PsychoacousticParameters *psychParamsCurrent, const Word16 element_mode ); -#else -void DetectTonalComponents( - Word16 indexOfTonalPeak[], - Word16 lowerIndex[], - Word16 upperIndex[], - Word16 *pNumIndexes, - const Word32 lastPitchLag, - const Word32 currentPitchLag, - const Word16 lastMDCTSpectrum[], - const Word16 lastMDCTSpectrum_exp, - const Word16 scaleFactors[], - const Word16 scaleFactors_exp[], - const Word16 scaleFactors_max_e, - const Word32 secondLastPowerSpectrum[], - const Word16 nSamples, - const Word16 nSamplesCore, - Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ - Word16 element_mode ); - -void RefineTonalComponents( - Word16 indexOfTonalPeak[], - Word16 lowerIndex[], - Word16 upperIndex[], - Word16 phaseDiff[], - Word16 phases[], - Word16 *pNumIndexes, - const Word32 lastPitchLag, - const Word32 currentPitchLag, - const Word16 lastMDCTSpectrum[], - const Word16 lastMDCTSpectrum_exp, - const Word16 scaleFactors[], - const Word16 scaleFactors_exp[], - const Word16 scaleFactors_max_e, - const Word32 secondLastPowerSpectrum[], - const Word16 nSamples, - const Word16 nSamplesCore, - const Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ - Word16 element_mode ); -#endif -#ifdef HARMONIZE_FUNC void RefineTonalComponents_fx( -#else -void ivas_RefineTonalComponents_fx( -#endif Word16 indexOfTonalPeak[], Word16 lowerIndex[], Word16 upperIndex[], @@ -5787,15 +5661,6 @@ void ivas_RefineTonalComponents_fx( const Word16 element_mode, const PsychoacousticParameters *psychParamsCurrent ); -#ifndef HARMONIZE_FUNC -ivas_error PsychoacousticParameters_Init( - const Word32 sr_core, /* i : sampling rate of core-coder */ - const Word16 nBins, /* i : Number of bins (spectral lines) */ - const Word8 nBands, /* i : Number of spectrum subbands */ - const Word16 isTCX20, /* i : Flag indicating if the subband division is for TCX20 or TCX10 */ - const Word16 isWarped, /* i : Flag indicating if the scale is linear or warped */ - PsychoacousticParameters *pPsychParams ); -#endif ivas_error TonalMDCTConceal_Init_fx( TonalMDCTConcealPtr self, const Word16 nSamples, @@ -7093,12 +6958,7 @@ ivas_error core_switching_pre_dec_fx( const Word16 nchan_out, /* i : number of output channels */ const Word16 last_element_mode, /* i : last_element_mode */ const Word32 last_element_brate, /* i : last element bitrate */ -#if defined( FIX_BASOP_REMOVE_SYNTH2_FX ) const Word16 Q_old_synthFB ); -#else - const Word16 Q_old_synthFB, - Word16 *Q_olapBufferSynth2 ); -#endif ivas_error core_switching_post_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ @@ -7450,7 +7310,6 @@ void stat_noise_uv_dec_fx( const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ ); -#ifdef HQ_ALIGN_DUPLICATED_CODE void stat_noise_uv_mod_fx( const Word16 element_mode, /* i : element mode */ const Word16 coder_type, /* i : Coder type */ @@ -7474,53 +7333,6 @@ void stat_noise_uv_mod_fx( Word16 *Q_stat_noise, /* i/o: noise scaling */ Word16 *Q_stat_noise_ge /* i/o: noise scaling */ ); -#else -void stat_noise_uv_mod_fx( - const Word16 coder_type, /* i : Coder type */ - Word16 noisiness, /* i : noisiness parameter Q0 */ - const Word16 *lsp_old, /* i : old LSP vector at 4th sfr Q15 */ - const Word16 *lsp_new, /* i : LSP vector at 4th sfr Q15 */ - const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q15 */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q12 */ - Word16 *exc2, /* i/o: excitation buffer Q_exc */ - Word16 Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ - const Word16 bfi, /* i : Bad frame indicator */ - Word32 *ge_sm, /* i/o: smoothed excitation gain Q_ge */ - Word16 *uv_count, /* i/o: unvoiced counter */ - Word16 *act_count, /* i/o: activation counter */ - Word16 lspold_s[], /* i/o: old LSP Q15 */ - Word16 *noimix_seed, /* i/o: mixture seed Q0 */ - Word16 *st_min_alpha, /* i/o: minimum alpha Q15 */ - Word16 *exc_pe, /* i/o: scale Q_stat_noise Q_stat_noise */ - const Word32 bitrate, /* i : core bitrate */ - const Word16 bwidth_fx, /* i : input bandwidth */ - Word16 *Q_stat_noise, /* i/o: noise scaling */ - Word16 *Q_stat_noise_ge /* i/o: noise scaling */ -); - -void stat_noise_uv_mod_ivas_fx( - const Word16 coder_type, /* i : Coder type */ - Word16 noisiness, /* i : noisiness parameter Q=0 */ - const Word16 *lsp_old, /* i : old LSP vector at 4th sfr Q=15*/ - const Word16 *lsp_new, /* i : LSP vector at 4th sfr Q=15*/ - const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q=15*/ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q=12*/ - Word16 *exc2, /* i/o: excitation buffer Q=Q_exc*/ - Word16 *Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ - const Word16 bfi, /* i : Bad frame indicator */ - Word32 *ge_sm, /* i/o: smoothed excitation gain Q=Q_stat_noise_ge (6)*/ - Word16 *uv_count, /* i/o: unvoiced counter */ - Word16 *act_count, /* i/o: activation counter */ - Word16 lspold_s[], /* i/o: old LSP Q=15*/ - Word16 *noimix_seed, /* i/o: mixture seed Q0 */ - Word16 *st_min_alpha, /* i/o: minimum alpha Q=15*/ - Word16 *exc_pe, /* i/o: scale Q_stat_noise Q=Q_stat_noise*/ - const Word32 bitrate, /* i : core bitrate */ - const Word16 bwidth_fx, /* i : i bandwidth */ - Word16 *Q_stat_noise, /* i/o: noise scaling */ - Word16 *Q_stat_noise_ge /* i/o: noise scaling */ -); -#endif Word16 FEC_SinOnset_fx( Word16 *exc, /* i/o : exc vector to modify */ @@ -8015,23 +7827,9 @@ void IGFDecApplyMono( Word32 *spectrum, /**< in/out: | MDCT spectrum */ Word16 *spectrum_e, /**< in/out: | exponent of spectrum */ const Word16 igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - Word16 bfi, /**< in: | frame loss == 1, frame good == 0 */ - Word16 element_mode /**< in: | IVAS element mode */ -#else - Word16 bfi /**< in: | frame loss == 1, frame good == 0 */ -#endif -); -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -void IGFDecApplyMono_ivas( - const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - Word32 *spectrum, /**< in/out: | MDCT spectrum */ - Word16 *spectrum_e, /**< in/out: | exponent of spectrum */ - const Word16 igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ Word16 bfi, /**< in: | frame loss == 1, frame good == 0 */ Word16 element_mode /**< in: | IVAS element mode */ ); -#endif void IGFDecApplyStereo( const IGF_DEC_INSTANCE_HANDLE hIGFDecL, /* i : instance handle of IGF Decoder */ @@ -8055,38 +7853,13 @@ void IGFDecSetMode( const Word16 defaultStopLine, /* i : default stop subband index */ const Word16 rf_mode /* i : flag to signal the RF mode */ ); -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -void IGFDecSetMode_ivas_fx( - const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i : instance handle of IGF Decoder */ - const Word32 total_brate, /* i : bitrate */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 defaultStartLine, /* i : default start subband index */ - const Word16 defaultStopLine, /* i : default stop subband index */ - const Word16 rf_mode /* i : flag to signal the RF mode */ -); -#endif -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -void IGFDecUpdateInfo( - const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word16 igfGridIdx /**< in: | IGF grid index */ -); -#endif -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS void IGFDecUpdateInfo( const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Decoder */ const Word16 subFrameIdx, /* i : index of subframe */ const Word16 igfGridIdx, /* i : IGF grid index */ const Word16 element_mode /* i : IVAS element mode type */ ); -#else -void IGFDecUpdateInfo_ivas_fx( - const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Decoder */ - const Word16 subFrameIdx, /* i : subframe index */ - const Word16 igfGridIdx /* i : IGF grid index */ -); -#endif void IGFDecCopyLPCFlatSpectrum( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ @@ -8333,13 +8106,6 @@ void modify_lsf( const Word16 reset_q /* Q0 */ ); -#ifndef HARMONIZE_2446_CON_TCX_FX -void con_tcx_fx( - Decoder_State *st, /* i/o: coder memory state */ - Word16 synth[] /* i/o: synth[] Q0 */ -); -#endif // !HARMONIZE_2446_CON_TCX_FX - /* o : damping factor Q14*/ Word16 Damping_fact_fx( const Word16 coder_type, /* i : coding type in last good received frame */ @@ -8853,16 +8619,6 @@ void decoder_tcx_post_ivas_fx( Word16 bfi, Word16 MCT_flag ); -#ifndef HARMONIZE_2446_CON_TCX_FX -void con_tcx_ivas_fx( - Decoder_State *st, /* i/o: coder memory state */ - Word16 synth[], /* i/o: synth[] Q0 */ - const Word16 coh, /* i : coherence of stereo signal */ - Word16 *noise_seed, /* i/o: noise seed for stereo */ - const Word16 only_left, /* i : TD-PLC only in left channel */ - const Word16 *A_cng /* i : CNG LP filter coefficients */ -); -#else void con_tcx_fx( Decoder_State *st, /* i/o: coder memory state */ Word16 synth[], /* i/o: synth[] Q0 */ @@ -8871,7 +8627,6 @@ void con_tcx_fx( const Word16 only_left, /* i : TD-PLC only in left channel */ const Word16 *A_cng /* i : CNG LP filter coefficients */ ); -#endif // !HARMONIZE_2446_CON_TCX_FX void ivas_mdct_core_reconstruct_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -9880,25 +9635,6 @@ void IGFSaveSpectrumForITF_ivas_fx( const Word32 *pITFSpectrum, /* i : MDCT spectrum */ Word16 exp_pITFSpectrum ); -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -Word16 IGFEncWriteBitstream_ivas_fx( - const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *pBitOffset, /* i : ptr to bitOffset counter */ - const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 isIndepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ -); -#endif -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -Word16 IGFSCFEncoderEncode_ivas_fx( - IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data or NULL in case there was no instance created */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 bitCount, /* i : offset to the first bit in bitbuffer which should be readed by iisArithDecoderDecode function */ - Word16 *sfe, /* i : ptr to an array which contain quantized scalefactor energies */ - const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ -); -#endif Word16 ari_encode_14bits_ext_ivas_fx( Word16 *ptr, /* Q0 */ Word16 bp, /* Q0 */ @@ -10066,15 +9802,6 @@ void SetModeIndex_ivas_fx( const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) Q0*/ ); -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -void IGFEncSetMode_ivas_fx( - const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */ - const Word32 total_brate, /* i : encoder total bitrate */ - const Word16 bwidth, /* i : encoder audio bandwidth */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 rf_mode /* i : flag to signal the RF mode */ -); -#endif void init_tcx_cfg_ivas_fx( TCX_CONFIG_HANDLE hTcxCfg, const Word32 total_brate, @@ -10441,11 +10168,7 @@ Word16 quant_2p_2N1_fx( const Word16 N /* i: number of bits FOR position */ ); -#ifdef FIX_2467_RENAME_GSC_FUNCTION void bands_and_bit_alloc_fx( -#else -void bands_and_bit_alloc_ivas_fx( -#endif const Word16 cor_strong_limit, /* i : HF correlation */ const Word16 noise_lev, /* i : dwn scaling factor */ const Word32 core_brate, /* i : core bit rate */ diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 2843d1d6b7424e55cdbc390e13133af8aab77728..5d5feebcbeeb8424eda7b769749f826c3e05d86a 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -1045,9 +1045,6 @@ extern const Word16 YG_dicHR_4_16kHz_fx[]; /* Q12 */ extern const Word16 YG_meanL2G_16kHz_fx[]; /* Q12 */ extern const Word16 YG_dicL2G_16kHz_fx[]; /* Q12 */ extern const Word16 GSC_freq_bits[]; // Q0 -#ifndef FIX_2467_RENAME_GSC_FUNCTION -extern const Word32 GSC_freq_bits_fx[]; /*Q18*/ -#endif extern const Word32 GSC_freq_bits_fx_Q18[]; /*Q18*/ extern const Word16 GSC_freq_DL0_bits[]; /* Q0 */ extern const Word16 Compl_GSC_freq_bits[]; /* Q0 */ diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index 376333284e1648f7227b1e70cfcd1088b9983cb2..f73ab13f3fe3c17ccc95e9137c253542e6928634 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -17264,23 +17264,6 @@ const Word16 GSC_freq_bits[] = 26, 96, 0, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4 /* ACELP_24k40*/ }; // Q0 -#ifndef FIX_2467_RENAME_GSC_FUNCTION -const Word32 GSC_freq_bits_fx[] =/*Q18*/ -{ - 5505024, 17563648, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0, /* ACELP_5k00*/ - 5505024, 17563648, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0, /* ACELP_6k15*/ - 5505024, 17563648, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0, /* ACELP_7k20*/ - 5505024, 19660800, -1048576, 6815744, 4194304, 3145728, 2883584, 2359296, 0, 0, 1048576, 1048576, 262144, 262144, 786432, 0, 0, /* ACELP_8k00*/ - 6815744, 20971520, -786432, 7340032, 4718592, 3407872, 3145728, 2359296, 0, 0, 1048576, 1048576, 262144, 262144, 786432, 0, 0, /* ACELP_8k00*/ - 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_11k60*/ - 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_12k15*/ - 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_12k85*/ - 8126464, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_13k20*/ 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_14k80*/ - 8126464, 25165824, -262144, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_13k20*/ 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_16k40*/ - 8126464, 25165824, 0, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_22k60*/ 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_16k40*/ - 8126464, 25165824, 0, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_22k60*/ 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_16k40*/ -}; -#endif const Word32 GSC_freq_bits_fx_Q18[] =/*Q18*/ { 5505024, 17301504, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0, diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 148c7587388be3ba6c7c3db5f610ba1f07f793e7..b9f0119ceacc38de2fdfbeb954105b694bf83e2b 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -367,9 +367,6 @@ typedef struct Word16 fftlenFac; // Q0 Word16 timeDomainBuffer[L_FRAME16k]; /*Q15*/ -#ifndef FIX_BASOP_REMOVE_SYNTH2_FX - Word32 olapBufferSynth2_fx[FFTLEN]; -#endif const Word32 *olapWinAna_fx; /* Q30 */ const Word16 *olapWinSyn_fx; /* Q15 */ @@ -720,9 +717,6 @@ typedef struct igf_grid_struct Word16 tile[IGF_MAX_TILES + 1]; Word16 infoIsRefined; Word16 infoGranuleLen; -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS - Word16 infoTransFac; -#endif Word16 whiteningThreshold[2][IGF_MAX_TILES]; /* 2Q13 */ Word16 gFactor; /* 1Q14 */ Word16 fFactor; /* 1Q14 */ diff --git a/lib_com/stat_noise_uv_mod_fx.c b/lib_com/stat_noise_uv_mod_fx.c index 7db32531abf88c12bb666a4b9eb9a22eaa16c9e4..301fb108b9b5ddbe22be3c79c90cc0ff6bb25c27 100644 --- a/lib_com/stat_noise_uv_mod_fx.c +++ b/lib_com/stat_noise_uv_mod_fx.c @@ -22,13 +22,14 @@ static Word16 calc_tilt_fx( const Word16 *x, const Word16 Q_shift, const Word16 len ); Word32 L_Sqrt_Q0( const Word32 x ); + + /*--------------------------------------------------------------------* * stat_noise_uv_mod() * * Modifies excitation signal in stationary noise segments *--------------------------------------------------------------------*/ -#ifdef HQ_ALIGN_DUPLICATED_CODE void stat_noise_uv_mod_fx( const Word16 element_mode, /* i : element mode */ const Word16 coder_type, /* i : Coder type */ @@ -52,30 +53,6 @@ void stat_noise_uv_mod_fx( Word16 *Q_stat_noise, /* i/o: noise scaling */ Word16 *Q_stat_noise_ge /* i/o: noise scaling */ ) -#else -void stat_noise_uv_mod_fx( - const Word16 coder_type, /* i : Coder type */ - Word16 noisiness, /* i : noisiness parameter Q0 */ - const Word16 *lsp_old, /* i : old LSP vector at 4th sfr Q15*/ - const Word16 *lsp_new, /* i : LSP vector at 4th sfr Q15*/ - const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q15*/ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q12*/ - Word16 *exc2, /* i/o: excitation buffer Q_exc */ - Word16 Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ - const Word16 bfi, /* i : Bad frame indicator */ - Word32 *ge_sm, /* i/o: smoothed excitation gain Q_ge */ - Word16 *uv_count, /* i/o: unvoiced counter */ - Word16 *act_count, /* i/o: activation counter */ - Word16 lspold_s[], /* i/o: old LSP Q15 */ - Word16 *noimix_seed, /* i/o: mixture seed Q0 */ - Word16 *st_min_alpha, /* i/o: minimum alpha Q15 */ - Word16 *exc_pe, /* i/o: scale Q_stat_noise Q_stat_noise */ - const Word32 bitrate, /* i : core bitrate */ - const Word16 bwidth_fx, /* i : input bandwidth */ - Word16 *Q_stat_noise, /* i/o: noise scaling */ - Word16 *Q_stat_noise_ge /* i/o: noise scaling */ -) -#endif { Word16 exctilt; /* Q15 */ Word32 vare; /* Q31 */ @@ -87,11 +64,9 @@ void stat_noise_uv_mod_fx( Word16 oldlsp_mix[M]; Word16 midlsp_mix[M]; Word16 newlsp_mix[M]; - Word16 beta; /* Q15 */ - Word16 Noimix_fract; /* (noimix_fac - 1.0) in Q15 */ -#ifdef HQ_ALIGN_DUPLICATED_CODE + Word16 beta; /* Q15 */ + Word16 Noimix_fract; /* (noimix_fac - 1.0) in Q15 */ Word32 L_Noimix_fract; /* (noimix_fac - 1.0) in Q15 */ -#endif /* noimix_fax * x <-> x + Noimix_fract * x */ Word16 i_subfr; Word16 i, k; @@ -102,10 +77,8 @@ void stat_noise_uv_mod_fx( Word32 L_tmp_res, L_tmp, L_tmp3, L_Ge; Word16 En_shift, Tmp; - Word16 Exc2_local[L_FRAME]; /* local_copy in scaled Q_local*/ -#ifdef HQ_ALIGN_DUPLICATED_CODE + Word16 Exc2_local[L_FRAME]; /* local_copy in scaled Q_local*/ Word32 L_Exc2_local[L_FRAME]; /* local_copy in scaled Q_local*/ -#endif /*---------------------------------------------------------* * Init local variables @@ -114,10 +87,8 @@ void stat_noise_uv_mod_fx( move16(); min_alpha = 16384; move16(); -#ifdef HQ_ALIGN_DUPLICATED_CODE L_Noimix_fract = 0; move32(); -#endif test(); test(); @@ -134,23 +105,11 @@ void stat_noise_uv_mod_fx( tmp_den = 31; move16(); tmp_shift = norm_s( tmp_den ); -#ifndef HQ_ALIGN_DUPLICATED_CODE - move16(); -#endif L_tmp_res = L_deposit_h( noisiness ); L_tmp_res = L_shl( L_tmp_res, sub( tmp_shift, 1 ) ); tmp_den = shl( tmp_den, tmp_shift ); -#ifndef HQ_ALIGN_DUPLICATED_CODE - move16(); -#endif tmp_res = div_l( L_tmp_res, tmp_den ); -#ifndef HQ_ALIGN_DUPLICATED_CODE - move16(); -#endif min_alpha = add_sat( tmp_res, 16384 ); -#ifndef HQ_ALIGN_DUPLICATED_CODE - move16(); -#endif /**st_min_alpha = sub(*st_min_alpha, 1638); move16();*/ min_alpha = s_max( min_alpha, sub( *st_min_alpha, 1638 ) ); @@ -172,17 +131,9 @@ void stat_noise_uv_mod_fx( Copy( exc2, Exc2_local, L_FRAME ); /* bound Q for internal use, optimization possible */ -#ifdef HQ_ALIGN_DUPLICATED_CODE Q_local = s_min( 11, s_max( -1, *Q_exc ) ); -#else - Q_local = s_min( 11, s_max( -1, Q_exc ) ); -#endif /* local excitation Q and incoming excitation Q*/ -#ifdef HQ_ALIGN_DUPLICATED_CODE Qdiff = sub( Q_local, *Q_exc ); -#else - Qdiff = sub( Q_local, Q_exc ); -#endif /* only shift if incoming Q is outside [11..-1] shift is done in energy calculations aswell */ Scale_sig( Exc2_local, L_FRAME, Qdiff ); /* current excitation Q and previous stat_noise states Q */ @@ -281,7 +232,7 @@ void stat_noise_uv_mod_fx( L_tmp_res = L_mac( 0, alpha, alpha ); L_tmp_res = L_mac( L_tmp_res, alpha_m1, alpha_m1 ); tmp_den = round_fx( L_Frac_sqrtQ31( L_tmp_res ) ); -#ifdef HQ_ALIGN_DUPLICATED_CODE + IF( EQ_16( element_mode, EVS_MONO ) ) { tmp_nom = sub( 32767, tmp_den ); @@ -298,13 +249,7 @@ void stat_noise_uv_mod_fx( Noimix_fract = tmp_res; // 15-exp_sqr move16(); } -#else - tmp_nom = sub( 32767, tmp_den ); - tmp_shift = norm_s( tmp_den ); - tmp_den = shl( tmp_den, tmp_shift ); - tmp_res = div_s( tmp_nom, tmp_den ); - Noimix_fract = shr( tmp_res, tmp_shift ); /* float value is in range 0.0 to 0.42 */ -#endif + /* L_Ge might be 0 in unvoiced WB */ L_Ge = L_max( L_Ge, 1 ); tmp_shift = norm_l( L_Ge ); @@ -313,7 +258,7 @@ void stat_noise_uv_mod_fx( L_tmp_res = Mult_32_16( *ge_sm, tmp_res ); /* Q_stat_noise_ge+45-Q_local-Q_ge-tmp_shift-15 */ L_tmp_res = Mult_32_16( L_tmp_res, sub( 32767, beta ) ); /*30-Q_local-tmp_shift+15-15 */ L_tmp_res = L_add_sat( L_shl_sat( L_tmp_res, sub( add( Q_local, tmp_shift ), 15 ) ), beta ); /* Q15 */ -#ifdef HQ_ALIGN_DUPLICATED_CODE + IF( EQ_16( element_mode, EVS_MONO ) ) { tmp_res = extract_h( L_shl_sat( L_tmp_res, 15 ) ); /* 15+15-16=14 */ @@ -323,10 +268,6 @@ void stat_noise_uv_mod_fx( { L_Noimix_fract = Mult_32_16( L_tmp_res, Noimix_fract ); /*15+15-exp_sqr-15 =15-exp_sqr */ } -#else - tmp_res = extract_h( L_shl_sat( L_tmp_res, 15 ) ); /* 15+15-16=14 */ - Noimix_fract = extract_l( Mult_32_16( L_tmp_res, Noimix_fract ) ); /*15+15-15 */ -#endif FOR( i = 0; i < L_FRAME; i++ ) { @@ -338,17 +279,12 @@ void stat_noise_uv_mod_fx( *--------------------------------------------------------------------*/ /* (1-alpha)*(float)sqrt(12.0f) * ((float)own_random(&(st->noimix_seed))/65536.0f) */ - randval = Random( noimix_seed ); /* +/-32767 */ - randval = mult_r( 28378, randval ); /* Q downscaled by 2 bits ends up in Q14 */ /*sqrt(12.0f) in Q13*/ -#ifdef HQ_ALIGN_DUPLICATED_CODE + randval = Random( noimix_seed ); /* +/-32767 */ + randval = mult_r( 28378, randval ); /* Q downscaled by 2 bits ends up in Q14 */ /*sqrt(12.0f) in Q13*/ randval = extract_l( L_shl( Mult_32_16( L_Ge, randval ), sub( 1, *Q_stat_noise_ge ) ) ); /*Q_local+Q_ge+14-15+1-Q_ge=Q_local */ -#else - randval = extract_l( L_shl( Mult_32_16( L_Ge, randval ), 1 - *Q_stat_noise_ge ) ); /*Q_local+Q_ge+14-15+1-Q_ge=Q_local */ -#endif - L_tmp = L_mult( Exc2_local[i], alpha ); /* Q_local + 16 */ - L_tmp = L_mac( L_tmp, randval, alpha_m1 ); /* Q_local + 16 */ + L_tmp = L_mult( Exc2_local[i], alpha ); /* Q_local + 16 */ + L_tmp = L_mac( L_tmp, randval, alpha_m1 ); /* Q_local + 16 */ -#ifdef HQ_ALIGN_DUPLICATED_CODE IF( EQ_16( element_mode, EVS_MONO ) ) { L_tmp3 = Mult_32_16( L_tmp, Noimix_fract ); /* Q_local+16+15-15 */ @@ -362,14 +298,8 @@ void stat_noise_uv_mod_fx( L_Exc2_local[i] = L_add( L_shr( L_tmp3, 1 ), Mpy_32_32( L_tmp, L_tmp_res ) ); // Q_local + 16 +15 -31 = Q_local move32(); } -#else - L_tmp3 = Mult_32_16( L_tmp, Noimix_fract ); /* Q_local+16+15-15 */ - L_tmp = L_add_sat( L_tmp3, L_shl_sat( Mult_32_16( L_tmp, tmp_res ), 1 ) ); /* Q_local+16+14-15+1 */ - Exc2_local[i] = extract_h( L_tmp ); /*Q_local */ - move16(); -#endif } -#ifdef HQ_ALIGN_DUPLICATED_CODE + IF( EQ_16( element_mode, EVS_MONO ) ) { *Q_stat_noise = Q_local; /* update for next call, routine can only be called once every frame */ @@ -395,319 +325,6 @@ void stat_noise_uv_mod_fx( move16(); Copy_Scale_sig_32_16( L_Exc2_local, exc2, L_FRAME, negate( shift ) ); // Q_exc } -#else - *Q_stat_noise = Q_local; /* update for next call, routine can only be called once every frame */ - move16(); - Qdiff = sub( Q_exc, Q_local ); /* local excitation and incoming excitation */ - Scale_sig( Exc2_local, L_FRAME, Qdiff ); - Copy( Exc2_local, exc2, L_FRAME ); -#endif - /*--------------------------------------------------------------------* - * Generate low-pass filtered version of ISP coefficients - *--------------------------------------------------------------------*/ - FOR( k = 0; k < M; k++ ) - { - move16(); - lspnew_s[k] = add( - mult( ISP_SMOOTHING_QUANT_A1_FX, lspold_s[k] ), - mult( 32767 - ISP_SMOOTHING_QUANT_A1_FX, lsp_new[k] ) ); - } - - /*--------------------------------------------------------------------* - * replace LPC coefficients - *--------------------------------------------------------------------*/ - - /*--------------------------------------------------------------------* - * pre-calculation of (1-beta) - *--------------------------------------------------------------------*/ - FOR( i = 0; i < M; i++ ) - { - move16(); - move16(); - move16(); - oldlsp_mix[i] = add( mult( beta, lsp_old[i] ), - mult( sub( 32767, beta ), lspold_s[i] ) ); - - midlsp_mix[i] = add( mult( beta, lsp_mid[i] ), - mult( sub( 32767, beta ), add( shr( lspold_s[i], 1 ), - shr( lspnew_s[i], 1 ) ) ) ); - - newlsp_mix[i] = add( mult( beta, lsp_new[i] ), - mult( sub( 32767, beta ), lspnew_s[i] ) ); - } - - int_lsp4_fx( L_FRAME, oldlsp_mix, midlsp_mix, newlsp_mix, Aq, M, 0 ); - Copy( lspnew_s, lspold_s, M ); - } - ELSE /* (unvoiced_vad != 0) */ - { - ( *act_count )++; - IF( GT_16( *act_count, 3 ) ) - { - *act_count = 3; - move16(); - *uv_count = 0; - move16(); - } - } -} - -#ifndef HQ_ALIGN_DUPLICATED_CODE -/*--------------------------------------------------------------------* - * stat_noise_uv_mod() - * - * Modifies excitation signal in stationary noise segments - *--------------------------------------------------------------------*/ - -void stat_noise_uv_mod_ivas_fx( - const Word16 coder_type, /* i : Coder type */ - Word16 noisiness, /* i : noisiness parameter Q=0 */ - const Word16 *lsp_old, /* i : old LSP vector at 4th sfr Q=15*/ - const Word16 *lsp_new, /* i : LSP vector at 4th sfr Q=15*/ - const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q=15*/ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q=12*/ - Word16 *exc2, /* i/o: excitation buffer Q=Q_exc*/ - Word16 *Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ - const Word16 bfi, /* i : Bad frame indicator */ - Word32 *ge_sm, /* i/o: smoothed excitation gain Q=Q_stat_noise_ge (6)*/ - Word16 *uv_count, /* i/o: unvoiced counter */ - Word16 *act_count, /* i/o: activation counter */ - Word16 lspold_s[], /* i/o: old LSP Q=15*/ - Word16 *noimix_seed, /* i/o: mixture seed Q0 */ - Word16 *st_min_alpha, /* i/o: minimum alpha Q=15*/ - Word16 *exc_pe, /* i/o: scale Q_stat_noise Q=Q_stat_noise*/ - const Word32 bitrate, /* i : core bitrate */ - const Word16 bwidth_fx, /* i : i bandwidth */ - Word16 *Q_stat_noise, /* i/o: noise scaling */ - Word16 *Q_stat_noise_ge /* i/o: noise scaling */ -) -{ - Word16 exctilt; /* Q15 */ - Word32 vare; /* Q31 */ - Word16 randval; /* Q?? */ - Word16 alpha; /* Q15 */ - Word16 alpha_m1; /* (1-alpha) Q15 */ - Word16 min_alpha; /* Q15 */ - Word16 lspnew_s[M]; /* Same for all LSP (Q15) */ - Word16 oldlsp_mix[M]; - Word16 midlsp_mix[M]; - Word16 newlsp_mix[M]; - Word16 beta; /* Q15 */ - Word16 Noimix_fract; /* (noimix_fac - 1.0) in Q15 */ - Word32 L_Noimix_fract; /* (noimix_fac - 1.0) in Q15 */ - /* noimix_fax * x <-> x + Noimix_fract * x */ - Word16 i_subfr; - Word16 i, k; - - /* Work variables for div and sqrt */ - Word16 tmp_nom, tmp_den, tmp_shift, tmp_res; - Word16 Qdiff, Q_local; /* new Q to be used for states Exc_pe and Ge_sm, and Exc2_local */ - Word32 L_tmp_res, L_tmp, L_tmp3, L_Ge; - - Word16 En_shift, Tmp; - Word16 Exc2_local[L_FRAME]; /* local_copy in scaled Q_local*/ - Word32 L_Exc2_local[L_FRAME]; /* local_copy in scaled Q_local*/ - - /*---------------------------------------------------------* - * Init local variables - *---------------------------------------------------------*/ - alpha = 32767; - move16(); - min_alpha = 16384; - move16(); - - test(); - test(); - test(); - IF( EQ_16( coder_type, INACTIVE ) && ( EQ_32( bitrate, ACELP_9k60 ) || ( LT_32( bitrate, ACELP_9k60 ) && GT_16( bwidth_fx, NB ) ) ) ) - { - min_alpha = *st_min_alpha; - move16(); - /*---------------------------------------------------------* - * decode noisiness parameter - *---------------------------------------------------------*/ - IF( bfi == 0 ) - { - tmp_den = 31; - move16(); - tmp_shift = norm_s( tmp_den ); - L_tmp_res = L_deposit_h( noisiness ); - L_tmp_res = L_shl( L_tmp_res, sub( tmp_shift, 1 ) ); - tmp_den = shl( tmp_den, tmp_shift ); - tmp_res = div_l( L_tmp_res, tmp_den ); - min_alpha = add_sat( tmp_res, 16384 ); - - /**st_min_alpha = sub(*st_min_alpha, 1638); move16();*/ - min_alpha = s_max( min_alpha, sub( *st_min_alpha, 1638 ) ); - - *st_min_alpha = min_alpha; - move16(); - } - } - - /*---------------------------------------------------------* - * Mix excitation signal with random noise - *---------------------------------------------------------*/ - test(); - test(); - test(); - IF( EQ_16( coder_type, INACTIVE ) && ( EQ_32( bitrate, ACELP_9k60 ) || ( LT_32( bitrate, ACELP_9k60 ) && GT_16( bwidth_fx, NB ) ) ) ) - { - /* use a local working copy for scaling and filtering, not needed if input Q-range is fixed */ - Copy( exc2, Exc2_local, L_FRAME ); - - /* bound Q for internal use, optimization possible */ - Q_local = s_min( 11, s_max( -1, *Q_exc ) ); - /* local excitation Q and incoming excitation Q*/ - Qdiff = sub( Q_local, *Q_exc ); - /* only shift if incoming Q is outside [11..-1] shift is done in energy calculations aswell */ - Scale_sig( Exc2_local, L_FRAME, Qdiff ); - /* current excitation Q and previous stat_noise states Q */ - Qdiff = sub( Q_local, *Q_stat_noise ); - - *Q_stat_noise_ge = GE_SHIFT; - move16(); /* assign the fixed Q for Ge_sm */ - - IF( Qdiff != 0 ) - { - Scale_sig( exc_pe, 1, Qdiff ); - } - - En_shift = 0; - move16(); - if ( GT_16( Q_local, 3 ) ) - { - /* increase margin for energy accumulation in calc_tilt and vare accumulation */ - En_shift = sub( Q_local, 3 ); - } - - IF( LT_16( min_alpha, TILT_COMP_LIM_FX ) ) - { - FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) - { - exctilt = calc_tilt_fx( &Exc2_local[i_subfr], En_shift, L_SUBFR ); /*Q15 */ - exctilt = mult( shl_sat( sub( TILT_COMP_LIM_FX, min_alpha ), 2 ), exctilt ); /*Q15 */ - preemph_fx( &Exc2_local[i_subfr], exctilt, L_SUBFR, exc_pe ); - } - } - - ( *uv_count )++; - - IF( LE_16( *uv_count, START_NG ) ) - { - alpha = 32767; - move16(); - *act_count = 3; - move16(); - Copy( lsp_new, lspold_s, M ); - } - ELSE - { - *uv_count = s_min( *uv_count, FULL_NG ); - move16(); - tmp_nom = sub( *uv_count, START_NG ); - tmp_den = sub( FULL_NG, START_NG ); - tmp_shift = norm_s( tmp_den ); - tmp_den = shl( tmp_den, tmp_shift ); - tmp_res = div_s( tmp_nom, tmp_den ); - tmp_res = shl_sat( tmp_res, tmp_shift ); - alpha = add( 32767, mult( tmp_res, sub( min_alpha, 32767 ) ) ); - - *act_count = 0; - move16(); - } - - /*---------------------------------------------------------* - * calculate lowpass filtered excitation gain - *---------------------------------------------------------*/ - Tmp = shr( Exc2_local[0], En_shift ); - vare = L_mult( Tmp, Tmp ); /* positive accumulation only */ - FOR( i = 1; i < L_FRAME; i++ ) - { - Tmp = shr( Exc2_local[i], En_shift ); - vare = L_mac_sat( vare, Tmp, Tmp ); /* positive accumulation only */ - } - - /* obtain Ge in Q_local with safety saturation */ - L_Ge = L_shl( L_Sqrt_Q0( L_shr( vare, 1 ) ), add( sub( *Q_stat_noise_ge, 4 ), En_shift ) ); /* L_Ge in Q_local*/ - - /* st->ge_sm = ISP_SMOOTHING_QUANT_A1 * st->ge_sm + (1.0f-ISP_SMOOTHING_QUANT_A1) * ge */ - - IF( EQ_16( *uv_count, 1 ) ) - { - *ge_sm = L_shr( L_Ge, Q_local ); - move32(); - } - ELSE - { - L_tmp = Mult_32_16( L_Ge, P1 ); /* 0.1*ge still in Q local */ - L_tmp3 = Mult_32_16( *ge_sm, P9 ); /* 0.9*ge_sm still in Q_ge */ - - *ge_sm = L_add( L_shr( L_tmp, Q_local ), L_tmp3 ); - move32(); /* addition in Q_ge domain*/ - } - - /*--------------------------------------------------------------------* - * generate mixture of excitation and noise - * float: - * noimix_fac = 1.0f/(float)sqrt(alpha*alpha + (1-alpha)*(1-alpha)) - *--------------------------------------------------------------------*/ - - beta = shl( sub( alpha, 16384 ), 1 ); - alpha_m1 = sub( 32767, alpha ); - L_tmp_res = L_mac( 0, alpha, alpha ); - L_tmp_res = L_mac( L_tmp_res, alpha_m1, alpha_m1 ); - tmp_den = round_fx( L_Frac_sqrtQ31( L_tmp_res ) ); - Word16 exp_sqr = 0; - move16(); - tmp_res = BASOP_Util_Divide1616_Scale( 32767, tmp_den, &exp_sqr ); // 15-exp_sqr - Noimix_fract = tmp_res; // 15-exp_sqr - move16(); - /* L_Ge might be 0 in unvoiced WB */ - L_Ge = L_max( L_Ge, 1 ); - tmp_shift = norm_l( L_Ge ); - tmp_den = extract_h( L_shl( L_Ge, tmp_shift ) ); /* Q_local+Q_ge+tmp_shift-16 */ - tmp_res = div_s( 1 << 14, tmp_den ); /* 15+14-Q_local-tmp_shift-Q_ge+16 */ - L_tmp_res = Mult_32_16( *ge_sm, tmp_res ); /* Q_stat_noise_ge+45-Q_local-Q_ge-tmp_shift-15 */ - L_tmp_res = Mult_32_16( L_tmp_res, sub( 32767, beta ) ); /*30-Q_local-tmp_shift+15-15 */ - L_tmp_res = L_add_sat( L_shl_sat( L_tmp_res, sub( add( Q_local, tmp_shift ), 15 ) ), beta ); /* Q15 */ - L_Noimix_fract = Mult_32_16( L_tmp_res, Noimix_fract ); /*15+15-exp_sqr-15 =15-exp_sqr */ - - FOR( i = 0; i < L_FRAME; i++ ) - { - /*--------------------------------------------------------------------* - * flt: exc2[i] = noimix_fac*exc2[i] * alpha + st->ge_sm*Rnd*((1.0f)-alpha) - * flt: exc2[i] = (noimix_fract*exc2[i]+exc2 )* alpha + st->ge_sm*Rnd*((1.0f)-alpha) - * NB: currently uses 32bit accumulation for best low level performance, - * possibly overkill if input is always up-scaled - *--------------------------------------------------------------------*/ - - /* (1-alpha)*(float)sqrt(12.0f) * ((float)own_random(&(st->noimix_seed))/65536.0f) */ - randval = Random( noimix_seed ); /* +/-32767 */ - randval = mult_r( 28378, randval ); /* Q downscaled by 2 bits ends up in Q14 */ /*sqrt(12.0f) in Q13*/ - randval = extract_l( L_shl( Mult_32_16( L_Ge, randval ), sub( 1, *Q_stat_noise_ge ) ) ); /*Q_local+Q_ge+14-15+1-Q_ge=Q_local */ - - L_tmp = L_mult( Exc2_local[i], alpha ); /* Q_local + 16 */ - L_tmp = L_mac( L_tmp, randval, alpha_m1 ); /* Q_local + 16 */ - L_tmp3 = Mult_32_32( L_tmp, L_Noimix_fract ); /* Q_local+16+15-exp_sqr-15 =Q_local +1 */ - L_Exc2_local[i] = L_add( L_shr( L_tmp3, 1 ), Mpy_32_32( L_tmp, L_tmp_res ) ); // Q_local + 16 +15 -31 = Q_local - move32(); - } - Word32 max_val; - maximum_abs_32_fx( L_Exc2_local, L_FRAME, &max_val ); - Word16 shift = 0; - move16(); - IF( GT_32( max_val, ONE_IN_Q15 ) ) - { - shift = norm_l( max_val ); - shift = sub( Q31 - Q15, shift ); - *Q_exc = sub( Q_local, shift ); // Q_exc = Q_local -shift - move16(); - } - *Q_stat_noise = Q_local; /* update for next call, routine can only be called once every frame */ - move16(); - - Copy_Scale_sig_32_16( L_Exc2_local, exc2, L_FRAME, negate( shift ) ); // Q_exc /*--------------------------------------------------------------------* * Generate low-pass filtered version of ISP coefficients @@ -758,7 +375,7 @@ void stat_noise_uv_mod_ivas_fx( } } } -#endif + /*---------------------------------------------------------------------------* * calc_tilt() diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 01a54975501fcea4799c7c6acef6b0ee44fc2549..f90e31410c4e1786f0d857a31e899b26bbd9eaa8 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -648,12 +648,8 @@ void Calc_rc0_h( /* computation of the autocorrelation function acf */ IF( element_mode != EVS_MONO && enc_dec == ENC ) { -#ifdef FIX_2462_PARCOR_FIX tmp2 = shr( h[0], 2 ); L_acc = L_mult( tmp2, tmp2 ); -#else - L_acc = L_mult( h[0], h[0] ); // TBV: shouldn't it be "shr( h[0], 2 )" ? -#endif FOR( i = 1; i < LONG_H_ST; i++ ) { tmp2 = shr( h[i], 2 ); @@ -665,15 +661,9 @@ void Calc_rc0_h( ptrs = h; -#ifdef FIX_2462_PARCOR_FIX temp = shr( *ptrs++, 2 ); move16(); L_acc = L_mac( L_acc, temp, shr( *ptrs, 2 ) ); -#else - temp = *ptrs++; - move16(); - L_acc = L_mult( temp, *ptrs ); -#endif FOR( i = 1; i < LONG_H_ST - 1; i++ ) { temp = shr( *ptrs++, 2 ); @@ -704,11 +694,7 @@ void Calc_rc0_h( L_acc = L_mac( L_acc, temp, *ptrs ); } } -#ifdef FIX_2462_PARCOR_FIX L_acc = L_shl_sat( L_acc, sh_acf ); -#else - L_acc = L_shl( L_acc, sh_acf ); -#endif acf1 = extract_h( L_acc ); /* Compute 1st parcor */ diff --git a/lib_com/syn_filt_fx.c b/lib_com/syn_filt_fx.c index f04688bd7a1142216061d08dd966966dd2765dd0..58592f6177f17c555400fac2795a0f8987bcea27 100644 --- a/lib_com/syn_filt_fx.c +++ b/lib_com/syn_filt_fx.c @@ -548,11 +548,7 @@ void E_UTIL_synthesis_fx( * Update of synthesis filter memories in case of ACELP@12k8 <-> ACELP@16k switching *--------------------------------------------------------------------*/ -#ifdef HARMONIZE_FUNC void synth_mem_updt2_fx( -#else -void ivas_synth_mem_updt2_fx( -#endif const Word16 L_frame, /* i : frame length */ const Word16 last_L_frame, /* i : frame length */ Word16 old_exc[], /* i/o: excitation buffer st->Q_syn */ @@ -630,43 +626,3 @@ void ivas_synth_mem_updt2_fx( return; } -#ifndef HARMONIZE_FUNC - -void synth_mem_updt2( - const Word16 L_frame, /* i : frame length */ - const Word16 last_L_frame, /* i : frame length */ - Word16 old_exc[], /* i/o: excitation buffer st->Q_syn */ - Word16 mem_syn_r[], /* i/o: synthesis filter memory st->Q_syn */ - Word16 mem_syn2[], /* o : synthesis filter memory for find_target st->Q_syn */ - Word16 mem_syn[], /* o : synthesis filter memory for find_target st->Q_syn */ - const Word16 dec /* i : flag for decoder indication */ -) -{ - Word16 mem_syn_r_size_old, mem_syn_r_size_new; - - /* Residual and update old_exc */ - IF( GE_16( dec, DEC ) ) - { - lerp( old_exc + L_EXC_MEM_DEC - ( last_L_frame + last_L_frame / 2 ), old_exc + L_EXC_MEM_DEC - ( L_frame + L_frame / 2 ), L_frame + L_frame / 2, last_L_frame + last_L_frame / 2 ); - } - ELSE - { - lerp( old_exc + L_EXC_MEM - last_L_frame, old_exc + L_EXC_MEM - L_frame, L_frame, last_L_frame ); - } - - /*Resamp memory*/ - /*Size of LPC syn memory*/ - /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */ - mem_syn_r_size_old = shr( last_L_frame, 4 ); - mem_syn_r_size_new = shr( L_frame, 4 ); - - lerp( mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - - Copy( mem_syn_r + L_SYN_MEM - M, mem_syn2, M ); - - IF( mem_syn != NULL ) - { - Copy( mem_syn2, mem_syn, M ); - } -} -#endif diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c index 1b09f98d2f45240bbaff58865aaef770503e0bd0..2223bfa9cf5be67544a660dd0d6034e3a6b41576 100644 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -20,26 +20,13 @@ static void calcPseudoSpec( const Word32 *mdctSpec, const Word16 mdctSpec_exp, const Word16 nSamples, Word16 floorPowerSpectrum, Word32 *powerSpec, Word16 *powerSpec_exp ); static void getEnvelope( const Word16 nSamples, const Word32 *powerSpec, Word16 F0, Word32 *envelope, Word32 *smoothedSpectrum ); static void GetF0( Word16 const nSamples, Word16 const nSamplesCore, Word32 const *const powerSpectrum, Word32 const pitchLag, Word16 *const pOrigF0, Word16 *const pF0 ); -#ifndef HARMONIZE_FUNC -static void ivas_GetF0_fx( Word16 const nSamples, Word16 const nSamplesCore, Word32 const *const powerSpectrum, Word32 const pitchLag, Word16 *const pOrigF0, Word16 *const pF0 ); -#endif static void findStrongestHarmonics( const Word16 nSamples, const Word32 *powerSpectrum, const Word16 F0, const Word16 nTotalHarmonics, Word16 *pHarmonicIndexes, Word16 *pnHarmonics ); static void CorrectF0( const Word16 *pHarmonicIndexes, const Word16 nHarmonics, Word16 *pF0 ); -#ifndef HARMONIZE_FUNC -static void ivas_CorrectF0_fx( const Word16 *pHarmonicIndexes, const Word16 nHarmonics, Word16 *pF0 ); -#endif static void findCandidates( const Word16 nSamples, const Word32 *MDCTSpectrum, const Word16 MDCTSpectrum_exp, Word16 *thresholdModificationNew, Word16 floorPowerSpectrum ); static void modifyThreshold( Word16 i, Word16 F0, Word16 threshold, Word16 *thresholdModification ); static void modifyThresholds( Word16 F0, Word16 origF0, Word16 *thresholdModification ); -#ifdef HARMONIZE_FUNC static void RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word16 *thresholdModification ); static void findTonalComponents_fx( Word16 *indexOfTonalPeak, Word16 *lowerIndex, Word16 *upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 *powerSpectrum, const Word16 powerSpectrum_e, Word16 F0, Word16 *thresholdModification, Word16 element_mode ); -#else -static void RefineThresholdsUsingPitch( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word16 *thresholdModification ); -static void ivas_RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word16 *thresholdModification ); -static void findTonalComponents( Word16 *indexOfTonalPeak, Word16 *lowerIndex, Word16 *upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 *powerSpectrum, Word16 F0, Word16 *thresholdModification, Word16 element_mode ); -static void ivas_findTonalComponents_fx( Word16 *indexOfTonalPeak, Word16 *lowerIndex, Word16 *upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 *powerSpectrum, const Word16 powerSpectrum_e, Word16 F0, Word16 *thresholdModification, Word16 element_mode ); -#endif /*-------------------------------------------------------------------* @@ -51,11 +38,7 @@ static void ivas_findTonalComponents_fx( Word16 *indexOfTonalPeak, Word16 *lower * pNumIndexes accordingly. *-------------------------------------------------------------------*/ -#ifdef HARMONIZE_FUNC void DetectTonalComponents_fx( -#else -void ivas_DetectTonalComponents_fx( -#endif Word16 indexOfTonalPeak[], /*Q0*/ Word16 lowerIndex[], /*Q0*/ Word16 upperIndex[], /*Q0*/ @@ -73,11 +56,7 @@ void ivas_DetectTonalComponents_fx( const Word16 nSamplesCore, Word16 floorPowerSpectrum, /* i : lower limit for power spectrum bins Q0*/ const PsychoacousticParameters *psychParamsCurrent, -#ifdef HARMONIZE_FUNC const Word16 element_mode /* i : element mode */ -#else - Word16 element_mode /* i : element mode */ -#endif ) { Word16 F0; @@ -89,7 +68,6 @@ void ivas_DetectTonalComponents_fx( set32_fx( pScaledMdctSpectrum, 0, L_FRAME_MAX ); -#ifdef HARMONIZE_FUNC IF( element_mode == EVS_MONO ) { mdct_shaping_16( lastMDCTSpectrum, nSamplesCore, nSamples, scaleFactors, scaleFactors_exp, scaleFactors_max_e, pScaledMdctSpectrum ); @@ -98,20 +76,12 @@ void ivas_DetectTonalComponents_fx( } ELSE { -#endif FOR( Word16 i = 0; i < nSamples; i++ ) { pScaledMdctSpectrum[i] = L_shl( lastMDCTSpectrum[i], 16 ); /*15-lastMDCTSpectrum_exp+16 -> 31 - lastMDCTSpectrum_exp*/ move32(); } -#ifndef HARMONIZE_FUNC - FOR( Word16 i = 0; i < FDNS_NPTS; i++ ) - { - sns_int_scf_fx[i] = L_shl_sat( scaleFactors[i], add( 1, scaleFactors_exp[i] ) ); // Q16 - move32(); - } -#endif IF( psychParamsCurrent == NULL ) { nBands = FDNS_NPTS; @@ -122,13 +92,11 @@ void ivas_DetectTonalComponents_fx( } ELSE { -#ifdef HARMONIZE_FUNC FOR( Word16 i = 0; i < FDNS_NPTS; i++ ) { sns_int_scf_fx[i] = L_shl_sat( scaleFactors[i], add( 1, scaleFactors_exp[i] ) ); // Q16 move32(); } -#endif q_pScaledMdctSpectrum = sub( 31, lastMDCTSpectrum_exp ); sns_shape_spectrum_fx( pScaledMdctSpectrum, &q_pScaledMdctSpectrum, psychParamsCurrent, sns_int_scf_fx, 16, nSamplesCore, NULL ); @@ -151,69 +119,20 @@ void ivas_DetectTonalComponents_fx( /* Guard bit */ lastMDCTSpect_exp = add( lastMDCTSpect_exp, 1 ); scale_sig32( pScaledMdctSpectrum, nSamples, -1 ); /*q_pScaledMdctSpectrum - 1*/ -#ifdef HARMONIZE_FUNC } -#endif /* Find peak candidates in the last frame. */ findCandidates( nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, floorPowerSpectrum ); /* Refine peak candidates using the pitch information */ -#ifdef HARMONIZE_FUNC RefineThresholdsUsingPitch_fx( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification ); -#else - ivas_RefineThresholdsUsingPitch_fx( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification ); -#endif /* Find peaks in the second last frame */ -#ifdef HARMONIZE_FUNC findTonalComponents_fx( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, secondLastPowerSpectrum_e, F0, thresholdModification, element_mode ); -#else - ivas_findTonalComponents_fx( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, secondLastPowerSpectrum_e, F0, thresholdModification, element_mode ); -#endif return; } -#ifndef HARMONIZE_FUNC -void DetectTonalComponents( - Word16 indexOfTonalPeak[], /*Q0*/ - Word16 lowerIndex[], /*Q0*/ - Word16 upperIndex[], /*Q0*/ - Word16 *pNumIndexes, /*Q0*/ - const Word32 lastPitchLag, /*Qx*/ - const Word32 currentPitchLag, /*Qx*/ - const Word16 lastMDCTSpectrum[], - const Word16 lastMDCTSpectrum_exp, - const Word16 scaleFactors[], - const Word16 scaleFactors_exp[], - const Word16 scaleFactors_max_e, - const Word32 secondLastPowerSpectrum[], /*Qx*/ - const Word16 nSamples, - const Word16 nSamplesCore, - Word16 floorPowerSpectrum, /* i : lower limit for power spectrum bins Q0*/ - Word16 element_mode ) -{ - Word16 F0; - Word16 thresholdModification[L_FRAME_MAX], lastMDCTSpect_exp; - Word32 pScaledMdctSpectrum[L_FRAME_MAX]; - - mdct_shaping_16( lastMDCTSpectrum, nSamplesCore, nSamples, scaleFactors, scaleFactors_exp, scaleFactors_max_e, pScaledMdctSpectrum ); - - lastMDCTSpect_exp = add( lastMDCTSpectrum_exp, scaleFactors_max_e ); - - /* Find peak candidates in the last frame. */ - findCandidates( nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, floorPowerSpectrum ); - - /* Refine peak candidates using the pitch information */ - RefineThresholdsUsingPitch( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification ); - - /* Find peaks in the second last frame */ - findTonalComponents( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, F0, thresholdModification, element_mode ); - - return; -} -#endif /*-------------------------------------------------------------------* * RefineTonalComponents() @@ -225,99 +144,8 @@ void DetectTonalComponents( * then keep in indexOfTonalPeak only the tonal components that are * again detected Updates indexOfTonalPeak, lowerIndex, upperIndex, * phaseDiff, phases, pNumIndexes accordingly. */ -#ifndef HARMONIZE_FUNC -void RefineTonalComponents( - Word16 indexOfTonalPeak[], /*Q0*/ - Word16 lowerIndex[], /*Q0*/ - Word16 upperIndex[], /*Q0*/ - Word16 phaseDiff[], /*Q12*/ - Word16 phases[], /*Q13*/ - Word16 *pNumIndexes, /*Q0*/ - const Word32 lastPitchLag, /*Qx*/ - const Word32 currentPitchLag, /*Qx*/ - const Word16 lastMDCTSpectrum[], - const Word16 lastMDCTSpectrum_exp, - const Word16 scaleFactors[], - const Word16 scaleFactors_exp[], - const Word16 scaleFactors_max_e, - const Word32 secondLastPowerSpectrum[], /*Qx*/ - const Word16 nSamples, - const Word16 nSamplesCore, - const Word16 floorPowerSpectrum, /* i : lower limit for power spectrum bins Q0*/ - Word16 element_mode ) -{ - Word16 newIndexOfTonalPeak[MAX_NUMBER_OF_IDX]; /*Q0*/ - Word16 newLowerIndex[MAX_NUMBER_OF_IDX]; /*Q0*/ - Word16 newUpperIndex[MAX_NUMBER_OF_IDX]; /*Q0*/ - Word16 newNumIndexes, nPreservedPeaks; - Word16 iNew, iOld, j; - Word16 *pOldPhase, *pNewPhase; - DetectTonalComponents( newIndexOfTonalPeak, newLowerIndex, newUpperIndex, &newNumIndexes, lastPitchLag, currentPitchLag, lastMDCTSpectrum, - lastMDCTSpectrum_exp, scaleFactors, scaleFactors_exp, scaleFactors_max_e, secondLastPowerSpectrum, nSamples, nSamplesCore, floorPowerSpectrum, element_mode ); - - nPreservedPeaks = 0; - move16(); - iNew = 0; - move16(); - pOldPhase = phases; /*Q13*/ - pNewPhase = phases; /*Q13*/ - - FOR( iOld = 0; iOld < *pNumIndexes; iOld++ ) - { - /* We don't want that the old peak index is at the border of the new peak region, that is why >= newUpperIndex and > newLowerIndex */ - test(); - WHILE( LT_16( iNew, newNumIndexes ) && GE_16( indexOfTonalPeak[iOld], newUpperIndex[iNew] ) ) - { - iNew = add( iNew, 1 ); - } - - test(); - IF( LT_16( iNew, newNumIndexes ) && GT_16( indexOfTonalPeak[iOld], newLowerIndex[iNew] ) ) - { - newIndexOfTonalPeak[nPreservedPeaks] = indexOfTonalPeak[iOld]; /*Q0*/ - move16(); - newLowerIndex[nPreservedPeaks] = lowerIndex[iOld]; /*Q0*/ - move16(); - newUpperIndex[nPreservedPeaks] = upperIndex[iOld]; /*Q0*/ - move16(); - phaseDiff[nPreservedPeaks] = phaseDiff[iOld]; /*Q12*/ - move16(); - - FOR( j = lowerIndex[iOld]; j <= upperIndex[iOld]; j++ ) - { - *pNewPhase++ = *pOldPhase++; /*Q13*/ - move16(); - } - nPreservedPeaks = add( nPreservedPeaks, 1 ); - } - ELSE - { - pOldPhase += sub( upperIndex[iOld], add( lowerIndex[iOld], 1 ) ); /*Q13*/ - } - } - - FOR( iNew = 0; iNew < nPreservedPeaks; iNew++ ) - { - indexOfTonalPeak[iNew] = newIndexOfTonalPeak[iNew]; /*Q0*/ - move16(); - lowerIndex[iNew] = newLowerIndex[iNew]; /*Q0*/ - move16(); - upperIndex[iNew] = newUpperIndex[iNew]; /*Q0*/ - move16(); - } - *pNumIndexes = nPreservedPeaks; /*Q0*/ - move16(); - - return; -} -#endif - -#ifdef HARMONIZE_FUNC void RefineTonalComponents_fx( -#else -void ivas_RefineTonalComponents_fx( -#endif Word16 indexOfTonalPeak[], /*Q0*/ Word16 lowerIndex[], /*Q0*/ Word16 upperIndex[], /*Q0*/ @@ -346,15 +174,9 @@ void ivas_RefineTonalComponents_fx( Word16 iNew, iOld, j; Word16 *pOldPhase, *pNewPhase; -#ifdef HARMONIZE_FUNC DetectTonalComponents_fx( newIndexOfTonalPeak, newLowerIndex, newUpperIndex, &newNumIndexes, lastPitchLag, currentPitchLag, lastMDCTSpectrum, lastMDCTSpectrum_exp, scaleFactors, scaleFactors_exp, scaleFactors_max_e, secondLastPowerSpectrum, secondLastPowerSpectrum_e, nSamples, nSamplesCore, floorPowerSpectrum, psychParamsCurrent, element_mode ); -#else - ivas_DetectTonalComponents_fx( newIndexOfTonalPeak, newLowerIndex, newUpperIndex, &newNumIndexes, lastPitchLag, currentPitchLag, lastMDCTSpectrum, - lastMDCTSpectrum_exp, scaleFactors, scaleFactors_exp, scaleFactors_max_e, secondLastPowerSpectrum, secondLastPowerSpectrum_e, nSamples, nSamplesCore, floorPowerSpectrum, - psychParamsCurrent, element_mode ); -#endif nPreservedPeaks = 0; move16(); @@ -625,66 +447,6 @@ static void GetF0( return; } -#ifndef HARMONIZE_FUNC -static void ivas_GetF0_fx( - Word16 /*short*/ const nSamples, /*i - Q0 */ - Word16 /*short*/ const nSamplesCore, /*i - Q0 */ - Word32 /*int*/ const *const powerSpectrum, - /*i - Qx */ /*is justed handed over and given back*/ - Word32 /*int*/ const pitchLag, /*i - Q16*/ - Word16 /*short*/ *const pOrigF0, /*o - Q10*/ - Word16 /*short*/ *const pF0 ) /*o - Q10*/ -{ - Word16 /*short*/ tmpPitchLag; - Word16 /*short*/ rgiStrongHarmonics[MAX_PEAKS_FROM_PITCH]; /*Q0*/ - Word16 /*short*/ nTotalHarmonics, nStrongHarmonics; - Word16 tmp; - - assert( LAST_HARMONIC_POS_TO_CHECK <= nSamplesCore ); - - /* Use only F0 >= 100 Hz */ - test(); - IF( ( pitchLag > 0 ) && ( LE_16( round_fx( pitchLag ), shr( nSamplesCore, 1 ) ) ) ) - { - - tmpPitchLag /*"halfPitchLag" in FLC - read as Q5 for comparison to halfpitchlag Q4*/ - = round_fx( L_shl( pitchLag, 4 ) ); /*no division by 2, will be done in following division - - furthermore, do a leftshift before rounding, to preserve more accuracy - - will be accommodated also in following division*/ - - /**pF0 = nSamplesCore/tmpPitchLag;*/ - BASOP_Util_Divide_MantExp( nSamplesCore, 0, tmpPitchLag, -( 1 /*division by 2*/ + 4 /*accommodate accuracy-prevention-leftshift*/ ), pF0, &tmp ); /*pF0 is Q15*/ - move16(); - *pF0 = shr_sat( *pF0, sub( 5, tmp ) ); /*Q10 without scalingfactor*/ - move16(); - *pOrigF0 = *pF0; /*Q10*/ - move16(); - tmp = 2 * LAST_HARMONIC_POS_TO_CHECK; - if ( LT_16( nSamples, 2 * LAST_HARMONIC_POS_TO_CHECK ) ) - { - move16(); - tmp = nSamples; - } - BASOP_Util_Divide_MantExp( tmp, 15, *pF0, 5, &nTotalHarmonics, &tmp ); - nTotalHarmonics = shl( nTotalHarmonics, sub( tmp, 15 ) ); - - - /* Get in rgiStrongHarmonics all i for which i*F0 are the strongest harmonics */ - findStrongestHarmonics( nSamples, powerSpectrum, *pF0, nTotalHarmonics, rgiStrongHarmonics, &nStrongHarmonics ); - - ivas_CorrectF0_fx( rgiStrongHarmonics, nStrongHarmonics, pF0 ); - } - ELSE - { - move16(); - move16(); - *pF0 = 0; - *pOrigF0 = 0; - } - - return; -} -#endif static void findStrongestHarmonics( const Word16 nSamples, @@ -773,154 +535,6 @@ static void findStrongestHarmonics( /* Use new F0, for which harmonics are most common in pHarmonicIndexes */ static void CorrectF0( -#ifndef HARMONIZE_FUNC - const Word16 /*short*/ *pHarmonicIndexes, /*I - Q0 */ - const Word16 /*short*/ nHarmonics, /*I - Q0 */ - Word16 /*short*/ *pF0 ) /*I/O - Q10 range: {0}, [4..18) */ -{ - Word16 /*short*/ i; - Word16 /*short*/ F0; - Word16 /*short*/ diff[MAX_PEAKS_FROM_PITCH - 1], sortedDiff[MAX_PEAKS_FROM_PITCH - 1]; /*Q0*/ - Word16 /*short*/ iMostCommonDiff, nMostCommonDiff, nSameDiff, iMult; /*Q0*/ - - Word16 tmp; - - F0 = *pF0; /*Q10*/ - - test(); - IF( F0 > 0 && nHarmonics != 0 ) - { - tmp = sub( nHarmonics, 1 ); - FOR( i = 0; i < tmp; i++ ) - { - diff[i] = sub( pHarmonicIndexes[i + 1], pHarmonicIndexes[i] ); /*Q0*/ - move16(); - sortedDiff[i] = diff[i]; /*Q0*/ - move16(); - } - sort_fx( sortedDiff, 0, sub( nHarmonics, 1 + 1 ) ); - iMostCommonDiff = sortedDiff[0]; /*Q0*/ - move16(); - nSameDiff = 1; - move16(); - i = 1; - move16(); - IF( EQ_16( imult1616( sortedDiff[0], pHarmonicIndexes[0] ), 1 ) ) - { - /* Find how many distances between peaks have length 1 */ - FOR( ; i < tmp; i++ ) - { - if ( EQ_16( sortedDiff[i], 1 ) ) - { - nSameDiff = add( nSameDiff, 1 ); - } - } - } - nMostCommonDiff = nSameDiff; /*Q0*/ - move16(); - - /* If there are at least 3 distances between peaks with length 1 and if the 1st harmonic is in pHarmonicIndexes then keep the original F0 */ - /* Otherwise find the most common distance between peaks */ - IF( LT_16( nSameDiff, 3 ) ) - { - /* Find the most common difference */ - FOR( i = nSameDiff; i < tmp; i++ ) - { - IF( EQ_16( sortedDiff[i], sortedDiff[i - 1] ) ) - { - nSameDiff = add( nSameDiff, 1 ); - } - ELSE - { - IF( GT_16( nSameDiff, nMostCommonDiff ) ) - { - nMostCommonDiff = nSameDiff; /*Q0*/ - move16(); - iMostCommonDiff = sortedDiff[i - 1]; /*Q0*/ - move16(); - } - ELSE - { - test(); - IF( EQ_16( nSameDiff, nMostCommonDiff ) && GT_16( abs_s( sub( iMostCommonDiff, pHarmonicIndexes[0] ) ), abs_s( sub( sortedDiff[i - 1], pHarmonicIndexes[0] ) ) ) ) - { - nMostCommonDiff = nSameDiff; /*Q0*/ - move16(); - iMostCommonDiff = sortedDiff[i - 1]; /*Q0*/ - move16(); - } - } - nSameDiff = 1; - move16(); - } - } - IF( GT_16( nSameDiff, nMostCommonDiff ) ) - { - nMostCommonDiff = nSameDiff; /*Q0*/ - move16(); - iMostCommonDiff = sortedDiff[nHarmonics - 2]; /*Q0*/ - move16(); - } - } - - /* If there are enough peaks at the same distance */ - IF( GE_16( nMostCommonDiff, MAX_PEAKS_FROM_PITCH / 2 ) ) - { - iMult = 1; - move16(); - FOR( i = 0; i < tmp; i++ ) - { - IF( EQ_16( diff[i], iMostCommonDiff ) ) - { - iMult = pHarmonicIndexes[i]; /*Q0*/ - move16(); - BREAK; - } - /* for rare cases of octave mismatch or missing harmonics */ - test(); - test(); - IF( GT_16( sub( nHarmonics, 2 ), i ) && ( EQ_16( diff[i], diff[i + 1] ) ) && ( EQ_16( add( diff[i], diff[i + 1] ), iMostCommonDiff ) ) ) - { - iMult = pHarmonicIndexes[i]; /*Q0*/ - move16(); - BREAK; - } - } - - /* If the real F0 is much higher than the original F0 from the pitch */ - - IF( LE_16( iMult, 3 ) ) - { - /* Use iMostCommonDiff, because the lowest pHarmonicIndexes[i] (which is equal to iMult) may not correspond to the new F0, but to it's multiple */ - F0 = round_fx_sat( L_shl_sat( L_mult( iMostCommonDiff /*Q0*/, F0 /*Q10*/ ), 15 ) ); /*Q10*/ - } - ELSE - { - F0 = 0; - move16(); - } - } - /* Otherwise if there are at least 3 distances between peaks with length 1 and if the 1st harmonic is in pHarmonicIndexes then keep the original F0 */ - /* Otherwise don't use F0 */ - ELSE - { - test(); - if ( ( GT_16( iMostCommonDiff, 1 ) ) || ( LT_16( nMostCommonDiff, 3 ) ) ) - { - /* Not enough peaks at the same distance => don't use the pitch. */ - F0 = 0; - move16(); - } - } - *pF0 = F0; - move16(); - } - - return; -} - -static void ivas_CorrectF0_fx( -#endif const Word16 /*short*/ *pHarmonicIndexes, /*I - Q0 */ const Word16 /*short*/ nHarmonics, /*I - Q0 */ Word16 /*short*/ *pF0 ) /*I/O - Q10 range: {0}, [4..18) */ @@ -1277,54 +891,8 @@ static void findCandidates( return; } -#ifndef HARMONIZE_FUNC -static void RefineThresholdsUsingPitch( - const Word16 nSamples, - const Word16 nSamplesCore, - const Word32 powerSpectrum[], /*Qx*/ - const Word32 lastPitchLag, /*Qx*/ - const Word32 currentPitchLag, /*Qx*/ - Word16 *pF0, /*Q10*/ - Word16 *thresholdModification /*Q10*/ -) -{ - Word16 pitchIsStable; - Word16 origF0; - Word32 L_tmp; - - /*pitchIsStable = (fabs(lastPitchLag-currentPitchLag) < 0.25f);*/ - pitchIsStable = 0; - move16(); - L_tmp = L_abs( L_sub( lastPitchLag, currentPitchLag ) ); - if ( LT_32( L_tmp, 16384l /*0.25f Q16*/ ) ) - { - pitchIsStable = 1; - move16(); - } - - IF( pitchIsStable ) - { - GetF0( nSamples, - nSamplesCore, - powerSpectrum, lastPitchLag, &origF0, pF0 ); - - modifyThresholds( *pF0, origF0, thresholdModification ); - } - ELSE - { - *pF0 = 0; - move16(); - } - - return; -} -#endif -#ifdef HARMONIZE_FUNC static void findTonalComponents_fx( -#else -static void ivas_findTonalComponents_fx( -#endif Word16 *indexOfTonalPeak, /* OUT Q0*/ Word16 *lowerIndex, /* OUT Q0*/ Word16 *upperIndex, /* OUT Q0*/ @@ -1357,7 +925,6 @@ static void ivas_findTonalComponents_fx( tmp_loop2 = sub( nSamples, 1 ); WHILE( LE_16( k, tmp_loop1 ) ) { -#ifdef HARMONIZE_FUNC Word16 flag = 0; IF( element_mode == EVS_MONO && GT_32( L_shr( smoothedSpectrum[k], 1 ), L_shl( Mpy_32_16_1( envelope[k] /*Q28,powerSpec_exp*/, thresholdModification[k] /*Q10*/ ), 4 ) ) ) { @@ -1366,17 +933,12 @@ static void ivas_findTonalComponents_fx( } ELSE { -#endif Word64 mult_64 = W_mult_32_16( envelope[k], thresholdModification[k] ); // (Q31-(powerSpectrum_e+LEVEL_EXP))+1+10 Word16 lshift = W_norm( mult_64 ); Word32 mult_32 = W_extract_h( W_shl( mult_64, lshift ) ); //(Q31-(powerSpectrum_e+LEVEL_EXP) + lshift )+11 -32 Word16 mult_exp = sub( Q31, sub( add( sub( Q31, add( powerSpectrum_e, LEVEL_EXP ) ), add( 10, lshift ) ), 31 ) ); -#ifdef HARMONIZE_FUNC flag = BASOP_Util_Cmp_Mant32Exp( smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), mult_32, mult_exp ); } -#else - Word16 flag = BASOP_Util_Cmp_Mant32Exp( smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), mult_32, mult_exp ); -#endif /* There is 3 bits headroom in envelope and max of thresholdModification is 16384, so shifting left for 4 would produce overflow only when the result is anyhow close to 1 */ IF( EQ_16( flag, 1 ) ) @@ -1504,11 +1066,7 @@ static void ivas_findTonalComponents_fx( return; } -#ifdef HARMONIZE_FUNC static void RefineThresholdsUsingPitch_fx( -#else -static void ivas_RefineThresholdsUsingPitch_fx( -#endif const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], /*Qx*/ @@ -1534,13 +1092,7 @@ static void ivas_RefineThresholdsUsingPitch_fx( IF( pitchIsStable ) { -#ifdef HARMONIZE_FUNC GetF0( nSamples, nSamplesCore, powerSpectrum, lastPitchLag, &origF0, pF0 ); -#else - ivas_GetF0_fx( nSamples, - nSamplesCore, - powerSpectrum, lastPitchLag, &origF0, pF0 ); -#endif modifyThresholds( *pF0, origF0, thresholdModification ); } @@ -1552,163 +1104,3 @@ static void ivas_RefineThresholdsUsingPitch_fx( return; } -#ifndef HARMONIZE_FUNC - -static void findTonalComponents( - Word16 *indexOfTonalPeak, /* OUT Q0*/ - Word16 *lowerIndex, /* OUT Q0*/ - Word16 *upperIndex, /* OUT Q0*/ - Word16 *numIndexes, /* OUT Q0*/ - Word16 nSamples, /* IN */ - const Word32 *powerSpectrum, /* IN Qx*/ - Word16 F0, /* IN */ - Word16 *thresholdModification, /* IN Q10*/ - Word16 element_mode ) /* IN */ -{ - Word32 envelope[L_FRAME_MAX]; /*powerSpec_exp + LEVEL_EXP*/ - Word32 smoothedSpectrum[L_FRAME_MAX]; /*powerSpec_exp + LEVEL_EXP*/ - Word16 nrOfFIS; - Word16 upperIdx, lowerIdx, lowerBound; - Word16 k, j, m; - Word32 biggerNeighbor; - Word16 tmp_loop1, tmp_loop2, tmp_loop3; - - getEnvelope( nSamples, powerSpectrum, F0, envelope, smoothedSpectrum ); - - nrOfFIS = 0; - move16(); - lowerBound = 0; - move16(); - - k = GROUP_LENGTH / 2; - move16(); - tmp_loop1 = sub( nSamples, ( GROUP_LENGTH - GROUP_LENGTH / 2 ) ); - tmp_loop2 = sub( nSamples, 1 ); - WHILE( LE_16( k, tmp_loop1 ) ) - { - /* There is 3 bits headroom in envelope and max of thresholdModification is 16384, so shifting left for 4 would produce overflow only when the result is anyhow close to 1 */ - IF( GT_32( L_shr( smoothedSpectrum[k], 1 ), L_shl( Mpy_32_16_1( envelope[k] /*Q28,powerSpec_exp*/, thresholdModification[k] /*Q10*/ ), 4 ) ) ) - { - /* The check that bin at k is bigger than bins at k-1 and k+1 is needed to avoid deadlocks when the thresholds are low. */ - /* It removes some true peaks, especially if non weighted sum is used for the smoothed spectrum. */ - biggerNeighbor = L_max( powerSpectrum[k - 1], powerSpectrum[k + 1] ); /*Qx*/ - - IF( GE_32( powerSpectrum[k], biggerNeighbor ) ) - { - /* Find the right foot */ - upperIdx = add( k, 1 ); - WHILE( LT_16( upperIdx, tmp_loop2 ) ) - { - IF( LT_32( powerSpectrum[upperIdx], powerSpectrum[upperIdx + 1] ) ) - { - /* Side lobes may increase for certain amount */ - IF( LT_32( L_shl( Mpy_32_16_1( powerSpectrum[upperIdx], ALLOWED_SIDE_LOBE_FLUCTUATION ), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP ), powerSpectrum[upperIdx + 1] ) ) - { - BREAK; - } - /* Check for further decrease after a side lobe increase */ - FOR( j = add( upperIdx, 1 ); j < tmp_loop2; j++ ) - { - IF( LT_32( powerSpectrum[j], L_shl( Mpy_32_16_1( powerSpectrum[j + 1], ALLOWED_SIDE_LOBE_FLUCTUATION ), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP ) ) ) - { - BREAK; - } - } - /* Side lobe increase must be 2 times smaller than the decrease to the foot */ - /* Eq. to 2.0f*powerSpectrum[lowerIdx-1]/powerSpectrum[lowerIdx] > powerSpectrum[lowerIdx]/powerSpectrum[j] */ - test(); - test(); - test(); - IF( ( EQ_16( element_mode, EVS_MONO ) && GT_32( Mpy_32_32( L_shl( powerSpectrum[upperIdx + 1], 1 ), powerSpectrum[j] ), Mpy_32_32( powerSpectrum[upperIdx], powerSpectrum[upperIdx] ) ) ) || - ( NE_16( element_mode, EVS_MONO ) && ( GT_64( W_mult_32_32( L_shl( powerSpectrum[upperIdx + 1], 1 ), powerSpectrum[j] ), W_mult_32_32( powerSpectrum[upperIdx], powerSpectrum[upperIdx] ) ) ) ) ) - { - BREAK; - } - upperIdx = sub( j, 1 ); - } - upperIdx = add( upperIdx, 1 ); - } - /* left foot */ - lowerIdx = sub( k, 1 ); - WHILE( GT_16( lowerIdx, lowerBound ) ) - { - IF( LT_32( powerSpectrum[lowerIdx], powerSpectrum[lowerIdx - 1] ) ) - { - /* Side lobes may increase for certain amount */ - IF( LT_32( L_shl( Mpy_32_16_1( powerSpectrum[lowerIdx], ALLOWED_SIDE_LOBE_FLUCTUATION ), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP ), powerSpectrum[lowerIdx - 1] ) ) - { - BREAK; - } - /* Check for further decrease after a side lobe increase */ - FOR( j = sub( lowerIdx, 1 ); j > 0; j-- ) - { - IF( LT_32( powerSpectrum[j], L_shl( Mpy_32_16_1( powerSpectrum[j - 1], ALLOWED_SIDE_LOBE_FLUCTUATION ), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP ) ) ) - { - BREAK; - } - } - /* Side lobe increase must be 2 times smaller than the decrease to the foot */ - /* Eq. to 2.0f*powerSpectrum[lowerIdx-1]/powerSpectrum[lowerIdx] > powerSpectrum[lowerIdx]/powerSpectrum[j] */ - IF( GT_32( Mpy_32_32( L_shl( powerSpectrum[lowerIdx - 1], 1 ), powerSpectrum[j] ), Mpy_32_32( powerSpectrum[lowerIdx], powerSpectrum[lowerIdx] ) ) ) - { - BREAK; - } - lowerIdx = add( j, 1 ); - } - lowerIdx = sub( lowerIdx, 1 ); - } - - lowerBound = upperIdx; - move16(); - - /* Check if there is a bigger peak up to the next peak foot */ - tmp_loop3 = s_min( upperIdx, tmp_loop1 ); - FOR( j = s_max( GROUP_LENGTH / 2, lowerIdx ); j <= tmp_loop3; j++ ) - { - if ( GT_32( powerSpectrum[j], powerSpectrum[k] ) ) - { - - k = j; - move16(); - } - } - - assert( ( nrOfFIS == 0 ) || ( indexOfTonalPeak[nrOfFIS - 1] < k ) ); - - lowerIndex[nrOfFIS] = sub( k, GROUP_LENGTH / 2 ); - move16(); - - upperIndex[nrOfFIS] = add( k, ( GROUP_LENGTH - GROUP_LENGTH / 2 - 1 ) ); - move16(); - - test(); - IF( ( nrOfFIS > 0 ) && ( LE_16( lowerIndex[nrOfFIS], upperIndex[nrOfFIS - 1] ) ) ) - { - m = shr( add( k, indexOfTonalPeak[nrOfFIS - 1] ), 1 ); - upperIndex[nrOfFIS - 1] = m; - move16(); - lowerIndex[nrOfFIS] = add( m, 1 ); - move16(); - } - - indexOfTonalPeak[nrOfFIS++] = k; - move16(); - - IF( EQ_16( nrOfFIS, MAX_NUMBER_OF_IDX ) ) - { - BREAK; - } - /* Jump to the next foot of the peak. */ - k = upperIdx; - move16(); - } - } - k = add( k, 1 ); - } - - *numIndexes = nrOfFIS; - move16(); - - return; -} -#endif diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index b192eb852ae0d07c3e79752f8b7e66247344b99c..c4241b3a542f89298c0ed27a2b8f7acdf2941aa5 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -448,11 +448,8 @@ ivas_error acelp_core_dec_fx( dec = DEC_IVAS; move16(); } -#ifdef HARMONIZE_FUNC + synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, dec ); -#else - ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, dec ); -#endif Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/ Copy_Scale_sig( st->mem_syn2_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); /*Q-1*/ Copy( st->mem_syn2_fx, st->mem_syn3_fx, M ); /*Q_syn*/ @@ -1443,15 +1440,9 @@ ivas_error acelp_core_dec_fx( IF( NE_16( st->nelp_mode_dec, 1 ) ) { /* modify the excitation signal of stationary unvoiced frames */ -#ifdef HQ_ALIGN_DUPLICATED_CODE stat_noise_uv_mod_fx( st->element_mode, st->coder_type, 0, st->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, &st->Q_exc, 1, &st->ge_sm_fx, &st->uv_count, &st->act_count, st->lspold_s_fx, &st->noimix_seed, &st->min_alpha_fx, &st->exc_pe_fx, st->core_brate, st->bwidth, &st->Q_stat_noise, &st->Q_stat_noise_ge ); -#else - stat_noise_uv_mod_fx( st->coder_type, 0, st->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st->Q_exc, 1, &st->ge_sm_fx, - &st->uv_count, &st->act_count, st->lspold_s_fx, &st->noimix_seed, &st->min_alpha_fx, - &st->exc_pe_fx, st->core_brate, st->bwidth, &st->Q_stat_noise, &st->Q_stat_noise_ge ); -#endif } } @@ -1645,9 +1636,6 @@ ivas_error acelp_core_dec_fx( IF( NE_16( st->element_mode, last_element_mode ) ) { set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); -#ifndef FIX_BASOP_REMOVE_SYNTH2_FX - set32_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, 0, st->hFdCngDec->hFdCngCom->fftlen ); -#endif } Word32 psyn_32_fx[L_FRAME16k]; @@ -1655,9 +1643,6 @@ ivas_error acelp_core_dec_fx( generate_masking_noise_ivas_fx( psyn_32_fx, &exp, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); Copy_Scale_sig_32_16( psyn_32_fx, psyn_fx, st->hFdCngDec->hFdCngCom->frameSize, sub( st->Q_syn, exp ) ); // Q = st->Q_syn -#ifndef FIX_BASOP_REMOVE_SYNTH2_FX - Copy_Scale_sig_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), -Q15 ); // Q0 -#endif } } } @@ -1745,9 +1730,6 @@ ivas_error acelp_core_dec_fx( IF( st->idchan == 0 ) { set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); -#ifndef FIX_BASOP_REMOVE_SYNTH2_FX - set32_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, 0, st->hFdCngDec->hFdCngCom->fftlen ); -#endif } IF( hStereoCng != NULL && ( st->idchan == 0 ) ) { diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index 26b5d26d378fe82efd0597ee25a42e377f67a80c..1fdfe44a4d749b9fcab176963c3860d83364668f 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -173,11 +173,7 @@ ivas_error amr_wb_dec_fx( } /* Updates in case of EVS -> AMR-WB IO switching */ -#if defined( FIX_BASOP_REMOVE_SYNTH2_FX ) IF( NE_32( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1 ) ), IVAS_ERR_OK ) ) -#else - IF( NE_32( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1, &tmp16 ) ), IVAS_ERR_OK ) ) -#endif { return error; } @@ -272,11 +268,7 @@ ivas_error amr_wb_dec_fx( set16_fx( st_fx->mem_MA_fx, 0, M ); /* update synthesis filter memories */ -#ifdef HARMONIZE_FUNC synth_mem_updt2_fx( L_FRAME, st_fx->last_L_frame, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, DEC ); -#else - synth_mem_updt2( L_FRAME, st_fx->last_L_frame, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, DEC ); -#endif Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/ Copy_Scale_sig( st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub( -1, st_fx->Q_syn ) ); /*Q-1*/ Copy( st_fx->mem_syn2_fx, st_fx->mem_syn3_fx, M ); /*Q_syn*/ diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index c2236a845ccabc018d9b768e6561d59592cbe0ca..dd3115fb709f0b1bcbdffa12ccfacdde208e166c 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -529,11 +529,7 @@ void open_decoder_LPD_fx( IF( !st->last_con_tcx ) { -#ifdef HARMONIZE_FUNC synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); -#else - synth_mem_updt2( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); -#endif } /*mem of deemphasis stayed unchanged.*/ @@ -1569,11 +1565,7 @@ void open_decoder_LPD_ivas_fx( move16(); IF( !st->last_con_tcx ) { -#ifdef HARMONIZE_FUNC synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); -#else - ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); -#endif } /*mem of deemphasis stayed unchanged.*/ diff --git a/lib_dec/core_dec_switch_fx.c b/lib_dec/core_dec_switch_fx.c index b273d78ec43b69756399cb68ec09b6d82eab03dd..142609fff4505ab659dc70912ef87ecd305fabeb 100644 --- a/lib_dec/core_dec_switch_fx.c +++ b/lib_dec/core_dec_switch_fx.c @@ -313,17 +313,13 @@ void mode_switch_decoder_LPD_ivas_fx( IF( st->igf && ( ( st->idchan == 0 ) || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) ) { /* switch IGF configuration */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFDecSetMode( st->hIGFDec, total_brate, bwidth, st->element_mode, -1, -1, st->rf_flag ); -#else - IGFDecSetMode_ivas_fx( st->hIGFDec, total_brate, bwidth, st->element_mode, -1, -1, st->rf_flag ); -#endif } + test(); test(); test(); test(); - assert( (Word16) ( st->sr_core / FRAMES_PER_SEC ) == extract_l( Mult_32_16( st->sr_core, INV_FRAME_PER_SEC_Q15 ) ) ); IF( NE_16( fscale, st->fscale ) || switchWB || bSwitchFromAmrwbIO || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) { diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index 7dcb25dcb2f94ce1e289c10242fd5bef338a50aa..b4f34830d36dbdb6787ee69da6e1c63fa64f74cd 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -1157,12 +1157,7 @@ ivas_error core_switching_pre_dec_fx( const Word16 nchan_out, /* i : number of output channels */ const Word16 last_element_mode, /* i : last_element_mode */ const Word32 last_element_brate, /* i : last element bitrate */ -#if defined( FIX_BASOP_REMOVE_SYNTH2_FX ) const Word16 Q_old_synthFB ) -#else - const Word16 Q_old_synthFB, - Word16 *Q_olapBufferSynth2 ) -#endif { Word32 tmp_fx; /*Q-12*/ Word16 i, oldLenClasBuff, newLenClasBuff; @@ -1664,11 +1659,7 @@ ivas_error core_switching_pre_dec_fx( ELSE IF( LT_16( st->L_frame, L_FRAME16k ) ) { /* resample from 16kHz to 12.8kHZ */ -#ifdef HARMONIZE_FUNC synth_mem_updt2_fx( st->L_frame, L_FRAME16k, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); -#else - synth_mem_updt2( st->L_frame, L_FRAME16k, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); -#endif } IF( hBWE_TD != NULL ) @@ -1954,11 +1945,8 @@ ivas_error core_switching_pre_dec_fx( } ELSE { -#ifdef FIX_BASOP_REMOVE_SYNTH2_FX lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ) ); -#else - L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ), Q_olapBufferSynth2 ); -#endif + test(); IF( LE_32( st->total_brate, SID_2k40 ) && LE_32( st->last_total_brate, SID_2k40 ) ) { diff --git a/lib_dec/dec_LPD_fx.c b/lib_dec/dec_LPD_fx.c index 55505d52e1de11ea103d15fa2abdaff977298852..5b1a13023474d2137853e702cef1b38354a3027f 100644 --- a/lib_dec/dec_LPD_fx.c +++ b/lib_dec/dec_LPD_fx.c @@ -570,11 +570,7 @@ void decoder_LPD_fx( IF( bfi != 0 && ( st->last_core != ACELP_CORE ) ) { /* PLC: [TCX: TD PLC] */ -#ifndef HARMONIZE_2446_CON_TCX_FX - con_tcx_fx( st, &synthFB[0] ); -#else con_tcx_fx( st, &synthFB[0], -16384, NULL, 0, NULL ); -#endif lerp( synthFB, synth, st->L_frame, hTcxDec->L_frameTCX ); st->con_tcx = 1; move16(); diff --git a/lib_dec/dec_ace_fx.c b/lib_dec/dec_ace_fx.c index c78697921b1dde8e4723081d30d0b1ed7f32cffd..515251e7f4a90320f99b445b525afa91016f8e75 100644 --- a/lib_dec/dec_ace_fx.c +++ b/lib_dec/dec_ace_fx.c @@ -174,11 +174,7 @@ void decoder_acelp_fx( test(); IF( st->prev_bfi && st->last_con_tcx && LT_16( st->L_frame, L_FRAME16k ) ) { -#ifdef HARMONIZE_FUNC synth_mem_updt2_fx( st->L_frame, L_FRAME16k, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); -#else - synth_mem_updt2( st->L_frame, L_FRAME16k, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); -#endif } test(); diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 0a0810349bedbcb97a708207765e21cdee2889ff..65ad45e3230401be45af293a06986135108bb0de 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -219,11 +219,7 @@ void decoder_tcx_fx( test(); IF( ( EQ_16( L_frame, shr( st->L_frame, 1 ) ) ) && ( st->tcxonly ) ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFDecUpdateInfo( st->hIGFDec, frame_cnt, IGF_GRID_LB_SHORT, st->element_mode ); -#else - IGFDecUpdateInfo( st->hIGFDec, IGF_GRID_LB_SHORT ); -#endif } ELSE { @@ -231,19 +227,11 @@ void decoder_tcx_fx( test(); IF( ( EQ_16( st->last_core, ACELP_CORE ) ) || ( left_rect && st->bfi ) ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFDecUpdateInfo( st->hIGFDec, frame_cnt, IGF_GRID_LB_TRAN, st->element_mode ); -#else - IGFDecUpdateInfo( st->hIGFDec, IGF_GRID_LB_TRAN ); -#endif } ELSE { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFDecUpdateInfo( st->hIGFDec, frame_cnt, IGF_GRID_LB_NORM, st->element_mode ); -#else - IGFDecUpdateInfo( st->hIGFDec, IGF_GRID_LB_NORM ); -#endif } } @@ -1040,11 +1028,8 @@ void decoder_tcx_fx( *st->hIGFDec->igfData.igfInfo.nfSeed = extract_l( L_mac0( 13849L, nf_seed, 31821 ) ); move16(); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFDecApplyMono( st->hIGFDec, x, &x_e, igfGridIdx, bfi, st->element_mode ); -#else - IGFDecApplyMono( st->hIGFDec, x, &x_e, igfGridIdx, bfi ); -#endif } test(); test(); @@ -1052,11 +1037,8 @@ void decoder_tcx_fx( { *st->hIGFDec->igfData.igfInfo.nfSeed = extract_l( L_mac0( 13849L, nf_seed, 31821 ) ); move16(); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFDecApplyMono( st->hIGFDec, x, &x_e, IGF_GRID_LB_SHORT, bfi, st->element_mode ); -#else - IGFDecApplyMono( st->hIGFDec, x, &x_e, IGF_GRID_LB_SHORT, bfi ); -#endif } index = hTcxCfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */ @@ -3755,11 +3737,7 @@ void init_tcx_info_fx( test(); IF( EQ_16( *L_frame, shr( st->L_frame, 1 ) ) && ( st->tcxonly ) ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFDecUpdateInfo( st->hIGFDec, frame_cnt, IGF_GRID_LB_SHORT, st->element_mode ); -#else - IGFDecUpdateInfo_ivas_fx( st->hIGFDec, frame_cnt, IGF_GRID_LB_SHORT ); -#endif } ELSE { @@ -3767,19 +3745,11 @@ void init_tcx_info_fx( test(); IF( st->last_core == ACELP_CORE || ( *left_rect && st->bfi ) ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFDecUpdateInfo( st->hIGFDec, frame_cnt, IGF_GRID_LB_TRAN, st->element_mode ); -#else - IGFDecUpdateInfo_ivas_fx( st->hIGFDec, frame_cnt, IGF_GRID_LB_TRAN ); -#endif } ELSE { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFDecUpdateInfo( st->hIGFDec, frame_cnt, IGF_GRID_LB_NORM, st->element_mode ); -#else - IGFDecUpdateInfo_ivas_fx( st->hIGFDec, frame_cnt, IGF_GRID_LB_NORM ); -#endif } } } @@ -3826,11 +3796,7 @@ void decoder_tcx_IGF_mono_fx( } } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFDecUpdateInfo( st->hIGFDec, frame_cnt, igfGridIdx, st->element_mode ); -#else - IGFDecUpdateInfo_ivas_fx( st->hIGFDec, frame_cnt, igfGridIdx ); -#endif IF( st->igf ) { @@ -3855,11 +3821,7 @@ void decoder_tcx_IGF_mono_fx( } } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFDecApplyMono( st->hIGFDec, x_fx, x_e, igfGridIdx, bfi, st->element_mode ); -#else - IGFDecApplyMono_ivas( st->hIGFDec, x_fx, x_e, igfGridIdx, bfi, st->element_mode ); -#endif *x_len = st->hIGFDec->igfData.igfInfo.grid[igfGridIdx].stopLine; move16(); @@ -3940,11 +3902,8 @@ void decoder_tcx_IGF_stereo_fx( move16(); } } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFDecUpdateInfo( sts[0]->hIGFDec, k, igfGridIdx, sts[0]->element_mode ); -#else - IGFDecUpdateInfo_ivas_fx( sts[0]->hIGFDec, k, igfGridIdx ); -#endif test(); IF( EQ_16( L_frame, shr( sts[1]->L_frame, 1 ) ) && ( sts[1]->tcxonly ) ) @@ -3966,12 +3925,8 @@ void decoder_tcx_IGF_stereo_fx( move16(); } } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - IGFDecUpdateInfo( sts[1]->hIGFDec, k, igfGridIdx, sts[1]->element_mode ); -#else - IGFDecUpdateInfo_ivas_fx( sts[1]->hIGFDec, k, igfGridIdx ); -#endif + IGFDecUpdateInfo( sts[1]->hIGFDec, k, igfGridIdx, sts[1]->element_mode ); IF( sts[0]->igf ) { @@ -5095,17 +5050,9 @@ void decoder_tcx_noisefilling_fx( { IGFDecCopyLPCFlatSpectrum_fx( st->hIGFDec, x, *x_e, IGF_GRID_LB_SHORT ); /* also replace flat spectrum for the second TCX10 sub frame */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFDecUpdateInfo( st->hIGFDec, 1, IGF_GRID_LB_SHORT, st->element_mode ); -#else - IGFDecUpdateInfo_ivas_fx( st->hIGFDec, 1, IGF_GRID_LB_SHORT ); -#endif IGFDecCopyLPCFlatSpectrum_fx( st->hIGFDec, x, *x_e, IGF_GRID_LB_SHORT ); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFDecUpdateInfo( st->hIGFDec, 0, IGF_GRID_LB_SHORT, st->element_mode ); -#else - IGFDecUpdateInfo_ivas_fx( st->hIGFDec, 0, IGF_GRID_LB_SHORT ); -#endif Copy( st->hIGFDec->igfData.igf_curr_subframe[0][0], st->hIGFDec->igfData.igf_curr_subframe[1][0], IGF_MAX_SFB ); } ELSE IF( bfi && st->igf && ( frame_cnt == 0 ) && ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) ) @@ -5328,11 +5275,7 @@ void decoder_tcx_noiseshaping_igf_fx( move16(); } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFDecApplyMono( st->hIGFDec, x_fx, x_e, igfGridIdx, bfi, st->element_mode ); -#else - IGFDecApplyMono_ivas( st->hIGFDec, x_fx, x_e, igfGridIdx, bfi, st->element_mode ); -#endif *x_len = s_max( *x_len, st->hIGFDec->igfData.igfInfo.grid[igfGridIdx].stopLine ); move16(); @@ -5344,11 +5287,7 @@ void decoder_tcx_noiseshaping_igf_fx( { IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFDecApplyMono( st->hIGFDec, x_fx, x_e, IGF_GRID_LB_SHORT, bfi, st->element_mode ); -#else - IGFDecApplyMono_ivas( st->hIGFDec, x_fx, x_e, IGF_GRID_LB_SHORT, bfi, st->element_mode ); -#endif *x_len = s_max( *x_len, st->hIGFDec->igfData.igfInfo.grid[IGF_GRID_LB_SHORT].stopLine ); move16(); diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 09b5af6607dc7b322c9abe5a393d6bb09ba05063..0eecfedee5ce85c5cb02452fb4e690b4c1de224e 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -87,878 +87,8 @@ con_tcx \brief main function in time domain TCX concealment *******************************************************/ -#ifndef HARMONIZE_2446_CON_TCX_FX void con_tcx_fx( - Decoder_State *st, /* i/o: coder memory state */ - Word16 synth[] /* i/o: synth[] Q0*/ -) -{ - Word16 i, s, c, L_frame, L_subfr, fLowPassFilter, T0; - Word16 n, mem_syn_r_size_old, mem_syn_r_size_new; - Word16 *noise; - Word16 mem_syn[M], *syn; - Word16 *exc, buf[OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2]; - Word16 pre_emph_buf; - Word16 hp_filt[L_FIR_FER2]; - Word16 alpha; - Word16 tmp_deemph, gain, gainCNG, gain_inov, scf; - Word16 *pt_exc, *pt1_exc; - Word16 Tc, tmpSeed; - Word16 fUseExtrapolatedPitch; - Word16 *ana_window; - Word16 r_h[M + 1], A_local[M + 1], mem, r_l[M + 1]; - PWord16 const *w; - Word16 W1, W2, W12; - Word16 Q_r; - Word16 tmp16, tmp16_2, tmp_loop, tmp_e, gain_tmp; - Word16 gainCNG_e, noise_e, gain_inov_e; /*Exponents for gainCNG, noise, gain_inov*/ - Word16 Q_syn; /*Q format of temporary synthesis buffer syn*/ - Word32 L_tmp, L_tmp2, step32_tmp; - Word32 predPitchLag, pitch_buf[NB_SUBFR16k], step32, gain32; - Word16 extrapolationFailed; - Word16 gainSynthDeemph; - Word16 gainSynthDeemph_e; - Word32 old_pitch_buf[2 * NB_SUBFR16k + 2]; - Word16 Q_exc, new_Q, exp_scale; - Word16 offset; - HQ_DEC_HANDLE hHQ_core; - TCX_LTP_DEC_HANDLE hTcxLtpDec; - TCX_DEC_HANDLE hTcxDec; - - hTcxLtpDec = st->hTcxLtpDec; - hHQ_core = st->hHQ_core; - hTcxDec = st->hTcxDec; - - /* inits */ - alpha = 0; - move16(); - fUseExtrapolatedPitch = 0; - move16(); - extrapolationFailed = 1; - move16(); - - noise_e = 0; - move16(); - Q_syn = -1; /*Q format of temporary synthesis buffer syn*/ - move16(); - offset = 0; - move16(); - - /* Framing parameters */ - L_frame = hTcxDec->L_frameTCX; /*Q0*/ - move16(); - /* L_subfr = st->L_frameTCX/st->nb_subfr */ - L_subfr = mult_r( hTcxDec->L_frameTCX, div_s( 1, st->nb_subfr ) ); /*Q0*/ - assert( L_subfr == hTcxDec->L_frameTCX / st->nb_subfr ); - move32(); - w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument Q15*/ - W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; - move16(); - W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 ); - W12 = shr( W1, 1 ); - - /* take the previous frame last pitch */ - Tc = round_fx( st->old_fpitchFB ); /*Q0*/ - - - set16_fx( buf, 0, OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2 ); /* initialize buf with 0 */ - // set16_fx(buf,0,shr(sizeof(buf),1)); /* initialize buf with 0 */ - - c = BASOP_Util_Divide1616_Scale( - L_frame, - st->L_frame, - &s ); - - FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) - { - old_pitch_buf[i] = L_shl( Mpy_32_16_1( st->old_pitch_buf_fx[i], c ), s ); /*Q16*/ - move32(); - } - - /* set excitation memory*/ - exc = buf + OLD_EXC_SIZE_DEC; /*Q_exc*/ - tmp_deemph = synth[-1]; /*Q0*/ - move16(); - pre_emph_buf = synth[-1]; /*Q0*/ - move16(); - - test(); - IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) - { - /* apply pre-emphasis to the signal */ - mem = shl( synth[( -( ( ( shr( L_frame, 1 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )], st->Q_syn_factor ); /*Q0*/ - move16(); - Q_exc = E_UTIL_f_preemph3( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 ); - Scale_sig( &( synth[-( ( shr( L_frame, 1 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ - st->Mode2_lp_gainc = L_deposit_l( 0 ); - - st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) ); /*Q16*/ - - st->Mode2_lp_gainp = L_max( st->Mode2_lp_gainp, 0 ); /*Q16*/ - st->Mode2_lp_gainp = L_min( st->Mode2_lp_gainp, 65536l /*1.0f Q16*/ ); /*Q16*/ - st->Mode2_lp_gainp = L_shl( st->Mode2_lp_gainp, 13 ); /*Q29*/ - - ana_window = buf; /*Q15*/ - ham_cos_window( ana_window, mult( L_frame, 24576 /*0.75f Q15*/ ), shr( L_frame, 2 ) ); - - /* Autocorrelation */ - autocorr_fx( &( synth[( -L_frame - 1 )] ), M, r_h, r_l, &Q_r, L_frame, ana_window, 0, 0 ); - - /* Lag windowing */ - lag_wind( r_h, r_l, M, st->output_Fs, LAGW_STRONG ); - - /* Levinson Durbin */ - E_LPC_lev_dur_fx( r_h, r_l, A_local, NULL, M, NULL ); - - /* copy for multiple frame loss */ - Copy( A_local, st->old_Aq_12_8_fx, M + 1 ); /*Q12*/ - - /* Residu */ - assert( ( 2 * L_subfr + Tc + 1 + M ) <= hTcxDec->old_synth_lenFB ); - - BASOP_SATURATE_WARNING_OFF_EVS /*saturation possible in case of spiky synthesis*/ - Residu3_fx( - A_local, - &( synth[-( ( add( ( L_subfr * 2 ), Tc ) + 1 ) + M )] ), /*Qx = Q0*/ - &( exc[-( ( add( ( L_subfr * 2 ), Tc ) + 1 ) + M )] ), /*Qx+1 = Q1*/ - add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M ), - 1 ); - BASOP_SATURATE_WARNING_ON_EVS - } - ELSE - { - /* apply pre-emphasis to the signal */ - mem = shl( synth[( -L_frame - 1 )], st->Q_syn_factor ); /*Q0*/ - move16(); - Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); - Scale_sig( &synth[-L_frame], L_frame, negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ - Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q12*/ - - offset = shr( L_frame, 1 ); - IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) - { - tmp16 = s_max( sub( Tc, shr( L_frame, 1 ) ), 0 ); - Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), add( offset, tmp16 ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/ - } - ELSE - { - Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-( L_subfr * 2 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/ - } - } - - /*-----------------------------------------------------------------* - * PLC: Construct the harmonic part of excitation - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( GT_16( st->last_good, UNVOICED_CLAS ) && !( EQ_16( st->last_good, UNVOICED_TRANSITION ) && EQ_16( st->core_ext_mode, GENERIC ) ) ) - { - test(); - IF( EQ_16( st->nbLostCmpt, 1 ) || hTcxDec->tcxConceal_recalc_exc ) - { - calcGainc_fx( exc, Q_exc, st->old_fpitchFB, L_subfr, st->Mode2_lp_gainp, &( st->Mode2_lp_gainc ) ); - } - - tmp16 = 0; - move16(); - if ( GT_32( st->output_Fs, 25600 ) ) - { - tmp16 = 1; - move16(); - } - - test(); - test(); - test(); - test(); - IF( ( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) && GE_16( st->rf_frame_type, RF_TCXFD ) && LE_16( st->rf_frame_type, RF_TCXTD2 ) && st->use_partial_copy ) - { - Word32 tcxltp_pitch_tmp; /*15Q16*/ - Word16 scale_tmp; /*getInvFrameLen()->9Q6*/ - Word16 tmp_shift; - tcxltp_pitch_tmp = L_add( L_deposit_h( hTcxLtpDec->tcxltp_pitch_int ), L_shl( L_deposit_l( div_s( hTcxLtpDec->tcxltp_pitch_fr, st->pit_res_max ) ), 1 ) ); /*15Q16*/ - scale_tmp = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) ); /*getInvFrameLen()->9Q6*/ - tmp_shift = norm_s( scale_tmp ); - predPitchLag = L_shl( Mpy_32_16_1( tcxltp_pitch_tmp, shl( scale_tmp, tmp_shift ) ), sub( 9, tmp_shift ) ); /*Q16*/ - - T0 = round_fx( predPitchLag ); /*Q0*/ - - test(); - test(); - if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) ) - { - fUseExtrapolatedPitch = 1; - move16(); - } - } - ELSE - { - pitch_pred_linear_fit( - st->nbLostCmpt, - st->last_good, - old_pitch_buf, - &( st->old_fpitchFB ), - &predPitchLag, - hTcxDec->pit_min_TCX, - hTcxDec->pit_max_TCX, - st->mem_pitch_gain, - tmp16, - st->plc_use_future_lag, - &extrapolationFailed, - st->nb_subfr ); - - T0 = round_fx( predPitchLag ); /*Q0*/ - test(); - test(); - test(); - if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) && ( extrapolationFailed == 0 ) ) - { - fUseExtrapolatedPitch = 1; - move16(); - } - } - - - fLowPassFilter = 0; - move16(); - pt_exc = exc + offset; /*Q_exc*/ - pt1_exc = pt_exc - Tc; /*Q_exc*/ - - if ( fUseExtrapolatedPitch != 0 ) - { - pt_exc = buf; /*Q_exc*/ - } - test(); - IF( LT_16( st->stab_fac_fx, 32767 /*1.f Q15*/ ) && EQ_16( st->nbLostCmpt, 1 ) ) - { - /* pitch cycle is first low-pass filtered */ - - IF( LE_32( st->output_Fs, 16000 ) ) - { - FOR( i = 0; i < Tc; i++ ) - { - *pt_exc++ = mac_r_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( - L_mult( 174 /* 0.0053f Q15*/, pt1_exc[-5] ), - 0 /* 0.0000f Q15*/, pt1_exc[-4] ), - -1442 /*-0.0440f Q15*/, pt1_exc[-3] ), - 0 /* 0.0000f Q15*/, pt1_exc[-2] ), - 8641 /* 0.2637f Q15*/, pt1_exc[-1] ), - 18022 /* 0.5500f Q15*/, pt1_exc[0] ), - 8641 /* 0.2637f Q15*/, pt1_exc[1] ), - 0 /* 0.0000f Q15*/, pt1_exc[2] ), - -1442 /*-0.0440f Q15*/, pt1_exc[3] ), - 0 /* 0.0000f Q15*/, pt1_exc[4] ), - 174 /* 0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/ - move16(); - pt1_exc++; - } - } - ELSE /*(st->output_Fs >= 32000)*/ - { - FOR( i = 0; i < Tc; i++ ) - { - *pt_exc++ = mac_r_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( - L_mult( -174 /*-0.0053f Q15*/, pt1_exc[-5] ), - -121 /*-0.0037f Q15*/, pt1_exc[-4] ), - -459 /*-0.0140f Q15*/, pt1_exc[-3] ), - 590 /* 0.0180f Q15*/, pt1_exc[-2] ), - 8743 /* 0.2668f Q15*/, pt1_exc[-1] ), - 16355 /* 0.4991f Q15*/, pt1_exc[0] ), - 8743 /* 0.2668f Q15*/, pt1_exc[1] ), - 590 /* 0.0180f Q15*/, pt1_exc[2] ), - -459 /*-0.0140f Q15*/, pt1_exc[3] ), - -121 /*-0.0037f Q15*/, pt1_exc[4] ), - -174 /*-0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/ - move16(); - pt1_exc++; - } - } - - fLowPassFilter = 1; - move16(); - } - ELSE - { - /* copy the first pitch cycle without low-pass filtering */ - FOR( i = 0; i < Tc; i++ ) - { - *pt_exc++ = *pt1_exc++; /*Q_exc*/ - move16(); - } - fLowPassFilter = 1; - move16(); - } - - if ( fUseExtrapolatedPitch != 0 ) - { - pt1_exc = buf; /*Q_exc*/ - } - tmp16 = add( sub( L_frame, imult1616( fLowPassFilter, Tc ) ), L_subfr ); - FOR( i = 0; i < tmp16; i++ ) - { - *pt_exc++ = *pt1_exc++; /*Q_exc*/ - move16(); - } - - if ( fUseExtrapolatedPitch != 0 ) - { - get_subframe_pitch( st->nb_subfr, - st->old_fpitch, - /* predPitchLag * L_frame/st->L_frame, */ - L_shr( Mpy_32_16_1( predPitchLag /*Q16*/, - mult_r( st->L_frame /*Q0*/, - getInvFrameLen( L_frame ) /*Q21*/ - ) /*Q6*/ - ) /*Q7*/, - 7 - 16 ) /*Q16*/, - pitch_buf ); - - PulseResynchronization_fx( buf, exc, L_frame, st->nb_subfr, st->old_fpitchFB, predPitchLag ); - } - ELSE - { - set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); /*Q16*/ - } - - IF( EQ_16( st->nbLostCmpt, 1 ) ) - { - pt_exc = exc + L_frame; - IF( T0 == 0 ) - { - pt1_exc = pt_exc - Tc; - } - ELSE - { - pt1_exc = pt_exc - T0; - } - - tmp_loop = shr( L_frame, 1 ); - FOR( i = 0; i < tmp_loop; i++ ) - { - *pt_exc++ = *pt1_exc++; /*Q_exc*/ - move16(); - } - } - - if ( fUseExtrapolatedPitch != 0 ) - { - st->old_fpitchFB = predPitchLag; /*Q16*/ - move32(); - } - st->bpf_gain_param = 0; - move16(); - - /* PLC: calculate damping factor */ - alpha = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac_fx, &( st->Mode2_lp_gainp ), 0 ); /*Q14*/ - IF( EQ_16( st->nbLostCmpt, 1 ) ) - { - st->cummulative_damping = 32767 /*1.f Q15*/; - move16(); - } - ELSE - { - st->cummulative_damping = shl_sat( mult_r_sat( st->cummulative_damping /*Q15*/, alpha /*Q14*/ ), 1 ) /*Q15*/; - move16(); - } - - gain32 = L_add( 2147483647l /*1.f Q31*/, 0 ); /*Q31*/ - gain = 32767 /*1.f Q15*/; /*Q15*/ - move16(); - test(); - IF( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) ) - { - gain32 = 1073741824l /*0.5f Q31*/; - move32(); - gain = 16384 /*0.5f Q15*/; - move16(); - } - - /*step = (1.0f/(L_frame+(L_frame/2))) * (gain - alpha);*/ - tmp16 = shr( imult1616( 3, L_frame ), 1 ); - tmp_e = norm_s( tmp16 ); - tmp16 = shl( tmp16, tmp_e ); - tmp16 = div_s( 16384 /*1.f Q14*/, tmp16 ); /*Q15,1+tmp_e-15*/ - tmp16_2 = sub( shr( gain, 1 ), alpha ) /*Q14*/; - step32 = L_shl( L_mult( tmp16, tmp16_2 ) /*Q30, 1+tmp_e-15*/, add( 1 - 14, tmp_e ) ) /*Q31*/; - - /* PLC: Apply fade out */ - tmp_loop = shr( imult1616( L_frame, 3 ), 1 ); - FOR( i = offset; i < tmp_loop; i++ ) - { - exc[i] = mult_r( exc[i], round_fx_sat( gain32 ) ) /*Q1*/; - move16(); - gain32 = L_sub_sat( gain32, step32 ); /*Q31*/ - } - - /* update old exc without random part */ - offset = s_max( sub( round_fx( st->old_fpitchFB ), shr( L_frame, 1 ) ), 0 ); /*Q0*/ - Copy( exc + sub( L_frame, offset ), hTcxDec->old_excFB_fx, add( shr( L_frame, 1 ), offset ) ); /*Q_exc*/ - /* copy old_exc as 16kHz for acelp decoding */ - IF( EQ_16( st->nbLostCmpt, 1 ) ) - { - lerp( exc - shr( L_frame, 1 ), st->old_exc_fx, L_EXC_MEM_DEC, add( L_frame, shr( L_frame, 1 ) ) ); - } - ELSE - { - Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); /*Q_exc*/ - lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); - } - st->Q_exc = Q_exc; - move16(); - } - ELSE - { - /* No harmonic part */ - set16_fx( &exc[0], 0, add( L_frame, shr( L_frame, 1 ) ) ); - IF( EQ_16( st->nbLostCmpt, 1 ) ) - { - calcGainc2_fx( &exc[0], Q_exc, L_subfr, &( st->Mode2_lp_gainc ) ); - } - set32_fx( pitch_buf, L_deposit_h( L_SUBFR ), st->nb_subfr ); /*Q16*/ - /* PLC: calculate damping factor */ - alpha = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac_fx, &( st->Mode2_lp_gainp ), 0 ); /*Q14*/ - } - - /*-----------------------------------------------------------------* - * Construct the random part of excitation - *-----------------------------------------------------------------*/ - - { - tmpSeed = st->seed_acelp; - move16(); - noise = buf; - noise_e = 1; /*set exponent of noise to 1*/ - move16(); - - tmp_loop = add( L_frame, L_FIR_FER2 - 1 ); - FOR( i = 0; i < tmp_loop; i++ ) - { - Random( &tmpSeed ); - noise[i] = shr( tmpSeed, noise_e ); /*Q: -noise_e*/ - move16(); - } - st->seed_acelp = tmpSeed; - move16(); - - tmp_loop = add( add( L_frame, shr( L_frame, 1 ) ), shl( L_FIR_FER2, 1 ) ); - FOR( ; i < tmp_loop; i++ ) - { - Random( &tmpSeed ); - noise[i] = shr( tmpSeed, noise_e ); /*Q: -noise_e*/ - move16(); - } - } - test(); - IF( EQ_16( st->last_good, VOICED_CLAS ) || EQ_16( st->last_good, ONSET ) ) - { - tmp16 = 19661 /*0.6f Q15*/; - move16(); - if ( LE_32( st->output_Fs, 16000 ) ) - { - tmp16 = 6554 /*0.2f Q15*/; - move16(); - } - - mem = noise[0]; - move16(); - preemph_copy_fx( &noise[1], &noise[1], tmp16, add( add( L_frame, shr( L_frame, 1 ) ), L_FIR_FER2 ), &mem ); - } - /* high rate filter tuning */ - IF( LE_32( st->output_Fs, 16000 ) ) - { - FOR( i = 0; i < L_FIR_FER2; i++ ) - { - hp_filt[i] = h_high3_16[i]; /*Q15*/ - move16(); - } - } - ELSE /*(st->output_Fs==32000)*/ - { - FOR( i = 0; i < L_FIR_FER2; i++ ) - { - hp_filt[i] = h_high3_32[i]; /*Q15*/ - move16(); - } - } - IF( EQ_16( st->nbLostCmpt, 1 ) ) - { - highPassFiltering_fx( st->last_good, add( add( L_frame, shr( L_frame, 1 ) ), L_FIR_FER2 ), noise, hp_filt, L_FIR_FER2 ); - } - ELSE - { - IF( GT_16( st->last_good, UNVOICED_TRANSITION ) ) - { - tmp_loop = add( add( L_frame, shr( L_frame, 1 ) ), L_FIR_FER2 ); - gain_tmp = negate( add( -32768, st->cummulative_damping ) ); /*Q15*/ - FOR( i = 0; i < tmp_loop; i++ ) - { - Word16 j; - L_tmp2 = 0; - move32(); - FOR( j = 11; j > 0; j-- ) - { - L_tmp2 = L_mac( L_tmp2, noise[( i + sub( L_FIR_FER2, j ) )], hp_filt[( L_FIR_FER2 - j )] ); - } - L_tmp2 = Mpy_32_16_1( L_tmp2, st->cummulative_damping /*Q15*/ ); /*Q0, noise_e*/ - noise[i] = mac_r( L_tmp2, gain_tmp, noise[i] ); /*Q15, noise_e*/ - move16(); - } - } - } - - /* PLC: [TCX: Fade-out] retrieve background level */ - tmp16 = 32767; - move16(); - gainSynthDeemph = getLevelSynDeemph_fx( &( tmp16 ), A_local, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ); /*Q5*/ - IF( st->tcxonly != 0 ) - { - /* gainCNG = st->conCngLevelBackgroundTrace/gainSynthDeemph; */ - BASOP_Util_Divide_MantExp( hTcxDec->conCngLevelBackgroundTrace, - hTcxDec->conCngLevelBackgroundTrace_e, - gainSynthDeemph, gainSynthDeemph_e, - &gainCNG, &gainCNG_e ); - } - ELSE - { - /* gainCNG = st->cngTDLevel/gainSynthDeemph; */ - BASOP_Util_Divide_MantExp( st->cngTDLevel, - st->cngTDLevel_e, - gainSynthDeemph, gainSynthDeemph_e, - &gainCNG, &gainCNG_e ); - } - - gain32 = L_add( st->Mode2_lp_gainc, 0 ); /* start-of-the-frame gain - Q16*/ - test(); - if ( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) ) - { - gain32 = Mpy_32_16_1( gain32, 22938 /*0.7f Q15*/ ); /*Q16*/ - } - L_tmp = L_shl_sat( gain32, 1 ); /*Q16*/ - IF( GT_32( L_shl( L_deposit_h( gainCNG ), sub( gainCNG_e, 31 - 16 ) /*Q16*/ ), L_tmp ) ) - { - gainCNG_e = sub( 15 + 1, norm_l( L_tmp ) ); - gainCNG = extract_l( L_shr( L_tmp, gainCNG_e ) ); /*Q15,gainCNG_e*/ - gainCNG_e = sub( gainCNG_e, 1 ); - } - - /* st->Mode2_lp_gainc = alpha * (st->Mode2_lp_gainc) + (1.0f - alpha) * gainCNG;*/ /* end-of-the-frame gain */ - - L_tmp = Mpy_32_16_1( st->Mode2_lp_gainc, alpha ) /*Q15*/; - L_tmp2 = L_mult( sub( 16384 /*1.f Q14*/, alpha ) /*Q14*/, gainCNG /*Q15,gainCNG_e*/ ); /*Q30,gainCNG_e*/ - st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp( L_tmp, 31 - 15, L_tmp2, add( gainCNG_e, 31 - 30 ), &tmp_e ); /*Q31-tmp_e*/ - st->Mode2_lp_gainc = L_shl( st->Mode2_lp_gainc, sub( tmp_e, 31 - 16 ) ); /*Q16*/ - move32(); - move32(); - - /* PLC: [TCX: Fade-out] Linearly attenuate the gain through the frame */ - /*step = (1.0f/L_frame) * (gain - (st->Mode2_lp_gainc));*/ - L_tmp = L_sub( gain32, st->Mode2_lp_gainc ); /*Q16*/ - tmp_e = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, tmp_e ); /*Q16,-tmp_e*/ - step32 = Mpy_32_16_1( L_tmp /*Q16,-tmp_e*/, getInvFrameLen( L_frame ) /*W16Q21*/ ); /*Q22,-tmp_e*/ - step32 = L_shl( step32, sub( 25 - 22, tmp_e ) ); /*Q25*/ - - pt_exc = noise + L_FIR_FER2 / 2; - - /*gain_inov = 1.0f / (float)sqrt( dot_product( pt_exc, pt_exc, L_frame ) / L_frame + 0.01f );*/ /* normalize energy */ - L_tmp = Dot_productSq16HQ( 0, pt_exc /*Q0,15+1*/, L_frame, &tmp_e ) /*Q31,tmp_e+16+16*/; - L_tmp = Mpy_32_16_1( L_tmp, getInvFrameLen( L_frame ) /*W16Q21*/ ) /*W32Q37,tmp_e+16+16*/ /*Q5,tmp_e*/; - tmp_e = add( tmp_e, 31 - 5 ); /*-->Q31*/ - gain_inov = round_fx( ISqrt32( L_tmp, &tmp_e ) ); /*Q15,tmp_e*/ - gain_inov_e = tmp_e; - move16(); - test(); - test(); - IF( EQ_16( st->last_good, UNVOICED_CLAS ) && NE_16( st->core_ext_mode, UNVOICED ) ) - { - gain_inov = mult_r( gain_inov, 26214 /*0.8f Q15*/ ); /*Q30*/ - } - ELSE IF( !( EQ_16( st->last_good, UNVOICED_CLAS ) || EQ_16( st->last_good, UNVOICED_TRANSITION ) ) ) - { - /*gain_inov *= (1.1f- 0.75*st->lp_gainp);*/ - L_tmp = Mpy_32_16_1( L_sub( 590558016l /*1.1f Q29*/, Mpy_32_16_1( st->Mode2_lp_gainp, 24576 ) ) /*Q29*/, gain_inov /*Q15,gain_inov_e*/ ); /*Q29,gain_inov_e*/ - tmp_e = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, tmp_e ); - gain_inov_e = add( sub( gain_inov_e, tmp_e ), 31 - 29 ); /*->Q31*/ - gain_inov = round_fx_sat( L_tmp ); /*Q15,gain_inov_e*/ - } - - st->Mode2_lp_gainp = L_shr( L_deposit_h( alpha /*Q14*/ ) /*Q14+16*/, 1 ); /*Q29*/ - move32(); - pt_exc = noise; /* non-causal ringing of the FIR filter */ - - tmp_e = norm_l( gain32 ); - tmp_e = sub( tmp_e, 5 ); /*5 Bit additional Headroom for the gain - should be enough*/ - gain32 = L_shl( gain32, tmp_e ); /*Q16,-tmp_e*/ - L_tmp = Mpy_32_16_1( gain32 /*Q16,-tmp_e*/, gain_inov /*Q15,gain_inov_e*/ ) /*Q16,gain_inov_e-tmp_e*/; - - gain_tmp = round_fx( L_tmp ); /*Q0, gain_inov_e-tmp_e*/ - - FOR( i = 0; i < L_FIR_FER2 / 2; i++ ) - { - *pt_exc = mult_r( *pt_exc, gain_tmp ); /*Q-15,noise_e+gain_inov_e-tmp_e*/ - move16(); - pt_exc++; - } - tmp16 = add( L_frame, L_FIR_FER2 / 2 ); - step32_tmp = L_shl( step32 /*Q25*/, sub( tmp_e, 25 - 16 ) ); /*Q16,-tmp_e*/ - FOR( i = 0; i < tmp16; i++ ) /* Actual filtered random part of excitation */ - { - *pt_exc = mult_r( *pt_exc, gain_tmp ); /*Q-15,noise_e+gain_inov_e-tmp_e*/ - move16(); - pt_exc++; - gain32 = L_sub( gain32 /*Q16,-tmp_e*/, step32_tmp ); /*Q16,-tmp_e*/ - gain_tmp = mult_r( round_fx( gain32 /*Q16,-tmp_e*/ ) /*Q0*/, gain_inov /*Q15,gain_inov_e*/ ) /*Q0,gain_inov_e-tmp_e*/; - } - tmp16 = shr( L_frame, 1 ); - FOR( i = 0; i < tmp16; i++ ) /* causal ringing of the FIR filter */ - { - *pt_exc = mult_r( *pt_exc, gain_tmp ); /*Q-15,noise_e+gain_inov_e-tmp_e*/ - move16(); - pt_exc++; - } - noise_e = add( sub( add( noise_e, gain_inov_e ), tmp_e ), 15 ); /*--> noise is Q0, noise_e*/ - /*buf[0;L_FIR_FER2 + L_Frame + L_Frame/2] Q0, noise_e*/ - - /*-----------------------------------------------------------------* - * Construct the total excitation - *-----------------------------------------------------------------*/ - - IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) - { - tmp16 = add( L_frame, shr( L_frame, 1 ) ); - FOR( i = 0; i < tmp16; i++ ) - { - exc[i] = add_sat( exc[i], shl_sat( noise[i + ( L_FIR_FER2 / 2 )], add( Q_exc, noise_e ) ) ); /*Q1*/ - move16(); - } - } - ELSE - { - bufferCopyFx( noise + L_FIR_FER2 / 2, exc, add( L_frame, shr( L_frame, 1 ) ), 0 /*Q_noise*/, noise_e, Q_exc, 0 /*exc_e*/ ); - Copy( exc + sub( L_frame, shl( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl( L_subfr, 1 ), shr( L_frame, 1 ) ) ); /*Q_exc*/ - /* copy old_exc as 16kHz for acelp decoding */ - IF( EQ_16( st->nbLostCmpt, 1 ) ) - { - lerp( exc, st->old_exc_fx, L_EXC_MEM_DEC, add( L_frame, shr( L_frame, 1 ) ) ); - } - ELSE - { - Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); /*Q_exc*/ - lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); - } - st->Q_exc = Q_exc; - move16(); - } - /*buf[0;L_FIR_FER2 + L_Frame + L_Frame/2] Q0, noise_e*/ - /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1*/ - - /* Update Pitch Lag memory */ - Copy32( &st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr ); /*Q16*/ - Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr ); /*Q16*/ - - /*----------------------------------------------------------* - * - compute the synthesis speech * - *----------------------------------------------------------*/ - - syn = buf + M; /*Q_syn*/ - Copy( synth - M, buf, M ); /*Q_syn*/ - IF( NE_32( st->element_mode, EVS_MONO ) ) // to keep evs bit-exactness - { - scf = norm_s( tmp_deemph ); - new_Q = sub( Q_exc, 4 ); - new_Q = s_max( new_Q, -1 ); - new_Q = s_min( new_Q, scf ); - } - ELSE - { - new_Q = sub( Q_exc, 3 ); - new_Q = s_max( new_Q, -1 ); - - scf = 0; - move16(); - } - - tmp16 = s_min( new_Q, st->prev_Q_syn ); - st->prev_Q_syn = new_Q; - move16(); - - exp_scale = sub( tmp16, sub( Q_exc, 1 ) ); - Q_syn = tmp16; - move16(); - - Copy_Scale_sig( buf, mem_syn, M, exp_scale ); /*Q: tmp16*/ - IF( NE_32( st->element_mode, EVS_MONO ) ) // to keep evs bit-exactness - { - if ( GT_16( sub( Q_syn, st->Q_syn_factor ), scf ) ) - { - Q_syn = add( scf, st->Q_syn_factor ); // so that (Q_syn - st->Q_syn_factor) = scf; - } - tmp_deemph = shl( tmp_deemph, sub( Q_syn, st->Q_syn_factor ) ); - } - ELSE - { - tmp_deemph = shl_sat( tmp_deemph, Q_syn ); /*Q_syn*/ - } - st->Q_syn_factor = 0; - move16(); - st->Q_syn = Q_syn; - move16(); - - /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1: exc*/ - /*buf[0;M] Q0: mem_syn*/ - E_UTIL_synthesis( - sub( Q_exc, Q_syn ), - A_local, - &exc[0], - &syn[0], - add( L_frame, shr( L_frame, 1 ) ), - mem_syn, - 1, - M ); - - /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame-1] Q1: exc*/ - /*buf[0;M-1] Q0: mem_syn*/ - /*buf[M;3/2 L_frame-1] Q-1: syn*/ - - n = extract_h( L_mult( L_frame, 9216 /*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/ ) ); /*q0*/ - - /* update ACELP synthesis memory */ - mem_syn_r_size_old = shr( L_frame, 4 ); /* replace 1.25/20.0 by shr(4) */ - /* copy mem_syn as 16kHz */ - mem_syn_r_size_new = shr( L_FRAME16k, 4 ); /* replace 1.25/20.0 by shr(4) */ - - Copy( syn + sub( L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); /*Q_syn*/ - lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); - Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /*Q_syn*/ - - /* Deemphasis and output synth and ZIR */ - deemph_fx( syn, st->preemph_fac, add( L_frame, shr( L_frame, 1 ) ), &tmp_deemph ); - bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); /*Q_syn*/ - - - lerp( syn + sub( L_frame, shr( L_frame, 1 ) ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); - st->hTcxDec->Q_old_syn_Overl = Q_syn; - move16(); - Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); /*Q_syn*/ - - FOR( i = 0; i < W12; i++ ) - { - hHQ_core->old_out_fx[( i + n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[( i + n )] ) ); /*Q_syn*/ - move16(); - } - FOR( ; i < W1; i++ ) - { - hHQ_core->old_out_fx[( i + n )] = round_fx( Mpy_32_16_1( L_mult( w[( ( W12 - 1 ) - ( i - W12 ) )].v.im, w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ), hHQ_core->old_out_fx[( i + n )] ) ); /*Q_syn*/ - move16(); - } - - set16_fx( &hHQ_core->old_out_fx[( W1 + n )], 0, n ); - - hHQ_core->Q_old_wtda = Q_syn; - move16(); - - /* As long as there is no synth scaling factor introduced, which - is given to the outside, there might occur overflows here */ - BASOP_SATURATE_WARNING_OFF_EVS - bufferCopyFx( syn, synth, L_frame, Q_syn, 0, 0, 0 ); /*Q_syn*/ - BASOP_SATURATE_WARNING_ON_EVS - - Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), sub( 0, Q_syn ) ); /*Q0*/ - hTcxDec->Q_syn_OverlFB = 0; - move16(); - - /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */ - IF( st->hWIDec != NULL ) - { - lerp( exc, st->hWIDec->old_exc2_fx, L_EXC_MEM, L_frame ); - lerp( syn, st->hWIDec->old_syn2_fx, L_EXC_MEM, L_frame ); - } - - st->bfi_pitch_fx /*Q6*/ = round_fx_sat( L_shl_sat( pitch_buf[( st->nb_subfr - 1 )] /*15Q16*/, 6 /*Q6*/ ) ); - move16(); - st->bfi_pitch_frame = st->L_frame; - move16(); - - /* create aliasing and windowing need for transition to TCX10/5 */ - bufferCopyFx( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ), Q_syn, 0, -1, 0 ); - hTcxDec->Q_syn_Overl_TDACFB = add( st->Q_syn, sub( st->Q_syn, -1 ) ); - move16(); - - FOR( i = 0; i < W12; i++ ) - { - buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); /*hTcxDec->Q_syn_Overl_TDACFB*/ - move16(); - } - FOR( ; i < W1; i++ ) - { - buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ); /*hTcxDec->Q_syn_Overl_TDACFB*/ - move16(); - } - - - FOR( i = 0; i < W2; i++ ) - { - hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[( ( W1 - 1 ) - i )] ); /*hTcxDec->Q_syn_Overl_TDACFB*/ - move16(); - } - - FOR( i = 0; i < W2; i++ ) - { - hTcxDec->syn_Overl_TDACFB[( W2 + i )] = add_sat( buf[( W2 + i )], buf[( ( ( W1 - 1 ) - W2 ) - i )] ); /*hTcxDec->Q_syn_Overl_TDACFB*/ - move16(); - } - - FOR( i = 0; i < W12; i++ ) - { - hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[i].v.re ); /*hTcxDec->Q_syn_Overl_TDACFB*/ - move16(); - } - FOR( ; i < W1; i++ ) - { - hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ); /*hTcxDec->Q_syn_Overl_TDACFB*/ - move16(); - } - - st->hTcxCfg->tcx_curr_overlap_mode = FULL_OVERLAP; - move16(); - - synth[-1] = pre_emph_buf; /*Q0*/ - move16(); - - /* update memory for low band */ - Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); /*Q_syn*/ - hTcxDec->Q_old_syn_Overl = -1; - move16(); - lerp( hTcxDec->syn_OverlFB, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); - hTcxDec->Q_syn_Overl = hTcxDec->Q_syn_OverlFB; - move16(); - lerp( hTcxDec->syn_Overl_TDACFB, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); - hTcxDec->Q_syn_Overl_TDAC = hTcxDec->Q_syn_Overl_TDACFB; - move16(); - lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, L_frame ); - - st->old_enr_LP = Enr_1_Az_fx( A_local, L_SUBFR ); /*Q3*/ - move16(); - - return; -} - -#endif // !HARMONIZE_2446_CON_TCX_FX - -#ifdef HARMONIZE_2446_CON_TCX_FX -void con_tcx_fx( - Decoder_State *st, /* i/o: coder memory state */ - Word16 synth[], /* i/o: synth[] Q0 */ - const Word16 coh, /* i : coherence of stereo signal Q14*/ - Word16 *noise_seed, /* i/o: noise seed for stereo Q0 */ - const Word16 only_left, /* i : TD-PLC only in left channel Q0 */ - const Word16 *A_cng /* i : CNG LP filter coefficients Q14*/ -) -#else -void con_tcx_ivas_fx( Decoder_State *st, /* i/o: coder memory state */ Word16 synth[], /* i/o: synth[] Q0 */ const Word16 coh, /* i : coherence of stereo signal Q14*/ @@ -966,8 +96,6 @@ void con_tcx_ivas_fx( const Word16 only_left, /* i : TD-PLC only in left channel Q0 */ const Word16 *A_cng /* i : CNG LP filter coefficients Q14*/ ) -#endif // HARMONIZE_2446_CON_TCX_FX - { Word16 i, s, c, L_frame, L_subfr, fLowPassFilter, T0; Word16 n, mem_syn_r_size_old, mem_syn_r_size_new; @@ -1061,16 +189,9 @@ void con_tcx_ivas_fx( IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) { /* apply pre-emphasis to the signal */ -#ifndef HARMONIZE_2446_CON_TCX_FX - mem = shl( synth[( -( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) - 1 )], st->Q_syn_factor ); -#else mem = shl_sat( synth[( -( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) - 1 )], st->Q_syn_factor ); -#endif // !HARMONIZE_2446_CON_TCX_FX move16(); -#ifndef HARMONIZE_2446_CON_TCX_FX - Q_exc = E_UTIL_f_preemph3_ivas_fx( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 ); -#else IF( NE_16( st->element_mode, EVS_MONO ) ) { Q_exc = E_UTIL_f_preemph3_ivas_fx( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl_sat( M, 1 ) ), &mem, 1 ); @@ -1079,11 +200,7 @@ void con_tcx_ivas_fx( { Q_exc = E_UTIL_f_preemph3( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl_sat( M, 1 ) ), &mem, 1 ); } -#endif // !HARMONIZE_2446_CON_TCX_FX -#ifndef HARMONIZE_2446_CON_TCX_FX - scale_sig( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl_sat( M, 1 ) ), negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ -#else IF( NE_16( st->element_mode, EVS_MONO ) ) { scale_sig( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl_sat( M, 1 ) ), negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ @@ -1093,14 +210,8 @@ void con_tcx_ivas_fx( Scale_sig( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl_sat( M, 1 ) ), negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ } -#endif // !HARMONIZE_2446_CON_TCX_FX st->Mode2_lp_gainc = L_deposit_l( 0 ); -#ifndef HARMONIZE_2446_CON_TCX_FX - st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) ); -#else st->Mode2_lp_gainp = get_gain2( synth - shl_sat( L_subfr, 1 ), synth - add( shl_sat( L_subfr, 1 ), Tc ), shl_sat( L_subfr, 1 ) ); -#endif // !HARMONIZE_2446_CON_TCX_FX - move32(); st->Mode2_lp_gainp = L_max( st->Mode2_lp_gainp, 0 ); /*Q16*/ @@ -1120,10 +231,6 @@ void con_tcx_ivas_fx( lag_wind( r_h, r_l, M, st->output_Fs, LAGW_STRONG ); /* Levinson Durbin */ -#ifndef HARMONIZE_2446_CON_TCX_FX - E_LPC_lev_dur_ivas_fx( r_h, r_l, A_local, NULL, M, NULL ); - -#else IF( NE_16( st->element_mode, EVS_MONO ) ) { E_LPC_lev_dur_ivas_fx( r_h, r_l, A_local, NULL, M, NULL ); @@ -1132,8 +239,6 @@ void con_tcx_ivas_fx( { E_LPC_lev_dur_fx( r_h, r_l, A_local, NULL, M, NULL ); } -#endif // !HARMONIZE_2446_CON_TCX_FX - /* copy for multiple frame loss */ Copy( A_local, st->old_Aq_12_8_fx, M + 1 ); /*Q14*/ @@ -1142,37 +247,19 @@ void con_tcx_ivas_fx( assert( ( 2 * L_subfr + Tc + 1 + M ) <= hTcxDec->old_synth_lenFB ); BASOP_SATURATE_WARNING_OFF_EVS /*saturation possible in case of spiky synthesis*/ -#ifndef HARMONIZE_2446_CON_TCX_FX - Residu3_fx( - A_local, - &( synth[-add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M )] ), /*Qx = Q0*/ - &( exc[-add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M )] ), /*Qx+1 = Q1*/ - add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M ), - 1 ); -#else Residu3_fx( A_local, &( synth[-add( add( add( shl_sat( L_subfr, 1 ), Tc ), 1 ), M )] ), /*Qx = Q0*/ &( exc[-add( add( add( shl_sat( L_subfr, 1 ), Tc ), 1 ), M )] ), /*Qx+1 = Q1*/ add( add( add( shl_sat( L_subfr, 1 ), Tc ), 1 ), M ), 1 ); -#endif // !HARMONIZE_2446_CON_TCX_FX BASOP_SATURATE_WARNING_ON_EVS } ELSE { /* apply pre-emphasis to the signal */ -#ifndef HARMONIZE_2446_CON_TCX_FX - mem = shl( synth[( -L_frame - 1 )], st->Q_syn_factor ); /*hTcxDec->Q_synth_factor_old*/ -#else mem = shl_sat( synth[( -L_frame - 1 )], st->Q_syn_factor ); /* hTcxDec->Q_synth_factor_old */ -#endif move16(); -#ifndef HARMONIZE_2446_CON_TCX_FX - Q_exc = E_UTIL_f_preemph3_ivas_fx( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); - scale_sig( &synth[-L_frame], L_frame, negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ - -#else IF( NE_16( st->element_mode, EVS_MONO ) ) { Q_exc = E_UTIL_f_preemph3_ivas_fx( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); @@ -1183,27 +270,17 @@ void con_tcx_ivas_fx( Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); Scale_sig( &synth[-L_frame], L_frame, negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ } -#endif // !HARMONIZE_2446_CON_TCX_FX Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q14*/ offset = shr( L_frame, 1 ); IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) { -#ifndef HARMONIZE_2446_CON_TCX_FX - tmp16 = s_max( Tc - shr( L_frame, 1 ), 0 ); -#else tmp16 = s_max( sub( Tc, shr( L_frame, 1 ) ), 0 ); -#endif // !HARMONIZE_2446_CON_TCX_FX - Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), add( offset, tmp16 ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/ } ELSE { -#ifndef HARMONIZE_2446_CON_TCX_FX - Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-( L_subfr * 2 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/ -#else Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-( L_subfr * 2 )] ), add( shl_sat( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/ -#endif // !HARMONIZE_2446_CON_TCX_FX } } @@ -1242,11 +319,7 @@ void con_tcx_ivas_fx( scale_tmp = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) ); /*getInvFrameLen()->9Q6*/ tmp_shift = norm_s( scale_tmp ); -#ifndef HARMONIZE_2446_CON_TCX_FX - predPitchLag = L_shl( Mpy_32_16_1( tcxltp_pitch_tmp, shl( scale_tmp, tmp_shift ) ), sub( 9, tmp_shift ) ); /*Q16*/ -#else predPitchLag = L_shl( Mpy_32_16_1( tcxltp_pitch_tmp, shl_sat( scale_tmp, tmp_shift ) ), sub( 9, tmp_shift ) ); /*Q16*/ -#endif // !HARMONIZE_2446_CON_TCX_FX T0 = round_fx( predPitchLag ); /*Q0*/ @@ -1305,20 +378,6 @@ void con_tcx_ivas_fx( { FOR( i = 0; i < Tc; i++ ) { -#ifndef HARMONIZE_2446_CON_TCX_FX - *pt_exc++ = mac_r( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( - L_mult( 174 /* 0.0053f Q15*/, pt1_exc[-5] ), - 0 /* 0.0000f Q15*/, pt1_exc[-4] ), - -1442 /*-0.0440f Q15*/, pt1_exc[-3] ), - 0 /* 0.0000f Q15*/, pt1_exc[-2] ), - 8641 /* 0.2637f Q15*/, pt1_exc[-1] ), - 18022 /* 0.5500f Q15*/, pt1_exc[0] ), - 8641 /* 0.2637f Q15*/, pt1_exc[1] ), - 0 /* 0.0000f Q15*/, pt1_exc[2] ), - -1442 /*-0.0440f Q15*/, pt1_exc[3] ), - 0 /* 0.0000f Q15*/, pt1_exc[4] ), - 174 /* 0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/ -#else *pt_exc++ = mac_r_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mult( 174 /* 0.0053f Q15*/, pt1_exc[-5] ), 0 /* 0.0000f Q15*/, pt1_exc[-4] ), @@ -1331,9 +390,6 @@ void con_tcx_ivas_fx( -1442 /*-0.0440f Q15*/, pt1_exc[3] ), 0 /* 0.0000f Q15*/, pt1_exc[4] ), 174 /* 0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/ - - -#endif // !HARMONIZE_2446_CON_TCX_FX move16(); pt1_exc++; } @@ -1342,20 +398,6 @@ void con_tcx_ivas_fx( { FOR( i = 0; i < Tc; i++ ) { -#ifndef HARMONIZE_2446_CON_TCX_FX - *pt_exc++ = mac_r( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( - L_mult( -174 /*-0.0053f Q15*/, pt1_exc[-5] ), - -121 /*-0.0037f Q15*/, pt1_exc[-4] ), - -459 /*-0.0140f Q15*/, pt1_exc[-3] ), - 590 /* 0.0180f Q15*/, pt1_exc[-2] ), - 8743 /* 0.2668f Q15*/, pt1_exc[-1] ), - 16355 /* 0.4991f Q15*/, pt1_exc[0] ), - 8743 /* 0.2668f Q15*/, pt1_exc[1] ), - 590 /* 0.0180f Q15*/, pt1_exc[2] ), - -459 /*-0.0140f Q15*/, pt1_exc[3] ), - -121 /*-0.0037f Q15*/, pt1_exc[4] ), - -174 /*-0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/ -#else *pt_exc++ = mac_r_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mult( -174 /*-0.0053f Q15*/, pt1_exc[-5] ), -121 /*-0.0037f Q15*/, pt1_exc[-4] ), @@ -1368,9 +410,6 @@ void con_tcx_ivas_fx( -459 /*-0.0140f Q15*/, pt1_exc[3] ), -121 /*-0.0037f Q15*/, pt1_exc[4] ), -174 /*-0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/ - - -#endif // !HARMONIZE_2446_CON_TCX_FX move16(); pt1_exc++; } @@ -1478,19 +517,12 @@ void con_tcx_ivas_fx( /*step = (1.0f/(L_frame+(L_frame/2))) * (gain - alpha);*/ tmp16 = shr( imult1616( 3, L_frame ), 1 ); tmp_e = norm_s( tmp16 ); -#ifndef HARMONIZE_2446_CON_TCX_FX - tmp16 = shl( tmp16, tmp_e ); -#else tmp16 = shl_sat( tmp16, tmp_e ); -#endif // !HARMONIZE_2446_CON_TCX_FX tmp16 = div_s( 16384 /*1.f Q14*/, tmp16 ); /*Q15,1+tmp_e-15*/ tmp16_2 = sub( shr( gain, 1 ), alpha ) /*Q14*/; -#ifndef HARMONIZE_2446_CON_TCX_FX - step32 = L_shl( L_mult( tmp16, tmp16_2 ) /*Q30, 1+tmp_e-15*/, add( 1 - 14, tmp_e ) ) /*Q31*/; -#else step32 = L_shl_sat( L_mult( tmp16, tmp16_2 ) /*Q30, 1+tmp_e-15*/, add( 1 - 14, tmp_e ) ) /*Q31*/; -#endif // HARMONIZE_2446_CON_TCX_FX + /* PLC: Apply fade out */ tmp_loop = shr( imult1616( L_frame, 3 ), 1 ); FOR( i = offset; i < tmp_loop; i++ ) @@ -1597,12 +629,8 @@ void con_tcx_ivas_fx( } st->seed_acelp = tmpSeed; move16(); -#ifndef HARMONIZE_2446_CON_TCX_FX - tmp_loop = add(add(L_frame, shr(L_frame, 1)), shl((L_FIR_FER2, 1)); -#else tmp_loop = add( add( L_frame, shr( L_frame, 1 ) ), 2 * L_FIR_FER2 ); -#endif // !HARMONIZE_2446_CON_TCX_FX - + FOR( ; i < tmp_loop; i++ ) { Random( &tmpSeed ); @@ -1659,11 +687,7 @@ void con_tcx_ivas_fx( move32(); FOR( j = 11; j > 0; j-- ) { -#ifndef HARMONIZE_2446_CON_TCX_FX - L_tmp2 = L_mac( L_tmp2, noise[( i + ( L_FIR_FER2 - j ) )], hp_filt[sub( L_FIR_FER2, j )] ); -#else L_tmp2 = L_mac( L_tmp2, noise[add( i, ( sub( L_FIR_FER2, j ) ) )], hp_filt[sub( L_FIR_FER2, j )] ); -#endif // !HARMONIZE_2446_CON_TCX_FX } L_tmp2 = Mpy_32_16_1( L_tmp2, st->cummulative_damping /*Q15*/ ); /*Q0, noise_e*/ noise[i] = mac_r( L_tmp2, gain_tmp, noise[i] ); /*Q15, noise_e*/ @@ -1720,11 +744,7 @@ void con_tcx_ivas_fx( { gain32 = Mpy_32_16_1( gain32, 22938 /*0.7f Q15*/ ); /*Q16*/ } -#ifndef HARMONIZE_2446_CON_TCX_FX - L_tmp = L_shl( gain32, 1 ); /*Q16*/ -#else L_tmp = L_shl_sat( gain32, 1 ); /*Q16*/ -#endif // !HARMONIZE_2446_CON_TCX_FX IF( GT_32( L_shl( L_deposit_h( gainCNG ), sub( gainCNG_e, 31 - 16 ) /*Q16*/ ), L_tmp ) ) { @@ -1750,37 +770,16 @@ void con_tcx_ivas_fx( step32 = Mpy_32_16_1( L_tmp /*Q16,-tmp_e*/, getInvFrameLen( L_frame ) /*W16Q21*/ ); /*Q22,-tmp_e*/ step32 = L_shl( step32, sub( 25 - 22, tmp_e ) ); /*Q25*/ -#ifndef HARMONIZE_2446_CON_TCX_FX - pt_exc = noise + shr( L_FIR_FER2, 1 ); -#else pt_exc = noise + L_FIR_FER2 / 2; -#endif // !HARMONIZE_2446_CON_TCX_FX /*gain_inov = 1.0f / (float)sqrt( dot_product( pt_exc, pt_exc, L_frame ) / L_frame + 0.01f );*/ /* normalize energy */ L_tmp = Dot_productSq16HQ( 0, pt_exc /*Q0,15+1*/, L_frame, &tmp_e ) /*Q31,tmp_e+16+16*/; -#ifndef HARMONIZE_2446_CON_TCX_FX - tmp_e = sub( add( tmp_e, shl( noise_e, 1 ) ), 1 ); // actual multiplier! -#else IF( NE_16( st->element_mode, EVS_MONO ) ) { tmp_e = sub( add( tmp_e, shl_sat( noise_e, 1 ) ), 1 ); // actual multiplier! } -#endif // !HARMONIZE_2446_CON_TCX_FX L_tmp = Mpy_32_16_1( L_tmp, getInvFrameLen( L_frame ) /*W16Q21*/ ) /*W32Q37,tmp_e+16+16*/ /*Q5,tmp_e*/; -#ifndef HARMONIZE_2446_CON_TCX_FX - tmp_e = add( tmp_e, 31 - 6 ); /*-->Q31*/ - gain_inov = 0; - move16(); - gain_inov_e = 0; - move16(); - IF( NE_32( L_tmp, 0 ) ) - { - gain_inov = round_fx( ISqrt32( L_tmp, &tmp_e ) ); /*Q15,tmp_e*/ - gain_inov_e = tmp_e; - move16(); - } -#else IF( NE_16( st->element_mode, EVS_MONO ) ) { tmp_e = add( tmp_e, 31 - 6 ); /*-->Q31*/ @@ -1803,8 +802,6 @@ void con_tcx_ivas_fx( move16(); } -#endif // !HARMONIZE_2446_CON_TCX_FX - test(); test(); IF( EQ_16( st->last_good, UNVOICED_CLAS ) && NE_16( st->core_ext_mode, UNVOICED ) ) @@ -1875,11 +872,7 @@ void con_tcx_ivas_fx( ELSE { bufferCopyFx( noise + L_FIR_FER2 / 2, exc, add( L_frame, shr( L_frame, 1 ) ), 0 /*Q_noise*/, noise_e, Q_exc, 0 /*exc_e*/ ); -#ifndef HARMONIZE_2446_CON_TCX_FX - Copy( exc + sub( L_frame, shl( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl( L_subfr, 1 ), shr( L_frame, 1 ) ) ); /*Q_exc*/ -#else Copy( exc + sub( L_frame, shl_sat( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl_sat( L_subfr, 1 ), shr( L_frame, 1 ) ) ); /*Q_exc*/ -#endif // !HARMONIZE_2446_CON_TCX_FX /* copy old_exc as 16kHz for acelp decoding */ IF( EQ_16( st->nbLostCmpt, 1 ) ) @@ -1908,12 +901,6 @@ void con_tcx_ivas_fx( syn = buf + M; /*Q_syn*/ Copy( synth - M, buf, M ); /*Q_syn*/ -#ifndef HARMONIZE_2446_CON_TCX_FX - scf = norm_s( tmp_deemph ); - new_Q = sub( Q_exc, 4 ); // deemph_fx filter gain can be up to 10 (~2^3.32), so 4 bits of headroom are needed to avoid overflow - new_Q = s_max( new_Q, -1 ); - new_Q = s_min( new_Q, scf ); -#else IF( NE_16( st->element_mode, EVS_MONO ) ) { scf = norm_s( tmp_deemph ); @@ -1929,7 +916,6 @@ void con_tcx_ivas_fx( scf = 0; move16(); } -#endif // !HARMONIZE_2446_CON_TCX_FX tmp16 = s_min( new_Q, st->prev_Q_syn ); st->prev_Q_syn = new_Q; @@ -1941,16 +927,6 @@ void con_tcx_ivas_fx( Copy_Scale_sig( buf, mem_syn, M, exp_scale ); /* Q: tmp16 */ -#ifndef HARMONIZE_2446_CON_TCX_FX - if ( GT_16( sub( Q_syn, st->Q_syn_factor ), scf ) ) - { - Q_syn = add( scf, st->Q_syn_factor ); // so that (Q_syn - st->Q_syn_factor) = scf; - } - tmp_deemph = shl( tmp_deemph, sub( Q_syn, st->Q_syn_factor ) ); - - st->Q_syn = Q_syn; - move16(); -#else IF( NE_16( st->element_mode, EVS_MONO ) ) { @@ -1982,7 +958,6 @@ void con_tcx_ivas_fx( st->Q_syn = Q_syn; move16(); } -#endif // !HARMONIZE_2446_CON_TCX_FX /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1: exc*/ /*buf[0;M] Q0: mem_syn*/ @@ -2046,12 +1021,10 @@ void con_tcx_ivas_fx( /* Deemphasis and output synth and ZIR */ deemph_fx( syn, st->preemph_fac, add( L_frame, shr( L_frame, 1 ) ), &tmp_deemph ); -#ifdef HARMONIZE_2446_CON_TCX_FX IF( EQ_16( st->element_mode, EVS_MONO ) ) { bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); /*Q_syn*/ } -#endif // HARMONIZE_2446_CON_TCX_FX lerp( syn + sub( L_frame, shr( L_frame, 1 ) ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); hTcxDec->Q_old_syn_Overl = Q_syn; @@ -2074,24 +1047,6 @@ void con_tcx_ivas_fx( hHQ_core->Q_old_wtda = Q_syn; move16(); -#ifndef HARMONIZE_2446_CON_TCX_FX - scf = add( getScaleFactor16( syn, L_frame ), Q_syn ); - IF( LT_16( scf, 0 ) ) // Only avoid left shift in bufferCopyFX when overflow could occur - { - st->Q_syn_factor = scf; - } - ELSE - { - st->Q_syn_factor = 0; - move16(); - } - bufferCopyFx( syn, synth, L_frame, Q_syn, st->Q_syn_factor, 0, 0 ); - - bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, st->Q_syn_factor, 0, 0 ); - - Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), sub( st->Q_syn_factor, Q_syn ) ); - hTcxDec->Q_syn_OverlFB = st->Q_syn_factor; -#else IF( NE_16( st->element_mode, EVS_MONO ) ) { scf = add( getScaleFactor16( syn, L_frame ), Q_syn ); @@ -2123,7 +1078,6 @@ void con_tcx_ivas_fx( hTcxDec->Q_syn_OverlFB = 0; move16(); } -#endif // !HARMONIZE_2446_CON_TCX_FX /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */ IF( st->hWIDec != NULL ) @@ -2138,11 +1092,6 @@ void con_tcx_ivas_fx( move16(); /* create aliasing and windowing need for transition to TCX10/5 */ -#ifndef HARMONIZE_2446_CON_TCX_FX - Copy( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ) ); - hTcxDec->Q_syn_Overl_TDACFB = Q_syn; - -#else IF( NE_16( st->element_mode, EVS_MONO ) ) { Copy( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ) ); @@ -2153,9 +1102,6 @@ void con_tcx_ivas_fx( bufferCopyFx( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ), Q_syn, 0, -1, 0 ); hTcxDec->Q_syn_Overl_TDACFB = add( st->Q_syn, sub( st->Q_syn, -1 ) ); } -#endif // HARMONIZE_2446_CON_TCX_FX - - move16(); FOR( i = 0; i < W12; i++ ) @@ -2200,9 +1146,6 @@ void con_tcx_ivas_fx( move16(); /* update memory for low band */ -#ifndef HARMONIZE_2446_CON_TCX_FX - st->Q_syn = Q_syn; -#else IF( NE_16( st->element_mode, EVS_MONO ) ) { st->Q_syn = Q_syn; @@ -2212,8 +1155,6 @@ void con_tcx_ivas_fx( Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); /*Q_syn*/ hTcxDec->Q_old_syn_Overl = -1; } -#endif // !HARMONIZE_2446_CON_TCX_FX - move16(); lerp( hTcxDec->syn_OverlFB, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); hTcxDec->Q_syn_Overl = hTcxDec->Q_syn_OverlFB; @@ -2222,14 +1163,10 @@ void con_tcx_ivas_fx( hTcxDec->Q_syn_Overl_TDAC = hTcxDec->Q_syn_Overl_TDACFB; move16(); lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, L_frame ); -#ifndef HARMONIZE_2446_CON_TCX_FX - st->hHQ_core->Q_old_wtda_LB = Q_syn; // st->hHQ_core->Q_old_wtda -#else IF( NE_16( st->element_mode, EVS_MONO ) ) { st->hHQ_core->Q_old_wtda_LB = Q_syn; // st->hHQ_core->Q_old_wtda } -#endif // !HARMONIZE_2446_CON_TCX_FX st->old_enr_LP = Enr_1_Az_fx( A_local, L_SUBFR ); /*Q3*/ move16(); diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 9e22ad6afd2ec951419bb7d81cad148765ac9360..add3a07c325f324e755746fcd5a0cadee4832812 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -315,11 +315,8 @@ ivas_error evs_dec_fx( /*---------------------------------------------------------------------* * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ -#if defined( FIX_BASOP_REMOVE_SYNTH2_FX ) + IF( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1 ) ) != IVAS_ERR_OK ) -#else - IF( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1, &tmp16 ) ) != IVAS_ERR_OK ) -#endif { return error; } diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index a737a4908a3ebcdddb3d3798e940432d1b5be419..97f53dfb6dd89f5f0b898ec9c7a637b198adbbd5 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -93,9 +93,6 @@ void initFdCngDec_fx( hFdCngDec->hFdCngCom->olapBufferAna = hFdCngDec->olapBufferAna; set16_fx( hFdCngDec->olapBufferSynth2, 0, FFTLEN ); hFdCngDec->hFdCngCom->olapBufferSynth2 = hFdCngDec->olapBufferSynth2; -#ifndef FIX_BASOP_REMOVE_SYNTH2_FX - set32_fx( hFdCngDec->hFdCngCom->olapBufferSynth2_fx, 0, FFTLEN ); -#endif /* Set some counters and flags */ @@ -4583,9 +4580,8 @@ void generate_masking_noise_ivas_fx( Word16 *seed = &( hFdCngCom->seed ); Word32 scale_fx; Word16 shift; -#ifdef FIX_BASOP_REMOVE_SYNTH2_FX Word32 olapBufferSynth2_32[FFTLEN]; -#endif + scale_fx = 0x40000000; // 1.0 in Q30 move32(); startBand = hFdCngCom->startBand; /*Q0*/ @@ -4707,13 +4703,9 @@ void generate_masking_noise_ivas_fx( } ELSE { -#ifdef FIX_BASOP_REMOVE_SYNTH2_FX Copy_Scale_sig_16_32_no_sat( hFdCngCom->olapBufferSynth2, olapBufferSynth2_32, FFTLEN, Q7 ); SynthesisSTFT_fx( fftBuffer_fx, maskingNoise_fx, olapBufferSynth2_32, hFdCngCom->olapWinSyn_fx, 0, hFdCngCom, element_mode, nchan_out ); Copy_Scale_sig_32_16( olapBufferSynth2_32, hFdCngCom->olapBufferSynth2, FFTLEN, -Q7 ); -#else - SynthesisSTFT_fx( fftBuffer_fx, maskingNoise_fx, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, 0, hFdCngCom, element_mode, nchan_out ); -#endif } *exp_out = sub( *exp_out, Q9 ); move16(); @@ -4761,12 +4753,7 @@ void generate_stereo_masking_noise_fx( { hFdCngCom = st->hFdCngDec->hFdCngCom; Copy_Scale_sig_16_32_no_sat( hStereoCng->olapBufferSynth22_fx, Ns_fx, shr( hFdCngCom->frameSize, 1 ), sub( Q6, st->Q_syn ) ); /*Q6*/ - -#ifdef FIX_BASOP_REMOVE_SYNTH2_FX - Copy_Scale_sig_16_32_no_sat( hFdCngCom->olapBufferSynth2, Np_fx, shr( hFdCngCom->frameSize, 1 ), 0 ); /*st->Q_syn*/ -#else - Copy32( hFdCngCom->olapBufferSynth2_fx, Np_fx, shr( hFdCngCom->frameSize, 1 ) ); /*st->Q_syn*/ -#endif + Copy_Scale_sig_16_32_no_sat( hFdCngCom->olapBufferSynth2, Np_fx, shr( hFdCngCom->frameSize, 1 ), 0 ); /*st->Q_syn*/ set32_fx( &Np_fx[( hFdCngCom->frameSize / 2 )], 0, shr( hFdCngCom->frameSize, 1 ) ); set32_fx( &Ns_fx[( hFdCngCom->frameSize / 2 )], 0, shr( hFdCngCom->frameSize, 1 ) ); @@ -4988,9 +4975,7 @@ void generate_masking_noise_lb_dirac_fx( Word16 cur_subframe_start_outfs; Word16 cur_subframe_start_cngfs; Word16 slot_size_cng; -#ifdef FIX_BASOP_REMOVE_SYNTH2_FX Word32 olapBufferSynth2_32[FFTLEN]; -#endif WHILE( n_samples_out > 0 ) { @@ -5045,13 +5030,10 @@ void generate_masking_noise_lb_dirac_fx( move32(); /* Perform STFT synthesis */ -#ifdef FIX_BASOP_REMOVE_SYNTH2_FX Copy_Scale_sig_16_32_no_sat( hFdCngCom->olapBufferSynth2, olapBufferSynth2_32, FFTLEN, Q7 ); SynthesisSTFT_dirac_fx( fftBuffer, tdBuffer + n_samples_start, olapBufferSynth2_32, hFdCngCom->olapWinSyn_fx, n_samples_out_loop, hFdCngCom ); Copy_Scale_sig_32_16( olapBufferSynth2_32, hFdCngCom->olapBufferSynth2, FFTLEN, -Q7 ); -#else - SynthesisSTFT_dirac_fx( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, n_samples_out_loop, hFdCngCom ); -#endif + scale_sig32( tdBuffer + n_samples_start, n_samples_out_loop, Q9 ); // Q2 -> Q11 } @@ -5062,13 +5044,9 @@ void generate_masking_noise_lb_dirac_fx( set32_fx( fftBuffer, 0, hFdCngCom->fftlen ); /* Perform STFT synthesis */ -#ifdef FIX_BASOP_REMOVE_SYNTH2_FX Copy_Scale_sig_16_32_no_sat( hFdCngCom->olapBufferSynth2, olapBufferSynth2_32, FFTLEN, Q7 ); SynthesisSTFT_dirac_fx( fftBuffer, tdBuffer + n_samples_start, olapBufferSynth2_32, hFdCngCom->olapWinSyn_fx, n_samples_out_loop, hFdCngCom ); Copy_Scale_sig_32_16( olapBufferSynth2_32, hFdCngCom->olapBufferSynth2, FFTLEN, -Q7 ); -#else - SynthesisSTFT_dirac_fx( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, n_samples_out_loop, hFdCngCom ); -#endif } hFdCngCom->fftBuffer_exp = 31 - 11; move16(); diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c index 917e966d3b8069f273a913ed1ac3ea1c94773a70..f50533b4b5c7f3bf7208cd0c9b1e67fe19ad3354 100644 --- a/lib_dec/gs_dec_fx.c +++ b/lib_dec/gs_dec_fx.c @@ -722,15 +722,9 @@ void gsc_dec_fx( * PVQ decoder *--------------------------------------------------------------------------------------*/ -#ifdef FIX_2467_RENAME_GSC_FUNCTION bands_and_bit_alloc_fx( hGSCDec->cor_strong_limit, hGSCDec->noise_lev, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, max_ener_band, bits_per_bands, &nb_subbands, NULL, NULL, &pvq_len, coder_type, st_fx->bwidth, st_fx->GSC_noisy_speech, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); -#else - bands_and_bit_alloc_ivas_fx( hGSCDec->cor_strong_limit, hGSCDec->noise_lev, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, - max_ener_band, bits_per_bands, &nb_subbands, NULL, NULL, &pvq_len, coder_type, st_fx->bwidth, st_fx->GSC_noisy_speech, - st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); -#endif IF( bit == 0 ) { diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index c4c15c03fc48bc502d4a60ca836e35c5fd17796b..06bdba2d819c13bacdf70e6464197e909c29e757 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -19,10 +19,11 @@ /**********************************************************************/ /* get scalefactor of an Word32 array with condition **************************************************************************/ -static Word16 IGF_getScaleFactor32Cond( /**< out: Q0 | measured headroom in range [0..31], 0 if all x[i] == 0 */ - const Word16 *cond, /**< in: Q0 | array conating the condition */ - const Word32 *x, /**< in: Q31 | array containing 32-bit data */ - const Word16 len_x /**< in: Q0 | length of the array to scan */ +/**< out: Q0 | measured headroom in range [0..31], 0 if all x[i] == 0 */ +static Word16 IGF_getScaleFactor32Cond( + const Word16 *cond, /**< in: Q0 | array conating the condition */ + const Word32 *x, /**< in: Q31 | array containing 32-bit data */ + const Word16 len_x /**< in: Q0 | length of the array to scan */ ) { Word16 i; @@ -32,7 +33,6 @@ static Word16 IGF_getScaleFactor32Cond( /**< ou Word32 x_max; Word32 tmp32; - x_max = 0; // Q31 move32(); x_min = 0; // Q31 @@ -75,116 +75,18 @@ static Word16 IGF_getScaleFactor32Cond( /**< ou return i; } -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/**********************************************************************/ /* -measures TCX noise -**************************************************************************/ -static Word16 IGF_replaceTCXNoise_1( /**< out: Q0 | number of noise bands */ - const Word32 *in, /**< in: Q31 | MDCT spectrum */ - Word16 s_l, /**< in: Q0 | noise headroom */ - const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ - const Word16 start, /**< in: Q0 | start MDCT subband index */ - const Word16 stop, /**< in: Q0 | stop MDCT subband index */ - Word32 *totalNoiseNrg /**< out: | measured noise energy */ -) -{ - Word16 sb; - Word16 tmp16; - Word16 noise; - Word32 nE; - - - tmp16 = 0; - move16(); - noise = 0; - move16(); - s_l = sub( s_l, 5 ); - nE = 0; - move32(); - - FOR( sb = start; sb < stop; sb++ ){ - IF( TCXNoise[sb] ){ - tmp16 = extract_h( L_shl( in[sb], s_l ) ); // Q31 + s_l -} -IF( TCXNoise[sb] ) -{ - nE = L_mac( nE, tmp16, tmp16 ); // Q31 + s_l -} -IF( TCXNoise[sb] ) -{ - noise = add( noise, 1 ); // Q0 -} -} - -*totalNoiseNrg = nE; // Q31 + s_l -move32(); - -return noise; -} - -static Word16 ivas_IGF_replaceTCXNoise_1_fx( /**< out: Q0 | number of noise bands */ - const Word32 *in, /**< in: in_exp | MDCT spectrum */ - Word16 in_exp, /**< in: Q0 | noise headroom */ - const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ - const Word16 start, /**< in: Q0 | start MDCT subband index */ - const Word16 stop, /**< in: Q0 | stop MDCT subband index */ - Word32 *totalNoiseNrg, /**< out: | measured noise energy */ - Word16 *totalNoiseNrg_exp ) -{ - Word16 sb; - Word16 tmp16, shift; - Word16 noise; - Word32 tmp32; - Word64 nE; - - - shift = 2; - move16(); - noise = 0; - move16(); - nE = 0; - move64(); - - *totalNoiseNrg = 0; - move32(); - *totalNoiseNrg_exp = 0; - move16(); - - FOR( sb = start; sb < stop; sb++ ) - { - IF( TCXNoise[sb] ) - { - tmp32 = L_shr( in[sb], shift ); - nE = W_mac_32_32( nE, tmp32, tmp32 ); // 62 - (in_exp + shift + in_exp + shift + 1) - noise = add( noise, 1 ); - } - } - - IF( nE ) - { - tmp16 = W_norm( nE ); - nE = W_shl( nE, tmp16 ); - *totalNoiseNrg = W_extract_h( nE ); - move32(); - *totalNoiseNrg_exp = sub( add( shl( shift, 1 ), shl( in_exp, 1 ) ), tmp16 ); - move16(); - } - - return noise; -} -#else - -static Word16 IGF_replaceTCXNoise_1( /**< out: Q0 | number of noise bands */ - const Word32 *in, /**< in: | MDCT spectrum */ - Word16 in_exp, /**< in: | MDCT spectrum exponent */ - Word16 s_l, /**< in: Q0 | noise headroom (for EVS) */ - const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ - const Word16 start, /**< in: Q0 | start MDCT subband index */ - const Word16 stop, /**< in: Q0 | stop MDCT subband index */ - Word32 *totalNoiseNrg, /**< out: | measured noise energy */ - Word16 *totalNoiseNrg_exp, /**< out: | measured noise energy exponent */ - const Word16 element_mode /**< in: | IVAS element mode type */ +/**< out: Q0 | number of noise bands */ +static Word16 IGF_replaceTCXNoise_1( + const Word32 *in, /**< in: | MDCT spectrum */ + Word16 in_exp, /**< in: | MDCT spectrum exponent */ + Word16 s_l, /**< in: Q0 | noise headroom (for EVS) */ + const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ + const Word16 start, /**< in: Q0 | start MDCT subband index */ + const Word16 stop, /**< in: Q0 | stop MDCT subband index */ + Word32 *totalNoiseNrg, /**< out: | measured noise energy */ + Word16 *totalNoiseNrg_exp, /**< out: | measured noise energy exponent */ + const Word16 element_mode /**< in: | IVAS element mode type */ ) { Word16 sb, tmp16, shift, noise; @@ -255,24 +157,24 @@ static Word16 IGF_replaceTCXNoise_1( /**< out: Q0 | n return noise; } -#endif -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + /**********************************************************************/ /* replaces TCX noise **************************************************************************/ -static void IGF_replaceTCXNoise_2( Word32 *in, /**< in/out: Q31 | MDCT spectrum */ - Word16 *in_exp_arr, /**< in/out: Q15 | MDCT spectrum exponent array */ - const Word16 in_exp, /**< in: | MDCT spectrum base exponent (used if in_exp_arr==NULL) */ - const Word16 s_l, /**< in: Q0 | noise headroom */ - const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ - const Word16 start, /**< in: Q0 | start MDCT subband index */ - const Word16 stop, /**< in: Q0 | stop MDCT subband index */ - Word32 totalNoiseNrg, /**< in: | measured noise energy */ - Word16 totalNoiseNrg_e, /**< in: | measured noise energy exp */ - const Word16 n_noise_bands, /**< in: | number of noise bands in src */ - Word16 *nfSeed, /**< in: | random generator noise seed */ - const Word16 element_mode /**< in: | IVAS element mode type */ +static void IGF_replaceTCXNoise_2( + Word32 *in, /**< in/out: Q31 | MDCT spectrum */ + Word16 *in_exp_arr, /**< in/out: Q15 | MDCT spectrum exponent array */ + const Word16 in_exp, /**< in: | MDCT spectrum base exponent (used if in_exp_arr==NULL) */ + const Word16 s_l, /**< in: Q0 | noise headroom */ + const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ + const Word16 start, /**< in: Q0 | start MDCT subband index */ + const Word16 stop, /**< in: Q0 | stop MDCT subband index */ + Word32 totalNoiseNrg, /**< in: | measured noise energy */ + Word16 totalNoiseNrg_e, /**< in: | measured noise energy exp */ + const Word16 n_noise_bands, /**< in: | number of noise bands in src */ + Word16 *nfSeed, /**< in: | random generator noise seed */ + const Word16 element_mode /**< in: | IVAS element mode type */ ) { Word16 g, n_noise_bands_tile, noise_band_ratio, sb, tmp, tmp_e, val; @@ -394,265 +296,16 @@ static void IGF_replaceTCXNoise_2( Word32 *in, /**< in } } } -#else -/**********************************************************************/ /* -replaces TCX noise -**************************************************************************/ -static void IGF_replaceTCXNoise_2( Word32 *in, /**< in/out: Q31 | MDCT spectrum */ - const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ - const Word16 start, /**< in: Q0 | start MDCT subband index */ - const Word16 stop, /**< in: Q0 | stop MDCT subband index */ - Word32 totalNoiseNrg, /**< in: | measured noise energy */ - const Word16 s_l, /**< in: Q0 | noise headroom */ - Word16 *nfSeed /**< in: | random generator noise seed */ -) -{ - Word16 sb; - Word16 g; - Word16 val; - Word32 rE; - Word32 L_tmp; - - - val = 0; - move16(); - rE = 0; - move32(); - - FOR( sb = start; sb < stop; sb++ ) - { - IF( TCXNoise[sb] ) - { - val = Random( nfSeed ); // Q0 - } - IF( TCXNoise[sb] ) - { - in[sb] = L_deposit_l( val ); // Q0 - move32(); - } - IF( TCXNoise[sb] ) - { - val = shr( val, 5 ); // Q-5 - } - IF( TCXNoise[sb] ) - { - rE = L_mac( rE, val, val ); // Q-9 - } - } - - totalNoiseNrg = L_shr( totalNoiseNrg, 1 ); // Q-9 - - - /* make sure that rE is never 0 */ - if ( rE == 0 ) - { - rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ // Q-9 - } - - /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ - if ( totalNoiseNrg == 0 ) - { - rE = L_max( rE, 0x00010000 ); // Q-9 - } - - /* make sure that rE is never smaller than totalNoiseNrg */ - L_tmp = L_sub( rE, totalNoiseNrg ); // Q-9 - if ( L_tmp < 0 ) - { - rE = totalNoiseNrg; /* save move32() -> use L_add(x, 0) = x; */ // Q-9 - move32(); - } - - - g = getSqrtWord32( L_mult( divide3232( totalNoiseNrg, rE ), 8192 /*1.0f / 4.0f Q15*/ ) ); // ((Q15 + Q15 + Q1) / 2) -> Q15 - g = shl_sat( g, 1 ); // Q16 - FOR( sb = start; sb < stop; sb++ ) - { - IF( TCXNoise[sb] ) - { - in[sb] = L_shr( L_mult( extract_l( in[sb] ), g ), s_l ); // Q15 + Q16 + Q1 - s_l - move32(); - } - } -} /**********************************************************************/ /* -replaces TCX noise with noise band ratio (for IVAS) +reads whitening levels **************************************************************************/ -static void IGF_replaceTCXNoise_2_new_ivas( Word32 *in, /**< in/out: | MDCT spectrum */ - const Word16 in_e, /**< in: | MDCT spectrum exp */ - const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ - const Word16 start, /**< in: Q0 | start MDCT subband index */ - const Word16 stop, /**< in: Q0 | stop MDCT subband index */ - Word32 totalNoiseNrg, /**< in: | measured noise energy */ - Word16 totalNoiseNrg_e, /**< in: | measured noise energy exp */ - const Word16 n_noise_bands, /**< in: | number of noise bands in src */ - Word16 *nfSeed /**< in: | random generator noise seed */ -) -{ - Word16 sb; - Word16 g; - Word16 val; - Word32 rE; - Word32 L_tmp; - Word16 n_noise_bands_tile; - Word16 noise_band_ratio; - - n_noise_bands_tile = 0; - move16(); - val = 0; - move16(); - rE = 0; - move32(); - - FOR( sb = start; sb < stop; sb++ ) - { - IF( TCXNoise[sb] ) - { - val = Random( nfSeed ); // Q0 - move16(); - in[sb] = L_deposit_l( val ); // Q0 - move32(); - val = shr( val, 5 ); // Q-5 - rE = L_mac( rE, val, val ); // Q-9 - n_noise_bands_tile = add( n_noise_bands_tile, 1 ); - } - } - - - IF( n_noise_bands_tile != 0 ) - { - noise_band_ratio = div_s( n_noise_bands_tile, n_noise_bands ); // Q15 - - /* make sure that rE is never 0 */ - if ( rE == 0 ) - { - rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ // Q31 - totalNoiseNrg_e - } - - /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ - if ( totalNoiseNrg == 0 ) - { - rE = L_max( rE, 0x00010000 ); // Q-9 - } - - Word16 tmp, tmp_e; - L_tmp = Mpy_32_16_1( totalNoiseNrg, noise_band_ratio ); // Q31 - totalNoiseNrg_e - tmp = BASOP_Util_Divide3232_Scale( L_tmp, rE, &tmp_e ); - tmp_e = add( tmp_e, sub( totalNoiseNrg_e, 40 ) ); - g = Sqrt16( tmp, &tmp_e ); - - FOR( sb = start; sb < stop; sb++ ) - { - IF( TCXNoise[sb] ) - { - Word16 nrm = norm_l( in[sb] ); - in[sb] = L_shl( in[sb], nrm ); // exp: 31 - tmp - move32(); - in[sb] = Mpy_32_16_1( in[sb], g ); // exp: 31 - tmp + tmp_e - move32(); - /* To handle corner cases */ - in[sb] = L_shr_sat( in[sb], sub( in_e, sub( add( 31, tmp_e ), nrm ) ) ); // Making the exponent same as original - move32(); - } - } - } -} - -/**********************************************************************/ /* - replaces TCX noise with noise band ratio (for IVAS) - **************************************************************************/ -static void IGF_replaceTCXNoise_2_new_ivas_with_var_shift( Word32 *in, /**< in/out: | MDCT spectrum */ - Word16 *in_e_arr, /**< in/out: | MDCT spectrum exp */ - const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ - const Word16 start, /**< in: Q0 | start MDCT subband index */ - const Word16 stop, /**< in: Q0 | stop MDCT subband index */ - Word32 totalNoiseNrg, /**< in: | measured noise energy */ - Word16 totalNoiseNrg_e, /**< in: | measured noise energy exp */ - const Word16 n_noise_bands, /**< in: Q0 | number of noise bands in src */ - Word16 *nfSeed /**< in: Q0 | random generator noise seed */ -) -{ - Word16 sb; - Word16 g; - Word16 val; - Word32 rE; - Word32 L_tmp; - Word16 n_noise_bands_tile; - Word16 noise_band_ratio; - - n_noise_bands_tile = 0; - move16(); - val = 0; - move16(); - rE = 0; - move32(); - - FOR( sb = start; sb < stop; sb++ ) - { - IF( TCXNoise[sb] ) - { - val = Random( nfSeed ); // Q0 - move16(); - in[sb] = L_deposit_l( val ); // Q0 - move32(); - in_e_arr[sb] = 31; - move16(); - val = shr( val, 5 ); // Q-5 - rE = L_mac( rE, val, val ); // Q-9 - n_noise_bands_tile = add( n_noise_bands_tile, 1 ); - } - } - - - IF( n_noise_bands_tile != 0 ) - { - noise_band_ratio = div_s( n_noise_bands_tile, n_noise_bands ); // Q15 - - /* make sure that rE is never 0 */ - if ( rE == 0 ) - { - rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ // Q31 - totalNoiseNrg_e - } - - /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ - if ( totalNoiseNrg == 0 ) - { - rE = L_max( rE, 0x00010000 ); // Q-9 - } - - Word16 tmp, tmp_e; - L_tmp = Mpy_32_16_1( totalNoiseNrg, noise_band_ratio ); // Q31 - totalNoiseNrg_e - tmp = BASOP_Util_Divide3232_Scale( L_tmp, rE, &tmp_e ); - tmp_e = add( tmp_e, sub( totalNoiseNrg_e, 40 ) ); - g = Sqrt16( tmp, &tmp_e ); - - FOR( sb = start; sb < stop; sb++ ) - { - Word16 nrm = norm_l( in[sb] ); - in[sb] = L_shl( in[sb], nrm ); - move32(); - in_e_arr[sb] = sub( in_e_arr[sb], nrm ); - move16(); - IF( TCXNoise[sb] ) - { - in[sb] = Mpy_32_16_1( in[sb], g ); - move32(); - in_e_arr[sb] = add( in_e_arr[sb], tmp_e ); - move16(); - } - } - } -} -#endif - -/**********************************************************************/ /* - reads whitening levels - **************************************************************************/ -static void IGF_decode_whitening_level( Decoder_State *st, /**< in: | decoder state */ - IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | instance handle of IGF Deccoder */ - const Word16 p /**< in: Q0 | tile index, p = [0, 3] */ +/**< in: | decoder state */ +static void IGF_decode_whitening_level( + Decoder_State *st, + IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | instance handle of IGF Deccoder */ + const Word16 p /**< in: Q0 | tile index, p = [0, 3] */ ) { Word16 tmp; @@ -679,11 +332,12 @@ static void IGF_decode_whitening_level( Decoder_State *st, } } -/**********************************************************************/ /* - reads flattening trigger - **************************************************************************/ -static void IGF_decode_temp_flattening_trigger( Decoder_State *st, /**< in: | decoder state */ - IGF_DEC_INSTANCE_HANDLE hInstance /**< in: | instance handle of IGF Deccoder */ +/**********************************************************************/ /* +reads flattening trigger +**************************************************************************/ +static void IGF_decode_temp_flattening_trigger( + Decoder_State *st, /**< in: | decoder state */ + IGF_DEC_INSTANCE_HANDLE hInstance /**< in: | instance handle of IGF Deccoder */ ) { hInstance->flatteningTrigger = get_next_indice_fx( st, 1 ); // Q0 @@ -693,10 +347,11 @@ static void IGF_decode_temp_flattening_trigger( Decoder_State *st, /**********************************************************************/ /* set power spectrum values to zero, needed for energy calculation **************************************************************************/ -static void IGF_setLinesToZero( const Word16 startLine, /**< in: Q0 | start MDCT subband index */ - const Word16 stopLine, /**< in: Q0 | stop MDCT subband index */ - const Word32 *pSpectralData, /**< in: | original MDCT spectrum */ - Word32 *pPowerSpecIGF /**< in/out: | prepared IGF energy spectrum */ +static void IGF_setLinesToZero( + const Word16 startLine, /**< in: Q0 | start MDCT subband index */ + const Word16 stopLine, /**< in: Q0 | stop MDCT subband index */ + const Word32 *pSpectralData, /**< in: | original MDCT spectrum */ + Word32 *pPowerSpecIGF /**< in/out: | prepared IGF energy spectrum */ ) { Word16 i; @@ -716,10 +371,11 @@ static void IGF_setLinesToZero( const Word16 startLine, /**< in /**********************************************************************/ /* Convert igfSpectrum fixed point values with exponent per index to per tile. **************************************************************************/ -static void IGF_convert_exponent_per_idx_to_per_tile( H_IGF_GRID hGrid, - Word32 *igfSpec, - Word16 *igfSpec_e_per_idx, - Word16 *igfSpec_e_per_tile ) +static void IGF_convert_exponent_per_idx_to_per_tile( + H_IGF_GRID hGrid, + Word32 *igfSpec, + Word16 *igfSpec_e_per_idx, + Word16 *igfSpec_e_per_tile ) { Word16 i; Word16 j; @@ -746,18 +402,20 @@ static void IGF_convert_exponent_per_idx_to_per_tile( H_IGF_GRID hGrid, } } -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS + /**********************************************************************/ /* prepare IGF spectrum **************************************************************************/ -static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 *TCXNoise, /**< in: Q0 | TCX noise vector */ - Word32 *igf_spec, /**< in: Q31 | prepared IGF spectrum */ - Word16 *igf_spec_e, /**< in: | array exponents of igf_spec, one exponent per tile */ - const Word32 *src_spec, /**< in: | source spectrum */ - const Word16 src_spec_e, /**< in: | exponent of src_spec, whitening off */ - const Word16 specMed_e /**< in: | exponent of medium flattening level */ +static void IGF_prep( + IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ + const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ + const Word16 *TCXNoise, /**< in: Q0 | TCX noise vector */ + Word32 *igf_spec, /**< in/out: | prepared IGF spectrum */ + Word16 *igf_spec_e, /**< in/out: | array exponents of igf_spec, one exponent per tile */ + Word32 *src_spec, /**< in/out: | source spectrum */ + const Word16 src_spec_e, /**< in: | exponent of src_spec, whitening off */ + const Word16 specMed_e, /**< in: | exponent of medium flattening level */ + const Word16 element_mode /**< in: | element mode */ ) { H_IGF_GRID hGrid; @@ -769,14 +427,14 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in Word16 n_noise_bands; Word16 n_noise_bands_off; Word16 strt_cpy; - Word16 startLine; Word16 minSrcSubband; Word16 tile_idx; Word32 totalNoiseNrg; Word32 totalNoiseNrg_off; + Word16 totalNoiseNrg_exp; + Word16 totalNoiseNrg_off_exp; const Word32 *sel_spec; - /* initialize variables */ hInfo = &hPrivateData->igfInfo; hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; @@ -788,9 +446,11 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in move32(); totalNoiseNrg_off = hPrivateData->totalNoiseNrg_off; move32(); - nTiles = hGrid->nTiles; + totalNoiseNrg_exp = hPrivateData->totalNoiseNrg_exp; + move16(); + totalNoiseNrg_off_exp = hPrivateData->totalNoiseNrg_off_exp; move16(); - startLine = hGrid->startLine; + nTiles = hGrid->nTiles; move16(); minSrcSubband = hGrid->minSrcSubband; move16(); @@ -799,9 +459,22 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( tile_idx = 0; tile_idx < nTiles; tile_idx++ ) { + Word16 tile_width, stop; + strt_cpy = hGrid->sbWrap[tile_idx]; move16(); + IF( element_mode > EVS_MONO ) + { + tile_width = sub( hGrid->swb_offset[hGrid->sfbWrap[tile_idx + 1]], hGrid->swb_offset[hGrid->sfbWrap[tile_idx]] ); // Q0 + stop = add( strt_cpy, tile_width ); // Q0 + } + ELSE + { + stop = hGrid->startLine; // Q0 + move16(); + } + /* strong whitening detected */ IF( EQ_16( IGF_WHITENING_STRONG, hPrivateData->currWhiteningLevel[tile_idx] ) ) { @@ -809,18 +482,18 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in abs_sum = 0; move32(); - FOR( i = strt_cpy; i < hGrid->startLine; i++ ) + FOR( i = strt_cpy; i < stop; i++ ) { - abs_sum = L_add( abs_sum, L_abs( src_spec[i] ) ); // Q31 - src_spec_e + abs_sum = L_add_sat( abs_sum, L_abs( src_spec[i] ) ); /* saturation since it just checks if abs_sum is greater than zero*/ // Q31 - src_spec_e } /* fill igf_spec with random noise */ - tb = hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]; + tb = hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]; // Q0 move16(); IF( abs_sum != 0 ) { - FOR( i = strt_cpy; i < startLine; i++ ) + FOR( i = strt_cpy; i < stop; i++ ) { igf_spec[tb++] = L_deposit_l( Random( hInfo->nfSeed ) ); /* 31Q0, fill LSBs */ // Q0 move32(); @@ -828,7 +501,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in } ELSE { - FOR( i = strt_cpy; i < startLine; i++ ) + FOR( i = strt_cpy; i < stop; i++ ) { igf_spec[tb++] = 0; // Q0 move32(); @@ -846,14 +519,19 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { IF( n_noise_bands != 0 ) { + Word16 start = ( EQ_16( element_mode, EVS_MONO ) ? minSrcSubband : strt_cpy ); IGF_replaceTCXNoise_2( igf_spec, + NULL, + specMed_e, + hPrivateData->headroom_TCX_noise_white, TCXNoise, - - minSrcSubband, - startLine, + start, + stop, totalNoiseNrg, - hPrivateData->headroom_TCX_noise_white, - hInfo->nfSeed ); + totalNoiseNrg_exp, + hPrivateData->n_noise_bands, + hInfo->nfSeed, + element_mode ); } /* selected source spectrum is igf_spec, igf_spec contains the whitened signal in the core region */ @@ -867,237 +545,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* off whitening detectded */ ELSE { - IF( n_noise_bands_off != 0 ) - { - IGF_replaceTCXNoise_2( hPrivateData->pSpecFlat, - TCXNoise, - minSrcSubband, - startLine, - totalNoiseNrg_off, - hPrivateData->headroom_TCX_noise, - hInfo->nfSeed ); - } - /* selected source spectrum is pSpecFlat, pSpecFlat contains the signal before the LPC reshaping */ - sel_spec = src_spec; - move16(); - - /* set exponent of the current tile */ - igf_spec_e[tile_idx] = src_spec_e; - move16(); - } - /* generate the raw IGF spectrum out if the selected spectrum */ - FOR( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ ) - { - FOR( tb = hGrid->swb_offset[sfb]; tb < hGrid->swb_offset[sfb + 1]; tb++ ) - { - igf_spec[tb] = sel_spec[strt_cpy]; // Q31 - igf_spec_e - move32(); - strt_cpy = add( strt_cpy, 1 ); - } - } - } - } -} - -#endif - -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/**********************************************************************/ /* -prepare IGF spectrum -**************************************************************************/ -static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 *TCXNoise, /**< in: Q0 | TCX noise vector */ - Word32 *igf_spec, /**< in/out: | prepared IGF spectrum */ - Word16 *igf_spec_e, /**< in/out: | array exponents of igf_spec, one exponent per tile */ - Word32 *src_spec, /**< in/out: | source spectrum */ - const Word16 src_spec_e, /**< in: | exponent of src_spec, whitening off */ - const Word16 specMed_e, /**< in: | exponent of medium flattening level */ - const Word16 element_mode /**< in: | element mode */ -) -#else -/**********************************************************************/ /* -prepare IGF spectrum (for IVAS) -**************************************************************************/ -static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 *TCXNoise, /**< in: Q0 | TCX noise vector */ - Word32 *igf_spec, /**< in/out: | prepared IGF spectrum */ - Word16 *igf_spec_e, /**< in/out: | array exponents of igf_spec, one exponent per tile */ - Word32 *src_spec, /**< in/out: | source spectrum */ - const Word16 src_spec_e, /**< in: | exponent of src_spec, whitening off */ - const Word16 specMed_e, /**< in: | exponent of medium flattening level */ - const Word16 element_mode /**< in: | element mode */ -) -#endif -{ - H_IGF_GRID hGrid; - H_IGF_INFO hInfo; - Word16 i; - Word16 tb; - Word16 sfb; - Word16 nTiles; - Word16 n_noise_bands; - Word16 n_noise_bands_off; - Word16 strt_cpy; -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS - Word16 startLine; -#endif - Word16 minSrcSubband; - Word16 tile_idx; - Word32 totalNoiseNrg; - Word32 totalNoiseNrg_off; - Word16 totalNoiseNrg_exp; - Word16 totalNoiseNrg_off_exp; - const Word32 *sel_spec; - - /* initialize variables */ - hInfo = &hPrivateData->igfInfo; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - n_noise_bands = hPrivateData->n_noise_bands; - move16(); - n_noise_bands_off = hPrivateData->n_noise_bands_off; - move16(); - totalNoiseNrg = hPrivateData->totalNoiseNrg; - move32(); - totalNoiseNrg_off = hPrivateData->totalNoiseNrg_off; - move32(); - totalNoiseNrg_exp = hPrivateData->totalNoiseNrg_exp; - move16(); - totalNoiseNrg_off_exp = hPrivateData->totalNoiseNrg_off_exp; - move16(); - nTiles = hGrid->nTiles; - move16(); -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS - startLine = hGrid->startLine; - move16(); -#endif - minSrcSubband = hGrid->minSrcSubband; - move16(); - tile_idx = 0; - move16(); - - FOR( tile_idx = 0; tile_idx < nTiles; tile_idx++ ) - { - Word16 tile_width, stop; - - strt_cpy = hGrid->sbWrap[tile_idx]; - move16(); - - IF( element_mode > EVS_MONO ) - { - tile_width = sub( hGrid->swb_offset[hGrid->sfbWrap[tile_idx + 1]], hGrid->swb_offset[hGrid->sfbWrap[tile_idx]] ); // Q0 - stop = add( strt_cpy, tile_width ); // Q0 - } - ELSE - { - stop = hGrid->startLine; // Q0 - move16(); - } - - /* strong whitening detected */ - IF( EQ_16( IGF_WHITENING_STRONG, hPrivateData->currWhiteningLevel[tile_idx] ) ) - { - Word32 abs_sum; - abs_sum = 0; - move32(); - - FOR( i = strt_cpy; i < stop; i++ ) - { - abs_sum = L_add_sat( abs_sum, L_abs( src_spec[i] ) ); /* saturation since it just checks if abs_sum is greater than zero*/ // Q31 - src_spec_e - } - - /* fill igf_spec with random noise */ - tb = hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]; // Q0 - move16(); - - IF( abs_sum != 0 ) - { - FOR( i = strt_cpy; i < stop; i++ ) - { - igf_spec[tb++] = L_deposit_l( Random( hInfo->nfSeed ) ); /* 31Q0, fill LSBs */ // Q0 - move32(); - } - } - ELSE - { - FOR( i = strt_cpy; i < stop; i++ ) - { - igf_spec[tb++] = 0; // Q0 - move32(); - } - } - - /* set exponent of the current tile, random noise is 31Q0 */ - igf_spec_e[tile_idx] = 31; - move16(); - } - ELSE - { - /* medium whitening detected */ - IF( EQ_16( IGF_WHITENING_MID, hPrivateData->currWhiteningLevel[tile_idx] ) ) - { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - IF( n_noise_bands != 0 ) - { - Word16 start = ( EQ_16( element_mode, EVS_MONO ) ? minSrcSubband : strt_cpy ); - IGF_replaceTCXNoise_2( igf_spec, - NULL, - specMed_e, - hPrivateData->headroom_TCX_noise_white, - TCXNoise, - start, - stop, - totalNoiseNrg, - totalNoiseNrg_exp, - hPrivateData->n_noise_bands, - hInfo->nfSeed, - element_mode ); - } -#else - IF( element_mode > EVS_MONO ) - { - IF( n_noise_bands != 0 ) - { - IGF_replaceTCXNoise_2_new_ivas( igf_spec, - specMed_e, - TCXNoise, - strt_cpy, - stop, - totalNoiseNrg, - totalNoiseNrg_exp, - hPrivateData->n_noise_bands, - hInfo->nfSeed ); - } - } - ELSE - { - IF( n_noise_bands != 0 ) - { - IGF_replaceTCXNoise_2( igf_spec, - TCXNoise, - minSrcSubband, - startLine, - totalNoiseNrg, - hPrivateData->headroom_TCX_noise_white, - hInfo->nfSeed ); - } - } -#endif - - /* selected source spectrum is igf_spec, igf_spec contains the whitened signal in the core region */ - sel_spec = igf_spec; - move16(); - - /* set exponent of the current tile */ - igf_spec_e[tile_idx] = specMed_e; - move16(); - } - /* off whitening detectded */ - ELSE - { - -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF( n_noise_bands_off != 0 ) { Word16 start = ( EQ_16( element_mode, EVS_MONO ) ? minSrcSubband : strt_cpy ); @@ -1114,36 +562,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in hInfo->nfSeed, element_mode ); } -#else - IF( GT_16( element_mode, EVS_MONO ) ) - { - IF( n_noise_bands_off != 0 ) - { - IGF_replaceTCXNoise_2_new_ivas( src_spec, - src_spec_e, - TCXNoise, - strt_cpy, - stop, - totalNoiseNrg_off, - totalNoiseNrg_off_exp, - hPrivateData->n_noise_bands_off, - hInfo->nfSeed ); - } - } - ELSE - { - IF( n_noise_bands_off != 0 ) - { - IGF_replaceTCXNoise_2( src_spec, - TCXNoise, - minSrcSubband, - startLine, - totalNoiseNrg_off, - hPrivateData->headroom_TCX_noise, - hInfo->nfSeed ); - } - } -#endif + /* selected source spectrum is pSpecFlat, pSpecFlat contains the signal before the LPC reshaping */ sel_spec = src_spec; move16(); @@ -1232,7 +651,6 @@ static void IGF_prepStereo( { IF( hPrivateDataL->n_noise_bands ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGF_replaceTCXNoise_2( igf_specL_fx, igf_specL_e_arr, 0, @@ -1245,17 +663,6 @@ static void IGF_prepStereo( hPrivateDataL->n_noise_bands, hInfoL->nfSeed, IVAS_CPE_MDCT ); -#else - IGF_replaceTCXNoise_2_new_ivas_with_var_shift( igf_specL_fx, - igf_specL_e_arr, - TCXNoiseL, - strt_cpy, - stop, - hPrivateDataL->totalNoiseNrg, - hPrivateDataL->totalNoiseNrg_exp, - hPrivateDataL->n_noise_bands, - hInfoL->nfSeed ); -#endif } selectionL = 0; move16(); @@ -1264,7 +671,6 @@ static void IGF_prepStereo( { IF( hPrivateDataL->n_noise_bands_off ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGF_replaceTCXNoise_2( src_specL_fx, NULL, src_specL_e, @@ -1277,17 +683,6 @@ static void IGF_prepStereo( hPrivateDataL->n_noise_bands_off, hInfoL->nfSeed, IVAS_CPE_MDCT ); -#else - IGF_replaceTCXNoise_2_new_ivas( src_specL_fx, - src_specL_e, - TCXNoiseL, - strt_cpy, - stop, - hPrivateDataL->totalNoiseNrg_off, - hPrivateDataL->totalNoiseNrg_off_exp, - hPrivateDataL->n_noise_bands_off, - hInfoL->nfSeed ); -#endif } selectionL = 1; move16(); @@ -1297,7 +692,6 @@ static void IGF_prepStereo( { IF( hPrivateDataR->n_noise_bands ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGF_replaceTCXNoise_2( igf_specR_fx, igf_specR_e_arr, 0, @@ -1310,17 +704,6 @@ static void IGF_prepStereo( hPrivateDataR->n_noise_bands, hInfoR->nfSeed, IVAS_CPE_MDCT ); -#else - IGF_replaceTCXNoise_2_new_ivas_with_var_shift( igf_specR_fx, - igf_specR_e_arr, - TCXNoiseR, - strt_cpy, - stop, - hPrivateDataR->totalNoiseNrg, - hPrivateDataR->totalNoiseNrg_exp, - hPrivateDataR->n_noise_bands, - hInfoR->nfSeed ); -#endif } selectionR = 0; move16(); @@ -1329,7 +712,6 @@ static void IGF_prepStereo( { IF( hPrivateDataR->n_noise_bands_off ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGF_replaceTCXNoise_2( src_specR_fx, NULL, src_specR_e, @@ -1342,17 +724,6 @@ static void IGF_prepStereo( hPrivateDataR->n_noise_bands_off, hInfoR->nfSeed, IVAS_CPE_MDCT ); -#else - IGF_replaceTCXNoise_2_new_ivas( src_specR_fx, - src_specR_e, - TCXNoiseR, - strt_cpy, - stop, - hPrivateDataR->totalNoiseNrg_off, - hPrivateDataR->totalNoiseNrg_off_exp, - hPrivateDataR->n_noise_bands_off, - hInfoR->nfSeed ); -#endif } selectionR = 1; move16(); @@ -1457,7 +828,6 @@ static void IGF_prepStereo( { IF( hPrivateDataL->n_noise_bands ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGF_replaceTCXNoise_2( igf_specL_fx, igf_specL_e_arr, 0, @@ -1470,17 +840,6 @@ static void IGF_prepStereo( hPrivateDataL->n_noise_bands, hInfoL->nfSeed, IVAS_CPE_MDCT ); -#else - IGF_replaceTCXNoise_2_new_ivas_with_var_shift( igf_specL_fx, - igf_specL_e_arr, - TCXNoiseL, - strt_cpy, - stop, - hPrivateDataL->totalNoiseNrg, - hPrivateDataL->totalNoiseNrg_exp, - hPrivateDataL->n_noise_bands, - hInfoL->nfSeed ); -#endif } selectionL = 0; move16(); @@ -1489,7 +848,6 @@ static void IGF_prepStereo( { IF( hPrivateDataL->n_noise_bands_off ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGF_replaceTCXNoise_2( src_specL_fx, NULL, src_specL_e, @@ -1502,17 +860,6 @@ static void IGF_prepStereo( hPrivateDataL->n_noise_bands_off, hInfoL->nfSeed, IVAS_CPE_MDCT ); -#else - IGF_replaceTCXNoise_2_new_ivas( src_specL_fx, - src_specL_e, - TCXNoiseL, - strt_cpy, - stop, - hPrivateDataL->totalNoiseNrg_off, - hPrivateDataL->totalNoiseNrg_off_exp, - hPrivateDataL->n_noise_bands_off, - hInfoL->nfSeed ); -#endif } selectionL = 1; move16(); @@ -1522,7 +869,6 @@ static void IGF_prepStereo( { IF( hPrivateDataR->n_noise_bands ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGF_replaceTCXNoise_2( igf_specR_fx, igf_specR_e_arr, 0, @@ -1535,17 +881,6 @@ static void IGF_prepStereo( hPrivateDataR->n_noise_bands, hInfoR->nfSeed, IVAS_CPE_MDCT ); -#else - IGF_replaceTCXNoise_2_new_ivas_with_var_shift( igf_specR_fx, - igf_specR_e_arr, - TCXNoiseR, - strt_cpy, - stop, - hPrivateDataR->totalNoiseNrg, - hPrivateDataR->totalNoiseNrg_exp, - hPrivateDataR->n_noise_bands, - hInfoR->nfSeed ); -#endif } selectionR = 0; move16(); @@ -1554,7 +889,6 @@ static void IGF_prepStereo( { IF( hPrivateDataR->n_noise_bands_off ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGF_replaceTCXNoise_2( src_specR_fx, NULL, src_specR_e, @@ -1567,17 +901,6 @@ static void IGF_prepStereo( hPrivateDataR->n_noise_bands_off, hInfoR->nfSeed, IVAS_CPE_MDCT ); -#else - IGF_replaceTCXNoise_2_new_ivas( src_specR_fx, - src_specR_e, - TCXNoiseR, - strt_cpy, - stop, - hPrivateDataR->totalNoiseNrg_off, - hPrivateDataR->totalNoiseNrg_off_exp, - hPrivateDataR->n_noise_bands_off, - hInfoR->nfSeed ); -#endif } selectionR = 1; move16(); @@ -1616,925 +939,151 @@ static void IGF_prepStereo( move16(); } - IF( ( coreMsMask[tb] == 0 ) ) - { - IF( EQ_16( coreMsMask[strt_cpy], 0 ) ) /* LR->LR */ - { - igf_specR_fx[tb] = selR; - move32(); - igf_specR_e_arr[tb] = selR_e; - move16(); - } - ELSE /* MS/DR -> LR */ - { - tmpL = Mpy_32_32( selL, c_fx ); // Q31 - selL_e - tmpR = Mpy_32_32( selR, c_fx ); // Q31 - selR_e - igf_specR_fx[tb] = BASOP_Util_Add_Mant32Exp( tmpL, selL_e, L_negate( tmpR ), selR_e, &tmp_e ); - move32(); - igf_specR_e_arr[tb] = tmp_e; - move16(); - } - } - ELSE - { - IF( EQ_16( coreMsMask[strt_cpy], 0 ) ) /* LR->MS/DR */ - { - tmpL = Mpy_32_32( selL, c_fx ); // Q31 - selL_e - tmpR = Mpy_32_32( selR, c_fx ); // Q31 - selR_e - igf_specR_fx[tb] = BASOP_Util_Add_Mant32Exp( tmpL, selL_e, L_negate( tmpR ), selR_e, &tmp_e ); - move32(); - igf_specR_e_arr[tb] = tmp_e; - move16(); - } - ELSE /* MS/DR -> MS/DR */ - { - igf_specR_fx[tb] = selR; - move32(); - igf_specR_e_arr[tb] = selR_e; - move16(); - } - } - strt_cpy = add( strt_cpy, 1 ); - } - } - } - } - - return; -} - -/**********************************************************************/ /* -calculates IGF energies -**************************************************************************/ -static void IGF_calc( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word32 *spectrum, /**< in: Q31 | MDCT spectrum */ - const Word16 spectrum_e, /**< in: | exponent of pSpectralData */ - Word32 *igf_spec, /**< in: Q31 | prepared IGF spectrum */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - Word16 *igf_spec_e, /**< in: | array exponents of igf_spec, one exponent per tile */ - const Word16 element_mode /**< in: | IVAS element mode type */ -#else - Word16 *igf_spec_e /**< in: | array exponents of igf_spec, one exponent per tile */ -#endif -) -{ - H_IGF_GRID hGrid; - Word16 i; - Word32 *igf_pN; /* Q31 | processed energy */ - Word16 *igf_pN_e; /* | exponents of igf_pN, one for each entry of igf_pN */ - Word32 *igf_sN; /* Q31 | survived energy */ - Word16 *igf_sN_e; /* | exponents of igf_sN, one for each entry of igf_sN */ - Word32 squaredSpectra[IGF_MAX_GRANULE_LEN]; /* Q31 | MDCT^2 spectra */ - Word16 squaredSpectra_e[IGF_MAX_TILES]; /* | exponents of squaredSpectra, one exponent per tile! */ - - - /* initialize variables */ - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - igf_pN = hPrivateData->igf_pN; - igf_pN_e = hPrivateData->igf_pN_e; - igf_sN = hPrivateData->igf_sN; - igf_sN_e = hPrivateData->igf_sN_e; - - set32_fx( squaredSpectra, 0, IGF_MAX_GRANULE_LEN ); - set16_fx( squaredSpectra_e, 0, IGF_MAX_TILES ); - - /* square the original spectrum */ - IGFCommonFuncsMDCTSquareSpec( hGrid->startLine, - hGrid->stopLine, - spectrum, - spectrum_e, - squaredSpectra, - squaredSpectra_e, -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - 0, - element_mode ); -#else - 0 ); -#endif - - /* calculate the energy per SFB of the survied subbands */ - IGFCommonFuncsCalcSfbEnergyPowerSpec( hGrid->startSfb, - hGrid->stopSfb, - hGrid->swb_offset, - squaredSpectra, - squaredSpectra_e, - igf_sN, - igf_sN_e ); - - /* loop over tiles, every tile has his own exponent! */ - FOR( i = 0; i < hGrid->nTiles; i++ ) - { - /* square the prepared IGF spectrum */ - IGFCommonFuncsMDCTSquareSpec( hGrid->tile[i], - hGrid->tile[i + 1], - igf_spec, - igf_spec_e[i], - squaredSpectra, - &squaredSpectra_e[i], -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - 0, - element_mode ); -#else - 0 ); -#endif - - /* set all squared values to 0, if the core contains survied lines */ - IGF_setLinesToZero( hGrid->tile[i], - hGrid->tile[i + 1], - spectrum, - squaredSpectra ); - - /* calculate the energy per SFB of the processed subbands */ - IGFCommonFuncsCalcSfbEnergyPowerSpec( hGrid->sfbWrap[i], - hGrid->sfbWrap[i + 1], - hGrid->swb_offset, - squaredSpectra, - &squaredSpectra_e[i], - igf_pN, - igf_pN_e ); - } -} - -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/**********************************************************************/ /* -calculates IGF energies (for IVAS) -**************************************************************************/ -static void IGF_calc_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word32 *spectrum, /**< in: Q31 | MDCT spectrum */ - const Word16 spectrum_e, /**< in: | exponent of pSpectralData */ - Word32 *igf_spec, /**< in: Q31 | prepared IGF spectrum */ - Word16 *igf_spec_e /**< in: | array exponents of igf_spec, one exponent per tile */ -) -{ - H_IGF_GRID hGrid; - Word16 i; - Word32 *igf_pN; /* Q31 | processed energy */ - Word16 *igf_pN_e; /* | exponents of igf_pN, one for each entry of igf_pN */ - Word32 *igf_sN; /* Q31 | survived energy */ - Word16 *igf_sN_e; /* | exponents of igf_sN, one for each entry of igf_sN */ - Word32 squaredSpectra[IGF_MAX_GRANULE_LEN]; /* Q31 | MDCT^2 spectra */ - Word16 squaredSpectra_e[IGF_MAX_TILES]; /* | exponents of squaredSpectra, one exponent per tile! */ - - - /* initialize variables */ - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - igf_pN = hPrivateData->igf_pN; - igf_pN_e = hPrivateData->igf_pN_e; - igf_sN = hPrivateData->igf_sN; - igf_sN_e = hPrivateData->igf_sN_e; - - set32_fx( squaredSpectra, 0, IGF_MAX_GRANULE_LEN ); - set16_fx( squaredSpectra_e, 0, IGF_MAX_TILES ); - - /* square the original spectrum */ - IGFCommonFuncsMDCTSquareSpec_ivas( hGrid->startLine, - hGrid->stopLine, - spectrum, - spectrum_e, - squaredSpectra, - squaredSpectra_e, - 0 ); - - /* calculate the energy per SFB of the survied subbands */ - IGFCommonFuncsCalcSfbEnergyPowerSpec( hGrid->startSfb, - hGrid->stopSfb, - hGrid->swb_offset, - squaredSpectra, - squaredSpectra_e, - igf_sN, - igf_sN_e ); - - /* loop over tiles, every tile has his own exponent! */ - FOR( i = 0; i < hGrid->nTiles; i++ ) - { - /* square the prepared IGF spectrum */ - IGFCommonFuncsMDCTSquareSpec_ivas( hGrid->tile[i], - hGrid->tile[i + 1], - igf_spec, - igf_spec_e[i], - squaredSpectra, - &squaredSpectra_e[i], - 0 ); - - /* set all squared values to 0, if the core contains survied lines */ - IGF_setLinesToZero( hGrid->tile[i], - hGrid->tile[i + 1], - spectrum, - squaredSpectra ); - - /* calculate the energy per SFB of the processed subbands */ - IGFCommonFuncsCalcSfbEnergyPowerSpec( hGrid->sfbWrap[i], - hGrid->sfbWrap[i + 1], - hGrid->swb_offset, - squaredSpectra, - &squaredSpectra_e[i], - igf_pN, - igf_pN_e ); - } -} -#endif -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/**********************************************************************/ /* -apply IGF -**************************************************************************/ -static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - Word32 *spectrum, /**< in: Q31 | MDCT spectrum */ - Word16 *spectrum_e, /**< in: | exponent of pSpectralData */ - const Word32 *igf_spec, /**< in: Q31 | prepared IGF spectrum */ - const Word16 *igf_spec_e, /**< in: | array exponents of igf_spec, one exponent per tile */ - Word32 *virtualSpec, /**< out:Q31 | virtual IGF spectrum, used for temp flattening */ - Word16 *virtualSpec_e, /**< out: | exponent of virtualSpec */ - Word16 *flag_sparse /**< out: Q0 | temp flattening indicator */ -) -{ - H_IGF_GRID hGrid; - Word16 i; - Word16 tb; - Word16 sfb; - Word16 shift; - Word16 s; - Word16 s_sfb; - Word16 start_sfb; - Word16 stop_sfb; - Word16 sfb_p1; - Word16 sfb_m1; - Word16 hopsize; - Word16 sum; - Word16 tileIdx; - Word16 width; /* Q0 | width of the current sfb */ - Word16 width_e; /* | exponent of widthent sfb, initialized as 15! */ - Word16 gFactor; /* 1Q14 | general SCF adaption */ - Word16 fFactor; /* 1Q14 | first SCF adaption */ - Word16 lFactor; /* 1Q14 | last SCF adaption */ - Word16 w0; /* Q15 | float value: 0.201f */ - Word16 w1; /* Q15 | float value: 0.389f */ - Word16 w2; /* Q15 | float value: 0.410f */ - Word16 dE; /* Q31 | energy below igfBgn */ - Word16 dE_e; /* | exponent of dE */ - Word16 gn; /* Q0 | gain read from bitstream + processing */ - Word16 gn_e; /* | exponent of gn */ - Word16 maxGain_e; /* | maximal gain exponent over sfbs */ - Word16 tmp; - Word16 tmp_e; - Word16 tmp_loop; - Word32 L_tmp; - Word16 L_tmp_e; - Word32 L_tmp2; - Word32 sNlocal; - Word16 sNlocal_e; - Word32 dNlocal; - Word16 dNlocal_e; - Word32 E; - Word16 E_e; - Word32 *sN; - Word16 *sN_e; - Word32 *pN; - Word16 *pN_e; - Word16 gain[IGF_MAX_SFB]; - Word16 gain_e[IGF_MAX_SFB]; - Word16 dN[IGF_MAX_SFB + 1]; - Word16 dN_e[IGF_MAX_SFB + 1]; - Word16 dS[IGF_MAX_SFB]; - Word16 dS_e[IGF_MAX_SFB]; - Word32 energyTmp[24]; - Word16 Hr; - move16(); - move16(); - - - /* initialize variables */ - w0 = 6586; // Q15 - move16(); - w1 = 12747; // Q15 - move16(); - w2 = 13435; // Q15 - move16(); - dE = 0; - move16(); - dE_e = 0; - move16(); - tmp = 0; - move16(); - s = 0; - move16(); - tmp_e = 0; - move16(); - gn = 0; - move16(); - gn_e = 0; - move16(); - maxGain_e = 0; - move16(); - L_tmp_e = 0; - move16(); - dNlocal_e = 0; - move16(); - L_tmp = 0; - move32(); - dNlocal = 0; - move32(); - - set16_fx( gain, 0, IGF_MAX_SFB ); - set16_fx( gain_e, 0, IGF_MAX_SFB ); - set16_fx( dN, 0, add( IGF_MAX_SFB, 1 ) ); - set16_fx( dN_e, 0, add( IGF_MAX_SFB, 1 ) ); - set16_fx( dS, 0, IGF_MAX_SFB ); - set16_fx( dS_e, 0, IGF_MAX_SFB ); - set32_fx( energyTmp, 0, 24 ); - - /* more inits */ - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - sN = hPrivateData->igf_sN; - sN_e = hPrivateData->igf_sN_e; - pN = hPrivateData->igf_pN; - pN_e = hPrivateData->igf_pN_e; - start_sfb = hGrid->startSfb; - move16(); - stop_sfb = hGrid->stopSfb; - move16(); - gFactor = hGrid->gFactor; - move16(); - fFactor = hGrid->fFactor; - move16(); - lFactor = hGrid->lFactor; - move16(); - - /* reset virtual spec */ - set16_fx( flag_sparse, 0, N_MAX_TCX - IGF_START_MN ); - set32_fx( virtualSpec, 0, N_MAX_TCX - IGF_START_MN ); - *virtualSpec_e = *spectrum_e; - move16(); - - /* collect energy below hGrid->startLine: */ - tmp = sub( hGrid->startLine, 24 ); - IGFCommonFuncsMDCTSquareSpec( tmp, - hGrid->startLine, - spectrum, - *spectrum_e, - energyTmp, - &dE_e, - negate( tmp ) ); - - L_tmp = sum_array_norm( energyTmp, 24, &shift ); - /* float: dE = (float)sqrt(dE / 24.f); basop: */ - shift = add( sub( shift, 4 ), dE_e ); /* x/24 = (x >> 4) * 1/1.5 */ - dE = Sqrt16norm( extract_h( L_tmp ), &shift ); - dE = mult_r( dE, 26755 /*0.81649658092772603273242802490196f Q15*/ ); /* 0.81649658092772603273242802490196f = sqrt(1/1.5)) */ - dE_e = shift; - move16(); - - /* select correct hopsize for envelope refinement */ - hopsize = 2; - move16(); - if ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_OFF ) ) - { - hopsize = 4; - move16(); - } - if ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_STRONG ) ) - { - hopsize = 1; - move16(); - } - hopsize = s_min( hopsize, hPrivateData->igfInfo.maxHopsize ); - - IF( GT_16( hopsize, 1 ) ) - { - FOR( sfb = start_sfb; sfb < stop_sfb; sfb += hopsize ) - { - tmp_loop = s_min( add( sfb, hopsize ), stop_sfb ); - FOR( tb = sfb + 1; tb < tmp_loop; tb++ ) - { - sN[sfb] = BASOP_Util_Add_Mant32Exp( sN[sfb], - sN_e[sfb], - sN[tb], - sN_e[tb], - &sN_e[sfb] ); - move32(); - pN[sfb] = BASOP_Util_Add_Mant32Exp( pN[sfb], - pN_e[sfb], - pN[tb], - pN_e[tb], - &pN_e[sfb] ); - move32(); - sN[tb] = L_deposit_l( 0 ); - pN[tb] = L_deposit_l( 0 ); - } - } - } - - /* IGF_rescale_SCF */ - IF( hGrid->infoIsRefined != 0 ) - { - FOR( sfb = start_sfb; sfb < stop_sfb; sfb += 2 ) - { - /* calculate and normalize the width of the current sfb */ - width = sub( hGrid->swb_offset[sfb + 2], hGrid->swb_offset[sfb] ); - shift = norm_s( width ); - width = shl( width, shift ); - width_e = sub( 15, shift ); /* initial value of width_e is 15, -> width = 15Q0 */ - - /* float: gn = 0.25f * igf_curr - 4.f; basop: */ - gn = hPrivateData->igf_curr[sfb >> 1]; // Q15 - move16(); - move16(); - gn_e = 13; /* set exponent of igf_curr to 13 = 15 - 2; -> igf_curr = igf_curr * 0.25, virtual division by 4 */ - move16(); - gn = sub( gn, 16 ); /* 13Q2 | 4 = 16 * 2^(-15 + 13); ("4" has same exponent as igf_curr now) */ - - /* float: tmp = pow(2.f, gn); basop: */ - L_tmp = BASOP_util_Pow2( L_deposit_h( gn ), gn_e, &L_tmp_e ); - - /* float: tmp = tmp * tmp; basop: */ - tmp = round_fx( L_tmp ); - L_tmp = L_mult( tmp, tmp ); - L_tmp_e = add( L_tmp_e, L_tmp_e ); - - /* get sNlocal | float: sNlocal = sN[ sfb ] + sN[ sfb+ 1 ]; basop: */ - sNlocal = BASOP_Util_Add_Mant32Exp( sN[sfb], - sN_e[sfb], - sN[sfb + 1], - sN_e[sfb + 1], - &sNlocal_e ); - - /* float: sNlocal /= width; basop: */ - shift = sub( norm_l( sNlocal ), 1 ); /* leave MSB empty, so in the division sNlocal is always smaller than width */ - sNlocal = L_deposit_h( div_s( extract_h( L_shl( sNlocal, shift ) ), width ) ); - sNlocal_e = sub( sub( sNlocal_e, shift ), width_e ); - - /* float: tmp = max(0.001 * sNlocal, tmp - sNlocal); basop: */ - L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, - L_tmp_e, - L_negate( sNlocal ), - sNlocal_e, - &L_tmp_e ); /* float: tmp = tmp - sNlocal */ - - /* max(0.001 * sNlocal, L_tmp) */ - /* Build a threshold and compare with L_tmp. - Build negated threshold and compare with negated L_tmp to cover also fullscale L_tmp case */ - BASOP_SATURATE_WARNING_OFF_EVS - L_tmp2 = L_shl_sat( L_negate( Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ) ), sub( sNlocal_e, L_tmp_e ) ); - L_tmp2 = L_sub_sat( L_tmp2, L_negate( L_tmp ) ); - BASOP_SATURATE_WARNING_ON_EVS - - IF( L_tmp2 < 0 ) - { - L_tmp = Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ); - L_tmp_e = sNlocal_e; - move16(); - } - - /* calc square root of L_tmp and store result in dN */ - L_tmp = Sqrt32( L_tmp, &L_tmp_e ); - dN[sfb] = round_fx_sat( L_tmp ); - move16(); - dN_e[sfb] = L_tmp_e; - move16(); - dN[sfb + 1] = dN[sfb]; - move16(); - dN_e[sfb + 1] = dN_e[sfb]; - move16(); - } - } - ELSE - { - FOR( sfb = start_sfb; sfb < stop_sfb; sfb++ ) - { - /* calculate and normalize the width of the current sfb */ - width = sub( hGrid->swb_offset[sfb + 1], hGrid->swb_offset[sfb] ); - shift = norm_s( width ); - width = shl( width, shift ); - width_e = sub( 15, shift ); /* initial value of width_e is 15, -> width = 15Q0 */ - - /* float: gn = 0.25f * igf_curr - 4.f; basop: */ - gn = hPrivateData->igf_curr[sfb]; - move16(); - move16(); - gn_e = 13; /* set exponent of igf_curr to 13 = 15 - 2; -> igf_curr = igf_curr * 0.25, virtual division by 4 */ - gn = sub( gn, 16 ); /* 13Q2 | 4 = 16 * 2^(-15 + 13); ("4" has same exponent as igf_curr now) */ - - /* float: tmp = pow(2.f, gn); basop: */ - L_tmp = BASOP_util_Pow2( L_deposit_h( gn ), gn_e, &L_tmp_e ); - - /* float: tmp = tmp * tmp; basop: */ - tmp = round_fx( L_tmp ); - L_tmp = L_mult( tmp, tmp ); - L_tmp_e = add( L_tmp_e, L_tmp_e ); - - /* get sNlocal */ - sNlocal = sN[sfb]; - move32(); - sNlocal_e = sN_e[sfb]; - move16(); - - /* float: sNlocal /= width; basop: */ - shift = sub( norm_l( sNlocal ), 1 ); /* leave MSB empty, so in the division sNlocal is always smaller than width */ - sNlocal = L_deposit_h( div_s( extract_h( L_shl( sNlocal, shift ) ), width ) ); - sNlocal_e = sub( sub( sNlocal_e, shift ), width_e ); - - /* float: tmp = max(0.001 * sNlocal, tmp - sNlocal); basop: */ - L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, - L_tmp_e, - L_negate( sNlocal ), - sNlocal_e, - &L_tmp_e ); /* float: tmp = tmp - sNlocal */ - - /* max(0.001 * sNlocal, L_tmp) */ - /* Build a threshold and compare with L_tmp. - Build negated threshold and compare with negated L_tmp to cover also fullscale L_tmp case */ - BASOP_SATURATE_WARNING_OFF_EVS - L_tmp2 = L_shl_sat( L_negate( Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ) ), sub( sNlocal_e, L_tmp_e ) ); - L_tmp2 = L_sub_sat( L_tmp2, L_negate( L_tmp ) ); - BASOP_SATURATE_WARNING_ON_EVS - - IF( L_tmp2 < 0 ) - { - L_tmp = Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ); - L_tmp_e = sNlocal_e; - move16(); - } - - /* calc square root of L_tmp and store result in dN */ - L_tmp = Sqrt32( L_tmp, &L_tmp_e ); - dN[sfb] = round_fx( L_tmp ); - move16(); - dN_e[sfb] = L_tmp_e; - move16(); - } - } - - dS[start_sfb] = dN[start_sfb]; - move16(); - dS_e[start_sfb] = dN_e[start_sfb]; - move16(); - - /* first value with adaption to core energy: */ - tmp_e = BASOP_Util_Add_MantExp( dE, - dE_e, - negate( dN[start_sfb] ), - dN_e[start_sfb], - &tmp ); /* float: tmp = dE - dN[start_sfb] */ - IF( tmp < 0 ) - { - /* float: dS[start_sfb] = dN[start_sfb] + fFactor * (dE-dN[start_sfb]); basop: */ - L_tmp = L_mult( fFactor, tmp ); - L_tmp_e = add( tmp_e, 1 ); /* 1Q14 | fFactor is 1Q14 */ - dS_e[start_sfb] = BASOP_Util_Add_MantExp( dN[start_sfb], - dN_e[start_sfb], - round_fx( L_tmp ), - L_tmp_e, - &dS[start_sfb] ); - move16(); - } - /* last value with less energy: */ - dS[stop_sfb - 1] = mult_r( lFactor, dN[stop_sfb - 1] ); - move16(); - move16(); - dS_e[stop_sfb - 1] = add( dN_e[stop_sfb - 1], 1 ); /* 1Q14 | lFactor is 1Q14 */ - - sfb_p1 = add( start_sfb, 1 ); - sfb_m1 = sub( stop_sfb, 1 ); - test(); - IF( hGrid->infoIsRefined != 0 && EQ_16( hopsize, 1 ) ) - { - /* apply filter to absolute energy values: */ - FOR( sfb = sfb_p1; sfb < sfb_m1; sfb++ ) - { - /* float: dS[sfb] = w0 * dN[sfb-1] + w1 * dN[sfb+0] + w2 * dN[sfb+1]; basop: */ - L_tmp = L_mult( w0, dN[sfb - 1] ); - dS[sfb] = round_fx( L_tmp ); - move16(); - dS_e[sfb] = dN_e[sfb - 1]; /* w0 is Q15, so no need to add an exponent */ - move16(); - L_tmp = L_mult( w1, dN[sfb] ); - dS_e[sfb] = BASOP_Util_Add_MantExp( dS[sfb], - dS_e[sfb], - round_fx( L_tmp ), - dN_e[sfb], /* w1 is Q15, so no need to add an exponent */ - &tmp ); - move16(); - dS[sfb] = tmp; - move16(); - L_tmp = L_mult( w2, dN[sfb + 1] ); - dS_e[sfb] = BASOP_Util_Add_MantExp( dS[sfb], - dS_e[sfb], - round_fx( L_tmp ), - dN_e[sfb + 1], /* w2 is Q15, so no need to add an exponent */ - &tmp ); - move16(); - dS[sfb] = tmp; - move16(); - } - } - ELSE - { - FOR( sfb = sfb_p1; sfb < sfb_m1; sfb++ ) - { - dS[sfb] = dN[sfb]; - move16(); - dS_e[sfb] = dN_e[sfb]; - move16(); - } - } - - Hr = 0; - move16(); - tileIdx = -1; - move16(); - FOR( sfb = start_sfb; sfb < stop_sfb; sfb += hopsize ) - { - E = 0; - move32(); - E_e = 0; - move16(); - sum = 0; - move16(); - - FOR( tb = 0; tb < hopsize; tb++ ) - { - /* calculate of the current sfb width */ - width = sub( hGrid->swb_offset[s_min( sfb + tb + 1, stop_sfb )], /* 15Q0 | width is Q0 */ - hGrid->swb_offset[s_min( sfb + tb, stop_sfb )] ); - - tmp = dS[s_min( sfb + tb, stop_sfb - 1 )]; - tmp_e = dS_e[s_min( sfb + tb, stop_sfb - 1 )]; - move16(); - move16(); - - /* square tmp */ - L_tmp = L_mult( tmp, tmp ); - L_tmp_e = add( tmp_e, tmp_e ); - - /* mult L_tmp times width */ - L_tmp = L_mult( round_fx( L_tmp ), width ); - L_tmp_e = add( L_tmp_e, 15 ); /* 15Q0 | width is Q0 */ - - /* calculate resulting energy */ - E = BASOP_Util_Add_Mant32Exp( E, - E_e, - L_tmp, - L_tmp_e, - &E_e ); - sum = add( sum, width ); /* 15Q0 | sum shares its exponent with width */ - } - - /* normalize sum for the following division */ - shift = norm_s( sum ); - sum = shl( sum, shift ); /* exponent of sum: sub(15, shift) */ - - /* divide E by sum */ - tmp = div_s( shr( round_fx_sat( E ), 1 ), sum ); /* shift E 1 bit to the right in order to make it smaller than sum */ - tmp_e = sub( add( E_e, 1 ), sub( 15, shift ) ); /* 15Q0 | sum is 15Q0 */ - - /* multiply the result by the hopsize */ - L_tmp = L_mult( tmp, hopsize ); - L_tmp_e = add( tmp_e, 15 ); /* 15Q0 | hopsize is 15Q0 */ - - /* take the square root and store the result in dS */ - L_tmp = Sqrt32( L_tmp, &L_tmp_e ); - dS[sfb] = round_fx( L_tmp ); - dS_e[sfb] = L_tmp_e; - move16(); - move16(); - - /* calculate the new dN */ - dN[sfb] = mult_r( gFactor, dS[sfb] ); - move16(); - move16(); - dN_e[sfb] = add( dS_e[sfb], 1 ); /* 1Q14 | gFactor is 1Q14 */ - - /* calculate of the current sfb width */ - width = sub( hGrid->swb_offset[sfb + 1], /* 15Q0 | width is Q0 */ - hGrid->swb_offset[sfb] ); - - /* square dN */ - L_tmp = L_mult( dN[sfb], dN[sfb] ); - L_tmp_e = add( dN_e[sfb], dN_e[sfb] ); - - /* mult L_tmp times width */ - shift = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, shift ); - L_tmp = L_mult( round_fx( L_tmp ), width ); - L_tmp_e = sub( add( L_tmp_e, 15 ), shift ); /* 15Q0 | width is Q0 */ - shift = norm_l( L_tmp ); - - /* store normalized result */ - dNlocal = L_shl( L_tmp, shift ); - dNlocal_e = sub( L_tmp_e, shift ); - - /* gain calculation */ - gain[sfb] = 0; - move16(); - IF( pN[sfb] != 0 ) - { - tmp = BASOP_Util_Divide3232_Scale( dNlocal, pN[sfb], &s ); - s = sub( add( s, dNlocal_e ), pN_e[sfb] ); - gain[sfb] = Sqrt16( tmp, &s ); - move16(); - gain_e[sfb] = s; - move16(); - - - /* get the maximal exponent of the gain array, needed for exponent adjustment of the spectrum */ - maxGain_e = s_max( maxGain_e, gain_e[sfb] ); - } - sfb_p1 = add( sfb, 1 ); - sfb_m1 = s_min( add( sfb, hopsize ), stop_sfb ); - FOR( s_sfb = sfb_p1; s_sfb < sfb_m1; s_sfb++ ) - { - gain[s_sfb] = gain[sfb]; - move16(); - gain_e[s_sfb] = gain_e[sfb]; - move16(); - } - - /*--- check gains /spectrum exponents for possible overflows --- */ - /* get tile index */ - IF( LE_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) - { - tileIdx = add( tileIdx, 1 ); - } - /*do a test multiplication with the highest possible value*/ - L_tmp = Mpy_32_16_1( (Word32) 0xFFFF8000 /*igf_spec occupies only the 16LSBs */, gain[sfb] ); - L_tmp_e = add( igf_spec_e[tileIdx], gain_e[sfb] ); - /*check whether overflow would occur and calculate Headroom, needed*/ - shift = sub( L_tmp_e, *spectrum_e ); - tmp = sub( shift, sub( norm_l( L_tmp ), TCX_IMDCT_HEADROOM ) ); - if ( tmp > 0 ) - { - Hr = s_max( Hr, tmp ); - } - - /* disable rescaling if gain is smaler than 1 */ - /* gain < 1, if norm_s(gain[sfb]) >= gain_e[sfb] */ - tmp = sub( norm_s( gain[sfb] ), gain_e[sfb] ); - if ( tmp >= 0 ) - { - Hr = 0; - move16(); - } - } - - /* Rescale spectrum if overflow may occur */ - tileIdx = -1; - move16(); - IF( Hr > 0 ) - { - /* rescale virtual Spec, cheap and easy: reset scalingfactor */ - *virtualSpec_e = add( *virtualSpec_e, Hr ); - move16(); - - /* rescale spectrum */ - FOR( i = 0; i < hGrid->stopLine; i++ ) - { - spectrum[i] = L_shr( spectrum[i], Hr ); - move16(); - } - *spectrum_e = add( *spectrum_e, Hr ); - move16(); - } - - /* tiling */ - tileIdx = -1; - move16(); - FOR( sfb = start_sfb; sfb < stop_sfb; sfb++ ) - { - /* get tile index */ - IF( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) - { - tileIdx = add( tileIdx, 1 ); - } - - IF( hPrivateData->frameLossCounter > 0 ) - { - /* normalize gain */ - tmp = norm_s( gain[sfb] ); - gain[sfb] = shl( gain[sfb], tmp ); - move16(); - gain_e[sfb] = sub( gain_e[sfb], tmp ); - move16(); - - /* gain[sfb] = min(gain[sfb], 12.f); */ - BASOP_SATURATE_WARNING_OFF_EVS /* threshold, may overflow */ - tmp = shl_sat( gain[sfb], sub( gain_e[sfb], 15 - 5 ) ); /* 10Q5 | tmp is in 10Q5 */ - BASOP_SATURATE_WARNING_ON_EVS - - IF( tmp > 384 ) /* 10Q5 | 384 = 12 in 10Q5 */ - { - gain[sfb] = 384; - move16(); - gain_e[sfb] = 10; - move16(); - } - - IF( LT_16( hPrivateData->frameLossCounter, 5 ) ) - { - /* gain[sfb] -= gain[sfb] / 8 * hPrivateData->frameLossCounter; -> multiply with 0Q15 -> adaption of the exponent not needed */ - IF( EQ_16( hPrivateData->frameLossCounter, 1 ) ) - { - /* 0Q15 | >> 3 ^= * 0.125 = 1 / 8 */ - gain[sfb] = sub( gain[sfb], shr_r( gain[sfb], 3 ) ); - move16(); - } - ELSE IF( EQ_16( hPrivateData->frameLossCounter, 2 ) ) - { - /* 0Q15 | >> 2 ^= * 0.25 = 2 / 8 */ - gain[sfb] = sub( gain[sfb], shr_r( gain[sfb], 2 ) ); - move16(); - } - ELSE IF( EQ_16( hPrivateData->frameLossCounter, 3 ) ) - { - /* 0Q15 | * 12288 ^= * 0.3750 = 3 / 8 */ - gain[sfb] = sub( gain[sfb], mult_r( gain[sfb], 12288 ) ); - move16(); - } - ELSE - { - /* 0Q15 | >> 1 ^= * 0.5 = 4 / 8 */ - gain[sfb] = sub( gain[sfb], shr_r( gain[sfb], 1 ) ); - move16(); - } - } - ELSE - { - /* gain[sfb] /= 2; -> reduce exponent by 1 */ - gain_e[sfb] = sub( gain_e[sfb], 1 ); - move16(); - } - } - - FOR( tb = hGrid->swb_offset[sfb]; tb < hGrid->swb_offset[sfb + 1]; tb++ ) - { - /* multiply the prepared IGF spectrum with the gain */ - L_tmp2 = 0; /* set L_tmp2 to default value */ - move32(); - L_tmp = Mpy_32_16_1( igf_spec[tb], gain[sfb] ); - L_tmp_e = add( igf_spec_e[tileIdx], gain_e[sfb] ); - - /* store the finalized IGF spectrum */ - IF( spectrum[tb] == 0 ) - { - shift = sub( L_tmp_e, *spectrum_e ); - tmp = sub( sub( norm_l( L_tmp ), shift ), 32 ); - IF( tmp < 0 ) - { - L_tmp2 = L_shl( L_tmp, shift ); - } - spectrum[tb] = L_tmp2; - move32(); - flag_sparse[tb - IGF_START_MN] = 1; - move16(); - } - ELSE - { - shift = sub( L_tmp_e, *virtualSpec_e ); - tmp = sub( sub( norm_l( L_tmp ), shift ), 32 ); - IF( tmp < 0 ) - { - L_tmp2 = L_shl( L_tmp, shift ); + IF( ( coreMsMask[tb] == 0 ) ) + { + IF( EQ_16( coreMsMask[strt_cpy], 0 ) ) /* LR->LR */ + { + igf_specR_fx[tb] = selR; + move32(); + igf_specR_e_arr[tb] = selR_e; + move16(); + } + ELSE /* MS/DR -> LR */ + { + tmpL = Mpy_32_32( selL, c_fx ); // Q31 - selL_e + tmpR = Mpy_32_32( selR, c_fx ); // Q31 - selR_e + igf_specR_fx[tb] = BASOP_Util_Add_Mant32Exp( tmpL, selL_e, L_negate( tmpR ), selR_e, &tmp_e ); + move32(); + igf_specR_e_arr[tb] = tmp_e; + move16(); + } + } + ELSE + { + IF( EQ_16( coreMsMask[strt_cpy], 0 ) ) /* LR->MS/DR */ + { + tmpL = Mpy_32_32( selL, c_fx ); // Q31 - selL_e + tmpR = Mpy_32_32( selR, c_fx ); // Q31 - selR_e + igf_specR_fx[tb] = BASOP_Util_Add_Mant32Exp( tmpL, selL_e, L_negate( tmpR ), selR_e, &tmp_e ); + move32(); + igf_specR_e_arr[tb] = tmp_e; + move16(); + } + ELSE /* MS/DR -> MS/DR */ + { + igf_specR_fx[tb] = selR; + move32(); + igf_specR_e_arr[tb] = selR_e; + move16(); + } + } + strt_cpy = add( strt_cpy, 1 ); } - virtualSpec[tb - IGF_START_MN] = L_tmp2; - move32(); - flag_sparse[tb - IGF_START_MN] = 2; - move16(); } } } + + return; } + /**********************************************************************/ /* -apply IGF (for IVAS) +calculates IGF energies **************************************************************************/ -static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - Word32 *spectrum, /**< in: Q31 | MDCT spectrum */ - Word16 *spectrum_e, /**< in: | exponent of pSpectralData */ - const Word32 *igf_spec, /**< in: Q31 | prepared IGF spectrum */ - const Word16 *igf_spec_e, /**< in: | array exponents of igf_spec, one exponent per tile */ - Word32 *virtualSpec, /**< out:Q31 | virtual IGF spectrum, used for temp flattening */ - Word16 *virtualSpec_e, /**< out: | exponent of virtualSpec */ - Word16 *flag_sparse, /**< out: Q0 | temp flattening indicator */ - Word16 bfi_apply_damping /**< in: | bfi apply damping */ +static void IGF_calc( + IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ + const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ + const Word32 *spectrum, /**< in: Q31 | MDCT spectrum */ + const Word16 spectrum_e, /**< in: | exponent of pSpectralData */ + Word32 *igf_spec, /**< in: Q31 | prepared IGF spectrum */ + Word16 *igf_spec_e, /**< in: | array exponents of igf_spec, one exponent per tile */ + const Word16 element_mode /**< in: | IVAS element mode type */ ) -#else +{ + H_IGF_GRID hGrid; + Word16 i; + Word32 *igf_pN; /* Q31 | processed energy */ + Word16 *igf_pN_e; /* | exponents of igf_pN, one for each entry of igf_pN */ + Word32 *igf_sN; /* Q31 | survived energy */ + Word16 *igf_sN_e; /* | exponents of igf_sN, one for each entry of igf_sN */ + Word32 squaredSpectra[IGF_MAX_GRANULE_LEN]; /* Q31 | MDCT^2 spectra */ + Word16 squaredSpectra_e[IGF_MAX_TILES]; /* | exponents of squaredSpectra, one exponent per tile! */ + + /* initialize variables */ + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + igf_pN = hPrivateData->igf_pN; + igf_pN_e = hPrivateData->igf_pN_e; + igf_sN = hPrivateData->igf_sN; + igf_sN_e = hPrivateData->igf_sN_e; + + set32_fx( squaredSpectra, 0, IGF_MAX_GRANULE_LEN ); + set16_fx( squaredSpectra_e, 0, IGF_MAX_TILES ); + + /* square the original spectrum */ + IGFCommonFuncsMDCTSquareSpec( hGrid->startLine, + hGrid->stopLine, + spectrum, + spectrum_e, + squaredSpectra, + squaredSpectra_e, + 0, + element_mode ); + + /* calculate the energy per SFB of the survied subbands */ + IGFCommonFuncsCalcSfbEnergyPowerSpec( hGrid->startSfb, + hGrid->stopSfb, + hGrid->swb_offset, + squaredSpectra, + squaredSpectra_e, + igf_sN, + igf_sN_e ); + + /* loop over tiles, every tile has his own exponent! */ + FOR( i = 0; i < hGrid->nTiles; i++ ) + { + /* square the prepared IGF spectrum */ + IGFCommonFuncsMDCTSquareSpec( hGrid->tile[i], + hGrid->tile[i + 1], + igf_spec, + igf_spec_e[i], + squaredSpectra, + &squaredSpectra_e[i], + 0, + element_mode ); + + /* set all squared values to 0, if the core contains survied lines */ + IGF_setLinesToZero( hGrid->tile[i], + hGrid->tile[i + 1], + spectrum, + squaredSpectra ); + + /* calculate the energy per SFB of the processed subbands */ + IGFCommonFuncsCalcSfbEnergyPowerSpec( hGrid->sfbWrap[i], + hGrid->sfbWrap[i + 1], + hGrid->swb_offset, + squaredSpectra, + &squaredSpectra_e[i], + igf_pN, + igf_pN_e ); + } +} + + /**********************************************************************/ /* apply IGF **************************************************************************/ -static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - Word32 *spectrum, /**< in: Q31 | MDCT spectrum */ - Word16 *spectrum_e, /**< in: | exponent of pSpectralData */ - const Word32 *igf_spec, /**< in: Q31 | prepared IGF spectrum */ - const Word16 *igf_spec_e, /**< in: | array exponents of igf_spec, one exponent per tile */ - Word32 *virtualSpec, /**< out:Q31 | virtual IGF spectrum, used for temp flattening */ - Word16 *virtualSpec_e, /**< out: | exponent of virtualSpec */ - Word16 *flag_sparse, /**< out: Q0 | temp flattening indicator */ - Word16 bfi_apply_damping, /**< in: | bfi apply damping */ - Word16 element_mode /**< in: | IVAS element mode type */ +static void IGF_appl( + IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ + const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ + Word32 *spectrum, /**< in: Q31 | MDCT spectrum */ + Word16 *spectrum_e, /**< in: | exponent of pSpectralData */ + const Word32 *igf_spec, /**< in: Q31 | prepared IGF spectrum */ + const Word16 *igf_spec_e, /**< in: | array exponents of igf_spec, one exponent per tile */ + Word32 *virtualSpec, /**< out:Q31 | virtual IGF spectrum, used for temp flattening */ + Word16 *virtualSpec_e, /**< out: | exponent of virtualSpec */ + Word16 *flag_sparse, /**< out: Q0 | temp flattening indicator */ + Word16 bfi_apply_damping, /**< in: | bfi apply damping */ + Word16 element_mode /**< in: | IVAS element mode type */ ) -#endif { H_IGF_GRID hGrid; Word16 i; @@ -2656,7 +1205,6 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* collect energy below hGrid->startLine: */ tmp = sub( hGrid->startLine, 24 ); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFCommonFuncsMDCTSquareSpec( tmp, hGrid->startLine, spectrum, @@ -2665,15 +1213,6 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in &dE_e, negate( tmp ), element_mode ); -#else - IGFCommonFuncsMDCTSquareSpec_ivas( tmp, - hGrid->startLine, - spectrum, - *spectrum_e, - energyTmp, - &dE_e, - negate( tmp ) ); -#endif L_tmp = sum_array_norm( energyTmp, 24, &shift ); /* float: dE = (float)sqrt(dE / 24.f); basop: */ @@ -2697,11 +1236,8 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in move16(); } hopsize = s_min( hopsize, hPrivateData->igfInfo.maxHopsize ); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF( hPrivateData->restrict_hopsize && GT_16( element_mode, EVS_MONO ) ) -#else - IF( hPrivateData->restrict_hopsize ) -#endif { hopsize = s_min( hopsize, 2 ); } @@ -2747,9 +1283,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in move16(); move16(); gn_e = 13; /* set exponent of igf_curr to 13 = 15 - 2; -> igf_curr = igf_curr * 0.25, virtual division by 4 */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS move16(); -#endif gn = sub( gn, 16 ); /* 13Q2 | 4 = 16 * 2^(-15 + 13); ("4" has same exponent as igf_curr now) */ /* float: tmp = pow(2.f, gn); basop: */ @@ -2796,7 +1330,6 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* calc square root of L_tmp and store result in dN */ L_tmp = Sqrt32( L_tmp, &L_tmp_e ); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS if ( EQ_16( element_mode, EVS_MONO ) ) { dN[sfb] = round_fx_sat( L_tmp ); @@ -2805,9 +1338,6 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { dN[sfb] = extract_h( L_tmp ); } -#else - dN[sfb] = extract_h( L_tmp ); -#endif move16(); dN_e[sfb] = L_tmp_e; move16(); @@ -2863,14 +1393,10 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* max(0.001 * sNlocal, L_tmp) */ /* Build a threshold and compare with L_tmp. Build negated threshold and compare with negated L_tmp to cover also fullscale L_tmp case */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS BASOP_SATURATE_WARNING_OFF_EVS -#endif L_tmp2 = L_shl_sat( L_negate( Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ) ), sub( sNlocal_e, L_tmp_e ) ); L_tmp2 = L_sub_sat( L_tmp2, L_negate( L_tmp ) ); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS BASOP_SATURATE_WARNING_ON_EVS; -#endif IF( L_tmp2 < 0 ) { @@ -3142,7 +1668,6 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in } } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS if ( EQ_16( element_mode, EVS_MONO ) ) { FOR( tb = hGrid->swb_offset[sfb]; tb < hGrid->swb_offset[sfb + 1]; tb++ ) @@ -3184,14 +1709,9 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in } else { -#endif FOR( tb = hGrid->swb_offset[sfb]; tb < hGrid->swb_offset[sfb + 1]; tb++ ) { /* multiply the prepared IGF spectrum with the gain */ -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS - L_tmp2 = 0; /* set L_tmp2 to default value */ - move32(); -#endif L_tmp = Mpy_32_16_1( igf_spec[tb], gain[sfb] ); L_tmp_e = add( igf_spec_e[tileIdx], gain_e[sfb] ); @@ -3215,15 +1735,11 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in move16(); } } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS } -#endif } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS if ( GT_16( element_mode, EVS_MONO ) ) { -#endif Word16 max_e; max_e = *spectrum_e; move16(); @@ -3258,20 +1774,20 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in } *virtualSpec_e = max_e; move16(); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS } -#endif } + /**********************************************************************/ /* spectral whitening **************************************************************************/ -static void IGF_getWhiteSpectralData( const Word32 *in, /**< in: Q31 | MDCT spectrum */ - Word16 s_l, /**< in: Q0 | getScaleFactor32() of in */ - Word32 *out, /**< out: Q31| whitened spectrum */ - const Word16 start, /**< in: Q0 | start MDCT subband index */ - const Word16 stop, /**< in: Q0 | stop MDCT subband index */ - const Word16 level /**< in: Q0 | whitening strength */ +static void IGF_getWhiteSpectralData( + const Word32 *in, /**< in: Q31 | MDCT spectrum */ + Word16 s_l, /**< in: Q0 | getScaleFactor32() of in */ + Word32 *out, /**< out: Q31| whitened spectrum */ + const Word16 start, /**< in: Q0 | start MDCT subband index */ + const Word16 stop, /**< in: Q0 | stop MDCT subband index */ + const Word16 level /**< in: Q0 | whitening strength */ ) { Word16 j; @@ -3455,56 +1971,10 @@ static void IGF_getWhiteSpectralData_ivas( /**********************************************************************/ /* refines the IGF grid **************************************************************************/ -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -static void IGF_RefineGrid( H_IGF_GRID hGrid /**< in/out: | IGF grid handle */ -) -{ - Word16 a[IGF_MAX_SFB + 1]; - Word16 sfb; - Word16 tmp; - Word16 delta; - - set16_fx( a, 0, IGF_MAX_SFB + 1 ); - - hGrid->infoIsRefined = 1; - move16(); - FOR( sfb = 0; sfb < hGrid->swb_offset_len; sfb++ ) - { - tmp = shl( sfb, 1 ); - a[tmp] = hGrid->swb_offset[sfb]; - move16(); - tmp = add( tmp, 1 ); - delta = sub( hGrid->swb_offset[sfb + 1], hGrid->swb_offset[sfb] ); - delta = mac_r( 0x00195000, 29491 /*0.45f Q16*/, shl_sat( delta, 5 ) ); - a[tmp] = add( hGrid->swb_offset[sfb], shr( delta, 6 ) ); - move16(); - IF( s_and( a[tmp], 1 ) != 0 ) - { - a[tmp] = sub( a[tmp], 1 ); - move16(); - } - } - hGrid->stopSfb = shl( hGrid->stopSfb, 1 ); - move16(); - FOR( sfb = 0; sfb <= hGrid->stopSfb; sfb++ ) - { - hGrid->swb_offset[sfb] = a[sfb]; - move16(); - } - - FOR( sfb = 0; sfb <= hGrid->nTiles; sfb++ ) - { - hGrid->sfbWrap[sfb] = shl( hGrid->sfbWrap[sfb], 1 ); - move16(); - } -} - -static void IGF_RefineGrid_ivas_fx( H_IGF_GRID hGrid /**< in/out: | IGF grid handle */ -#else -static void IGF_RefineGrid( H_IGF_GRID hGrid, /**< in/out: | IGF grid handle */ - const Word16 element_mode /**< in : | IVAS element mode type */ -#endif +static void IGF_RefineGrid( + H_IGF_GRID hGrid, /**< in/out: | IGF grid handle */ + const Word16 element_mode /**< in : | IVAS element mode type */ ) { Word16 a[IGF_MAX_SFB + 1]; @@ -3527,141 +1997,46 @@ static void IGF_RefineGrid( H_IGF_GRID hGrid, /**< in/out: | IGF grid ha delta = mac_r( 0x00195000, 29491 /*0.45f Q16*/, shl_sat( delta, 5 ) ); a[tmp] = add( hGrid->swb_offset[sfb], shr( delta, 6 ) ); move16(); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF( GT_16( element_mode, EVS_MONO ) ) { -#endif // Rounding off delta values >=t+0.5 to t+1 IF( GE_16( sub( delta, shl( shr( delta, 6 ), 6 ) ), MID ) ) { a[tmp] = add( a[tmp], 1 ); - move16(); - } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - } -#endif - IF( s_and( a[tmp], 1 ) != 0 ) - { - a[tmp] = sub( a[tmp], 1 ); - move16(); - } - } - hGrid->stopSfb = shl( hGrid->stopSfb, 1 ); - move16(); - FOR( sfb = 0; sfb <= hGrid->stopSfb; sfb++ ) - { - hGrid->swb_offset[sfb] = a[sfb]; - move16(); - } - - FOR( sfb = 0; sfb <= hGrid->nTiles; sfb++ ) - { - hGrid->sfbWrap[sfb] = shl( hGrid->sfbWrap[sfb], 1 ); - move16(); - } -} - -/**********************************************************************/ /* -reads whitening information from the bitstream -**************************************************************************/ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS -void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ - Decoder_State *st, /**< in: | decoder state */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ -) -#else -void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ - Decoder_State *st, /**< in: | decoder state */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ -) -#endif -{ - IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; - H_IGF_GRID hGrid; - Word16 p; - Word16 nT; - Word16 tmp; - - - IF( hInstance != NULL ) - { - hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - nT = hGrid->nTiles; - move16(); - tmp = 0; - move16(); - - /* set/reset all values to default = IGF_WHITENING_OFF */ - FOR( p = 0; p < IGF_MAX_TILES; p++ ) - { - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; // Q0 - move16(); - } - - IF( isIndepFrame == 0 ) - { - tmp = get_next_indice_fx( st, 1 ); // Q0 - } - - IF( tmp == 1 ) - { - FOR( p = 0; p < nT; p++ ) - { - hPrivateData->currWhiteningLevel[p] = hPrivateData->prevWhiteningLevel[p]; // Q0 - move16(); - } - } - ELSE - { - IGF_decode_whitening_level( st, hPrivateData, 0 ); - test(); - IF( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) - { - tmp = 0; - move16(); - } - ELSE - { - tmp = get_next_indice_fx( st, 1 ); // Q0 - } - - IF( EQ_16( tmp, 1 ) ) - { - FOR( p = 1; p < nT; p++ ) - { - IGF_decode_whitening_level( st, hPrivateData, p ); - } - } - ELSE - { - FOR( p = 1; p < nT; p++ ) - { - hPrivateData->currWhiteningLevel[p] = hPrivateData->currWhiteningLevel[0]; // Q0 - move16(); - } + move16(); } } - /* save current level for concealment */ - FOR( p = 0; p < IGF_MAX_TILES; p++ ) + IF( s_and( a[tmp], 1 ) != 0 ) { - hPrivateData->prevWhiteningLevel[p] = hPrivateData->currWhiteningLevel[p]; // Q0 + a[tmp] = sub( a[tmp], 1 ); move16(); } + } + hGrid->stopSfb = shl( hGrid->stopSfb, 1 ); + move16(); + FOR( sfb = 0; sfb <= hGrid->stopSfb; sfb++ ) + { + hGrid->swb_offset[sfb] = a[sfb]; + move16(); + } - /* read flattening trigger from bitstream */ - IGF_decode_temp_flattening_trigger( st, hInstance ); + FOR( sfb = 0; sfb <= hGrid->nTiles; sfb++ ) + { + hGrid->sfbWrap[sfb] = shl( hGrid->sfbWrap[sfb], 1 ); + move16(); } } -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ - Decoder_State *st, /**< in: | decoder state */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ +/**********************************************************************/ /* +reads whitening information from the bitstream +**************************************************************************/ +void IGFDecReadData( + const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ + Decoder_State *st, /**< in: | decoder state */ + const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ + const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ ) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; @@ -3692,7 +2067,7 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins tmp = get_next_indice_fx( st, 1 ); // Q0 } - IF( EQ_16( tmp, 1 ) ) + IF( tmp == 1 ) { FOR( p = 0; p < nT; p++ ) { @@ -3703,7 +2078,17 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins ELSE { IGF_decode_whitening_level( st, hPrivateData, 0 ); - tmp = get_next_indice_fx( st, 1 ); // Q0 + test(); + IF( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) + { + tmp = 0; + move16(); + } + ELSE + { + tmp = get_next_indice_fx( st, 1 ); // Q0 + } + IF( EQ_16( tmp, 1 ) ) { FOR( p = 1; p < nT; p++ ) @@ -3732,15 +2117,17 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins IGF_decode_temp_flattening_trigger( st, hInstance ); } } -#endif + + /**********************************************************************/ /* read the IGF level information from the bitsream **************************************************************************/ -void IGFDecReadLevel( /**< out: Q0 | return igfAllZero flag indicating if no envelope is transmitted */ - const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - Decoder_State *st, /**< in: | decoder state */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ +/**< out: Q0 | return igfAllZero flag indicating if no envelope is transmitted */ +void IGFDecReadLevel( + const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + Decoder_State *st, /**< in: | decoder state */ + const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ + const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ ) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; @@ -3778,168 +2165,14 @@ void IGFDecReadLevel( /**< ou /**********************************************************************/ /* apply the IGF decoder **************************************************************************/ -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - Word32 *spectrum, /**< in/out: | MDCT spectrum */ - Word16 *spectrum_e, /**< in/out: | exponent of spectrum */ - const Word16 igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ - Word16 bfi /**< in: | frame loss == 1, frame good == 0 */ -) -{ - IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; - H_IGF_GRID hGrid; - Word16 i; - Word16 whiteningLevel; - Word16 s_l; /* | headroom of pSpecFlat */ - Word16 specMed_e; /* | exponent of the medium whitened spectrum */ - Word32 igf_spec[IGF_MAX_GRANULE_LEN]; /* Q31 | prepared IGF spectrum */ - Word16 igf_spec_e[IGF_MAX_TILES]; /* | exponents of igf_spec, one exponent per tile */ - - - hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - - /* initialize variables */ - whiteningLevel = 7; - move16(); - specMed_e = 0; - move16(); - hPrivateData->n_noise_bands = 0; - move16(); - hPrivateData->n_noise_bands_off = 0; - move16(); - hPrivateData->headroom_TCX_noise_white = 0; - move16(); - hPrivateData->headroom_TCX_noise = 0; - move16(); - hPrivateData->totalNoiseNrg = 0; - move32(); - hPrivateData->totalNoiseNrg_off = 0; - move32(); - - set32_fx( igf_spec, 0, IGF_MAX_GRANULE_LEN ); - set16_fx( igf_spec_e, 0, IGF_MAX_TILES ); - - /* concealment counter */ - IF( bfi != 0 ) - { - hPrivateData->frameLossCounter = add( hPrivateData->frameLossCounter, 1 ); - move16(); - } - ELSE - { - hPrivateData->frameLossCounter = 0; - move16(); - } - - /* skip IGF processing if all IGF levels are zero */ - IF( hInstance->infoIGFAllZero == 0 ) - { - - - FOR( i = 0; i < hGrid->nTiles; i++ ) - { - IF( EQ_16( hPrivateData->currWhiteningLevel[i], IGF_WHITENING_MID ) ) - { - s_l = getScaleFactor32( hPrivateData->pSpecFlat + hGrid->minSrcSubband - whiteningLevel, - add( sub( hGrid->startLine, hGrid->minSrcSubband ), whiteningLevel ) ); - - specMed_e = hPrivateData->pSpecFlat_exp; - move16(); - IGF_getWhiteSpectralData( hPrivateData->pSpecFlat, - s_l, - igf_spec, - hGrid->minSrcSubband, - hGrid->startLine, - whiteningLevel ); - - /*14 seems to be precise enough*/ - hPrivateData->headroom_TCX_noise_white = IGF_getScaleFactor32Cond( hInstance->infoTCXNoise_evs + hGrid->minSrcSubband, - igf_spec + hGrid->minSrcSubband, - sub( hGrid->startLine, hGrid->minSrcSubband ) ); - hPrivateData->n_noise_bands = IGF_replaceTCXNoise_1( igf_spec, - hPrivateData->headroom_TCX_noise_white, - hInstance->infoTCXNoise_evs, - hGrid->minSrcSubband, - hGrid->startLine, - &hPrivateData->totalNoiseNrg ); - move16(); - move16(); - - BREAK; - } - } - - FOR( i = 0; i < hGrid->nTiles; i++ ) - { - IF( hPrivateData->currWhiteningLevel[i] == IGF_WHITENING_OFF ) - { - hPrivateData->headroom_TCX_noise = IGF_getScaleFactor32Cond( hInstance->infoTCXNoise_evs + hGrid->minSrcSubband, - hPrivateData->pSpecFlat + hGrid->minSrcSubband, - sub( hGrid->startLine, hGrid->minSrcSubband ) ); - - hPrivateData->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateData->pSpecFlat, - hPrivateData->headroom_TCX_noise, - hInstance->infoTCXNoise_evs, - hGrid->minSrcSubband, - hGrid->startLine, - &hPrivateData->totalNoiseNrg_off ); - move16(); - move16(); - - BREAK; - } - } - - /* apply IGF in three steps: */ - IGF_prep( hPrivateData, - igfGridIdx, - hInstance->infoTCXNoise_evs, - igf_spec, - igf_spec_e, - hPrivateData->pSpecFlat, - hPrivateData->pSpecFlat_exp, - specMed_e ); - IGF_calc( hPrivateData, - igfGridIdx, - spectrum, - *spectrum_e, - igf_spec, - igf_spec_e ); - IGF_appl( hPrivateData, - igfGridIdx, - spectrum, - spectrum_e, - igf_spec, - igf_spec_e, - hInstance->virtualSpec, - &hInstance->virtualSpec_e, - hInstance->flag_sparseBuf ); - } - - /* reset TCX noise indicator vector */ - set16_fx( hInstance->infoTCXNoise_evs, 0, IGF_START_MX ); -} - -/**********************************************************************/ /* -apply the IGF decoder (for IVAS) -**************************************************************************/ -void IGFDecApplyMono_ivas( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - Word32 *spectrum, /**< in/out: | MDCT spectrum */ - Word16 *spectrum_e, /**< in/out: | exponent of spectrum */ - const Word16 igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ - Word16 bfi, /**< in: | frame loss == 1, frame good == 0 */ - Word16 element_mode /**< in: | IVAS element mode */ -) -#else -void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - Word32 *spectrum, /**< in/out: | MDCT spectrum */ - Word16 *spectrum_e, /**< in/out: | exponent of spectrum */ - const Word16 igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ - Word16 bfi, /**< in: | frame loss == 1, frame good == 0 */ - Word16 element_mode /**< in: | IVAS element mode */ +void IGFDecApplyMono( + const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + Word32 *spectrum, /**< in/out: | MDCT spectrum */ + Word16 *spectrum_e, /**< in/out: | exponent of spectrum */ + const Word16 igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ + Word16 bfi, /**< in: | frame loss == 1, frame good == 0 */ + Word16 element_mode /**< in: | IVAS element mode */ ) -#endif { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; @@ -3949,9 +2182,6 @@ void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | in Word16 specMed_e; /* | exponent of the medium whitened spectrum */ Word32 igf_spec[IGF_MAX_GRANULE_LEN]; /* Q31 | prepared IGF spectrum */ Word16 igf_spec_e[IGF_MAX_TILES]; /* | exponents of igf_spec, one exponent per tile */ -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS - Word16 len; -#endif hPrivateData = &hInstance->igfData; hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; @@ -3968,23 +2198,6 @@ void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | in whiteningLevel = IGF_MID_WHITENING_LEVEL; move16(); } -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS - IF( EQ_16( igfGridIdx, IGF_GRID_LB_SHORT ) ) - { - len = ( N_MAX_TCX - IGF_START_MN ) / 2; - move16(); - } - ELSE - { - len = ( N_MAX_TCX - IGF_START_MN ); - move16(); - } - - set16_fx( hInstance->flag_sparse, 0, len ); - set32_fx( hInstance->virtualSpec_fx, 0, len ); - hInstance->virtualSpec_e = 0; - move16(); -#endif specMed_e = 0; move16(); @@ -4025,8 +2238,6 @@ void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | in { IF( EQ_16( hPrivateData->currWhiteningLevel[i], IGF_WHITENING_MID ) ) { - test(); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IF( EQ_16( element_mode, EVS_MONO ) ) { s_l = getScaleFactor32( hPrivateData->pSpecFlat + hGrid->minSrcSubband - whiteningLevel, @@ -4072,32 +2283,7 @@ void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | in specMed_e = igf_spec_e[i]; move16(); } -#else - IF( EQ_16( element_mode, EVS_MONO ) || !bfi ) - { - s_l = getScaleFactor32( hPrivateData->pSpecFlat + hGrid->minSrcSubband - whiteningLevel, - add( sub( hGrid->startLine, hGrid->minSrcSubband ), whiteningLevel ) ); - - IGF_getWhiteSpectralData_ivas( hPrivateData->pSpecFlat, - hPrivateData->pSpecFlat_exp, - s_l, - igf_spec, - &igf_spec_e[i], - hGrid->minSrcSubband, - hGrid->startLine, - whiteningLevel ); - } - ELSE - { - Copy32( hPrivateData->pSpecFlat, igf_spec, hGrid->startLine ); - igf_spec_e[i] = hPrivateData->pSpecFlat_exp, - move16(); - } - specMed_e = igf_spec_e[i]; - move16(); -#endif -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS hPrivateData->n_noise_bands = IGF_replaceTCXNoise_1( igf_spec, igf_spec_e[i], hPrivateData->headroom_TCX_noise_white, @@ -4107,28 +2293,16 @@ void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | in &hPrivateData->totalNoiseNrg, &hPrivateData->totalNoiseNrg_exp, element_mode ); -#else - hPrivateData->n_noise_bands = ivas_IGF_replaceTCXNoise_1_fx( igf_spec, - igf_spec_e[i], - hInstance->infoTCXNoise_ptr, - hGrid->minSrcSubband, - hGrid->startLine, - &hPrivateData->totalNoiseNrg, - &hPrivateData->totalNoiseNrg_exp ); -#endif move16(); BREAK; } } - FOR( i = 0; i < hGrid->nTiles; i++ ) { IF( EQ_16( hPrivateData->currWhiteningLevel[i], IGF_WHITENING_OFF ) ) { - -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IF( EQ_16( element_mode, EVS_MONO ) ) { hPrivateData->headroom_TCX_noise = IGF_getScaleFactor32Cond( hInstance->infoTCXNoise_evs + hGrid->minSrcSubband, @@ -4145,21 +2319,11 @@ void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | in &hPrivateData->totalNoiseNrg_off, &hPrivateData->totalNoiseNrg_off_exp, element_mode ); -#else - hPrivateData->n_noise_bands_off = ivas_IGF_replaceTCXNoise_1_fx( hPrivateData->pSpecFlat, - hPrivateData->pSpecFlat_exp, - hInstance->infoTCXNoise_ptr, - hGrid->minSrcSubband, - hGrid->startLine, - &hPrivateData->totalNoiseNrg_off, - &hPrivateData->totalNoiseNrg_off_exp ); -#endif move16(); BREAK; } } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGF_prep( hPrivateData, igfGridIdx, EQ_16( element_mode, EVS_MONO ) ? hInstance->infoTCXNoise_evs : hInstance->infoTCXNoise_ptr, @@ -4189,47 +2353,14 @@ void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | in hInstance->flag_sparseBuf, 1, element_mode ); -#else - IGF_prep_ivas( hPrivateData, - igfGridIdx, - hInstance->infoTCXNoise_ptr, - igf_spec, - igf_spec_e, - hPrivateData->pSpecFlat, - hPrivateData->pSpecFlat_exp, - specMed_e, - element_mode ); - - IGF_calc_ivas( hPrivateData, - igfGridIdx, - spectrum, - *spectrum_e, - igf_spec, - igf_spec_e ); - - IGF_appl_ivas( hPrivateData, - igfGridIdx, - spectrum, - spectrum_e, - igf_spec, - igf_spec_e, - hInstance->virtualSpec, - &hInstance->virtualSpec_e, - hInstance->flag_sparseBuf, - 1 ); -#endif } /* reset TCX noise indicator vector */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IF( EQ_16( element_mode, EVS_MONO ) ) { set16_fx( hInstance->infoTCXNoise_evs, 0, IGF_START_MX ); } ELSE IF( EQ_16( igfGridIdx, IGF_GRID_LB_SHORT ) ) -#else - IF( EQ_16( igfGridIdx, IGF_GRID_LB_SHORT ) ) -#endif { set16_fx( hInstance->infoTCXNoise_ptr, 0, IGF_START_MX / 2 ); } @@ -4381,7 +2512,6 @@ void IGFDecApplyStereo( move16(); } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS hPrivateDataL->n_noise_bands = IGF_replaceTCXNoise_1( igf_specL_fx, specMedL_e, 0, @@ -4391,15 +2521,6 @@ void IGFDecApplyStereo( &hPrivateDataL->totalNoiseNrg, &hPrivateDataL->totalNoiseNrg_exp, IVAS_CPE_MDCT ); -#else - hPrivateDataL->n_noise_bands = ivas_IGF_replaceTCXNoise_1_fx( igf_specL_fx, - specMedL_e, - hIGFDecL->infoTCXNoise_ptr, - hGrid->minSrcSubband, - hGrid->startLine, - &hPrivateDataL->totalNoiseNrg, - &hPrivateDataL->totalNoiseNrg_exp ); -#endif move16(); IF( !bfi ) @@ -4422,7 +2543,6 @@ void IGFDecApplyStereo( move16(); } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS hPrivateDataR->n_noise_bands = IGF_replaceTCXNoise_1( igf_specR_fx, specMedR_e, 0, @@ -4432,15 +2552,6 @@ void IGFDecApplyStereo( &hPrivateDataR->totalNoiseNrg, &hPrivateDataR->totalNoiseNrg_exp, IVAS_CPE_MDCT ); -#else - hPrivateDataR->n_noise_bands = ivas_IGF_replaceTCXNoise_1_fx( igf_specR_fx, - specMedR_e, - hIGFDecR->infoTCXNoise_ptr, - hGrid->minSrcSubband, - hGrid->startLine, - &hPrivateDataR->totalNoiseNrg, - &hPrivateDataR->totalNoiseNrg_exp ); -#endif move16(); BREAK; } @@ -4451,7 +2562,6 @@ void IGFDecApplyStereo( test(); IF( EQ_16( hPrivateDataL->currWhiteningLevel[i], IGF_WHITENING_OFF ) || EQ_16( hPrivateDataR->currWhiteningLevel[i], IGF_WHITENING_OFF ) ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS hPrivateDataL->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateDataL->pSpecFlat, hPrivateDataL->pSpecFlat_exp, 0, @@ -4461,18 +2571,8 @@ void IGFDecApplyStereo( &hPrivateDataL->totalNoiseNrg_off, &hPrivateDataL->totalNoiseNrg_off_exp, IVAS_CPE_MDCT ); -#else - hPrivateDataL->n_noise_bands_off = ivas_IGF_replaceTCXNoise_1_fx( hPrivateDataL->pSpecFlat, - hPrivateDataL->pSpecFlat_exp, - hIGFDecL->infoTCXNoise_ptr, - hGrid->minSrcSubband, - hGrid->startLine, - &hPrivateDataL->totalNoiseNrg_off, - &hPrivateDataL->totalNoiseNrg_off_exp ); -#endif move16(); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS hPrivateDataR->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateDataR->pSpecFlat, hPrivateDataR->pSpecFlat_exp, 0, @@ -4482,15 +2582,6 @@ void IGFDecApplyStereo( &hPrivateDataR->totalNoiseNrg_off, &hPrivateDataR->totalNoiseNrg_off_exp, IVAS_CPE_MDCT ); -#else - hPrivateDataR->n_noise_bands_off = ivas_IGF_replaceTCXNoise_1_fx( hPrivateDataR->pSpecFlat, - hPrivateDataR->pSpecFlat_exp, - hIGFDecR->infoTCXNoise_ptr, - hGrid->minSrcSubband, - hGrid->startLine, - &hPrivateDataR->totalNoiseNrg_off, - &hPrivateDataR->totalNoiseNrg_off_exp ); -#endif move16(); BREAK; } @@ -4531,8 +2622,6 @@ void IGFDecApplyStereo( igf_specR_fx, igf_specR_e_arr, igf_specR_e ); - -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGF_calc( hPrivateDataL, igfGridIdx, spectrumL_fx, @@ -4569,40 +2658,6 @@ void IGFDecApplyStereo( hIGFDecR->flag_sparseBuf, bfi_apply_damping, IVAS_CPE_MDCT ); -#else - IGF_calc_ivas( hPrivateDataL, - igfGridIdx, - spectrumL_fx, - *spectrumL_e, - igf_specL_fx, - igf_specL_e ); - IGF_calc_ivas( hPrivateDataR, - igfGridIdx, - spectrumR_fx, - *spectrumR_e, - igf_specR_fx, - igf_specR_e ); - IGF_appl_ivas( hPrivateDataL, - igfGridIdx, - spectrumL_fx, - spectrumL_e, - igf_specL_fx, - igf_specL_e, - hIGFDecL->virtualSpec, - &hIGFDecL->virtualSpec_e, - hIGFDecL->flag_sparseBuf, - bfi_apply_damping ); - IGF_appl_ivas( hPrivateDataR, - igfGridIdx, - spectrumR_fx, - spectrumR_e, - igf_specR_fx, - igf_specR_e, - hIGFDecR->virtualSpec, - &hIGFDecR->virtualSpec_e, - hIGFDecR->flag_sparseBuf, - bfi_apply_damping ); -#endif } /* reset TCX noise indicator vector */ @@ -4659,23 +2714,13 @@ void IGFDecSetMode( move16(); test(); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IF( LE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000 ) || ( NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_96000 ) && NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_96000_CPE ) && NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_128000 ) && NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_128000_CPE ) ) ) -#else - IF( ( LE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000 ) ) || ( LE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000 ) ) ) -#endif { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_NORM], element_mode ); IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_TRAN], element_mode ); IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_SHORT], element_mode ); -#else - IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_NORM] ); - IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_TRAN] ); - IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_SHORT] ); -#endif } } ELSE @@ -4699,101 +2744,8 @@ void IGFDecSetMode( return; } -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -void IGFDecSetMode_ivas_fx( - const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i : instance handle of IGF Decoder */ - const Word32 total_brate, /* i : bitrate */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 defaultStartLine, /* i : default start subband index */ - const Word16 defaultStopLine, /* i : default stop subband index */ - const Word16 rf_mode /* i : flag to signal the RF mode */ -) -{ - IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; - - hPrivateData = &hIGFDec->igfData; - hIGFDec->isIGFActive = 0; - move16(); - - IF( IGFCommonFuncsIGFConfiguration_ivas_fx( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) ) - { - IGFSCFDecoderOpen( &hPrivateData->hArithSCFdec, &hPrivateData->igfInfo, total_brate, bwidth, element_mode, rf_mode ); - - hIGFDec->infoIGFAllZero = 0; - move16(); - hIGFDec->isIGFActive = 1; - move16(); - hIGFDec->infoIGFStopLine = hPrivateData->igfInfo.grid[0].stopLine; - move16(); - hIGFDec->infoIGFStartLine = hPrivateData->igfInfo.grid[0].startLine; - move16(); - hIGFDec->infoIGFStopFreq = hPrivateData->igfInfo.grid[0].stopFrequency; - move16(); - hIGFDec->infoIGFStartFreq = hPrivateData->igfInfo.grid[0].startFrequency; - move16(); - - test(); - /* no refinement if maxHopsize is 1 */ - IF( NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_96000 ) && NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_96000_CPE ) && - NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_128000 ) && NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_128000_CPE ) ) - { - IGF_RefineGrid_ivas_fx( &hPrivateData->igfInfo.grid[IGF_GRID_LB_NORM] ); - IGF_RefineGrid_ivas_fx( &hPrivateData->igfInfo.grid[IGF_GRID_LB_TRAN] ); - IGF_RefineGrid_ivas_fx( &hPrivateData->igfInfo.grid[IGF_GRID_LB_SHORT] ); - } - /* IGFDecOutInformation(hIGFDec); */ - } - ELSE - { - hIGFDec->infoIGFStopLine = defaultStopLine; - move16(); - hIGFDec->infoIGFStartLine = defaultStartLine; - move16(); - hIGFDec->infoIGFStopFreq = -1; - move16(); - hIGFDec->infoIGFStartFreq = -1; - move16(); - IVAS_ERROR( IVAS_ERR_INTERNAL, "IGFDecSetMode: initialization error!" ); - } - - hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; - hIGFDec->infoTCXNoise_ptr = &hIGFDec->infoTCXNoise_evs[0]; - hIGFDec->virtualSpec_fx = &hIGFDec->virtualSpec[0]; - hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf_fx[0]; - hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0]; - return; -} -#endif -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/**********************************************************************/ /* -updates the start/stop frequency of IGF according to igfGridIdx -**************************************************************************/ -void IGFDecUpdateInfo( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word16 igfGridIdx /**< in: | IGF grid index */ -) -{ - IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; - H_IGF_GRID hGrid; - - hPrivateData = &hInstance->igfData; - IF( hInstance->isIGFActive != 0 ) - { - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - hInstance->infoIGFStartFreq = hGrid->startFrequency; - move16(); - hInstance->infoIGFStopFreq = hGrid->stopFrequency; - move16(); - hInstance->infoIGFStartLine = hGrid->startLine; - move16(); - hInstance->infoIGFStopLine = hGrid->stopLine; - move16(); - } -} -#endif -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS /*-------------------------------------------------------------------* * IGFDecUpdateInfo() * @@ -4806,29 +2758,13 @@ void IGFDecUpdateInfo( const Word16 igfGridIdx, /* i : IGF grid index */ const Word16 element_mode /* i : IVAS element mode type */ ) -#else -/*-------------------------------------------------------------------* - * IGFDecUpdateInfo_ivas_fx() - * - * updates the start/stop frequency of IGF according to igfGridIdx - *-------------------------------------------------------------------*/ - -void IGFDecUpdateInfo_ivas_fx( - const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Decoder */ - const Word16 subFrameIdx, /* i : index of subframe */ - const Word16 igfGridIdx /* i : IGF grid index */ -) -#endif { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS // todo mul, 2026-03-12: Check, whether this restriction to EVS_MONO is necessary. It's apparently not present in float. - IF( GT_16( element_mode, EVS_MONO ) ) { -#endif hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; hIGFDec->infoTCXNoise_ptr = &hIGFDec->infoTCXNoise_evs[0]; @@ -4841,9 +2777,7 @@ void IGFDecUpdateInfo_ivas_fx( { IGFDecRestoreTCX10SubFrameData_fx( hIGFDec, subFrameIdx ); } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS } -#endif hPrivateData = &hIGFDec->igfData; IF( hIGFDec->isIGFActive ) diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index 82c566a56d2e47e513d678a54a020d1e7f11d1f2..bae2638e15c67d5ccb26102b92b4f527bc961233 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -969,10 +969,8 @@ ivas_error init_decoder_fx( move16(); st_fx->prev_Q_syn = 0; move16(); -#ifdef FIX_BASOP_2871_INIT_Q_SYN_FACTOR st_fx->Q_syn_factor = 0; move16(); -#endif FOR( i = 0; i < L_Q_MEM; i++ ) { diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index e558413a2785ef35bdeeea4644665efa1b98e490..40688cf919ed9544c4e9b96ec261e00e53621a91 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -438,15 +438,8 @@ ivas_error ivas_core_dec_fx( /*---------------------------------------------------------------------* * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ -#ifdef FIX_BASOP_REMOVE_SYNTH2_FX - IF( NE_32( ( error = core_switching_pre_dec_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn ) ), IVAS_ERR_OK ) ) -#else - Word16 Q_olapBufferSynth2; - Q_olapBufferSynth2 = Q15; /*Initializing with max values to avoid warnings*/ - move16(); - IF( NE_32( ( error = core_switching_pre_dec_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth2 ) ), IVAS_ERR_OK ) ) -#endif + IF( NE_32( ( error = core_switching_pre_dec_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_dec/ivas_mct_dec_fx.c b/lib_dec/ivas_mct_dec_fx.c index 127637bfce17324fb2c4d566e3f9c64f3463c86a..11892029f36f1bf5c8d37dfe5081f95225afab5b 100644 --- a/lib_dec/ivas_mct_dec_fx.c +++ b/lib_dec/ivas_mct_dec_fx.c @@ -676,11 +676,7 @@ ivas_error mct_dec_reconfigure_fx( IF( st->igf ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFDecSetMode( st->hIGFDec, st_ivas->hCPE[cpe_id]->element_brate, st->bwidth, st->element_mode, -1, -1, st->rf_flag ); -#else - IGFDecSetMode_ivas_fx( st->hIGFDec, st_ivas->hCPE[cpe_id]->element_brate, st->bwidth, st->element_mode, -1, -1, st->rf_flag ); -#endif } } } diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 9225fa00949b0786f708c14bdd8aaedbc99f9f1f..9dfdddda17ac93923852914e3f2242e0cfe40eee 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -72,11 +72,7 @@ void mdct_read_IGF_bits_fx( /* read IGF payload */ IGFDecReadLevel( st->hIGFDec, st0, temp, 1 ); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFDecReadData( st->hIGFDec, st0, temp, 1 ); -#else - IGFDecReadData_ivas_fx( st->hIGFDec, st0, temp, 1 ); -#endif } IF( EQ_16( st->core, TCX_10_CORE ) ) @@ -95,11 +91,7 @@ void mdct_read_IGF_bits_fx( } IGFDecReadLevel( st->hIGFDec, st0, IGF_GRID_LB_SHORT, temp ); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_SHORT, temp ); -#else - IGFDecReadData_ivas_fx( st->hIGFDec, st0, IGF_GRID_LB_SHORT, temp ); -#endif IGFDecStoreTCX10SubFrameData( st->hIGFDec, k ); } @@ -1305,29 +1297,17 @@ void ivas_mdct_core_reconstruct_fx( /* PLC: [TCX: TD PLC] */ IF( MCT_flag != 0 ) { -#ifndef HARMONIZE_2446_CON_TCX_FX - con_tcx_ivas_fx( st, &synthFB_fx[0], -16384, NULL, 0, NULL ); //-1.Q14 = -16384 -#else con_tcx_fx( st, &synthFB_fx[0], -16384, NULL, 0, NULL ); //-1.Q14 = -16384 -#endif // !HARMONIZE_2446_CON_TCX_FX } ELSE { IF( sts[1]->core != ACELP_CORE ) { -#ifndef HARMONIZE_2446_CON_TCX_FX - con_tcx_ivas_fx( st, &synthFB_fx[0], hCPE->hStereoMdct->lastCoh_fx, &sts[0]->seed_acelp, 1, &st->hFdCngDec->hFdCngCom->A_cng[0] ); -#else con_tcx_fx( st, &synthFB_fx[0], hCPE->hStereoMdct->lastCoh_fx, &sts[0]->seed_acelp, 1, &st->hFdCngDec->hFdCngCom->A_cng[0] ); -#endif // !HARMONIZE_2446_CON_TCX_FX } ELSE { -#ifndef HARMONIZE_2446_CON_TCX_FX - con_tcx_ivas_fx( st, &synthFB_fx[0], hCPE->hStereoMdct->lastCoh_fx, &sts[0]->seed_acelp, 0, &st->hFdCngDec->hFdCngCom->A_cng[0] ); -#else con_tcx_fx( st, &synthFB_fx[0], hCPE->hStereoMdct->lastCoh_fx, &sts[0]->seed_acelp, 0, &st->hFdCngDec->hFdCngCom->A_cng[0] ); -#endif // !HARMONIZE_2446_CON_TCX_FX } } st->hHQ_core->Q_old_wtda = add( st->hHQ_core->Q_old_wtda, q_syn ); diff --git a/lib_dec/ivas_tcx_core_dec_fx.c b/lib_dec/ivas_tcx_core_dec_fx.c index 56f20a923d75c3f061db708b05b295fc78592a27..eb5c88faaf648cfc673f81b72ca5ff994d5e188d 100644 --- a/lib_dec/ivas_tcx_core_dec_fx.c +++ b/lib_dec/ivas_tcx_core_dec_fx.c @@ -489,11 +489,8 @@ void stereo_tcx_core_dec_fx( } /* PLC: [TCX: TD PLC] */ -#ifndef HARMONIZE_2446_CON_TCX_FX - con_tcx_fx( st, &synthFB_fx[0] /*, -1.f, NULL, 0, NULL */ ); -#else con_tcx_fx( st, &synthFB_fx[0], -16384, NULL, 0, NULL ); -#endif // !HARMONIZE_2446_CON_TCX_FX + test(); IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) { @@ -879,9 +876,6 @@ void stereo_tcx_core_dec_fx( Copy_Scale_sig_16_32_no_sat( signal_out_fx, signal_out_32_fx, st->hFdCngDec->hFdCngCom->frameSize, Q6 ); generate_masking_noise_ivas_fx( signal_out_32_fx, &exp, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); Copy_Scale_sig_32_16( signal_out_32_fx, signal_out_fx, st->hFdCngDec->hFdCngCom->frameSize, negate( exp ) ); // Q0 -#ifndef FIX_BASOP_REMOVE_SYNTH2_FX - Copy_Scale_sig_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), -Q15 ); // Q0 -#endif } } diff --git a/lib_dec/stat_noise_uv_dec_fx.c b/lib_dec/stat_noise_uv_dec_fx.c index ff8d8d1c1e9a327c4dae4888083b770fe9a6b7c0..b36fec665a0a6ef2d91aa16db1d907a175c0694f 100644 --- a/lib_dec/stat_noise_uv_dec_fx.c +++ b/lib_dec/stat_noise_uv_dec_fx.c @@ -76,30 +76,11 @@ void stat_noise_uv_dec_fx( IF( !st_fx->Opt_AMR_WB ) { -#ifdef HQ_ALIGN_DUPLICATED_CODE stat_noise_uv_mod_fx( st_fx->element_mode, coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq, exc2, &st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); - -#else - IF( st_fx->element_mode > EVS_MONO ) - { - stat_noise_uv_mod_ivas_fx( coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq, exc2, &st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, - st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, - &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, - &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); - } - ELSE - { - stat_noise_uv_mod_fx( coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq, exc2, st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, - st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, - &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, - &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); - } -#endif } - return; } diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 9adfdcf5259ddbc7a15f36efa75e16ab8bf74b0e..c8dfc5a5da7ff5117e071c1e13c9f604ee627a50 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -3572,11 +3572,7 @@ void swb_tbe_dec_fx( Lmax = 0; move32(); -#ifdef FIX_2465_Q_BWE_EXC FOR( cnt = 0; cnt < sig_len; cnt++ ) -#else - FOR( cnt = 0; cnt < sig_len; cnt++ ) // note: this differs from the encoder where the length is always L_FRAME32k -#endif { Lmax = L_max( Lmax, L_abs( bwe_exc_extended_fx[cnt] ) ); } diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 4d290e72ab486f8ece5b0164a3733b03c012236c..ee491c23b98d630861b228c01efa4b3cb12bd496 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -21,11 +21,7 @@ static void CalcMDXT( const TonalMDCTConcealPtr hTonalMDCTConc, const Word16 type, const Word16 *timeSignal, Word32 *mdxtOutput, Word16 *mdxtOutput_e ); static void CalcPowerSpec( const Word32 *mdctSpec, const Word16 mdctSpec_exp, const Word32 *mdstSpec, const Word16 mdstSpec_exp, const Word16 nSamples, const Word16 floorPowerSpectrum, Word32 *powerSpec, Word16 *powerSpec_exp ); -#ifdef HARMONIZE_FUNC static void CalcPowerSpecAndDetectTonalComponents_fx( TonalMDCTConcealPtr const hTonalMDCTConc, Word32 secondLastMDST[], Word16 secondLastMDST_exp, Word32 secondLastMDCT[], Word16 secondLastMDCT_exp, Word32 const pitchLag, const PsychoacousticParameters *psychParamsCurrent, Word16 element_mode ); -#else -static void CalcPowerSpecAndDetectTonalComponents( TonalMDCTConcealPtr const hTonalMDCTConc, Word32 secondLastMDST[], Word16 secondLastMDST_exp, Word32 secondLastMDCT[], Word16 secondLastMDCT_exp, Word32 const pitchLag, Word16 element_mode ); -#endif static void FindPhases( TonalMDCTConcealPtr const hTonalMDCTConc, Word32 secondLastMDCT[], Word32 secondLastMDST[], Word16 diff_exp ); static void FindPhaseDifferences( TonalMDCTConcealPtr const hTonalMDCTConc, Word32 powerSpectrum[] ); @@ -715,11 +711,7 @@ static void FindPhaseDifferences( } -#ifdef HARMONIZE_FUNC static void CalcPowerSpecAndDetectTonalComponents_fx( -#else -static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( -#endif TonalMDCTConcealPtr const hTonalMDCTConc, Word32 secondLastMDST[], // Q31 - secondLastMDST_exp Word16 secondLastMDST_exp, @@ -747,13 +739,11 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( move16(); /* It is taken into account that the MDCT is not normalized. */ -#ifdef HARMONIZE_FUNC IF( element_mode == EVS_MONO ) { floorPowerSpectrum /*Q0*/ = extract_l( Mpy_32_16_1( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 82 ) ); /*1/400 = 82 Q15*/ } ELSE -#endif { floorPowerSpectrum /*Q0*/ = extract_l( Mpy_32_32( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 5368709 ) ); /*1/400 = 5368709 Q31*/ } @@ -780,7 +770,6 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( set32_fx( powerSpectrum + hTonalMDCTConc->nSamples, 0, sub( hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples ) ); } -#ifdef HARMONIZE_FUNC Word16 spectralData_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; move16(); if ( element_mode == EVS_MONO ) @@ -804,24 +793,6 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( nSamples, hTonalMDCTConc->nSamplesCore, floorPowerSpectrum, psychParamsCurrent, element_mode ); -#else - ivas_DetectTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, - (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, - (Word16 *) hTonalMDCTConc->pTCI->upperIndex, - (Word16 *) &hTonalMDCTConc->pTCI->numIndexes, - hTonalMDCTConc->lastPitchLag, - pitchLag, - hTonalMDCTConc->lastBlockData.spectralData, - hTonalMDCTConc->lastBlockData.spectralData_exp, - hTonalMDCTConc->lastBlockData.scaleFactors, - hTonalMDCTConc->lastBlockData.scaleFactors_exp, - hTonalMDCTConc->lastBlockData.scaleFactors_max_e, - powerSpectrum, - powerSpectrum_exp, - nSamples, - hTonalMDCTConc->nSamplesCore, - floorPowerSpectrum, psychParamsCurrent, element_mode ); -#endif FindPhases( hTonalMDCTConc, secondLastMDCT, secondLastMDST, sub( secondLastMDST_exp, secondLastMDCT_exp ) ); @@ -879,10 +850,8 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( move16(); } -#ifdef HARMONIZE_FUNC IF( element_mode != EVS_MONO ) { -#endif IF( LT_16( old_power_spectrum_q, power_spectrum_q ) ) { Scale_sig32( powerSpectrum, length, sub( old_power_spectrum_q, power_spectrum_q ) ); // Q(old_power_spectrum_q-power_spectrum_q) @@ -894,9 +863,7 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( } Scale_sig32( powerSpectrum, nSamples, -3 ); /*Adding guard bits*/ // Q(31 - powerSpectrum_exp )-3 powerSpectrum_exp = add( powerSpectrum_exp, 3 ); -#ifdef HARMONIZE_FUNC } -#endif FOR( i = hTonalMDCTConc->nSamplesCore; i < nSamples; i++ ) { @@ -904,20 +871,16 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( move32(); } -#ifdef HARMONIZE_FUNC IF( element_mode == EVS_MONO ) { powerSpectrum_exp = sub( powerSpectrum_exp, hTonalMDCTConc->secondLastBlockData.gain_tcx_exp ); } ELSE { -#endif Word16 shift = Find_Max_Norm32( powerSpectrum, nSamples ); scale_sig32( powerSpectrum, nSamples, shift ); powerSpectrum_exp = sub( powerSpectrum_exp, shift ); -#ifdef HARMONIZE_FUNC } -#endif /* 16 bits are now enough for storing the power spectrum */ FOR( i = 0; i < nSamples; i++ ) @@ -933,123 +896,6 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( return; } -#ifndef HARMONIZE_FUNC -static void CalcPowerSpecAndDetectTonalComponents( - TonalMDCTConcealPtr const hTonalMDCTConc, - Word32 secondLastMDST[], // Q31-secondLastMDST_exp - Word16 secondLastMDST_exp, - Word32 secondLastMDCT[], // Q31-secondLastMDCT_exp - Word16 secondLastMDCT_exp, - Word32 const pitchLag, /*15Q16*/ - Word16 element_mode ) -{ - Word16 nSamples; - Word16 i; - Word16 floorPowerSpectrum; /* Minimum significant value of a spectral line in the power spectrum */ - Word32 powerSpectrum[L_FRAME_MAX]; - Word16 invScaleFactors[FDNS_NPTS]; - Word16 invScaleFactors_exp[FDNS_NPTS]; - Word16 powerSpectrum_exp, tmp_exp, old_exp; - - - nSamples = hTonalMDCTConc->nNonZeroSamples; - move16(); - - /* It is taken into account that the MDCT is not normalized. */ - floorPowerSpectrum /*Q0*/ = extract_l( Mpy_32_16_1( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 82 ) ); /*1/400 = 82 Q15*/ - powerSpectrum_exp = 0; - move16(); - - CalcPowerSpec( secondLastMDCT, - secondLastMDCT_exp, - secondLastMDST, - secondLastMDST_exp, - nSamples, - floorPowerSpectrum, - powerSpectrum, - &powerSpectrum_exp ); - - /* This setting to minimal level is required because the power spectrum is used in the threshold adaptation using the pitch up to hTonalMDCTConc->nSamples. */ - set32_fx( powerSpectrum + nSamples, floorPowerSpectrum, sub( hTonalMDCTConc->nSamples, nSamples ) ); - /* this setting to zero is needed since the FDNS needs to be called - with hTonalMDCTConc->nSamplesCore; it relevant only for nb; it has no effect - to the output, but memory checker may complain otherwise due to the - usage of uninitialized values */ - IF( GT_16( hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples ) ) - { - set32_fx( powerSpectrum + hTonalMDCTConc->nSamples, 0, sub( hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples ) ); - } - - DetectTonalComponents( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, - (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, - (Word16 *) hTonalMDCTConc->pTCI->upperIndex, - (Word16 *) &hTonalMDCTConc->pTCI->numIndexes, - hTonalMDCTConc->lastPitchLag, - pitchLag, - hTonalMDCTConc->lastBlockData.spectralData, - add( hTonalMDCTConc->lastBlockData.spectralData_exp, hTonalMDCTConc->lastBlockData.gain_tcx_exp ), - hTonalMDCTConc->lastBlockData.scaleFactors, - hTonalMDCTConc->lastBlockData.scaleFactors_exp, - hTonalMDCTConc->lastBlockData.scaleFactors_max_e, - powerSpectrum, - nSamples, - hTonalMDCTConc->nSamplesCore, - floorPowerSpectrum, element_mode ); - - FindPhases( hTonalMDCTConc, secondLastMDCT, secondLastMDST, sub( secondLastMDST_exp, secondLastMDCT_exp ) ); - - FindPhaseDifferences( hTonalMDCTConc, powerSpectrum ); - - IF( hTonalMDCTConc->pTCI->numIndexes > 0 ) - { - - hTonalMDCTConc->secondLastPowerSpectrum = hTonalMDCTConc->secondLastBlockData.spectralData; - - /*sqrtFLOAT(powerSpectrum, powerSpectrum, nSamples);*/ - old_exp = powerSpectrum_exp; - move16(); - powerSpectrum_exp = mult_r( sub( powerSpectrum_exp, 2 ), 1 << 14 ); /*remove 2 bits of headroom from CalcPowerSpec*/ - FOR( i = 0; i < nSamples; i++ ) - { - tmp_exp = old_exp; - move16(); - powerSpectrum[i] = Sqrt32( powerSpectrum[i], &tmp_exp ); // Q31- tmp_exp - powerSpectrum[i] = L_shr( powerSpectrum[i], sub( powerSpectrum_exp, tmp_exp ) ); // Q31- tmp_exp - move32(); - } - - FOR( i = 0; i < hTonalMDCTConc->nScaleFactors; i++ ) - { - move16(); - move16(); - invScaleFactors_exp[i] = hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]; - invScaleFactors[i] = Inv16( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i] ); // Q31 - invScaleFactors_exp[i] - } - - - /* here mdct_shaping() is intentionally used rather then mdct_shaping_16() */ - { - mdct_shaping( powerSpectrum, hTonalMDCTConc->nSamplesCore, invScaleFactors, invScaleFactors_exp ); - } - FOR( i = hTonalMDCTConc->nSamplesCore; i < nSamples; i++ ) - { - powerSpectrum[i] = L_shl_sat( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[FDNS_NPTS - 1] ), invScaleFactors_exp[FDNS_NPTS - 1] ); // powerSpectrum_exp+ 2*invScaleFactors_exp -15 - move32(); - } - - /* 16 bits are now enough for storing the power spectrum */ - FOR( i = 0; i < nSamples; i++ ) - { - hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx_sat( powerSpectrum[i] ); // Q31-powerSpectrum_exp - move32(); - } - - powerSpectrum_exp = sub( powerSpectrum_exp, hTonalMDCTConc->secondLastBlockData.gain_tcx_exp ); - hTonalMDCTConc->secondLastPowerSpectrum_exp = powerSpectrum_exp; - move16(); - } -} -#endif static void CalcMDXT( const TonalMDCTConcealPtr hTonalMDCTConc, @@ -1150,11 +996,7 @@ void TonalMDCTConceal_Detect_fx( } secondLastMDCT_exp = sub( secondLastMDCT_exp, s ); move16(); -#ifdef HARMONIZE_FUNC CalcPowerSpecAndDetectTonalComponents_fx( hTonalMDCTConc, secondLastMDST, secondLastMDST_exp, secondLastMDCT, secondLastMDCT_exp, pitchLag, NULL, element_mode ); -#else - CalcPowerSpecAndDetectTonalComponents( hTonalMDCTConc, secondLastMDST, secondLastMDST_exp, secondLastMDCT, secondLastMDCT_exp, pitchLag, element_mode ); -#endif } ELSE { @@ -1178,11 +1020,7 @@ void TonalMDCTConceal_Detect_fx( move32(); } -#ifdef HARMONIZE_FUNC RefineTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, -#else - RefineTonalComponents( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, -#endif (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, (Word16 *) hTonalMDCTConc->pTCI->upperIndex, hTonalMDCTConc->pTCI->phaseDiff, @@ -1196,16 +1034,10 @@ void TonalMDCTConceal_Detect_fx( hTonalMDCTConc->lastBlockData.scaleFactors_exp, hTonalMDCTConc->lastBlockData.scaleFactors_max_e, powerSpectrum, -#ifdef HARMONIZE_FUNC -1, -#endif nSamples, hTonalMDCTConc->nSamplesCore, -#ifdef HARMONIZE_FUNC extract_l( Mpy_32_16_1( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 82 ) ), element_mode, NULL ); -#else - extract_l( Mpy_32_16_1( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 82 ) ), element_mode ); /* floorPowerSpectrum */ -#endif } } } @@ -1295,11 +1127,7 @@ void TonalMDCTConceal_Detect_ivas_fx( } secondLastMDCT_exp = sub( secondLastMDCT_exp, s ); move16(); -#ifdef HARMONIZE_FUNC CalcPowerSpecAndDetectTonalComponents_fx( hTonalMDCTConc, secondLastMDST, secondLastMDST_exp, secondLastMDCT, secondLastMDCT_exp, pitchLag, psychParamsCurrent, element_mode ); -#else - ivas_CalcPowerSpecAndDetectTonalComponents_fx( hTonalMDCTConc, secondLastMDST, secondLastMDST_exp, secondLastMDCT, secondLastMDCT_exp, pitchLag, psychParamsCurrent, element_mode ); -#endif } ELSE { @@ -1348,11 +1176,7 @@ void TonalMDCTConceal_Detect_ivas_fx( powerSpectrum_exp = sub( 31, sub( shl( sub( Q31 - 3, powerSpectrum_exp ), 1 ), 31 ) ); } -#ifdef HARMONIZE_FUNC RefineTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, -#else - ivas_RefineTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, -#endif (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, (Word16 *) hTonalMDCTConc->pTCI->upperIndex, hTonalMDCTConc->pTCI->phaseDiff, diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index 45c285ead4d88db272373fba0c1a07eaa160ce2f..904577880ae89eb23a6d403c0f9ac050d9b66a1e 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -309,11 +309,7 @@ ivas_error acelp_core_enc_fx( set16_fx( st->mem_MA_fx, 0, M ); /* update synthesis filter memories */ -#ifdef HARMONIZE_FUNC synth_mem_updt2_fx( st->L_frame, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); -#else - synth_mem_updt2( st->L_frame, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); -#endif Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM ); // Q_new Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn1_fx, M ); /* hLPDmem->q_mem_syn */ Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn3, M ); /* hLPDmem->q_mem_syn */ @@ -840,12 +836,8 @@ ivas_error acelp_core_enc_fx( IF( NE_16( nelp_mode, 1 ) ) { Copy( exc_fx, exc2_fx, st->L_frame ); // Q_new -#ifdef HQ_ALIGN_DUPLICATED_CODE Word16 q_exc2 = Q_new; stat_noise_uv_enc_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, &q_exc2 ); -#else - stat_noise_uv_enc_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, Q_new ); -#endif } } ELSE @@ -859,11 +851,7 @@ ivas_error acelp_core_enc_fx( Copy( exc_fx, exc2_fx, st->L_frame ); // Q_new Word16 q_exc2 = Q_new; move16(); -#ifdef HQ_ALIGN_DUPLICATED_CODE stat_noise_uv_enc_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, &q_exc2 ); -#else - stat_noise_uv_enc_ivas_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, &q_exc2 ); -#endif } } diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c index ca617fec215f42c803a80f11e8674a0e32413835..c3ff039f9dcf7724fa088096a41000ca84ba89d7 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -207,11 +207,7 @@ void amr_wb_enc_fx( set16_fx( st->mem_MA_fx, 0, M ); /* update synthesis filter memories */ -#ifdef HARMONIZE_FUNC synth_mem_updt2_fx( L_FRAME, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn1_fx, hLPDmem->mem_syn, ENC ); -#else - synth_mem_updt2( L_FRAME, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn1_fx, hLPDmem->mem_syn, ENC ); -#endif Copy( hLPDmem->mem_syn1_fx, hLPDmem->mem_syn2, M ); /* q_mem_syn */ Copy( hLPDmem->old_exc, old_exc, L_EXC_MEM ); /* q_lpd_old_exc */ diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 6492e15c102ad0b83c20c6dd4ffd1b448bb9d192..7fae11949351474a433d43eab4d4fb491affb158 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -3776,12 +3776,8 @@ void coder_tcx_fx( IF( st->igf ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS Word16 q_spectrum = sub( Q31, *spectrum_e ); ProcessIGF_fx( st, 0, spectrum, &q_spectrum, NULL, 0, powerSpec, &powerSpec_e, 1, 0, 0, 0 ); -#else - ProcessIGF_fx( st->hIGFEnc, st, spectrum, spectrum_e, powerSpec, &powerSpec_e, 1, hTcxEnc->fUseTns[0], ( st->last_core == ACELP_CORE ), 0 ); -#endif } ShapeSpectrum_fx( hTcxCfg, A, gainlpc, gainlpc_e, diff --git a/lib_enc/core_enc_2div_fx.c b/lib_enc/core_enc_2div_fx.c index 25cd633400cd5783a80a04b93e5f8b4c53ab6499..3012bb094cfe97ad8d2084676ae69eac221d4f52 100644 --- a/lib_enc/core_enc_2div_fx.c +++ b/lib_enc/core_enc_2div_fx.c @@ -67,17 +67,13 @@ void core_encode_twodiv_fx( move16(); move16(); move16(); -#ifdef FIX_FLOAT_1536_INIT_NO_PARAM_LPC move16(); -#endif tnsSize[0] = 0; tnsSize[1] = 0; tnsBits[0] = 0; tnsBits[1] = 0; ltpBits = 0; -#ifdef FIX_FLOAT_1536_INIT_NO_PARAM_LPC no_param_lpc = 0; -#endif FOR( i = 0; i < 3; i++ ) { diff --git a/lib_enc/core_enc_init_fx.c b/lib_enc/core_enc_init_fx.c index 2e81df2787a82ec7264f182a12e103884be19e9a..aefe833bfcf1d029b595baee40bcc7114a021f46 100644 --- a/lib_enc/core_enc_init_fx.c +++ b/lib_enc/core_enc_init_fx.c @@ -712,11 +712,7 @@ static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old, const Word16 s Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); } -#ifdef HARMONIZE_FUNC synth_mem_updt2_fx( st->L_frame, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); -#else - synth_mem_updt2( st->L_frame, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); -#endif /*Mem of deemphasis stay unchanged : hLPDmem->syn*/ { @@ -1064,11 +1060,7 @@ void init_coder_ace_plus_ivas_fx( test(); IF( st->igf && st->hIGFEnc != NULL ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFEncSetMode_fx( st->hIGFEnc, igf_brate, st->bwidth, st->element_mode, st->rf_mode ); -#else - IGFEncSetMode_ivas_fx( st->hIGFEnc, igf_brate, st->bwidth, st->element_mode, st->rf_mode ); -#endif } ELSE IF( st->hIGFEnc != NULL ) { @@ -1697,11 +1689,7 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh /*Mem of deemphasis stay unchanged : hLPDmem->syn*/ IF( hLPDmem != NULL ) { -#ifdef HARMONIZE_FUNC synth_mem_updt2_fx( st->L_frame, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); -#else - ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); -#endif Word16 tmp, A[M + 1], Ap[M + 1], tmp_buf[M + 1]; /* Update wsyn */ /* lsp2a_stab( st->lsp_old, A, M ); */ diff --git a/lib_enc/enc_prm_fx.c b/lib_enc/enc_prm_fx.c index 943bd943ab66320dcdea068151cb9b1033da19b3..2c1b6b5d7c82490590b5e1896336b471c45bfb0b 100644 --- a/lib_enc/enc_prm_fx.c +++ b/lib_enc/enc_prm_fx.c @@ -786,19 +786,11 @@ void enc_prm_fx( move16(); IF( EQ_16( st->last_core, ACELP_CORE ) ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFEncWriteBitstream_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, IGF_GRID_LB_TRAN, 1, st->element_mode ); -#else - IGFEncWriteBitstream_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, IGF_GRID_LB_TRAN, 1 ); -#endif } ELSE { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFEncWriteBitstream_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, IGF_GRID_LB_NORM, 1, st->element_mode ); -#else - IGFEncWriteBitstream_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, IGF_GRID_LB_NORM, 1 ); -#endif } } total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); /* Q0 */ @@ -1113,11 +1105,7 @@ void writeTCXparam_fx( test(); IF( LT_16( st->element_mode, IVAS_CPE_MDCT ) && k == 0 && st->igf && EQ_16( core, TCX_10_CORE ) ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS nbits_igf = IGFEncWriteConcatenatedBitstream_fx( st->hIGFEnc, hBstr ); /* Q0 */ -#else - nbits_igf = IGFEncWriteConcatenatedBitstream_ivas_fx( st->hIGFEnc, hBstr ); /* Q0 */ -#endif } flag_ctx_hm = 0; @@ -1285,11 +1273,8 @@ void writeTCXparam_fx( } st->hIGFEnc->infoTotalBitsPerFrameWritten = 0; move16(); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncWriteBitstream_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, gridIdx, 1, st->element_mode ); -#else - IGFEncWriteBitstream_ivas_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, gridIdx, 1 ); -#endif } total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); /* Q0 */ diff --git a/lib_enc/ext_sig_ana_fx.c b/lib_enc/ext_sig_ana_fx.c index 9aa5c8d08a18bcff6a8d98e116fef264103765a0..f5b91249ff996820a63ea5fb9ce49eb484f9d713 100644 --- a/lib_enc/ext_sig_ana_fx.c +++ b/lib_enc/ext_sig_ana_fx.c @@ -74,10 +74,8 @@ void core_signal_analysis_high_bitrate_fx( (void) vad_hover_flag; (void) last_element_mode; -#ifdef FIX_BASOP_2470_POWER_SPEC_E_INIT powerSpec_e = 0; /* for TCX5, this is not initialized in AnalyzePowerSpectrum_fx(), but still passed to ProcessIGF_fx() */ move16(); -#endif left_overlap = -1; move16(); @@ -456,12 +454,8 @@ void core_signal_analysis_high_bitrate_fx( } IF( st->igf ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS Word16 q_spectrum = sub( Q31, spectrum_e[frameno] ); ProcessIGF_fx( st, 0, spectrum[frameno], &q_spectrum, NULL, 0, powerSpec, &powerSpec_e, transform_type[frameno] == TCX_20, frameno, 0, 0 ); -#else - ProcessIGF_fx( st->hIGFEnc, st, spectrum[frameno], &( spectrum_e[frameno] ), powerSpec, &powerSpec_e, transform_type[frameno] == TCX_20, hTcxEnc->fUseTns[frameno], ( st->last_core == ACELP_CORE ), frameno ); -#endif } /* Copy memory */ @@ -1261,11 +1255,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( IF( st->igf ) { Word16 q_spectrum = sub( Q31, hTcxEnc->spectrum_e[frameno] ); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS ProcessIGF_fx( st, N_MAX + L_MDCT_OVLP_MAX, hTcxEnc->spectrum_fx[frameno], &q_spectrum, hTcxEnc->spectrum_fx[frameno], q_spectrum, powerSpec, powerSpec_e, transform_type[frameno] == TCX_20, frameno, 0, vad_hover_flag ); -#else - ProcessIGF_ivas_fx( st, N_MAX + L_MDCT_OVLP_MAX, hTcxEnc->spectrum_fx[frameno], &q_spectrum, hTcxEnc->spectrum_fx[frameno], q_spectrum, powerSpec, powerSpec_e, transform_type[frameno] == TCX_20, frameno, 0, vad_hover_flag ); -#endif } } } diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index 493e5e8f365bfa2925a80d7179d4cab309e5bf08..6c7a8b6c07422bf44396daf75a3c55847c36d3ff 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -580,13 +580,8 @@ void gsc_enc_fx( * Frequency encoder *--------------------------------------------------------------------------------------*/ -#ifdef FIX_2467_RENAME_GSC_FUNCTION bands_and_bit_alloc_fx( hGSCEnc->cor_strong_limit, hGSCEnc->noise_lev, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, max_ener_band, bits_per_bands, &nb_subbands, exc_diff, concat_in, &pvq_len, st_fx->coder_type, st_fx->bwidth, st_fx->GSC_noisy_speech, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); -#else - bands_and_bit_alloc_ivas_fx( hGSCEnc->cor_strong_limit, hGSCEnc->noise_lev, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, max_ener_band, bits_per_bands, &nb_subbands, exc_diff, concat_in, &pvq_len, - st_fx->coder_type, st_fx->bwidth, st_fx->GSC_noisy_speech, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); -#endif Q_tmp = *Q_exc; move16(); diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index 5d2a3cce487dab43f5d818abb3a7d455e35f0561..91df70552a8225792ae6ff7a8f24a329731b547b 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -249,11 +249,7 @@ void hq_hr_enc_fx( { IF( NE_16( hqswb_clas, HQ_HVQ ) ) { -#ifdef HQ_ALIGN_DUPLICATED_CODE apply_envelope_enc_fx( t_audio_q_norm, ynrm, num_sfm, sfm_start, sfm_end, t_audio_q_fx ); -#else - apply_envelope_enc_ivas_fx( t_audio_q_norm, ynrm, num_sfm, sfm_start, sfm_end, t_audio_q_fx ); -#endif scale_sig32( t_audio_q_fx, length, sub( Q12, Q_audio ) ); // Q12 } diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 95c7bcb3f8da170d22367c286cea9df892aa7bc9..822bc8715b01c73971a9b29f84cacb37352616f4 100644 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -141,21 +141,13 @@ static void IGF_CalculateEnvelope( IGFCommonFuncsCalcSfbEnergyPowerSpec( hGrid->startSfb, hGrid->stopSfb, hGrid->swb_offset, LFPowerSpectrum, &PowerSpectrum_e, sfbEnergyTileC, sfbEnergyTileC_exp ); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFCommonFuncsMDCTSquareSpec( hGrid->startLine, hGrid->stopLine, LFMDCTSpectrum, MDCTSpectrum_e, LFMDCTSpectrum, &LFMDCTSpectrum_exp, 0, EVS_MONO ); -#else - IGFCommonFuncsMDCTSquareSpec( hGrid->startLine, hGrid->stopLine, LFMDCTSpectrum, MDCTSpectrum_e, LFMDCTSpectrum, &LFMDCTSpectrum_exp, 0 ); -#endif IGFCommonFuncsCalcSfbEnergyPowerSpec( hGrid->startSfb, hGrid->stopSfb, hGrid->swb_offset, LFMDCTSpectrum, &LFMDCTSpectrum_exp, sfbEnergyTileR, sfbEnergyTileR_exp ); } ELSE { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFCommonFuncsMDCTSquareSpec( hGrid->startLine, hGrid->stopLine, pMDCTSpectrum, MDCTSpectrum_e, LFMDCTSpectrum, &LFMDCTSpectrum_exp, 0, EVS_MONO ); -#else - IGFCommonFuncsMDCTSquareSpec( hGrid->startLine, hGrid->stopLine, pMDCTSpectrum, MDCTSpectrum_e, LFMDCTSpectrum, &LFMDCTSpectrum_exp, 0 ); -#endif IGFCommonFuncsCalcSfbEnergyPowerSpec( hGrid->startSfb, hGrid->stopSfb, hGrid->swb_offset, LFMDCTSpectrum, &LFMDCTSpectrum_exp, sfbEnergyR, sfbEnergyR_exp ); } @@ -255,71 +247,7 @@ static void IGF_CalculateEnvelope( return; } -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/**********************************************************************/ /* -writes IGF SCF values -**************************************************************************/ - -/**< out: Q0 | number of bits writen */ -static void IGF_WriteEnvelope( - const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : | instance handle of IGF Encoder */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *pBitOffset, /* i : | ptr to bitOffset counter */ - const Word16 igfGridIdx, /* i : Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 isIndepFlag, /* i : Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ - Word16 *igfAllZero /* i : Q0 | returns 1 if all IGF scfs are zero, else 0 */ -) -{ - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - H_IGF_GRID hGrid; - Word16 sfb; - - *igfAllZero = 1; - move16(); - hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - - FOR( sfb = hGrid->startSfb; sfb < hGrid->stopSfb; sfb++ ) - { - IF( hPrivateData->igfScfQuantized[sfb] != 0 ) - { - *igfAllZero = 0; - move16(); - BREAK; - } - } - - IF( *igfAllZero != 0 ) - { - IGF_write_bit_fx( hBstr, pBitOffset, 1 ); - if ( NULL == hBstr ) - { - IGFSCFEncoderSaveContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); - } - IGFSCFEncoderReset_fx( &hPrivateData->hIGFSCFArithEnc ); - if ( NULL == hBstr ) - { - IGFSCFEncoderRestoreContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); - } - } - ELSE - { - IGF_write_bit_fx( hBstr, pBitOffset, 0 ); - if ( NULL == hBstr ) - { - IGFSCFEncoderSaveContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); - } - - *pBitOffset = IGFSCFEncoderEncode_fx( &hPrivateData->hIGFSCFArithEnc, hBstr, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], igfGridIdx, isIndepFlag ); - move16(); - if ( NULL == hBstr ) - { - IGFSCFEncoderRestoreContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); - } - } -} -#else /*-------------------------------------------------------------------* * IGF_WriteEnvelope() * @@ -398,18 +326,19 @@ static Word16 IGF_WriteEnvelope( return totBitCount; } -#endif -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + + /**********************************************************************/ /* identifies significant spectral content **************************************************************************/ -void IGF_ErodeSpectrum( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - Word32 *pSpectrum, /**< in/out: | MDCT spectrum */ - Word32 *pPowerSpectrum, /**< in/out: | power spectrum */ - Word16 pPowerSpectrum_exp, /**< in: | exponent of power spectrum */ - const Word16 igfGridIdx, /**< in: Q0 | IGF grid index */ - const Word16 mct_on, /**< in: | flag that indicates mct on/off */ - const Word16 element_mode /**< in: | IVAS element mode type */ +void IGF_ErodeSpectrum( + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + Word32 *pSpectrum, /**< in/out: | MDCT spectrum */ + Word32 *pPowerSpectrum, /**< in/out: | power spectrum */ + Word16 pPowerSpectrum_exp, /**< in: | exponent of power spectrum */ + const Word16 igfGridIdx, /**< in: Q0 | IGF grid index */ + const Word16 mct_on, /**< in: | flag that indicates mct on/off */ + const Word16 element_mode /**< in: | IVAS element mode type */ ) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; @@ -626,971 +555,788 @@ void IGF_ErodeSpectrum( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in move16(); } } -#else + + /**********************************************************************/ /* -identifies significant spectral content +crest factor calculation **************************************************************************/ -void IGF_ErodeSpectrum( - Word16 *highPassEner_exp, /* o : exponent of highPassEner */ - const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : instance handle of IGF Encoder */ - Word32 *pSpectrum, /* i/o: MDCT spectrum */ - Word32 *pPowerSpectrum, /* i/o: power spectrum */ - Word16 pPowerSpectrum_exp, /* i : exponent of power spectrum */ - const Word16 igfGridIdx /* i : IGF grid index */ +/* o: Q15| crest factor */ +Word16 IGF_getCrest( + Word16 *crest_exp, /* o : exponent of crest factor */ + const Word32 *powerSpectrum, /* i : Q31 | power spectrum */ + const Word16 *powerSpectrum_exp, /* i : exponent of power spectrum */ + const Word16 start, /* i : Q0 | start subband index */ + const Word16 stop, /* i : Q0 | stop subband index */ + const Word16 element_mode /* i : IVAS element mode type */ ) { - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - H_IGF_GRID hGrid; Word16 i; - Word16 igfBgn; - Word16 igfEnd; - Word32 highPassEner; /* Q31 */ - Word32 lastLine; - Word32 nextLine; - Word32 highPassEner_Ovfl; + Word16 x; Word16 s; - Word16 tmploop; - Word16 *swb_offset; - Word16 sfb; - Word16 startSfb; - Word16 stopSfb; - Word16 line; - Word16 flag; - Word16 *igfScaleF; + Word32 x_eff32; + Word16 x_max; + Word16 crest; Word16 tmp; - Word32 L_tmp; + Word32 tmp32; + Word16 powSpec_exp; - hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - igfBgn = hGrid->startLine; - move16(); - igfEnd = hGrid->stopLine; - move16(); - swb_offset = hGrid->swb_offset; - move16(); - startSfb = hGrid->startSfb; + x_eff32 = 0; + move32(); + x_max = 0; move16(); - stopSfb = hGrid->stopSfb; + crest = 16384 /*.5f Q15*/; move16(); - igfScaleF = hPrivateData->igfScfQuantized; + *crest_exp = 1; move16(); - *highPassEner_exp = 0; + powSpec_exp = powerSpectrum_exp[0]; move16(); - highPassEner = 0; - move32(); - - IF( NULL == pPowerSpectrum ) - { - FOR( i = igfBgn; i < hGrid->infoGranuleLen; i++ ) - { - pSpectrum[i] = L_deposit_l( 0 ); - } - return; - } - IF( igfBgn > 0 ) + FOR( i = start; i < stop; i++ ) { - Word64 W_highPassEner = 0; - move64(); - FOR( i = 0; i < igfBgn; i++ ) - { - W_highPassEner = W_add( W_highPassEner, W_deposit32_l( Mpy_32_16_1( pPowerSpectrum[i], shl( i, 4 ) /*Q4*/ ) ) /*Q20, pPowerSpectrum_exp*/ ); - } - - highPassEner = w_norm_llQ31( W_highPassEner, highPassEner_exp ); /*Q20, highPassEner_exp*/ - *highPassEner_exp = add( *highPassEner_exp, pPowerSpectrum_exp ); - move16(); - test(); - test(); - if ( NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_9600 ) && - NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_RF_SWB_13200 ) && - NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_13200 ) ) - { - igfBgn = shl( igfBgn, 1 ); - } - highPassEner = L_deposit_l( BASOP_Util_Divide3216_Scale( highPassEner /*Q20, highPassEner_exp*/, igfBgn /*Q0*/, &s ) ); /*Q15, highPassEner_exp+11-16+s*/ - *highPassEner_exp = add( add( *highPassEner_exp, s ), 12 - 16 + ( 31 - 15 ) ); /*Q15->Q31,highPassEner_exp*/ - lastLine = pSpectrum[i - 1]; - move32(); - nextLine = 0; - move32(); - - /* May overflow - just for threshold comparison */ - /* negate because the negated may be 1 larger in abs, */ - /* so whenever compared to the negation of a maximum possible pPowerspectrum, it is still larger */ - highPassEner_Ovfl = L_shl_sat( L_negate( highPassEner ), sub( *highPassEner_exp, pPowerSpectrum_exp ) ); - L_tmp = L_add_sat( pPowerSpectrum[i - 1], highPassEner_Ovfl ); + /*x = max(0, (int)(log(powerSpectrum[i]) * INV_LOG_2));*/ - if ( L_tmp >= 0 ) - { - nextLine = pSpectrum[i]; - move32(); - } - tmploop = sub( igfEnd, 1 ); - FOR( /*i*/; i < tmploop; i++ ) + /*see IGF_getSFM for more comment */ + if ( GT_16( element_mode, EVS_MONO ) ) { - /* May overflow - just for threshold comparison */ - BASOP_SATURATE_WARNING_OFF_EVS - L_tmp = L_add_sat( pPowerSpectrum[i], highPassEner_Ovfl ); - BASOP_SATURATE_WARNING_ON_EVS; - - IF( L_tmp < 0 ) - { - lastLine = pSpectrum[i]; - move32(); - pSpectrum[i] = nextLine; - move32(); - nextLine = 0; - move32(); - } - ELSE - { - pSpectrum[i - 1] = lastLine; - move32(); - lastLine = pSpectrum[i]; - move32(); - nextLine = pSpectrum[i + 1]; - move32(); - } + powSpec_exp = powerSpectrum_exp[i]; /* exponent is a vector in IVAS (and a scalar in EVS) */ + move16(); } + x = sub( sub( powSpec_exp, norm_l( powerSpectrum[i] ) ), 1 ); /*Q0*/ - /* May overflow - just for threshold comparison */ - BASOP_SATURATE_WARNING_OFF_EVS - L_tmp = L_add_sat( pPowerSpectrum[i], highPassEner_Ovfl ); - BASOP_SATURATE_WARNING_ON_EVS - if ( L_tmp < 0 ) + if ( powerSpectrum[i] == 0 ) /*special case: energy is zero*/ { - pSpectrum[i] = L_deposit_l( 0 ); - move32(); + x = 0; + move16(); } + x = s_max( 0, x ); + x_eff32 = L_mac0( x_eff32, x, x ); /*Q0*/ + x_max = s_max( x_max, x ); /*Q0*/ } - /* delete spectrum above igfEnd: */ - FOR( i = igfEnd; i < hGrid->infoGranuleLen; i++ ) - { - pSpectrum[i] = L_deposit_l( 0 ); - move32(); - pPowerSpectrum[i] = L_deposit_l( 0 ); - move32(); - } + /*x_eff /= (stop - start);*/ + x_eff32 = BASOP_Util_Divide3216_Scale( x_eff32, sub( stop, start ), &s ); /*Q-1, s*/ + s = add( s, 32 ); /*make x_eff Q31*/ - FOR( sfb = startSfb; sfb < stopSfb; sfb++ ) + /*trunkate to int*/ + x_eff32 = L_shr( x_eff32, sub( 31, s ) ); + x_eff32 = L_shl( x_eff32, sub( 31, s ) ); + + test(); + IF( x_eff32 > 0 && x_max > 0 ) { - flag = 0; - move16(); - FOR( line = swb_offset[sfb]; line < swb_offset[sfb + 1]; line++ ) - { - if ( pSpectrum[line] != 0 ) - { - flag = 1; - move16(); - } - } - tmp = igfScaleF[sfb]; + /*crest = max(1.f, (float)x_max/sqrt(x_eff));*/ + tmp32 = ISqrt32( x_eff32, &s ); /*Q31, s*/ + tmp32 = Mpy_32_16_1( tmp32 /*Q31, s*/, x_max /*Q0*/ ); /*Q16, s*/ + i = norm_l( tmp32 ); + tmp32 = L_shl( tmp32, i ); /*Q31, s-i+15*/ + crest = extract_h( tmp32 ); + *crest_exp = add( sub( s, i ), 15 ); move16(); - if ( flag ) + /* limit crest factor to a lower bound of 1, may overflow */ + BASOP_SATURATE_WARNING_OFF_EVS + tmp = shl_sat( -1, sub( 15, *crest_exp ) ); /* build negative threshold */ + tmp = add_sat( crest, tmp ); + BASOP_SATURATE_WARNING_ON_EVS + if ( tmp < 0 ) { - tmp = sub( igfScaleF[sfb], 1 ); + crest = 1; + move16(); } - if ( igfScaleF[sfb] ) + if ( tmp < 0 ) { - igfScaleF[sfb] = tmp; + *crest_exp = 15; move16(); } } - return; + return crest; } -void IGF_ErodeSpectrum_ivas_fx( - const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : instance handle of IGF Encoder */ - Word32 *pSpectrum, /* i/o: MDCT spectrum Qx*/ - Word32 *pPowerSpectrum, /* i/o: power spectrum */ - Word16 pPowerSpectrum_exp, /* i : exponent of power spectrum */ - const Word16 igfGridIdx, /* i : IGF grid index */ - const Word16 mct_on ) +/************************************************************************* +calculates spectral flatness measurment +**************************************************************************/ + +/* o: Q15| SFM value */ +Word16 IGF_getSFM( + Word16 *SFM_exp, /* o : | exponent of SFM Factor */ + const Word32 *energy, /* i : Q31| energies */ + const Word16 *energy_exp, /* i : | exponent of energies */ + const Word16 start, /* i : Q0 | start subband index */ + const Word16 stop, /* i : Q0 | stop subband index */ + const Word16 element_mode /* i : | IVAS element mode type */ +) { - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - H_IGF_GRID hGrid; - Word16 i; - Word16 igfBgn; - Word16 igfEnd; - Word32 highPassEner; /* Q31 */ - Word32 lastLine; - Word32 nextLine; - Word16 *swb_offset; - Word16 sfb; - Word16 startSfb; - Word16 stopSfb; - Word16 line; - Word16 *igfScaleF; - Word16 tmp; - Word16 factor; - Word16 exp1, exp2; - Word16 num, den; - Word32 temp; + Word16 n, i, s; + Word32 num; + Word32 denom; + Word16 denom_exp; + Word16 invDenom_exp, numf_exp; + Word16 numf; + Word32 SFM32; + Word16 invDenom, SFM; + Word64 W_denom; + Word16 en_exp; - hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - igfBgn = hGrid->startLine; - move16(); - igfEnd = hGrid->stopLine; - move16(); - swb_offset = hGrid->swb_offset; + num = 0; + move32(); + *SFM_exp = 0; move16(); - startSfb = hGrid->startSfb; + SFM = 32767 /*1.0f Q15*/; move16(); - stopSfb = hGrid->stopSfb; + en_exp = energy_exp[0]; move16(); - igfScaleF = hPrivateData->igfScfQuantized; + denom_exp = 0; move16(); - - IF( NULL == pPowerSpectrum ) + W_denom = 0; + move64(); + if ( EQ_16( element_mode, EVS_MONO ) ) { - FOR( i = igfBgn; i < hGrid->infoGranuleLen; i++ ) - { - pSpectrum[i] = 0; - move32(); - } - return; + denom = L_shr( 2147483 /*0,001 in Q31 - float is "1", here*/, s_min( en_exp, 31 ) ); + denom = L_max( denom, 1 ); + move32(); + move32(); + W_denom = W_deposit32_l( denom ); + move64(); + } + else + { + denom = 65536; // 1.f in Q16 + move32(); + denom_exp = 15; + move16(); } - IF( igfBgn > 0 ) + /*ln(x * 2^-Qx * 2^xExp) = ln(x) - Qx + xExp*/ + /* n = sub(sub(31,norm_l(tmp32)),1); */ /*<- ld */ + /* n = sub(n,31); */ /*<- -Qx */ + /* n = add(n,*energy_exp); */ /*<- +xExp */ + IF( EQ_16( element_mode, EVS_MONO ) ) { - Word64 sum = 0; - move64(); - FOR( i = 0; i < igfBgn; i++ ) + FOR( i = start; i < stop; i++ ) { - sum = W_mac_32_16( sum, pPowerSpectrum[i], i ); // Q: 31-pPowerSpectrum_exp+1 - } - exp1 = W_norm( sum ); - sum = W_shl( sum, sub( exp1, 1 ) ); // Q: 31-pPowerSpectrum_exp+1+exp1-1 - num = extract_h( W_extract_h( sum ) ); // Q: 31-pPowerSpectrum_exp+exp1-48 = -pPowerSpectrum_exp+exp1-17 - exp1 = add( 32, sub( pPowerSpectrum_exp, exp1 ) ); // exp: 32+pPowerSpectrum_exp-exp1 + n = sub( sub( en_exp, norm_l( energy[i] ) ), 1 ); /*<-- short form*/ - IF( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_9600 ) || - EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_RF_SWB_13200 ) || - EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_13200 ) || - EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_16400_CPE ) ) - { - factor = ONE_IN_Q14; // Q14 - move16(); - } - ELSE IF( mct_on && ( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_64000_CPE ) ) ) - { - factor = 11469; // 0.7f in Q14 - move16(); + if ( energy[i] == 0 ) /*special case: energy is zero*/ + { + n = 0; + move16(); + } + + n = s_max( 0, n ); + num = L_add( num, L_deposit_l( n ) ); /*Q0*/ + W_denom = W_add( W_deposit32_l( energy[i] ), W_denom ); } - ELSE + } + ELSE + { + FOR( i = start; i < stop; i++ ) { - factor = 32767; // 2.f in Q14 + en_exp = energy_exp[i]; /* exponent is a vector in IVAS (and a scalar in EVS) */ move16(); - } - - temp = L_mult( igfBgn, factor ); // exp: 16 - exp2 = norm_l( temp ); - den = extract_h( L_shl( temp, exp2 ) ); // exp: 16-exp2 - exp2 = sub( 16, exp2 ); - - highPassEner = L_deposit_h( div_s( num, den ) ); // exp: exp1-exp2 - - /* highPassEner is used only for comparison, saturation doesn't effect the outcome */ - highPassEner = L_shl_sat( highPassEner, sub( sub( exp1, exp2 ), pPowerSpectrum_exp ) ); // exp: pPowerSpectrum_exp - - lastLine = pSpectrum[i - 1]; // Qx - move32(); - nextLine = pSpectrum[i]; // Qx - move32(); - - if ( LT_32( pPowerSpectrum[i - 1], highPassEner ) ) - { - nextLine = 0; - move32(); - } + n = sub( sub( en_exp, norm_l( energy[i] ) ), 1 ); /*<-- short form*/ - FOR( /*i*/; i < igfEnd - 1; i++ ) - { - /* May overflow - just for threshold comparison */ - IF( LT_32( pPowerSpectrum[i], highPassEner ) ) - { - lastLine = pSpectrum[i]; // Qx - move32(); - pSpectrum[i] = nextLine; // Qx - move32(); - nextLine = 0; - move32(); - } - ELSE + if ( energy[i] == 0 ) /*special case: energy is zero*/ { - pSpectrum[i - 1] = lastLine; // Qx - move32(); - lastLine = pSpectrum[i]; // Qx - move32(); - nextLine = pSpectrum[i + 1]; // Qx - move32(); + n = 0; + move16(); } - } - /* May overflow - just for threshold comparison */ - if ( LT_32( pPowerSpectrum[i], highPassEner ) ) - { - pSpectrum[i] = 0; - move32(); + n = s_max( 0, n ); + num = L_add( num, L_deposit_l( n ) ); /*Q0*/ + denom = BASOP_Util_Add_Mant32Exp( energy[i], en_exp, denom, denom_exp, &denom_exp ); } } - /* delete spectrum above igfEnd: */ - FOR( i = igfEnd; i < hGrid->infoGranuleLen; i++ ) + IF( EQ_16( element_mode, EVS_MONO ) ) { - pSpectrum[i] = 0; - pPowerSpectrum[i] = 0; - move32(); - move32(); + denom = w_norm_llQ31( W_denom, &denom_exp ); /*Q31*/ + denom_exp = add( denom_exp, en_exp ); } - // Below check is present at the beginning of the function and is not required here - /* IF( NULL != pPowerSpectrum ) */ + /* calculate SFM only if signal is present */ + IF( denom != 0 ) { - FOR( sfb = startSfb; sfb < stopSfb; sfb++ ) - { - tmp = 0; - move16(); - FOR( line = swb_offset[sfb]; line < swb_offset[sfb + 1]; line++ ) - { - if ( pSpectrum[line] != 0 ) - { - tmp = add( tmp, 1 ); - } - } + /*numf = (float)num / (float)(stop - start);*/ + numf = BASOP_Util_Divide3216_Scale( num, /*Q0*/ + sub( stop, start ), /*Q0*/ + &s ); /*Q-1 s*/ + numf_exp = add( s, 16 ); /*-> numf Q15 numf_exp*/ + /*denom /= (float)(stop - start);*/ + /*return ((float)pow(2.0, numf + 0.5f) / denom);*/ + + /*SFM= ((float)pow(2.0, numf + 0.5f) * invDenom);*/ + invDenom = BASOP_Util_Divide3232_uu_1616_Scale( L_deposit_l( sub( stop, start ) ) /*Q0*/, + denom /*Q31, denom_exp*/, + &s ); /*Q-16, s-denom_exp*/ + invDenom_exp = add( sub( s, denom_exp ), 31 ); /*invDenom: Q15, invDenom_exp*/ + + /*add .5f to numf*/ + SFM32 = L_add( L_shl( L_deposit_l( numf ), numf_exp ) /*16Q15*/, 16384l /*.5f Q15*/ ); /*16Q15*/ + s = norm_l( SFM32 ); + SFM32 = L_shl( SFM32, s ); + s = sub( 16, s ); /*SFM32(numf) is Q31 now*/ - Word16 igfScaleF_cnt = igfScaleF[sfb]; + /*do the pow2 and the mult*/ + SFM32 = BASOP_util_Pow2( SFM32, s, &s ); + SFM32 = Mpy_32_16_1( SFM32, invDenom ); + *SFM_exp = add( s, invDenom_exp ); + + /*Transform to Q15*/ + s = norm_l( SFM32 ); + SFM = round_fx_sat( L_shl_sat( SFM32, s ) ); + *SFM_exp = sub( *SFM_exp, s ); + move16(); + /**SFM_exp = s_min(*SFM_exp, 0);*/ + IF( *SFM_exp > 0 ) + { + *SFM_exp = 0; move16(); - test(); - if ( tmp && igfScaleF[sfb] ) - { - igfScaleF_cnt = sub( igfScaleF[sfb], 1 ); - } - igfScaleF[sfb] = igfScaleF_cnt; + SFM = 32767 /*1.0f Q15*/; move16(); } } + + return SFM /*Q15*/; } -#endif -/**********************************************************************/ /* -crest factor calculation -**************************************************************************/ -/* o: Q15| crest factor */ -Word16 IGF_getCrest( - Word16 *crest_exp, /* o : exponent of crest factor */ - const Word32 *powerSpectrum, /* i : Q31 | power spectrum */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - const Word16 *powerSpectrum_exp, /* i : exponent of power spectrum */ -#else - const Word16 powerSpectrum_exp, /* i : exponent of power spectrum */ -#endif - const Word16 start, /* i : Q0 | start subband index */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - const Word16 stop, /* i : Q0 | stop subband index */ - const Word16 element_mode /* i : IVAS element mode type */ -#else - const Word16 stop /* i : Q0 | stop subband index */ -#endif +/*-------------------------------------------------------------------* + * IGF_getCrest_new() + * + * crest factor calculation + *-------------------------------------------------------------------*/ + +/*! r: crest factor */ +static Word16 IGF_getCrest_new_fx( + const Word16 *logSpec, /* i : power spectrum */ + const Word16 start, /* i : start subband index */ + const Word16 stop, /* i : stop subband index */ + Word16 *crest_exp /*Stores the exponent of the result(return value)*/ ) { Word16 i; Word16 x; - Word16 s; - Word32 x_eff32; + Word32 x_eff; Word16 x_max; - Word16 crest; - Word16 tmp; - Word32 tmp32; -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - Word16 powSpec_exp; -#endif - - x_eff32 = 0; - move32(); + Word16 exp; + Word16 temp; + Word16 temp_e; + Word16 crest; /*1.0f in Q15*/ + x_eff = 0; x_max = 0; + exp = 0; + temp = 0; + crest = 32767; /*1.0f in Q15*/ + move32(); move16(); - crest = 16384 /*.5f Q15*/; move16(); - *crest_exp = 1; move16(); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - powSpec_exp = powerSpectrum_exp[0]; move16(); -#endif FOR( i = start; i < stop; i++ ) { - /*x = max(0, (int)(log(powerSpectrum[i]) * INV_LOG_2));*/ + x = logSpec[i]; + move16(); + x_eff = L_mac0( x_eff, x, x ); - /*see IGF_getSFM for more comment */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - if ( GT_16( element_mode, EVS_MONO ) ) - { - powSpec_exp = powerSpectrum_exp[i]; /* exponent is a vector in IVAS (and a scalar in EVS) */ - move16(); - } - x = sub( sub( powSpec_exp, norm_l( powerSpectrum[i] ) ), 1 ); /*Q0*/ -#else - x = sub( sub( powerSpectrum_exp, norm_l( powerSpectrum[i] ) ), 1 ); /*Q0*/ -#endif - if ( powerSpectrum[i] == 0 ) /*special case: energy is zero*/ + if ( GT_16( x, x_max ) ) { - x = 0; + x_max = x; move16(); } - x = s_max( 0, x ); - x_eff32 = L_mac0( x_eff32, x, x ); /*Q0*/ - x_max = s_max( x_max, x ); /*Q0*/ } - /*x_eff /= (stop - start);*/ - x_eff32 = BASOP_Util_Divide3216_Scale( x_eff32, sub( stop, start ), &s ); /*Q-1, s*/ - s = add( s, 32 ); /*make x_eff Q31*/ - - /*trunkate to int*/ - x_eff32 = L_shr( x_eff32, sub( 31, s ) ); - x_eff32 = L_shl( x_eff32, sub( 31, s ) ); + x_eff = BASOP_Util_Divide3216_Scale( x_eff, sub( stop, start ), &temp_e ); + temp_e = add( temp_e, 16 ); /*exp += 31 - 15 + 16(because x_eff is word32)*/ + x_eff = L_shr( x_eff, sub( 15, temp_e ) ); + temp_e = 15; + move16(); + temp = Sqrt16( extract_l( x_eff ), &temp_e ); test(); - IF( x_eff32 > 0 && x_max > 0 ) + IF( x_eff > 0 && x_max > 0 ) { - /*crest = max(1.f, (float)x_max/sqrt(x_eff));*/ - tmp32 = ISqrt32( x_eff32, &s ); /*Q31, s*/ - tmp32 = Mpy_32_16_1( tmp32 /*Q31, s*/, x_max /*Q0*/ ); /*Q16, s*/ - i = norm_l( tmp32 ); - tmp32 = L_shl( tmp32, i ); /*Q31, s-i+15*/ - crest = extract_h( tmp32 ); - *crest_exp = add( sub( s, i ), 15 ); - move16(); - /* limit crest factor to a lower bound of 1, may overflow */ - BASOP_SATURATE_WARNING_OFF_EVS - tmp = shl_sat( -1, sub( 15, *crest_exp ) ); /* build negative threshold */ - tmp = add_sat( crest, tmp ); - BASOP_SATURATE_WARNING_ON_EVS - if ( tmp < 0 ) - { - crest = 1; - move16(); - } - if ( tmp < 0 ) + temp = BASOP_Util_Divide1616_Scale( x_max, temp, &exp ); + exp = add( exp, sub( 15, temp_e ) ); + IF( exp < 0 ) { - *crest_exp = 15; + temp = shl( temp, exp ); + exp = 0; move16(); } + crest = s_max( shl_sat( 1, sub( 15, exp ) ), temp ); } - + *crest_exp = exp; + move16(); return crest; } -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/* o: Q15| crest factor */ -Word16 IGF_getCrest_ivas( - Word16 *crest_exp, /* o : | exponent of crest factor */ - const Word32 *powerSpectrum, /* i : Q31 | power spectrum */ - const Word16 *powerSpectrum_exp, /* i : | exponent of power spectrum */ - const Word16 start, /* i : Q0 | start subband index */ - const Word16 stop /* i : Q0 | stop subband index */ +/*-------------------------------------------------------------------* + * IGF_getSFM_new() + * + * calculates spectral flatness measurement + *-------------------------------------------------------------------*/ + +/*! r: SFM value */ +static Word16 IGF_getSFM_new_fx( + const Word32 *powerSpectrum, /* i : power spectrum */ + const Word16 *logSpec, /* i : log of power spectrum */ + const Word16 start, /* i : start subband index */ + const Word16 stop, /* i : stop subband index */ + Word16 *e_ps /*Stores exp related to power spectrum*/ ) { + Word16 n; Word16 i; - Word16 x; - Word16 s; - Word32 x_eff32; - Word16 x_max; - Word16 crest; - Word16 tmp; - Word32 tmp32; + Word16 num; + Word32 denom; + Word16 numf; + Word32 tmp; + Word16 sfm; + Word16 sfm_e; + Word16 denom_e; + Word16 numf_e; /*stores exponent for numf*/ + Word16 tmp_e; - x_eff32 = 0; - move32(); - x_max = 0; + num = 0; + denom = ONE_IN_Q30; + denom_e = 1; + sfm = MAX16B; // Q15 move16(); - crest = 16384 /*.5f Q15*/; + move32(); move16(); - *crest_exp = 1; move16(); FOR( i = start; i < stop; i++ ) { - /*x = max(0, (int)(log(powerSpectrum[i]) * INV_LOG_2));*/ - - /*see IGF_getSFM for more comment */ - x = sub( sub( powerSpectrum_exp[i], norm_l( powerSpectrum[i] ) ), 1 ); /*Q0*/ - if ( powerSpectrum[i] == 0 ) /*special case: energy is zero*/ - { - x = 0; - move16(); - } - x = s_max( 0, x ); - x_eff32 = L_mac0( x_eff32, x, x ); /*Q0*/ - x_max = s_max( x_max, x ); /*Q0*/ + tmp = powerSpectrum[i]; + n = logSpec[i /*-start*/]; + move32(); + move16(); + num = add( num, n ); + denom = BASOP_Util_Add_Mant32Exp( tmp, e_ps[i], denom, denom_e, &denom_e ); } - /*x_eff /= (stop - start);*/ - x_eff32 = BASOP_Util_Divide3216_Scale( x_eff32, sub( stop, start ), &s ); /*Q-1, s*/ - s = add( s, 32 ); /*make x_eff Q31*/ - - /*trunkate to int*/ - x_eff32 = L_shr( x_eff32, sub( 31, s ) ); - x_eff32 = L_shl( x_eff32, sub( 31, s ) ); + numf = BASOP_Util_Divide1616_Scale( num, sub( stop, start ), &numf_e ); + denom = BASOP_Util_Divide3216_Scale( denom, sub( stop, start ), &tmp_e ); + denom_e = add( add( denom_e, tmp_e ), 1 ); /*denom_e+tmp_e-15 +16(because type of denom is word32)*/ - test(); - IF( x_eff32 > 0 && x_max > 0 ) + IF( denom != 0 ) { - /*crest = max(1.f, (float)x_max/sqrt(x_eff));*/ - tmp32 = ISqrt32( x_eff32, &s ); /*Q31, s*/ - tmp32 = Mpy_32_16_1( tmp32 /*Q31, s*/, x_max /*Q0*/ ); /*Q16, s*/ - i = norm_l( tmp32 ); - tmp32 = L_shl( tmp32, i ); /*Q31, s-i+15*/ - crest = extract_h( tmp32 ); - *crest_exp = add( sub( s, i ), 15 ); - move16(); - /* limit crest factor to a lower bound of 1, may overflow */ - BASOP_SATURATE_WARNING_OFF_EVS - tmp = shl_sat( -1, sub( 15, *crest_exp ) ); /* build negative threshold */ - tmp = add_sat( crest, tmp ); - BASOP_SATURATE_WARNING_ON_EVS - if ( tmp < 0 ) - { - crest = 1; - move16(); - } - if ( tmp < 0 ) - { - *crest_exp = 15; - move16(); - } + tmp = BASOP_util_Pow2( L_add( numf, shl_sat( 1, sub( 14, numf_e ) ) ), add( 16, numf_e ), &tmp_e ); + sfm = BASOP_Util_Divide3232_Scale( tmp, denom, &sfm_e ); + sfm_e = add( sfm_e, sub( tmp_e, denom_e ) ); + sfm = shl_sat( extract_l( L_min( sfm, L_shl_sat( 1, sub( 15, sfm_e ) ) ) ), sfm_e ); } - return crest; + return sfm; } -#endif +/*-------------------------------------------------------------------* + * IGF_Whitening() + * + * calculates the IGF whitening levels by SFM and crest + *-------------------------------------------------------------------*/ -/************************************************************************* -calculates spectral flatness measurment -**************************************************************************/ - -/* o: Q15| SFM value */ -Word16 IGF_getSFM( - Word16 *SFM_exp, /* o : | exponent of SFM Factor */ - const Word32 *energy, /* i : Q31| energies */ - const Word16 *energy_exp, /* i : | exponent of energies */ - const Word16 start, /* i : Q0 | start subband index */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - const Word16 stop, /* i : Q0 | stop subband index */ - const Word16 element_mode /* i : | IVAS element mode type */ -#else - const Word16 stop /* i : Q0 | stop subband index */ -#endif +static void IGF_Whitening( + const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : | instance handle of IGF Encoder */ + Word32 *powerSpectrum, /* i : Q31 | MDCT/MDST power spectrum */ + Word16 *powerSpectrum_e, /* i : Q31 | MDCT/MDST power spectrum */ + const Word16 igfGridIdx, /* i : Q0 | IGF grid index */ + const Word16 isTransient, /* i : Q0 | flag indicating if transient is detected */ + const Word16 last_core_acelp, /* i : Q0 | indicator if last frame was ACELP core */ + const Word16 isTNSActive, /* i : Q0 | indicator if TNS is active */ + const Word16 sp_aud_decision0, /* i : Q0 | first stage classifier decision */ + const Word32 brate, /* i : Q0 | bitrate */ + const Word16 element_mode /* i : Q0 | element mode */ ) { - Word16 n, i, s; - Word32 num; - Word32 denom; - Word16 denom_exp; - Word16 invDenom_exp, numf_exp; - Word16 numf; + IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; + H_IGF_GRID hGrid; + Word16 p; /*Q0*/ + Word16 tmp; + Word16 tmp_e; + Word16 SFM_src; + Word16 SFM_tar; + Word16 SFM_src_e; + Word16 SFM_tar_e; + Word16 num_Tiles; + Word16 SFM; + Word16 SFM_e; Word32 SFM32; - Word16 invDenom, SFM; -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - Word64 W_denom; - Word16 en_exp; - -#else - move32(); - move32(); + Word16 crest; + Word16 s; + Word32 tmp32; + Word16 crest_e; - move32(); -#endif - num = 0; - move32(); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - *SFM_exp = 0; - move16(); - SFM = 32767 /*1.0f Q15*/; - move16(); - en_exp = energy_exp[0]; - move16(); - denom_exp = 0; + SFM = -ONE_IN_Q13; /*1.0f Q13*/ + tmp_e = 0; + crest = 0; + tmp32 = 0; move16(); - W_denom = 0; - move64(); - if ( EQ_16( element_mode, EVS_MONO ) ) - { - denom = L_shr( 2147483 /*0,001 in Q31 - float is "1", here*/, s_min( en_exp, 31 ) ); - denom = L_max( denom, 1 ); - move32(); - move32(); - W_denom = W_deposit32_l( denom ); - move64(); - } - else - { - denom = 65536; // 1.f in Q16 - move32(); - denom_exp = 15; - move16(); - } -#else - denom = L_shr( 2147483 /*0,001 in Q31 - float is "1", here*/, s_min( *energy_exp, 31 ) ); - denom = L_max( denom, 1 ); - *SFM_exp = 0; move16(); - SFM = 32767 /*1.0f Q15*/; move16(); + move32(); - Word64 W_denom = W_deposit32_l( denom ); -#endif - /*ln(x * 2^-Qx * 2^xExp) = ln(x) - Qx + xExp*/ - /* n = sub(sub(31,norm_l(tmp32)),1); */ /*<- ld */ - /* n = sub(n,31); */ /*<- -Qx */ - /* n = add(n,*energy_exp); */ /*<- +xExp */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - if ( EQ_16( element_mode, EVS_MONO ) ) - { -#endif - FOR( i = start; i < stop; i++ ) - { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - n = sub( sub( en_exp, norm_l( energy[i] ) ), 1 ); /*<-- short form*/ -#else - n = sub( sub( *energy_exp, norm_l( energy[i] ) ), 1 ); /*<-- short form*/ -#endif - - if ( energy[i] == 0 ) /*special case: energy is zero*/ - { - n = 0; - move16(); - } + hPrivateData = &hIGFEnc->igfData; + hGrid = &hPrivateData->igfInfo.grid[(Word16) igfGridIdx]; - n = s_max( 0, n ); - num = L_add( num, L_deposit_l( n ) ); /*Q0*/ - W_denom = W_add( W_deposit32_l( energy[i] ), W_denom ); - } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - } - else + IF( NE_16( igfGridIdx, IGF_GRID_LB_NORM ) ) { - FOR( i = start; i < stop; i++ ) + FOR( p = 0; p < hGrid->nTiles; p++ ) { - en_exp = energy_exp[i]; /* exponent is a vector in IVAS (and a scalar in EVS) */ + /* reset filter */ + hPrivateData->prevSFM_FIR[p] = L_deposit_l( 0 ); + hPrivateData->prevSFM_IIR[p] = 0; move16(); - n = sub( sub( en_exp, norm_l( energy[i] ) ), 1 ); /*<-- short form*/ - if ( energy[i] == 0 ) /*special case: energy is zero*/ - { - n = 0; - move16(); - } - - n = s_max( 0, n ); - num = L_add( num, L_deposit_l( n ) ); /*Q0*/ - denom = BASOP_Util_Add_Mant32Exp( energy[i], en_exp, denom, denom_exp, &denom_exp ); + /* preset values: */ + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; + move16(); } } -#endif -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - IF( EQ_16( element_mode, EVS_MONO ) ) - { - denom = w_norm_llQ31( W_denom, &denom_exp ); /*Q31*/ - denom_exp = add( denom_exp, en_exp ); - } -#else - denom = w_norm_llQ31( W_denom, &denom_exp ); /*Q31*/ - denom_exp = add( denom_exp, *energy_exp ); -#endif - - /* calculate SFM only if signal is present */ - IF( denom != 0 ) - { - /*numf = (float)num / (float)(stop - start);*/ - numf = BASOP_Util_Divide3216_Scale( num, /*Q0*/ - sub( stop, start ), /*Q0*/ - &s ); /*Q-1 s*/ - numf_exp = add( s, 16 ); /*-> numf Q15 numf_exp*/ - /*denom /= (float)(stop - start);*/ - /*return ((float)pow(2.0, numf + 0.5f) / denom);*/ - - /*SFM= ((float)pow(2.0, numf + 0.5f) * invDenom);*/ - invDenom = BASOP_Util_Divide3232_uu_1616_Scale( L_deposit_l( sub( stop, start ) ) /*Q0*/, - denom /*Q31, denom_exp*/, - &s ); /*Q-16, s-denom_exp*/ - invDenom_exp = add( sub( s, denom_exp ), 31 ); /*invDenom: Q15, invDenom_exp*/ - - /*add .5f to numf*/ - SFM32 = L_add( L_shl( L_deposit_l( numf ), numf_exp ) /*16Q15*/, 16384l /*.5f Q15*/ ); /*16Q15*/ - s = norm_l( SFM32 ); - SFM32 = L_shl( SFM32, s ); - s = sub( 16, s ); /*SFM32(numf) is Q31 now*/ - - /*do the pow2 and the mult*/ - SFM32 = BASOP_util_Pow2( SFM32, s, &s ); - SFM32 = Mpy_32_16_1( SFM32, invDenom ); - *SFM_exp = add( s, invDenom_exp ); - - /*Transform to Q15*/ - s = norm_l( SFM32 ); - SFM = round_fx_sat( L_shl_sat( SFM32, s ) ); - *SFM_exp = sub( *SFM_exp, s ); - move16(); - /**SFM_exp = s_min(*SFM_exp, 0);*/ - IF( *SFM_exp > 0 ) - { - *SFM_exp = 0; - move16(); - SFM = 32767 /*1.0f Q15*/; - move16(); - } - } - - return SFM /*Q15*/; -} - -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/************************************************************************* -calculates spectral flatness measurment -**************************************************************************/ - -/* o: Q15| SFM value */ -Word16 IGF_getSFM_ivas_fx( - Word16 *SFM_exp, /* o : | exponent of SFM Factor */ - const Word32 *energy, /* i : Q31| energies */ - const Word16 *energy_exp, /* i : | exponent of energies */ - const Word16 start, /* i : Q0 | start subband index */ - const Word16 stop /* i : Q0 | stop subband index */ -) -{ - Word16 n, i, s; - Word32 num; - Word32 denom; - Word16 denom_exp; - Word16 invDenom_exp, numf_exp; - Word16 numf; - Word32 SFM32; - Word16 invDenom, SFM; - - num = 0; - move32(); - denom = 65536; // 1.f in Q16 - denom_exp = 15; - *SFM_exp = 0; - move16(); - SFM = 32767 /*1.0f Q15*/; - move16(); - - FOR( i = start; i < stop; i++ ) - { - /*ln(x * 2^-Qx * 2^xExp) = ln(x) - Qx + xExp*/ - - /* n = sub(sub(31,norm_l(tmp32)),1); */ /*<- ld */ - /* n = sub(n,31); */ /*<- -Qx */ - /* n = add(n,*energy_exp); */ /*<- +xExp */ - - n = sub( sub( energy_exp[i], norm_l( energy[i] ) ), 1 ); /*<-- short form*/ - - if ( energy[i] == 0 ) /*special case: energy is zero*/ - { - n = 0; - move16(); - } - - n = s_max( 0, n ); - num = L_add( num, L_deposit_l( n ) ); /*Q0*/ - - denom = BASOP_Util_Add_Mant32Exp( energy[i], energy_exp[i], denom, denom_exp, &denom_exp ); - } - - /* calculate SFM only if signal is present */ - IF( denom != 0 ) - { - /*numf = (float)num / (float)(stop - start);*/ - numf = BASOP_Util_Divide3216_Scale( num, /*Q0*/ - sub( stop, start ), /*Q0*/ - &s ); /*Q-1 s*/ - numf_exp = add( s, 16 ); /*-> numf Q15 numf_exp*/ - /*denom /= (float)(stop - start);*/ - /*return ((float)pow(2.0, numf + 0.5f) / denom);*/ - - /*SFM= ((float)pow(2.0, numf + 0.5f) * invDenom);*/ - invDenom = BASOP_Util_Divide3232_uu_1616_Scale( L_deposit_l( sub( stop, start ) ) /*Q0*/, - denom /*Q31, denom_exp*/, - &s ); /*Q-16, s-denom_exp*/ - invDenom_exp = add( sub( s, denom_exp ), 31 ); /*invDenom: Q15, invDenom_exp*/ - - /*add .5f to numf*/ - SFM32 = L_add( L_shl( L_deposit_l( numf ), numf_exp ) /*16Q15*/, 16384l /*.5f Q15*/ ); /*16Q15*/ - s = norm_l( SFM32 ); - SFM32 = L_shl( SFM32, s ); - s = sub( 16, s ); /*SFM32(numf) is Q31 now*/ - - /*do the pow2 and the mult*/ - SFM32 = BASOP_util_Pow2( SFM32, s, &s ); - SFM32 = Mpy_32_16_1( SFM32, invDenom ); - *SFM_exp = add( s, invDenom_exp ); - - /*Transform to Q15*/ - s = norm_l( SFM32 ); - SFM = round_fx_sat( L_shl_sat( SFM32, s ) ); - *SFM_exp = sub( *SFM_exp, s ); - move16(); - /**SFM_exp = s_min(*SFM_exp, 0);*/ - IF( *SFM_exp > 0 ) - { - *SFM_exp = 0; - move16(); - SFM = 32767 /*1.0f Q15*/; - move16(); - } - } - - return SFM /*Q15*/; -} -#endif -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/**********************************************************************/ /* -calculates the IGF whitening levels by SFM and crest -**************************************************************************/ - -static void IGF_Whitening( - const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : | instance handle of IGF Encoder */ - Word32 *powerSpectrum, /* i : Q31 | MDCT/MDST power spectrum */ - const Word16 powerSpectrum_exp, /* i : | exponent of powerspectrum */ - const Word16 igfGridIdx, /* i : Q0 | IGF grid index */ - Word16 isTransient, /* i : Q0 | boolean, indicating if transient is detected */ - Word16 last_core_acelp /* i : Q0 | indictaor if last frame was acelp coded */ -) -{ - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - H_IGF_GRID hGrid; - Word16 p; /*Q0*/ - Word16 tmp; - Word16 SFM; - Word16 crest; - Word16 SFM_exp; - Word16 crest_exp; - Word16 s; - Word32 tmp32; - Word32 SFM32; - - hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - - IF( igfGridIdx != IGF_GRID_LB_NORM ) - { - FOR( p = 0; p < hGrid->nTiles; p++ ) - { - /* reset filter */ - hPrivateData->prevSFM_FIR[p] = L_deposit_l( 0 ); - move32(); - hPrivateData->prevSFM_IIR[p] = 0; - move16(); - - /* preset values: */ - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; - move16(); - } - } - FOR( p = 0; p < IGF_MAX_TILES; p++ ) + FOR( p = 0; p < IGF_MAX_TILES; p++ ) { /* update prev data: */ hPrivateData->igfPrevWhiteningLevel[p] = hPrivateData->igfCurrWhiteningLevel[p]; - move16(); /* preset values: */ hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; move16(); + move16(); } - IF( !s_or( isTransient, hPrivateData->wasTransient ) ) + test(); + IF( !( isTransient || hPrivateData->wasTransient ) ) { IF( powerSpectrum ) { Word16 nT = hGrid->nTiles; move16(); - SWITCH( hPrivateData->igfInfo.bitRateIndex ) + IF( EQ_16( element_mode, EVS_MONO ) ) { - case IGF_BITRATE_WB_9600: - case IGF_BITRATE_SWB_9600: - case IGF_BITRATE_SWB_16400: - case IGF_BITRATE_SWB_24400: - case IGF_BITRATE_SWB_32000: - case IGF_BITRATE_FB_16400: - case IGF_BITRATE_FB_24400: - case IGF_BITRATE_FB_32000: - nT = sub( nT, 1 ); - BREAK; - default: - BREAK; + SWITCH( hPrivateData->igfInfo.bitRateIndex ) + { + case IGF_BITRATE_WB_9600: + case IGF_BITRATE_SWB_9600: + case IGF_BITRATE_SWB_16400: + case IGF_BITRATE_SWB_24400: + case IGF_BITRATE_SWB_32000: + case IGF_BITRATE_FB_16400: + case IGF_BITRATE_FB_24400: + case IGF_BITRATE_FB_32000: + nT = sub( nT, 1 ); + BREAK; + default: + BREAK; + } } + FOR( p = 0; p < nT; p++ ) { - /*tmp = IGF_getSFM(powerSpectrum, hGrid->tile[p], hGrid->tile[p+1]) / IGF_getCrest(powerSpectrum, hGrid->tile[p], hGrid->tile[p+1]);*/ - SFM = IGF_getSFM( &SFM_exp, powerSpectrum, &powerSpectrum_exp, hGrid->tile[p], hGrid->tile[p + 1] ); - crest = IGF_getCrest( &crest_exp, powerSpectrum, powerSpectrum_exp, hGrid->tile[p], hGrid->tile[p + 1] ); + Word16 sb; - tmp = BASOP_Util_Divide1616_Scale( SFM, crest, &s ); /* Q15 */ - s = add( s, sub( SFM_exp, crest_exp ) ); - tmp32 = L_shl( L_deposit_l( tmp ) /*16Q15, s*/, add( s, 1 ) ); /* 15Q16 */ + IF( isTNSActive && GT_16( element_mode, EVS_MONO ) ) + { + FOR( sb = hGrid->tile[p]; sb < hGrid->tile[p + 1]; sb++ ) + { + hPrivateData->logSpec[sb] = 0; /* max(0,FLT_MIN_EXP=-125 )*/ + move16(); + IF( GE_32( powerSpectrum[sb], 1 ) ) + { + hPrivateData->logSpec[sb] = extract_l( L_max( 0, L_shr( L_add( BASOP_Util_Log2( powerSpectrum[sb] ), L_shl( powerSpectrum_e[sb], Q25 ) ), Q25 ) ) ); + } + } + } + /* if current tile contains only a single SFB, reuse already computed SFM values */ test(); - IF( last_core_acelp || hPrivateData->wasTransient ) + IF( element_mode > EVS_MONO && EQ_16( sub( hGrid->sfbWrap[p + 1], hGrid->sfbWrap[p] ), 1 ) ) { - hPrivateData->prevSFM_FIR[p] = tmp32; /* 15Q16 */ - move32(); - hPrivateData->prevSFM_IIR[p] = shr( tmp, 2 ); /* 2Q13 */ + tmp = hPrivateData->SFM_tb_fx[p]; + tmp_e = hPrivateData->sfb_tb_e[p]; + move16(); move16(); } + ELSE IF( EQ_16( element_mode, EVS_MONO ) ) + { + SFM = IGF_getSFM( &SFM_e, powerSpectrum, powerSpectrum_e, hGrid->tile[p], hGrid->tile[p + 1], element_mode ); + crest = IGF_getCrest( &crest_e, powerSpectrum, powerSpectrum_e, hGrid->tile[p], hGrid->tile[p + 1], element_mode ); - /*SFM = tmp + hPrivateData->prevSFM_FIR[p] + 0.5f * hPrivateData->prevSFM_IIR[p];*/ - SFM32 = L_add( tmp32, hPrivateData->prevSFM_FIR[p] ); - SFM32 = L_mac0( SFM32, hPrivateData->prevSFM_IIR[p] /*Q13*/, 4 /*.5f Q3*/ ); /*15Q16*/ - - BASOP_SATURATE_WARNING_OFF_EVS - /*SFM = min(2.7f, SFM);*/ - /*Overflow possible in shift, intended*/ - tmp = add_sat( crest, tmp ); - SFM = s_min( 22118 /*2.7f Q13*/, extract_h( L_shr_sat( SFM32, 16 - 29 ) /*->Q29*/ ) /*->Q13*/ ); - BASOP_SATURATE_WARNING_ON_EVS - - hPrivateData->prevSFM_FIR[p] = tmp32; /*15Q16*/ - move32(); - hPrivateData->prevSFM_IIR[p] = SFM; - move16(); - - IF( GT_16( SFM, hGrid->whiteningThreshold[1][p] ) ) + tmp = BASOP_Util_Divide1616_Scale( SFM, crest, &s ); /* Q15 */ + s = add( s, sub( SFM_e, crest_e ) ); + tmp32 = L_shl( L_deposit_l( tmp ) /*16Q15, s*/, add( s, 1 ) ); /* 15Q16 */ + } + ELSE { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_STRONG; - move16(); + SFM = IGF_getSFM_new_fx( powerSpectrum, hPrivateData->logSpec, hGrid->tile[p], hGrid->tile[p + 1], powerSpectrum_e ); + crest = IGF_getCrest_new_fx( hPrivateData->logSpec, hGrid->tile[p], hGrid->tile[p + 1], &crest_e ); + tmp = BASOP_Util_Divide1616_Scale( SFM, crest, &tmp_e ); + tmp_e = sub( tmp_e, crest_e ); } - ELSE IF( GT_16( SFM, hGrid->whiteningThreshold[0][p] ) ) + + test(); + IF( last_core_acelp || hPrivateData->wasTransient ) { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; + IF( EQ_16( element_mode, EVS_MONO ) ) + { + hPrivateData->prevSFM_FIR[p] = tmp32; /* 15Q16 */ + hPrivateData->prevSFM_IIR[p] = shr( tmp, 2 ); /* 2Q13 */ + } + ELSE + { + hPrivateData->prevSFM_FIR[p] = L_shl( tmp, add( 1, tmp_e ) ); /*16-(15-exp)=>15Q16*/ + hPrivateData->prevSFM_IIR[p] = shl( tmp, sub( tmp_e, 2 ) ); /*13-(15-exp)=>2Q13*/ + } + move32(); move16(); } - } - SWITCH( hPrivateData->igfInfo.bitRateIndex ) + + test(); + IF( LE_32( brate, IVAS_48k ) && EQ_16( element_mode, IVAS_CPE_MDCT ) ) + { + Word16 temp; + num_Tiles = 0; + SFM_src = 0; + SFM_tar = 0; + SFM_src_e = 0; + SFM_tar_e = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + + FOR( sb = hGrid->sfbWrap[p]; sb < hGrid->sfbWrap[p + 1]; sb++ ) + { + num_Tiles = add( num_Tiles, 1 ); + SFM_src_e = BASOP_Util_Add_MantExp( hPrivateData->SFM_sb_fx[sb], hPrivateData->sfb_sb_e[sb], SFM_src, SFM_src_e, &SFM_src ); + SFM_tar_e = BASOP_Util_Add_MantExp( hPrivateData->SFM_tb_fx[sb], hPrivateData->sfb_tb_e[sb], SFM_tar, SFM_tar_e, &SFM_tar ); + } + + /* compute the average */ + SFM_src = shr( BASOP_Util_Divide1616_Scale( SFM_src, num_Tiles, &temp ), 2 ); + SFM_src_e = add( SFM_src_e, sub( temp, 13 ) ); /*temp-15+2:because right shifted by 2 which are the guard bits*/ + SFM_tar = shr( BASOP_Util_Divide1616_Scale( SFM_tar, num_Tiles, &temp ), 2 ); + SFM_tar_e = add( SFM_tar_e, sub( temp, 13 ) ); /*temp-15+2:because right shifted by 2 which are the guard bits*/ + + IF( LT_16( SFM_tar_e, SFM_src_e ) ) + { + SFM_tar = shl( SFM_tar, sub( SFM_tar_e, SFM_src_e ) ); /*making the q for SFM_tar and SFM_src equal with 2 as guard bits*/ + SFM_tar_e = SFM_src_e; + } + ELSE + { + SFM_src = shr( SFM_src, sub( SFM_tar_e, SFM_src_e ) ); /*making the q for SFM_tar and SFM_src equal with 2 as guard bits*/ + SFM_src_e = SFM_tar_e; + } + move16(); + + test(); + test(); + IF( ( p > 0 ) && ( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) ) + { + test(); + if ( EQ_16( p, 1 ) && EQ_16( abs_s( sub( hPrivateData->igfCurrWhiteningLevel[0], hPrivateData->igfCurrWhiteningLevel[1] ) ), 2 ) ) /* OFF vs. STRONG */ + { + hPrivateData->igfCurrWhiteningLevel[0] = IGF_WHITENING_MID; + move16(); + } + hPrivateData->igfCurrWhiteningLevel[p] = hPrivateData->igfCurrWhiteningLevel[p - 1]; + move16(); + } + ELSE IF( sp_aud_decision0 ) + { + /* Music */ + /* whitening Off: when tonality of target is more than source or tonality of target is close to that of source */ + test(); + if ( LE_16( SFM_tar, SFM_src ) || LE_32( SFM_tar, L_add( SFM_src, L_shl( 1, sub( 14, SFM_src_e /*0.5 with exponent SFM_src_e*/ ) ) ) ) ) + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; + move16(); + } + + /* whitening mid: */ + test(); + if ( GT_32( SFM_tar, L_add( SFM_src, L_shl( 1, sub( 14, SFM_src_e /*0.5 with exponent SFM_src_e*/ ) ) ) ) && LE_32( SFM_tar, L_add( SFM_src, L_shl( 5, sub( 13, SFM_src_e ) ) /*1.25 with exponent SFM_src_e*/ ) ) ) + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; + move16(); + } + + /* whitening strong */ + if ( GT_32( SFM_tar, L_add( SFM_src, L_shl( 5, sub( 13, SFM_src_e ) ) /*1.25 with exponent SFM_src_e*/ ) ) ) + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_STRONG; + move16(); + } + } + ELSE + { + /* Speech */ + /* whitening Off: when tonality of target is more than source or tonality of target is close to that of source */ + test(); + if ( LE_16( SFM_tar, SFM_src ) || LE_32( SFM_tar, L_add( SFM_src, L_shr( 3277 /*0.1 Q15*/, SFM_src_e ) ) ) ) + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; + move16(); + } + + /* whitening mid: */ + test(); + if ( GT_32( SFM_tar, L_add( SFM_src, L_shr( 3277 /*0.1 Q15*/, SFM_src_e ) ) ) && LE_32( SFM_tar, L_add( SFM_src, L_shl( 1, sub( 14, SFM_src_e /*0.5 with exponent SFM_src_e*/ ) ) ) ) ) + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; + move16(); + } + + /* whitening strong */ + if ( GT_32( SFM_tar, L_add( SFM_src, L_shl( 1, sub( 14, SFM_src_e /*0.5 with exponent SFM_src_e*/ ) ) ) ) ) + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_STRONG; + move16(); + } + } + + SFM = shl( SFM_tar, sub( SFM_tar_e, 2 ) ); /*2Q13*/ + } + ELSE + { + test(); + IF( element_mode > EVS_MONO && EQ_16( sub( hGrid->sfbWrap[p + 1], hGrid->sfbWrap[p] ), 1 ) ) + { + SFM = shl( tmp, sub( tmp_e, 2 ) ); /*2Q13*/ + } + ELSE IF( EQ_16( element_mode, EVS_MONO ) ) + { + /*SFM = tmp + hPrivateData->prevSFM_FIR[p] + 0.5f * hPrivateData->prevSFM_IIR[p];*/ + SFM32 = L_add( tmp32, hPrivateData->prevSFM_FIR[p] ); + SFM32 = L_mac0( SFM32, hPrivateData->prevSFM_IIR[p] /*Q13*/, 4 /*.5f Q3*/ ); /*15Q16*/ + BASOP_SATURATE_WARNING_OFF_EVS + /*SFM = min(2.7f, SFM);*/ + /*Overflow possible in shift, intended*/ + tmp = add_sat( crest, tmp ); + SFM = s_min( 22118 /*2.7f Q13*/, extract_h( L_shr_sat( SFM32, 16 - 29 ) /*->Q29*/ ) /*->Q13*/ ); + BASOP_SATURATE_WARNING_ON_EVS; + } + ELSE + { + Word32 temp; + temp = L_add( L_shl( tmp, sub( tmp_e, 2 ) ), L_add( L_shr( hPrivateData->prevSFM_FIR[p], 3 ), L_shr( hPrivateData->prevSFM_IIR[p], 1 ) ) ); + SFM = extract_l( L_min( 22118 /*2.7*/, temp ) ); /*2Q13*/ + } + IF( EQ_16( element_mode, EVS_MONO ) ) + { + hPrivateData->prevSFM_FIR[p] = tmp32; /*15Q16*/ + } + ELSE + { + hPrivateData->prevSFM_FIR[p] = L_shl( tmp, add( 1, tmp_e ) ); /*15Q16*/ + } + hPrivateData->prevSFM_IIR[p] = SFM; + move32(); + move16(); + + IF( GT_16( SFM, hGrid->whiteningThreshold[1][p] ) ) + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_STRONG; + move16(); + } + ELSE IF( GT_16( SFM, hGrid->whiteningThreshold[0][p] ) ) + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; + move16(); + } + ELSE + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; + move16(); + } + } + + IF( element_mode > EVS_MONO ) + { + IF( last_core_acelp ) /* reset */ + { + set16_fx( hPrivateData->igfPastSFM_fx[p], -ONE_IN_Q13, IGF_PAST_SFM_LEN ); + hPrivateData->igfWhiteningHangoverCnt[p] = 2; + move16(); + } + ELSE + { + test(); + test(); + test(); + test(); + /* check whether change in whitening level should be allowed or not (if SFM is inside a certain margin around thresholds) */ + IF( NE_16( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfPrevWhiteningLevel[p] ) && + ( ( GT_32( SFM, L_sub( hGrid->whiteningThreshold[0][p], 1229 /*0.15f Q13*/ ) ) && LT_32( SFM, L_add( hGrid->whiteningThreshold[0][p], 1229 ) ) ) || + ( GT_32( SFM, L_sub( hGrid->whiteningThreshold[1][p], 1229 ) ) && LT_32( SFM, L_add( hGrid->whiteningThreshold[1][p], 1229 ) ) ) ) ) + { + Word16 mean_past_SFM; + Word16 mean_past_SFM_e; + Word16 countable; + Word16 i; + mean_past_SFM = 0; + mean_past_SFM_e = 0; + countable = 0; + move16(); + move16(); + move16(); + + /* compute mean of last (available) SFM values */ + FOR( i = 0; i < IGF_PAST_SFM_LEN; i++ ) + { + IF( hPrivateData->igfPastSFM_fx[p][i] >= 0 ) + { + mean_past_SFM_e = BASOP_Util_Add_MantExp( mean_past_SFM, mean_past_SFM_e, hPrivateData->igfPastSFM_fx[p][i], 2, &mean_past_SFM ); + countable = add( countable, 1 ); + } + } + IF( countable ) + { + Word16 temp; + mean_past_SFM = BASOP_Util_Divide1616_Scale( mean_past_SFM, countable, &temp ); + mean_past_SFM_e = add( mean_past_SFM_e, sub( temp, 15 ) ); + mean_past_SFM = shl( mean_past_SFM, sub( mean_past_SFM_e, 2 ) ); /*mean_past_SFM_e=2*/ + /* deny change in whitening level for small deviations from mean SFM */ + if ( LT_16( abs_s( sub( SFM, mean_past_SFM ) ), 1638 ) /*0.2 in Q13*/ ) + { + hPrivateData->igfCurrWhiteningLevel[p] = hPrivateData->igfPrevWhiteningLevel[p]; + move16(); + } + } + } + } + + hPrivateData->igfPastSFM_fx[p][hPrivateData->igfPastSFM_pos] = SFM; /*2Q13*/ + move16(); + } + } + + SWITCH( hPrivateData->igfInfo.bitRateIndex ) { case IGF_BITRATE_WB_9600: case IGF_BITRATE_RF_WB_13200: + case IGF_BITRATE_WB_13200_CPE: + case IGF_BITRATE_WB_16400_CPE: case IGF_BITRATE_RF_SWB_13200: case IGF_BITRATE_SWB_9600: + case IGF_BITRATE_SWB_13200_CPE: case IGF_BITRATE_SWB_16400: case IGF_BITRATE_SWB_24400: + case IGF_BITRATE_SWB_24400_CPE: + case IGF_BITRATE_SWB_32000_CPE: case IGF_BITRATE_SWB_32000: case IGF_BITRATE_FB_16400: case IGF_BITRATE_FB_24400: + case IGF_BITRATE_FB_24400_CPE: + case IGF_BITRATE_FB_32000_CPE: case IGF_BITRATE_FB_32000: - move16(); hPrivateData->igfCurrWhiteningLevel[hGrid->nTiles - 1] = hPrivateData->igfCurrWhiteningLevel[hGrid->nTiles - 2]; + move16(); BREAK; default: BREAK; @@ -1610,2286 +1356,672 @@ static void IGF_Whitening( /* reset filter */ FOR( p = 0; p < IGF_MAX_TILES; p++ ) { - hPrivateData->prevSFM_FIR[p] = L_deposit_l( 0 ); - move32(); + hPrivateData->prevSFM_FIR[p] = 0; hPrivateData->prevSFM_IIR[p] = 0; + move32(); move16(); } } - hPrivateData->wasTransient = isTransient; - move16(); - - return; -} -#else -/*-------------------------------------------------------------------* - * IGF_getCrest_new() - * - * crest factor calculation - *-------------------------------------------------------------------*/ -/*! r: crest factor */ -static Word16 IGF_getCrest_new_fx( - const Word16 *logSpec, /* i : power spectrum */ - const Word16 start, /* i : start subband index */ - const Word16 stop, /* i : stop subband index */ - Word16 *crest_exp /*Stores the exponent of the result(return value)*/ -) -{ - Word16 i; - Word16 x; - Word32 x_eff; - Word16 x_max; - Word16 exp; - Word16 temp; - Word16 temp_e; - Word16 crest; /*1.0f in Q15*/ - x_eff = 0; - x_max = 0; - exp = 0; - temp = 0; - crest = 32767; /*1.0f in Q15*/ - move32(); - move16(); - move16(); - move16(); - move16(); - - FOR( i = start; i < stop; i++ ) + IF( element_mode > EVS_MONO ) { - x = logSpec[i]; - move16(); - x_eff = L_mac0( x_eff, x, x ); - - if ( GT_16( x, x_max ) ) + IF( EQ_16( SFM, -ONE_IN_Q13 /*1.0f 2Q13*/ ) ) /* reset */ { - x_max = x; - move16(); + FOR( p = 0; p < hGrid->nTiles; p++ ) + { + set16_fx( hPrivateData->igfPastSFM_fx[p], -ONE_IN_Q13, IGF_PAST_SFM_LEN ); + hPrivateData->igfWhiteningHangoverCnt[p] = 2; + move16(); + } } - } - x_eff = BASOP_Util_Divide3216_Scale( x_eff, sub( stop, start ), &temp_e ); - temp_e = add( temp_e, 16 ); /*exp += 31 - 15 + 16(because x_eff is word32)*/ - x_eff = L_shr( x_eff, sub( 15, temp_e ) ); - temp_e = 15; - move16(); - temp = Sqrt16( extract_l( x_eff ), &temp_e ); + /* vibrato handling */ + FOR( p = 0; p < hGrid->nTiles; p = p + 2 ) + { + test(); + test(); + test(); + IF( ( hPrivateData->igfPrevWhiteningLevel[p] == IGF_WHITENING_OFF && hPrivateData->igfCurrWhiteningLevel[p] != IGF_WHITENING_OFF ) || + ( hPrivateData->igfPrevWhiteningLevel[p + 1] == IGF_WHITENING_OFF && hPrivateData->igfCurrWhiteningLevel[p + 1] != IGF_WHITENING_OFF ) ) + { + Word16 i; + Word16 pastSfm_a[4], pastSfm_b[4]; + Word16 pastSfmDiffSum_a, pastSfmDiffSum_b; - test(); - IF( x_eff > 0 && x_max > 0 ) - { - temp = BASOP_Util_Divide1616_Scale( x_max, temp, &exp ); - exp = add( exp, sub( 15, temp_e ) ); - IF( exp < 0 ) + FOR( i = 0; i < 4; i++ ) + { + pastSfm_a[i] = hPrivateData->igfPastSFM_fx[p][add( hPrivateData->igfPastSFM_pos, sub( 4, i ) ) % IGF_PAST_SFM_LEN]; + pastSfm_b[i] = hPrivateData->igfPastSFM_fx[p + 1][add( hPrivateData->igfPastSFM_pos, sub( 4, i ) ) % IGF_PAST_SFM_LEN]; + move16(); + move16(); + } + pastSfmDiffSum_a = pastSfmDiffSum_b = 0; + move16(); + move16(); + FOR( i = 0; i < 3; i++ ) + { + IF( NE_16( pastSfm_a[i + 1], -ONE_IN_Q13 ) ) + { + pastSfmDiffSum_a = add( pastSfmDiffSum_a, sub( pastSfm_a[i], pastSfm_a[i + 1] ) ); + pastSfmDiffSum_b = add( pastSfmDiffSum_b, sub( pastSfm_b[i], pastSfm_b[i + 1] ) ); + } + ELSE + { + BREAK; + } + } + test(); + test(); + test(); + test(); + /* if tonality oscillates between two tiles, turn whitening off in both */ + IF( ( ( pastSfmDiffSum_a > 0 && pastSfmDiffSum_b < 0 ) || + ( pastSfmDiffSum_a < 0 && pastSfmDiffSum_b > 0 ) ) && + ( GT_32( L_abs( L_sub( pastSfmDiffSum_a, pastSfmDiffSum_b ) ), ONE_IN_Q12 /* 0.5 in Q13 */ ) ) ) + { + hPrivateData->igfCurrWhiteningLevel[p] = hPrivateData->igfCurrWhiteningLevel[p + 1] = IGF_WHITENING_OFF; + move16(); + move16(); + } + } + } + + /* hangover */ + FOR( p = 0; p < hGrid->nTiles; p++ ) { - temp = shl( temp, exp ); - exp = 0; - move16(); + IF( NE_16( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfPrevWhiteningLevel[p] ) ) + { + hPrivateData->igfWhiteningHangoverCnt[p] = add( hPrivateData->igfWhiteningHangoverCnt[p], 1 ); + IF( EQ_16( hPrivateData->igfWhiteningHangoverCnt[p], 3 ) ) + { + hPrivateData->igfWhiteningHangoverCnt[p] = 0; + } + ELSE + { + hPrivateData->igfCurrWhiteningLevel[p] = hPrivateData->igfPrevWhiteningLevel[p]; + } + move16(); + move16(); + } + ELSE + { + hPrivateData->igfWhiteningHangoverCnt[p] = 0; + move16(); + } } - crest = s_max( shl_sat( 1, sub( 15, exp ) ), temp ); + + hPrivateData->igfPastSFM_pos = add( hPrivateData->igfPastSFM_pos, 1 ) % IGF_PAST_SFM_LEN; + move16(); } - *crest_exp = exp; + + hPrivateData->wasTransient = isTransient; move16(); - return crest; + + return; } -/*-------------------------------------------------------------------* - * IGF_getSFM_new() - * - * calculates spectral flatness measurement - *-------------------------------------------------------------------*/ -/*! r: SFM value */ -static Word16 IGF_getSFM_new_fx( - const Word32 *powerSpectrum, /* i : power spectrum */ - const Word16 *logSpec, /* i : log of power spectrum */ - const Word16 start, /* i : start subband index */ - const Word16 stop, /* i : stop subband index */ - Word16 *e_ps /*Stores exp related to power spectrum*/ +/**********************************************************************/ /* +write whitening levels into bitstream +**************************************************************************/ + +/* o: Q0 | number of bits written */ +static Word16 IGF_WriteWhiteningTile_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /* i : | ptr to bitOffset counter */ + Word16 whiteningLevel /* i : Q0 | whitening levels to write */ ) { - Word16 n; - Word16 i; - Word16 num; - Word32 denom; - Word16 numf; - Word32 tmp; - Word16 sfm; - Word16 sfm_e; - Word16 denom_e; - Word16 numf_e; /*stores exponent for numf*/ - Word16 tmp_e; + Word16 totBitCount; + Word16 startBitCount; - num = 0; - denom = ONE_IN_Q30; - denom_e = 1; - sfm = MAX16B; // Q15 - move16(); - move32(); + totBitCount = 0; + startBitCount = *pBitOffset; move16(); move16(); - FOR( i = start; i < stop; i++ ) + IF( EQ_16( whiteningLevel, IGF_WHITENING_MID ) ) { - tmp = powerSpectrum[i]; - n = logSpec[i /*-start*/]; - move32(); - move16(); - num = add( num, n ); - denom = BASOP_Util_Add_Mant32Exp( tmp, e_ps[i], denom, denom_e, &denom_e ); + IGF_write_bits( hBstr, pBitOffset, 0, 1 ); } - - numf = BASOP_Util_Divide1616_Scale( num, sub( stop, start ), &numf_e ); - denom = BASOP_Util_Divide3216_Scale( denom, sub( stop, start ), &tmp_e ); - denom_e = add( add( denom_e, tmp_e ), 1 ); /*denom_e+tmp_e-15 +16(because type of denom is word32)*/ - - IF( denom != 0 ) + ELSE { - tmp = BASOP_util_Pow2( L_add( numf, shl_sat( 1, sub( 14, numf_e ) ) ), add( 16, numf_e ), &tmp_e ); - sfm = BASOP_Util_Divide3232_Scale( tmp, denom, &sfm_e ); - sfm_e = add( sfm_e, sub( tmp_e, denom_e ) ); - sfm = shl_sat( extract_l( L_min( sfm, L_shl_sat( 1, sub( 15, sfm_e ) ) ) ), sfm_e ); + IGF_write_bits( hBstr, pBitOffset, 1, 1 ); + IF( EQ_16( whiteningLevel, IGF_WHITENING_OFF ) ) + { + IGF_write_bits( hBstr, pBitOffset, 0, 1 ); + } + ELSE + { + IGF_write_bits( hBstr, pBitOffset, 1, 1 ); + } } + totBitCount = sub( *pBitOffset, startBitCount ); - return sfm; + return totBitCount; } -/*-------------------------------------------------------------------* - * IGF_Whitening() - * - * calculates the IGF whitening levels by SFM and crest - *-------------------------------------------------------------------*/ -static void IGF_Whitening( - const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : | instance handle of IGF Encoder */ - Word32 *powerSpectrum, /* i : Q31 | MDCT/MDST power spectrum */ - Word16 *powerSpectrum_e, /* i : Q31 | MDCT/MDST power spectrum */ - const Word16 igfGridIdx, /* i : Q0 | IGF grid index */ - const Word16 isTransient, /* i : Q0 | flag indicating if transient is detected */ - const Word16 last_core_acelp, /* i : Q0 | indicator if last frame was ACELP core */ - const Word16 isTNSActive, /* i : Q0 | indicator if TNS is active */ - const Word16 sp_aud_decision0, /* i : Q0 | first stage classifier decision */ - const Word32 brate, /* i : Q0 | bitrate */ - const Word16 element_mode /* i : Q0 | element mode */ +/**********************************************************************/ /* +writes the whitening levels +**************************************************************************/ + +/* o: Q0 | total number of bits written */ +static Word16 IGF_WriteWhiteningLevels_fx( + const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : | instance handle of IGF encoder */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /* i : | ptr to bitOffset counter */ + const Word16 igfGridIdx, /* i : Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 isIndepFlag /* i : Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ ) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; - Word16 p; /*Q0*/ - Word16 tmp; - Word16 tmp_e; - Word16 SFM_src; - Word16 SFM_tar; - Word16 SFM_src_e; - Word16 SFM_tar_e; - Word16 num_Tiles; - Word16 SFM; - Word16 SFM_e; - Word32 SFM32; - Word16 crest; - Word16 s; + Word16 p; + Word16 nTiles; + Word16 isSame; Word32 tmp32; - Word16 crest_e; + Word16 totBitCount; + Word16 startBitCount; - SFM = -ONE_IN_Q13; /*1.0f Q13*/ - tmp_e = 0; - crest = 0; - tmp32 = 0; + totBitCount = 0; move16(); + isSame = 1; move16(); + startBitCount = *pBitOffset; + move16(); + hPrivateData = &hInstance->igfData; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + nTiles = hGrid->nTiles; move16(); - move32(); - - hPrivateData = &hIGFEnc->igfData; - hGrid = &hPrivateData->igfInfo.grid[(Word16) igfGridIdx]; - IF( NE_16( igfGridIdx, IGF_GRID_LB_NORM ) ) + IF( isIndepFlag ) { - FOR( p = 0; p < hGrid->nTiles; p++ ) + isSame = 0; + move16(); + } + ELSE + { + p = 0; + move16(); + tmp32 = 0; + move32(); + test(); + WHILE( ( LT_16( p, nTiles ) ) && ( tmp32 == 0 ) ) { - /* reset filter */ - hPrivateData->prevSFM_FIR[p] = L_deposit_l( 0 ); - hPrivateData->prevSFM_IIR[p] = 0; - move16(); - - /* preset values: */ - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; - move16(); + test(); + tmp32 = L_sub( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfPrevWhiteningLevel[p] ); + if ( tmp32 != 0 ) + { + isSame = 0; + move16(); + } + p++; } } - - FOR( p = 0; p < IGF_MAX_TILES; p++ ) + IF( isSame ) { - /* update prev data: */ - hPrivateData->igfPrevWhiteningLevel[p] = hPrivateData->igfCurrWhiteningLevel[p]; - /* preset values: */ - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; - move16(); - move16(); + IGF_write_bits( hBstr, pBitOffset, 1, 1 ); } - - test(); - IF( !( isTransient || hPrivateData->wasTransient ) ) + ELSE { - IF( powerSpectrum ) + IF( !isIndepFlag ) { - Word16 nT = hGrid->nTiles; + IGF_write_bits( hBstr, pBitOffset, 0, 1 ); + } + IGF_WriteWhiteningTile_fx( hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[0] ); + p = 1; + move16(); + tmp32 = 0; + move32(); + test(); + IF( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) + { + isSame = 1; move16(); - IF( EQ_16( element_mode, EVS_MONO ) ) + } + ELSE + { + if ( LT_16( p, nTiles ) ) { - SWITCH( hPrivateData->igfInfo.bitRateIndex ) - { - case IGF_BITRATE_WB_9600: - case IGF_BITRATE_SWB_9600: - case IGF_BITRATE_SWB_16400: - case IGF_BITRATE_SWB_24400: - case IGF_BITRATE_SWB_32000: - case IGF_BITRATE_FB_16400: - case IGF_BITRATE_FB_24400: - case IGF_BITRATE_FB_32000: - nT = sub( nT, 1 ); - BREAK; - default: - BREAK; - } + isSame = 1; + move16(); } - - FOR( p = 0; p < nT; p++ ) + test(); + WHILE( ( LT_16( p, nTiles ) ) && ( tmp32 == 0 ) ) { - Word16 sb; - - IF( isTNSActive && GT_16( element_mode, EVS_MONO ) ) - { - FOR( sb = hGrid->tile[p]; sb < hGrid->tile[p + 1]; sb++ ) - { - hPrivateData->logSpec[sb] = 0; /* max(0,FLT_MIN_EXP=-125 )*/ - move16(); - IF( GE_32( powerSpectrum[sb], 1 ) ) - { - hPrivateData->logSpec[sb] = extract_l( L_max( 0, L_shr( L_add( BASOP_Util_Log2( powerSpectrum[sb] ), L_shl( powerSpectrum_e[sb], Q25 ) ), Q25 ) ) ); - } - } - } - - /* if current tile contains only a single SFB, reuse already computed SFM values */ test(); - IF( element_mode > EVS_MONO && EQ_16( sub( hGrid->sfbWrap[p + 1], hGrid->sfbWrap[p] ), 1 ) ) + tmp32 = L_sub( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfCurrWhiteningLevel[p - 1] ); + if ( tmp32 != 0 ) { - tmp = hPrivateData->SFM_tb_fx[p]; - tmp_e = hPrivateData->sfb_tb_e[p]; - move16(); + isSame = 0; move16(); } - ELSE IF( EQ_16( element_mode, EVS_MONO ) ) - { - SFM = IGF_getSFM( &SFM_e, powerSpectrum, powerSpectrum_e, hGrid->tile[p], hGrid->tile[p + 1], element_mode ); - crest = IGF_getCrest( &crest_e, powerSpectrum, powerSpectrum_e, hGrid->tile[p], hGrid->tile[p + 1], element_mode ); + p++; + } + } + test(); + IF( !isSame ) + { + IGF_write_bits( hBstr, pBitOffset, 1, 1 ); + FOR( p = 1; p < nTiles; p++ ) + { + IGF_WriteWhiteningTile_fx( hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[p] ); + } + } + ELSE IF( NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) && NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) + { + IGF_write_bits( hBstr, pBitOffset, 0, 1 ); + } + } - tmp = BASOP_Util_Divide1616_Scale( SFM, crest, &s ); /* Q15 */ - s = add( s, sub( SFM_e, crest_e ) ); - tmp32 = L_shl( L_deposit_l( tmp ) /*16Q15, s*/, add( s, 1 ) ); /* 15Q16 */ - } - ELSE - { - SFM = IGF_getSFM_new_fx( powerSpectrum, hPrivateData->logSpec, hGrid->tile[p], hGrid->tile[p + 1], powerSpectrum_e ); - crest = IGF_getCrest_new_fx( hPrivateData->logSpec, hGrid->tile[p], hGrid->tile[p + 1], &crest_e ); - tmp = BASOP_Util_Divide1616_Scale( SFM, crest, &tmp_e ); - tmp_e = sub( tmp_e, crest_e ); - } + totBitCount = sub( *pBitOffset, startBitCount ); - test(); - IF( last_core_acelp || hPrivateData->wasTransient ) - { - IF( EQ_16( element_mode, EVS_MONO ) ) - { - hPrivateData->prevSFM_FIR[p] = tmp32; /* 15Q16 */ - hPrivateData->prevSFM_IIR[p] = shr( tmp, 2 ); /* 2Q13 */ - } - ELSE - { - hPrivateData->prevSFM_FIR[p] = L_shl( tmp, add( 1, tmp_e ) ); /*16-(15-exp)=>15Q16*/ - hPrivateData->prevSFM_IIR[p] = shl( tmp, sub( tmp_e, 2 ) ); /*13-(15-exp)=>2Q13*/ - } - move32(); - move16(); - } + return totBitCount; +} - test(); - IF( LE_32( brate, IVAS_48k ) && EQ_16( element_mode, IVAS_CPE_MDCT ) ) - { - Word16 temp; - num_Tiles = 0; - SFM_src = 0; - SFM_tar = 0; - SFM_src_e = 0; - SFM_tar_e = 0; - move16(); - move16(); - move16(); - move16(); - move16(); - FOR( sb = hGrid->sfbWrap[p]; sb < hGrid->sfbWrap[p + 1]; sb++ ) - { - num_Tiles = add( num_Tiles, 1 ); - SFM_src_e = BASOP_Util_Add_MantExp( hPrivateData->SFM_sb_fx[sb], hPrivateData->sfb_sb_e[sb], SFM_src, SFM_src_e, &SFM_src ); - SFM_tar_e = BASOP_Util_Add_MantExp( hPrivateData->SFM_tb_fx[sb], hPrivateData->sfb_tb_e[sb], SFM_tar, SFM_tar_e, &SFM_tar ); - } +/*-------------------------------------------------------------------* + * IGF_WriteFlatteningTrigger_fx() + * + * write flattening trigger + *-------------------------------------------------------------------*/ - /* compute the average */ - SFM_src = shr( BASOP_Util_Divide1616_Scale( SFM_src, num_Tiles, &temp ), 2 ); - SFM_src_e = add( SFM_src_e, sub( temp, 13 ) ); /*temp-15+2:because right shifted by 2 which are the guard bits*/ - SFM_tar = shr( BASOP_Util_Divide1616_Scale( SFM_tar, num_Tiles, &temp ), 2 ); - SFM_tar_e = add( SFM_tar_e, sub( temp, 13 ) ); /*temp-15+2:because right shifted by 2 which are the guard bits*/ +/*! r: number of bits written */ +static Word16 IGF_WriteFlatteningTrigger_fx( + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + BSTR_ENC_HANDLE hBstr, /**< inout: | encoder bitstream handle */ + Word16 *pBitOffset /**< in: | ptr to bitOffset counter */ +) +{ + Word16 flatteningTrigger; - IF( LT_16( SFM_tar_e, SFM_src_e ) ) - { - SFM_tar = shl( SFM_tar, sub( SFM_tar_e, SFM_src_e ) ); /*making the q for SFM_tar and SFM_src equal with 2 as guard bits*/ - SFM_tar_e = SFM_src_e; - } - ELSE - { - SFM_src = shr( SFM_src, sub( SFM_tar_e, SFM_src_e ) ); /*making the q for SFM_tar and SFM_src equal with 2 as guard bits*/ - SFM_src_e = SFM_tar_e; - } - move16(); + Word16 totBitCount; + Word16 startBitCount; + totBitCount = 0; + startBitCount = *pBitOffset; + flatteningTrigger = hInstance->flatteningTrigger; + move16(); + move16(); + move16(); - test(); - test(); - IF( ( p > 0 ) && ( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) ) - { - test(); - if ( EQ_16( p, 1 ) && EQ_16( abs_s( sub( hPrivateData->igfCurrWhiteningLevel[0], hPrivateData->igfCurrWhiteningLevel[1] ) ), 2 ) ) /* OFF vs. STRONG */ - { - hPrivateData->igfCurrWhiteningLevel[0] = IGF_WHITENING_MID; - move16(); - } - hPrivateData->igfCurrWhiteningLevel[p] = hPrivateData->igfCurrWhiteningLevel[p - 1]; - move16(); - } - ELSE IF( sp_aud_decision0 ) - { - /* Music */ - /* whitening Off: when tonality of target is more than source or tonality of target is close to that of source */ - test(); - if ( LE_16( SFM_tar, SFM_src ) || LE_32( SFM_tar, L_add( SFM_src, L_shl( 1, sub( 14, SFM_src_e /*0.5 with exponent SFM_src_e*/ ) ) ) ) ) - { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; - move16(); - } + IGF_write_bits( hBstr, pBitOffset, flatteningTrigger, 1 ); + totBitCount = sub( *pBitOffset, startBitCount ); - /* whitening mid: */ - test(); - if ( GT_32( SFM_tar, L_add( SFM_src, L_shl( 1, sub( 14, SFM_src_e /*0.5 with exponent SFM_src_e*/ ) ) ) ) && LE_32( SFM_tar, L_add( SFM_src, L_shl( 5, sub( 13, SFM_src_e ) ) /*1.25 with exponent SFM_src_e*/ ) ) ) - { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; - move16(); - } - - /* whitening strong */ - if ( GT_32( SFM_tar, L_add( SFM_src, L_shl( 5, sub( 13, SFM_src_e ) ) /*1.25 with exponent SFM_src_e*/ ) ) ) - { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_STRONG; - move16(); - } - } - ELSE - { - /* Speech */ - /* whitening Off: when tonality of target is more than source or tonality of target is close to that of source */ - test(); - if ( LE_16( SFM_tar, SFM_src ) || LE_32( SFM_tar, L_add( SFM_src, L_shr( 3277 /*0.1 Q15*/, SFM_src_e ) ) ) ) - { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; - move16(); - } - - /* whitening mid: */ - test(); - if ( GT_32( SFM_tar, L_add( SFM_src, L_shr( 3277 /*0.1 Q15*/, SFM_src_e ) ) ) && LE_32( SFM_tar, L_add( SFM_src, L_shl( 1, sub( 14, SFM_src_e /*0.5 with exponent SFM_src_e*/ ) ) ) ) ) - { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; - move16(); - } - - /* whitening strong */ - if ( GT_32( SFM_tar, L_add( SFM_src, L_shl( 1, sub( 14, SFM_src_e /*0.5 with exponent SFM_src_e*/ ) ) ) ) ) - { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_STRONG; - move16(); - } - } - - SFM = shl( SFM_tar, sub( SFM_tar_e, 2 ) ); /*2Q13*/ - } - ELSE - { - test(); - IF( element_mode > EVS_MONO && EQ_16( sub( hGrid->sfbWrap[p + 1], hGrid->sfbWrap[p] ), 1 ) ) - { - SFM = shl( tmp, sub( tmp_e, 2 ) ); /*2Q13*/ - } - ELSE IF( EQ_16( element_mode, EVS_MONO ) ) - { - /*SFM = tmp + hPrivateData->prevSFM_FIR[p] + 0.5f * hPrivateData->prevSFM_IIR[p];*/ - SFM32 = L_add( tmp32, hPrivateData->prevSFM_FIR[p] ); - SFM32 = L_mac0( SFM32, hPrivateData->prevSFM_IIR[p] /*Q13*/, 4 /*.5f Q3*/ ); /*15Q16*/ - BASOP_SATURATE_WARNING_OFF_EVS - /*SFM = min(2.7f, SFM);*/ - /*Overflow possible in shift, intended*/ - tmp = add_sat( crest, tmp ); - SFM = s_min( 22118 /*2.7f Q13*/, extract_h( L_shr_sat( SFM32, 16 - 29 ) /*->Q29*/ ) /*->Q13*/ ); - BASOP_SATURATE_WARNING_ON_EVS; - } - ELSE - { - Word32 temp; - temp = L_add( L_shl( tmp, sub( tmp_e, 2 ) ), L_add( L_shr( hPrivateData->prevSFM_FIR[p], 3 ), L_shr( hPrivateData->prevSFM_IIR[p], 1 ) ) ); - SFM = extract_l( L_min( 22118 /*2.7*/, temp ) ); /*2Q13*/ - } - IF( EQ_16( element_mode, EVS_MONO ) ) - { - hPrivateData->prevSFM_FIR[p] = tmp32; /*15Q16*/ - } - ELSE - { - hPrivateData->prevSFM_FIR[p] = L_shl( tmp, add( 1, tmp_e ) ); /*15Q16*/ - } - hPrivateData->prevSFM_IIR[p] = SFM; - move32(); - move16(); - - IF( GT_16( SFM, hGrid->whiteningThreshold[1][p] ) ) - { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_STRONG; - move16(); - } - ELSE IF( GT_16( SFM, hGrid->whiteningThreshold[0][p] ) ) - { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; - move16(); - } - ELSE - { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; - move16(); - } - } - - IF( element_mode > EVS_MONO ) - { - IF( last_core_acelp ) /* reset */ - { - set16_fx( hPrivateData->igfPastSFM_fx[p], -ONE_IN_Q13, IGF_PAST_SFM_LEN ); - hPrivateData->igfWhiteningHangoverCnt[p] = 2; - move16(); - } - ELSE - { - test(); - test(); - test(); - test(); - /* check whether change in whitening level should be allowed or not (if SFM is inside a certain margin around thresholds) */ - IF( NE_16( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfPrevWhiteningLevel[p] ) && - ( ( GT_32( SFM, L_sub( hGrid->whiteningThreshold[0][p], 1229 /*0.15f Q13*/ ) ) && LT_32( SFM, L_add( hGrid->whiteningThreshold[0][p], 1229 ) ) ) || - ( GT_32( SFM, L_sub( hGrid->whiteningThreshold[1][p], 1229 ) ) && LT_32( SFM, L_add( hGrid->whiteningThreshold[1][p], 1229 ) ) ) ) ) - { - Word16 mean_past_SFM; - Word16 mean_past_SFM_e; - Word16 countable; - Word16 i; - mean_past_SFM = 0; - mean_past_SFM_e = 0; - countable = 0; - move16(); - move16(); - move16(); - - /* compute mean of last (available) SFM values */ - FOR( i = 0; i < IGF_PAST_SFM_LEN; i++ ) - { - IF( hPrivateData->igfPastSFM_fx[p][i] >= 0 ) - { - mean_past_SFM_e = BASOP_Util_Add_MantExp( mean_past_SFM, mean_past_SFM_e, hPrivateData->igfPastSFM_fx[p][i], 2, &mean_past_SFM ); - countable = add( countable, 1 ); - } - } - IF( countable ) - { - Word16 temp; - mean_past_SFM = BASOP_Util_Divide1616_Scale( mean_past_SFM, countable, &temp ); - mean_past_SFM_e = add( mean_past_SFM_e, sub( temp, 15 ) ); - mean_past_SFM = shl( mean_past_SFM, sub( mean_past_SFM_e, 2 ) ); /*mean_past_SFM_e=2*/ - /* deny change in whitening level for small deviations from mean SFM */ - if ( LT_16( abs_s( sub( SFM, mean_past_SFM ) ), 1638 ) /*0.2 in Q13*/ ) - { - hPrivateData->igfCurrWhiteningLevel[p] = hPrivateData->igfPrevWhiteningLevel[p]; - move16(); - } - } - } - } - - hPrivateData->igfPastSFM_fx[p][hPrivateData->igfPastSFM_pos] = SFM; /*2Q13*/ - move16(); - } - } - - SWITCH( hPrivateData->igfInfo.bitRateIndex ) - { - case IGF_BITRATE_WB_9600: - case IGF_BITRATE_RF_WB_13200: - case IGF_BITRATE_WB_13200_CPE: - case IGF_BITRATE_WB_16400_CPE: - case IGF_BITRATE_RF_SWB_13200: - case IGF_BITRATE_SWB_9600: - case IGF_BITRATE_SWB_13200_CPE: - case IGF_BITRATE_SWB_16400: - case IGF_BITRATE_SWB_24400: - case IGF_BITRATE_SWB_24400_CPE: - case IGF_BITRATE_SWB_32000_CPE: - case IGF_BITRATE_SWB_32000: - case IGF_BITRATE_FB_16400: - case IGF_BITRATE_FB_24400: - case IGF_BITRATE_FB_24400_CPE: - case IGF_BITRATE_FB_32000_CPE: - case IGF_BITRATE_FB_32000: - hPrivateData->igfCurrWhiteningLevel[hGrid->nTiles - 1] = hPrivateData->igfCurrWhiteningLevel[hGrid->nTiles - 2]; - move16(); - BREAK; - default: - BREAK; - } - } - ELSE - { - FOR( p = 0; p < hGrid->nTiles; p++ ) - { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; - move16(); - } - } - } - ELSE - { - /* reset filter */ - FOR( p = 0; p < IGF_MAX_TILES; p++ ) - { - hPrivateData->prevSFM_FIR[p] = 0; - hPrivateData->prevSFM_IIR[p] = 0; - move32(); - move16(); - } - } - - IF( element_mode > EVS_MONO ) - { - IF( EQ_16( SFM, -ONE_IN_Q13 /*1.0f 2Q13*/ ) ) /* reset */ - { - FOR( p = 0; p < hGrid->nTiles; p++ ) - { - set16_fx( hPrivateData->igfPastSFM_fx[p], -ONE_IN_Q13, IGF_PAST_SFM_LEN ); - hPrivateData->igfWhiteningHangoverCnt[p] = 2; - move16(); - } - } - - /* vibrato handling */ - FOR( p = 0; p < hGrid->nTiles; p = p + 2 ) - { - test(); - test(); - test(); - IF( ( hPrivateData->igfPrevWhiteningLevel[p] == IGF_WHITENING_OFF && hPrivateData->igfCurrWhiteningLevel[p] != IGF_WHITENING_OFF ) || - ( hPrivateData->igfPrevWhiteningLevel[p + 1] == IGF_WHITENING_OFF && hPrivateData->igfCurrWhiteningLevel[p + 1] != IGF_WHITENING_OFF ) ) - { - Word16 i; - Word16 pastSfm_a[4], pastSfm_b[4]; - Word16 pastSfmDiffSum_a, pastSfmDiffSum_b; - - FOR( i = 0; i < 4; i++ ) - { - pastSfm_a[i] = hPrivateData->igfPastSFM_fx[p][add( hPrivateData->igfPastSFM_pos, sub( 4, i ) ) % IGF_PAST_SFM_LEN]; - pastSfm_b[i] = hPrivateData->igfPastSFM_fx[p + 1][add( hPrivateData->igfPastSFM_pos, sub( 4, i ) ) % IGF_PAST_SFM_LEN]; - move16(); - move16(); - } - pastSfmDiffSum_a = pastSfmDiffSum_b = 0; - move16(); - move16(); - FOR( i = 0; i < 3; i++ ) - { - IF( NE_16( pastSfm_a[i + 1], -ONE_IN_Q13 ) ) - { - pastSfmDiffSum_a = add( pastSfmDiffSum_a, sub( pastSfm_a[i], pastSfm_a[i + 1] ) ); - pastSfmDiffSum_b = add( pastSfmDiffSum_b, sub( pastSfm_b[i], pastSfm_b[i + 1] ) ); - } - ELSE - { - BREAK; - } - } - test(); - test(); - test(); - test(); - /* if tonality oscillates between two tiles, turn whitening off in both */ - IF( ( ( pastSfmDiffSum_a > 0 && pastSfmDiffSum_b < 0 ) || - ( pastSfmDiffSum_a < 0 && pastSfmDiffSum_b > 0 ) ) && - ( GT_32( L_abs( L_sub( pastSfmDiffSum_a, pastSfmDiffSum_b ) ), ONE_IN_Q12 /* 0.5 in Q13 */ ) ) ) - { - hPrivateData->igfCurrWhiteningLevel[p] = hPrivateData->igfCurrWhiteningLevel[p + 1] = IGF_WHITENING_OFF; - move16(); - move16(); - } - } - } - - /* hangover */ - FOR( p = 0; p < hGrid->nTiles; p++ ) - { - IF( NE_16( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfPrevWhiteningLevel[p] ) ) - { - hPrivateData->igfWhiteningHangoverCnt[p] = add( hPrivateData->igfWhiteningHangoverCnt[p], 1 ); - IF( EQ_16( hPrivateData->igfWhiteningHangoverCnt[p], 3 ) ) - { - hPrivateData->igfWhiteningHangoverCnt[p] = 0; - } - ELSE - { - hPrivateData->igfCurrWhiteningLevel[p] = hPrivateData->igfPrevWhiteningLevel[p]; - } - move16(); - move16(); - } - ELSE - { - hPrivateData->igfWhiteningHangoverCnt[p] = 0; - move16(); - } - } - - hPrivateData->igfPastSFM_pos = add( hPrivateData->igfPastSFM_pos, 1 ) % IGF_PAST_SFM_LEN; - move16(); - } - - hPrivateData->wasTransient = isTransient; - move16(); - - return; -} -#endif -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/**********************************************************************/ /* -write whitening levels into bitstream -**************************************************************************/ - -/* o: Q0 | number of bits written */ -static void IGF_WriteWhiteningTile_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *pBitOffset, /* i : | ptr to bitOffset counter */ - Word16 whiteningLevel /* i : Q0 | whitening levels to write */ -) -{ - IF( EQ_32( whiteningLevel, IGF_WHITENING_MID ) ) - { - IGF_write_bits( hBstr, pBitOffset, 0, 1 ); - } - ELSE - { - IGF_write_bits( hBstr, pBitOffset, 1, 1 ); - IF( EQ_32( whiteningLevel, IGF_WHITENING_OFF ) ) - { - IGF_write_bits( hBstr, pBitOffset, 0, 1 ); - } - ELSE - { - IGF_write_bits( hBstr, pBitOffset, 1, 1 ); - } - } - - return; -} -#else -/**********************************************************************/ /* -write whitening levels into bitstream -**************************************************************************/ - -/* o: Q0 | number of bits written */ -static Word16 IGF_WriteWhiteningTile_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *pBitOffset, /* i : | ptr to bitOffset counter */ - Word16 whiteningLevel /* i : Q0 | whitening levels to write */ -) -{ - Word16 totBitCount; - Word16 startBitCount; - - totBitCount = 0; - startBitCount = *pBitOffset; - move16(); - move16(); - - IF( EQ_16( whiteningLevel, IGF_WHITENING_MID ) ) - { - IGF_write_bits( hBstr, pBitOffset, 0, 1 ); - } - ELSE - { - IGF_write_bits( hBstr, pBitOffset, 1, 1 ); - IF( EQ_16( whiteningLevel, IGF_WHITENING_OFF ) ) - { - IGF_write_bits( hBstr, pBitOffset, 0, 1 ); - } - ELSE - { - IGF_write_bits( hBstr, pBitOffset, 1, 1 ); - } - } - totBitCount = sub( *pBitOffset, startBitCount ); - - return totBitCount; -} - -#endif -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/**********************************************************************/ /* -writes the whitening levels -**************************************************************************/ - -/* o: Q0 | total number of bits written */ -static void IGF_WriteWhiteningLevels_fx( - const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : | instance handle of IGF encoder */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *pBitOffset, /* i : | ptr to bitOffset counter */ - const Word16 igfGridIdx, /* i : Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 isIndepFlag /* i : Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ -) -{ - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - H_IGF_GRID hGrid; - Word16 p; - Word16 nTiles; - Word16 isSame; - Word32 tmp32; - - isSame = 1; - move16(); - hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - nTiles = hGrid->nTiles; - move16(); - - IF( isIndepFlag ) - { - isSame = 0; - move16(); - } - ELSE - { - p = 0; - move16(); - tmp32 = 0; - move32(); - test(); - WHILE( ( LT_16( p, nTiles ) ) && ( tmp32 == 0 ) ) - { - test(); - tmp32 = L_sub( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfPrevWhiteningLevel[p] ); - if ( tmp32 != 0 ) - { - isSame = 0; - move16(); - } - p++; - } - } - IF( isSame ) - { - IGF_write_bits( hBstr, pBitOffset, 1, 1 ); - } - ELSE - { - IF( !isIndepFlag ) - { - IGF_write_bits( hBstr, pBitOffset, 0, 1 ); - } - IGF_WriteWhiteningTile_fx( hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[0] ); - p = 1; - move16(); - tmp32 = 0; - move32(); - if ( LT_16( p, nTiles ) ) - { - isSame = 1; - move16(); - } - test(); - WHILE( ( LT_16( p, nTiles ) ) && ( tmp32 == 0 ) ) - { - test(); - tmp32 = L_sub( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfCurrWhiteningLevel[p - 1] ); - if ( tmp32 != 0 ) - { - isSame = 0; - move16(); - } - p++; - } - - IF( !isSame ) - { - IGF_write_bits( hBstr, pBitOffset, 1, 1 ); - FOR( p = 1; p < nTiles; p++ ) - { - IGF_WriteWhiteningTile_fx( hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[p] ); - } - } - ELSE - { - IGF_write_bits( hBstr, pBitOffset, 0, 1 ); - } - } -} -#else -/**********************************************************************/ /* -writes the whitening levels -**************************************************************************/ - -/* o: Q0 | total number of bits written */ -static Word16 IGF_WriteWhiteningLevels_fx( - const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : | instance handle of IGF encoder */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *pBitOffset, /* i : | ptr to bitOffset counter */ - const Word16 igfGridIdx, /* i : Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 isIndepFlag /* i : Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ -) -{ - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - H_IGF_GRID hGrid; - Word16 p; - Word16 nTiles; - Word16 isSame; - Word32 tmp32; - Word16 totBitCount; - Word16 startBitCount; - - totBitCount = 0; - move16(); - isSame = 1; - move16(); - startBitCount = *pBitOffset; - move16(); - hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - nTiles = hGrid->nTiles; - move16(); - - IF( isIndepFlag ) - { - isSame = 0; - move16(); - } - ELSE - { - p = 0; - move16(); - tmp32 = 0; - move32(); - test(); - WHILE( ( LT_16( p, nTiles ) ) && ( tmp32 == 0 ) ) - { - test(); - tmp32 = L_sub( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfPrevWhiteningLevel[p] ); - if ( tmp32 != 0 ) - { - isSame = 0; - move16(); - } - p++; - } - } - IF( isSame ) - { - IGF_write_bits( hBstr, pBitOffset, 1, 1 ); - } - ELSE - { - IF( !isIndepFlag ) - { - IGF_write_bits( hBstr, pBitOffset, 0, 1 ); - } - IGF_WriteWhiteningTile_fx( hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[0] ); - p = 1; - move16(); - tmp32 = 0; - move32(); - test(); - IF( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) - { - isSame = 1; - move16(); - } - ELSE - { - if ( LT_16( p, nTiles ) ) - { - isSame = 1; - move16(); - } - test(); - WHILE( ( LT_16( p, nTiles ) ) && ( tmp32 == 0 ) ) - { - test(); - tmp32 = L_sub( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfCurrWhiteningLevel[p - 1] ); - if ( tmp32 != 0 ) - { - isSame = 0; - move16(); - } - p++; - } - } - test(); - IF( !isSame ) - { - IGF_write_bits( hBstr, pBitOffset, 1, 1 ); - FOR( p = 1; p < nTiles; p++ ) - { - IGF_WriteWhiteningTile_fx( hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[p] ); - } - } - ELSE IF( NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) && NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) - { - IGF_write_bits( hBstr, pBitOffset, 0, 1 ); - } - } - - totBitCount = sub( *pBitOffset, startBitCount ); - - return totBitCount; -} - -#endif -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/**********************************************************************/ /* -write flattening trigger -**************************************************************************/ - -/* o: number of bits written */ -static void IGF_WriteFlatteningTrigger_fx( - const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : instance handle of IGF Encoder */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *pBitOffset /* i : ptr to bitOffset counter */ -) -{ - Word16 flatteningTrigger; - - - flatteningTrigger = hInstance->flatteningTrigger; - move16(); - - IGF_write_bits( hBstr, pBitOffset, flatteningTrigger, 1 ); -} -#else -/*-------------------------------------------------------------------* - * IGF_WriteFlatteningTrigger_fx() - * - * write flattening trigger - *-------------------------------------------------------------------*/ - -/*! r: number of bits written */ -static Word16 IGF_WriteFlatteningTrigger_fx( - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - BSTR_ENC_HANDLE hBstr, /**< inout: | encoder bitstream handle */ - Word16 *pBitOffset /**< in: | ptr to bitOffset counter */ -) -{ - Word16 flatteningTrigger; - - Word16 totBitCount; - Word16 startBitCount; - totBitCount = 0; - startBitCount = *pBitOffset; - flatteningTrigger = hInstance->flatteningTrigger; - move16(); - move16(); - move16(); - - IGF_write_bits( hBstr, pBitOffset, flatteningTrigger, 1 ); - totBitCount = sub( *pBitOffset, startBitCount ); - - return totBitCount; -} - -#endif -/**********************************************************************/ /* -updates the start/stop frequency of IGF according to igfGridIdx -**************************************************************************/ - -void IGF_UpdateInfo( - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ -) -{ - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - H_IGF_GRID hGrid; - - - hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - hInstance->infoStartFrequency = hGrid->startFrequency; - move16(); - hInstance->infoStopFrequency = hGrid->stopFrequency; - move16(); - hInstance->infoStartLine = hGrid->startLine; - move16(); - hInstance->infoStopLine = hGrid->stopLine; - move16(); - - return; -} - - -/**********************************************************************/ /* -IGF bitsream writer -**************************************************************************/ - -/**< out: | number of bits written per frame */ -Word16 IGFEncWriteBitstream_fx( - const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : instance handle of IGF Encoder */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *pBitOffset, /* i : ptr to bitOffset counter */ - const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - const Word16 isIndepFlag, /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ - const Word16 element_mode /* i : IVAS element mode type */ -#else - const Word16 isIndepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ -#endif -) -{ - Word16 igfAllZero; - Word16 startBitCount; - - - startBitCount = *pBitOffset; - move16(); - hInstance->infoTotalBitsPerFrameWritten = 0; - move16(); - - if ( isIndepFlag ) - { - hInstance->infoTotalBitsWritten = 0; - move16(); - } - -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - IGF_WriteEnvelope( hInstance, hBstr, pBitOffset, igfGridIdx, isIndepFlag, &igfAllZero, element_mode ); -#else - IGF_WriteEnvelope( hInstance, hBstr, pBitOffset, igfGridIdx, isIndepFlag, &igfAllZero ); -#endif - - IGF_WriteWhiteningLevels_fx( hInstance, hBstr, pBitOffset, igfGridIdx, isIndepFlag ); - - IGF_WriteFlatteningTrigger_fx( hInstance, hBstr, pBitOffset ); - - hInstance->infoTotalBitsPerFrameWritten = sub( *pBitOffset, startBitCount ); - hInstance->infoTotalBitsWritten = add( hInstance->infoTotalBitsWritten, hInstance->infoTotalBitsPerFrameWritten ); - move16(); - move16(); - - return hInstance->infoTotalBitsPerFrameWritten; -} - -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/**********************************************************************/ /* -sets the IGF mode according to given bitrate -**************************************************************************/ - -void IGFEncSetMode_fx( - const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */ - const Word32 total_brate, /* i : encoder total bitrate */ - const Word16 bwidth, /* i : encoder audio bandwidth */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 rf_mode /* i : flag to signal the RF mode */ -) -{ - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - Word16 i; - - hPrivateData = &hIGFEnc->igfData; - hPrivateData->igfBitstreamBits = 0; - move16(); - set16_fx( hPrivateData->igfScfQuantized, 0, IGF_MAX_SFB ); - set16_fx( hPrivateData->igfCurrWhiteningLevel, 0, IGF_MAX_TILES ); - set16_fx( hPrivateData->igfPrevWhiteningLevel, 0, IGF_MAX_TILES ); - FOR( i = 0; i < IGF_BITBUFSIZE / 8; i++ ) - { - hPrivateData->igfBitstream[i] = 0; - move16(); - } - hPrivateData->wasTransient = 0; - move16(); - set32_fx( hPrivateData->prevSFM_FIR, 0, IGF_MAX_TILES ); - set16_fx( hPrivateData->prevSFM_IIR, 0, IGF_MAX_TILES ); - - IF( IGFCommonFuncsIGFConfiguration( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) != 0 ) - { - IGFSCFEncoderOpen_fx( &hPrivateData->hIGFSCFArithEnc, &hPrivateData->igfInfo, total_brate, bwidth, element_mode, rf_mode ); - - hIGFEnc->infoSamplingRate = hPrivateData->igfInfo.sampleRate; - move32(); - hIGFEnc->infoStartFrequency = hPrivateData->igfInfo.grid[0].startFrequency; - move16(); - hIGFEnc->infoStopFrequency = hPrivateData->igfInfo.grid[0].stopFrequency; - move16(); - hIGFEnc->infoStartLine = hPrivateData->igfInfo.grid[0].startLine; - move16(); - hIGFEnc->infoStopLine = hPrivateData->igfInfo.grid[0].stopLine; - move16(); - } - ELSE - { - /* IGF configuration failed -> error! */ - hIGFEnc->infoSamplingRate = 0; - move32(); - hIGFEnc->infoStartFrequency = -1; - move16(); - hIGFEnc->infoStopFrequency = -1; - move16(); - hIGFEnc->infoStartLine = -1; - move16(); - hIGFEnc->infoStopLine = -1; - move16(); - fprintf( stderr, "IGFEncSetMode_fx: initialization error!\n" ); - } - - /* reset remaining variables */ - hIGFEnc->infoTotalBitsWritten = 0; - move16(); - hIGFEnc->infoTotalBitsPerFrameWritten = 0; - move16(); - hIGFEnc->flatteningTrigger = 0; - move16(); - hIGFEnc->spec_be_igf_e = 0; - move16(); - hIGFEnc->tns_predictionGain = 0; - move16(); - set32_fx( hIGFEnc->spec_be_igf, 0, N_MAX_TCX - IGF_START_MN ); - - return; -} -#endif -/*-------------------------------------------------------------------* - * pack_bit() - * - * insert a bit into packed octet - *-------------------------------------------------------------------*/ - -static void pack_bit_fx( - const Word16 bit, /* i : bit to be packed */ - UWord8 **pt, /* i/o: pointer to octet array into which bit will be placed */ - UWord8 *omask /* i/o: output mask to indicate where in the octet the bit is to be written */ -) -{ - if ( EQ_16( *omask, 0x80 ) ) - { - **pt = 0; - move16(); - } - - if ( bit != 0 ) - { - **pt = (UWord8) s_or( **pt, *omask ); - move16(); - } - - *omask = (UWord8) UL_lshr( *omask, 1 ); - move16(); - IF( *omask == 0 ) - { - *omask = 0x80; - move16(); - ( *pt )++; - } - - return; -} - -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/*-------------------------------------------------------------------* - * IGFEncConcatenateBitstream() - * - * IGF bitstream concatenation for TCX10 modes - *-------------------------------------------------------------------*/ - -void IGFEncConcatenateBitstream( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ - const Word16 bsBits, /* i : number of IGF bits written to list of indices */ - BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ -) -#else -/*-------------------------------------------------------------------* - * IGFEncConcatenateBitstream_fx() - * - * IGF bitstream concatenation for TCX10 modes - *-------------------------------------------------------------------*/ - -void IGFEncConcatenateBitstream_ivas_fx( - const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ - const Word16 bsBits, /* i : number of IGF bits written to list of indices */ - BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ -) -#endif -{ - Word16 i; - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - Indice *ind_list; - UWord8 *pFrame; /* byte array with bit packet and byte aligned coded speech data */ - Word16 *pFrame_size; /* number of bits in the binary encoded access unit [bits] */ - Word16 k, nb_bits_written; - Word32 imask; - UWord8 omask; - - hPrivateData = &hIGFEnc->igfData; - - ind_list = &hBstr->ind_list[hBstr->nb_ind_tot - bsBits]; /* here, we assume that each bit has been written as a single indice */ - pFrame = hPrivateData->igfBitstream; - move16(); - pFrame_size = &hPrivateData->igfBitstreamBits; - move16(); - nb_bits_written = 0; - move16(); - - omask = (UWord8) UL_lshr( 0x80, s_and( *pFrame_size, 0x7 ) ); - move16(); - pFrame += *pFrame_size >> 3; - - /* bitstream packing (conversion of individual indices into a serial stream) */ - FOR( i = 0; i < bsBits; i++ ){ - IF( ind_list[i].nb_bits > 0 ){ - /* mask from MSB to LSB */ - imask = L_shl( 1, sub( ind_list[i].nb_bits, 1 ) ); - - /* write bit by bit */ - FOR( k = 0; k < ind_list[i].nb_bits; k++ ) - { - pack_bit_fx( extract_l( L_and( ind_list[i].value, imask ) ), &pFrame, &omask ); - imask = L_shr( imask, 1 ); - } - nb_bits_written = add( nb_bits_written, ind_list[i].nb_bits ); - - /* delete the indice */ - ind_list[i].nb_bits = -1; - move16(); -} -} - -*pFrame_size = add( *pFrame_size, nb_bits_written ); -move16(); - -/* update list of indices */ -hBstr->nb_ind_tot = sub( hBstr->nb_ind_tot, bsBits ); -hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, nb_bits_written ); - -return; -} - - -/**********************************************************************/ /* - IGF write concatenated bitsream for TCX10 modes -**************************************************************************/ - -/* o: Q0 | total number of bits written */ -Word16 IGFEncWriteConcatenatedBitstream_fx( - const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : instance handle of IGF Encoder */ - BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ -) -{ - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - Word16 i; - Word16 tmp; - Word16 bitsLeft; - UWord8 *pBitstream; - - hPrivateData = &hInstance->igfData; - pBitstream = &hPrivateData->igfBitstream[0]; - - tmp = shr( hPrivateData->igfBitstreamBits, 3 ); - FOR( i = 0; i < tmp; i++ ) - { - push_next_indice( hBstr, pBitstream[i], 8 ); - } - - bitsLeft = s_and( hPrivateData->igfBitstreamBits, 0x7 ); - IF( bitsLeft > 0 ) - { - push_next_indice( hBstr, shr( pBitstream[i], sub( 8, bitsLeft ) ), bitsLeft ); - } - - return hInstance->infoTotalBitsWritten; + return totBitCount; } -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/**< out: Q0 | total number of bits written */ -Word16 IGFEncWriteConcatenatedBitstream_ivas_fx( - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ -) -{ - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - Word16 i; - Word16 tmp; - Word16 bitsLeft; - UWord8 *pBitstream; - - hPrivateData = &hInstance->igfData; - pBitstream = &hPrivateData->igfBitstream[0]; - - tmp = shr( hPrivateData->igfBitstreamBits, 3 ); - FOR( i = 0; i < tmp; i++ ) - { - push_next_indice( hBstr, pBitstream[i], 8 ); - } - - bitsLeft = s_and( hPrivateData->igfBitstreamBits, 0x7 ); - IF( bitsLeft > 0 ) - { - push_next_indice( hBstr, shr( pBitstream[i], sub( 8, bitsLeft ) ), bitsLeft ); - } - return hInstance->infoTotalBitsWritten; -} -#endif -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /**********************************************************************/ /* -apply the IGF encoder, main encoder interface -**************************************************************************/ - -void IGFEncApplyMono_fx( - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - const Word16 igfGridIdx, /**< in: Q0 | IGF grid index */ - Encoder_State *st, /**< in: | Encoder state */ - Word32 *pMDCTSpectrum, /**< in: Q31 | MDCT spectrum */ - Word16 MDCTSpectrum_e, /**< in: | exponent of MDCT spectrum */ - Word32 *pPowerSpectrum, /**< in: Q31 | MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 PowerSpectrum_e, /**< in: | exponent of pPowerSpectrum */ - Word16 isTCX20, /**< in: Q0 | flag indicating if the input is TCX20 or TCX10/2xTCX5 */ - Word16 isTNSActive, /**< in: Q0 | flag indicating if the TNS is active */ - Word16 last_core_acelp /**< in: Q0 | indicator if last frame was acelp coded */ -) -{ - Word32 *pPowerSpectrumParameter; /* If it is NULL it informs a function that specific handling is needed */ - Word32 *pPowerSpectrumParameterWhitening; /* If it is NULL it informs a function that specific handling is needed */ - Word16 highPassEner_exp; /*exponent of highpass energy - maybe not needed*/ - - pPowerSpectrumParameter = NULL; - test(); - if ( ( isTNSActive == 0 ) && ( isTCX20 != 0 ) ) - { - pPowerSpectrumParameter = pPowerSpectrum; - } - pPowerSpectrumParameterWhitening = NULL; - if ( isTCX20 != 0 ) - { - pPowerSpectrumParameterWhitening = pPowerSpectrum; - } - - IGF_UpdateInfo( hInstance, igfGridIdx ); - - IGF_CalculateEnvelope( hInstance, pMDCTSpectrum, MDCTSpectrum_e, pPowerSpectrumParameter, PowerSpectrum_e, igfGridIdx ); - - IGF_Whitening( hInstance, pPowerSpectrumParameterWhitening, PowerSpectrum_e, igfGridIdx, ( st->hTranDet->transientDetector.bIsAttackPresent == 1 ), last_core_acelp ); - - pPowerSpectrumParameter = NULL; - if ( isTCX20 != 0 ) - { - pPowerSpectrumParameter = pPowerSpectrum; - } - - IGF_ErodeSpectrum( &highPassEner_exp, hInstance, pMDCTSpectrum, pPowerSpectrumParameter, PowerSpectrum_e, igfGridIdx ); - - return; -} -#endif - -ivas_error IGF_Reconfig_fx( - IGF_ENC_INSTANCE_HANDLE *hIGFEnc, /* i/o: instance handle of IGF Encoder */ - const Word16 igf, /* i : IGF on/off */ - const Word16 reset, /* i : reset flag */ - const Word32 brate, /* i : bitrate for configuration */ - const Word16 bwidth, /* i : signal bandwidth */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 rf_mode /* i : flag to signal the RF mode */ -) -{ - ivas_error error; - - error = IVAS_ERR_OK; - move32(); - - test(); - test(); - test(); - IF( igf && *hIGFEnc == NULL ) - { - IF( ( *hIGFEnc = (IGF_ENC_INSTANCE_HANDLE) malloc( sizeof( IGF_ENC_INSTANCE ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n" ) ); - } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - IGFEncSetMode_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); -#else - IGFEncSetMode_ivas_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); -#endif - } - ELSE IF( igf && reset ) - { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - IGFEncSetMode_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); -#else - IGFEncSetMode_ivas_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); -#endif - } - ELSE IF( !igf && *hIGFEnc != NULL ) - { - free( *hIGFEnc ); - *hIGFEnc = NULL; - } - - return error; -} - - -#define INV_Log2_10_Q15 9864 /*1/log2(10) in Q15*/ -#define INV_Log2_10_Q12 1233 /*1/log2(10) in Q12*/ -#define INV_Log2_e_Q15 22713 /*1/log2(e) in Q15*/ - -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/*-------------------------------------------------------------------* - * IGF_getCrest_new() - * - * crest factor calculation - *-------------------------------------------------------------------*/ - -/*! r: crest factor */ -static Word16 IGF_getCrest_new_fx( - const Word16 *logSpec, /* i : power spectrum */ - const Word16 start, /* i : start subband index */ - const Word16 stop, /* i : stop subband index */ - Word16 *crest_exp /*Stores the exponent of the result(return value)*/ -) -{ - Word16 i; - Word16 x; - Word32 x_eff; - Word16 x_max; - Word16 exp; - Word16 temp; - Word16 temp_e; - Word16 crest; /*1.0f in Q15*/ - x_eff = 0; - x_max = 0; - exp = 0; - temp = 0; - crest = 32767; /*1.0f in Q15*/ - move32(); - move16(); - move16(); - move16(); - move16(); - - FOR( i = start; i < stop; i++ ) - { - x = logSpec[i]; - move16(); - x_eff = L_mac0( x_eff, x, x ); - - if ( GT_16( x, x_max ) ) - { - x_max = x; - move16(); - } - } - - x_eff = BASOP_Util_Divide3216_Scale( x_eff, sub( stop, start ), &temp_e ); - temp_e = add( temp_e, 16 ); /*exp += 31 - 15 + 16(because x_eff is word32)*/ - x_eff = L_shr( x_eff, sub( 15, temp_e ) ); - temp_e = 15; - move16(); - temp = Sqrt16( extract_l( x_eff ), &temp_e ); - - test(); - IF( x_eff > 0 && x_max > 0 ) - { - temp = BASOP_Util_Divide1616_Scale( x_max, temp, &exp ); - exp = add( exp, sub( 15, temp_e ) ); - IF( exp < 0 ) - { - temp = shl( temp, exp ); - exp = 0; - move16(); - } - crest = s_max( shl_sat( 1, sub( 15, exp ) ), temp ); - } - *crest_exp = exp; - move16(); - return crest; -} - - -/*-------------------------------------------------------------------* - * IGF_getSFM_new() - * - * calculates spectral flatness measurement - *-------------------------------------------------------------------*/ - -/*! r: SFM value */ -static Word16 IGF_getSFM_new_fx( - const Word32 *powerSpectrum, /* i : power spectrum */ - const Word16 *logSpec, /* i : log of power spectrum */ - const Word16 start, /* i : start subband index */ - const Word16 stop, /* i : stop subband index */ - Word16 *e_ps /*Stores exp related to power spectrum*/ -) -{ - Word16 n; - Word16 i; - Word16 num; - Word32 denom; - Word16 numf; - Word32 tmp; - Word16 sfm; - Word16 sfm_e; - Word16 denom_e; - Word16 numf_e; /*stores exponent for numf*/ - Word16 tmp_e; - - num = 0; - denom = ONE_IN_Q30; - denom_e = 1; - sfm = MAX16B; // Q15 - move16(); - move32(); - move16(); - move16(); - - FOR( i = start; i < stop; i++ ) - { - tmp = powerSpectrum[i]; - n = logSpec[i /*-start*/]; - move32(); - move16(); - num = add( num, n ); - denom = BASOP_Util_Add_Mant32Exp( tmp, e_ps[i], denom, denom_e, &denom_e ); - } - - numf = BASOP_Util_Divide1616_Scale( num, sub( stop, start ), &numf_e ); - denom = BASOP_Util_Divide3216_Scale( denom, sub( stop, start ), &tmp_e ); - denom_e = add( add( denom_e, tmp_e ), 1 ); /*denom_e+tmp_e-15 +16(because type of denom is word32)*/ - - IF( denom != 0 ) - { - tmp = BASOP_util_Pow2( L_add( numf, shl_sat( 1, sub( 14, numf_e ) ) ), add( 16, numf_e ), &tmp_e ); - sfm = BASOP_Util_Divide3232_Scale( tmp, denom, &sfm_e ); - sfm_e = add( sfm_e, sub( tmp_e, denom_e ) ); - sfm = shl_sat( extract_l( L_min( sfm, L_shl_sat( 1, sub( 15, sfm_e ) ) ) ), sfm_e ); - } - - return sfm; -} -#endif -/*-------------------------------------------------------------------* - * IGF_getTilt() - * - * calculates spectral tilt - *-------------------------------------------------------------------*/ - -/*! r: spectral tilt value */ - -/*-------------------------------------------------------------------* - * IGF_getTNR() - * - * calculates tonal-to-noise ratio - *-------------------------------------------------------------------*/ - -/*! r: spectral tilt value */ -/* Returns value with exponent as 9 and Q as 22*/ +updates the start/stop frequency of IGF according to igfGridIdx +**************************************************************************/ -static Word32 IGF_getTNR_ivas_fx( - const Word32 *powerSpectrum, /* i : energies */ - const Word16 start, /* i : start subband index */ - const Word16 stop, /* i : stop subband index */ - const Word16 adap, /* i : SFB width adaptation */ - Word16 *e_ps, /*Stores exponent for powerSpectrum*/ - Word16 e_adap /*Stores exponent for adap*/ +void IGF_UpdateInfo( + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ ) { - Word16 i; - Word16 width; - Word32 avg; - Word32 tonal; - Word16 tonal_e; /* holds exp for tonal*/ - Word32 noise; - Word16 noise_e; /* holds exp for noise*/ - Word32 tonalToNoise; - Word32 rootSpec[300]; - Word16 rootSpec_e[300]; /*rootSpec_e[i] holds exp for rootSpec[i]*/ - Word16 avg_e; /* holds exp for avg*/ - Word16 tmp_e; - avg = 0; - tonal = 0; - noise = EPSILON_FX; - tonal_e = 0; - noise_e = 0; - avg_e = 0; - tmp_e = 0; - move32(); - move32(); - move32(); + IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; + H_IGF_GRID hGrid; + + + hPrivateData = &hInstance->igfData; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + hInstance->infoStartFrequency = hGrid->startFrequency; move16(); + hInstance->infoStopFrequency = hGrid->stopFrequency; move16(); + hInstance->infoStartLine = hGrid->startLine; move16(); + hInstance->infoStopLine = hGrid->stopLine; move16(); - set32_fx( rootSpec, 0, 300 ); - set16_fx( rootSpec_e, 0, 300 ); - - width = sub( stop, start ); - FOR( i = start; i < stop; i++ ) - { - rootSpec_e[( i - start )] = e_ps[i]; - move16(); - rootSpec[( i - start )] = Sqrt32( powerSpectrum[i], &rootSpec_e[( i - start )] ); /*rootSpec[i - start] = sqrtf( powerSpectrum[i] );*/ - move32(); - avg = BASOP_Util_Add_Mant32Exp( avg, avg_e, rootSpec[( i - start )], rootSpec_e[( i - start )], &avg_e ); /*avg += rootSpec[i - start];resultant exponent is avg_e*/ - } - avg = BASOP_Util_Divide3216_Scale( avg, width, &tmp_e ); /*avg /= width;*/ - avg_e = add( 16, sub( add( avg_e, tmp_e ), 15 ) ); - - FOR( i = start; i < stop; i++ ) - { - Word16 normSpec_e; /*stores resultant exponent for normSpec*/ - Word16 normSpec = BASOP_Util_Divide3232_Scale( rootSpec[i - start], avg, &normSpec_e ); /*rootSpec[i - start] / avg;*/ - normSpec_e = add( normSpec_e, sub( rootSpec_e[i - start], avg_e ) ); - IF( GT_32( normSpec, L_add_sat( L_shl_sat( 1, sub( 15, normSpec_e ) ), L_shl_sat( adap, sub( e_adap, normSpec_e ) ) ) ) ) - { - tonal = BASOP_Util_Add_Mant32Exp( tonal, tonal_e, rootSpec[( i - start )], rootSpec_e[( i - start )], &tonal_e ); /*tonal += rootSpec[i - start];*/ - } - ELSE IF( LT_32( normSpec, L_shl_sat( 1, sub( 15, normSpec_e ) ) ) ) - { - noise = BASOP_Util_Add_Mant32Exp( noise, noise_e, rootSpec[( i - start )], rootSpec_e[( i - start )], &noise_e ); /*noise += rootSpec[i - start];*/ - } - } - - /*tonalToNoise = 20.f * log10f( max( 1e-018f, tonal / noise ) )*/ - IF( noise == 0 ) // To handle condition if denom = 0 - { - tonalToNoise = imult3216( L_shr( L_add( L_shl( 18 /* log10f(1e-018f) */, Q25 ), Mpy_32_16_1( L_add( BASOP_Util_Log2( tonal ), L_shl( tonal_e, Q25 ) ) /*Q25*/, INV_Log2_10_Q15 ) /*25+15-15*/ ), 3 ) /*Q22*/, 20 ); - } - ELSE - { - Word16 temp = BASOP_Util_Divide3232_Scale( tonal, noise, &tmp_e ); /*tonal / noise*/ - tmp_e = add( tmp_e, sub( tonal_e, noise_e ) ); - IF( GE_16( temp, 1 ) ) - { - tonalToNoise = imult3216( Mult_32_16( L_add( BASOP_Util_Log2( temp ), L_shl( add( 16, tmp_e ), Q25 ) ) /*Q25*/, INV_Log2_10_Q12 ) /*25+12-15*/, 20 ); /*Q22*/ - } - ELSE - { - tonalToNoise = -1509949440; /*-360.f Q22*/ - move32(); - } - } - - return tonalToNoise; + return; } -/*-------------------------------------------------------------------* - * IGF_CalculateEnvelope() - * - * envelope estimation - *-------------------------------------------------------------------*/ -static void IGF_CalculateEnvelope_ivas_fx( - const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ - Word32 *pMDCTSpectrum_fx, /* i : MDCT spectrum */ - Word16 e_mdct, /* i : exp of MDCT spectrum */ - Word32 *pPowerSpectrum_fx, /* i : MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 *e_ps, /* i : exp of power spectrum */ - const Word16 igfGridIdx, /* i : IGF grid index */ - const Word16 isTransient, /* i : flag indicating if transient is detected */ - const Word16 last_core_acelp, /* i : indicator if last frame was ACELP core */ - const Word16 element_mode, /* i : IVAS element_mode */ - const Word16 att /* i : attenuation */ +/**********************************************************************/ /* +IGF bitsream writer +**************************************************************************/ + +/**< out: | number of bits written per frame */ +Word16 IGFEncWriteBitstream_fx( + const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : instance handle of IGF Encoder */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /* i : ptr to bitOffset counter */ + const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 isIndepFlag, /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ + const Word16 element_mode /* i : IVAS element mode type */ ) { - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - H_IGF_GRID hGrid; - Word16 *swb_offset; - Word16 sfb; /* this is the actual scalefactor band */ - Word16 width; /* this is width in subbands of the actual scalefactor band */ - Word16 tile_idx; - Word16 strt_cpy; - Word32 gain; /* the gain which has to be applied to the source tile to get the destination energy */ - Word16 sb; - Word32 sfbEnergyR; - Word32 sfbEnergyC; /* the energy of the destination region of the tile */ - Word32 sfbEnergyTileR; - Word32 sfbEnergyTileC; /* the energy of the destination region of the tile */ - Word16 tmp, x, y; - Word16 mean_x_fx, mean_y_fx; - Word32 mean_xy_fx, mean_x2_fx; - Word16 tmp_tb; - Word16 tmp_sb; - Word16 sfbCnt; - Word16 sfm; - Word16 crest; - Word16 temp; - Word16 mean_x_e, mean_y_e; /*Stores exponent for mean_x and mean_y respectively*/ - Word16 mean_xy_e, mean_x2_e; /*stores exponent for mean_xy and mean_x2 respectively*/ - Word16 sfbEnergyTileR_e; /*Exponent for sfbEnergyTileR*/ - Word16 sfbEnergyTileC_e; /*Exponent for sfbEnergyTileC*/ - Word16 sfbEnergyC_e; /*Exponent for sfbEnergyC*/ - Word16 sfbEnergyR_e; - Word16 gain_e; /*exponent for gain*/ - Word16 tmp_tb_e; /*Stores exponent for tmp_tb*/ - Word16 tmp_sb_e; /*stores exponent for tmp_sb*/ - Word16 crest_exp; /*Stores the exponent of the result(return value)*/ - Word16 sfm_exp; /*stores exponent for ouput from sfm*/ - Word16 tmp_e; + Word16 igfAllZero; + Word16 startBitCount; - hPrivateData = &hIGFEnc->igfData; - hGrid = &hPrivateData->igfInfo.grid[(Word16) igfGridIdx]; - swb_offset = hGrid->swb_offset; - IF( element_mode > EVS_MONO ) - { - IF( igfGridIdx != IGF_GRID_LB_NORM ) - { - FOR( sfbCnt = 0; sfbCnt < sub( hGrid->sfbWrap[hGrid->nTiles], hGrid->sfbWrap[0] ); sfbCnt++ ) - { - /* reset filter */ - hPrivateData->prevSFM_FIR_SFB_TB_fx[sfbCnt] = 0; // exponent : hPrivateData->prevSFB_FIR_TB_e[sfbCnt] - hPrivateData->prevSFB_FIR_TB_e[sfbCnt] = 0; - hPrivateData->prevSFM_IIR_SFB_TB_fx[sfbCnt] = 0; // exponent : hPrivateData->prevSFB_IIR_TB_e[sfbCnt] - hPrivateData->prevSFB_IIR_TB_e[sfbCnt] = 0; - hPrivateData->prevSFM_FIR_SFB_SB_fx[sfbCnt] = 0; // exponent : hPrivateData->prevSFB_FIR_SB_e[sfbCnt] - hPrivateData->prevSFB_FIR_SB_e[sfbCnt] = 0; - hPrivateData->prevSFM_IIR_SFB_SB_fx[sfbCnt] = 0; // exponent : hPrivateData->prevSFB_IIR_SB_e[sfbCnt] - hPrivateData->prevSFB_IIR_SB_e[sfbCnt] = 0; - hPrivateData->prevDampingFactor_IIR_fx[sfbCnt] = MIN16B; /* -1.f in Q15*/ - hPrivateData->prevDampingFactor_IIR_e[sfbCnt] = 0; - hPrivateData->dampingFactorSmoothing[sfbCnt] = 2; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - } - } - } + startBitCount = *pBitOffset; + move16(); + hInstance->infoTotalBitsPerFrameWritten = 0; + move16(); - IF( pPowerSpectrum_fx ) + if ( isIndepFlag ) { - FOR( sb = hGrid->sbWrap[0]; sb < swb_offset[hGrid->sfbWrap[hGrid->nTiles]]; sb++ ) - { - IF( LT_32( 1, pPowerSpectrum_fx[sb] ) ) - { - hPrivateData->logSpec[sb] = s_max( 0, extract_l( W_extract_l( W_shr( W_add( BASOP_Util_Log2( pPowerSpectrum_fx[sb] ), W_shl( e_ps[sb], Q25 ) ), Q25 ) ) ) ); - move16(); - } - ELSE - { - hPrivateData->logSpec[sb] = 0; - move16(); - } - } + hInstance->infoTotalBitsWritten = 0; + move16(); } - FOR( tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++ ) - { - strt_cpy = hGrid->sbWrap[tile_idx]; - move16(); + IGF_WriteEnvelope( hInstance, hBstr, pBitOffset, igfGridIdx, isIndepFlag, &igfAllZero, element_mode ); - FOR( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ ) - { - width = sub( swb_offset[sfb + 1], swb_offset[sfb] ); - sfbEnergyTileR = EPSILON_FIX; - sfbEnergyTileC = EPSILON_FIX; - sfbEnergyC = EPSILON_FX; - sfbEnergyTileR_e = 0; - sfbEnergyTileC_e = 0; - sfbEnergyC_e = 0; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); + IGF_WriteWhiteningLevels_fx( hInstance, hBstr, pBitOffset, igfGridIdx, isIndepFlag ); - IF( pPowerSpectrum_fx != NULL ) - { - tmp = strt_cpy; - move16(); - FOR( sb = swb_offset[sfb]; sb < swb_offset[sfb + 1]; sb++ ) - { - Word16 shift = norm_l( pPowerSpectrum_fx[sb] ); - sfbEnergyC = BASOP_Util_Add_Mant32Exp( sfbEnergyC, sfbEnergyC_e, L_shl( pPowerSpectrum_fx[sb], shift ), sub( e_ps[sb], shift ), &sfbEnergyC_e ); - // sfbEnergyTileR = BASOP_Util_Add_Mant32Exp( sfbEnergyTileR, sfbEnergyTileR_e, Mult_32_32( pMDCTSpectrum_fx[strt_cpy], pMDCTSpectrum_fx[strt_cpy] ), shl( e_mdct, 1 ), &sfbEnergyTileR_e ); - Word64 tmp64 = W_mult_32_32( pMDCTSpectrum_fx[strt_cpy], pMDCTSpectrum_fx[strt_cpy] ); - Word16 tmp64_e = W_norm( tmp64 ); - tmp64 = W_shl( tmp64, tmp64_e ); + IGF_WriteFlatteningTrigger_fx( hInstance, hBstr, pBitOffset ); - sfbEnergyTileR = BASOP_Util_Add_Mant32Exp( sfbEnergyTileR, sfbEnergyTileR_e, W_extract_h( tmp64 ), shl( e_mdct, 1 ) - tmp64_e, &sfbEnergyTileR_e ); - shift = norm_l( pPowerSpectrum_fx[strt_cpy] ); - sfbEnergyTileC = BASOP_Util_Add_Mant32Exp( sfbEnergyTileC, sfbEnergyTileC_e, L_shl( pPowerSpectrum_fx[strt_cpy], shift ), sub( e_ps[strt_cpy], shift ), &sfbEnergyTileC_e ); + hInstance->infoTotalBitsPerFrameWritten = sub( *pBitOffset, startBitCount ); + hInstance->infoTotalBitsWritten = add( hInstance->infoTotalBitsWritten, hInstance->infoTotalBitsPerFrameWritten ); + move16(); + move16(); - strt_cpy = add( strt_cpy, 1 ); - } + return hInstance->infoTotalBitsPerFrameWritten; +} - sfbEnergyTileR = L_deposit_h( BASOP_Util_Divide3232_Scale( sfbEnergyTileR, width, &tmp_e ) ); - sfbEnergyTileR_e = add( sub( sfbEnergyTileR_e, Q31 ), tmp_e ); - IF( sfbEnergyTileR == 0 ) - { - sfbEnergyTileR = EPSILON_FX; - sfbEnergyTileR_e = 0; - move32(); - move16(); - } - IF( sfbEnergyC == 0 ) - { - sfbEnergyC = EPSILON_FX; - sfbEnergyC_e = 0; - move32(); - move16(); - } - IF( sfbEnergyTileC == 0 ) - { - sfbEnergyTileC = EPSILON_FX; - sfbEnergyTileC_e = 0; - temp = BASOP_Util_Divide3232_Scale( sfbEnergyC, sfbEnergyTileC, &tmp_e ); - tmp_e = add( tmp_e, sub( sfbEnergyC_e, sfbEnergyTileC_e ) ); - move32(); - move16(); - } - ELSE - { - /*gain = (float) ( sfbEnergyTileR * ( sfbEnergyC / sfbEnergyTileC ) );*/ - temp = BASOP_Util_Divide3232_Scale( sfbEnergyC, sfbEnergyTileC, &tmp_e ); - tmp_e = add( tmp_e, sub( sfbEnergyC_e, sfbEnergyTileC_e ) ); - } +/*-------------------------------------------------------------------* + * pack_bit() + * + * insert a bit into packed octet + *-------------------------------------------------------------------*/ - gain = Mult_32_16( sfbEnergyTileR, temp ); // gain_e - gain_e = add( tmp_e, sfbEnergyTileR_e ); +static void pack_bit_fx( + const Word16 bit, /* i : bit to be packed */ + UWord8 **pt, /* i/o: pointer to octet array into which bit will be placed */ + UWord8 *omask /* i/o: output mask to indicate where in the octet the bit is to be written */ +) +{ + if ( EQ_16( *omask, 0x80 ) ) + { + **pt = 0; + move16(); + } - IF( element_mode > EVS_MONO ) - { - test(); - IF( !isTransient ) - { - Word16 diffSFM; - Word16 shiftedSFM = 0; - Word16 shiftedSFM_e = 0; - move16(); - move16(); + if ( bit != 0 ) + { + **pt = (UWord8) s_or( **pt, *omask ); + move16(); + } - // tmp_tb = IGF_getSFM_new( pPowerSpectrum, hPrivateData->logSpec, swb_offset[sfb], swb_offset[sfb + 1] ) / IGF_getCrest_new( hPrivateData->logSpec, swb_offset[sfb], swb_offset[sfb + 1] ); - sfm = IGF_getSFM_new_fx( pPowerSpectrum_fx, hPrivateData->logSpec, swb_offset[sfb], swb_offset[sfb + 1], e_ps ); - sfm_exp = 0; - move16(); - crest = IGF_getCrest_new_fx( hPrivateData->logSpec, swb_offset[sfb], swb_offset[sfb + 1], &crest_exp ); - tmp_tb = BASOP_Util_Divide1616_Scale( sfm, crest, &tmp_e ); // tmp_tb_e - tmp_tb_e = add( tmp_e, sub( sfm_exp, crest_exp ) ); + *omask = (UWord8) UL_lshr( *omask, 1 ); + move16(); + IF( *omask == 0 ) + { + *omask = 0x80; + move16(); + ( *pt )++; + } - // tmp_sb = IGF_getSFM_new( pPowerSpectrum, hPrivateData->logSpec, tmp, strt_cpy ) / IGF_getCrest_new( hPrivateData->logSpec, tmp, strt_cpy ); - sfm = IGF_getSFM_new_fx( pPowerSpectrum_fx, hPrivateData->logSpec, tmp, strt_cpy, e_ps ); - crest = IGF_getCrest_new_fx( hPrivateData->logSpec, tmp, strt_cpy, &crest_exp ); - tmp_sb = BASOP_Util_Divide1616_Scale( sfm, crest, &tmp_e ); // tmp_sb_e - tmp_sb_e = add( tmp_e, sub( sfm_exp, crest_exp ) ); + return; +} - test(); - IF( last_core_acelp || hPrivateData->wasTransient ) - { - hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = tmp_tb; /*Exponent for hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] : hPrivateData->prevSFB_FIR_TB_e[sfb] and hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] : hPrivateData->prevSFB_IIR_TB_e[sfb] */ - hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = tmp_sb; /*Exponent for hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] : hPrivateData->prevSFB_FIR_SB_e[sfb] and hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] : hPrivateData->prevSFB_IIR_SB_e[sfb] */ - hPrivateData->prevSFB_FIR_TB_e[sfb] = hPrivateData->prevSFB_IIR_TB_e[sfb] = tmp_tb_e; - hPrivateData->prevSFB_FIR_SB_e[sfb] = hPrivateData->prevSFB_IIR_SB_e[sfb] = tmp_sb_e; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - } +/*-------------------------------------------------------------------* + * IGFEncConcatenateBitstream() + * + * IGF bitstream concatenation for TCX10 modes + *-------------------------------------------------------------------*/ - tmp_tb = shr( tmp_tb, 2 ); /*taking 2 guard bits so it's exponent tmp_sb_e=+2*/ - tmp_sb = shr( tmp_sb, 2 ); /*taking 2 guard bits so it's exponent tmp_tb_e=+2 */ - tmp_sb_e = add( tmp_sb_e, 2 ); - tmp_tb_e = add( tmp_tb_e, 2 ); +void IGFEncConcatenateBitstream( + const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ + const Word16 bsBits, /* i : number of IGF bits written to list of indices */ + BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ +) +{ + Word16 i; + IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; + Indice *ind_list; + UWord8 *pFrame; /* byte array with bit packet and byte aligned coded speech data */ + Word16 *pFrame_size; /* number of bits in the binary encoded access unit [bits] */ + Word16 k, nb_bits_written; + Word32 imask; + UWord8 omask; - Word16 tmp0, tmp2, tmp3, tmp4; - Word16 tmp0_e, tmp2_e, tmp3_e, tmp4_e; - tmp0 = shr( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], 2 ); - tmp0_e = add( hPrivateData->prevSFB_FIR_TB_e[sfb], 2 ); - move16(); - tmp2 = shr( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], 2 ); - tmp2_e = add( hPrivateData->prevSFB_IIR_TB_e[sfb], 2 ); - move16(); - tmp3 = shr( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], 2 ); - tmp3_e = add( hPrivateData->prevSFB_FIR_SB_e[sfb], 2 ); - move16(); - tmp4 = shr( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], 2 ); - tmp4_e = add( hPrivateData->prevSFB_IIR_SB_e[sfb], 2 ); - move16(); - Word16 x1, x2; + hPrivateData = &hIGFEnc->igfData; - Word16 x1_e = BASOP_Util_Add_MantExp( tmp0, tmp0_e, tmp2, tmp2_e - 1, &x1 ); - Word16 x2_e = BASOP_Util_Add_MantExp( tmp3, tmp3_e, tmp4, tmp4_e - 1, &x2 ); - hPrivateData->sfb_tb_e[sfb] = BASOP_Util_Add_MantExp( tmp_tb, tmp_tb_e, x1, x1_e, &hPrivateData->SFM_tb_fx[sfb] ); // hPrivateData->sfb_sb_e[sfb] - move16(); - BASOP_Util_Add_MantExp( 22118, 2, negate( hPrivateData->SFM_tb_fx[sfb] ), hPrivateData->sfb_tb_e[sfb], &tmp ); + ind_list = &hBstr->ind_list[hBstr->nb_ind_tot - bsBits]; /* here, we assume that each bit has been written as a single indice */ + pFrame = hPrivateData->igfBitstream; + move16(); + pFrame_size = &hPrivateData->igfBitstreamBits; + move16(); + nb_bits_written = 0; + move16(); - IF( tmp < 0 ) - { - hPrivateData->sfb_tb_e[sfb] = 2; - hPrivateData->SFM_tb_fx[sfb] = 22118; - move16(); - move16(); - } + omask = (UWord8) UL_lshr( 0x80, s_and( *pFrame_size, 0x7 ) ); + move16(); + pFrame += *pFrame_size >> 3; - hPrivateData->sfb_sb_e[sfb] = BASOP_Util_Add_MantExp( tmp_sb, tmp_sb_e, x2, x2_e, &hPrivateData->SFM_sb_fx[sfb] ); // hPrivateData->sfb_tb_e[sfb] - move16(); - BASOP_Util_Add_MantExp( 22118, 2, negate( hPrivateData->SFM_sb_fx[sfb] ), hPrivateData->sfb_sb_e[sfb], &tmp ); + /* bitstream packing (conversion of individual indices into a serial stream) */ + FOR( i = 0; i < bsBits; i++ ){ + IF( ind_list[i].nb_bits > 0 ){ + /* mask from MSB to LSB */ + imask = L_shl( 1, sub( ind_list[i].nb_bits, 1 ) ); - IF( tmp < 0 ) - { - hPrivateData->sfb_sb_e[sfb] = 2; - hPrivateData->SFM_sb_fx[sfb] = 22118; - move16(); - move16(); - } + /* write bit by bit */ + FOR( k = 0; k < ind_list[i].nb_bits; k++ ) + { + pack_bit_fx( extract_l( L_and( ind_list[i].value, imask ) ), &pFrame, &omask ); + imask = L_shr( imask, 1 ); + } + nb_bits_written = add( nb_bits_written, ind_list[i].nb_bits ); - BASOP_Util_Add_MantExp( hPrivateData->SFM_sb_fx[sfb], hPrivateData->sfb_sb_e[sfb], negate( hPrivateData->SFM_tb_fx[sfb] ), hPrivateData->sfb_tb_e[sfb], &diffSFM ); + /* delete the indice */ + ind_list[i].nb_bits = -1; + move16(); +} +} - test(); - IF( diffSFM > 0 && LT_32( hPrivateData->SFM_tb_fx[sfb], L_shr( 3277 /*0.1 Q15*/, hPrivateData->sfb_tb_e[sfb] ) ) ) /* check whether target SFB is more tonal than source SFB */ - { - Word16 currDampingFactor, dampingFactor; - Word16 slope, threshold; - Word16 alpha; - Word16 slope_e, threshold_e, currDampingFactor_e, dampingFactor_e, alpha_e; +*pFrame_size = add( *pFrame_size, nb_bits_written ); +move16(); - /* calculate spectral tilt to detect sudden drops (or increases) in energy in the current SFB */ - // slope = IGF_getTilt_fx( pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1], e_ps, &slope_e ); +/* update list of indices */ +hBstr->nb_ind_tot = sub( hBstr->nb_ind_tot, bsBits ); +hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, nb_bits_written ); - x = 1; - mean_x_fx = mean_y_fx = 0; - Word32 mean_y_fx_tmp = 0; - move32(); - mean_xy_fx = mean_x2_fx = 0; - mean_x_e = 15; - mean_xy_e = mean_y_e = mean_x2_e = 31; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); +return; +} - FOR( sb = swb_offset[sfb]; sb < swb_offset[sfb + 1]; sb++ ) - { - mean_x_fx = add( mean_x_fx, x ); /*Q0*/ - mean_x2_fx = L_add( mean_x2_fx, L_mult0( x, x ) ); /*Q0*/ - /*y = 20.f * log10f( max( 1.f, powerSpectrum[i] ) );*/ - IF( LE_64( W_deposit32_l( pPowerSpectrum_fx[sb] ), W_shl( 1, ( sub( 31, e_ps[sb] ) ) ) ) ) - { - y = 0; - move16(); - } - ELSE - { - y = imult1616( 20, extract_l( L_shr( Mult_32_16( ( L_add( BASOP_Util_Log2( pPowerSpectrum_fx[sb] ), L_shl( e_ps[sb], Q25 ) ) ), INV_Log2_10_Q15 ), Q25 ) ) ); /*Q0*/ - } - mean_y_fx_tmp = L_mac0( mean_y_fx_tmp, y, 1 ); /*Q0*/ - mean_xy_fx = L_add( mean_xy_fx, L_mult0( y, x ) ); /*Q0*/ +/**********************************************************************/ /* + IGF write concatenated bitsream for TCX10 modes +**************************************************************************/ - x = add( x, 1 ); - } - mean_y_fx = BASOP_Util_Divide3216_Scale( mean_y_fx_tmp, width, &tmp_e ); /* mean_y_e*/ +/* o: Q0 | total number of bits written */ +Word16 IGFEncWriteConcatenatedBitstream_fx( + const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : instance handle of IGF Encoder */ + BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ +) +{ + IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; + Word16 i; + Word16 tmp; + Word16 bitsLeft; + UWord8 *pBitstream; - mean_y_e = add( mean_y_e, sub( tmp_e, 15 ) ); - mean_x_fx = BASOP_Util_Divide1616_Scale( mean_x_fx, width, &tmp_e ); /* mean_x_e*/ - mean_x_e = add( mean_x_e, sub( tmp_e, 15 ) ); - mean_xy_fx = BASOP_Util_Divide3216_Scale( mean_xy_fx, width, &tmp_e ); /* mean_xy_e*/ - mean_xy_e = add( mean_xy_e, sub( tmp_e, 15 ) ); - mean_x2_fx = BASOP_Util_Divide3216_Scale( mean_x2_fx, width, &tmp_e ); /* mean_x2_e*/ - mean_x2_e = add( mean_x2_e, sub( tmp_e, 15 ) ); + hPrivateData = &hInstance->igfData; + pBitstream = &hPrivateData->igfBitstream[0]; - /*slope = ( mean_xy - mean_x * mean_y ) / ( mean_x2 - mean_x * mean_x );*/ - slope = BASOP_Util_Divide3232_Scale( ( L_sub( mean_xy_fx, L_shl( mult( mean_x_fx, mean_y_fx ), sub( add( mean_x_e, mean_y_e ), mean_xy_e ) ) ) ), ( L_sub( mean_x2_fx, L_shl( mult( mean_x_fx, mean_x_fx ), sub( add( mean_x_e, mean_x_e ), mean_x2_e ) ) ) ), &slope_e ); - slope_e = add( slope_e, sub( mean_xy_e, mean_x2_e ) ); + tmp = shr( hPrivateData->igfBitstreamBits, 3 ); + FOR( i = 0; i < tmp; i++ ) + { + push_next_indice( hBstr, pBitstream[i], 8 ); + } - /* determine whether strong tilt is due to a step in the spectrum (e.g. band limitation, no damping) - or a tonal component close the band border (apply damping) by calculating SFM for a shift of 1/2 SFB width*/ - threshold = BASOP_Util_Divide1616_Scale( 60, width, &threshold_e ); + bitsLeft = s_and( hPrivateData->igfBitstreamBits, 0x7 ); + IF( bitsLeft > 0 ) + { + push_next_indice( hBstr, shr( pBitstream[i], sub( 8, bitsLeft ) ), bitsLeft ); + } - test(); - IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( slope, add( slope_e, 16 ), negate( threshold ), add( threshold_e, 16 ) ), -1 ) ) - { - Word16 shift = shr( width, 1 ); - sfm = IGF_getSFM_new_fx( pPowerSpectrum_fx, hPrivateData->logSpec, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift, e_ps ); - crest = IGF_getCrest_new_fx( hPrivateData->logSpec, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift, &crest_exp ); - shiftedSFM = BASOP_Util_Divide1616_Scale( sfm, crest, &shiftedSFM_e ); - } - ELSE IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( slope, add( slope_e, 16 ), threshold, add( threshold_e, 16 ) ), 1 ) && ( NE_16( sfb, sub( hGrid->sfbWrap[hGrid->nTiles], 1 ) ) ) ) - { - Word16 shift = shr( width, 1 ); - shiftedSFM = BASOP_Util_Divide1616_Scale( IGF_getSFM_new_fx( pPowerSpectrum_fx, hPrivateData->logSpec, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift, e_ps ), IGF_getCrest_new_fx( hPrivateData->logSpec, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift, &crest_exp ), &tmp_e ); - sfm = IGF_getSFM_new_fx( pPowerSpectrum_fx, hPrivateData->logSpec, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift, e_ps ); - crest = IGF_getCrest_new_fx( hPrivateData->logSpec, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift, &crest_exp ); - shiftedSFM = BASOP_Util_Divide1616_Scale( sfm, crest, &shiftedSFM_e ); - } - shiftedSFM_e = add( shiftedSFM_e, sub( sfm_exp, crest_exp ) ); + return hInstance->infoTotalBitsWritten; +} - IF( GT_32( shiftedSFM, L_shl( 1311 /*0.04f Q15*/, negate( shiftedSFM_e ) ) ) ) - { - currDampingFactor = 32767; /*1.f Q15*/ - currDampingFactor_e = 0; - move16(); - move16(); - } - ELSE - { - // alpha = min( 320.f / (float) swb_offset[sfb + 1], 1.25f ); - temp = BASOP_Util_Divide1616_Scale( 320, swb_offset[sfb + 1], &alpha_e ); - alpha = extract_l( L_min( temp, L_shl( 20480 /*1.25 Q14*/, sub( 1, alpha_e ) ) ) ); // alpha_e - // currDampingFactor = expf( 1.25f * alpha * logf( hPrivateData->SFM_tb[sfb] / hPrivateData->SFM_sb[sfb] ) ); - temp = BASOP_Util_Divide1616_Scale( hPrivateData->SFM_tb_fx[sfb], hPrivateData->SFM_sb_fx[sfb], &tmp_e ); // tmp_e - tmp_e = add( tmp_e, sub( hPrivateData->sfb_tb_e[sfb], hPrivateData->sfb_sb_e[sfb] ) ); - Word16 temp1 = mult( 20480 /* 1.25f in Q14 */, alpha ); - Word16 tmp1_e = add( 1, alpha_e ); - currDampingFactor = round_fx( BASOP_util_Pow2( Mpy_32_16_1( L_add( BASOP_Util_Log2( temp ), L_shl_sat( add( 16, tmp_e ), 25 ) ), temp1 ), add( tmp1_e, 6 ), &currDampingFactor_e ) ); // currDampingFactor_e +ivas_error IGF_Reconfig_fx( + IGF_ENC_INSTANCE_HANDLE *hIGFEnc, /* i/o: instance handle of IGF Encoder */ + const Word16 igf, /* i : IGF on/off */ + const Word16 reset, /* i : reset flag */ + const Word32 brate, /* i : bitrate for configuration */ + const Word16 bwidth, /* i : signal bandwidth */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 rf_mode /* i : flag to signal the RF mode */ +) +{ + ivas_error error; - /* calculate tonal-to-noise ratio and reduce damping for low values*/ + error = IVAS_ERR_OK; + move32(); - Word32 tonalToNoise; - Word16 adap; - Word16 adap_e; /*stores exp for adap*/ - Word16 tonalToNoise_e; /*stores exponent for tonalToNoise*/ - tonalToNoise_e = 9; - move16(); - adap = BASOP_Util_Divide1616_Scale( width, 40, &adap_e ); - tonalToNoise = IGF_getTNR_ivas_fx( pPowerSpectrum_fx, swb_offset[sfb], swb_offset[sfb + 1], adap, e_ps, adap_e ); /*Q22*/ + test(); + test(); + test(); + IF( igf && *hIGFEnc == NULL ) + { + IF( ( *hIGFEnc = (IGF_ENC_INSTANCE_HANDLE) malloc( sizeof( IGF_ENC_INSTANCE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n" ) ); + } + IGFEncSetMode_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); + } + ELSE IF( igf && reset ) + { + IGFEncSetMode_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); + } + ELSE IF( !igf && *hIGFEnc != NULL ) + { + free( *hIGFEnc ); + *hIGFEnc = NULL; + } - IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( tonalToNoise, tonalToNoise_e, L_add( L_shl( 10, sub( 15, adap_e ) ), adap ), add( 16, adap_e ) ), -1 ) ) - { - // currDampingFactor += 0.03f * ( ( 10 + adap ) - tonalToNoise ); - Word32 temp2 = BASOP_Util_Add_Mant32Exp( L_add( L_shl( 10, sub( 15, adap_e ) ) /*exp:adap_e*/, adap ), add( adap_e, 16 ), L_negate( tonalToNoise ), tonalToNoise_e, &tmp_e ); // tmp_e - currDampingFactor_e = BASOP_Util_Add_MantExp( currDampingFactor, currDampingFactor_e, extract_l( Mult_32_32( 983 /*0.03f Q15*/, temp2 ) ), tmp_e, &currDampingFactor ); // currDampingFactor_e - } - } + return error; +} - Word32 L_tmp = hPrivateData->prevDampingFactor_IIR_fx[sfb]; - move32(); - L_tmp = L_shl( L_tmp, hPrivateData->prevDampingFactor_IIR_e[sfb] ); - test(); - test(); - IF( last_core_acelp || hPrivateData->wasTransient || EQ_32( L_tmp, MIN16B ) ) - { - tmp = BASOP_Util_Cmp_Mant32Exp( currDampingFactor, currDampingFactor_e, 3277 /* 0.1f in Q15 */, 0 ); - IF( tmp >= 0 ) - { - hPrivateData->prevDampingFactor_IIR_fx[sfb] = currDampingFactor; - hPrivateData->prevDampingFactor_IIR_e[sfb] = currDampingFactor_e; - move16(); - move16(); - } - ELSE - { - hPrivateData->prevDampingFactor_IIR_fx[sfb] = 3277; /* 0.1 in Q15 */ - hPrivateData->prevDampingFactor_IIR_e[sfb] = 0; - move16(); - move16(); - } - } - IF( last_core_acelp ) - { - hPrivateData->dampingFactorSmoothing[sfb] = 2; - move16(); - } - dampingFactor_e = BASOP_Util_Add_MantExp( currDampingFactor, currDampingFactor_e, hPrivateData->prevDampingFactor_IIR_fx[sfb], hPrivateData->prevDampingFactor_IIR_e[sfb], &dampingFactor ); // dampingFactor_e - dampingFactor = shr( dampingFactor, 1 ); +#define INV_Log2_10_Q15 9864 /*1/log2(10) in Q15*/ +#define INV_Log2_10_Q12 1233 /*1/log2(10) in Q12*/ +#define INV_Log2_e_Q15 22713 /*1/log2(e) in Q15*/ - gain = Mult_32_16( gain, shl_sat( extract_l( L_min( L_add( dampingFactor, Mult_32_16( L_shl( hPrivateData->dampingFactorSmoothing[sfb], sub( 15, dampingFactor_e ) ) /*Q:15-dampingFactor_e*/, 3277 /*0.1f Q15*/ ) /*Q:15-dampingFactor_e*/ ), shl_sat( 1, sub( 15, dampingFactor_e ) ) ) ), dampingFactor_e ) /*Q15*/ ); - hPrivateData->prevDampingFactor_IIR_fx[sfb] = dampingFactor; - move16(); - hPrivateData->prevDampingFactor_IIR_e[sfb] = dampingFactor_e; - move16(); - if ( hPrivateData->dampingFactorSmoothing[sfb] > 0 ) - { - hPrivateData->dampingFactorSmoothing[sfb] = sub( hPrivateData->dampingFactorSmoothing[sfb], 1 ); - move16(); - } - } - ELSE - { - hPrivateData->prevDampingFactor_IIR_fx[sfb] = MIN16B; // exponent : hPrivateData->prevDampingFactor_IIR_e[sfb] - hPrivateData->prevDampingFactor_IIR_e[sfb] = 0; - hPrivateData->dampingFactorSmoothing[sfb] = 1; - move16(); - move16(); - move16(); - } +/*-------------------------------------------------------------------* + * IGF_getTNR() + * + * calculates tonal-to-noise ratio + *-------------------------------------------------------------------*/ - hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = tmp_tb; // hPrivateData->prevSFB_FIR_TB_e[sfb] - hPrivateData->prevSFB_FIR_TB_e[sfb] = tmp_tb_e; - hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = hPrivateData->SFM_tb_fx[sfb]; // hPrivateData->prevSFB_IIR_TB_e[sfb] - hPrivateData->prevSFB_IIR_TB_e[sfb] = hPrivateData->sfb_tb_e[sfb]; - hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = tmp_sb; // hPrivateData->prevSFB_FIR_SB_e[sfb] - hPrivateData->prevSFB_FIR_SB_e[sfb] = tmp_sb_e; - hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = hPrivateData->SFM_sb_fx[sfb]; // hPrivateData->prevSFB_IIR_SB_e[sfb] - hPrivateData->prevSFB_IIR_SB_e[sfb] = hPrivateData->sfb_sb_e[sfb]; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - } - ELSE - { - hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = 0; // hPrivateData->prevSFB_FIR_TB_e[sfb] - hPrivateData->prevSFB_FIR_TB_e[sfb] = 0; - hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = 0; // hPrivateData->prevSFB_IIR_TB_e[sfb] - hPrivateData->prevSFB_IIR_TB_e[sfb] = 0; - hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = 0; // hPrivateData->prevSFB_IIR_TB_e[sfb] - hPrivateData->prevSFB_FIR_SB_e[sfb] = 0; - hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = 0; // hPrivateData->prevSFB_IIR_SB_e[sfb] - hPrivateData->prevSFB_IIR_SB_e[sfb] = 0; - hPrivateData->prevDampingFactor_IIR_fx[sfb] = MIN16B; /* hPrivateData->prevDampingFactor_IIR_e[sfb]*/ - hPrivateData->prevDampingFactor_IIR_e[sfb] = 0; - hPrivateData->dampingFactorSmoothing[sfb] = 2; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - } - } - } - ELSE - { - tmp_e = e_mdct; - move16(); - sfbEnergyR = add_sat( EPSILON_FX, BASOP_Util_Divide3216_Scale( sum2_32_fx( pMDCTSpectrum_fx + swb_offset[sfb], width, &tmp_e ) /*exp: tmp_e*/, width, &sfbEnergyR_e ) ); // sfbEnergyR_e - sfbEnergyR_e = add( sfbEnergyR_e, add( tmp_e, -15 ) ); - gain = L_shl( sfbEnergyR, 16 ); // gain_e - move32(); - gain_e = sfbEnergyR_e; +/*! r: spectral tilt value */ +/* Returns value with exponent as 9 and Q as 22*/ + +static Word32 IGF_getTNR_ivas_fx( + const Word32 *powerSpectrum, /* i : energies */ + const Word16 start, /* i : start subband index */ + const Word16 stop, /* i : stop subband index */ + const Word16 adap, /* i : SFB width adaptation */ + Word16 *e_ps, /*Stores exponent for powerSpectrum*/ + Word16 e_adap /*Stores exponent for adap*/ +) +{ + Word16 i; + Word16 width; + Word32 avg; + Word32 tonal; + Word16 tonal_e; /* holds exp for tonal*/ + Word32 noise; + Word16 noise_e; /* holds exp for noise*/ + Word32 tonalToNoise; + Word32 rootSpec[300]; + Word16 rootSpec_e[300]; /*rootSpec_e[i] holds exp for rootSpec[i]*/ + Word16 avg_e; /* holds exp for avg*/ + Word16 tmp_e; + avg = 0; + tonal = 0; + noise = EPSILON_FX; + tonal_e = 0; + noise_e = 0; + avg_e = 0; + tmp_e = 0; + move32(); + move32(); + move32(); + move16(); + move16(); + move16(); + move16(); - IF( element_mode > EVS_MONO ) - { - hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = 0; // hPrivateData->prevSFB_FIR_TB_e[sfb] - hPrivateData->prevSFB_FIR_TB_e[sfb] = 0; - hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = 0; // hPrivateData->prevSFB_IIR_TB_e[sfb] - hPrivateData->prevSFB_IIR_TB_e[sfb] = 0; - hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = 0; // hPrivateData->prevSFB_IIR_TB_e[sfb] - hPrivateData->prevSFB_FIR_SB_e[sfb] = 0; - hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = 0; // hPrivateData->prevSFB_IIR_SB_e[sfb] - hPrivateData->prevSFB_IIR_SB_e[sfb] = 0; - hPrivateData->prevDampingFactor_IIR_fx[sfb] = MIN16B; /* hPrivateData->prevDampingFactor_IIR_e[sfb]*/ - hPrivateData->prevDampingFactor_IIR_e[sfb] = 0; - hPrivateData->dampingFactorSmoothing[sfb] = 2; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - } - } + set32_fx( rootSpec, 0, 300 ); + set16_fx( rootSpec_e, 0, 300 ); - gain = Mult_32_16( gain, att ); // gain_e - gain_e = add( gain_e, 0 ); + width = sub( stop, start ); + FOR( i = start; i < stop; i++ ) + { + rootSpec_e[( i - start )] = e_ps[i]; + move16(); + rootSpec[( i - start )] = Sqrt32( powerSpectrum[i], &rootSpec_e[( i - start )] ); /*rootSpec[i - start] = sqrtf( powerSpectrum[i] );*/ + move32(); + avg = BASOP_Util_Add_Mant32Exp( avg, avg_e, rootSpec[( i - start )], rootSpec_e[( i - start )], &avg_e ); /*avg += rootSpec[i - start];resultant exponent is avg_e*/ + } + avg = BASOP_Util_Divide3216_Scale( avg, width, &tmp_e ); /*avg /= width;*/ + avg_e = add( 16, sub( add( avg_e, tmp_e ), 15 ) ); - /*gain=0.5f+log2f(gain)*2+16 becuase 2.885390081777927f=2*1/loge(2) so 2*1/loge(2)*loge(x) can be written as 2*log2(x)*/ - gain = L_add( ONE_IN_Q22, L_add( L_add( L_shr( BASOP_Util_Log2( gain ), 1 ), L_shl( gain_e, Q24 ) ), L_shl( 16, Q23 ) ) ); /*Q23*/ - test(); - test(); - IF( !isTransient && ( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) ) - { - gain = L_add( gain, ONE_IN_Q21 ); /* better preservation of original HF band energy */ - } - test(); - test(); - IF( !isTransient && ( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_64000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_64000_CPE ) ) ) - { - gain = L_add( gain, ONE_IN_Q20 ); - } - gain = L_min( gain, 91 << Q23 ); /* 13+15+63, see arithcode encode residual */ - gain = L_max( gain, 0 ); - gain_e = 8; /* stores exponent for gain_fx*/ - move16(); - hPrivateData->igfScfQuantized[sfb] = extract_l( L_shr( gain, Q23 ) ); /*Q0*/ - move16(); + FOR( i = start; i < stop; i++ ) + { + Word16 normSpec_e; /*stores resultant exponent for normSpec*/ + Word16 normSpec = BASOP_Util_Divide3232_Scale( rootSpec[i - start], avg, &normSpec_e ); /*rootSpec[i - start] / avg;*/ + normSpec_e = add( normSpec_e, sub( rootSpec_e[i - start], avg_e ) ); + IF( GT_32( normSpec, L_add_sat( L_shl_sat( 1, sub( 15, normSpec_e ) ), L_shl_sat( adap, sub( e_adap, normSpec_e ) ) ) ) ) + { + tonal = BASOP_Util_Add_Mant32Exp( tonal, tonal_e, rootSpec[( i - start )], rootSpec_e[( i - start )], &tonal_e ); /*tonal += rootSpec[i - start];*/ + } + ELSE IF( LT_32( normSpec, L_shl_sat( 1, sub( 15, normSpec_e ) ) ) ) + { + noise = BASOP_Util_Add_Mant32Exp( noise, noise_e, rootSpec[( i - start )], rootSpec_e[( i - start )], &noise_e ); /*noise += rootSpec[i - start];*/ } } - return; + /*tonalToNoise = 20.f * log10f( max( 1e-018f, tonal / noise ) )*/ + IF( noise == 0 ) // To handle condition if denom = 0 + { + tonalToNoise = imult3216( L_shr( L_add( L_shl( 18 /* log10f(1e-018f) */, Q25 ), Mpy_32_16_1( L_add( BASOP_Util_Log2( tonal ), L_shl( tonal_e, Q25 ) ) /*Q25*/, INV_Log2_10_Q15 ) /*25+15-15*/ ), 3 ) /*Q22*/, 20 ); + } + ELSE + { + Word16 temp = BASOP_Util_Divide3232_Scale( tonal, noise, &tmp_e ); /*tonal / noise*/ + tmp_e = add( tmp_e, sub( tonal_e, noise_e ) ); + IF( GE_16( temp, 1 ) ) + { + tonalToNoise = imult3216( Mult_32_16( L_add( BASOP_Util_Log2( temp ), L_shl( add( 16, tmp_e ), Q25 ) ) /*Q25*/, INV_Log2_10_Q12 ) /*25+12-15*/, 20 ); /*Q22*/ + } + ELSE + { + tonalToNoise = -1509949440; /*-360.f Q22*/ + move32(); + } + } + + return tonalToNoise; } /*-------------------------------------------------------------------* - * IGF_CalculateStereoEnvelope_fx() + * IGF_CalculateEnvelope() * * envelope estimation - *-------------------------------------------------------------------*/ -static void IGF_CalculateStereoEnvelope_fx( - const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ - const Word32 *pMDCTSpectrum_fx, /* i : MDCT spectrum */ - Word16 pMDCTSpectrum_e, /* i : exponent for pMDCTSpectrum_fx */ - const Word32 *pMDCTSpectrumMsInv_fx, /* i : MDCT spectrum */ - Word16 pMDCTSpectrumMsInv_e, /* i : expontent for pMDCTSpectrumMsInv_fx */ - const Word32 *pPowerSpectrum_fx, /* i : MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 *pPowerSpectrum_e, /* i : exponent for pPowerSpectrum_fx */ - const Word32 *pPowerSpectrumMsInv_fx, /* i : inverse power spectrum */ - Word16 *q_pPowerSpectrumMsInv, /* i : Q for pPowerSpectrumMsInv_fx */ - const Word16 igfGridIdx, /* i : IGF grid index */ - const Word16 coreMsMask[N_MAX], /* i : line wise ms Mask */ - const Word16 isTransient, /* i : flag indicating if transient is detected */ - const Word16 last_core_acelp, /* i : indicator if last frame was ACELP core */ - const Word16 mct_on ) + +static void IGF_CalculateEnvelope_ivas_fx( + const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ + Word32 *pMDCTSpectrum_fx, /* i : MDCT spectrum */ + Word16 e_mdct, /* i : exp of MDCT spectrum */ + Word32 *pPowerSpectrum_fx, /* i : MDCT^2 + MDST^2 spectrum, or estimate */ + Word16 *e_ps, /* i : exp of power spectrum */ + const Word16 igfGridIdx, /* i : IGF grid index */ + const Word16 isTransient, /* i : flag indicating if transient is detected */ + const Word16 last_core_acelp, /* i : indicator if last frame was ACELP core */ + const Word16 element_mode, /* i : IVAS element_mode */ + const Word16 att /* i : attenuation */ +) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; @@ -3898,90 +2030,68 @@ static void IGF_CalculateStereoEnvelope_fx( Word16 width; /* this is width in subbands of the actual scalefactor band */ Word16 tile_idx; Word16 strt_cpy; - Word32 gain_fx; /* the gain which has to be applied to the source tile to get the destination energy */ + Word32 gain; /* the gain which has to be applied to the source tile to get the destination energy */ Word16 sb; - Word16 sfbEnergyR_fx; - Word32 sfbEnergyC_fx; /* the energy of the destination region of the tile */ - Word32 sfbEnergyTileR_fx; - Word32 sfbEnergyTileC_fx; /* the energy of the destination region of the tile */ + Word32 sfbEnergyR; + Word32 sfbEnergyC; /* the energy of the destination region of the tile */ + Word32 sfbEnergyTileR; + Word32 sfbEnergyTileC; /* the energy of the destination region of the tile */ Word16 tmp, x, y; Word16 mean_x_fx, mean_y_fx; Word32 mean_xy_fx, mean_x2_fx; - Word16 slope_fx; - Word16 tmp_tb_fx; - Word16 tmp_sb_fx; + Word16 tmp_tb; + Word16 tmp_sb; Word16 sfbCnt; - Word32 tileSrcSpec_fx[MAX_IGF_SFB_LEN]; Word16 sfm; Word16 crest; Word16 temp; - Word16 mean_x_e, mean_y_e; /*Stores exponent for mean_x and mean_y respectively*/ - Word16 mean_xy_e, mean_x2_e; /*stores exponent for mean_xy and mean_x2 respectively*/ - Word16 tileSrcSpec_e[MAX_IGF_SFB_LEN]; /*Exponent for tileSrcSpec_fx*/ - Word16 sfbEnergyTileR_e; /*Exponent for sfbEnergyTileR_fx*/ - Word16 sfbEnergyTileC_e; /*Exponent for sfbEnergyTileC_fx*/ - Word16 sfbEnergyC_e; /*Exponent for sfbEnergyC_fx*/ - Word16 gain_e; /*exponent for gain_fx*/ - Word16 crest_exp; /*stores exponent for output from crest*/ - Word16 sfm_exp; /*stores exponent for ouput from sfm*/ - Word16 tmp_tb_e; /*Stores exponent for tmp_tb_fx*/ - Word16 tmp_sb_e; /*stores exponent for tmp_sb_fx*/ - Word16 slope_e; /*stores exponent for slope_fx*/ - Word16 sfbEnergyR_e; /*stores exponent for sfbEnergyR*/ + Word16 mean_x_e, mean_y_e; /*Stores exponent for mean_x and mean_y respectively*/ + Word16 mean_xy_e, mean_x2_e; /*stores exponent for mean_xy and mean_x2 respectively*/ + Word16 sfbEnergyTileR_e; /*Exponent for sfbEnergyTileR*/ + Word16 sfbEnergyTileC_e; /*Exponent for sfbEnergyTileC*/ + Word16 sfbEnergyC_e; /*Exponent for sfbEnergyC*/ + Word16 sfbEnergyR_e; + Word16 gain_e; /*exponent for gain*/ + Word16 tmp_tb_e; /*Stores exponent for tmp_tb*/ + Word16 tmp_sb_e; /*stores exponent for tmp_sb*/ + Word16 crest_exp; /*Stores the exponent of the result(return value)*/ + Word16 sfm_exp; /*stores exponent for ouput from sfm*/ Word16 tmp_e; - Word32 temp_pPowerSpectrumMsInv[N_MAX], length; - Word16 q_temp_pPowerSpectrumMsInv = Q31, i; - move16(); - - IF( pPowerSpectrumMsInv_fx != NULL ) - { - length = N_MAX; - move16(); - if ( mct_on ) - { - length = L_FRAME48k; - move16(); - } - FOR( i = 0; i < length; i++ ) - { - IF( pPowerSpectrumMsInv_fx[i] != 0 ) - { - q_temp_pPowerSpectrumMsInv = s_min( q_temp_pPowerSpectrumMsInv, add( q_pPowerSpectrumMsInv[i], norm_l( pPowerSpectrumMsInv_fx[i] ) ) ); - } - } - FOR( i = 0; i < length; i++ ) - { - temp_pPowerSpectrumMsInv[i] = L_shl( pPowerSpectrumMsInv_fx[i], sub( q_temp_pPowerSpectrumMsInv, q_pPowerSpectrumMsInv[i] ) ); - move32(); - } - } hPrivateData = &hIGFEnc->igfData; hGrid = &hPrivateData->igfInfo.grid[(Word16) igfGridIdx]; swb_offset = hGrid->swb_offset; - move16(); - IF( igfGridIdx != IGF_GRID_LB_NORM ) + IF( element_mode > EVS_MONO ) { - FOR( sfbCnt = 0; sfbCnt < sub( hGrid->sfbWrap[hGrid->nTiles], hGrid->sfbWrap[0] ); sfbCnt++ ) + IF( igfGridIdx != IGF_GRID_LB_NORM ) { - /* reset filter */ - hPrivateData->prevSFM_FIR_SFB_TB_fx[sfbCnt] = 0; // exponent : hPrivateData->prevSFB_FIR_TB_e[sfbCnt] - hPrivateData->prevSFM_IIR_SFB_TB_fx[sfbCnt] = 0; // exponent : hPrivateData->prevSFB_IIR_TB_e[sfbCnt] - hPrivateData->prevSFM_FIR_SFB_SB_fx[sfbCnt] = 0; // exponent : hPrivateData->prevSFB_FIR_SB_e[sfbCnt] - hPrivateData->prevSFM_IIR_SFB_SB_fx[sfbCnt] = 0; // exponent : hPrivateData->prevSFB_IIR_SB_e[sfbCnt] - hPrivateData->prevSFB_FIR_TB_e[sfbCnt] = 0; - hPrivateData->prevSFB_IIR_TB_e[sfbCnt] = 0; - hPrivateData->prevSFB_FIR_SB_e[sfbCnt] = 0; - hPrivateData->prevSFB_IIR_SB_e[sfbCnt] = 0; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); + FOR( sfbCnt = 0; sfbCnt < sub( hGrid->sfbWrap[hGrid->nTiles], hGrid->sfbWrap[0] ); sfbCnt++ ) + { + /* reset filter */ + hPrivateData->prevSFM_FIR_SFB_TB_fx[sfbCnt] = 0; // exponent : hPrivateData->prevSFB_FIR_TB_e[sfbCnt] + hPrivateData->prevSFB_FIR_TB_e[sfbCnt] = 0; + hPrivateData->prevSFM_IIR_SFB_TB_fx[sfbCnt] = 0; // exponent : hPrivateData->prevSFB_IIR_TB_e[sfbCnt] + hPrivateData->prevSFB_IIR_TB_e[sfbCnt] = 0; + hPrivateData->prevSFM_FIR_SFB_SB_fx[sfbCnt] = 0; // exponent : hPrivateData->prevSFB_FIR_SB_e[sfbCnt] + hPrivateData->prevSFB_FIR_SB_e[sfbCnt] = 0; + hPrivateData->prevSFM_IIR_SFB_SB_fx[sfbCnt] = 0; // exponent : hPrivateData->prevSFB_IIR_SB_e[sfbCnt] + hPrivateData->prevSFB_IIR_SB_e[sfbCnt] = 0; + hPrivateData->prevDampingFactor_IIR_fx[sfbCnt] = MIN16B; /* -1.f in Q15*/ + hPrivateData->prevDampingFactor_IIR_e[sfbCnt] = 0; + hPrivateData->dampingFactorSmoothing[sfbCnt] = 2; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + } } } @@ -3989,16 +2099,16 @@ static void IGF_CalculateStereoEnvelope_fx( { FOR( sb = hGrid->sbWrap[0]; sb < swb_offset[hGrid->sfbWrap[hGrid->nTiles]]; sb++ ) { - /*hPrivateData->logSpec[sb] = max( 0, (Word16) ( logf( max( FLT_MIN, pPowerSpectrum[sb] ) ) * INV_LOG_2 ) );*/ - IF( LE_32( 1, pPowerSpectrum_fx[sb] ) ) + IF( LT_32( 1, pPowerSpectrum_fx[sb] ) ) { - hPrivateData->logSpec[sb] = s_max( 0, (Word16) L_shr( L_add( BASOP_Util_Log2( pPowerSpectrum_fx[sb] ), L_shl( pPowerSpectrum_e[sb], Q25 ) ), 25 ) ); + hPrivateData->logSpec[sb] = s_max( 0, extract_l( W_extract_l( W_shr( W_add( BASOP_Util_Log2( pPowerSpectrum_fx[sb] ), W_shl( e_ps[sb], Q25 ) ), Q25 ) ) ) ); + move16(); } ELSE { - hPrivateData->logSpec[sb] = 0; /*max(0,-126) is always 0*/ + hPrivateData->logSpec[sb] = 0; + move16(); } - move16(); } } @@ -4010,401 +2120,409 @@ static void IGF_CalculateStereoEnvelope_fx( FOR( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ ) { width = sub( swb_offset[sfb + 1], swb_offset[sfb] ); - sfbEnergyTileR_fx = EPSILON_FX; - sfbEnergyTileC_fx = EPSILON_FX; - sfbEnergyC_fx = EPSILON_FX; + sfbEnergyTileR = EPSILON_FIX; + sfbEnergyTileC = EPSILON_FIX; + sfbEnergyC = EPSILON_FX; sfbEnergyTileR_e = 0; sfbEnergyTileC_e = 0; sfbEnergyC_e = 0; move16(); move16(); move16(); - move32(); - move32(); - move32(); - IF( pPowerSpectrum_fx ) + move16(); + move16(); + move16(); + + IF( pPowerSpectrum_fx != NULL ) { - Word16 final_exp; - Word16 norm_exp; - Word32 scaled_value; tmp = strt_cpy; move16(); - FOR( sb = swb_offset[sfb]; sb < swb_offset[sfb + 1]; sb++ ) { - IF( NE_16( coreMsMask[sb], coreMsMask[strt_cpy] ) ) - { - sfbEnergyC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyC_fx, sfbEnergyC_e, pPowerSpectrum_fx[sb], pPowerSpectrum_e[sb], &sfbEnergyC_e ); /*resultant exponent is stored in sfbEnergyC_e*/ - norm_exp = norm_l( pMDCTSpectrumMsInv_fx[strt_cpy] ); - final_exp = sub( pMDCTSpectrumMsInv_e, norm_exp ); - scaled_value = L_shl( pMDCTSpectrumMsInv_fx[strt_cpy], norm_exp ); - sfbEnergyTileR_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileR_fx, sfbEnergyTileR_e, Mult_32_32( scaled_value, scaled_value ), shl( final_exp, 1 ), &sfbEnergyTileR_e ); /*resultant exponent is stored in sfbEnergyTileR_e*/ - sfbEnergyTileC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileC_fx, sfbEnergyTileC_e, pPowerSpectrumMsInv_fx[strt_cpy], sub( 31, q_pPowerSpectrumMsInv[strt_cpy] ), &sfbEnergyTileC_e ); /*resultant exponent is stored in sfbEnergyTileC_e*/ - tileSrcSpec_fx[strt_cpy - tmp] = temp_pPowerSpectrumMsInv[strt_cpy]; /*resultant exponent is stored in tileSrcSpec_e*/ - tileSrcSpec_e[strt_cpy - tmp] = sub( 31, q_temp_pPowerSpectrumMsInv ); - } - ELSE - { - sfbEnergyC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyC_fx, sfbEnergyC_e, pPowerSpectrum_fx[sb], pPowerSpectrum_e[sb], &sfbEnergyC_e ); /*resultant exponent is stored in sfbEnergyC_e*/ - norm_exp = norm_l( pMDCTSpectrum_fx[strt_cpy] ); - final_exp = sub( pMDCTSpectrum_e, norm_exp ); - scaled_value = L_shl( pMDCTSpectrum_fx[strt_cpy], norm_exp ); - sfbEnergyTileR_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileR_fx, sfbEnergyTileR_e, Mult_32_32( scaled_value, scaled_value ), shl( final_exp, 1 ), &sfbEnergyTileR_e ); /*resultant exponent is stored in sfbEnergyTileR_e*/ - sfbEnergyTileC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileC_fx, sfbEnergyTileC_e, pPowerSpectrum_fx[strt_cpy], pPowerSpectrum_e[strt_cpy], &sfbEnergyTileC_e ); /*resultant exponent is stored in sfbEnergyTileC_e*/ - tileSrcSpec_fx[strt_cpy - tmp] = pPowerSpectrum_fx[strt_cpy]; /*resultant exponent is stored in tileSrcSpec_e*/ - tileSrcSpec_e[strt_cpy - tmp] = pPowerSpectrum_e[strt_cpy]; - } - move32(); - move16(); + Word16 shift = norm_l( pPowerSpectrum_fx[sb] ); + sfbEnergyC = BASOP_Util_Add_Mant32Exp( sfbEnergyC, sfbEnergyC_e, L_shl( pPowerSpectrum_fx[sb], shift ), sub( e_ps[sb], shift ), &sfbEnergyC_e ); + // sfbEnergyTileR = BASOP_Util_Add_Mant32Exp( sfbEnergyTileR, sfbEnergyTileR_e, Mult_32_32( pMDCTSpectrum_fx[strt_cpy], pMDCTSpectrum_fx[strt_cpy] ), shl( e_mdct, 1 ), &sfbEnergyTileR_e ); + Word64 tmp64 = W_mult_32_32( pMDCTSpectrum_fx[strt_cpy], pMDCTSpectrum_fx[strt_cpy] ); + Word16 tmp64_e = W_norm( tmp64 ); + tmp64 = W_shl( tmp64, tmp64_e ); + + sfbEnergyTileR = BASOP_Util_Add_Mant32Exp( sfbEnergyTileR, sfbEnergyTileR_e, W_extract_h( tmp64 ), shl( e_mdct, 1 ) - tmp64_e, &sfbEnergyTileR_e ); + shift = norm_l( pPowerSpectrum_fx[strt_cpy] ); + sfbEnergyTileC = BASOP_Util_Add_Mant32Exp( sfbEnergyTileC, sfbEnergyTileC_e, L_shl( pPowerSpectrum_fx[strt_cpy], shift ), sub( e_ps[strt_cpy], shift ), &sfbEnergyTileC_e ); + strt_cpy = add( strt_cpy, 1 ); } - sfbEnergyTileR_fx = BASOP_Util_Divide3216_Scale( sfbEnergyTileR_fx, width, &tmp_e ); - sfbEnergyTileR_e = sub( add( sfbEnergyTileR_e, tmp_e ), 15 ); /*stores the resultant exponent for sfbEnergyTileR_fx*/ - - /*gain = (float) ( sfbEnergyTileR * ( sfbEnergyC / sfbEnergyTileC ) );*/ - temp = BASOP_Util_Divide3232_Scale( sfbEnergyC_fx, L_add( sfbEnergyTileC_fx, EPSILON_FX ), &tmp_e ); - gain_e = add( tmp_e, sub( sfbEnergyC_e, sfbEnergyTileC_e ) ); - gain_fx = Mult_32_16( sfbEnergyTileR_fx, temp ); - gain_e = add( 16, add( gain_e, sfbEnergyTileR_e ) ); /*stores the resultant exponent for gain_fx*/ + sfbEnergyTileR = L_deposit_h( BASOP_Util_Divide3232_Scale( sfbEnergyTileR, width, &tmp_e ) ); + sfbEnergyTileR_e = add( sub( sfbEnergyTileR_e, Q31 ), tmp_e ); - IF( !isTransient ) + IF( sfbEnergyTileR == 0 ) { - Word16 diffSFM_fx; - Word16 shiftedSFM_fx; - Word16 shiftedSFM_e; /*stores the resultant exponent for shiftedSFM_fx*/ - shiftedSFM_fx = 0; - shiftedSFM_e = 0; + sfbEnergyTileR = EPSILON_FX; + sfbEnergyTileR_e = 0; + move32(); + move16(); + } + IF( sfbEnergyC == 0 ) + { + sfbEnergyC = EPSILON_FX; + sfbEnergyC_e = 0; + move32(); move16(); + } + IF( sfbEnergyTileC == 0 ) + { + sfbEnergyTileC = EPSILON_FX; + sfbEnergyTileC_e = 0; + temp = BASOP_Util_Divide3232_Scale( sfbEnergyC, sfbEnergyTileC, &tmp_e ); + tmp_e = add( tmp_e, sub( sfbEnergyC_e, sfbEnergyTileC_e ) ); + move32(); move16(); + } + ELSE + { + /*gain = (float) ( sfbEnergyTileR * ( sfbEnergyC / sfbEnergyTileC ) );*/ + temp = BASOP_Util_Divide3232_Scale( sfbEnergyC, sfbEnergyTileC, &tmp_e ); + tmp_e = add( tmp_e, sub( sfbEnergyC_e, sfbEnergyTileC_e ) ); + } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - // tmp_tb = IGF_getSFM(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]) / IGF_getCrest(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]); - sfm = IGF_getSFM( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1], IVAS_CPE_MDCT ); -#else - // tmp_tb = IGF_getSFM_ivas(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]) / IGF_getCrest_ivas(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]); - sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1] ); -#endif -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1], IVAS_CPE_MDCT ); -#else - crest = IGF_getCrest_ivas( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1] ); -#endif - tmp_tb_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &tmp_e ); - tmp_tb_e = add( tmp_e, sub( sfm_exp, crest_exp ) ); /*stores the resultant exponent for tmp_tb_fx*/ - -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - // tmp_sb = IGF_getSFM(tileSrcSpec, 0, strt_cpy - tmp) / IGF_getCrest(tileSrcSpec, 0, strt_cpy - tmp); - sfm = IGF_getSFM( &sfm_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ), IVAS_CPE_MDCT ); -#else - // tmp_sb = IGF_getSFM_ivas(tileSrcSpec, 0, strt_cpy - tmp) / IGF_getCrest_ivas(tileSrcSpec, 0, strt_cpy - tmp); - sfm = IGF_getSFM_ivas_fx( &sfm_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ) ); -#endif -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - crest = IGF_getCrest( &crest_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ), IVAS_CPE_MDCT ); -#else - crest = IGF_getCrest_ivas( &crest_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ) ); -#endif - tmp_sb_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &tmp_e ); - tmp_sb_e = add( tmp_e, sub( sfm_exp, crest_exp ) ); /*stores the resultant exponent for tmp_sb_fx*/ + gain = Mult_32_16( sfbEnergyTileR, temp ); // gain_e + gain_e = add( tmp_e, sfbEnergyTileR_e ); - IF( last_core_acelp || hPrivateData->wasTransient ) + IF( element_mode > EVS_MONO ) + { + test(); + IF( !isTransient ) { - hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = tmp_tb_fx; /*Exponent for hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] and hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] values stored in hPrivateData->sfb_tb_e[sfb] */ - hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = tmp_sb_fx; /*Exponent for hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] and hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] values stored in hPrivateData->sfb_sb_e[sfb]*/ - hPrivateData->prevSFB_FIR_TB_e[sfb] = tmp_sb_e; - hPrivateData->prevSFB_IIR_TB_e[sfb] = tmp_sb_e; - hPrivateData->prevSFB_FIR_SB_e[sfb] = tmp_sb_e; - hPrivateData->prevSFB_IIR_SB_e[sfb] = tmp_sb_e; - move16(); - move16(); - move16(); - move16(); - move16(); + Word16 diffSFM; + Word16 shiftedSFM = 0; + Word16 shiftedSFM_e = 0; move16(); move16(); + + // tmp_tb = IGF_getSFM_new( pPowerSpectrum, hPrivateData->logSpec, swb_offset[sfb], swb_offset[sfb + 1] ) / IGF_getCrest_new( hPrivateData->logSpec, swb_offset[sfb], swb_offset[sfb + 1] ); + sfm = IGF_getSFM_new_fx( pPowerSpectrum_fx, hPrivateData->logSpec, swb_offset[sfb], swb_offset[sfb + 1], e_ps ); + sfm_exp = 0; move16(); - } - ELSE - { - /* Purpose of this block: - -to make the exponent of hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] and hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] equal to that of tmp_tb_fx - -to make the exponent of hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] and hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] equal to that of tmp_sb_fx - */ - Word16 diff_sb_e; /*stores the difference of exponents for sb*/ - Word16 diff_tb_e; /*stores the difference of exponents for tb*/ - diff_sb_e = sub( tmp_sb_e, hPrivateData->sfb_sb_e[sfb] ); - diff_tb_e = sub( tmp_tb_e, hPrivateData->sfb_tb_e[sfb] ); - IF( LE_16( tmp_tb_e, hPrivateData->sfb_tb_e[sfb] ) ) - { - tmp_tb_fx = shl( tmp_tb_fx, diff_tb_e ); - tmp_tb_e = hPrivateData->sfb_tb_e[sfb]; - move16(); - } - ELSE + crest = IGF_getCrest_new_fx( hPrivateData->logSpec, swb_offset[sfb], swb_offset[sfb + 1], &crest_exp ); + tmp_tb = BASOP_Util_Divide1616_Scale( sfm, crest, &tmp_e ); // tmp_tb_e + tmp_tb_e = add( tmp_e, sub( sfm_exp, crest_exp ) ); + + // tmp_sb = IGF_getSFM_new( pPowerSpectrum, hPrivateData->logSpec, tmp, strt_cpy ) / IGF_getCrest_new( hPrivateData->logSpec, tmp, strt_cpy ); + sfm = IGF_getSFM_new_fx( pPowerSpectrum_fx, hPrivateData->logSpec, tmp, strt_cpy, e_ps ); + crest = IGF_getCrest_new_fx( hPrivateData->logSpec, tmp, strt_cpy, &crest_exp ); + tmp_sb = BASOP_Util_Divide1616_Scale( sfm, crest, &tmp_e ); // tmp_sb_e + tmp_sb_e = add( tmp_e, sub( sfm_exp, crest_exp ) ); + + test(); + IF( last_core_acelp || hPrivateData->wasTransient ) { - hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = shr( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], diff_tb_e ); - hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = shr( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], diff_tb_e ); - move16(); + hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = tmp_tb; /*Exponent for hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] : hPrivateData->prevSFB_FIR_TB_e[sfb] and hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] : hPrivateData->prevSFB_IIR_TB_e[sfb] */ + hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = tmp_sb; /*Exponent for hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] : hPrivateData->prevSFB_FIR_SB_e[sfb] and hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] : hPrivateData->prevSFB_IIR_SB_e[sfb] */ + hPrivateData->prevSFB_FIR_TB_e[sfb] = hPrivateData->prevSFB_IIR_TB_e[sfb] = tmp_tb_e; + hPrivateData->prevSFB_FIR_SB_e[sfb] = hPrivateData->prevSFB_IIR_SB_e[sfb] = tmp_sb_e; move16(); - hPrivateData->prevSFB_FIR_TB_e[sfb] = tmp_tb_e; - hPrivateData->prevSFB_IIR_TB_e[sfb] = tmp_tb_e; move16(); move16(); - } - IF( LE_16( tmp_sb_e, hPrivateData->sfb_sb_e[sfb] ) ) - { - tmp_sb_fx = shl( tmp_sb_fx, diff_sb_e ); - tmp_sb_e = hPrivateData->sfb_sb_e[sfb]; move16(); - } - ELSE - { - hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = shr( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], diff_sb_e ); - hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = shr( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], diff_sb_e ); move16(); move16(); - hPrivateData->prevSFB_FIR_SB_e[sfb] = tmp_sb_e; - hPrivateData->prevSFB_IIR_SB_e[sfb] = tmp_sb_e; move16(); move16(); } - } - tmp_tb_fx = shr_sat( tmp_tb_fx, sub( 2, tmp_tb_e ) ); /* Since we're limiting max value to 2.7f we can saturate to Q13 */ - tmp_sb_fx = shr_sat( tmp_sb_fx, sub( 2, tmp_sb_e ) ); /* Since we're limiting max value to 2.7f we can saturate to Q13 */ - hPrivateData->SFM_tb_fx[sfb] = add_sat( tmp_tb_fx, add_sat( shr( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], sub( 2, hPrivateData->prevSFB_FIR_TB_e[sfb] ) ), shr( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], sub( 3, hPrivateData->prevSFB_IIR_TB_e[sfb] ) ) ) ); /* Since we're limiting max value to 2.7f we can saturate to Q13 */ - hPrivateData->SFM_tb_fx[sfb] = s_min( 22118 /*2.7f Q13*/, hPrivateData->SFM_tb_fx[sfb] ); /* resultant exponent stored in hPrivateData->sfb_sb_e[sfb]*/ - hPrivateData->SFM_sb_fx[sfb] = add_sat( tmp_sb_fx, add_sat( shr( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], sub( 2, hPrivateData->prevSFB_FIR_SB_e[sfb] ) ), shr( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], sub( 3, hPrivateData->prevSFB_IIR_SB_e[sfb] ) ) ) ); /* Since we're limiting max value to 2.7f we can saturate to Q13 */ - hPrivateData->SFM_sb_fx[sfb] = s_min( 22118 /*2.7f Q13*/, hPrivateData->SFM_sb_fx[sfb] ); /*resultant exponent stores in hPrivateData->sfb_tb_e[sfb]*/ - move16(); - move16(); - move16(); - move16(); - hPrivateData->sfb_sb_e[sfb] = 2; - hPrivateData->sfb_tb_e[sfb] = 2; - move16(); - move16(); - diffSFM_fx = sub( hPrivateData->SFM_sb_fx[sfb], hPrivateData->SFM_tb_fx[sfb] ); /*Q13*/ + tmp_tb = shr( tmp_tb, 2 ); /*taking 2 guard bits so it's exponent tmp_sb_e=+2*/ + tmp_sb = shr( tmp_sb, 2 ); /*taking 2 guard bits so it's exponent tmp_tb_e=+2 */ + tmp_sb_e = add( tmp_sb_e, 2 ); + tmp_tb_e = add( tmp_tb_e, 2 ); - test(); - IF( diffSFM_fx > 0 && LT_16( hPrivateData->SFM_tb_fx[sfb], 819 /*0.1 Q13*/ ) ) /* check whether target SFB is more tonal than source SFB */ - { - Word16 currDampingFactor_fx, dampingFactor_fx, alpha_fx; - Word16 threshold_e, threshold_fx, alpha_e, currDampingFactor_e, dampingFactor_e; - /* calculate spectral tilt to detect sudden drops (or increases) in energy in the current SFB */ - x = 1; - mean_x_fx = mean_y_fx = 0; - mean_xy_fx = mean_x2_fx = 0; - mean_x_e = mean_y_e = 15; - mean_xy_e = mean_x2_e = 31; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); + Word16 tmp0, tmp2, tmp3, tmp4; + Word16 tmp0_e, tmp2_e, tmp3_e, tmp4_e; + tmp0 = shr( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], 2 ); + tmp0_e = add( hPrivateData->prevSFB_FIR_TB_e[sfb], 2 ); move16(); - FOR( sb = swb_offset[sfb]; sb < swb_offset[sfb + 1]; sb++ ) - { - mean_x_fx = add( mean_x_fx, x ); /*Q0*/ - mean_x2_fx = L_add( mean_x2_fx, L_mult0( x, x ) ); /*Q0*/ - - /*y = 20 * (Word16) log10f( max( 1e-018f, pPowerSpectrum[sb] ) );*/ - IF( LT_32( pPowerSpectrum_fx[sb], 1 ) ) - { - y = 20 * ( -18 ); - move16(); - } - ELSE - { - y = imult1616( 20, extract_l( L_shr( Mult_32_16( ( L_add( BASOP_Util_Log2( pPowerSpectrum_fx[sb] ), L_shl( pPowerSpectrum_e[sb], Q25 ) ) ), INV_Log2_10_Q15 ), 25 ) ) ); /*Q0*/ - } - mean_y_fx = add( mean_y_fx, y ); /*Q0*/ - mean_xy_fx = L_add( mean_xy_fx, L_mult0( y, x ) ); /*Q0*/ - - x = add( x, 1 ); - } - mean_y_fx = BASOP_Util_Divide1616_Scale( mean_y_fx, width, &tmp_e ); /* resultant exp stores in mean_y_e*/ - mean_y_e = add( mean_y_e, sub( tmp_e, 15 ) ); - mean_x_fx = BASOP_Util_Divide1616_Scale( mean_x_fx, width, &tmp_e ); /* resultant exp stores in mean_x_e*/ - mean_x_e = add( mean_x_e, sub( tmp_e, 15 ) ); - mean_xy_fx = BASOP_Util_Divide3216_Scale( mean_xy_fx, width, &tmp_e ); /* resultant exp stores in mean_xy_e*/ - mean_xy_e = add( mean_xy_e, sub( tmp_e, 15 ) ); - mean_x2_fx = BASOP_Util_Divide3216_Scale( mean_x2_fx, width, &tmp_e ); /* resultant exp stores in mean_x2_e*/ - mean_x2_e = add( mean_x2_e, sub( tmp_e, 15 ) ); + tmp2 = shr( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], 2 ); + tmp2_e = add( hPrivateData->prevSFB_IIR_TB_e[sfb], 2 ); + move16(); + tmp3 = shr( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], 2 ); + tmp3_e = add( hPrivateData->prevSFB_FIR_SB_e[sfb], 2 ); + move16(); + tmp4 = shr( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], 2 ); + tmp4_e = add( hPrivateData->prevSFB_IIR_SB_e[sfb], 2 ); + move16(); + Word16 x1, x2; - /*slope = ( mean_xy - mean_x * mean_y ) / ( mean_x2 - mean_x * mean_x );*/ - slope_fx = BASOP_Util_Divide3232_Scale( ( L_sub( mean_xy_fx, L_shl( mult( mean_x_fx, mean_y_fx ), sub( add( mean_x_e, mean_y_e ), mean_xy_e ) ) ) ), ( L_sub( mean_x2_fx, L_shl( mult( mean_x_fx, mean_x_fx ), sub( add( mean_x_e, mean_x_e ), mean_x2_e ) ) ) ), &slope_e ); - slope_e = add( slope_e, sub( mean_xy_e, mean_x2_e ) ); /*stores resultant exponent for slope_fx*/ + Word16 x1_e = BASOP_Util_Add_MantExp( tmp0, tmp0_e, tmp2, tmp2_e - 1, &x1 ); + Word16 x2_e = BASOP_Util_Add_MantExp( tmp3, tmp3_e, tmp4, tmp4_e - 1, &x2 ); + hPrivateData->sfb_tb_e[sfb] = BASOP_Util_Add_MantExp( tmp_tb, tmp_tb_e, x1, x1_e, &hPrivateData->SFM_tb_fx[sfb] ); // hPrivateData->sfb_sb_e[sfb] + move16(); + BASOP_Util_Add_MantExp( 22118, 2, negate( hPrivateData->SFM_tb_fx[sfb] ), hPrivateData->sfb_tb_e[sfb], &tmp ); - /* determine whether strong tilt is due to a step in the spectrum (e.g. band limitation, no damping) - or a tonal component close the band border (apply damping) by calculating SFM for a shift of 1/2 SFB width*/ - threshold_fx = BASOP_Util_Divide1616_Scale( 60, width, &threshold_e ); /*stores resultant exponent for threshold_fx*/ - test(); - IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( slope_fx, add( slope_e, 16 ), negate( threshold_fx ), add( threshold_e, 16 ) ), -1 ) ) - { - Word16 shift = shr( width, 1 ); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - // shiftedSFM = IGF_getSFM( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ) / IGF_getCrest( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ); - sfm = IGF_getSFM( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ), IVAS_CPE_MDCT ); -#else - // shiftedSFM = IGF_getSFM_ivas( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ) / IGF_getCrest_ivas( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ); - sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ) ); -#endif -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ), IVAS_CPE_MDCT ); -#else - crest = IGF_getCrest_ivas( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ) ); -#endif - shiftedSFM_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &shiftedSFM_e ); - } - ELSE IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( slope_fx, add( slope_e, 16 ), threshold_fx, add( threshold_e, 16 ) ), 1 ) && ( NE_16( sfb, sub( hGrid->sfbWrap[hGrid->nTiles], 1 ) ) ) ) - { - Word16 shift; - shift = shr( width, 1 ); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - // shiftedSFM = IGF_getSFM( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ) / IGF_getCrest( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ); - sfm = IGF_getSFM( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ), IVAS_CPE_MDCT ); -#else - // shiftedSFM = IGF_getSFM_ivas( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ) / IGF_getCrest_ivas( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ); - sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ) ); -#endif -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ), IVAS_CPE_MDCT ); -#else - crest = IGF_getCrest_ivas( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ) ); -#endif - shiftedSFM_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &shiftedSFM_e ); - } - IF( shiftedSFM_fx ) + IF( tmp < 0 ) { - shiftedSFM_e = add( shiftedSFM_e, sub( sfm_exp, crest_exp ) ); /* stores resultant exponent for shiftedSFM_fx*/ + hPrivateData->sfb_tb_e[sfb] = 2; + hPrivateData->SFM_tb_fx[sfb] = 22118; + move16(); + move16(); } - // alpha = min( 320.f / (float) swb_offset[sfb + 1], 1.25f ); - temp = BASOP_Util_Divide1616_Scale( 320, swb_offset[sfb + 1], &alpha_e ); - alpha_fx = extract_l( L_min( temp, L_shl( 20480 /*1.25 Q14*/, sub( 1, alpha_e ) ) ) ); /* exponent is alpha_e*/ - temp = BASOP_Util_Divide1616_Scale( hPrivateData->SFM_tb_fx[sfb], hPrivateData->SFM_sb_fx[sfb], &tmp_e ); - tmp_e = add( tmp_e, sub( hPrivateData->sfb_tb_e[sfb], hPrivateData->sfb_sb_e[sfb] ) ); /* stores resultant exponent for temp */ - - // currDampingFactor = expf( alpha * logf( hPrivateData->SFM_tb[sfb] / hPrivateData->SFM_sb[sfb] ) ); - currDampingFactor_fx = round_fx( BASOP_util_Pow2( Mpy_32_16_1( L_add( BASOP_Util_Log2( temp ), L_shl( add( 16, tmp_e ), 25 ) ), alpha_fx ), add( alpha_e, 6 ), &currDampingFactor_e ) ); /*exp is currDampingFactor_e*/ + hPrivateData->sfb_sb_e[sfb] = BASOP_Util_Add_MantExp( tmp_sb, tmp_sb_e, x2, x2_e, &hPrivateData->SFM_sb_fx[sfb] ); // hPrivateData->sfb_tb_e[sfb] + move16(); + BASOP_Util_Add_MantExp( 22118, 2, negate( hPrivateData->SFM_sb_fx[sfb] ), hPrivateData->sfb_sb_e[sfb], &tmp ); - IF( GT_32( shiftedSFM_fx, L_shl( 1311 /*0.04f Q15*/, negate( shiftedSFM_e ) ) ) ) + IF( tmp < 0 ) { - currDampingFactor_fx = 32767; /*1.f Q15*/ - currDampingFactor_e = 0; + hPrivateData->sfb_sb_e[sfb] = 2; + hPrivateData->SFM_sb_fx[sfb] = 22118; move16(); move16(); } + + BASOP_Util_Add_MantExp( hPrivateData->SFM_sb_fx[sfb], hPrivateData->sfb_sb_e[sfb], negate( hPrivateData->SFM_tb_fx[sfb] ), hPrivateData->sfb_tb_e[sfb], &diffSFM ); + test(); - test(); - IF( last_core_acelp || hPrivateData->wasTransient || EQ_32( hPrivateData->prevDampingFactor_IIR_fx[sfb], L_shl( -1, sub( 15, hPrivateData->prevDampingFactor_IIR_e[sfb] ) ) ) ) + IF( diffSFM > 0 && LT_32( hPrivateData->SFM_tb_fx[sfb], L_shr( 3277 /*0.1 Q15*/, hPrivateData->sfb_tb_e[sfb] ) ) ) /* check whether target SFB is more tonal than source SFB */ { - tmp = BASOP_Util_Cmp_Mant32Exp( currDampingFactor_fx, currDampingFactor_e, 3277, 0 ); - IF( tmp >= 0 ) + Word16 currDampingFactor, dampingFactor; + Word16 slope, threshold; + Word16 alpha; + Word16 slope_e, threshold_e, currDampingFactor_e, dampingFactor_e, alpha_e; + + /* calculate spectral tilt to detect sudden drops (or increases) in energy in the current SFB */ + // slope = IGF_getTilt_fx( pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1], e_ps, &slope_e ); + + x = 1; + mean_x_fx = mean_y_fx = 0; + Word32 mean_y_fx_tmp = 0; + move32(); + mean_xy_fx = mean_x2_fx = 0; + mean_x_e = 15; + mean_xy_e = mean_y_e = mean_x2_e = 31; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + + FOR( sb = swb_offset[sfb]; sb < swb_offset[sfb + 1]; sb++ ) { - hPrivateData->prevDampingFactor_IIR_fx[sfb] = currDampingFactor_fx; - hPrivateData->prevDampingFactor_IIR_e[sfb] = currDampingFactor_e; + mean_x_fx = add( mean_x_fx, x ); /*Q0*/ + mean_x2_fx = L_add( mean_x2_fx, L_mult0( x, x ) ); /*Q0*/ + + /*y = 20.f * log10f( max( 1.f, powerSpectrum[i] ) );*/ + IF( LE_64( W_deposit32_l( pPowerSpectrum_fx[sb] ), W_shl( 1, ( sub( 31, e_ps[sb] ) ) ) ) ) + { + y = 0; + move16(); + } + ELSE + { + y = imult1616( 20, extract_l( L_shr( Mult_32_16( ( L_add( BASOP_Util_Log2( pPowerSpectrum_fx[sb] ), L_shl( e_ps[sb], Q25 ) ) ), INV_Log2_10_Q15 ), Q25 ) ) ); /*Q0*/ + } + mean_y_fx_tmp = L_mac0( mean_y_fx_tmp, y, 1 ); /*Q0*/ + mean_xy_fx = L_add( mean_xy_fx, L_mult0( y, x ) ); /*Q0*/ + + x = add( x, 1 ); } - ELSE + mean_y_fx = BASOP_Util_Divide3216_Scale( mean_y_fx_tmp, width, &tmp_e ); /* mean_y_e*/ + + mean_y_e = add( mean_y_e, sub( tmp_e, 15 ) ); + mean_x_fx = BASOP_Util_Divide1616_Scale( mean_x_fx, width, &tmp_e ); /* mean_x_e*/ + mean_x_e = add( mean_x_e, sub( tmp_e, 15 ) ); + mean_xy_fx = BASOP_Util_Divide3216_Scale( mean_xy_fx, width, &tmp_e ); /* mean_xy_e*/ + mean_xy_e = add( mean_xy_e, sub( tmp_e, 15 ) ); + mean_x2_fx = BASOP_Util_Divide3216_Scale( mean_x2_fx, width, &tmp_e ); /* mean_x2_e*/ + mean_x2_e = add( mean_x2_e, sub( tmp_e, 15 ) ); + + /*slope = ( mean_xy - mean_x * mean_y ) / ( mean_x2 - mean_x * mean_x );*/ + slope = BASOP_Util_Divide3232_Scale( ( L_sub( mean_xy_fx, L_shl( mult( mean_x_fx, mean_y_fx ), sub( add( mean_x_e, mean_y_e ), mean_xy_e ) ) ) ), ( L_sub( mean_x2_fx, L_shl( mult( mean_x_fx, mean_x_fx ), sub( add( mean_x_e, mean_x_e ), mean_x2_e ) ) ) ), &slope_e ); + slope_e = add( slope_e, sub( mean_xy_e, mean_x2_e ) ); + + /* determine whether strong tilt is due to a step in the spectrum (e.g. band limitation, no damping) + or a tonal component close the band border (apply damping) by calculating SFM for a shift of 1/2 SFB width*/ + threshold = BASOP_Util_Divide1616_Scale( 60, width, &threshold_e ); + + test(); + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( slope, add( slope_e, 16 ), negate( threshold ), add( threshold_e, 16 ) ), -1 ) ) { - hPrivateData->prevDampingFactor_IIR_fx[sfb] = 3277; /* 0.1 in Q15 */ - hPrivateData->prevDampingFactor_IIR_e[sfb] = 0; + Word16 shift = shr( width, 1 ); + sfm = IGF_getSFM_new_fx( pPowerSpectrum_fx, hPrivateData->logSpec, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift, e_ps ); + crest = IGF_getCrest_new_fx( hPrivateData->logSpec, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift, &crest_exp ); + shiftedSFM = BASOP_Util_Divide1616_Scale( sfm, crest, &shiftedSFM_e ); + } + ELSE IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( slope, add( slope_e, 16 ), threshold, add( threshold_e, 16 ) ), 1 ) && ( NE_16( sfb, sub( hGrid->sfbWrap[hGrid->nTiles], 1 ) ) ) ) + { + Word16 shift = shr( width, 1 ); + shiftedSFM = BASOP_Util_Divide1616_Scale( IGF_getSFM_new_fx( pPowerSpectrum_fx, hPrivateData->logSpec, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift, e_ps ), IGF_getCrest_new_fx( hPrivateData->logSpec, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift, &crest_exp ), &tmp_e ); + sfm = IGF_getSFM_new_fx( pPowerSpectrum_fx, hPrivateData->logSpec, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift, e_ps ); + crest = IGF_getCrest_new_fx( hPrivateData->logSpec, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift, &crest_exp ); + shiftedSFM = BASOP_Util_Divide1616_Scale( sfm, crest, &shiftedSFM_e ); } + shiftedSFM_e = add( shiftedSFM_e, sub( sfm_exp, crest_exp ) ); - move16(); - move16(); - } + IF( GT_32( shiftedSFM, L_shl( 1311 /*0.04f Q15*/, negate( shiftedSFM_e ) ) ) ) + { + currDampingFactor = 32767; /*1.f Q15*/ + currDampingFactor_e = 0; + move16(); + move16(); + } + ELSE + { + // alpha = min( 320.f / (float) swb_offset[sfb + 1], 1.25f ); + temp = BASOP_Util_Divide1616_Scale( 320, swb_offset[sfb + 1], &alpha_e ); + alpha = extract_l( L_min( temp, L_shl( 20480 /*1.25 Q14*/, sub( 1, alpha_e ) ) ) ); // alpha_e - { - Word32 tonalToNoise; - Word16 adap; - Word16 adap_e; /*stores exp for adap*/ - Word16 tonalToNoise_e; /*stores exponent for tonalToNoise*/ - tonalToNoise_e = 9; /*stores exponent for tonalToNoise*/ - move16(); - adap = BASOP_Util_Divide1616_Scale( width, 30, &adap_e ); - tonalToNoise = IGF_getTNR_ivas_fx( pPowerSpectrum_fx, swb_offset[sfb], swb_offset[sfb + 1], adap, pPowerSpectrum_e, adap_e ); /*Q22*/ - IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( tonalToNoise, tonalToNoise_e, L_add( L_shl( 10, sub( 15, adap_e ) ), adap ), add( 16, adap_e ) ), -1 ) ) + // currDampingFactor = expf( 1.25f * alpha * logf( hPrivateData->SFM_tb[sfb] / hPrivateData->SFM_sb[sfb] ) ); + temp = BASOP_Util_Divide1616_Scale( hPrivateData->SFM_tb_fx[sfb], hPrivateData->SFM_sb_fx[sfb], &tmp_e ); // tmp_e + tmp_e = add( tmp_e, sub( hPrivateData->sfb_tb_e[sfb], hPrivateData->sfb_sb_e[sfb] ) ); + Word16 temp1 = mult( 20480 /* 1.25f in Q14 */, alpha ); + Word16 tmp1_e = add( 1, alpha_e ); + currDampingFactor = round_fx( BASOP_util_Pow2( Mpy_32_16_1( L_add( BASOP_Util_Log2( temp ), L_shl_sat( add( 16, tmp_e ), 25 ) ), temp1 ), add( tmp1_e, 6 ), &currDampingFactor_e ) ); // currDampingFactor_e + + /* calculate tonal-to-noise ratio and reduce damping for low values*/ + + Word32 tonalToNoise; + Word16 adap; + Word16 adap_e; /*stores exp for adap*/ + Word16 tonalToNoise_e; /*stores exponent for tonalToNoise*/ + tonalToNoise_e = 9; + move16(); + adap = BASOP_Util_Divide1616_Scale( width, 40, &adap_e ); + tonalToNoise = IGF_getTNR_ivas_fx( pPowerSpectrum_fx, swb_offset[sfb], swb_offset[sfb + 1], adap, e_ps, adap_e ); /*Q22*/ + + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( tonalToNoise, tonalToNoise_e, L_add( L_shl( 10, sub( 15, adap_e ) ), adap ), add( 16, adap_e ) ), -1 ) ) + { + // currDampingFactor += 0.03f * ( ( 10 + adap ) - tonalToNoise ); + Word32 temp2 = BASOP_Util_Add_Mant32Exp( L_add( L_shl( 10, sub( 15, adap_e ) ) /*exp:adap_e*/, adap ), add( adap_e, 16 ), L_negate( tonalToNoise ), tonalToNoise_e, &tmp_e ); // tmp_e + currDampingFactor_e = BASOP_Util_Add_MantExp( currDampingFactor, currDampingFactor_e, extract_l( Mult_32_32( 983 /*0.03f Q15*/, temp2 ) ), tmp_e, &currDampingFactor ); // currDampingFactor_e + } + } + + Word32 L_tmp = hPrivateData->prevDampingFactor_IIR_fx[sfb]; + move32(); + L_tmp = L_shl( L_tmp, hPrivateData->prevDampingFactor_IIR_e[sfb] ); + test(); + test(); + IF( last_core_acelp || hPrivateData->wasTransient || EQ_32( L_tmp, MIN16B ) ) { - // currDampingFactor += 0.1f * ( ( 10 + adap ) - tonalToNoise ); - Word32 temp2 = BASOP_Util_Add_Mant32Exp( L_add( L_shl( 10, sub( 15, adap_e ) ) /*exp:adap_e*/, adap ), add( adap_e, 16 ), L_negate( tonalToNoise ), tonalToNoise_e, &tmp_e ); /* resultant exp is tmp_e*/ - currDampingFactor_e = BASOP_Util_Add_MantExp( currDampingFactor_fx, currDampingFactor_e, extract_l( Mult_32_16( temp2, 3277 /*0.1f Q15*/ ) ), tmp_e, &currDampingFactor_fx ); /*stores resultant exp for currDampingFactor_fx*/ + tmp = BASOP_Util_Cmp_Mant32Exp( currDampingFactor, currDampingFactor_e, 3277 /* 0.1f in Q15 */, 0 ); + IF( tmp >= 0 ) + { + hPrivateData->prevDampingFactor_IIR_fx[sfb] = currDampingFactor; + hPrivateData->prevDampingFactor_IIR_e[sfb] = currDampingFactor_e; + move16(); + move16(); + } + ELSE + { + hPrivateData->prevDampingFactor_IIR_fx[sfb] = 3277; /* 0.1 in Q15 */ + hPrivateData->prevDampingFactor_IIR_e[sfb] = 0; + move16(); + move16(); + } + } + IF( last_core_acelp ) + { + hPrivateData->dampingFactorSmoothing[sfb] = 2; + move16(); } - } - dampingFactor_e = BASOP_Util_Add_MantExp( currDampingFactor_fx, currDampingFactor_e, hPrivateData->prevDampingFactor_IIR_fx[sfb], hPrivateData->prevDampingFactor_IIR_e[sfb], &dampingFactor_fx ); - dampingFactor_fx = shr( dampingFactor_fx, 1 ); /* resultant exponent is dampingFactor_e*/ - IF( NE_16( BASOP_Util_Cmp_Mant32Exp( dampingFactor_fx, add( dampingFactor_e, 16 ), shr( hPrivateData->prevDampingFactor_IIR_fx[sfb], 1 ), add( hPrivateData->prevDampingFactor_IIR_e[sfb], 16 ) ), -1 ) ) - { - // do nothing - } - ELSE - { - dampingFactor_fx = shr( hPrivateData->prevDampingFactor_IIR_fx[sfb], 1 ); /* resultant exponent is hPrivateData->prevDampingFactor_IIR_e[sfb]*/ - dampingFactor_e = hPrivateData->prevDampingFactor_IIR_e[sfb]; + dampingFactor_e = BASOP_Util_Add_MantExp( currDampingFactor, currDampingFactor_e, hPrivateData->prevDampingFactor_IIR_fx[sfb], hPrivateData->prevDampingFactor_IIR_e[sfb], &dampingFactor ); // dampingFactor_e + dampingFactor = shr( dampingFactor, 1 ); + + gain = Mult_32_16( gain, shl_sat( extract_l( L_min( L_add( dampingFactor, Mult_32_16( L_shl( hPrivateData->dampingFactorSmoothing[sfb], sub( 15, dampingFactor_e ) ) /*Q:15-dampingFactor_e*/, 3277 /*0.1f Q15*/ ) /*Q:15-dampingFactor_e*/ ), shl_sat( 1, sub( 15, dampingFactor_e ) ) ) ), dampingFactor_e ) /*Q15*/ ); + + hPrivateData->prevDampingFactor_IIR_fx[sfb] = dampingFactor; move16(); + hPrivateData->prevDampingFactor_IIR_e[sfb] = dampingFactor_e; + move16(); + if ( hPrivateData->dampingFactorSmoothing[sfb] > 0 ) + { + hPrivateData->dampingFactorSmoothing[sfb] = sub( hPrivateData->dampingFactorSmoothing[sfb], 1 ); + move16(); + } } - IF( dampingFactor_e < 0 ) + ELSE { - dampingFactor_fx = shl( dampingFactor_fx, dampingFactor_e ); - dampingFactor_e = 0; + hPrivateData->prevDampingFactor_IIR_fx[sfb] = MIN16B; // exponent : hPrivateData->prevDampingFactor_IIR_e[sfb] + hPrivateData->prevDampingFactor_IIR_e[sfb] = 0; + hPrivateData->dampingFactorSmoothing[sfb] = 1; + move16(); + move16(); move16(); } - gain_fx = Mult_32_16( gain_fx, shl_sat( extract_l( L_min( L_add( dampingFactor_fx, Mult_32_16( L_shl( hPrivateData->dampingFactorSmoothing[sfb], sub( 15, dampingFactor_e ) ) /*Q:15-dampingFactor_e*/, 3277 /*0.1f Q15*/ ) /*Q:15-dampingFactor_e*/ ), shl_sat( 1, sub( 15, dampingFactor_e ) ) ) ), dampingFactor_e ) /*Q15*/ ); - hPrivateData->prevDampingFactor_IIR_fx[sfb] = dampingFactor_fx; - hPrivateData->prevDampingFactor_IIR_e[sfb] = dampingFactor_e; + hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = tmp_tb; // hPrivateData->prevSFB_FIR_TB_e[sfb] + hPrivateData->prevSFB_FIR_TB_e[sfb] = tmp_tb_e; + hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = hPrivateData->SFM_tb_fx[sfb]; // hPrivateData->prevSFB_IIR_TB_e[sfb] + hPrivateData->prevSFB_IIR_TB_e[sfb] = hPrivateData->sfb_tb_e[sfb]; + hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = tmp_sb; // hPrivateData->prevSFB_FIR_SB_e[sfb] + hPrivateData->prevSFB_FIR_SB_e[sfb] = tmp_sb_e; + hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = hPrivateData->SFM_sb_fx[sfb]; // hPrivateData->prevSFB_IIR_SB_e[sfb] + hPrivateData->prevSFB_IIR_SB_e[sfb] = hPrivateData->sfb_sb_e[sfb]; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); move16(); move16(); - if ( hPrivateData->dampingFactorSmoothing[sfb] > 0 ) - { - hPrivateData->dampingFactorSmoothing[sfb] = sub( hPrivateData->dampingFactorSmoothing[sfb], 1 ); - move16(); - } } ELSE { - hPrivateData->prevDampingFactor_IIR_fx[sfb] = -( 1 << 15 ); /* resultant exp which is 0 stores in hPrivateData->prevDampingFactor_IIR_e[sfb]*/ + hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = 0; // hPrivateData->prevSFB_FIR_TB_e[sfb] + hPrivateData->prevSFB_FIR_TB_e[sfb] = 0; + hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = 0; // hPrivateData->prevSFB_IIR_TB_e[sfb] + hPrivateData->prevSFB_IIR_TB_e[sfb] = 0; + hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = 0; // hPrivateData->prevSFB_IIR_TB_e[sfb] + hPrivateData->prevSFB_FIR_SB_e[sfb] = 0; + hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = 0; // hPrivateData->prevSFB_IIR_SB_e[sfb] + hPrivateData->prevSFB_IIR_SB_e[sfb] = 0; + hPrivateData->prevDampingFactor_IIR_fx[sfb] = MIN16B; /* hPrivateData->prevDampingFactor_IIR_e[sfb]*/ hPrivateData->prevDampingFactor_IIR_e[sfb] = 0; - hPrivateData->dampingFactorSmoothing[sfb] = 1; + hPrivateData->dampingFactorSmoothing[sfb] = 2; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); move16(); move16(); move16(); } - - hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = tmp_tb_fx; - hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = hPrivateData->SFM_tb_fx[sfb]; - hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = tmp_sb_fx; - hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = hPrivateData->SFM_sb_fx[sfb]; - hPrivateData->prevSFB_FIR_TB_e[sfb] = hPrivateData->sfb_tb_e[sfb]; - hPrivateData->prevSFB_IIR_TB_e[sfb] = hPrivateData->sfb_tb_e[sfb]; - hPrivateData->prevSFB_FIR_SB_e[sfb] = hPrivateData->sfb_sb_e[sfb]; - hPrivateData->prevSFB_IIR_SB_e[sfb] = hPrivateData->sfb_sb_e[sfb]; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); } - ELSE + } + ELSE + { + tmp_e = e_mdct; + move16(); + sfbEnergyR = add_sat( EPSILON_FX, BASOP_Util_Divide3216_Scale( sum2_32_fx( pMDCTSpectrum_fx + swb_offset[sfb], width, &tmp_e ) /*exp: tmp_e*/, width, &sfbEnergyR_e ) ); // sfbEnergyR_e + sfbEnergyR_e = add( sfbEnergyR_e, add( tmp_e, -15 ) ); + gain = L_shl( sfbEnergyR, 16 ); // gain_e + move32(); + gain_e = sfbEnergyR_e; + + IF( element_mode > EVS_MONO ) { - hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = 0; - hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = 0; - hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = 0; - hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = 0; + hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = 0; // hPrivateData->prevSFB_FIR_TB_e[sfb] hPrivateData->prevSFB_FIR_TB_e[sfb] = 0; + hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = 0; // hPrivateData->prevSFB_IIR_TB_e[sfb] hPrivateData->prevSFB_IIR_TB_e[sfb] = 0; + hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = 0; // hPrivateData->prevSFB_IIR_TB_e[sfb] hPrivateData->prevSFB_FIR_SB_e[sfb] = 0; + hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = 0; // hPrivateData->prevSFB_IIR_SB_e[sfb] hPrivateData->prevSFB_IIR_SB_e[sfb] = 0; - + hPrivateData->prevDampingFactor_IIR_fx[sfb] = MIN16B; /* hPrivateData->prevDampingFactor_IIR_e[sfb]*/ + hPrivateData->prevDampingFactor_IIR_e[sfb] = 0; hPrivateData->dampingFactorSmoothing[sfb] = 2; move16(); move16(); @@ -4415,53 +2533,33 @@ static void IGF_CalculateStereoEnvelope_fx( move16(); move16(); move16(); + move16(); + move16(); } } - ELSE - { - tmp_e = pMDCTSpectrum_e; - sfbEnergyR_fx = add_sat( EPSILON_FX, BASOP_Util_Divide3216_Scale( sum2_32_fx( pMDCTSpectrum_fx + swb_offset[sfb], width, &tmp_e ) /*exp: tmp_e*/, width, &sfbEnergyR_e ) ); - sfbEnergyR_e = add( sfbEnergyR_e, add( tmp_e, -15 ) ); /* stores resultant exponent for sfbEnergyR_fx*/ - gain_fx = sfbEnergyR_fx; /*resultant exponent stored in gain_e=sfbEnergyR_e*/ - move32(); - gain_e = add( sfbEnergyR_e, 16 ); /* because gain_fx is word32;only after adding 16 q of gain_fx is 15-sfbEnergyR_e*/ - hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = 0; - hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = 0; - hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = 0; - hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = 0; - hPrivateData->prevSFB_FIR_TB_e[sfb] = 0; - hPrivateData->prevSFB_IIR_TB_e[sfb] = 0; - hPrivateData->prevSFB_FIR_SB_e[sfb] = 0; - hPrivateData->prevSFB_IIR_SB_e[sfb] = 0; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - } + gain = Mult_32_16( gain, att ); // gain_e + gain_e = add( gain_e, 0 ); + /*gain=0.5f+log2f(gain)*2+16 becuase 2.885390081777927f=2*1/loge(2) so 2*1/loge(2)*loge(x) can be written as 2*log2(x)*/ - gain_fx = L_add( ONE_IN_Q22, L_add( L_add( L_shr( BASOP_Util_Log2( gain_fx ), 1 ), L_shl( gain_e, Q24 ) ), L_shl( 16, Q23 ) ) ); /*Q23*/ + gain = L_add( ONE_IN_Q22, L_add( L_add( L_shr( BASOP_Util_Log2( gain ), 1 ), L_shl( gain_e, Q24 ) ), L_shl( 16, Q23 ) ) ); /*Q23*/ test(); test(); - if ( !isTransient && ( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) ) + IF( !isTransient && ( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) ) { - gain_fx = L_add( gain_fx, ONE_IN_Q21 ); /* better preservation of original HF band energy */ + gain = L_add( gain, ONE_IN_Q21 ); /* better preservation of original HF band energy */ } test(); test(); - if ( !isTransient && ( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_64000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_64000_CPE ) ) ) + IF( !isTransient && ( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_64000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_64000_CPE ) ) ) { - gain_fx = L_add( gain_fx, ONE_IN_Q20 ); + gain = L_add( gain, ONE_IN_Q20 ); } - gain_fx = L_min( gain_fx, 91 << Q23 ); /* 13+15+63, see arithcode encode residual */ - gain_fx = L_max( gain_fx, 0 ); + gain = L_min( gain, 91 << Q23 ); /* 13+15+63, see arithcode encode residual */ + gain = L_max( gain, 0 ); gain_e = 8; /* stores exponent for gain_fx*/ move16(); - hPrivateData->igfScfQuantized[sfb] = (Word16) ( L_shr( gain_fx, 23 ) ); /*Q0*/ + hPrivateData->igfScfQuantized[sfb] = extract_l( L_shr( gain, Q23 ) ); /*Q0*/ move16(); } } @@ -4469,786 +2567,580 @@ static void IGF_CalculateStereoEnvelope_fx( return; } -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /*-------------------------------------------------------------------* - * IGF_WriteEnvelope() + * IGF_CalculateStereoEnvelope_fx() * - * writes IGF SCF values + * envelope estimation + *-------------------------------------------------------------------*/ -/*! r: number of bits writen */ -static Word16 IGF_WriteEnvelope_ivas( - const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *pBitOffset, /* i : ptr to bitOffset counter */ - const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 isIndepFlag, /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ - Word16 *igfAllZero /* i : returns 1 if all IGF scfs are zero, else 0 */ -) +static void IGF_CalculateStereoEnvelope_fx( + const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ + const Word32 *pMDCTSpectrum_fx, /* i : MDCT spectrum */ + Word16 pMDCTSpectrum_e, /* i : exponent for pMDCTSpectrum_fx */ + const Word32 *pMDCTSpectrumMsInv_fx, /* i : MDCT spectrum */ + Word16 pMDCTSpectrumMsInv_e, /* i : expontent for pMDCTSpectrumMsInv_fx */ + const Word32 *pPowerSpectrum_fx, /* i : MDCT^2 + MDST^2 spectrum, or estimate */ + Word16 *pPowerSpectrum_e, /* i : exponent for pPowerSpectrum_fx */ + const Word32 *pPowerSpectrumMsInv_fx, /* i : inverse power spectrum */ + Word16 *q_pPowerSpectrumMsInv, /* i : Q for pPowerSpectrumMsInv_fx */ + const Word16 igfGridIdx, /* i : IGF grid index */ + const Word16 coreMsMask[N_MAX], /* i : line wise ms Mask */ + const Word16 isTransient, /* i : flag indicating if transient is detected */ + const Word16 last_core_acelp, /* i : indicator if last frame was ACELP core */ + const Word16 mct_on ) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; - Word16 sfb; - Word16 totBitCount; - Word16 startBitCount; - - startBitCount = *pBitOffset; - totBitCount = 0; - *igfAllZero = 1; - move16(); - move16(); + Word16 *swb_offset; + Word16 sfb; /* this is the actual scalefactor band */ + Word16 width; /* this is width in subbands of the actual scalefactor band */ + Word16 tile_idx; + Word16 strt_cpy; + Word32 gain_fx; /* the gain which has to be applied to the source tile to get the destination energy */ + Word16 sb; + Word16 sfbEnergyR_fx; + Word32 sfbEnergyC_fx; /* the energy of the destination region of the tile */ + Word32 sfbEnergyTileR_fx; + Word32 sfbEnergyTileC_fx; /* the energy of the destination region of the tile */ + Word16 tmp, x, y; + Word16 mean_x_fx, mean_y_fx; + Word32 mean_xy_fx, mean_x2_fx; + Word16 slope_fx; + Word16 tmp_tb_fx; + Word16 tmp_sb_fx; + Word16 sfbCnt; + Word32 tileSrcSpec_fx[MAX_IGF_SFB_LEN]; + Word16 sfm; + Word16 crest; + Word16 temp; + Word16 mean_x_e, mean_y_e; /*Stores exponent for mean_x and mean_y respectively*/ + Word16 mean_xy_e, mean_x2_e; /*stores exponent for mean_xy and mean_x2 respectively*/ + Word16 tileSrcSpec_e[MAX_IGF_SFB_LEN]; /*Exponent for tileSrcSpec_fx*/ + Word16 sfbEnergyTileR_e; /*Exponent for sfbEnergyTileR_fx*/ + Word16 sfbEnergyTileC_e; /*Exponent for sfbEnergyTileC_fx*/ + Word16 sfbEnergyC_e; /*Exponent for sfbEnergyC_fx*/ + Word16 gain_e; /*exponent for gain_fx*/ + Word16 crest_exp; /*stores exponent for output from crest*/ + Word16 sfm_exp; /*stores exponent for ouput from sfm*/ + Word16 tmp_tb_e; /*Stores exponent for tmp_tb_fx*/ + Word16 tmp_sb_e; /*stores exponent for tmp_sb_fx*/ + Word16 slope_e; /*stores exponent for slope_fx*/ + Word16 sfbEnergyR_e; /*stores exponent for sfbEnergyR*/ + Word16 tmp_e; + Word32 temp_pPowerSpectrumMsInv[N_MAX], length; + Word16 q_temp_pPowerSpectrumMsInv = Q31, i; move16(); - hPrivateData = &hIGFEnc->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - FOR( sfb = hGrid->startSfb; sfb < hGrid->stopSfb; sfb++ ) + IF( pPowerSpectrumMsInv_fx != NULL ) { - IF( hPrivateData->igfScfQuantized[sfb] != 0 ) + length = N_MAX; + move16(); + if ( mct_on ) { - *igfAllZero = 0; + length = L_FRAME48k; move16(); - BREAK; - } - } - - IF( *igfAllZero != 0 ) - { - IGF_write_bit_fx( hBstr, pBitOffset, 1 ); - - if ( NULL == hBstr ) - { - IGFSCFEncoderSaveContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); } - - IGFSCFEncoderReset_fx( &hPrivateData->hIGFSCFArithEnc ); - - if ( NULL == hBstr ) - { - IGFSCFEncoderRestoreContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); - } - } - ELSE - { - IGF_write_bit_fx( hBstr, pBitOffset, 0 ); - - if ( NULL == hBstr ) + FOR( i = 0; i < length; i++ ) { - IGFSCFEncoderSaveContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); - } - - *pBitOffset = IGFSCFEncoderEncode_ivas_fx( &hPrivateData->hIGFSCFArithEnc, hBstr, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], igfGridIdx, isIndepFlag ); - move16(); - - if ( NULL == hBstr ) + IF( pPowerSpectrumMsInv_fx[i] != 0 ) + { + q_temp_pPowerSpectrumMsInv = s_min( q_temp_pPowerSpectrumMsInv, add( q_pPowerSpectrumMsInv[i], norm_l( pPowerSpectrumMsInv_fx[i] ) ) ); + } + } + FOR( i = 0; i < length; i++ ) { - IGFSCFEncoderRestoreContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); + temp_pPowerSpectrumMsInv[i] = L_shl( pPowerSpectrumMsInv_fx[i], sub( q_temp_pPowerSpectrumMsInv, q_pPowerSpectrumMsInv[i] ) ); + move32(); } } - totBitCount = sub( *pBitOffset, startBitCount ); - - return totBitCount; -} - -#endif -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/*-------------------------------------------------------------------* - * IGF_Whitening() - * - * calculates the IGF whitening levels by SFM and crest - *-------------------------------------------------------------------*/ - -static void IGF_Whitening_ivas_fx( - const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : | instance handle of IGF Encoder */ - Word32 *powerSpectrum, /* i : Q31 | MDCT/MDST power spectrum */ - Word16 *powerSpectrum_e, /* i : Q31 | MDCT/MDST power spectrum */ - const Word16 igfGridIdx, /* i : Q0 | IGF grid index */ - const Word16 isTransient, /* i : Q0 | flag indicating if transient is detected */ - const Word16 last_core_acelp, /* i : Q0 | indicator if last frame was ACELP core */ - const Word16 isTNSActive, /* i : Q0 | indicator if TNS is active */ - const Word16 sp_aud_decision0, /* i : Q0 | first stage classifier decision */ - const Word32 brate, /* i : Q0 | bitrate */ - const Word16 element_mode /* i : Q0 | element mode */ -) -{ - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - H_IGF_GRID hGrid; - Word16 p; /*Q0*/ - Word16 tmp; - Word16 tmp_e; - Word16 SFM_src; - Word16 SFM_tar; - Word16 SFM_src_e; - Word16 SFM_tar_e; - Word16 num_Tiles; - Word16 SFM; - Word16 crest_e; - - SFM = -ONE_IN_Q13; /*1.0f Q13*/ - move16(); hPrivateData = &hIGFEnc->igfData; hGrid = &hPrivateData->igfInfo.grid[(Word16) igfGridIdx]; + swb_offset = hGrid->swb_offset; + move16(); - IF( NE_16( igfGridIdx, IGF_GRID_LB_NORM ) ) + IF( igfGridIdx != IGF_GRID_LB_NORM ) { - FOR( p = 0; p < hGrid->nTiles; p++ ) + FOR( sfbCnt = 0; sfbCnt < sub( hGrid->sfbWrap[hGrid->nTiles], hGrid->sfbWrap[0] ); sfbCnt++ ) { /* reset filter */ - hPrivateData->prevSFM_FIR[p] = L_deposit_l( 0 ); - hPrivateData->prevSFM_IIR[p] = 0; + hPrivateData->prevSFM_FIR_SFB_TB_fx[sfbCnt] = 0; // exponent : hPrivateData->prevSFB_FIR_TB_e[sfbCnt] + hPrivateData->prevSFM_IIR_SFB_TB_fx[sfbCnt] = 0; // exponent : hPrivateData->prevSFB_IIR_TB_e[sfbCnt] + hPrivateData->prevSFM_FIR_SFB_SB_fx[sfbCnt] = 0; // exponent : hPrivateData->prevSFB_FIR_SB_e[sfbCnt] + hPrivateData->prevSFM_IIR_SFB_SB_fx[sfbCnt] = 0; // exponent : hPrivateData->prevSFB_IIR_SB_e[sfbCnt] + hPrivateData->prevSFB_FIR_TB_e[sfbCnt] = 0; + hPrivateData->prevSFB_IIR_TB_e[sfbCnt] = 0; + hPrivateData->prevSFB_FIR_SB_e[sfbCnt] = 0; + hPrivateData->prevSFB_IIR_SB_e[sfbCnt] = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); move16(); - - /* preset values: */ - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; move16(); } } - FOR( p = 0; p < IGF_MAX_TILES; p++ ) + IF( pPowerSpectrum_fx ) { - /* update prev data: */ - hPrivateData->igfPrevWhiteningLevel[p] = hPrivateData->igfCurrWhiteningLevel[p]; - /* preset values: */ - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; - move16(); - move16(); + FOR( sb = hGrid->sbWrap[0]; sb < swb_offset[hGrid->sfbWrap[hGrid->nTiles]]; sb++ ) + { + /*hPrivateData->logSpec[sb] = max( 0, (Word16) ( logf( max( FLT_MIN, pPowerSpectrum[sb] ) ) * INV_LOG_2 ) );*/ + IF( LE_32( 1, pPowerSpectrum_fx[sb] ) ) + { + hPrivateData->logSpec[sb] = s_max( 0, (Word16) L_shr( L_add( BASOP_Util_Log2( pPowerSpectrum_fx[sb] ), L_shl( pPowerSpectrum_e[sb], Q25 ) ), 25 ) ); + } + ELSE + { + hPrivateData->logSpec[sb] = 0; /*max(0,-126) is always 0*/ + } + move16(); + } } - test(); - IF( !( isTransient || hPrivateData->wasTransient ) ) + FOR( tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++ ) { - IF( powerSpectrum ) + strt_cpy = hGrid->sbWrap[tile_idx]; + move16(); + + FOR( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ ) { - FOR( p = 0; p < hGrid->nTiles; p++ ) + width = sub( swb_offset[sfb + 1], swb_offset[sfb] ); + sfbEnergyTileR_fx = EPSILON_FX; + sfbEnergyTileC_fx = EPSILON_FX; + sfbEnergyC_fx = EPSILON_FX; + sfbEnergyTileR_e = 0; + sfbEnergyTileC_e = 0; + sfbEnergyC_e = 0; + move16(); + move16(); + move16(); + move32(); + move32(); + move32(); + IF( pPowerSpectrum_fx ) { - Word16 sb; - - IF( isTNSActive ) - { - FOR( sb = hGrid->tile[p]; sb < hGrid->tile[p + 1]; sb++ ) - { - IF( LT_32( powerSpectrum[sb], 1 ) ) - { - hPrivateData->logSpec[sb] = 0; /* max(0,FLT_MIN_EXP=-125 )*/ - } - ELSE - { - hPrivateData->logSpec[sb] = extract_l( L_max( 0, L_shr( L_add( BASOP_Util_Log2( powerSpectrum[sb] ), L_shl( powerSpectrum_e[sb], Q25 ) ), Q25 ) ) ); - } - move16(); - } - } - - /* if current tile contains only a single SFB, reuse already computed SFM values */ - test(); - IF( element_mode > EVS_MONO && EQ_16( sub( hGrid->sfbWrap[p + 1], hGrid->sfbWrap[p] ), 1 ) ) - { - tmp = hPrivateData->SFM_tb_fx[p]; - tmp_e = hPrivateData->sfb_tb_e[p]; - move16(); - move16(); - } - ELSE - { - tmp = BASOP_Util_Divide1616_Scale( IGF_getSFM_new_fx( powerSpectrum, hPrivateData->logSpec, hGrid->tile[p], hGrid->tile[p + 1], powerSpectrum_e ), IGF_getCrest_new_fx( hPrivateData->logSpec, hGrid->tile[p], hGrid->tile[p + 1], &crest_e ), &tmp_e ); - tmp_e = sub( tmp_e, crest_e ); - } - - test(); - IF( last_core_acelp || hPrivateData->wasTransient ) - { - hPrivateData->prevSFM_FIR[p] = L_shl( tmp, add( 1, tmp_e ) ); /*16-(15-exp)=>15Q16*/ - hPrivateData->prevSFM_IIR[p] = shl( tmp, sub( tmp_e, 2 ) ); /*13-(15-exp)=>2Q13*/ - move32(); - move16(); - } - - test(); - IF( LE_32( brate, IVAS_48k ) && EQ_16( element_mode, IVAS_CPE_MDCT ) ) - { - Word16 temp; - num_Tiles = 0; - SFM_src = 0; - SFM_tar = 0; - SFM_src_e = 0; - SFM_tar_e = 0; - move16(); - move16(); - move16(); - move16(); - move16(); - - FOR( sb = hGrid->sfbWrap[p]; sb < hGrid->sfbWrap[p + 1]; sb++ ) - { - num_Tiles = add( num_Tiles, 1 ); - SFM_src_e = BASOP_Util_Add_MantExp( hPrivateData->SFM_sb_fx[sb], hPrivateData->sfb_sb_e[sb], SFM_src, SFM_src_e, &SFM_src ); - SFM_tar_e = BASOP_Util_Add_MantExp( hPrivateData->SFM_tb_fx[sb], hPrivateData->sfb_tb_e[sb], SFM_tar, SFM_tar_e, &SFM_tar ); - } - - /* compute the average */ - SFM_src = shr( BASOP_Util_Divide1616_Scale( SFM_src, num_Tiles, &temp ), 2 ); - SFM_src_e = add( SFM_src_e, sub( temp, 13 ) ); /*temp-15+2:because right shifted by 2 which are the guard bits*/ - SFM_tar = shr( BASOP_Util_Divide1616_Scale( SFM_tar, num_Tiles, &temp ), 2 ); - SFM_tar_e = add( SFM_tar_e, sub( temp, 13 ) ); /*temp-15+2:because right shifted by 2 which are the guard bits*/ - - IF( LT_16( SFM_tar_e, SFM_src_e ) ) - { - SFM_tar = shl( SFM_tar, sub( SFM_tar_e, SFM_src_e ) ); /*making the q for SFM_tar and SFM_src equal with 2 as guard bits*/ - SFM_tar_e = SFM_src_e; - } - ELSE - { - SFM_src = shr( SFM_src, sub( SFM_tar_e, SFM_src_e ) ); /*making the q for SFM_tar and SFM_src equal with 2 as guard bits*/ - SFM_src_e = SFM_tar_e; - } - move16(); - - test(); - test(); - IF( ( p > 0 ) && ( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) ) - { - test(); - if ( EQ_16( p, 1 ) && EQ_16( abs_s( sub( hPrivateData->igfCurrWhiteningLevel[0], hPrivateData->igfCurrWhiteningLevel[1] ) ), 2 ) ) /* OFF vs. STRONG */ - { - hPrivateData->igfCurrWhiteningLevel[0] = IGF_WHITENING_MID; - move16(); - } - hPrivateData->igfCurrWhiteningLevel[p] = hPrivateData->igfCurrWhiteningLevel[p - 1]; - move16(); - } - ELSE IF( sp_aud_decision0 ) - { - /* Music */ - /* whitening Off: when tonality of target is more than source or tonality of target is close to that of source */ - test(); - if ( LE_16( SFM_tar, SFM_src ) || LE_32( SFM_tar, L_add( SFM_src, L_shl( 1, sub( 14, SFM_src_e /*0.5 with exponent SFM_src_e*/ ) ) ) ) ) - { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; - move16(); - } - - /* whitening mid: */ - test(); - if ( GT_32( SFM_tar, L_add( SFM_src, L_shl( 1, sub( 14, SFM_src_e /*0.5 with exponent SFM_src_e*/ ) ) ) ) && LE_32( SFM_tar, L_add( SFM_src, L_shl( 5, sub( 13, SFM_src_e ) ) /*1.25 with exponent SFM_src_e*/ ) ) ) - { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; - move16(); - } - - /* whitening strong */ - if ( GT_32( SFM_tar, L_add( SFM_src, L_shl( 5, sub( 13, SFM_src_e ) ) /*1.25 with exponent SFM_src_e*/ ) ) ) - { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_STRONG; - move16(); - } - } - ELSE - { - /* Speech */ - /* whitening Off: when tonality of target is more than source or tonality of target is close to that of source */ - test(); - if ( LE_16( SFM_tar, SFM_src ) || LE_32( SFM_tar, L_add( SFM_src, L_shr( 3277 /*0.1 Q15*/, SFM_src_e ) ) ) ) - { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; - move16(); - } - - /* whitening mid: */ - test(); - if ( GT_32( SFM_tar, L_add( SFM_src, L_shr( 3277 /*0.1 Q15*/, SFM_src_e ) ) ) && LE_32( SFM_tar, L_add( SFM_src, L_shl( 1, sub( 14, SFM_src_e /*0.5 with exponent SFM_src_e*/ ) ) ) ) ) - { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; - move16(); - } - - /* whitening strong */ - if ( GT_32( SFM_tar, L_add( SFM_src, L_shl( 1, sub( 14, SFM_src_e /*0.5 with exponent SFM_src_e*/ ) ) ) ) ) - { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_STRONG; - move16(); - } - } + Word16 final_exp; + Word16 norm_exp; + Word32 scaled_value; + tmp = strt_cpy; + move16(); - SFM = shl( SFM_tar, sub( SFM_tar_e, 2 ) ); /*2Q13*/ - } - ELSE + FOR( sb = swb_offset[sfb]; sb < swb_offset[sfb + 1]; sb++ ) { - test(); - IF( element_mode > EVS_MONO && EQ_16( sub( hGrid->sfbWrap[p + 1], hGrid->sfbWrap[p] ), 1 ) ) + IF( NE_16( coreMsMask[sb], coreMsMask[strt_cpy] ) ) { - SFM = shl( tmp, sub( tmp_e, 2 ) ); /*2Q13*/ + sfbEnergyC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyC_fx, sfbEnergyC_e, pPowerSpectrum_fx[sb], pPowerSpectrum_e[sb], &sfbEnergyC_e ); /*resultant exponent is stored in sfbEnergyC_e*/ + norm_exp = norm_l( pMDCTSpectrumMsInv_fx[strt_cpy] ); + final_exp = sub( pMDCTSpectrumMsInv_e, norm_exp ); + scaled_value = L_shl( pMDCTSpectrumMsInv_fx[strt_cpy], norm_exp ); + sfbEnergyTileR_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileR_fx, sfbEnergyTileR_e, Mult_32_32( scaled_value, scaled_value ), shl( final_exp, 1 ), &sfbEnergyTileR_e ); /*resultant exponent is stored in sfbEnergyTileR_e*/ + sfbEnergyTileC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileC_fx, sfbEnergyTileC_e, pPowerSpectrumMsInv_fx[strt_cpy], sub( 31, q_pPowerSpectrumMsInv[strt_cpy] ), &sfbEnergyTileC_e ); /*resultant exponent is stored in sfbEnergyTileC_e*/ + tileSrcSpec_fx[strt_cpy - tmp] = temp_pPowerSpectrumMsInv[strt_cpy]; /*resultant exponent is stored in tileSrcSpec_e*/ + tileSrcSpec_e[strt_cpy - tmp] = sub( 31, q_temp_pPowerSpectrumMsInv ); } ELSE { - Word32 temp; - temp = L_add( L_shl( tmp, sub( tmp_e, 2 ) ), L_add( L_shr( hPrivateData->prevSFM_FIR[p], 3 ), L_shr( hPrivateData->prevSFM_IIR[p], 1 ) ) ); - SFM = extract_l( L_min( 22118 /*2.7*/, temp ) ); /*2Q13*/ + sfbEnergyC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyC_fx, sfbEnergyC_e, pPowerSpectrum_fx[sb], pPowerSpectrum_e[sb], &sfbEnergyC_e ); /*resultant exponent is stored in sfbEnergyC_e*/ + norm_exp = norm_l( pMDCTSpectrum_fx[strt_cpy] ); + final_exp = sub( pMDCTSpectrum_e, norm_exp ); + scaled_value = L_shl( pMDCTSpectrum_fx[strt_cpy], norm_exp ); + sfbEnergyTileR_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileR_fx, sfbEnergyTileR_e, Mult_32_32( scaled_value, scaled_value ), shl( final_exp, 1 ), &sfbEnergyTileR_e ); /*resultant exponent is stored in sfbEnergyTileR_e*/ + sfbEnergyTileC_fx = BASOP_Util_Add_Mant32Exp( sfbEnergyTileC_fx, sfbEnergyTileC_e, pPowerSpectrum_fx[strt_cpy], pPowerSpectrum_e[strt_cpy], &sfbEnergyTileC_e ); /*resultant exponent is stored in sfbEnergyTileC_e*/ + tileSrcSpec_fx[strt_cpy - tmp] = pPowerSpectrum_fx[strt_cpy]; /*resultant exponent is stored in tileSrcSpec_e*/ + tileSrcSpec_e[strt_cpy - tmp] = pPowerSpectrum_e[strt_cpy]; } - hPrivateData->prevSFM_FIR[p] = L_shl( tmp, add( 1, tmp_e ) ); /*15Q16*/ - hPrivateData->prevSFM_IIR[p] = SFM; move32(); move16(); + strt_cpy = add( strt_cpy, 1 ); + } + + sfbEnergyTileR_fx = BASOP_Util_Divide3216_Scale( sfbEnergyTileR_fx, width, &tmp_e ); + sfbEnergyTileR_e = sub( add( sfbEnergyTileR_e, tmp_e ), 15 ); /*stores the resultant exponent for sfbEnergyTileR_fx*/ + + /*gain = (float) ( sfbEnergyTileR * ( sfbEnergyC / sfbEnergyTileC ) );*/ + temp = BASOP_Util_Divide3232_Scale( sfbEnergyC_fx, L_add( sfbEnergyTileC_fx, EPSILON_FX ), &tmp_e ); + gain_e = add( tmp_e, sub( sfbEnergyC_e, sfbEnergyTileC_e ) ); + gain_fx = Mult_32_16( sfbEnergyTileR_fx, temp ); + gain_e = add( 16, add( gain_e, sfbEnergyTileR_e ) ); /*stores the resultant exponent for gain_fx*/ + + IF( !isTransient ) + { + Word16 diffSFM_fx; + Word16 shiftedSFM_fx; + Word16 shiftedSFM_e; /*stores the resultant exponent for shiftedSFM_fx*/ + shiftedSFM_fx = 0; + shiftedSFM_e = 0; + move16(); + move16(); - IF( GT_16( SFM, hGrid->whiteningThreshold[1][p] ) ) + // tmp_tb = IGF_getSFM(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]) / IGF_getCrest(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]); + sfm = IGF_getSFM( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1], IVAS_CPE_MDCT ); + + crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1], IVAS_CPE_MDCT ); + + tmp_tb_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &tmp_e ); + tmp_tb_e = add( tmp_e, sub( sfm_exp, crest_exp ) ); /*stores the resultant exponent for tmp_tb_fx*/ + + // tmp_sb = IGF_getSFM(tileSrcSpec, 0, strt_cpy - tmp) / IGF_getCrest(tileSrcSpec, 0, strt_cpy - tmp); + sfm = IGF_getSFM( &sfm_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ), IVAS_CPE_MDCT ); + + crest = IGF_getCrest( &crest_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ), IVAS_CPE_MDCT ); + + tmp_sb_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &tmp_e ); + tmp_sb_e = add( tmp_e, sub( sfm_exp, crest_exp ) ); /*stores the resultant exponent for tmp_sb_fx*/ + + IF( last_core_acelp || hPrivateData->wasTransient ) { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_STRONG; + hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = tmp_tb_fx; /*Exponent for hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] and hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] values stored in hPrivateData->sfb_tb_e[sfb] */ + hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = tmp_sb_fx; /*Exponent for hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] and hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] values stored in hPrivateData->sfb_sb_e[sfb]*/ + hPrivateData->prevSFB_FIR_TB_e[sfb] = tmp_sb_e; + hPrivateData->prevSFB_IIR_TB_e[sfb] = tmp_sb_e; + hPrivateData->prevSFB_FIR_SB_e[sfb] = tmp_sb_e; + hPrivateData->prevSFB_IIR_SB_e[sfb] = tmp_sb_e; + move16(); + move16(); + move16(); + move16(); move16(); - } - ELSE IF( GT_16( SFM, hGrid->whiteningThreshold[0][p] ) ) - { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; move16(); - } - ELSE - { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; move16(); - } - } - - IF( element_mode > EVS_MONO ) - { - IF( last_core_acelp ) /* reset */ - { - set16_fx( hPrivateData->igfPastSFM_fx[p], -ONE_IN_Q13, IGF_PAST_SFM_LEN ); - hPrivateData->igfWhiteningHangoverCnt[p] = 2; move16(); } ELSE { - test(); - test(); - test(); - test(); - /* check whether change in whitening level should be allowed or not (if SFM is inside a certain margin around thresholds) */ - IF( NE_16( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfPrevWhiteningLevel[p] ) && - ( ( GT_32( SFM, L_sub( hGrid->whiteningThreshold[0][p], 1229 /*0.15f Q13*/ ) ) && LT_32( SFM, L_add( hGrid->whiteningThreshold[0][p], 1229 ) ) ) || - ( GT_32( SFM, L_sub( hGrid->whiteningThreshold[1][p], 1229 ) ) && LT_32( SFM, L_add( hGrid->whiteningThreshold[1][p], 1229 ) ) ) ) ) + /* Purpose of this block: + -to make the exponent of hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] and hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] equal to that of tmp_tb_fx + -to make the exponent of hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] and hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] equal to that of tmp_sb_fx + */ + Word16 diff_sb_e; /*stores the difference of exponents for sb*/ + Word16 diff_tb_e; /*stores the difference of exponents for tb*/ + diff_sb_e = sub( tmp_sb_e, hPrivateData->sfb_sb_e[sfb] ); + diff_tb_e = sub( tmp_tb_e, hPrivateData->sfb_tb_e[sfb] ); + IF( LE_16( tmp_tb_e, hPrivateData->sfb_tb_e[sfb] ) ) { - Word16 mean_past_SFM; - Word16 mean_past_SFM_e; - Word16 countable; - Word16 i; - mean_past_SFM = 0; - mean_past_SFM_e = 0; - countable = 0; + tmp_tb_fx = shl( tmp_tb_fx, diff_tb_e ); + tmp_tb_e = hPrivateData->sfb_tb_e[sfb]; + move16(); + } + ELSE + { + hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = shr( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], diff_tb_e ); + hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = shr( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], diff_tb_e ); move16(); move16(); + hPrivateData->prevSFB_FIR_TB_e[sfb] = tmp_tb_e; + hPrivateData->prevSFB_IIR_TB_e[sfb] = tmp_tb_e; + move16(); + move16(); + } + IF( LE_16( tmp_sb_e, hPrivateData->sfb_sb_e[sfb] ) ) + { + tmp_sb_fx = shl( tmp_sb_fx, diff_sb_e ); + tmp_sb_e = hPrivateData->sfb_sb_e[sfb]; + move16(); + } + ELSE + { + hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = shr( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], diff_sb_e ); + hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = shr( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], diff_sb_e ); + move16(); + move16(); + hPrivateData->prevSFB_FIR_SB_e[sfb] = tmp_sb_e; + hPrivateData->prevSFB_IIR_SB_e[sfb] = tmp_sb_e; + move16(); move16(); - - /* compute mean of last (available) SFM values */ - FOR( i = 0; i < IGF_PAST_SFM_LEN; i++ ) - { - IF( hPrivateData->igfPastSFM_fx[p][i] >= 0 ) - { - mean_past_SFM_e = BASOP_Util_Add_MantExp( mean_past_SFM, mean_past_SFM_e, hPrivateData->igfPastSFM_fx[p][i], 2, &mean_past_SFM ); - countable = add( countable, 1 ); - } - } - IF( countable ) - { - Word16 temp; - mean_past_SFM = BASOP_Util_Divide1616_Scale( mean_past_SFM, countable, &temp ); - mean_past_SFM_e = add( mean_past_SFM_e, sub( temp, 15 ) ); - mean_past_SFM = shl( mean_past_SFM, sub( mean_past_SFM_e, 2 ) ); /*mean_past_SFM_e=2*/ - /* deny change in whitening level for small deviations from mean SFM */ - if ( LT_16( abs_s( sub( SFM, mean_past_SFM ) ), 1638 ) /*0.2 in Q13*/ ) - { - hPrivateData->igfCurrWhiteningLevel[p] = hPrivateData->igfPrevWhiteningLevel[p]; - move16(); - } - } } } - - hPrivateData->igfPastSFM_fx[p][hPrivateData->igfPastSFM_pos] = SFM; /*2Q13*/ + tmp_tb_fx = shr_sat( tmp_tb_fx, sub( 2, tmp_tb_e ) ); /* Since we're limiting max value to 2.7f we can saturate to Q13 */ + tmp_sb_fx = shr_sat( tmp_sb_fx, sub( 2, tmp_sb_e ) ); /* Since we're limiting max value to 2.7f we can saturate to Q13 */ + hPrivateData->SFM_tb_fx[sfb] = add_sat( tmp_tb_fx, add_sat( shr( hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb], sub( 2, hPrivateData->prevSFB_FIR_TB_e[sfb] ) ), shr( hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb], sub( 3, hPrivateData->prevSFB_IIR_TB_e[sfb] ) ) ) ); /* Since we're limiting max value to 2.7f we can saturate to Q13 */ + hPrivateData->SFM_tb_fx[sfb] = s_min( 22118 /*2.7f Q13*/, hPrivateData->SFM_tb_fx[sfb] ); /* resultant exponent stored in hPrivateData->sfb_sb_e[sfb]*/ + hPrivateData->SFM_sb_fx[sfb] = add_sat( tmp_sb_fx, add_sat( shr( hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb], sub( 2, hPrivateData->prevSFB_FIR_SB_e[sfb] ) ), shr( hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb], sub( 3, hPrivateData->prevSFB_IIR_SB_e[sfb] ) ) ) ); /* Since we're limiting max value to 2.7f we can saturate to Q13 */ + hPrivateData->SFM_sb_fx[sfb] = s_min( 22118 /*2.7f Q13*/, hPrivateData->SFM_sb_fx[sfb] ); /*resultant exponent stores in hPrivateData->sfb_tb_e[sfb]*/ move16(); - } - } - - SWITCH( hPrivateData->igfInfo.bitRateIndex ) - { - case IGF_BITRATE_WB_9600: - case IGF_BITRATE_RF_WB_13200: - case IGF_BITRATE_WB_13200_CPE: - case IGF_BITRATE_WB_16400_CPE: - case IGF_BITRATE_RF_SWB_13200: - case IGF_BITRATE_SWB_9600: - case IGF_BITRATE_SWB_13200_CPE: - case IGF_BITRATE_SWB_16400: - case IGF_BITRATE_SWB_24400: - case IGF_BITRATE_SWB_24400_CPE: - case IGF_BITRATE_SWB_32000_CPE: - case IGF_BITRATE_SWB_32000: - case IGF_BITRATE_FB_16400: - case IGF_BITRATE_FB_24400: - case IGF_BITRATE_FB_24400_CPE: - case IGF_BITRATE_FB_32000_CPE: - case IGF_BITRATE_FB_32000: - hPrivateData->igfCurrWhiteningLevel[hGrid->nTiles - 1] = hPrivateData->igfCurrWhiteningLevel[hGrid->nTiles - 2]; move16(); - break; - default: - break; - } - } - ELSE - { - FOR( p = 0; p < hGrid->nTiles; p++ ) - { - hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; - move16(); - } - } - } - ELSE - { - /* reset filter */ - FOR( p = 0; p < IGF_MAX_TILES; p++ ) - { - hPrivateData->prevSFM_FIR[p] = L_deposit_l( 0 ); - hPrivateData->prevSFM_IIR[p] = 0; - move32(); - move16(); - } - } - - IF( element_mode > EVS_MONO ) - { - IF( EQ_16( SFM, -ONE_IN_Q13 /*1.0f 2Q13*/ ) ) /* reset */ - { - FOR( p = 0; p < hGrid->nTiles; p++ ) - { - set16_fx( hPrivateData->igfPastSFM_fx[p], -ONE_IN_Q13, IGF_PAST_SFM_LEN ); - hPrivateData->igfWhiteningHangoverCnt[p] = 2; - move16(); - } - } - - /* vibrato handling */ - FOR( p = 0; p < hGrid->nTiles; p = p + 2 ) - { - test(); - test(); - test(); - IF( ( hPrivateData->igfPrevWhiteningLevel[p] == IGF_WHITENING_OFF && hPrivateData->igfCurrWhiteningLevel[p] != IGF_WHITENING_OFF ) || - ( hPrivateData->igfPrevWhiteningLevel[p + 1] == IGF_WHITENING_OFF && hPrivateData->igfCurrWhiteningLevel[p + 1] != IGF_WHITENING_OFF ) ) - { - Word16 i; - Word16 pastSfm_a[4], pastSfm_b[4]; - Word16 pastSfmDiffSum_a, pastSfmDiffSum_b; - - FOR( i = 0; i < 4; i++ ) - { - pastSfm_a[i] = hPrivateData->igfPastSFM_fx[p][add( hPrivateData->igfPastSFM_pos, sub( 4, i ) ) % IGF_PAST_SFM_LEN]; - pastSfm_b[i] = hPrivateData->igfPastSFM_fx[p + 1][add( hPrivateData->igfPastSFM_pos, sub( 4, i ) ) % IGF_PAST_SFM_LEN]; move16(); move16(); - } - pastSfmDiffSum_a = pastSfmDiffSum_b = 0; - move16(); - move16(); - FOR( i = 0; i < 3; i++ ) - { - IF( NE_16( pastSfm_a[i + 1], -ONE_IN_Q13 ) ) - { - pastSfmDiffSum_a = add( pastSfmDiffSum_a, sub( pastSfm_a[i], pastSfm_a[i + 1] ) ); - pastSfmDiffSum_b = add( pastSfmDiffSum_b, sub( pastSfm_b[i], pastSfm_b[i + 1] ) ); - } - ELSE - { - break; - } - } - - test(); - test(); - test(); - test(); - /* if tonality oscillates between two tiles, turn whitening off in both */ - IF( ( ( pastSfmDiffSum_a > 0 && pastSfmDiffSum_b < 0 ) || - ( pastSfmDiffSum_a < 0 && pastSfmDiffSum_b > 0 ) ) && - ( GT_32( L_abs( L_sub( pastSfmDiffSum_a, pastSfmDiffSum_b ) ), ONE_IN_Q12 /* 0.5 in Q13 */ ) ) ) - { - hPrivateData->igfCurrWhiteningLevel[p] = hPrivateData->igfCurrWhiteningLevel[p + 1] = IGF_WHITENING_OFF; + hPrivateData->sfb_sb_e[sfb] = 2; + hPrivateData->sfb_tb_e[sfb] = 2; move16(); move16(); - } - } - } - /* hangover */ - FOR( p = 0; p < hGrid->nTiles; p++ ) - { - IF( NE_16( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfPrevWhiteningLevel[p] ) ) - { - hPrivateData->igfWhiteningHangoverCnt[p] = add( hPrivateData->igfWhiteningHangoverCnt[p], 1 ); - IF( EQ_16( hPrivateData->igfWhiteningHangoverCnt[p], 3 ) ) - { - hPrivateData->igfWhiteningHangoverCnt[p] = 0; - } - ELSE - { - hPrivateData->igfCurrWhiteningLevel[p] = hPrivateData->igfPrevWhiteningLevel[p]; - } - move16(); - move16(); - } - ELSE - { - hPrivateData->igfWhiteningHangoverCnt[p] = 0; - move16(); - } - } + diffSFM_fx = sub( hPrivateData->SFM_sb_fx[sfb], hPrivateData->SFM_tb_fx[sfb] ); /*Q13*/ - hPrivateData->igfPastSFM_pos = add( hPrivateData->igfPastSFM_pos, 1 ) % IGF_PAST_SFM_LEN; - move16(); - } + test(); + IF( diffSFM_fx > 0 && LT_16( hPrivateData->SFM_tb_fx[sfb], 819 /*0.1 Q13*/ ) ) /* check whether target SFB is more tonal than source SFB */ + { + Word16 currDampingFactor_fx, dampingFactor_fx, alpha_fx; + Word16 threshold_e, threshold_fx, alpha_e, currDampingFactor_e, dampingFactor_e; + /* calculate spectral tilt to detect sudden drops (or increases) in energy in the current SFB */ + x = 1; + mean_x_fx = mean_y_fx = 0; + mean_xy_fx = mean_x2_fx = 0; + mean_x_e = mean_y_e = 15; + mean_xy_e = mean_x2_e = 31; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + FOR( sb = swb_offset[sfb]; sb < swb_offset[sfb + 1]; sb++ ) + { + mean_x_fx = add( mean_x_fx, x ); /*Q0*/ + mean_x2_fx = L_add( mean_x2_fx, L_mult0( x, x ) ); /*Q0*/ - hPrivateData->wasTransient = isTransient; - move16(); + /*y = 20 * (Word16) log10f( max( 1e-018f, pPowerSpectrum[sb] ) );*/ + IF( LT_32( pPowerSpectrum_fx[sb], 1 ) ) + { + y = 20 * ( -18 ); + move16(); + } + ELSE + { + y = imult1616( 20, extract_l( L_shr( Mult_32_16( ( L_add( BASOP_Util_Log2( pPowerSpectrum_fx[sb] ), L_shl( pPowerSpectrum_e[sb], Q25 ) ) ), INV_Log2_10_Q15 ), 25 ) ) ); /*Q0*/ + } + mean_y_fx = add( mean_y_fx, y ); /*Q0*/ + mean_xy_fx = L_add( mean_xy_fx, L_mult0( y, x ) ); /*Q0*/ - return; -} -#endif -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/*-------------------------------------------------------------------* - * IGF_WriteWhiteningTile_fx() - * - * write whitening levels into bitstream - *-------------------------------------------------------------------*/ + x = add( x, 1 ); + } + mean_y_fx = BASOP_Util_Divide1616_Scale( mean_y_fx, width, &tmp_e ); /* resultant exp stores in mean_y_e*/ + mean_y_e = add( mean_y_e, sub( tmp_e, 15 ) ); + mean_x_fx = BASOP_Util_Divide1616_Scale( mean_x_fx, width, &tmp_e ); /* resultant exp stores in mean_x_e*/ + mean_x_e = add( mean_x_e, sub( tmp_e, 15 ) ); + mean_xy_fx = BASOP_Util_Divide3216_Scale( mean_xy_fx, width, &tmp_e ); /* resultant exp stores in mean_xy_e*/ + mean_xy_e = add( mean_xy_e, sub( tmp_e, 15 ) ); + mean_x2_fx = BASOP_Util_Divide3216_Scale( mean_x2_fx, width, &tmp_e ); /* resultant exp stores in mean_x2_e*/ + mean_x2_e = add( mean_x2_e, sub( tmp_e, 15 ) ); -/*! r: number of bits written */ -static Word16 IGF_WriteWhiteningTile_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *pBitOffset, /* i : ptr to bitOffset counter */ - Word16 whiteningLevel /* i : whitening levels to write, Q0 */ -) -{ - Word16 totBitCount; - Word16 startBitCount; + /*slope = ( mean_xy - mean_x * mean_y ) / ( mean_x2 - mean_x * mean_x );*/ + slope_fx = BASOP_Util_Divide3232_Scale( ( L_sub( mean_xy_fx, L_shl( mult( mean_x_fx, mean_y_fx ), sub( add( mean_x_e, mean_y_e ), mean_xy_e ) ) ) ), ( L_sub( mean_x2_fx, L_shl( mult( mean_x_fx, mean_x_fx ), sub( add( mean_x_e, mean_x_e ), mean_x2_e ) ) ) ), &slope_e ); + slope_e = add( slope_e, sub( mean_xy_e, mean_x2_e ) ); /*stores resultant exponent for slope_fx*/ - totBitCount = 0; - startBitCount = *pBitOffset; - move16(); - move16(); + /* determine whether strong tilt is due to a step in the spectrum (e.g. band limitation, no damping) + or a tonal component close the band border (apply damping) by calculating SFM for a shift of 1/2 SFB width*/ + threshold_fx = BASOP_Util_Divide1616_Scale( 60, width, &threshold_e ); /*stores resultant exponent for threshold_fx*/ + test(); + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( slope_fx, add( slope_e, 16 ), negate( threshold_fx ), add( threshold_e, 16 ) ), -1 ) ) + { + Word16 shift = shr( width, 1 ); - IF( EQ_32( whiteningLevel, IGF_WHITENING_MID ) ) - { - IGF_write_bits( hBstr, pBitOffset, 0, 1 ); - } - ELSE - { - IGF_write_bits( hBstr, pBitOffset, 1, 1 ); - IF( whiteningLevel == IGF_WHITENING_OFF ) - { - IGF_write_bits( hBstr, pBitOffset, 0, 1 ); - } - ELSE - { - IGF_write_bits( hBstr, pBitOffset, 1, 1 ); - } - } - totBitCount = sub( *pBitOffset, startBitCount ); + // shiftedSFM = IGF_getSFM( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ) / IGF_getCrest( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ); + sfm = IGF_getSFM( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ), IVAS_CPE_MDCT ); - return totBitCount; -} -#endif -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/*-------------------------------------------------------------------* - * IGF_WriteWhiteningLevels_fx() - * - * writes the whitening levels - *-------------------------------------------------------------------*/ + crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ), IVAS_CPE_MDCT ); -/* o: Q0 | total number of bits written */ -static Word16 IGF_WriteWhiteningLevels_ivas_fx( - const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : instance handle of IGF encoder */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *pBitOffset, /* i : ptr to bitOffset counter */ - const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details, Q0 */ - const Word16 isIndepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame, Q0 */ -) -{ - IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - H_IGF_GRID hGrid; - Word16 p; - Word16 nTiles; - Word16 isSame; - Word32 tmp32; - Word16 totBitCount; - Word16 startBitCount; + shiftedSFM_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &shiftedSFM_e ); + } + ELSE IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( slope_fx, add( slope_e, 16 ), threshold_fx, add( threshold_e, 16 ) ), 1 ) && ( NE_16( sfb, sub( hGrid->sfbWrap[hGrid->nTiles], 1 ) ) ) ) + { + Word16 shift; + shift = shr( width, 1 ); + + // shiftedSFM = IGF_getSFM( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ) / IGF_getCrest( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ); + sfm = IGF_getSFM( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ), IVAS_CPE_MDCT ); + + crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ), IVAS_CPE_MDCT ); + + shiftedSFM_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &shiftedSFM_e ); + } + IF( shiftedSFM_fx ) + { + shiftedSFM_e = add( shiftedSFM_e, sub( sfm_exp, crest_exp ) ); /* stores resultant exponent for shiftedSFM_fx*/ + } + + // alpha = min( 320.f / (float) swb_offset[sfb + 1], 1.25f ); + temp = BASOP_Util_Divide1616_Scale( 320, swb_offset[sfb + 1], &alpha_e ); + alpha_fx = extract_l( L_min( temp, L_shl( 20480 /*1.25 Q14*/, sub( 1, alpha_e ) ) ) ); /* exponent is alpha_e*/ + temp = BASOP_Util_Divide1616_Scale( hPrivateData->SFM_tb_fx[sfb], hPrivateData->SFM_sb_fx[sfb], &tmp_e ); + tmp_e = add( tmp_e, sub( hPrivateData->sfb_tb_e[sfb], hPrivateData->sfb_sb_e[sfb] ) ); /* stores resultant exponent for temp */ + + // currDampingFactor = expf( alpha * logf( hPrivateData->SFM_tb[sfb] / hPrivateData->SFM_sb[sfb] ) ); + currDampingFactor_fx = round_fx( BASOP_util_Pow2( Mpy_32_16_1( L_add( BASOP_Util_Log2( temp ), L_shl( add( 16, tmp_e ), 25 ) ), alpha_fx ), add( alpha_e, 6 ), &currDampingFactor_e ) ); /*exp is currDampingFactor_e*/ + + IF( GT_32( shiftedSFM_fx, L_shl( 1311 /*0.04f Q15*/, negate( shiftedSFM_e ) ) ) ) + { + currDampingFactor_fx = 32767; /*1.f Q15*/ + currDampingFactor_e = 0; + move16(); + move16(); + } + test(); + test(); + IF( last_core_acelp || hPrivateData->wasTransient || EQ_32( hPrivateData->prevDampingFactor_IIR_fx[sfb], L_shl( -1, sub( 15, hPrivateData->prevDampingFactor_IIR_e[sfb] ) ) ) ) + { + tmp = BASOP_Util_Cmp_Mant32Exp( currDampingFactor_fx, currDampingFactor_e, 3277, 0 ); + IF( tmp >= 0 ) + { + hPrivateData->prevDampingFactor_IIR_fx[sfb] = currDampingFactor_fx; + hPrivateData->prevDampingFactor_IIR_e[sfb] = currDampingFactor_e; + } + ELSE + { + hPrivateData->prevDampingFactor_IIR_fx[sfb] = 3277; /* 0.1 in Q15 */ + hPrivateData->prevDampingFactor_IIR_e[sfb] = 0; + } + + move16(); + move16(); + } + + { + Word32 tonalToNoise; + Word16 adap; + Word16 adap_e; /*stores exp for adap*/ + Word16 tonalToNoise_e; /*stores exponent for tonalToNoise*/ + tonalToNoise_e = 9; /*stores exponent for tonalToNoise*/ + move16(); + adap = BASOP_Util_Divide1616_Scale( width, 30, &adap_e ); + tonalToNoise = IGF_getTNR_ivas_fx( pPowerSpectrum_fx, swb_offset[sfb], swb_offset[sfb + 1], adap, pPowerSpectrum_e, adap_e ); /*Q22*/ + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( tonalToNoise, tonalToNoise_e, L_add( L_shl( 10, sub( 15, adap_e ) ), adap ), add( 16, adap_e ) ), -1 ) ) + { + // currDampingFactor += 0.1f * ( ( 10 + adap ) - tonalToNoise ); + Word32 temp2 = BASOP_Util_Add_Mant32Exp( L_add( L_shl( 10, sub( 15, adap_e ) ) /*exp:adap_e*/, adap ), add( adap_e, 16 ), L_negate( tonalToNoise ), tonalToNoise_e, &tmp_e ); /* resultant exp is tmp_e*/ + currDampingFactor_e = BASOP_Util_Add_MantExp( currDampingFactor_fx, currDampingFactor_e, extract_l( Mult_32_16( temp2, 3277 /*0.1f Q15*/ ) ), tmp_e, &currDampingFactor_fx ); /*stores resultant exp for currDampingFactor_fx*/ + } + } + + dampingFactor_e = BASOP_Util_Add_MantExp( currDampingFactor_fx, currDampingFactor_e, hPrivateData->prevDampingFactor_IIR_fx[sfb], hPrivateData->prevDampingFactor_IIR_e[sfb], &dampingFactor_fx ); + dampingFactor_fx = shr( dampingFactor_fx, 1 ); /* resultant exponent is dampingFactor_e*/ + IF( NE_16( BASOP_Util_Cmp_Mant32Exp( dampingFactor_fx, add( dampingFactor_e, 16 ), shr( hPrivateData->prevDampingFactor_IIR_fx[sfb], 1 ), add( hPrivateData->prevDampingFactor_IIR_e[sfb], 16 ) ), -1 ) ) + { + // do nothing + } + ELSE + { + dampingFactor_fx = shr( hPrivateData->prevDampingFactor_IIR_fx[sfb], 1 ); /* resultant exponent is hPrivateData->prevDampingFactor_IIR_e[sfb]*/ + dampingFactor_e = hPrivateData->prevDampingFactor_IIR_e[sfb]; + move16(); + } + IF( dampingFactor_e < 0 ) + { + dampingFactor_fx = shl( dampingFactor_fx, dampingFactor_e ); + dampingFactor_e = 0; + move16(); + } + gain_fx = Mult_32_16( gain_fx, shl_sat( extract_l( L_min( L_add( dampingFactor_fx, Mult_32_16( L_shl( hPrivateData->dampingFactorSmoothing[sfb], sub( 15, dampingFactor_e ) ) /*Q:15-dampingFactor_e*/, 3277 /*0.1f Q15*/ ) /*Q:15-dampingFactor_e*/ ), shl_sat( 1, sub( 15, dampingFactor_e ) ) ) ), dampingFactor_e ) /*Q15*/ ); - totBitCount = 0; - move16(); - isSame = 1; - move16(); - startBitCount = *pBitOffset; - move16(); - hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - nTiles = hGrid->nTiles; - move16(); + hPrivateData->prevDampingFactor_IIR_fx[sfb] = dampingFactor_fx; + hPrivateData->prevDampingFactor_IIR_e[sfb] = dampingFactor_e; + move16(); + move16(); + if ( hPrivateData->dampingFactorSmoothing[sfb] > 0 ) + { + hPrivateData->dampingFactorSmoothing[sfb] = sub( hPrivateData->dampingFactorSmoothing[sfb], 1 ); + move16(); + } + } + ELSE + { + hPrivateData->prevDampingFactor_IIR_fx[sfb] = -( 1 << 15 ); /* resultant exp which is 0 stores in hPrivateData->prevDampingFactor_IIR_e[sfb]*/ + hPrivateData->prevDampingFactor_IIR_e[sfb] = 0; + hPrivateData->dampingFactorSmoothing[sfb] = 1; + move16(); + move16(); + move16(); + } - IF( isIndepFlag ) - { - isSame = 0; - move16(); - } - ELSE - { - p = 0; - move16(); - tmp32 = 0; - move32(); - test(); - WHILE( ( LT_16( p, nTiles ) ) && ( tmp32 == 0 ) ) - { - test(); - tmp32 = L_sub( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfPrevWhiteningLevel[p] ); - if ( tmp32 != 0 ) - { - isSame = 0; - move16(); + hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = tmp_tb_fx; + hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = hPrivateData->SFM_tb_fx[sfb]; + hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = tmp_sb_fx; + hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = hPrivateData->SFM_sb_fx[sfb]; + hPrivateData->prevSFB_FIR_TB_e[sfb] = hPrivateData->sfb_tb_e[sfb]; + hPrivateData->prevSFB_IIR_TB_e[sfb] = hPrivateData->sfb_tb_e[sfb]; + hPrivateData->prevSFB_FIR_SB_e[sfb] = hPrivateData->sfb_sb_e[sfb]; + hPrivateData->prevSFB_IIR_SB_e[sfb] = hPrivateData->sfb_sb_e[sfb]; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + } + ELSE + { + hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = 0; + hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = 0; + hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = 0; + hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = 0; + hPrivateData->prevSFB_FIR_TB_e[sfb] = 0; + hPrivateData->prevSFB_IIR_TB_e[sfb] = 0; + hPrivateData->prevSFB_FIR_SB_e[sfb] = 0; + hPrivateData->prevSFB_IIR_SB_e[sfb] = 0; + + hPrivateData->dampingFactorSmoothing[sfb] = 2; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + } } - p++; - } - } - IF( isSame ) - { - IGF_write_bits( hBstr, pBitOffset, 1, 1 ); - } - ELSE - { - IF( !isIndepFlag ) - { - IGF_write_bits( hBstr, pBitOffset, 0, 1 ); - } - IGF_WriteWhiteningTile_ivas_fx( hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[0] ); - p = 1; - move16(); - tmp32 = 0; - move32(); - test(); - IF( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) - { - isSame = 1; - move16(); - } - ELSE - { - if ( LT_16( p, nTiles ) ) + ELSE { - isSame = 1; + tmp_e = pMDCTSpectrum_e; + sfbEnergyR_fx = add_sat( EPSILON_FX, BASOP_Util_Divide3216_Scale( sum2_32_fx( pMDCTSpectrum_fx + swb_offset[sfb], width, &tmp_e ) /*exp: tmp_e*/, width, &sfbEnergyR_e ) ); + sfbEnergyR_e = add( sfbEnergyR_e, add( tmp_e, -15 ) ); /* stores resultant exponent for sfbEnergyR_fx*/ + gain_fx = sfbEnergyR_fx; /*resultant exponent stored in gain_e=sfbEnergyR_e*/ + move32(); + gain_e = add( sfbEnergyR_e, 16 ); /* because gain_fx is word32;only after adding 16 q of gain_fx is 15-sfbEnergyR_e*/ + + hPrivateData->prevSFM_FIR_SFB_TB_fx[sfb] = 0; + hPrivateData->prevSFM_IIR_SFB_TB_fx[sfb] = 0; + hPrivateData->prevSFM_FIR_SFB_SB_fx[sfb] = 0; + hPrivateData->prevSFM_IIR_SFB_SB_fx[sfb] = 0; + hPrivateData->prevSFB_FIR_TB_e[sfb] = 0; + hPrivateData->prevSFB_IIR_TB_e[sfb] = 0; + hPrivateData->prevSFB_FIR_SB_e[sfb] = 0; + hPrivateData->prevSFB_IIR_SB_e[sfb] = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); move16(); } + /*gain=0.5f+log2f(gain)*2+16 becuase 2.885390081777927f=2*1/loge(2) so 2*1/loge(2)*loge(x) can be written as 2*log2(x)*/ + gain_fx = L_add( ONE_IN_Q22, L_add( L_add( L_shr( BASOP_Util_Log2( gain_fx ), 1 ), L_shl( gain_e, Q24 ) ), L_shl( 16, Q23 ) ) ); /*Q23*/ test(); - WHILE( ( LT_16( p, nTiles ) ) && ( tmp32 == 0 ) ) + test(); + if ( !isTransient && ( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) ) { - test(); - tmp32 = L_sub( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfCurrWhiteningLevel[p - 1] ); - if ( tmp32 != 0 ) - { - isSame = 0; - move16(); - } - p++; + gain_fx = L_add( gain_fx, ONE_IN_Q21 ); /* better preservation of original HF band energy */ } - } - test(); - IF( !isSame ) - { - IGF_write_bits( hBstr, pBitOffset, 1, 1 ); - FOR( p = 1; p < nTiles; p++ ) + test(); + test(); + if ( !isTransient && ( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_64000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_64000_CPE ) ) ) { - IGF_WriteWhiteningTile_ivas_fx( hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[p] ); + gain_fx = L_add( gain_fx, ONE_IN_Q20 ); } - } - ELSE IF( NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) && NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) - { - IGF_write_bits( hBstr, pBitOffset, 0, 1 ); + gain_fx = L_min( gain_fx, 91 << Q23 ); /* 13+15+63, see arithcode encode residual */ + gain_fx = L_max( gain_fx, 0 ); + gain_e = 8; /* stores exponent for gain_fx*/ + move16(); + hPrivateData->igfScfQuantized[sfb] = (Word16) ( L_shr( gain_fx, 23 ) ); /*Q0*/ + move16(); } } - totBitCount = sub( *pBitOffset, startBitCount ); - - return totBitCount; -} -#endif -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/*-------------------------------------------------------------------* - * IGF_WriteFlatteningTrigger_fx() - * - * write flattening trigger - *-------------------------------------------------------------------*/ - -/*! r: number of bits written */ -static Word16 IGF_WriteFlatteningTrigger_ivas_fx( - const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : instance handle of IGF Encoder */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *pBitOffset /* i : ptr to bitOffset counter */ -) -{ - Word16 flatteningTrigger; - Word16 totBitCount; - Word16 startBitCount; - totBitCount = 0; - startBitCount = *pBitOffset; - flatteningTrigger = hInstance->flatteningTrigger; - move16(); - move16(); - move16(); - - IGF_write_bits( hBstr, pBitOffset, flatteningTrigger, 1 ); - totBitCount = sub( *pBitOffset, startBitCount ); - - return totBitCount; + return; } -#endif -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/*-------------------------------------------------------------------* - * IGFEncWriteBitstream() - * - * IGF bitstream writer - *-------------------------------------------------------------------*/ - -/*! r: number of bits written per frame */ -Word16 IGFEncWriteBitstream_ivas_fx( - const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *pBitOffset, /* i : ptr to bitOffset counter */ - const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 isIndepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ -) -{ - Word16 igfAllZero; - Word16 startBitCount; - - startBitCount = *pBitOffset; - move16(); - hIGFEnc->infoTotalBitsPerFrameWritten = 0; - move16(); - - if ( isIndepFlag ) - { - hIGFEnc->infoTotalBitsWritten = 0; - move16(); - } - - - IGF_WriteEnvelope_ivas( hIGFEnc, hBstr, pBitOffset, igfGridIdx, isIndepFlag, &igfAllZero ); - - IGF_WriteWhiteningLevels_ivas_fx( hIGFEnc, hBstr, pBitOffset, igfGridIdx, isIndepFlag ); - - IGF_WriteFlatteningTrigger_ivas_fx( hIGFEnc, hBstr, pBitOffset ); - hIGFEnc->infoTotalBitsPerFrameWritten = sub( *pBitOffset, startBitCount ); - hIGFEnc->infoTotalBitsWritten = add( hIGFEnc->infoTotalBitsWritten, hIGFEnc->infoTotalBitsPerFrameWritten ); - move16(); - move16(); - - return hIGFEnc->infoTotalBitsPerFrameWritten; -} -#endif /*-------------------------------------------------------------------* * IGFEncSetMode() @@ -5256,11 +3148,7 @@ Word16 IGFEncWriteBitstream_ivas_fx( * sets the IGF mode according to given bitrate *-------------------------------------------------------------------*/ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS void IGFEncSetMode_fx( -#else -void IGFEncSetMode_ivas_fx( -#endif const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */ const Word32 total_brate, /* i : encoder total bitrate */ const Word16 bwidth, /* i : encoder audio bandwidth */ @@ -5277,16 +3165,6 @@ void IGFEncSetMode_ivas_fx( set16_fx( hPrivateData->igfScfQuantized, 0, IGF_MAX_SFB ); set16_fx( hPrivateData->igfCurrWhiteningLevel, 0, IGF_MAX_TILES ); set16_fx( hPrivateData->igfPrevWhiteningLevel, 0, IGF_MAX_TILES ); -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS - set16_fx( hPrivateData->igfWhiteningHangoverCnt, 0, IGF_MAX_TILES ); - FOR( i = 0; i < IGF_MAX_TILES; i++ ) - { - set16_fx( hPrivateData->igfPastSFM_fx[i], -( ONE_IN_Q13 ), IGF_PAST_SFM_LEN ); - } - - hPrivateData->igfPastSFM_pos = 0; - move16(); -#endif FOR( i = 0; i < IGF_BITBUFSIZE / 8; i++ ) { @@ -5297,7 +3175,7 @@ void IGFEncSetMode_ivas_fx( move16(); set32_fx( hPrivateData->prevSFM_FIR, 0, IGF_MAX_TILES ); set16_fx( hPrivateData->prevSFM_IIR, 0, IGF_MAX_TILES ); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + /* IVAS specific settings */ set16_fx( hPrivateData->igfWhiteningHangoverCnt, 0, IGF_MAX_TILES ); FOR( i = 0; i < IGF_MAX_TILES; i++ ) @@ -5307,7 +3185,6 @@ void IGFEncSetMode_ivas_fx( hPrivateData->igfPastSFM_pos = 0; move16(); -#endif set16_fx( hPrivateData->dampingFactorSmoothing, 2, IGF_MAX_SFB ); set16_fx( hPrivateData->prevSFM_FIR_SFB_SB_fx, 0, IGF_MAX_SFB ); set16_fx( hPrivateData->prevSFB_FIR_TB_e, 15, IGF_MAX_SFB ); @@ -5325,11 +3202,7 @@ void IGFEncSetMode_ivas_fx( set16_fx( hPrivateData->SFM_sb_fx, 0, IGF_MAX_SFB ); set16_fx( hPrivateData->SFM_tb_fx, 0, IGF_MAX_SFB ); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IF( IGFCommonFuncsIGFConfiguration( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) != 0 ) -#else - IF( IGFCommonFuncsIGFConfiguration_ivas_fx( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) != 0 ) -#endif { IGFSCFEncoderOpen_fx( &hPrivateData->hIGFSCFArithEnc, &hPrivateData->igfInfo, total_brate, bwidth, element_mode, rf_mode ); @@ -5405,7 +3278,6 @@ void IGFEncResetTCX10BitCounter_fx( * apply the IGF encoder, main encoder interface *-------------------------------------------------------------------*/ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS void IGFEncApplyMono_fx( Encoder_State *st, /* i : Encoder state */ Word16 powerSpectrum_len, /* i : length of pPowerSpectrum_fx buffer */ @@ -5419,21 +3291,6 @@ void IGFEncApplyMono_fx( const Word16 sp_aud_decision0, /* i : first stage switching decision */ const Word16 vad_hover_flag /* i : VAD hangover flag */ ) -#else -void IGFEncApplyMono_ivas_fx( - Encoder_State *st, /* i : Encoder state */ - Word16 powerSpectrum_len, /* i : length of pPowerSpectrum_fx buffer */ - const Word16 igfGridIdx, /* i : IGF grid index */ - Word32 *pMDCTSpectrum_fx, /* i/o: MDCT spectrum */ - Word16 e_mdct, /* i : exponent of pMDCTspectrum */ - Word32 *pPowerSpectrum_fx, /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 *e_ps, /* i : exponent of pPowerSpectrum */ - const Word16 isTCX20, /* i : flag indicating if the input is TCX20 or TCX10/2xTCX5 */ - const Word8 isTNSActive, /* i : flag indicating if the TNS is active */ - const Word16 sp_aud_decision0, /* i : first stage switching decision */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ -) -#endif { Word32 *pPowerSpectrumParameter_fx; Word16 *pPowerSpectrumParameter_exp; @@ -5475,7 +3332,6 @@ void IGFEncApplyMono_ivas_fx( calculate_hangover_attenuation_gain_fx( st, &att_fx, vad_hover_flag ); } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IF( EQ_16( st->element_mode, EVS_MONO ) ) { IGF_CalculateEnvelope( st->hIGFEnc, pMDCTSpectrum_fx, e_mdct, pPowerSpectrumParameter_fx, *e_ps, igfGridIdx ); @@ -5484,9 +3340,6 @@ void IGFEncApplyMono_ivas_fx( { IGF_CalculateEnvelope_ivas_fx( st->hIGFEnc, pMDCTSpectrum_fx, e_mdct, pPowerSpectrumParameter_fx, pPowerSpectrumParameter_exp, igfGridIdx, st->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp, st->element_mode, att_fx ); } -#else - IGF_CalculateEnvelope_ivas_fx( st->hIGFEnc, pMDCTSpectrum_fx, e_mdct, pPowerSpectrumParameter_fx, pPowerSpectrumParameter_exp, igfGridIdx, st->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp, st->element_mode, att_fx ); -#endif IF( isTCX20 ) { @@ -5499,26 +3352,10 @@ void IGFEncApplyMono_ivas_fx( pPowerSpectrumParameter_exp = NULL; } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGF_Whitening( st->hIGFEnc, pPowerSpectrumParameter_fx, pPowerSpectrumParameter_exp, igfGridIdx, st->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp, isTNSActive, sp_aud_decision0, EQ_16( st->element_mode, IVAS_CPE_MDCT ) ? st->element_brate : st->total_brate, st->element_mode ); -#else - IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - IGF_Whitening_ivas_fx( st->hIGFEnc, pPowerSpectrumParameter_fx, pPowerSpectrumParameter_exp, igfGridIdx, st->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp, isTNSActive, sp_aud_decision0, st->element_brate, st->element_mode ); - } - ELSE - { - IGF_Whitening_ivas_fx( st->hIGFEnc, pPowerSpectrumParameter_fx, pPowerSpectrumParameter_exp, igfGridIdx, st->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp, isTNSActive, sp_aud_decision0, st->total_brate, st->element_mode ); - } -#endif -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS - IF( pPowerSpectrumParameter_fx ) - { -#else IF( pPowerSpectrumParameter_fx && GT_16( st->element_mode, EVS_MONO ) ) { -#endif FOR( Word16 i = 0; i < powerSpectrum_len; i++ ) { common_pPowerSpectrum_exp = s_max( common_pPowerSpectrum_exp, pPowerSpectrumParameter_exp[i] ); @@ -5531,18 +3368,13 @@ void IGFEncApplyMono_ivas_fx( } pPowerSpectrumParameter_fx = common_pPowerSpectrum_fx; } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF( EQ_16( st->element_mode, EVS_MONO ) ) { common_pPowerSpectrum_exp = *e_ps; } -#endif -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGF_ErodeSpectrum( st->hIGFEnc, pMDCTSpectrum_fx, pPowerSpectrumParameter_fx, common_pPowerSpectrum_exp, igfGridIdx, 0, st->element_mode ); -#else - IGF_ErodeSpectrum_ivas_fx( st->hIGFEnc, pMDCTSpectrum_fx, pPowerSpectrumParameter_fx, common_pPowerSpectrum_exp, igfGridIdx, 0 ); -#endif return; } @@ -5659,11 +3491,7 @@ void IGFEncApplyStereo_fx( exp_pPowerSpectrumParameter_fx[ch] = NULL; } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGF_Whitening( hIGFEnc[ch], pPowerSpectrumParameter_fx[ch], exp_pPowerSpectrumParameter_fx[ch], igfGridIdx, sts[ch]->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp, ( sts[0]->hTcxEnc->fUseTns[frameno] || sts[1]->hTcxEnc->fUseTns[frameno] ), sp_aud_decision0, element_brate, sts[ch]->element_mode ); -#else - IGF_Whitening_ivas_fx( hIGFEnc[ch], pPowerSpectrumParameter_fx[ch], exp_pPowerSpectrumParameter_fx[ch], igfGridIdx, sts[ch]->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp, ( sts[0]->hTcxEnc->fUseTns[frameno] || sts[1]->hTcxEnc->fUseTns[frameno] ), sp_aud_decision0, element_brate, sts[ch]->element_mode ); -#endif IF( pPowerSpectrumParameter_fx[ch] ) { @@ -5686,11 +3514,7 @@ void IGFEncApplyStereo_fx( } pPowerSpectrumParameter_fx[ch] = common_pPowerSpectrum_fx; } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGF_ErodeSpectrum( hIGFEnc[ch], sts[ch]->hTcxEnc->spectrum_fx[frameno], pPowerSpectrumParameter_fx[ch], common_pPowerSpectrum_exp, igfGridIdx, mct_on, sts[ch]->element_mode ); -#else - IGF_ErodeSpectrum_ivas_fx( hIGFEnc[ch], sts[ch]->hTcxEnc->spectrum_fx[frameno], pPowerSpectrumParameter_fx[ch], common_pPowerSpectrum_exp, igfGridIdx, mct_on ); -#endif } return; @@ -5752,19 +3576,11 @@ ivas_error IGF_Reconfig( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n" ) ); } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFEncSetMode_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); -#else - IGFEncSetMode_ivas_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); -#endif } ELSE IF( igf && reset ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFEncSetMode_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); -#else - IGFEncSetMode_ivas_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); -#endif } ELSE IF( !igf && *hIGFEnc != NULL ) { diff --git a/lib_enc/igf_scf_enc_fx.c b/lib_enc/igf_scf_enc_fx.c index 7d6c7cf7d448d19d557d3e15674aaecb4cfa494e..185c97a317ab6dbb80f64faae5185317433de17d 100644 --- a/lib_enc/igf_scf_enc_fx.c +++ b/lib_enc/igf_scf_enc_fx.c @@ -1,4 +1,3 @@ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS /****************************************************************************************************** (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, @@ -31,7 +30,6 @@ *******************************************************************************************************/ -#endif /*==================================================================================== EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -119,28 +117,21 @@ static void arith_encode_bits( IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ Word16 *ptr, /* i/o: pointer to expanded bit buffer, one bit in each Word16 */ Word16 x, /* i : value to encode */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - Word16 nBits, /* i : number of bits to encode */ - Word16 element_mode /* i : IVAS element mode type */ -#else - Word16 nBits /* i : number of bits to encode */ -#endif + Word16 nBits, /* i : number of bits to encode */ + Word16 element_mode /* i : IVAS element mode type */ ) { Word16 i; Word16 bit; -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IF( EQ_16( element_mode, EVS_MONO ) ) { -#endif FOR( i = nBits - 1; i >= 0; --i ) /* nBits > 0 */ { bit = s_and( shr( x, i ), 1 ); hPrivateData->ptrBitIndex = ari_encode_14bits_sign_fx( ptr, hPrivateData->ptrBitIndex, MAX16B /* disable the bit count limitation */, &hPrivateData->acState_fx, bit ); move16(); } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS } ELSE { @@ -151,7 +142,6 @@ static void arith_encode_bits( move16(); } } -#endif return; } @@ -162,12 +152,8 @@ static void arith_encode_residual( Word16 *ptr, /* i/o: pointer to expanded bit buffer, one bit in each Word16 */ Word16 x, /* i : residual value to encode */ const UWord16 *cumulativeFrequencyTable, /* i : cumulative frequency table to be used */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - Word16 tableOffset, /* i : offset used to align the table */ - Word16 element_mode /* i : IVAS element mode type */ -#else - Word16 tableOffset /* i : offset used to align the table */ -#endif + Word16 tableOffset, /* i : offset used to align the table */ + Word16 element_mode /* i : IVAS element mode type */ ) { Word16 extra; @@ -181,7 +167,6 @@ static void arith_encode_residual( { x = sub( x, IGF_MIN_ENC_SEPARATE - 1 ); /* (x - IGF_MIN_ENC_SEPARATE) + 1 */ /* encode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IF( EQ_16( element_mode, EVS_MONO ) ) { hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, @@ -198,14 +183,8 @@ static void arith_encode_residual( x, cumulativeFrequencyTable ); } -#else - hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState_fx, - x, - cumulativeFrequencyTable ); -#endif move16(); + return; } @@ -213,7 +192,6 @@ static void arith_encode_residual( { /* send escape code 0 to indicate x <= IGF_MIN_ENC_SEPARATE - 1 */ extra = sub( IGF_MIN_ENC_SEPARATE - 1, x ); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IF( EQ_16( element_mode, EVS_MONO ) ) { hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, @@ -230,20 +208,14 @@ static void arith_encode_residual( 0, cumulativeFrequencyTable ); } -#else - hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState_fx, - 0, - cumulativeFrequencyTable ); -#endif + move16(); } ELSE /* x > IGF_MAX_ENC_SEPARATE */ { /* send escape code (IGF_SYMBOLS_IN_TABLE - 1) to indicate x >= IGF_MAX_ENC_SEPARATE + 1 */ extra = sub( x, IGF_MAX_ENC_SEPARATE + 1 ); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF( EQ_16( element_mode, EVS_MONO ) ) { hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, @@ -260,13 +232,6 @@ static void arith_encode_residual( IGF_SYMBOLS_IN_TABLE - 1, cumulativeFrequencyTable ); } -#else - hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState_fx, - IGF_SYMBOLS_IN_TABLE - 1, - cumulativeFrequencyTable ); -#endif move16(); } @@ -275,45 +240,28 @@ static void arith_encode_residual( IF( extra_tmp < 0 ) { /* encode extra with 4 bits if extra < 15 */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS arith_encode_bits( hPrivateData, ptr, extra, 4, element_mode ); -#else - arith_encode_bits( hPrivateData, ptr, extra, 4 ); -#endif } ELSE /* extra >= 15 */ { /* send escape code 15 to indicate extra >= 15 */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS arith_encode_bits( hPrivateData, ptr, 15, 4, element_mode ); -#else - arith_encode_bits( hPrivateData, ptr, 15, 4 ); -#endif extra_safety = sub( extra_tmp, 63 ); IF( extra_safety < 0 ) { /* encode additional extra with 6 bits */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS arith_encode_bits( hPrivateData, ptr, extra_tmp, 6, element_mode ); -#else - arith_encode_bits( hPrivateData, ptr, extra_tmp, 6 ); -#endif } ELSE { /* extra_tmp >= 63 */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IF( GT_16( element_mode, EVS_MONO ) ) { arith_encode_bits( hPrivateData, ptr, 63, 6, element_mode ); } -#endif + /* encode safety extra with 7 bits */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS arith_encode_bits( hPrivateData, ptr, extra_safety, 7, element_mode ); -#else - arith_encode_bits( hPrivateData, ptr, extra_safety, 7 ); -#endif } } @@ -321,118 +269,6 @@ static void arith_encode_residual( } -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -static void encode_sfe_vector( - IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ - Word16 *ptr, /* i : pointer to expanded bit buffer, one bit in each short */ - const Word16 t, /* i : frame counter reset to 0 at each independent frame */ - Word16 *prev_x, /* i : previous vector */ - Word16 *x, /* i : current vector to encode */ - const Word16 length /* i : number of elements to encode */ -) -{ - /* - f - ^ - | d a x - | c b - | e --> t - */ - Word16 f; - Word16 pred; - Word16 res; - Word16 ctx; - Word16 ctx_f; - Word16 ctx_t; - Word16 prev_offset; - Word32 index1; - Word32 index2; - - FOR( f = 0; f < length; ++f ) - { - IF( t == 0 ) - { - IF( f == 0 ) - { - /* (t == 0) && (f == 0) */ - /* encode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ - hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState_fx, - shr( x[f], 2 ), - (const UWord16 *) hPrivateData->cf_se00 ); - move16(); - arith_encode_bits( hPrivateData, ptr, s_and( x[f], 3 ), 2 ); /* LSBs as 2 bit raw */ - } - ELSE IF( EQ_16( f, 1 ) ) - { - /* (t == 0) && (f == 1) */ - res = sub( x[f], x[0] ); /* pred = b */ - arith_encode_residual( hPrivateData, - ptr, - res, - hPrivateData->cf_se01, - hPrivateData->cf_off_se01 ); - } - ELSE - { - /* (t == 0) && (f >= 2) */ - prev_offset = sub( f, 1 ); - res = sub( x[f], x[prev_offset] ); - ctx = quant_ctx( sub( x[prev_offset], x[sub( prev_offset, 1 )] ) ); /* Q(b - e) */ - /* index1 is (IGF_SYMBOLS_IN_TABLE + 1) * (CTX_OFFSET + ctx) */ - index1 = L_mac0( ( IGF_SYMBOLS_IN_TABLE + 1 ) * IGF_CTX_OFFSET, ( IGF_SYMBOLS_IN_TABLE + 1 ), ctx ); - /* index2 is IGF_CTX_OFFSET + ctx */ - index2 = L_mac0( IGF_CTX_OFFSET, 1, ctx ); - arith_encode_residual( hPrivateData, - ptr, - res, - hPrivateData->cf_se02 + index1, - hPrivateData->cf_off_se02[index2] ); - } - } - ELSE - { - /* t == 1 */ - IF( f == 0 ) - { - /* (t == 1) && (f == 0) */ - res = sub( x[f], prev_x[f] ); - move16(); /* pred = a */ - arith_encode_residual( hPrivateData, - ptr, - res, - hPrivateData->cf_se10, - hPrivateData->cf_off_se10 ); - } - ELSE - { - /* (t == 1) && (f >= 1) */ - prev_offset = sub( f, 1 ); - pred = add( prev_x[f], x[prev_offset] ); - pred = sub( pred, prev_x[prev_offset] ); /* pred = a + b - c */ - res = sub( x[f], pred ); - ctx_f = quant_ctx( sub( prev_x[f], prev_x[prev_offset] ) ); /* Q(a - c) */ - ctx_t = quant_ctx( sub( x[prev_offset], prev_x[prev_offset] ) ); /* Q(b - c) */ - /* index1 is (IGF_SYMBOLS_IN_TABLE + 1) * IGF_CTX_COUNT * (IGF_CTX_OFFSET + ctx_t) - + (IGF_SYMBOLS_IN_TABLE + 1) * (IGF_CTX_OFFSET + ctx_f) */ - index1 = L_mac0( - ( ( IGF_SYMBOLS_IN_TABLE + 1 ) * IGF_CTX_COUNT + ( IGF_SYMBOLS_IN_TABLE + 1 ) ) * IGF_CTX_OFFSET, - ( IGF_SYMBOLS_IN_TABLE + 1 ) * IGF_CTX_COUNT, ctx_t ); - index1 = L_mac0( index1, ( IGF_SYMBOLS_IN_TABLE + 1 ), ctx_f ); - /* index2 is IGF_CTX_COUNT * (IGF_CTX_OFFSET + ctx_t) + (IGF_CTX_OFFSET + ctx_f) */ - index2 = L_mac0( ( IGF_CTX_COUNT + 1 ) * IGF_CTX_OFFSET, IGF_CTX_COUNT, ctx_t ); - index2 = L_mac0( index2, 1, ctx_f ); - arith_encode_residual( hPrivateData, - ptr, - res, - hPrivateData->cf_se11 + index1, - hPrivateData->cf_off_se11[index2] ); - } - } - } -} -#else /*---------------------------------------------------------------------* * encode_sfe_vector() * @@ -526,7 +362,7 @@ static void encode_sfe_vector( return; } -#endif + /**********************************************************************/ /** resets the internal encoder memory (context memory) @@ -556,10 +392,8 @@ Word16 IGFSCFEncoderEncode_fx( const Word16 bitCount, /* i : offset to the first bit in bitbuffer which should be readed by iisArithDecoderDecode function */ Word16 *sfe, /* i : ptr to an array which contain quantized scalefactor energies */ const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - const Word16 element_mode, /* i : IVAS element mode type */ -#endif - const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ + const Word16 element_mode, /* i : IVAS element mode type */ + const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ ) { Word16 ptr[IGF_BITBUFSIZE]; /* temporary expanded bit buffer, one bit in each Word16 */ @@ -571,7 +405,7 @@ Word16 IGFSCFEncoderEncode_fx( move16(); hPublicData->bitCount = bitCount; move16(); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + /* start AC encoding */ IF( EQ_16( element_mode, EVS_MONO ) ) { @@ -581,9 +415,6 @@ Word16 IGFSCFEncoderEncode_fx( { ari_start_encoding_14bits_ivas_fx( &hPublicData->acState ); } -#else - ari_start_encoding_14bits_fx( &hPublicData->acState_fx ); /* start AC encoding */ -#endif /* check if coder needs a reset and do it if necessary */ IF( indepFlag != 0 ) @@ -592,13 +423,8 @@ Word16 IGFSCFEncoderEncode_fx( IGFSCFEncoderReset_fx( hPublicData ); } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS encode_sfe_vector( hPublicData, ptr, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx], element_mode ); -#else - encode_sfe_vector( hPublicData, ptr, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx] ); -#endif -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS /* finish AC encoding */ IF( EQ_16( element_mode, EVS_MONO ) ) { @@ -608,11 +434,6 @@ Word16 IGFSCFEncoderEncode_fx( { hPublicData->ptrBitIndex = ari_done_encoding_14bits_ivas_fx( ptr, hPublicData->ptrBitIndex, &hPublicData->acState ); } -#else - hPublicData->ptrBitIndex = ari_done_encoding_14bits_fx( ptr, - hPublicData->ptrBitIndex, - &hPublicData->acState_fx ); -#endif hPublicData->bitCount = add( hPublicData->bitCount, hPublicData->ptrBitIndex ); move16(); move16(); diff --git a/lib_enc/ivas_decision_matrix_enc_fx.c b/lib_enc/ivas_decision_matrix_enc_fx.c index adb69a98889a2b36c231f1620c799985f3aec45f..4cb3aa296df0e6b6ba3d3e44f93aacca5053f1b3 100644 --- a/lib_enc/ivas_decision_matrix_enc_fx.c +++ b/lib_enc/ivas_decision_matrix_enc_fx.c @@ -36,9 +36,8 @@ #include "prot_fx.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" /* Function prototypes */ -#ifdef HQ_ALIGN_DUPLICATED_CODE #include "prot_fx_enc.h" -#endif + /*-----------------------------------------------------------------* * ivas_decision_matrix_enc() @@ -191,11 +190,7 @@ void ivas_decision_matrix_enc_fx( ELSE { /* select TCX core or HQ core using bits_frame_nominal to match the TCX configuration bitrate */ -#ifdef HQ_ALIGN_DUPLICATED_CODE st->core = mdct_classifier_fx( st, fft_buff, enerBuffer, enerBuffer_exp, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ) ); /* Q0 */ -#else - st->core = mdct_classifier_ivas_fx( st, fft_buff, enerBuffer, enerBuffer_exp, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ) ); /* Q0 */ -#endif move16(); } } diff --git a/lib_enc/ivas_mct_core_enc_fx.c b/lib_enc/ivas_mct_core_enc_fx.c index 176a3592555ad07f853d75874a134e99f6f489c5..5bc9c0682f0a96dc85708f384773f4b7a8558e62 100644 --- a/lib_enc/ivas_mct_core_enc_fx.c +++ b/lib_enc/ivas_mct_core_enc_fx.c @@ -673,11 +673,9 @@ void ivas_mct_core_enc_fx( { q_spectrum = sub( 31, st->hTcxEnc->spectrum_e[n] ); set16_fx( exp_powerSpec[ch], sub( Q31, q_powSpec[ch] ), N_MAX + L_MDCT_OVLP_MAX ); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + ProcessIGF_fx( st, L_FRAME48k, st->hTcxEnc->spectrum_fx[n], &q_spectrum, orig_spectrum_fx[ch][n], q_origSpec, &powerSpec_fx[ch][n * L_subframeTCX], &exp_powerSpec[ch][n * L_subframeTCX], st->core == TCX_20_CORE, n, sp_aud_decision0[ch], 0 ); -#else - ProcessIGF_ivas_fx( st, L_FRAME48k, st->hTcxEnc->spectrum_fx[n], &q_spectrum, orig_spectrum_fx[ch][n], q_origSpec, &powerSpec_fx[ch][n * L_subframeTCX], &exp_powerSpec[ch][n * L_subframeTCX], st->core == TCX_20_CORE, n, sp_aud_decision0[ch], 0 ); -#endif + st->hIGFEnc->spec_be_igf_e = sub( 31, q_origSpec ); st->hTcxEnc->spectrum_e[n] = sub( 31, q_spectrum ); move16(); diff --git a/lib_enc/ivas_mct_enc_mct_fx.c b/lib_enc/ivas_mct_enc_mct_fx.c index 254c4c2a87b1b08a47b3109c68caa818c32a842b..e150a1e4073fbfc8152022109f6c822e33d9fb27 100644 --- a/lib_enc/ivas_mct_enc_mct_fx.c +++ b/lib_enc/ivas_mct_enc_mct_fx.c @@ -1107,19 +1107,8 @@ void mctStereoIGF_enc_fx( q_spectrum = sub( 31, st->hTcxEnc->spectrum_e[n] ); set16_fx( exp_powerSpec[p_ch[ch]], sub( Q31, q_powerSpec[p_ch[ch]] ), L_FRAME48k ); -#ifdef FIX_BASOP_2472_IGF_SP_AUD_DEC_CHAN -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + ProcessIGF_fx( st, L_FRAME48k, st->hTcxEnc->spectrum_fx[n], &q_spectrum, orig_spectrum_fx[p_ch[ch]][n], q_origSpec, &powerSpec_fx[p_ch[ch]][n * L_subframeTCX], &exp_powerSpec[p_ch[ch]][n * L_subframeTCX], st->core == TCX_20_CORE, n, sp_aud_decision0[ch1], 0 ); -#else - ProcessIGF_ivas_fx( st, L_FRAME48k, st->hTcxEnc->spectrum_fx[n], &q_spectrum, orig_spectrum_fx[p_ch[ch]][n], q_origSpec, &powerSpec_fx[p_ch[ch]][n * L_subframeTCX], &exp_powerSpec[p_ch[ch]][n * L_subframeTCX], st->core == TCX_20_CORE, n, sp_aud_decision0[ch1], 0 ); -#endif -#else -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - ProcessIGF_fx( st, L_FRAME48k, st->hTcxEnc->spectrum_fx[n], &q_spectrum, orig_spectrum_fx[p_ch[ch]][n], q_origSpec, &powerSpec_fx[p_ch[ch]][n * L_subframeTCX], &exp_powerSpec[p_ch[ch]][n * L_subframeTCX], st->core == TCX_20_CORE, n, sp_aud_decision0[ch], 0 ); -#else - ProcessIGF_ivas_fx( st, L_FRAME48k, st->hTcxEnc->spectrum_fx[n], &q_spectrum, orig_spectrum_fx[p_ch[ch]][n], q_origSpec, &powerSpec_fx[p_ch[ch]][n * L_subframeTCX], &exp_powerSpec[p_ch[ch]][n * L_subframeTCX], st->core == TCX_20_CORE, n, sp_aud_decision0[ch], 0 ); -#endif -#endif st->hTcxEnc->spectrum_e[n] = sub( 31, q_spectrum ); move16(); @@ -1160,11 +1149,7 @@ void mctStereoIGF_enc_fx( q_spectrum = sub( 31, st->hTcxEnc->spectrum_e[n] ); set16_fx( exp_powerSpec[ch], sub( Q31, q_powerSpec[ch] ), L_FRAME48k ); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS ProcessIGF_fx( st, L_FRAME48k, st->hTcxEnc->spectrum_fx[n], &q_spectrum, orig_spectrum_fx[ch][n], q_origSpec, &powerSpec_fx[ch][n * L_subframeTCX], &exp_powerSpec[ch][n * L_subframeTCX], st->core == TCX_20_CORE, n, sp_aud_decision0[ch], 0 ); -#else - ProcessIGF_ivas_fx( st, L_FRAME48k, st->hTcxEnc->spectrum_fx[n], &q_spectrum, orig_spectrum_fx[ch][n], q_origSpec, &powerSpec_fx[ch][n * L_subframeTCX], &exp_powerSpec[ch][n * L_subframeTCX], st->core == TCX_20_CORE, n, sp_aud_decision0[ch], 0 ); -#endif st->hTcxEnc->spectrum_e[n] = sub( 31, q_spectrum ); move16(); } diff --git a/lib_enc/ivas_mdct_core_enc_fx.c b/lib_enc/ivas_mdct_core_enc_fx.c index 96777796c0520be831b702e5dccdd40fe42aae41..438c646dd094c0201e151e4d76b63973940b4ce9 100644 --- a/lib_enc/ivas_mdct_core_enc_fx.c +++ b/lib_enc/ivas_mdct_core_enc_fx.c @@ -1096,19 +1096,11 @@ void enc_prm_igf_mdct( st->hIGFEnc->infoTotalBitsPerFrameWritten = 0; move16(); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFEncWriteBitstream_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, ( st->last_core == ACELP_CORE ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1, st->element_mode ); -#else - IGFEncWriteBitstream_ivas_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, ( st->last_core == ACELP_CORE ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1 ); -#endif } ELSE { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFEncWriteConcatenatedBitstream_fx( st->hIGFEnc, hBstr ); -#else - IGFEncWriteConcatenatedBitstream_ivas_fx( st->hIGFEnc, hBstr ); -#endif } total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); diff --git a/lib_enc/ivas_qmetadata_enc_fx.c b/lib_enc/ivas_qmetadata_enc_fx.c index 5730d9b846bc6b1f69cd5bfdab4792c371c7f6a8..f466654409f3de0c4f8d4d5b250d29314be839cb 100644 --- a/lib_enc/ivas_qmetadata_enc_fx.c +++ b/lib_enc/ivas_qmetadata_enc_fx.c @@ -4663,28 +4663,15 @@ static Word16 encode_coherence_indexesDCT0_fx( move16(); i = 0; move16(); -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC /* verify that idx and idx1 can be represented on 63 bits as it has been designed through split outside this function */ assert( nbits < 63 ); assert( nbits1 < 63 ); -#endif FOR( i = 0; i < no_idx16 - 1; i++ ) { k = sub( k, 16 ); -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC hMetaData->ind_list[indice_coherence + i].value = u_extract_l( (UWord32) W_extract_l( W_shr( idx, k ) ) ); /* ( ( idx >> k ) & 65535 ); 16 bits */ -#else - hMetaData->ind_list[indice_coherence + i].value = ( ( idx >> k ) & 65535 ); /* 16 bits */ - move16(); -#endif } -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC hMetaData->ind_list[indice_coherence + i].value = u_extract_l( (UWord32) L_and( W_extract_l( idx ), L_sub( L_shl( 1, k ), 1 ) ) ); /* ( idx & ( ( 1 << k ) - 1 ) ); */ -#else - hMetaData->ind_list[indice_coherence + i].value = ( idx & ( ( 1 << k ) - 1 ) ); - move16(); -#endif - IF( nbits1 > 0 ) { @@ -4705,19 +4692,9 @@ static Word16 encode_coherence_indexesDCT0_fx( FOR( j = i + 1; j < no_idx16 + i; j++ ) { k = sub( k, 16 ); -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC hMetaData->ind_list[indice_coherence + j].value = u_extract_l( (UWord32) W_extract_l( W_shr( idx1, k ) ) ); /* ( ( idx1 >> k ) & 65535 ); 16 bits */ -#else - hMetaData->ind_list[indice_coherence + j].value = ( ( idx1 >> k ) & 65535 ); /* 16 bits */ - move16(); -#endif } -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC hMetaData->ind_list[indice_coherence + j].value = u_extract_l( (UWord32) L_and( W_extract_l( idx1 ), L_sub( L_shl( 1, k ), 1 ) ) ); /* ( idx1 & ( ( 1 << k ) - 1 ) ); */ -#else - hMetaData->ind_list[indice_coherence + j].value = ( idx1 & ( ( 1 << k ) - 1 ) ); - move16(); -#endif } return add( nbits, nbits1 ); @@ -4987,28 +4964,19 @@ static Word16 encode_spread_coherence_1sf_fx( no_idx16 = shr_r( add( nbits_fr, ONE_IN_Q3 ), 4 ); } -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC /* verify that idx and idx1 can be represented on 63 bits as it has been designed through split outside this function */ assert( nbits_fr < 63 ); assert( nbits_fr1 < 63 ); -#endif + /* write combined index */ k = nbits_fr; move16(); FOR( i = 0; i < no_idx16 - 1; i++ ) { k = sub( k, 16 ); -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC push_next_indice( hMasaMetaData, u_extract_l( (UWord32) W_extract_l( W_shr( idx, k ) ) ), 16 ); /* ( ( idx >> k ) & 65535 ); 16 bits */ -#else - push_next_indice( hMasaMetaData, ( ( idx >> k ) & 65535 ), 16 ); /* 16 bits */ -#endif } -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC push_next_indice( hMasaMetaData, u_extract_l( (UWord32) L_and( W_extract_l( idx ), L_sub( L_shl( 1, k ), 1 ) ) ), k ); /* ( idx & ( ( 1 << k ) - 1 ) ); */ -#else - push_next_indice( hMasaMetaData, ( idx & ( ( 1 << k ) - 1 ) ), k ); -#endif IF( nbits_fr1 > 0 ) { @@ -5030,17 +4998,9 @@ static Word16 encode_spread_coherence_1sf_fx( FOR( i = 0; i < no_idx16 - 1; i++ ) { k = sub( k, 16 ); -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC push_next_indice( hMasaMetaData, u_extract_l( (UWord32) W_extract_l( W_shr( idx1, k ) ) ), 16 ); /* ( ( idx1 >> k ) & 65535 ); 16 bits */ -#else - push_next_indice( hMasaMetaData, ( ( idx1 >> k ) & 65535 ), 16 ); /* 16 bits */ -#endif } -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC push_next_indice( hMasaMetaData, u_extract_l( (UWord32) L_and( W_extract_l( idx1 ), L_sub( L_shl( 1, k ), 1 ) ) ), k ); /* ( idx1 & ( ( 1 << k ) - 1 ) ); */ -#else - push_next_indice( hMasaMetaData, ( idx1 & ( ( 1 << k ) - 1 ) ), k ); -#endif } } ELSE @@ -5233,11 +5193,9 @@ static Word16 encode_surround_coherence_fx( no_idx16 = shr_r( add( nbits_fr, ONE_IN_Q3 ), 4 ); } -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC /* verify that idx and idx1 can be represented on 63 bits as it has been designed through split outside this function */ assert( nbits_fr < 63 ); assert( nbits_fr1 < 63 ); -#endif /* write combined index */ k = nbits_fr; @@ -5245,17 +5203,9 @@ static Word16 encode_surround_coherence_fx( FOR( i = 0; i < no_idx16 - 1; i++ ) { k = sub( k, 16 ); -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC push_next_indice( hMetaData, u_extract_l( (UWord32) W_extract_l( W_shr( idx, k ) ) ), 16 ); /* ( ( idx >> k ) & 65535 ); 16 bits */ -#else - push_next_indice( hMetaData, ( ( idx >> k ) & 65535 ), 16 ); /* 16 bits */ -#endif } -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC push_next_indice( hMetaData, u_extract_l( (UWord32) L_and( W_extract_l( idx ), L_sub( L_shl( 1, k ), 1 ) ) ), k ); /* ( idx & ( ( 1 << k ) - 1 ) ); */ -#else - push_next_indice( hMetaData, ( idx & ( ( 1 << k ) - 1 ) ), k ); -#endif IF( nbits_fr1 > 0 ) { @@ -5277,17 +5227,9 @@ static Word16 encode_surround_coherence_fx( FOR( i = 0; i < no_idx16 - 1; i++ ) { k = sub( k, 16 ); -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC push_next_indice( hMetaData, u_extract_l( (UWord32) W_extract_l( W_shr( idx1, k ) ) ), 16 ); /* ( ( idx1 >> k ) & 65535 ); 16 bits */ -#else - push_next_indice( hMetaData, ( ( idx1 >> k ) & 65535 ), 16 ); /* 16 bits */ -#endif } -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC push_next_indice( hMetaData, u_extract_l( (UWord32) L_and( W_extract_l( idx1 ), L_sub( L_shl( 1, k ), 1 ) ) ), k ); /* ( idx1 & ( ( 1 << k ) - 1 ) ); */ -#else - push_next_indice( hMetaData, ( idx1 & ( ( 1 << k ) - 1 ) ), k ); -#endif } } ELSE @@ -5482,11 +5424,9 @@ static Word16 encode_surround_coherence_hr_fx( no_idx16 = add( shr( nbits_fr, 4 ), 1 ); } -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC /* verify that idx and idx1 can be represented on 63 bits as it has been designed through split outside this function */ assert( nbits_fr < 63 ); assert( nbits_fr1 < 63 ); -#endif /* write combined index */ k = nbits_fr; @@ -5494,17 +5434,9 @@ static Word16 encode_surround_coherence_hr_fx( FOR( i = 0; i < no_idx16 - 1; i++ ) { k = sub( k, 16 ); -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC push_next_indice( hMetaData, u_extract_l( (UWord32) W_extract_l( W_shr( idx, k ) ) ), 16 ); /* ( ( idx >> k ) & 65535 ); 16 bits */ -#else - push_next_indice( hMetaData, ( ( idx >> k ) & 65535 ), 16 ); /* 16 bits */ -#endif } -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC push_next_indice( hMetaData, u_extract_l( (UWord32) L_and( W_extract_l( idx ), L_sub( L_shl( 1, k ), 1 ) ) ), k ); /* ( idx & ( ( 1 << k ) - 1 ) ); */ -#else - push_next_indice( hMetaData, ( idx & ( ( 1 << k ) - 1 ) ), k ); -#endif IF( nbits_fr1 > 0 ) { @@ -5524,17 +5456,9 @@ static Word16 encode_surround_coherence_hr_fx( FOR( i = 0; i < no_idx16 - 1; i++ ) { k = sub( k, 16 ); -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC push_next_indice( hMetaData, u_extract_l( (UWord32) W_extract_l( W_shr( idx1, k ) ) ), 16 ); /* ( ( idx1 >> k ) & 65535 ); 16 bits */ -#else - push_next_indice( hMetaData, ( ( idx1 >> k ) & 65535 ), 16 ); /* 16 bits */ -#endif } -#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC push_next_indice( hMetaData, u_extract_l( (UWord32) L_and( W_extract_l( idx1 ), L_sub( L_shl( 1, k ), 1 ) ) ), k ); /* ( idx1 & ( ( 1 << k ) - 1 ) ); */ -#else - push_next_indice( hMetaData, ( idx1 & ( ( 1 << k ) - 1 ) ), k ); -#endif } } ELSE diff --git a/lib_enc/mdct_classifier_fx.c b/lib_enc/mdct_classifier_fx.c index 8c1f697bf7e6f6fdec18abd4896652459dd843dd..07dc67883ae73443962c33e85bac7e41f4ecc4a9 100644 --- a/lib_enc/mdct_classifier_fx.c +++ b/lib_enc/mdct_classifier_fx.c @@ -80,435 +80,14 @@ static void dft_mag_square_fx( return; } -#ifndef HQ_ALIGN_DUPLICATED_CODE + /*-------------------------------------------------------------------* * mdct_classifier() * * MDCT signal classifier for HQ_CORE/TCX_20_CORE *-------------------------------------------------------------------*/ -/* o: MDCT A/B decision */ -Word16 mdct_classifier_fx( - const Word16 *fft_buff, /* i : re[0], re[1], ..., re[n/2], im[n/2 - 1], im[n/2 - 2], ..., im[1] */ - Encoder_State *st_fx, /* i/o: Encoder state variable */ - Word32 *cldfbBuf_Ener, // enerBuffer_exp - Word16 enerBuffer_exp, - const Word32 brate /* i : current brate, IVAS: nominal bitrate, EVS: st->total_brate */ -) -{ - Word16 c; - Word32 magSq[129], *pMagSq, nf, pe; - Word16 k; - Word16 np; - Word32 max_cand; - Word16 max_i; - Word32 p_energy_man, n_energy_man, man; - Word16 p_energy_exp, n_energy_exp, expo; - Word16 d_acc; - Word16 pos_last; - Word16 clas_sec; - Word16 clas_final; - Word16 condition1, condition2; - Word16 factor; - Word32 acc; - UWord16 lsb16; - UWord32 lsb32; - Word32 gain1, gain2, gain3, gain11, gain4; - Word32 peak_l, peak_h, avrg_l, avrg_h, peak_H1, avrg_H1, peak_H2, avrg_H2; - Word16 condition3, condition4; - Word32 gain1_tmp = 0, gain2_tmp = 0; - Word16 exp, exp1, exp2, exp3; - Word32 L_tmp, L_tmp1; - TCX_ENC_HANDLE hTcxEnc = st_fx->hTcxEnc; - - dft_mag_square_fx( fft_buff, magSq, 256 ); - - nf = L_add( magSq[0], 0 ); - pe = L_add( magSq[0], 0 ); - np = 0; - move16(); - max_cand = L_negate( 1 ); - max_i = 0; - move16(); - p_energy_man = L_deposit_l( 0 ); - n_energy_man = L_deposit_l( 0 ); - p_energy_exp = n_energy_exp = 32; - move16(); - move16(); - d_acc = 0; - move16(); - pos_last = -1; - move16(); - - pMagSq = magSq; - FOR( k = 0; k < 128; k++ ) - { - /* NB: a*f + b*(1 - f) needs two multiplies - * = (a - b)*f + b saves one multiply */ - IF( GT_32( *( ++pMagSq ), nf ) ) - { - factor = 31385; - move16(); /* 0.9578 in Q15 */ - } - ELSE - { - factor = 21207; - move16(); /* 0.6472 in Q15 */ - } - acc = L_sub( nf, *pMagSq ); - Mpy_32_16_ss( acc, factor, &acc, &lsb16 ); - nf = L_add( acc, *pMagSq ); - IF( GT_32( *pMagSq, pe ) ) - { - factor = 13840; - move16(); /* 0.42237 in Q15 */ - } - ELSE - { - factor = 26308; - move16(); /* 0.80285 in Q15 */ - } - acc = L_sub( pe, *pMagSq ); - Mpy_32_16_ss( acc, factor, &acc, &lsb16 ); - pe = L_add( acc, *pMagSq ); - Mpy_32_16_ss( pe, 20972, &acc, &lsb16 ); /* 0.64 in Q15 */ - IF( GT_32( *pMagSq, acc ) ) - { - IF( GT_32( *pMagSq, max_cand ) ) - { - max_cand = L_add( *pMagSq, 0 ); - max_i = add( 2, k ); - } - } - ELSE - { - IF( max_i > 0 ) - { - IF( ( np > 0 ) ) - { - d_acc = sub( add( d_acc, max_i ), pos_last ); - } - np = add( np, 1 ); - pos_last = max_i; - move16(); - } - - max_cand = L_negate( 1 ); - max_i = 0; - move16(); - } - - IF( pe != 0 ) - { - expo = norm_l( pe ); - man = L_shl( pe, expo ); // expo - Mpy_32_32_ss( man, man, &man, &lsb32 ); /* pe square */ - expo = shl( expo, 1 ); /* Multiply by 2 due to squaring. */ - floating_point_add( &p_energy_man, &p_energy_exp, man, expo ); - } - IF( nf != 0 ) - { - expo = norm_l( nf ); - man = L_shl( nf, expo ); - Mpy_32_32_ss( man, man, &man, &lsb32 ); /* nf square */ - expo = shl( expo, 1 ); /* Multiply by 2 due to squaring. */ - floating_point_add( &n_energy_man, &n_energy_exp, man, expo ); - } - } - - gain1 = L_deposit_l( 0 ); - gain2 = L_deposit_l( 0 ); - gain3 = L_deposit_l( 0 ); - - FOR( k = 0; k < 8; k++ ) - { - gain1 = L_add( gain1, L_shr( cldfbBuf_Ener[k], 3 ) ); - gain2 = L_add( gain2, L_shr( cldfbBuf_Ener[k + 8], 3 ) ); - gain3 = L_add( gain3, L_shr( cldfbBuf_Ener[k + 16], 3 ) ); - } - - /* gain11 = 8*(gain1 - cldfbBuf_Ener[0]/8)/7; */ - acc = L_shr( cldfbBuf_Ener[0], 3 ); - acc = L_sub( gain1, acc ); - acc = Mult_32_16( acc, 4681 /*(1/7).Q15*/ ); - gain11 = L_shl( acc, 3 ); - gain4 = L_deposit_l( 0 ); - FOR( k = 0; k < 12; k++ ) - { - gain4 = L_add( gain4, Mult_32_16( cldfbBuf_Ener[k + 12], 2731 /*(1/12).Q15*/ ) ); - } - - - peak_H1 = L_add( cldfbBuf_Ener[25], 0 ); - Mpy_32_16_ss( cldfbBuf_Ener[25], 6554 /*0.4.Q15*/, &avrg_H1, &lsb16 ); - FOR( k = 1; k < 5; k++ ) - { - IF( GT_32( cldfbBuf_Ener[k + 25], peak_H1 ) ) - { - peak_H1 = L_add( cldfbBuf_Ener[k + 25], 0 ); - } - avrg_H1 = L_add( avrg_H1, Mult_32_16( cldfbBuf_Ener[k + 25], 6554 /*0.4.Q15*/ ) ); - } - - peak_H2 = L_add( cldfbBuf_Ener[20], 0 ); - Mpy_32_16_ss( cldfbBuf_Ener[20], 6554 /*0.4.Q15*/, &avrg_H2, &lsb16 ); - FOR( k = 1; k < 5; k++ ) - { - IF( GT_32( cldfbBuf_Ener[k + 20], peak_H2 ) ) - { - peak_H2 = L_add( cldfbBuf_Ener[k + 20], 0 ); - } - avrg_H2 = L_add( avrg_H2, Mult_32_16( cldfbBuf_Ener[k + 20], 6554 /*0.4.Q15*/ ) ); - } - // End - peak_l = L_deposit_l( 0 ); - avrg_l = L_deposit_l( 0 ); - peak_h = L_deposit_l( 0 ); - avrg_h = L_deposit_l( 0 ); - FOR( k = 0; k < 32; k++ ) - { - avrg_l = L_add( avrg_l, L_shr( magSq[k + 20], 5 ) ); - avrg_h = L_add( avrg_h, L_shr( magSq[k + 96], 5 ) ); - IF( GT_32( magSq[k + 20], peak_l ) ) - { - peak_l = L_add( magSq[k + 20], 0 ); - } - IF( GT_32( magSq[k + 96], peak_h ) ) - { - peak_h = L_add( magSq[k + 96], 0 ); - } - } - - /* Compute: d_acc - 12*(np -1). */ - acc = L_deposit_l( d_acc ); - IF( L_msu( acc, 12 / 2, sub( np, 1 ) ) > 0 ) /* 12/2 is to compensate the fractional mode multiply */ - { - condition1 = 1; /* Signifies: d_acc/(np - 1) > 12 */ - move16(); - } - ELSE - { - condition1 = 0; /* Signifies: d_acc/(np - 1) <= 12 */ - move16(); - /* NB: For np = 0 or 1, it fits this condition. */ - } - - /* Compute: p_energy - 147.87276*n_energy. */ - IF( n_energy_man != 0 ) - { - Mpy_32_16_ss( n_energy_man, 18928, &acc, &lsb16 ); /* 147.87276 in Q7 */ - expo = sub( n_energy_exp, 15 - 7 ); /* Due to 18928 in Q7 */ - acc = L_negate( acc ); /* To facilitate the following floating_point_add() to perform subtraction. */ - floating_point_add( &acc, &expo, p_energy_man, p_energy_exp ); - } - ELSE - { - acc = L_deposit_l( 0 ); - } - IF( acc > 0 ) - { - condition2 = 1; /* Signifies: p_energy / n_energy > 147.87276 */ - move16(); - } - ELSE - { - condition2 = 0; /* Signifies: p_energy / n_energy <= 147.87276 */ - move16(); - } - - condition3 = 0; - move16(); - condition4 = 0; - move16(); - - L_tmp = Mult_32_16( peak_h, 12603 /*1/2.56.Q15*/ ); - IF( GT_32( peak_l, L_tmp ) ) - { - exp = norm_l( peak_l ); - } - ELSE - { - exp = norm_l( L_tmp ); - } - IF( GT_32( avrg_h, avrg_l ) ) - { - exp1 = norm_l( avrg_h ); - } - ELSE - { - exp1 = norm_l( avrg_l ); - } - - L_tmp1 = Mult_32_16( peak_l, 12603 /*1/2.56.Q15*/ ); - IF( GT_32( peak_h, L_tmp1 ) ) - { - exp2 = norm_l( peak_h ); - } - ELSE - { - exp2 = norm_l( L_tmp1 ); - } - - test(); - test(); - test(); - test(); - IF( GT_32( Mult_32_16( gain3, 27307 ), gain2 ) || ( GE_32( gain3, Mult_32_16( gain2, 26214 ) ) && GT_32( peak_H1, L_shl_sat( avrg_H1, 1 ) ) ) || ( LT_32( Mult_32_32( L_shl( peak_l, exp ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( L_tmp, exp ), L_shl( avrg_l, exp1 ) ) ) || GT_32( Mult_32_32( L_shl( L_tmp1, exp2 ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( peak_h, exp2 ), L_shl( avrg_l, exp1 ) ) ) ) ) - { - condition3 = 1; - move16(); - } - - L_tmp = Mult_32_16( peak_h, 12800 /*(1/2.56).Q15*/ ); - IF( GT_32( peak_l, L_tmp ) ) - { - exp = norm_l( peak_l ); - } - ELSE - { - exp = norm_l( L_tmp ); - } - - L_tmp1 = Mult_32_16( peak_l, 6400 /*(1/5.12).Q15*/ ); - IF( GT_32( peak_h, L_tmp1 ) ) - { - exp2 = norm_l( peak_h ); - } - ELSE - { - exp2 = norm_l( L_tmp1 ); - } - - IF( GT_32( peak_h, L_shl( L_tmp1, 1 ) ) ) - { - exp3 = norm_l( peak_h ); - } - ELSE - { - exp3 = sub( norm_l( L_tmp1 ), 1 ); - } - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( GT_32( gain4, Mult_32_16( gain11, 26214 /*0.8.Q15*/ ) ) && GT_32( Mult_32_32( L_shl( peak_l, exp ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( Mult_32_16( peak_h, 12800 /*(1/2.56).Q15*/ ), exp ), L_shl( avrg_l, exp1 ) ) ) && LT_32( Mult_32_32( L_shl( Mult_32_16( peak_l, 6400 /*(1/5.12).Q15*/ ), exp2 ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( peak_h, exp2 ), L_shl( avrg_l, exp1 ) ) ) ) || ( GT_32( gain4, Mult_32_16( gain11, 9830 /*0.3.Q15*/ ) ) && LT_32( Mult_32_16( peak_h, 21845 /*(1/1.5).Q15*/ ), avrg_h ) && LT_32( Mult_32_16( peak_H2, 21845 /*(1/1.5).Q15*/ ), avrg_H2 ) ) || ( LT_32( Mult_32_32( L_shl( peak_l, exp ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( Mult_32_16( peak_h, 12800 /*(1/2.56).Q15*/ ), exp ), L_shl( avrg_l, exp1 ) ) ) && GT_32( Mult_32_16( peak_h, 21845 /*(1/1.5).Q15*/ ), avrg_h ) ) || ( GT_32( Mult_32_32( L_shl( Mult_32_16( peak_l, 12800 /*(1/2.56).Q15*/ ), exp3 ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( peak_h, exp3 ), L_shl( avrg_l, exp1 ) ) ) > 0 && LT_32( Mult_32_16( peak_h, 21845 /*(1/1.5).Q15*/ ), avrg_h ) ) ) - { - condition4 = 1; - move16(); - } - - test(); - test(); - test(); - test(); - IF( ( GE_32( brate, HQ_MDCTCLASS_CROSSOVER_BRATE ) && GT_32( st_fx->input_Fs, 16000 ) && ( s_xor( condition1, condition2 ) != 0 || condition3 ) ) || ( ( LT_32( brate, HQ_MDCTCLASS_CROSSOVER_BRATE ) || EQ_32( st_fx->input_Fs, 16000 ) ) && condition4 ) ) - { - c = MDCT_CLASSIFER_HQ_LOCAL; /* Q13 */ - move16(); - } - ELSE - { - c = MDCT_CLASSIFER_TCX_LOCAL; /* Q13 */ - move16(); - } - - /* Smooth decision from instantaneous decision*/ - acc = L_mult( hTcxEnc->clas_sec_old_fx, MDCT_CLASSIFER_SMOOTH_FILT_COEFF ); /* st_fx->clas_sec_old_fx in Q13 */ - clas_sec = mac_r( acc, c, 0x7fff /*1.Q15*/ - MDCT_CLASSIFER_SMOOTH_FILT_COEFF ); /* clas_sec and c are in Q13 */ - /* Do thresholding with hysteresis */ - IF( GT_16( st_fx->last_enerBuffer_exp, enerBuffer_exp ) ) - { - gain1_tmp = L_shr( gain1, sub( st_fx->last_enerBuffer_exp, enerBuffer_exp ) ); // st_fx->last_enerBuffer_exp - move32(); - gain2_tmp = L_shr( gain2, sub( st_fx->last_enerBuffer_exp, enerBuffer_exp ) ); // st_fx->last_enerBuffer_exp - move32(); - } - ELSE - { - hTcxEnc->last_gain1 = L_shr( hTcxEnc->last_gain1, sub( enerBuffer_exp, st_fx->last_enerBuffer_exp ) ); // enerBuffer_exp - move32(); - hTcxEnc->last_gain2 = L_shr( hTcxEnc->last_gain2, sub( enerBuffer_exp, st_fx->last_enerBuffer_exp ) ); // enerBuffer_exp - move32(); - gain1_tmp = gain1; - move32(); - gain2_tmp = gain2; - move32(); - } - - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( EQ_16( hTcxEnc->clas_final_old, HQ_CORE ) || EQ_16( hTcxEnc->clas_final_old, TCX_20_CORE ) ) && ( ( GT_32( hTcxEnc->last_gain1, L_shr( gain1_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain1, L_shl_sat( gain1_tmp, 1 ) ) ) && ( GT_32( hTcxEnc->last_gain2, L_shr( gain2_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain2, L_shl_sat( gain2_tmp, 1 ) ) ) ) ) - { - clas_final = hTcxEnc->clas_final_old; - move16(); - } - ELSE IF( GT_16( clas_sec, hTcxEnc->clas_sec_old_fx ) && GT_16( clas_sec, MDCT_CLASSIFER_THRESH_UP ) ) /* Going up? */ - { - clas_final = HQ_CORE; /* Q0 */ - move16(); - } - ELSE IF( LT_16( clas_sec, MDCT_CLASSIFER_THRESH_DOWN ) ) /* Going down */ - { - clas_final = TCX_20_CORE; - move16(); - } - ELSE - { - clas_final = hTcxEnc->clas_final_old; - move16(); - } - - test(); - test(); - test(); - /* Prevent the usage of MDCTA on noisy-speech or inactive */ - if ( EQ_16( st_fx->mdct_sw_enable, MODE2 ) && ( EQ_16( st_fx->flag_noisy_speech_snr, 1 ) || st_fx->vad_flag == 0 ) && EQ_16( clas_final, HQ_CORE ) ) - { - clas_final = TCX_20_CORE; - move16(); - } - /* Restrict usage of HQ_core to supported operating range */ - /* EVS: brate == st->total_brate */ - /* IVAS: brate is the nominal bitrate while st->total_brate may fluctuate. This sets a hard limit for HQ at HQ_16k40 */ - test(); - test(); - test(); - if ( LE_32( st_fx->total_brate, HQ_16k40 ) || LT_32( brate, HQ_16k40 ) || EQ_16( st_fx->bwidth, NB ) || GT_32( brate, IVAS_48k ) ) - { - clas_final = TCX_20_CORE; - move16(); - } - - /* Memory update */ - hTcxEnc->clas_sec_old_fx = clas_sec; - move16(); /* Q13 */ - hTcxEnc->clas_final_old = clas_final; - move16(); /* Q0 */ - hTcxEnc->last_gain1 = gain1; - move32(); - hTcxEnc->last_gain2 = gain2; - move32(); - st_fx->last_enerBuffer_exp = enerBuffer_exp; - move16(); - - return clas_final; /* Q0 */ -} -#endif -#ifdef HQ_ALIGN_DUPLICATED_CODE Word16 mdct_classifier_fx( -#else -Word16 mdct_classifier_ivas_fx( -#endif Encoder_State *st, /* i/o: Encoder state variable */ const Word16 *fft_buff, /* i : FFT spectrum from fft_rel */ const Word32 enerBuffer[], /* i : energy buffer */ @@ -548,11 +127,8 @@ Word16 mdct_classifier_ivas_fx( move16(); test(); -#ifdef HQ_ALIGN_DUPLICATED_CODE + test(); IF( EQ_32( st->input_Fs, 32000 ) || EQ_32( st->input_Fs, 48000 ) || EQ_16( st->element_mode, EVS_MONO ) ) -#else - IF( EQ_32( st->input_Fs, 32000 ) || EQ_32( st->input_Fs, 48000 ) ) -#endif { gain2_start = GAIN2_START_SWB; gain3_start = GAIN3_START_SWB; @@ -766,7 +342,6 @@ Word16 mdct_classifier_ivas_fx( } } -#ifdef HQ_ALIGN_DUPLICATED_CODE IF( EQ_16( st->element_mode, EVS_MONO ) ) { peak_H1 = L_add( enerBuffer[H1_start], 0 ); @@ -799,25 +374,7 @@ Word16 mdct_classifier_ivas_fx( avrg_H1 = L_add( avrg_H1, enerBuffer[H1_start + i] ); // enerBuffer_exp } } -#else - peak_H1 = enerBuffer[H1_start]; // enerBuffer_exp - move32(); - - avrg_H1 = enerBuffer[H1_start]; // enerBuffer_exp - move32(); - - FOR( i = 1; i < H_length; i++ ) - { - IF( GT_32( enerBuffer[H1_start + i], peak_H1 ) ) - { - peak_H1 = enerBuffer[H1_start + i]; // enerBuffer_exp - move32(); - } - avrg_H1 = L_add( avrg_H1, enerBuffer[H1_start + i] ); // enerBuffer_exp - } -#endif -#ifdef HQ_ALIGN_DUPLICATED_CODE IF( EQ_16( st->element_mode, EVS_MONO ) ) { peak_H2 = L_add( enerBuffer[H2_start], 0 ); @@ -850,23 +407,7 @@ Word16 mdct_classifier_ivas_fx( avrg_H2 = L_add( avrg_H2, enerBuffer[H2_start + i] ); } } -#else - peak_H2 = enerBuffer[H2_start]; - move32(); - avrg_H2 = enerBuffer[H2_start]; - move32(); - - FOR( i = 1; i < H_length; i++ ) - { - IF( GT_32( enerBuffer[H2_start + i], peak_H2 ) ) - { - peak_H2 = enerBuffer[H2_start + i]; - move32(); - } - avrg_H2 = L_add( avrg_H2, enerBuffer[H2_start + i] ); - } -#endif peak_l = L_deposit_l( 0 ); avrg_l = L_deposit_l( 0 ); peak_h = L_deposit_l( 0 ); @@ -1087,12 +628,8 @@ Word16 mdct_classifier_ivas_fx( test(); test(); test(); -#ifdef HQ_ALIGN_DUPLICATED_CODE test(); if ( ( EQ_16( st->mdct_sw_enable, MODE2 ) || GT_16( st->element_mode, EVS_MONO ) ) && ( EQ_16( st->flag_noisy_speech_snr, 1 ) || st->vad_flag == 0 ) && EQ_16( clas_final, HQ_CORE ) ) -#else - if ( EQ_16( st->mdct_sw_enable, MODE2 || st->element_mode > EVS_MONO ) && ( EQ_16( st->flag_noisy_speech_snr, 1 ) || st->vad_flag == 0 ) && EQ_16( clas_final, HQ_CORE ) ) -#endif { clas_final = TCX_20_CORE; move16(); diff --git a/lib_enc/pit_enc_fx.c b/lib_enc/pit_enc_fx.c index 30c2b493d43a45c0aeabf6c2d06e60dc6886dfc4..0e1b433b1f7a61c436e9af1ce15778eabf522669 100644 --- a/lib_enc/pit_enc_fx.c +++ b/lib_enc/pit_enc_fx.c @@ -17,9 +17,7 @@ #define inv_T0_res InvIntTable static void limit_T0_voiced2( Word16 res, const Word16 *T_op, Word16 *T0_min, Word16 *T0_min_frac, Word16 *T0_max, Word16 *T0_max_frac, Word16 pit_min, Word16 pit_max, Word16 i_subfr ); -#ifdef HARMONIZE_FUNC static void norm_corr_ivas_fx( const Word16 exc[], const Word16 xn[], const Word16 h[], const Word16 t_min, const Word16 t_max, Word16 ncorr[], const Word16 L_subfr, Word16 Q_new ); -#endif /*==============================================================================*/ @@ -955,11 +953,7 @@ Word16 pitch_fr4_fx( * excitation) *---------------------------------------------------------------------*/ -#ifdef HARMONIZE_FUNC static void norm_corr_ivas_fx( -#else -void norm_corr_ivas_fx( -#endif const Word16 exc[], /* i : excitation buffer Q_new */ const Word16 xn[], /* i : target signal Q_new-1 */ const Word16 h[], /* i : weighted synthesis filter impulse response Q(14 - norm_s(h[0])) */ @@ -1005,11 +999,7 @@ void norm_corr_ivas_fx( corr = extract_h( L_tmp ); /* Compute 1/sqrt(energy of excf[]) */ -#ifndef FIX_2471_REMOVE_POSSIBLE_OVRF - Word16 _0_01 = extract_l( L_shr( 21474836 /* 0.01 in Q31 */, sub( 31, add( shl( sub( Q_new, h_e ), 1 ), 1 ) ) ) ); -#else Word64 _0_01 = W_shr( 21474836 /* 0.01 in Q31 */, sub( 31, add( shl( sub( Q_new, h_e ), 1 ), 1 ) ) ); -#endif W_tmp = W_mac_16_16( _0_01, excf[0], excf[0] ); FOR( i = 1; i < L_subfr; i++ ) { diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index 0f0cbddff753561aad9058477f52d0017dab48f3..e25c15dde949578eab5a997bf4ecc7e38f28fb24 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -789,11 +789,7 @@ void pre_proc_fx( IF( ( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) ) && EQ_32( st->total_brate, ACELP_32k ) ) { /* Select MDCT Core */ -#ifdef HQ_ALIGN_DUPLICATED_CODE st->core = mdct_classifier_fx( st, fft_buff, enerBuffer, sub( enerBuffer_exp, 31 ), st->total_brate ); -#else - st->core = mdct_classifier_fx( fft_buff, st, enerBuffer, sub( enerBuffer_exp, 31 ), st->total_brate ); -#endif } test(); IF( ( EQ_32( st->total_brate, ACELP_13k20 ) ) && ( NE_16( st->bwidth, FB ) ) ) @@ -1234,11 +1230,7 @@ void pre_proc_fx( test(); IF( ( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) ) && EQ_32( st->total_brate, ACELP_24k40 ) ) { -#ifdef HQ_ALIGN_DUPLICATED_CODE st->core = mdct_classifier_fx( st, fft_buff, enerBuffer, sub( enerBuffer_exp, 31 ), st->total_brate ); -#else - st->core = mdct_classifier_fx( fft_buff, st, enerBuffer, sub( enerBuffer_exp, 31 ), st->total_brate ); -#endif } test(); IF( ( EQ_32( st->total_brate, ACELP_16k40 ) ) && ( NE_16( st->bwidth, FB ) ) ) diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 2b644e164ca480079fc9be8cefe98fb22dfa0e4c..0281d8f6d1c2d2d87a44723a7db1e3350528a6be 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -244,7 +244,6 @@ void ivas_long_enr_fx( const Word16 Etot_LR[] /* i : total channel energy LR channels Q=8*/ ); -#ifdef HQ_ALIGN_DUPLICATED_CODE Word16 mdct_classifier_fx( Encoder_State *st, /* i/o: Encoder state variable */ const Word16 *fft_buff, /* i : FFT spectrum from fft_rel */ @@ -252,16 +251,6 @@ Word16 mdct_classifier_fx( Word16 enerBuffer_exp, /* i : energy buffer exponent */ const Word32 brate /* i : current brate, IVAS: nominal bitrate, EVS: st->total_brate */ ); -#else -/* o: MDCT A/B decision */ -Word16 mdct_classifier_fx( - const Word16 *Y, /* i : re[0], re[1], ..., re[n/2], im[n/2 - 1], im[n/2 - 2], ..., im[1] */ - Encoder_State *st_fx, /* i/o: Encoder state variable */ - Word32 *cldfbBuf_Ener, - Word16 enerBuffer_exp, - const Word32 brate /* i : current brate, IVAS: nominal bitrate, EVS: st->total_brate */ -); -#endif void noise_est_down_fx( const Word32 fr_bands[], /* i : per band i energy (contains 2 vectors) */ @@ -783,18 +772,6 @@ void norm_corr_fx( const Word16 L_subfr /* i : subframe size */ ); -#ifndef HARMONIZE_FUNC -void norm_corr_ivas_fx( - const Word16 exc[], /* i : excitation buffer Q_new */ - const Word16 xn[], /* i : target signal Q_new-1 */ - const Word16 h[], /* i : weighted synthesis filter impulse response Q(14 - norm_s(h[0])) */ - const Word16 t_min, /* i : minimum value of searched range */ - const Word16 t_max, /* i : maximum value of searched range */ - Word16 ncorr[], /* o : normalized correlation */ - const Word16 L_subfr, /* i : subframe size */ - Word16 Q_new /* i */ -); -#endif Word16 peak_avrg_ratio_fx( const Word32 total_brate, /* Q0 */ const Word32 *input_hi_fx, /* i : i signal Q_coeff*/ @@ -1013,22 +990,6 @@ void AVQ_cod_lpc_fx( Word16 Nsv /* i : number of subvectors (lg=Nsv*8) */ ); -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -void ProcessIGF_ivas_fx( - Encoder_State *st, /* i : Encoder state */ - Word16 powerSpec_len, /* i : length of pPowerSpectrum buffer */ - Word32 *pMDCTSpectrum, /* i : MDCT spectrum */ - Word16 *q_spectrum, /* i/o: Q of spectrum */ - const Word32 *pITFMDCTSpectrum, /* i : MDCT spectrum fir ITF */ - const Word16 q_ITFMDCTSpectrum, /* i : Q of MDCT spectrum fir ITF */ - Word32 *pPowerSpectrum, /* i : MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 *q_powerSpec, /* i/o: Q of power spectrum */ - const Word16 isTCX20, /* i : flag indicating if the input is TCX20 or TCX10/2xTCX5 */ - const Word16 frameno, /* i : flag indicating index of current subframe */ - const Word16 sp_aud_decision0, /* i : first stage switching decision */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ -); -#else void ProcessIGF_fx( Encoder_State *st, /* i : Encoder state */ Word16 powerSpec_len, /* i : length of pPowerSpectrum buffer */ @@ -1043,7 +1004,7 @@ void ProcessIGF_fx( const Word16 sp_aud_decision0, /* i : first stage switching decision */ const Word16 vad_hover_flag /* i : VAD hangover flag */ ); -#endif + void ProcessIGF_ivas_fx_64( Encoder_State *st, /* i/o: Encoder state */ const Word16 powerSpec_len, /* i : length of pPowerSpectrum buffer */ @@ -1056,20 +1017,6 @@ void ProcessIGF_ivas_fx_64( const Word16 sp_aud_decision0 /* i : first stage switching decision */ ); -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -void ProcessIGF_fx( - IGF_ENC_INSTANCE_HANDLE const hInstance, /**< in: instance handle of IGF Encoder */ - Encoder_State *st, /**< in: Encoder state */ - Word32 pMDCTSpectrum[], /**< in: MDCT spectrum */ - Word16 *pMDCTSpectrum_e, - Word32 pPowerSpectrum[], /**< in: MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 *pPowerSpectrum_e, - Word16 isTCX20, /**< in: flag indicating if the i is TCX20 or TCX10/2xTCX5 */ - Word16 isTNSActive, /**< in: flag indicating if the TNS is active */ - Word16 isTransition, /**< in: flag indicating if the i is the transition from from ACELP to TCX20/TCX10 */ - Word16 frameno /**< in: flag indicating index of current subframe */ -); -#endif void AnalyzePowerSpectrum_fx( Encoder_State *st, /* i/o: encoder states */ Word16 L_frame, /* i : frame length */ @@ -1794,7 +1741,6 @@ void encod_audio_fx( const Word16 shift /* i : Shift needed to obtain 12 bits vectors */ ); -#ifdef HQ_ALIGN_DUPLICATED_CODE void stat_noise_uv_enc_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word32 *LepsP, /* i : LP prediction errors */ @@ -1804,28 +1750,6 @@ void stat_noise_uv_enc_fx( Word16 *exc2, /* i/o: excitation buffer */ const Word16 uc_two_stage_flag, /* o : flag indicating two-stage UC */ Word16 *Q_new ); -#else -void stat_noise_uv_enc_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word32 *LepsP, /* i : LP prediction errors */ - const Word16 *isp_new, /* i : immittance spectral pairs at 4th sfr */ - const Word16 *isp_mid, /* i : immittance spectral pairs at 2nd sfr */ - Word16 *Aq, /* i : A(z) quantized for the 4 subframes */ - Word16 *exc2, /* i/o: excitation buffer */ - const Word16 uc_two_stage_flag, /* o : flag undicating two-stage UC */ - Word16 Q_new ); -#endif -#ifndef HQ_ALIGN_DUPLICATED_CODE -void stat_noise_uv_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word32 *LepsP, /* i : LP prediction errors Q=Qx*/ - const Word16 *isp_new, /* i : immittance spectral pairs at 4th sfr Q=15*/ - const Word16 *isp_mid, /* i : immittance spectral pairs at 2nd sfr Q=15*/ - Word16 *Aq, /* i : A(z) quantized for the 4 subframes Q=12 */ - Word16 *exc2, /* i/o: excitation buffer Q=Q_stat_noise */ - const Word16 uc_two_stage_flag, /* o : flag undicating two-stage UC */ - Word16 *Q_new ); -#endif void analy_sp_fx( const Word16 element_mode, /* i : element mode */ @@ -2544,12 +2468,8 @@ Word16 IGFEncWriteBitstream_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - const Word16 isIndepFlag, /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ - const Word16 element_mode /**< in: | IVAS element mode type */ -#else - const Word16 isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ -#endif + const Word16 isIndepFlag, /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ + const Word16 element_mode /**< in: | IVAS element mode type */ ); void ACcontextMapping_encode2_no_mem_s17_LC_fx( @@ -2567,13 +2487,6 @@ Word16 IGFEncWriteConcatenatedBitstream_fx( BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ); -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/**< out: Q0 | total number of bits written */ -Word16 IGFEncWriteConcatenatedBitstream_ivas_fx( - const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : instance handle of IGF Encoder */ - BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ -); -#endif void signaling_enc_rf_fx( Encoder_State *st /* i : encoder state structure */ ); @@ -2659,60 +2572,24 @@ void IGF_UpdateInfo( /* o: Q15| crest factor */ Word16 IGF_getCrest( - Word16 *crest_exp, /**< out: | exponent of crest factor */ - const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + Word16 *crest_exp, /**< out: | exponent of crest factor */ + const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ const Word16 *powerSpectrum_exp, /**< in: | exponent of power spectrum */ -#else - const Word16 powerSpectrum_exp, /**< in: | exponent of power spectrum */ -#endif - const Word16 start, /**< in: Q0 | start subband index */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - const Word16 stop, /**< in: Q0 | stop subband index */ - const Word16 element_mode /**< in: | IVAS element mode type */ -#else - const Word16 stop /**< in: Q0 | stop subband index */ -#endif + const Word16 start, /**< in: Q0 | start subband index */ + const Word16 stop, /**< in: Q0 | stop subband index */ + const Word16 element_mode /**< in: | IVAS element mode type */ ); -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/* o: Q15| crest factor */ -Word16 IGF_getCrest_ivas( - Word16 *crest_exp, /* o : | exponent of crest factor */ - const Word32 *powerSpectrum, /* i : Q31 | power spectrum */ - const Word16 *powerSpectrum_exp, /* i : | exponent of power spectrum */ - const Word16 start, /* i : Q0 | start subband index */ - const Word16 stop /* i : Q0 | stop subband index */ -); -#endif /* o: Q15| SFM value */ Word16 IGF_getSFM( Word16 *SFM_exp, /* o : | exponent of SFM Factor */ const Word32 *energy, /* i : Q31| energies */ const Word16 *energy_exp, /* i : | exponent of energies */ const Word16 start, /* i : Q0 | start subband index */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS const Word16 stop, /* i : Q0 | stop subband index */ const Word16 element_mode /* i : | IVAS element mode type */ -#else - const Word16 stop /* i : Q0 | stop subband index */ -#endif -); -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/* o: Q15| SFM value */ -Word16 IGF_getSFM_ivas_fx( - Word16 *SFM_exp, /* o : | exponent of SFM Factor */ - const Word32 *energy, /* i : Q31| energies */ - const Word16 *energy_exp, /* i : | exponent of energies */ - const Word16 start, /* i : Q0 | start subband index */ - const Word16 stop /* i : Q0 | stop subband index */ ); -#endif -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS -/**********************************************************************/ /* -identifies significant spectral content -**************************************************************************/ void IGF_ErodeSpectrum( const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : instance handle of IGF Encoder */ Word32 *pSpectrum, /* i/o: MDCT spectrum */ @@ -2722,39 +2599,8 @@ void IGF_ErodeSpectrum( const Word16 mct_on, /* i : flag that indicates mct on/off */ const Word16 element_mode /* i : IVAS element mode type */ ); -#else -void IGF_ErodeSpectrum( - Word16 *highPassEner_exp, /* o : exponent of highPassEner */ - const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : instance handle of IGF Encoder */ - Word32 *pSpectrum, /* i/o: MDCT spectrum */ - Word32 *pPowerSpectrum, /* i/o: power spectrum */ - Word16 pPowerSpectrum_exp, /* i : exponent of power spectrum */ - const Word16 igfGridIdx /* i : IGF grid index */ -); -void IGF_ErodeSpectrum_ivas_fx( - const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : instance handle of IGF Encoder */ - Word32 *pSpectrum, /* i/o: MDCT spectrum */ - Word32 *pPowerSpectrum, /* i/o: power spectrum */ - Word16 pPowerSpectrum_exp, /* i : exponent of power spectrum */ - const Word16 igfGridIdx, /* i : IGF grid index */ - const Word16 mct_on ); -#endif -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS void IGFEncApplyMono_fx( - const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : | instance handle of IGF Encoder */ - const Word16 igfGridIdx, /* i : Q0 | IGF grid index */ - Encoder_State *st, /* i : | Encoder state */ - Word32 *pMDCTSpectrum, /* i : Q31 | MDCT spectrum */ - Word16 MDCTSpectrum_e, /* i : | exponent of MDCT spectrum */ - Word32 *pPowerSpectrum, /* i : Q31 | MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 PowerSpectrum_e, /* i : | exponent of pPowerSpectrum */ - Word16 isTCX20, /* i : Q0 | flag indicating if the i is TCX20 or TCX10/2xTCX5 */ - Word16 isTNSActive, /* i : Q0 | flag indicating if the TNS is active */ - Word16 last_core_acelp /* i : Q0 | indictaor if last frame was acelp coded */ -); - -void IGFEncApplyMono_ivas_fx( Encoder_State *st, /* i : Encoder state */ Word16 powerSpectrum_len, /* i : length of pPowerSpectrum_fx */ const Word16 igfGridIdx, /* i : IGF grid index */ @@ -2767,37 +2613,6 @@ void IGFEncApplyMono_ivas_fx( const Word16 sp_aud_decision0, /* i : first stage switching decision */ const Word16 vad_hover_flag /* i : VAD hangover flag */ ); -#else -void IGFEncApplyMono_fx( - Encoder_State *st, /* i : Encoder state */ - Word16 powerSpectrum_len, /* i : length of pPowerSpectrum_fx */ - const Word16 igfGridIdx, /* i : IGF grid index */ - Word32 *pMDCTSpectrum_fx, /* i/o: MDCT spectrum */ - Word16 e_mdct, /* i : exponent of pMDCTspectrum */ - Word32 *pPowerSpectrum_fx, /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 *e_ps, /* i : exponent of pPowerSpectrum */ - const Word16 isTCX20, /* i : flag indicating if the input is TCX20 or TCX10/2xTCX5 */ - const Word8 isTNSActive, /* i : flag indicating if the TNS is active */ - const Word16 sp_aud_decision0, /* i : first stage switching decision */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ -); -#endif - -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -void IGFEncConcatenateBitstream_ivas_fx( - const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ - const Word16 bsBits, /* i : number of IGF bits written to list of indices */ - BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ -); - -void IGFEncConcatenateBitstream_fx( - const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : instance handle of IGF Encoder */ - Word16 bsBits, /* i : number of IGF bits written to list of indices */ - Word16 *next_ind, /* i/o: pointer to actual bit indice */ - Word16 *nb_bits, /* i/o: total number of bits already written */ - Indice *ind_list_fx /* i : pointer to list of indices */ -); -#endif void msvq_enc_fx( const Word16 *const *cb, /* i : Codebook (indexed cb[*stages][levels][p]) (0Q15) */ @@ -2977,10 +2792,8 @@ Word16 IGFSCFEncoderEncode_fx( const Word16 bitCount, /* i : offset to the first bit in bitbuffer which should be readed by iisArithDecoderDecode function */ Word16 *sfe, /* i : ptr to an array which contain quantized scalefactor energies */ const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - const Word16 element_mode, /* i : IVAS element mode type */ -#endif - const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ + const Word16 element_mode, /* i : IVAS element mode type */ + const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ ); void IGFSCFEncoderSaveContextState_fx( diff --git a/lib_enc/stat_noise_uv_enc_fx.c b/lib_enc/stat_noise_uv_enc_fx.c index 07d124ece983201bf7f95747f1a140499034bcdd..8306c60d78ed09e7b5c2b36206c31ccd3c4a2da6 100644 --- a/lib_enc/stat_noise_uv_enc_fx.c +++ b/lib_enc/stat_noise_uv_enc_fx.c @@ -36,7 +36,6 @@ /* _ None */ /*=======================================================================*/ -#ifdef HQ_ALIGN_DUPLICATED_CODE void stat_noise_uv_enc_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word32 *LepsP, /* i : LP prediction errors */ @@ -46,17 +45,6 @@ void stat_noise_uv_enc_fx( Word16 *exc2, /* i/o: excitation buffer */ const Word16 uc_two_stage_flag, /* o : flag indicating two-stage UC */ Word16 *Q_new ) -#else -void stat_noise_uv_enc_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word32 *LepsP, /* i : LP prediction errors */ - const Word16 *isp_new, /* i : immittance spectral pairs at 4th sfr */ - const Word16 *isp_mid, /* i : immittance spectral pairs at 2nd sfr */ - Word16 *Aq, /* i : A(z) quantized for the 4 subframes */ - Word16 *exc2, /* i/o: excitation buffer */ - const Word16 uc_two_stage_flag, /* o : flag undicating two-stage UC */ - Word16 Q_new ) -#endif { Word16 noisiness = 0; move16(); @@ -109,93 +97,9 @@ void stat_noise_uv_enc_fx( * Modify the stationary noise excitation signal *-----------------------------------------------------------------*/ -#ifdef HQ_ALIGN_DUPLICATED_CODE stat_noise_uv_mod_fx( st_fx->element_mode, st_fx->coder_type, noisiness, st_fx->lsp_old_fx, isp_new, isp_mid, Aq, exc2, Q_new, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); -#else - stat_noise_uv_mod_fx( st_fx->coder_type, noisiness, st_fx->lsp_old_fx, isp_new, isp_mid, Aq, exc2, Q_new, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, - st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx, - st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); -#endif - - - return; -} - -#ifndef HQ_ALIGN_DUPLICATED_CODE -void stat_noise_uv_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word32 *LepsP, /* i : LP prediction errors Q=Qx*/ - const Word16 *isp_new, /* i : immittance spectral pairs at 4th sfr Q=15*/ - const Word16 *isp_mid, /* i : immittance spectral pairs at 2nd sfr Q=15*/ - Word16 *Aq, /* i : A(z) quantized for the 4 subframes Q=12 */ - Word16 *exc2, /* i/o: excitation buffer Q=Q_stat_noise */ - const Word16 uc_two_stage_flag, /* o : flag undicating two-stage UC */ - Word16 *Q_new ) -{ - Word16 noisiness = 0; - move16(); - Word16 num, den, expn, expd; - - test(); - test(); - test(); - IF( ( EQ_16( st_fx->coder_type, UNVOICED ) && uc_two_stage_flag == 0 ) || ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) ) ) - { - /*-----------------------------------------------------------------* - * Calculate and write the noisiness parameter - *-----------------------------------------------------------------*/ - - /* epsP[2] is located in LepsP[0] and epsP[16] in LepsP[1] */ - expn = sub( norm_l( LepsP[0] ), 1 ); - num = extract_h( L_shl( LepsP[0], expn ) ); /*expn-16*/ - expd = norm_l( LepsP[1] ); - den = extract_h( L_shl( LepsP[1], expd ) ); /*expd-16*/ - num = div_s( num, den ); /*expn-expd+15*/ - num = shr_sat( num, add( sub( expn, expd ), 5 ) ); /*Q10*/ - num = sub( num, 1024 ); /*num - 1*/ - - test(); - IF( NE_16( st_fx->bwidth, NB ) ) - { - /* WB case */ - /* noisiness = (Word16)(((epsP[2] / epsP[16]) - 1)*2 * 32);*/ - noisiness = shr( num, 4 ); /*Q10 x64 -> Q0 */ - } - ELSE IF( EQ_16( st_fx->coder_type, INACTIVE ) && EQ_16( st_fx->bwidth, NB ) ) - { - /* NB GSC case */ - /* noisiness = (Word16)(((epsP[2] / epsP[16]) - 1)*.25f * 32);*/ - noisiness = shr( num, 4 + 3 ); /*Q10 x8 -> Q0 */ - } - ELSE - { - /* NB case */ - noisiness = shr( num, 4 + 2 ); /*Q16 x16 -> Q0 */ - } - - noisiness = s_max( noisiness, 0 ); - noisiness = s_min( noisiness, 31 ); - - push_indice( st_fx->hBstr, IND_NOISINESS, noisiness, 5 ); - } - - /*-----------------------------------------------------------------* - * Modify the stationary noise excitation signal - *-----------------------------------------------------------------*/ - -#ifdef HQ_ALIGN_DUPLICATED_CODE - stat_noise_uv_mod_fx( st_fx->element_mode, st_fx->coder_type, noisiness, st_fx->lsp_old_fx, isp_new, isp_mid, Aq, exc2, Q_new, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, - st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx, - st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); -#else - stat_noise_uv_mod_ivas_fx( st_fx->coder_type, noisiness, st_fx->lsp_old_fx, isp_new, isp_mid, Aq, exc2, Q_new, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, - st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx, - st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); -#endif - return; } -#endif diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index d5a2ba0637a3f960449c4d0b330d7faf6e324aef..42dbe29195ec8ccb3fe0dcfbd0d842cfbf264395 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -2143,7 +2143,6 @@ void swb_tbe_enc_fx( /* -------- start of memory rescaling -------- */ /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ -#ifdef FIX_2465_Q_BWE_EXC Word16 sig_len = L_FRAME32k + NL_BUFF_OFFSET; move16(); IF( st_fx->element_mode == EVS_MONO ) @@ -2154,10 +2153,6 @@ void swb_tbe_enc_fx( Lmax = L_deposit_l( 0 ); FOR( cnt = 0; cnt < sig_len; cnt++ ) -#else - Lmax = L_deposit_l( 0 ); - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) -#endif { Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); } diff --git a/lib_enc/tcx_ltp_enc_fx.c b/lib_enc/tcx_ltp_enc_fx.c index 9f481bbd12747c020078badcaec616d50e164bc8..72e8818ecbf3d8a6ee65f24e3528a4721685db41 100644 --- a/lib_enc/tcx_ltp_enc_fx.c +++ b/lib_enc/tcx_ltp_enc_fx.c @@ -1019,21 +1019,13 @@ void tcx_ltp_encode_ivas_fx( IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { -#ifndef FIX_2471_REMOVE_POSSIBLE_OVRF - tempFlatness_fx = extract_l( L_shr( GetTCXAvgTemporalFlatnessMeasure_ivas_fx( st->hTranDet, NSUBBLOCKS - NSUBBLOCKS_SHIFT, add( nPrevSubblocks, NSUBBLOCKS_SHIFT ) ), 14 ) ); // Q7 -#else tempFlatness_fx = extract_h( L_shl_sat( GetTCXAvgTemporalFlatnessMeasure_ivas_fx( st->hTranDet, NSUBBLOCKS - NSUBBLOCKS_SHIFT, add( nPrevSubblocks, NSUBBLOCKS_SHIFT ) ), 2 ) ); -#endif maxEnergyChange_fx = GetTCXMaxenergyChange_ivas_fx( st->hTranDet, (const Word8) isTCX10, NSUBBLOCKS - NSUBBLOCKS_SHIFT, add( nPrevSubblocks, NSUBBLOCKS_SHIFT ) ); // Q3 } ELSE { -#ifndef FIX_2471_REMOVE_POSSIBLE_OVRF - tempFlatness_fx = extract_l( L_shr( ( GetTCXAvgTemporalFlatnessMeasure_ivas_fx( st->hTranDet, NSUBBLOCKS, nPrevSubblocks ) ), 14 ) ); // Q7 -#else tempFlatness_fx = extract_h( L_shl_sat( ( GetTCXAvgTemporalFlatnessMeasure_ivas_fx( st->hTranDet, NSUBBLOCKS, nPrevSubblocks ) ), 2 ) ); // Q7 -#endif - maxEnergyChange_fx = GetTCXMaxenergyChange_ivas_fx( st->hTranDet, (const Word8) isTCX10, NSUBBLOCKS, nPrevSubblocks ); // Q3 + maxEnergyChange_fx = GetTCXMaxenergyChange_ivas_fx( st->hTranDet, (const Word8) isTCX10, NSUBBLOCKS, nPrevSubblocks ); // Q3 } /* Switch LTP on */ diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index 622d5ad54f0759a6f6269b34056f1c3236ea6aea..4d7cc3b688dfc5d7fa5d0ffe4c0430f850e6ad79 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -3338,118 +3338,6 @@ Word16 tcx_res_Q_spec_fx( return bits; } -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -void ProcessIGF_fx( - IGF_ENC_INSTANCE_HANDLE const hInstance, /* i : instance handle of IGF Encoder */ - Encoder_State *st, /* i : Encoder state */ - Word32 pMDCTSpectrum[], /* i : MDCT spectrum */ - Word16 *pMDCTSpectrum_e, - Word32 pPowerSpectrum[], /* i : MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 *pPowerSpectrum_e, - Word16 isTCX20, /* i : flag indicating if the input is TCX20 or TCX10/2xTCX5 */ - Word16 isTNSActive, /* i : flag indicating if the TNS is active */ - Word16 isTransition, /* i : flag indicating if the input is the transition from from ACELP to TCX20/TCX10 */ - Word16 frameno /* i : flag indicating index of current subframe */ -) -{ - Word16 igfGridIdx; - Word16 isIndepFlag; - Word16 bsBits; - Word16 pBsStart; - BSTR_ENC_HANDLE hBstr = st->hBstr; - IGF_ENC_INSTANCE_HANDLE hIGFEnc = st->hIGFEnc; - - isIndepFlag = 1; - move16(); - test(); - IF( isTransition && isTCX20 ) - { - igfGridIdx = IGF_GRID_LB_TRAN; - move16(); - } - ELSE - { - IF( isTCX20 ) - { - igfGridIdx = IGF_GRID_LB_NORM; - move16(); - } - ELSE - { - /* It is short block */ - igfGridIdx = IGF_GRID_LB_SHORT; - move16(); - if ( EQ_16( frameno, 1 ) ) - { - isIndepFlag = 0; - move16(); - } - } - } - - IGFEncApplyMono_fx( hInstance, /**< in: instance handle of IGF Encoder */ - igfGridIdx, /**< in: IGF grid index */ - st, /**< in: Encoder state */ - pMDCTSpectrum, /**< in: MDCT spectrum */ - *pMDCTSpectrum_e, - pPowerSpectrum, /**< in: MDCT^2 + MDST^2 spectrum, or estimate */ - *pPowerSpectrum_e, - isTCX20, /**< in: flag indicating if the input is TCX20 or TCX10/2xTCX5 */ - isTNSActive, /**< in: flag indicating if the TNS is active */ - ( st->last_core == ACELP_CORE ) ); - { - const Word32 tns_predictionGain = st->hIGFEnc->tns_predictionGain; - const Word16 startLine = st->hIGFEnc->infoStartLine; - const Word16 endLine = st->hIGFEnc->infoStopLine; - const Word16 maxOrder = 8; - const Word32 *spec_before = st->hIGFEnc->spec_be_igf; - Word16 curr_order = 0; - Word16 A[ITF_MAX_FILTER_ORDER + 1]; - Word16 Q_A; - Word16 predictionGain = 0; - Word16 *flatteningTrigger = &( st->hIGFEnc->flatteningTrigger ); - - move32(); - move16(); - move16(); - move16(); - move32(); - move16(); - move16(); - - ITF_Detect_fx( spec_before, startLine, endLine, maxOrder, A, &Q_A, &predictionGain, &curr_order, shl( st->hIGFEnc->spec_be_igf_e, 1 ) ); - *flatteningTrigger = 0; - move16(); - test(); - IF( LT_32( tns_predictionGain, 9646899l /*1.15 Q23*/ ) && - LT_16( predictionGain, 147 /*1.15 Q7*/ ) ) - { - *flatteningTrigger = 1; - move16(); - } - } - - move16(); - hInstance->infoTotalBitsPerFrameWritten = 0; - move16(); - IF( isTCX20 ) - { - IGFEncWriteBitstream_fx( hInstance, NULL, &hInstance->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); - } - ELSE - { - pBsStart = hBstr->nb_ind_tot; - move16(); - - IGFEncWriteBitstream_ivas_fx( hIGFEnc, hBstr, &hIGFEnc->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); - - bsBits = sub( hBstr->nb_ind_tot, pBsStart ); - IGFEncConcatenateBitstream_ivas_fx( hIGFEnc, bsBits, hBstr ); - } - - return; -} -#endif void attenuateNbSpectrum_fx( Word16 L_frame, @@ -3479,26 +3367,11 @@ void attenuateNbSpectrum_fx( } /*---------------------------------------------------------------------* - * ProcessIGF_ivas_fx() + * ProcessIGF_fx() * * *---------------------------------------------------------------------*/ -#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -void ProcessIGF_ivas_fx( - Encoder_State *st, /* i : Encoder state */ - Word16 powerSpec_len, /* i : length of pPowerSpectrum buffer */ - Word32 *pMDCTSpectrum, /* i : MDCT spectrum (*q_spectrum) */ - Word16 *q_spectrum, /* i/o: Q of spectrum */ - const Word32 *pITFMDCTSpectrum, /* i : MDCT spectrum fir ITF */ - const Word16 q_ITFMDCTSpectrum, /* i : Q of MDCT spectrum fir ITF */ - Word32 *pPowerSpectrum, /* i : MDCT^2 + MDST^2 spectrum, or estimate (*q_powerSpec) */ - Word16 *exp_powerSpec, /* i/o: Q of power spectrum */ - const Word16 isTCX20, /* i : flag indicating if the input is TCX20 or TCX10/2xTCX5 */ - const Word16 frameno, /* i : flag indicating index of current subframe */ - const Word16 sp_aud_decision0, /* i : first stage switching decision */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ -) -#else + void ProcessIGF_fx( Encoder_State *st, /* i : Encoder state */ Word16 powerSpec_len, /* i : length of pPowerSpectrum buffer */ @@ -3513,13 +3386,10 @@ void ProcessIGF_fx( const Word16 sp_aud_decision0, /* i : first stage switching decision */ const Word16 vad_hover_flag /* i : VAD hangover flag */ ) -#endif { Word16 igfGridIdx, isIndepFlag, bsBits, pBsStart, curr_order; Word16 predictionGain; -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS Word32 tns_predictionGain; -#endif Word16 A[ITF_MAX_FILTER_ORDER + 1]; Word16 q_A; @@ -3551,20 +3421,12 @@ void ProcessIGF_fx( } } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IF( GT_16( st->element_mode, EVS_MONO ) ) { IGFSaveSpectrumForITF_ivas_fx( hIGFEnc, igfGridIdx, pITFMDCTSpectrum, sub( Q31, q_ITFMDCTSpectrum ) ); } -#else - IGFSaveSpectrumForITF_ivas_fx( hIGFEnc, igfGridIdx, pITFMDCTSpectrum, sub( Q31, q_ITFMDCTSpectrum ) ); -#endif -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFEncApplyMono_fx( st, powerSpec_len, igfGridIdx, pMDCTSpectrum, sub( Q31, *q_spectrum ), pPowerSpectrum, exp_powerSpec, isTCX20, st->hTcxEnc->fUseTns[frameno], sp_aud_decision0, vad_hover_flag ); -#else - IGFEncApplyMono_ivas_fx( st, powerSpec_len, igfGridIdx, pMDCTSpectrum, sub( Q31, *q_spectrum ), pPowerSpectrum, exp_powerSpec, isTCX20, st->hTcxEnc->fUseTns[frameno], sp_aud_decision0, vad_hover_flag ); -#endif curr_order = 0; move16(); @@ -3573,7 +3435,6 @@ void ProcessIGF_fx( q_A = 0; move16(); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IF( EQ_16( st->element_mode, EVS_MONO ) ) { ITF_Detect_fx( hIGFEnc->spec_be_igf, hIGFEnc->infoStartLine, hIGFEnc->infoStopLine, 8 /*maxOrder*/, A, &q_A, &predictionGain, &curr_order, shl( st->hIGFEnc->spec_be_igf_e, 1 ) ); @@ -3582,17 +3443,10 @@ void ProcessIGF_fx( { ITF_Detect_ivas_fx( hIGFEnc->spec_be_igf, hIGFEnc->infoStartLine, hIGFEnc->infoStopLine, 8 /*maxOrder*/, A, &q_A, &predictionGain, &curr_order, sub( 31, hIGFEnc->spec_be_igf_e ) ); } -#else - ITF_Detect_ivas_fx( hIGFEnc->spec_be_igf, hIGFEnc->infoStartLine, hIGFEnc->infoStopLine, 8 /*maxOrder*/, A, &q_A, &predictionGain, &curr_order, sub( 31, hIGFEnc->spec_be_igf_e ) ); -#endif test(); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS tns_predictionGain = L_deposit_l( hIGFEnc->tns_predictionGain ); // todo: mul, 2026-03-12: check, why this is in Q23 IF( LT_32( tns_predictionGain, ONE_POINT_ONE_FIVE_Q23 ) && LT_16( predictionGain, ONE_POINT_ONE_FIVE_Q7 ) ) -#else - IF( LT_16( hIGFEnc->tns_predictionGain, ONE_POINT_ONE_FIVE_Q7 ) && LT_16( predictionGain, ONE_POINT_ONE_FIVE_Q7 ) ) -#endif { hIGFEnc->flatteningTrigger = 1; move16(); @@ -3608,29 +3462,18 @@ void ProcessIGF_fx( IF( isTCX20 ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFEncWriteBitstream_fx( hIGFEnc, NULL, &hIGFEnc->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag, st->element_mode ); -#else - IGFEncWriteBitstream_ivas_fx( hIGFEnc, NULL, &hIGFEnc->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); -#endif } ELSE { pBsStart = hBstr->nb_ind_tot; move16(); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFEncWriteBitstream_fx( hIGFEnc, hBstr, &hIGFEnc->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag, st->element_mode ); -#else - IGFEncWriteBitstream_ivas_fx( hIGFEnc, hBstr, &hIGFEnc->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); -#endif bsBits = sub( hBstr->nb_ind_tot, pBsStart ); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncConcatenateBitstream( hIGFEnc, bsBits, hBstr ); -#else - IGFEncConcatenateBitstream_ivas_fx( hIGFEnc, bsBits, hBstr ); -#endif } return; @@ -3722,11 +3565,7 @@ void ProcessStereoIGF_fx( IF( EQ_16( sts[ch]->core, TCX_20_CORE ) ) { -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFEncWriteBitstream_fx( hIGFEnc[ch], NULL, &hIGFEnc[ch]->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag, sts[ch]->element_mode ); -#else - IGFEncWriteBitstream_ivas_fx( hIGFEnc[ch], NULL, &hIGFEnc[ch]->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); -#endif } ELSE { @@ -3738,18 +3577,11 @@ void ProcessStereoIGF_fx( { hBstr->ind_list = sts[0]->hBstr->ind_list + sts[0]->hBstr->nb_ind_tot; } -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGFEncWriteBitstream_fx( hIGFEnc[ch], hBstr, &hIGFEnc[ch]->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag, sts[ch]->element_mode ); -#else - IGFEncWriteBitstream_ivas_fx( hIGFEnc[ch], hBstr, &hIGFEnc[ch]->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); -#endif bsBits = sub( hBstr->nb_ind_tot, pBsStart ); -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncConcatenateBitstream( hIGFEnc[ch], bsBits, hBstr ); -#else - IGFEncConcatenateBitstream_ivas_fx( hIGFEnc[ch], bsBits, hBstr ); -#endif } } @@ -3829,11 +3661,8 @@ void ProcessIGF_ivas_fx_64( q_spectrum = sub( Q31, st->hTcxEnc->spectrum_e[frameno] ); Scale_sig32( pITFMDCTSpectrum, st->hIGFEnc->infoStopLine, sub( q_spectrum, sub( Q31, q_ITFMDCTSpectrum ) ) ); /* q_spectrum */ -#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + ProcessIGF_fx( st, powerSpec_len, pMDCTSpectrum, &q_spectrum, pITFMDCTSpectrum, q_spectrum, &powerSpec_fx[frameno * L_subframeTCX], &exp_powerSpec[frameno * L_subframeTCX], st->core == TCX_20_CORE, frameno, sp_aud_decision0, 0 ); -#else - ProcessIGF_ivas_fx( st, powerSpec_len, pMDCTSpectrum, &q_spectrum, pITFMDCTSpectrum, q_spectrum, &powerSpec_fx[frameno * L_subframeTCX], &exp_powerSpec[frameno * L_subframeTCX], st->core == TCX_20_CORE, frameno, sp_aud_decision0, 0 ); -#endif return; } diff --git a/lib_rend/ivas_dirac_rend_fx.c b/lib_rend/ivas_dirac_rend_fx.c index 48a90ada52c612f913dff9774dd31ae1e7fdc12e..67ded0b8b8c7daa13e7b931acd6566e23c4ad2ec 100644 --- a/lib_rend/ivas_dirac_rend_fx.c +++ b/lib_rend/ivas_dirac_rend_fx.c @@ -4283,9 +4283,7 @@ static void ivas_masa_ext_dirac_render_sf_fx( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] ); move16(); -#ifdef FIX_2448_RENDERER_MSAN_ERROR IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx ) -#endif { Word16 proto_power_diff_smooth_prev_temp_q = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len ); Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, proto_power_diff_smooth_prev_temp_q ); // hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q + proto_power_diff_smooth_prev_temp_q @@ -4293,9 +4291,7 @@ static void ivas_masa_ext_dirac_render_sf_fx( move16(); } -#ifdef FIX_2448_RENDERER_MSAN_ERROR IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx ) -#endif { Word16 proto_power_diff_smooth_temp_q = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len ); Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, proto_power_diff_smooth_temp_q ); // hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q + proto_power_diff_smooth_temp_q @@ -4303,9 +4299,7 @@ static void ivas_masa_ext_dirac_render_sf_fx( move16(); } -#ifdef FIX_2448_RENDERER_MSAN_ERROR IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx ) -#endif { Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) diff --git a/lib_rend/ivas_objectRenderer_fx.c b/lib_rend/ivas_objectRenderer_fx.c index 02e280949751fd866f999f53cd0ba1c50f6f6734..daa06bbf4ff3e02369be234e144727f7f12da5f2 100644 --- a/lib_rend/ivas_objectRenderer_fx.c +++ b/lib_rend/ivas_objectRenderer_fx.c @@ -350,11 +350,8 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( const Word16 ism_md_subframe_update, /* i : Number of subframes to delay ism metadata to sync with audio */ Word32 *output_fx[], /* i/o: SCE channels / Binaural synthesis Q11 */ const Word16 output_frame, /* i : output frame length */ - const Word16 num_subframes /* i : number of subframes to render */ -#ifdef FIX_FLOAT_1528_5MS_REND_ISM_META_DELAY_COMPENSATION - , - Word16 *metaSfCounter /* i/o: subframe counter for metadata update */ -#endif + const Word16 num_subframes, /* i : number of subframes to render */ + Word16 *metaSfCounter /* i/o: subframe counter for metadata update */ ) { Word16 subframe_length; @@ -404,108 +401,95 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( FOR( subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) { -#ifdef FIX_FLOAT_1528_5MS_REND_ISM_META_DELAY_COMPENSATION - IF( EQ_16( *metaSfCounter, ism_md_subframe_update ) ) - { - /* Update object position(s) */ - IF( NE_32( ( error = TDREND_Update_object_positions_fx( hBinRendererTd, num_src, ivas_format, hIsmMetaData ) ), IVAS_ERR_OK ) ) - { - return error; - } - } -#else - IF( EQ_16( subframe_idx, ism_md_subframe_update ) ){ + IF( EQ_16( *metaSfCounter, ism_md_subframe_update ) ){ /* Update object position(s) */ IF( NE_32( ( error = TDREND_Update_object_positions_fx( hBinRendererTd, num_src, ivas_format, hIsmMetaData ) ), IVAS_ERR_OK ) ){ return error; } } -#endif -#ifdef FIX_FLOAT_1528_5MS_REND_ISM_META_DELAY_COMPENSATION - *metaSfCounter = add( *metaSfCounter, 1 ); - IF( EQ_16( *metaSfCounter, 4 ) ) - { - *metaSfCounter = 0; - move16(); - } - -#endif - /* Update the listener's location/orientation */ - Word16 tmp_headRotEnabled; - tmp_headRotEnabled = 0; - move16(); - Word16 tmp_CombinedOrient_subframe_idx; - tmp_CombinedOrient_subframe_idx = 0; - move16(); - IF( enableCombinedOrientation != NULL ) - { - tmp_headRotEnabled = enableCombinedOrientation[hCombinedOrientationData->subframe_idx]; - move16(); - tmp_CombinedOrient_subframe_idx = hCombinedOrientationData->subframe_idx; - move16(); - } - - IF( NE_32( ( error = TDREND_Update_listener_orientation_fx( hBinRendererTd, tmp_headRotEnabled, ( Quaternions != NULL ) ? &Quaternions[tmp_CombinedOrient_subframe_idx] : NULL, ( Pos != NULL ) ? &Pos[tmp_CombinedOrient_subframe_idx] : NULL ) ), IVAS_ERR_OK ) ) - { - return error; - } - - IF( hReverb != NULL ) - { - Word16 i; +*metaSfCounter = add( *metaSfCounter, 1 ); +IF( EQ_16( *metaSfCounter, 4 ) ) +{ + *metaSfCounter = 0; + move16(); +} - FOR( i = 0; i < num_src; ++i ) - { - scale_sig32( output_fx[i], output_frame, -4 ); // Q11 - 4 = Q7 - } +/* Update the listener's location/orientation */ +Word16 tmp_headRotEnabled; +tmp_headRotEnabled = 0; +move16(); +Word16 tmp_CombinedOrient_subframe_idx; +tmp_CombinedOrient_subframe_idx = 0; +move16(); +IF( enableCombinedOrientation != NULL ) +{ + tmp_headRotEnabled = enableCombinedOrientation[hCombinedOrientationData->subframe_idx]; + move16(); + tmp_CombinedOrient_subframe_idx = hCombinedOrientationData->subframe_idx; + move16(); +} - IF( NE_32( ( error = ivas_reverb_process_fx( hReverb, transport_config, 0, output_fx, p_reverb_signal_fx, subframe_idx ) ), IVAS_ERR_OK ) ) // Q p_reverb_signal_fx = Q output_fx - 2 = 5 - { - return error; - } +IF( NE_32( ( error = TDREND_Update_listener_orientation_fx( hBinRendererTd, tmp_headRotEnabled, ( Quaternions != NULL ) ? &Quaternions[tmp_CombinedOrient_subframe_idx] : NULL, ( Pos != NULL ) ? &Pos[tmp_CombinedOrient_subframe_idx] : NULL ) ), IVAS_ERR_OK ) ) +{ + return error; +} - FOR( i = 0; i < num_src; ++i ) - { - scale_sig32( output_fx[i], output_frame, 4 ); // Q7 + 4 = Q11 - } +IF( hReverb != NULL ) +{ + Word16 i; - FOR( i = 0; i < BINAURAL_CHANNELS; ++i ) - { - scale_sig32( p_reverb_signal_fx[i] + subframe_idx * hReverb->full_block_size, hReverb->full_block_size, 2 + 4 ); // Q5 + 6 = Q11 - } - } + FOR( i = 0; i < num_src; ++i ) + { + scale_sig32( output_fx[i], output_frame, -4 ); // Q11 - 4 = Q7 + } - /* Render subframe */ - IF( NE_32( ( error = TDREND_GetMix_fx( hBinRendererTd, output_fx, subframe_length, subframe_idx ) ), IVAS_ERR_OK ) ) - { - return error; - } + IF( NE_32( ( error = ivas_reverb_process_fx( hReverb, transport_config, 0, output_fx, p_reverb_signal_fx, subframe_idx ) ), IVAS_ERR_OK ) ) // Q p_reverb_signal_fx = Q output_fx - 2 = 5 + { + return error; + } - /* Advance subframe pointer */ - c_indx = 0; - move16(); - FOR( nS = 0; nS < num_src; nS++ ) - { - test(); - IF( !( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( nS, lfe_idx ) ) ) /* Skip LFE for MC */ - { - hBinRendererTd->Sources[c_indx]->InputFrame_p_fx += subframe_length; - c_indx = add( c_indx, 1 ); - } - } + FOR( i = 0; i < num_src; ++i ) + { + scale_sig32( output_fx[i], output_frame, 4 ); // Q7 + 4 = Q11 + } - /* update combined orientation access index */ - ivas_combined_orientation_update_index( hCombinedOrientationData, subframe_length ); + FOR( i = 0; i < BINAURAL_CHANNELS; ++i ) + { + scale_sig32( p_reverb_signal_fx[i] + subframe_idx * hReverb->full_block_size, hReverb->full_block_size, 2 + 4 ); // Q5 + 6 = Q11 } +} - IF( hReverb != NULL ) +/* Render subframe */ +IF( NE_32( ( error = TDREND_GetMix_fx( hBinRendererTd, output_fx, subframe_length, subframe_idx ) ), IVAS_ERR_OK ) ) +{ + return error; +} + +/* Advance subframe pointer */ +c_indx = 0; +move16(); +FOR( nS = 0; nS < num_src; nS++ ) +{ + test(); + IF( !( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( nS, lfe_idx ) ) ) /* Skip LFE for MC */ { - v_add_32( reverb_signal_fx[0], output_fx[0], output_fx[0], output_frame ); // Q11 - v_add_32( reverb_signal_fx[1], output_fx[1], output_fx[1], output_frame ); // Q11 + hBinRendererTd->Sources[c_indx]->InputFrame_p_fx += subframe_length; + c_indx = add( c_indx, 1 ); } +} - return IVAS_ERR_OK; +/* update combined orientation access index */ +ivas_combined_orientation_update_index( hCombinedOrientationData, subframe_length ); +} + +IF( hReverb != NULL ) +{ + v_add_32( reverb_signal_fx[0], output_fx[0], output_fx[0], output_frame ); // Q11 + v_add_32( reverb_signal_fx[1], output_fx[1], output_fx[1], output_frame ); // Q11 +} + +return IVAS_ERR_OK; } @@ -902,18 +886,14 @@ ivas_error ivas_td_binaural_open_ext_fx( *---------------------------------------------------------------------*/ ivas_error ivas_td_binaural_renderer_ext_fx( -#ifdef FIX_FLOAT_1528_5MS_REND_ISM_META_DELAY_COMPENSATION - TDREND_WRAPPER *pTDRend, /* i/o: TD Renderer wrapper structure */ -#else - const TDREND_WRAPPER *pTDRend, /* i : TD Renderer wrapper structure */ -#endif + TDREND_WRAPPER *pTDRend, /* i/o: TD Renderer wrapper structure */ const AUDIO_CONFIG inConfig, /* i : Input audio configuration */ const LSSETUP_CUSTOM_HANDLE customLsInput, /* i : Input custom loudspeaker layout */ const COMBINED_ORIENTATION_HANDLE *hCombinedOrientationData, /* i : Combined head and external orientations */ const IVAS_ISM_METADATA *currentPos, /* i : Object position */ const REVERB_HANDLE hReverb, /* i : Reverberator handle */ const Word16 ism_md_subframe_update_ext, /* i : Metadata Delay in subframes to sync with audio delay */ - const Word32 output_Fs, /* i : output sampling rate */ + const Word32 output_Fs, /* i : output sampling rate */ const Word16 output_frame, /* i : output frame length */ Word32 output[][L_FRAME48k], /* i/o: SCE channels / Binaural synthesis Q11 */ Word16 *exp ) @@ -1027,15 +1007,9 @@ ivas_error ivas_td_binaural_renderer_ext_fx( } } -#ifdef FIX_FLOAT_1528_5MS_REND_ISM_META_DELAY_COMPENSATION IF( NE_32( ( error = ivas_td_binaural_renderer_unwrap_fx( hReverb, transport_config, pTDRend->hBinRendererTd, num_src, lfe_idx, ivas_format, hIsmMetaData, *hCombinedOrientationData, ism_md_subframe_update_ext, p_output_fx, output_frame, num_subframes, &pTDRend->metaSfCounter ) ), IVAS_ERR_OK ) ) -#else - IF( NE_32( ( error = ivas_td_binaural_renderer_unwrap_fx( hReverb, transport_config, pTDRend->hBinRendererTd, num_src, lfe_idx, ivas_format, hIsmMetaData, *hCombinedOrientationData, - ism_md_subframe_update_ext, p_output_fx, output_frame, num_subframes ) ), - IVAS_ERR_OK ) ) -#endif { return error; } diff --git a/lib_rend/ivas_prot_rend_fx.h b/lib_rend/ivas_prot_rend_fx.h index 7206a2093c075f84e6a2d824e2119f966aa4df98..92caf486ff2239c99454a54b6bf9ee480db9c3bf 100644 --- a/lib_rend/ivas_prot_rend_fx.h +++ b/lib_rend/ivas_prot_rend_fx.h @@ -670,19 +670,12 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( const Word16 ism_md_subframe_update, /* i : Number of subframes to delay ism metadata to sync with audio */ Word32 *output_fx[], /* i/o: SCE channels / Binaural synthesis Q11 */ const Word16 output_frame, /* i : output frame length */ - const Word16 num_subframes /* i : number of subframes to render */ -#ifdef FIX_FLOAT_1528_5MS_REND_ISM_META_DELAY_COMPENSATION - , + const Word16 num_subframes, /* i : number of subframes to render */ Word16 *metaSfCounter /* i/o: subframe counter for metadata update */ -#endif ); ivas_error ivas_td_binaural_renderer_ext_fx( -#ifdef FIX_FLOAT_1528_5MS_REND_ISM_META_DELAY_COMPENSATION TDREND_WRAPPER *pTDRend, /* i/o: TD Renderer wrapper structure */ -#else - const TDREND_WRAPPER *pTDRend, /* i : TD Renderer wrapper structure */ -#endif const AUDIO_CONFIG inConfig, /* i : Input audio configuration */ const LSSETUP_CUSTOM_HANDLE customLsInput, /* i : Input custom loudspeaker layout */ const COMBINED_ORIENTATION_HANDLE *hCombinedOrientationData,/* i : Combined head and external orientations */ diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 7684dff68a1bb3046024fefc7740280b3a4c64fc..00a5ba8057779d112c4cf58beaf2016a4d6e82c9 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1278,9 +1278,7 @@ typedef struct Word32 binaural_latency_ns; BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd; TDREND_HRFILT_FiltSet_t **hHrtfTD; -#ifdef FIX_FLOAT_1528_5MS_REND_ISM_META_DELAY_COMPENSATION Word16 metaSfCounter; -#endif } TDREND_WRAPPER, *TDREND_WRAPPER_HANDLE; diff --git a/lib_rend/lib_rend_fx.c b/lib_rend/lib_rend_fx.c index 5e49dc0cc06f4876bb148a8a79bef27033fb5b06..8ade538fcc7ba8f30eadcaadc465111ccf885d2f 100644 --- a/lib_rend/lib_rend_fx.c +++ b/lib_rend/lib_rend_fx.c @@ -531,7 +531,6 @@ static void accumulate2dArrayToBuffer_fx( } -#ifdef FIX_BASOP_2436_REUSED_CLDFB_IN_OMASA_SR /*-------------------------------------------------------------------* * audio_buffer_td_to_cldfb_fx() * @@ -612,7 +611,6 @@ static void audio_buffer_td_to_cldfb_fx( } } } -#endif /*-------------------------------------------------------------------* @@ -1511,10 +1509,8 @@ static TDREND_WRAPPER defaultTdRendWrapper( move32(); w.hBinRendererTd = NULL; w.hHrtfTD = NULL; -#ifdef FIX_FLOAT_1528_5MS_REND_ISM_META_DELAY_COMPENSATION w.metaSfCounter = 0; move16(); -#endif return w; } @@ -6608,11 +6604,7 @@ static ivas_error rotateFrameSba_fx( static ivas_error renderIsmToBinaural( -#ifdef FIX_FLOAT_1528_5MS_REND_ISM_META_DELAY_COMPENSATION input_ism *ismInput, -#else - const input_ism *ismInput, -#endif IVAS_REND_AudioBuffer outAudio ) { Word32 tmpTDRendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; @@ -7160,22 +7152,15 @@ static ivas_error renderIsmToSplitBinaural( IVAS_QUATERNION localHeadRot[MAX_PARAM_SPATIAL_SUBFRAMES]; Word16 i; Word32 tmpBinaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][L_FRAME48k]; -#ifndef FIX_BASOP_2436_REUSED_CLDFB_IN_OMASA_SR - Word16 ch, slot_idx, num_bands; - Word32 tmpBinaural_CldfbRe[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 tmpBinaural_CldfbIm[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; -#endif Word16 output_frame = ismInput->base.inputBuffer.config.numSamplesPerChannel; COMBINED_ORIENTATION_HANDLE pCombinedOrientationData; Word16 ism_md_subframe_update_ext, exp; push_wmops( "renderIsmToSplitBinaural" ); -#ifdef FIX_BASOP_2436_REUSED_CLDFB_IN_OMASA_SR assert( !outAudio.config.is_cldfb && "ISM renderering only supports TD output. If CLDFB output was requested, " "we convert to CLDFB higher up the stack after rendering all ISMs" ); -#endif pSplitRendWrapper = ismInput->base.ctx.pSplitRendWrapper; pMultiBinPoseData = &pSplitRendWrapper->multiBinPoseData; @@ -7258,56 +7243,10 @@ static ivas_error renderIsmToSplitBinaural( } } -#ifndef FIX_BASOP_2436_REUSED_CLDFB_IN_OMASA_SR - IF( NE_16( outAudio.config.is_cldfb, 0 ) ) - { - /* Perform CLDFB analysis on rendered audio, since the output buffer is CLDFB domain */ - Word16 q_cldfb; - - q_cldfb = exp; - num_bands = extract_l( Mpy_32_32( imult3216( *ismInput->base.ctx.pOutSampleRate, BINAURAL_MAXBANDS ), 44740 /* 1/48000 in Q31 */ ) ); /* Q0 */ - FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) - { - FOR( slot_idx = 0; slot_idx < IVAS_CLDFB_NO_COL_MAX; slot_idx++ ) - { - cldfbAnalysis_ts_fx( &tmpProcessing[ch][num_bands * slot_idx], - &tmpBinaural_CldfbRe[BINAURAL_CHANNELS * pos_idx + ch][slot_idx][0], - &tmpBinaural_CldfbIm[BINAURAL_CHANNELS * pos_idx + ch][slot_idx][0], - num_bands, -#ifdef FIX_2436_CLDFBANAHANDLE_ADRESS - ismInput->base.ctx.pSplitRendWrapper->hCldfbHandles->cldfbAna[BINAURAL_CHANNELS * pos_idx + ch], -#else - ismInput->base.ctx.pSplitRendWrapper->hCldfbHandles->cldfbAna[pos_idx + ch], -#endif - &q_cldfb ); - /* scale re and im according to exp-q_cldfb */ - { - Word32 *realBuffer_fx = &tmpBinaural_CldfbRe[BINAURAL_CHANNELS * pos_idx + ch][slot_idx][0]; - Word32 *imagBuffer_fx = &tmpBinaural_CldfbIm[BINAURAL_CHANNELS * pos_idx + ch][slot_idx][0]; - Word16 noChannels = ismInput->base.ctx.pSplitRendWrapper->hCldfbHandles->cldfbAna[pos_idx + ch]->no_channels; - - Word16 scale = sub( exp, q_cldfb ); - FOR( Word16 j = 0; j < noChannels; j++ ) - { - realBuffer_fx[j] = L_shl( realBuffer_fx[j], scale ); /*Q(exp)*/ - imagBuffer_fx[j] = L_shl( imagBuffer_fx[j], scale ); /*Q(exp)*/ - } - q_cldfb = exp; - } - } - } - } - ELSE - { -#endif /*FIX_BASOP_2436_REUSED_CLDFB_IN_OMASA_SR*/ - - /* Copy rendered audio to tmp storage buffer. Copying directly to output would - * overwrite original audio, which is still needed for rendering next head pose. */ - Copy32( tmpProcessing[0], tmpBinaural[i_mult( 2, pos_idx )], output_frame ); - Copy32( tmpProcessing[1], tmpBinaural[add( i_mult( 2, pos_idx ), 1 )], output_frame ); -#ifndef FIX_BASOP_2436_REUSED_CLDFB_IN_OMASA_SR - } -#endif + /* Copy rendered audio to tmp storage buffer. Copying directly to output would + * overwrite original audio, which is still needed for rendering next head pose. */ + Copy32( tmpProcessing[0], tmpBinaural[i_mult( 2, pos_idx )], output_frame ); + Copy32( tmpProcessing[1], tmpBinaural[add( i_mult( 2, pos_idx ), 1 )], output_frame ); /* Overwrite processing buffer with original input audio again */ copyBufferTo2dArray_fx( ismInput->base.inputBuffer, tmpProcessing ); @@ -7319,18 +7258,8 @@ static ivas_error renderIsmToSplitBinaural( Copy_Quat_fx( &originalHeadRot[i], &pCombinedOrientationData->Quaternions[i] ); } -#ifndef FIX_BASOP_2436_REUSED_CLDFB_IN_OMASA_SR - if ( outAudio.config.is_cldfb ) - { - accumulateCLDFBArrayToBuffer_fx( tmpBinaural_CldfbRe, tmpBinaural_CldfbIm, exp, &outAudio ); - } - else - { -#endif /*FIX_BASOP_2436_REUSED_CLDFB_IN_OMASA_SR*/ - accumulate2dArrayToBuffer_fx( tmpBinaural, &outAudio ); -#ifndef FIX_BASOP_2436_REUSED_CLDFB_IN_OMASA_SR - } -#endif + accumulate2dArrayToBuffer_fx( tmpBinaural, &outAudio ); + pop_wmops(); /* Encoding to split rendering bitstream done at a higher level */ @@ -7483,8 +7412,6 @@ static ivas_error renderActiveInputsIsm( ivas_error error; Word16 input_q = outAudio.q_factor; move16(); - -#ifdef FIX_BASOP_2436_REUSED_CLDFB_IN_OMASA_SR Word16 num_active_inputs; IVAS_REND_AudioBuffer work_buffer; Word32 tmp_td_binaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS * L_FRAME48k]; @@ -7532,7 +7459,6 @@ static ivas_error renderActiveInputsIsm( move32(); set32_fx( tmp_td_binaural, 0, MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS * L_FRAME48k ); } -#endif FOR( ( i = 0, pCurrentInput = hIvasRend->inputsIsm ); i < RENDERER_MAX_ISM_INPUTS; ( ++i, ++pCurrentInput ) ) { @@ -7544,11 +7470,7 @@ static ivas_error renderActiveInputsIsm( *outAudio.pq_fact = input_q; move16(); -#ifdef FIX_BASOP_2436_REUSED_CLDFB_IN_OMASA_SR IF( NE_32( ( error = renderInputIsm( pCurrentInput, hIvasRend->outputConfig, work_buffer ) ), IVAS_ERR_OK ) ) -#else - IF( NE_32( ( error = renderInputIsm( pCurrentInput, hIvasRend->outputConfig, outAudio ) ), IVAS_ERR_OK ) ) -#endif { return error; } @@ -7562,7 +7484,6 @@ static ivas_error renderActiveInputsIsm( move16(); } -#ifdef FIX_BASOP_2436_REUSED_CLDFB_IN_OMASA_SR IF( outAudio.config.is_cldfb ) { audio_buffer_td_to_cldfb_fx( work_buffer, @@ -7570,7 +7491,6 @@ static ivas_error renderActiveInputsIsm( hIvasRend->sampleRateOut, hIvasRend->splitRendWrapper->hCldfbHandles->cldfbAna ); } -#endif return IVAS_ERR_OK; } @@ -11516,11 +11436,8 @@ static void intermidiate_ext_dirac_render( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] = add( tmp, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] ); move16(); } -#ifdef FIX_BASOP_2475_ASSERT_IN_MASA2_REND_TO_MONO + IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx != NULL && GT_16( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, 0 ) ) -#else - IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx != NULL ) -#endif { tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len ); @@ -11529,11 +11446,7 @@ static void intermidiate_ext_dirac_render( move16(); } -#ifdef FIX_BASOP_2475_ASSERT_IN_MASA2_REND_TO_MONO IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != NULL && GT_16( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, 0 ) ) -#else - IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != NULL ) -#endif { tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q + tmp) */