From 09fdd5e51e4b08e67f831c99081e75d4b3acfa1b Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Wed, 24 Sep 2025 09:44:56 +0200 Subject: [PATCH] Add clipping test feature under DEBUGGING --- apps/encoder.c | 8 ++++++++ lib_com/prot.h | 11 +++++++++++ lib_com/tools.c | 40 ++++++++++++++++++++++++++++++++++++++++ lib_enc/ivas_cpe_enc.c | 4 ++++ lib_enc/ivas_init_enc.c | 5 +++++ lib_enc/ivas_ism_enc.c | 4 ++++ lib_enc/ivas_sce_enc.c | 4 ++++ lib_enc/ivas_stat_enc.h | 5 +++++ lib_enc/lib_enc.c | 20 ++++++++++++++++++++ lib_enc/lib_enc.h | 7 +++++++ 10 files changed, 108 insertions(+) diff --git a/apps/encoder.c b/apps/encoder.c index 91c4b58d1..4ff6171dd 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -211,6 +211,8 @@ int main( #ifdef DEBUG_SBA int16_t numTransportChannels = 1; #endif + int32_t noClipping; + float maxOverload, minOverload; #endif #ifdef DEBUGGING @@ -820,6 +822,12 @@ int main( } #ifdef DEBUGGING + if ( ( noClipping = IVAS_ENC_GetNoCLipping( hIvasEnc, &maxOverload, &minOverload ) ) > 0 ) + { + fprintf( stdout, "Core input overload detected: %d samples!!!\n", noClipping ); + fprintf( stdout, "Max overload value: %f \n", maxOverload ); + fprintf( stdout, "Min overload value: %f \n\n", minOverload ); + } print_snr(); #endif /*------------------------------------------------------------------------------------------* diff --git a/lib_com/prot.h b/lib_com/prot.h index c15608e73..fa039ea74 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -215,6 +215,17 @@ void mvr2r( const int16_t n /* i : vector size */ ); +#ifdef DEBUGGING +/*! r: number of overload samples */ +uint32_t check_clipping( + const float x[], /* i : input vector */ + const int16_t n, /* i : vector size */ + float *maxOverload, /* i/o: max overload value */ + float *minOverload /* i/o: max overload value */ +); + +#endif +/*! r: number of clipped samples */ void mvs2s( const int16_t x[], /* i : input vector */ int16_t y[], /* o : output vector */ diff --git a/lib_com/tools.c b/lib_com/tools.c index ca374507a..6945a9575 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -373,6 +373,46 @@ void mvs2s( return; } +#ifdef DEBUGGING +/*! r: number of overload samples */ +uint32_t check_clipping( + const float x[], /* i : input vector */ + const int16_t n, /* i : vector size */ + float *maxOverload, /* i/o: max overload value */ + float *minOverload /* i/o: max overload value */ +) +{ + int16_t i; + float temp; + uint32_t noClipping = 0; + + for ( i = 0; i < n; i++ ) + { + temp = x[i]; + + if ( temp >= ( MAX16B_FLT + 0.5f ) ) + { + noClipping++; + if ( temp > *maxOverload ) + { + *maxOverload = temp; + } + } + else if ( temp <= ( MIN16B_FLT - 0.5f ) ) + { + noClipping++; + if ( temp < *minOverload ) + { + *minOverload = temp; + } + } + } + + return noClipping; +} + +#endif +/*! r: number of clipped samples */ uint32_t mvr2s( const float x[], /* i : input vector */ int16_t y[], /* o : output vector */ diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 42ec9f842..6761e54ed 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -501,6 +501,10 @@ ivas_error ivas_cpe_enc( for ( n = 0; n < n_CoreChannels; n++ ) { +#ifdef DEBUGGING + st_ivas->noClipping += check_clipping( hCPE->hCoreCoder[n]->input, input_frame, &st_ivas->maxOverload, &st_ivas->minOverload ); + +#endif error = pre_proc_front_ivas( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8[n], old_inp_16k[n], &ener[n], &relE[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], &vad_hover_flag[n], &attack_flag[n], realBuffer[n], imagBuffer[n], old_wsp[n], pitch_fr[n], voicing_fr[n], &loc_harm[n], &cor_map_sum[n], &vad_flag_dtx[n], enerBuffer[n], diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 89d4d6ddf..2143af94d 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -413,6 +413,11 @@ ivas_error ivas_init_encoder( st_ivas->nchan_transport = -1; +#ifdef DEBUGGING + st_ivas->noClipping = 0; + st_ivas->maxOverload = 0; + st_ivas->minOverload = 0; +#endif /*-----------------------------------------------------------------* * Allocate floating-point input audio buffers *-----------------------------------------------------------------*/ diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 3cb1d9816..e2df76f1c 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -179,6 +179,10 @@ ivas_error ivas_ism_enc( * Front Pre-processing *----------------------------------------------------------------*/ +#ifdef DEBUGGING + st_ivas->noClipping += check_clipping( hSCE->hCoreCoder[0]->input, input_frame, &st_ivas->maxOverload, &st_ivas->minOverload ); + +#endif error = pre_proc_front_ivas( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8[sce_id][0], old_inp_16k[sce_id][0], &ener[sce_id][0], &relE[sce_id][0], A[sce_id][0], Aw[sce_id][0], epsP[sce_id][0], lsp_new[sce_id][0], lsp_mid[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], realBuffer[sce_id][0], imagBuffer[sce_id][0], old_wsp[sce_id][0], pitch_fr[sce_id][0], voicing_fr[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer[sce_id][0], diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 5fcc1980e..02d81d083 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -182,6 +182,10 @@ ivas_error ivas_sce_enc( * Front Pre-processing *----------------------------------------------------------------*/ +#ifdef DEBUGGING + st_ivas->noClipping += check_clipping( hSCE->hCoreCoder[0]->input, input_frame, &st_ivas->maxOverload, &st_ivas->minOverload ); + +#endif error = pre_proc_front_ivas( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8[0], old_inp_16k[0], &ener[0], &relE[0], A[0], Aw[0], epsP[0], lsp_new[0], lsp_mid[0], &vad_hover_flag[0], &attack_flag[0], realBuffer[0], imagBuffer[0], old_wsp[0], pitch_fr[0], voicing_fr[0], &loc_harm[0], &cor_map_sum[0], &vad_flag_dtx[0], enerBuffer[0], diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 44c5c5ea1..e5ca0102a 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1254,6 +1254,11 @@ typedef struct int16_t nCPE; /* number of total CPEs */ SCE_ENC_HANDLE hSCE[MAX_SCE]; /* SCE handles */ CPE_ENC_HANDLE hCPE[MCT_MAX_BLOCKS]; /* CPE handles */ +#ifdef DEBUGGING + int32_t noClipping; /* number of clipped samples */ + float maxOverload; /* Maximum overload value */ + float minOverload; /* Maximum overload value */ +#endif /* multichannel modules */ ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS]; /* ISM metadata handles (storage for one frame of read ISM metadata) */ diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 1685ef7c8..157b8ce7a 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -2455,3 +2455,23 @@ static void init_encoder_config( return; } + +#ifdef DEBUGGING + +/*---------------------------------------------------------------------* + * IVAS_ENC_GetNoCLipping() + * + * return number of clipped samples + *---------------------------------------------------------------------*/ + +int32_t IVAS_ENC_GetNoCLipping( + IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */ + float *maxOverload, /* o : Max overload value */ + float *minOverload /* o : Min overload value */ +) +{ + *maxOverload = hIvasEnc->st_ivas->maxOverload; + *minOverload = hIvasEnc->st_ivas->minOverload; + return hIvasEnc->st_ivas->noClipping; +} +#endif diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index 5a42c3dad..567db4a97 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -391,6 +391,13 @@ void IVAS_ENC_PrintDisclaimer( void ); +#ifdef DEBUGGING +int32_t IVAS_ENC_GetNoCLipping( + IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */ + float *maxOverload, /* o : Max overload value */ + float *minOverload /* o : Min overload value */ +); +#endif /* clang-format on */ #endif /* LIB_ENC_H */ -- GitLab