diff --git a/lib_com/options.h b/lib_com/options.h index 298c4bff0e05d065ad1a156771d4aab1e361d718..484de232aa48b1865b46fd4fea0e4eb7f0a5a0fb 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -176,6 +176,7 @@ #define NONBE_FIX_1196_TD_HEADTRACKING_INTERPOLATION /* Ericsson: Issue 1196, Always apply filter interpolation for each subframe */ #define NONBE_1220_OMASA_JBM_BRATE_SW_FLUSH /* VA: issue 1220: fix bug in renderer flush in OMASA 1ISM JBM bitrate switching */ #define NONBE_1229_FIX_ISM1_DPID /* Eri: issue 1229: fix bug causing ISM 1 to use default -dpid instead of the specified one */ +#define NONBE_1233_HQ_CLASSIFIER_DIV_BY_ZERO /* Eri: issue 1233: Address possible division by zero in hf_spectrum_sparseness() */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_enc/hq_classifier_enc.c b/lib_enc/hq_classifier_enc.c index a41942d658493d35e9d6995f43a78d0241573bf1..b0ef15969b11166728597de7441b65613882d699 100644 --- a/lib_enc/hq_classifier_enc.c +++ b/lib_enc/hq_classifier_enc.c @@ -573,6 +573,60 @@ static int16_t hf_spectrum_sparseness( inv_rms = 0.0f; crest_mod = 0.0f; maximum( A, L_SPEC_HB, &Amax ); +#ifdef NONBE_1233_HQ_CLASSIFIER_DIV_BY_ZERO + if ( Amax == 0 ) + { + /* For all-zero input the crest is 1.0 */ + crest = 1.0f; + crest_mod = 1.0f; + low_count = 0; + } + else + { + thr = Amax * PEAK_THRESHOLD; + movmean = 0.0f; /* avoid uninitialized warning */ + p_num = &inv_tbl[HALF_WIN_LENGTH + 1]; /* Table for division 1./(11:21) */ + for ( i = 0; i < L_SPEC_HB; i++ ) + { + inv_rms += A[i] * A[i]; + if ( A[i] < thr ) + { + low_count += 1; + } + if ( i <= HALF_WIN_LENGTH ) + { + if ( i == 0 ) + { + movmean = sum_f( &A[0], i + HALF_WIN_LENGTH + 1 ) * ( *p_num ); + } + else + { + p_num++; + movmean = movmean + ( A[i + HALF_WIN_LENGTH] - movmean ) * ( *p_num ); + } + } + else + { + if ( L_SPEC_HB <= i + HALF_WIN_LENGTH ) + { + p_num--; + movmean = movmean + ( movmean - A[i - HALF_WIN_LENGTH - 1] ) * ( *p_num ); + } + else + { + movmean = movmean + ( A[i + HALF_WIN_LENGTH] - A[i - HALF_WIN_LENGTH - 1] ) * ( *p_num ); + } + } + if ( crest_mod < movmean ) + { + crest_mod = movmean; + } + } + inv_rms = 1.0f / (float) sqrtf( inv_rms / L_SPEC_HB ); + crest = Amax * inv_rms; + crest_mod = crest_mod * inv_rms; + } +#else thr = Amax * PEAK_THRESHOLD; movmean = 0.0f; /* avoid uninitialized warning */ p_num = &inv_tbl[HALF_WIN_LENGTH + 1]; /* Table for division 1./(11:21) */ @@ -615,6 +669,7 @@ static int16_t hf_spectrum_sparseness( inv_rms = 1.0f / (float) sqrtf( inv_rms / L_SPEC_HB ); crest = Amax * inv_rms; crest_mod = crest_mod * inv_rms; +#endif *crest_lp = HQ_CREST_FAC_SM * ( *crest_lp ) + ( 1.0f - HQ_CREST_FAC_SM ) * crest; *crest_mod_lp = HQ_CREST_FAC_SM * ( *crest_mod_lp ) + ( 1.0f - HQ_CREST_FAC_SM ) * crest_mod;