Loading lib_com/prot_fx.h +10 −0 Original line number Diff line number Diff line Loading @@ -3642,6 +3642,16 @@ Word16 ITF_Detect_fx( Word32 const pSpectrum[], Word16 *curr_order, Word16 Q ); Word16 ITF_Detect_ivas_fx( Word32 const pSpectrum[], const Word16 startLine, const Word16 stopLine, const Word16 maxOrder, Word16 *A, Word16 *Q_A, Word16 *predictionGain, Word16 *curr_order, Word16 Q ); void ITF_Apply_fx( Word32 spectrum[], Word16 startLine, Word16 stopLine, Loading lib_com/tns_base.c +139 −0 Original line number Diff line number Diff line Loading @@ -602,6 +602,145 @@ Word16 ITF_Detect_fx( return 1; } Word16 ITF_Detect_ivas_fx( const Word32 pSpectrum[], /*Q*/ const Word16 startLine, /*Q0*/ const Word16 stopLine, /*Q0*/ const Word16 maxOrder, /*Q0*/ Word16 *A, /*Q_A*/ Word16 *Q_A, Word16 *predictionGain, /*Q7*/ Word16 *curr_order, /*Q0*/ Word16 Q ) { Word32 norms[MAX_SUBDIVISIONS]; Word16 num_subdivisions, i, length; Word16 iStartLine, iEndLine, spectrumLength; Word32 rxx[ITF_MAX_FILTER_ORDER + 1]; Word16 q_rxx[ITF_MAX_FILTER_ORDER + 1]; Word32 temp_spectrum[640]; const Word16 *pWindow; const Word32 *ptr_spectrum1, *ptr_spectrum2; Word16 iSubdivisions, lag; Word16 headroom, guard_bits, shift, q_min; Word64 sum; Word16 fac, q_fac, exp, q_temp; Word32 temp; IF( maxOrder <= 0 ) { return 0; } pWindow = tnsAcfWindow_fx; set_zero_fx( norms, MAX_SUBDIVISIONS ); set_zero_fx( rxx, ITF_MAX_FILTER_ORDER + 1 ); /* This initialization is required */ set16_fx( q_rxx, Q31, ITF_MAX_FILTER_ORDER + 1 ); /* This initialization is required */ spectrumLength = sub( stopLine, startLine ); num_subdivisions = 0; move16(); /* Calculate norms for each spectrum part */ FOR( iSubdivisions = 0; iSubdivisions < MAX_SUBDIVISIONS; iSubdivisions++ ) { /* iStartLine = startLine + ( stopLine - startLine ) * iSubdivisions / nSubdivisions; */ iStartLine = add( startLine, mult( imult1616( spectrumLength, iSubdivisions ), 10923 /* 1/MAX_SUBDIVISIONS in Q15 */ ) ); /*Q0*/ /* iEndLine = startLine + ( stopLine - startLine ) * ( iSubdivisions + 1 ) / nSubdivisions; */ iEndLine = add( startLine, mult( imult1616( spectrumLength, add( iSubdivisions, 1 ) ), 10923 /* 1/MAX_SUBDIVISIONS in Q15 */ ) ); /*Q0*/ /* Variable initialization */ /* norms[iSubdivisions] = sum2_f(pSpectrum + iStartLine - IGF_START_MN, iEndLine - iStartLine); */ ptr_spectrum1 = pSpectrum + sub( iStartLine, IGF_START_MN ); length = sub( iEndLine, iStartLine ); headroom = L_norm_arr( ptr_spectrum1, length ); guard_bits = find_guarded_bits_fx( length ); shift = sub( headroom, guard_bits ); Copy_Scale_sig32( ptr_spectrum1, temp_spectrum, length, shift ); // Q -> Q+shift sum = 0; move64(); FOR( i = 0; i < length; i++ ) { sum = W_mac_32_32( sum, temp_spectrum[i], temp_spectrum[i] ); // 2(Q+shift)+1 } IF( LE_64( sum, W_shl( 32768 * 2 /* HLM_MIN_NRG in Q1 */, shl( add( Q, shift ), 1 ) ) ) ) { BREAK; } /* fac = 1.0f / norms[iSubdivisions]; */ exp = W_norm( sum ); sum = W_shl( sum, exp ); // 2(Q+shift)+1+exp fac = div_s( ONE_IN_Q14, extract_h( W_extract_h( sum ) ) ); // 15+14-(2(Q+shift)+1+exp-48) = 76-(2(Q+shift)+exp) q_fac = sub( 76, add( shl( add( Q, shift ), 1 ), exp ) ); pWindow = tnsAcfWindow_fx; /* For additional loop condition */ /* Variable initialization */ /*for ( lag = 1; lag <= maxOrder; lag++ ) { rxx[lag] += fac * ( *pWindow ) * dotp( pSpectrum + iStartLine - IGF_START_MN, pSpectrum + iStartLine - IGF_START_MN + lag, iEndLine - iStartLine - lag ); pWindow++; }*/ ptr_spectrum1 = temp_spectrum; // pSpectrum + iStartLine - IGF_START_MN; FOR( lag = 1; lag <= maxOrder; lag++ ) { /* dotp( pSpectrum + iStartLine - IGF_START_MN, pSpectrum + iStartLine - IGF_START_MN + lag, iEndLine - iStartLine - lag ) */ ptr_spectrum2 = temp_spectrum + lag; // pSpectrum + iStartLine - IGF_START_MN + lag; sum = 0; move64(); FOR( i = 0; i < iEndLine - iStartLine - lag; i++ ) { sum = W_mac_32_32( sum, ptr_spectrum1[i], ptr_spectrum2[i] ); // 2(Q+shift)+1 } exp = W_norm( sum ); sum = W_shl( sum, exp ); // 2(Q+shift)+1+exp temp = Mpy_32_32( L_mult0( fac, *pWindow ), W_extract_h( sum ) ); // (q_fac+15)+(2(Q+shift)+1+exp-32)-31 = q_fac+2(Q+shift)+exp-47 q_temp = sub( add( q_fac, add( shl( add( Q, shift ), 1 ), exp ) ), 47 ); /* rxx[lag] += fac * (*pWindow) * dotp(pSpectrum + iStartLine - IGF_START_MN, pSpectrum + iStartLine - IGF_START_MN + lag, iEndLine - iStartLine - lag); */ q_min = sub( s_min( q_temp, q_rxx[lag] ), 1 ); rxx[lag] = L_add( L_shl( rxx[lag], sub( q_min, q_rxx[lag] ) ), L_shl( temp, sub( q_min, q_temp ) ) ); q_rxx[lag] = q_min; move32(); move16(); pWindow++; } num_subdivisions = add( num_subdivisions, 1 ); } minimum_s( q_rxx + 1, ITF_MAX_FILTER_ORDER, &q_min ); q_min = s_min( Q29, q_min ); FOR( i = 1; i < ITF_MAX_FILTER_ORDER; i++ ) { rxx[i] = L_shl( rxx[i], sub( q_min, q_rxx[i] ) ); move32(); } IF( EQ_16( iSubdivisions, MAX_SUBDIVISIONS ) ) /* meaning there is no subdivision with low energy */ { rxx[0] = L_shl( MAX_SUBDIVISIONS, q_min ); move32(); /* Limit the maximum order to spectrum length/4 */ ITF_GetFilterParameters_fx( rxx, s_min( maxOrder, shr( spectrumLength, 2 ) ), A, Q_A, predictionGain ); *curr_order = maxOrder; /*Q0*/ move16(); } return 1; } /* Helper functions for Hufmann table coding */ Loading lib_enc/igf_enc.c +2 −2 Original line number Diff line number Diff line Loading @@ -575,8 +575,8 @@ static void IGF_CalculateEnvelope_ivas_fx( strt_cpy = add( strt_cpy, 1 ); } sfbEnergyTileR = L_deposit_l( BASOP_Util_Divide3232_Scale( sfbEnergyTileR, width, &tmp_e ) ); sfbEnergyTileR_e = add( sub( sfbEnergyTileR_e, Q15 ), tmp_e ); sfbEnergyTileR = L_deposit_h( BASOP_Util_Divide3232_Scale( sfbEnergyTileR, width, &tmp_e ) ); sfbEnergyTileR_e = add( sub( sfbEnergyTileR_e, Q31 ), tmp_e ); IF( sfbEnergyTileR == 0 ) { Loading lib_enc/ivas_core_enc.c +4 −4 Original line number Diff line number Diff line Loading @@ -498,14 +498,14 @@ ivas_error ivas_core_enc_fx( IF( EQ_16( nSubframes, NB_DIV ) ) { Word16 max_e = s_max( orig_spectrum_e[i][0], orig_spectrum_e[i][1] ); Scale_sig32( hMCT->p_orig_spectrum_long_fx[cpe_id][i], N_TCX10_MAX, sub( orig_spectrum_e[i][0], max_e ) ); // exp(max_e) Scale_sig32( hMCT->p_orig_spectrum_long_fx[cpe_id][i] + N_TCX10_MAX, N_TCX10_MAX, sub( orig_spectrum_e[i][1], max_e ) ); // exp(max_e) hMCT->q_orig_spectrum_long_fx[cpe_id][i] = max_e; scale_sig32( hMCT->p_orig_spectrum_long_fx[cpe_id][i], N_TCX10_MAX, sub( orig_spectrum_e[i][0], max_e ) ); // exp(max_e) scale_sig32( hMCT->p_orig_spectrum_long_fx[cpe_id][i] + N_TCX10_MAX, N_TCX10_MAX, sub( orig_spectrum_e[i][1], max_e ) ); // exp(max_e) hMCT->q_orig_spectrum_long_fx[cpe_id][i] = sub( Q31, max_e ); move16(); } ELSE { hMCT->q_orig_spectrum_long_fx[cpe_id][i] = orig_spectrum_e[i][0]; hMCT->q_orig_spectrum_long_fx[cpe_id][i] = sub( Q31, orig_spectrum_e[i][0] ); move16(); } Loading lib_enc/ivas_tcx_core_enc.c +1 −1 Original line number Diff line number Diff line Loading @@ -466,7 +466,7 @@ void stereo_tcx_core_enc( E_LPC_lsp_lsf_conversion( lsp_fx, lsf_fx, M ); /* Quantize */ Q_lsf_tcxlpc_fx( lsf_fx, lsf_tcx_q_fx, lspq_ind, param_lpc, M, st->narrowBand, tcx_lpc_cdk, st->mem_MA_fx, st->hTcxCfg->coder_type, st->Bin_E_fx, Q_ener ); Q_lsf_tcxlpc_ivas_fx( lsf_fx, lsf_tcx_q_fx, lspq_ind, param_lpc, M, st->narrowBand, tcx_lpc_cdk, st->mem_MA_fx, st->hTcxCfg->coder_type, st->Bin_E_fx, st->q_Bin_E ); /* Account for consumed bits */ nbits_lpc[0] = TCXLPC_NUMBITS; Loading Loading
lib_com/prot_fx.h +10 −0 Original line number Diff line number Diff line Loading @@ -3642,6 +3642,16 @@ Word16 ITF_Detect_fx( Word32 const pSpectrum[], Word16 *curr_order, Word16 Q ); Word16 ITF_Detect_ivas_fx( Word32 const pSpectrum[], const Word16 startLine, const Word16 stopLine, const Word16 maxOrder, Word16 *A, Word16 *Q_A, Word16 *predictionGain, Word16 *curr_order, Word16 Q ); void ITF_Apply_fx( Word32 spectrum[], Word16 startLine, Word16 stopLine, Loading
lib_com/tns_base.c +139 −0 Original line number Diff line number Diff line Loading @@ -602,6 +602,145 @@ Word16 ITF_Detect_fx( return 1; } Word16 ITF_Detect_ivas_fx( const Word32 pSpectrum[], /*Q*/ const Word16 startLine, /*Q0*/ const Word16 stopLine, /*Q0*/ const Word16 maxOrder, /*Q0*/ Word16 *A, /*Q_A*/ Word16 *Q_A, Word16 *predictionGain, /*Q7*/ Word16 *curr_order, /*Q0*/ Word16 Q ) { Word32 norms[MAX_SUBDIVISIONS]; Word16 num_subdivisions, i, length; Word16 iStartLine, iEndLine, spectrumLength; Word32 rxx[ITF_MAX_FILTER_ORDER + 1]; Word16 q_rxx[ITF_MAX_FILTER_ORDER + 1]; Word32 temp_spectrum[640]; const Word16 *pWindow; const Word32 *ptr_spectrum1, *ptr_spectrum2; Word16 iSubdivisions, lag; Word16 headroom, guard_bits, shift, q_min; Word64 sum; Word16 fac, q_fac, exp, q_temp; Word32 temp; IF( maxOrder <= 0 ) { return 0; } pWindow = tnsAcfWindow_fx; set_zero_fx( norms, MAX_SUBDIVISIONS ); set_zero_fx( rxx, ITF_MAX_FILTER_ORDER + 1 ); /* This initialization is required */ set16_fx( q_rxx, Q31, ITF_MAX_FILTER_ORDER + 1 ); /* This initialization is required */ spectrumLength = sub( stopLine, startLine ); num_subdivisions = 0; move16(); /* Calculate norms for each spectrum part */ FOR( iSubdivisions = 0; iSubdivisions < MAX_SUBDIVISIONS; iSubdivisions++ ) { /* iStartLine = startLine + ( stopLine - startLine ) * iSubdivisions / nSubdivisions; */ iStartLine = add( startLine, mult( imult1616( spectrumLength, iSubdivisions ), 10923 /* 1/MAX_SUBDIVISIONS in Q15 */ ) ); /*Q0*/ /* iEndLine = startLine + ( stopLine - startLine ) * ( iSubdivisions + 1 ) / nSubdivisions; */ iEndLine = add( startLine, mult( imult1616( spectrumLength, add( iSubdivisions, 1 ) ), 10923 /* 1/MAX_SUBDIVISIONS in Q15 */ ) ); /*Q0*/ /* Variable initialization */ /* norms[iSubdivisions] = sum2_f(pSpectrum + iStartLine - IGF_START_MN, iEndLine - iStartLine); */ ptr_spectrum1 = pSpectrum + sub( iStartLine, IGF_START_MN ); length = sub( iEndLine, iStartLine ); headroom = L_norm_arr( ptr_spectrum1, length ); guard_bits = find_guarded_bits_fx( length ); shift = sub( headroom, guard_bits ); Copy_Scale_sig32( ptr_spectrum1, temp_spectrum, length, shift ); // Q -> Q+shift sum = 0; move64(); FOR( i = 0; i < length; i++ ) { sum = W_mac_32_32( sum, temp_spectrum[i], temp_spectrum[i] ); // 2(Q+shift)+1 } IF( LE_64( sum, W_shl( 32768 * 2 /* HLM_MIN_NRG in Q1 */, shl( add( Q, shift ), 1 ) ) ) ) { BREAK; } /* fac = 1.0f / norms[iSubdivisions]; */ exp = W_norm( sum ); sum = W_shl( sum, exp ); // 2(Q+shift)+1+exp fac = div_s( ONE_IN_Q14, extract_h( W_extract_h( sum ) ) ); // 15+14-(2(Q+shift)+1+exp-48) = 76-(2(Q+shift)+exp) q_fac = sub( 76, add( shl( add( Q, shift ), 1 ), exp ) ); pWindow = tnsAcfWindow_fx; /* For additional loop condition */ /* Variable initialization */ /*for ( lag = 1; lag <= maxOrder; lag++ ) { rxx[lag] += fac * ( *pWindow ) * dotp( pSpectrum + iStartLine - IGF_START_MN, pSpectrum + iStartLine - IGF_START_MN + lag, iEndLine - iStartLine - lag ); pWindow++; }*/ ptr_spectrum1 = temp_spectrum; // pSpectrum + iStartLine - IGF_START_MN; FOR( lag = 1; lag <= maxOrder; lag++ ) { /* dotp( pSpectrum + iStartLine - IGF_START_MN, pSpectrum + iStartLine - IGF_START_MN + lag, iEndLine - iStartLine - lag ) */ ptr_spectrum2 = temp_spectrum + lag; // pSpectrum + iStartLine - IGF_START_MN + lag; sum = 0; move64(); FOR( i = 0; i < iEndLine - iStartLine - lag; i++ ) { sum = W_mac_32_32( sum, ptr_spectrum1[i], ptr_spectrum2[i] ); // 2(Q+shift)+1 } exp = W_norm( sum ); sum = W_shl( sum, exp ); // 2(Q+shift)+1+exp temp = Mpy_32_32( L_mult0( fac, *pWindow ), W_extract_h( sum ) ); // (q_fac+15)+(2(Q+shift)+1+exp-32)-31 = q_fac+2(Q+shift)+exp-47 q_temp = sub( add( q_fac, add( shl( add( Q, shift ), 1 ), exp ) ), 47 ); /* rxx[lag] += fac * (*pWindow) * dotp(pSpectrum + iStartLine - IGF_START_MN, pSpectrum + iStartLine - IGF_START_MN + lag, iEndLine - iStartLine - lag); */ q_min = sub( s_min( q_temp, q_rxx[lag] ), 1 ); rxx[lag] = L_add( L_shl( rxx[lag], sub( q_min, q_rxx[lag] ) ), L_shl( temp, sub( q_min, q_temp ) ) ); q_rxx[lag] = q_min; move32(); move16(); pWindow++; } num_subdivisions = add( num_subdivisions, 1 ); } minimum_s( q_rxx + 1, ITF_MAX_FILTER_ORDER, &q_min ); q_min = s_min( Q29, q_min ); FOR( i = 1; i < ITF_MAX_FILTER_ORDER; i++ ) { rxx[i] = L_shl( rxx[i], sub( q_min, q_rxx[i] ) ); move32(); } IF( EQ_16( iSubdivisions, MAX_SUBDIVISIONS ) ) /* meaning there is no subdivision with low energy */ { rxx[0] = L_shl( MAX_SUBDIVISIONS, q_min ); move32(); /* Limit the maximum order to spectrum length/4 */ ITF_GetFilterParameters_fx( rxx, s_min( maxOrder, shr( spectrumLength, 2 ) ), A, Q_A, predictionGain ); *curr_order = maxOrder; /*Q0*/ move16(); } return 1; } /* Helper functions for Hufmann table coding */ Loading
lib_enc/igf_enc.c +2 −2 Original line number Diff line number Diff line Loading @@ -575,8 +575,8 @@ static void IGF_CalculateEnvelope_ivas_fx( strt_cpy = add( strt_cpy, 1 ); } sfbEnergyTileR = L_deposit_l( BASOP_Util_Divide3232_Scale( sfbEnergyTileR, width, &tmp_e ) ); sfbEnergyTileR_e = add( sub( sfbEnergyTileR_e, Q15 ), tmp_e ); sfbEnergyTileR = L_deposit_h( BASOP_Util_Divide3232_Scale( sfbEnergyTileR, width, &tmp_e ) ); sfbEnergyTileR_e = add( sub( sfbEnergyTileR_e, Q31 ), tmp_e ); IF( sfbEnergyTileR == 0 ) { Loading
lib_enc/ivas_core_enc.c +4 −4 Original line number Diff line number Diff line Loading @@ -498,14 +498,14 @@ ivas_error ivas_core_enc_fx( IF( EQ_16( nSubframes, NB_DIV ) ) { Word16 max_e = s_max( orig_spectrum_e[i][0], orig_spectrum_e[i][1] ); Scale_sig32( hMCT->p_orig_spectrum_long_fx[cpe_id][i], N_TCX10_MAX, sub( orig_spectrum_e[i][0], max_e ) ); // exp(max_e) Scale_sig32( hMCT->p_orig_spectrum_long_fx[cpe_id][i] + N_TCX10_MAX, N_TCX10_MAX, sub( orig_spectrum_e[i][1], max_e ) ); // exp(max_e) hMCT->q_orig_spectrum_long_fx[cpe_id][i] = max_e; scale_sig32( hMCT->p_orig_spectrum_long_fx[cpe_id][i], N_TCX10_MAX, sub( orig_spectrum_e[i][0], max_e ) ); // exp(max_e) scale_sig32( hMCT->p_orig_spectrum_long_fx[cpe_id][i] + N_TCX10_MAX, N_TCX10_MAX, sub( orig_spectrum_e[i][1], max_e ) ); // exp(max_e) hMCT->q_orig_spectrum_long_fx[cpe_id][i] = sub( Q31, max_e ); move16(); } ELSE { hMCT->q_orig_spectrum_long_fx[cpe_id][i] = orig_spectrum_e[i][0]; hMCT->q_orig_spectrum_long_fx[cpe_id][i] = sub( Q31, orig_spectrum_e[i][0] ); move16(); } Loading
lib_enc/ivas_tcx_core_enc.c +1 −1 Original line number Diff line number Diff line Loading @@ -466,7 +466,7 @@ void stereo_tcx_core_enc( E_LPC_lsp_lsf_conversion( lsp_fx, lsf_fx, M ); /* Quantize */ Q_lsf_tcxlpc_fx( lsf_fx, lsf_tcx_q_fx, lspq_ind, param_lpc, M, st->narrowBand, tcx_lpc_cdk, st->mem_MA_fx, st->hTcxCfg->coder_type, st->Bin_E_fx, Q_ener ); Q_lsf_tcxlpc_ivas_fx( lsf_fx, lsf_tcx_q_fx, lspq_ind, param_lpc, M, st->narrowBand, tcx_lpc_cdk, st->mem_MA_fx, st->hTcxCfg->coder_type, st->Bin_E_fx, st->q_Bin_E ); /* Account for consumed bits */ nbits_lpc[0] = TCXLPC_NUMBITS; Loading