From ca2bd30cfd6a4d1fab081ba8b87e7abf512a2def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20Toftg=C3=A5rd?= Date: Tue, 30 Aug 2022 09:16:12 +0200 Subject: [PATCH 01/13] Fix for issue 59, under define FIX_I59. - Correcting delay of LFE using binaural_latency_ns instead of latency_s for total latency of binaural renderer. - Corrected delay compensation for TD renderer by removing IVAS_FB_DEC_DELAY_NS and do rounding in samples instead of in nanosecond. --- lib_com/delay_comp.c | 10 +++++++++- lib_com/ivas_prot.h | 4 ++++ lib_com/options.h | 1 + lib_com/prot.h | 2 ++ lib_dec/ivas_binauralRenderer.c | 4 ++++ lib_dec/ivas_dec.c | 5 +++++ lib_dec/ivas_init_dec.c | 4 ++++ lib_dec/ivas_lfe_dec.c | 13 +++++++++++++ lib_dec/ivas_stat_dec.h | 4 ++++ lib_dec/lib_dec.c | 5 ++++- lib_enc/lib_enc.c | 4 ++++ .../tests/unit_tests/crend/ivas_crend_utest_utils.c | 4 ++++ 12 files changed, 58 insertions(+), 2 deletions(-) diff --git a/lib_com/delay_comp.c b/lib_com/delay_comp.c index a957150b93..047b4d154c 100644 --- a/lib_com/delay_comp.c +++ b/lib_com/delay_comp.c @@ -54,8 +54,10 @@ float get_delay( const int16_t what_delay, /* i : what delay? (ENC or DEC) */ const int32_t io_fs, /* i : input/output sampling frequency */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ +#ifndef FIX_I59 HANDLE_CLDFB_FILTER_BANK hCldfb, /* i : Handle of Cldfb analysis */ RENDERER_TYPE renderer_type, /* i : IVAS rendering type */ +#endif const int32_t binaural_latency_ns /* i : binaural renderer HRTF delay in ns */ ) { @@ -94,7 +96,12 @@ float get_delay( else /* IVAS */ { delay = IVAS_DEC_DELAY_NS; - +#ifdef FIX_I59 + /* compensate for binaural renderer delay */ + { + delay += binaural_latency_ns; + } +#else if ( hCldfb != NULL || renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) { delay += IVAS_FB_DEC_DELAY_NS; @@ -104,6 +111,7 @@ float get_delay( { delay += binaural_latency_ns; } +#endif } } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 497c6a6bef..4ea1c98606 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4815,7 +4815,11 @@ void ivas_lfe_enc( ivas_error ivas_create_lfe_dec( LFE_DEC_HANDLE *hLFE_out, /* o : IVAS LFE decoder structure */ const int32_t output_Fs, /* i : output sampling rate */ +#ifdef FIX_I59 + const int32_t binaural_latency_ns /* i : additional LFE delay to sync with binaural renderer */ +#else const float add_delay_s /* i : additional LFE delay to sync with binaural filter */ +#endif ); void ivas_lfe_dec_close( diff --git a/lib_com/options.h b/lib_com/options.h index 77a14be529..c34eadfe94 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -153,6 +153,7 @@ #define FIX_I87 /* fix for issue 86: incorrect Ambisonics order set for head rotation in SBA */ +#define FIX_I59 /* fix for issue 59: correcting delay of LFE and delay compensation */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_com/prot.h b/lib_com/prot.h index d9b238bdf0..7b18b9ae49 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -716,8 +716,10 @@ float get_delay( const int16_t what_delay, /* i : what delay? (ENC or DEC) */ const int32_t io_fs, /* i : input/output sampling frequency */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ +#ifndef FIX_I59 HANDLE_CLDFB_FILTER_BANK hCldfb, /* i : Handle of Cldfb analysis */ RENDERER_TYPE renderer_type, /* i : IVAS rendering type */ +#endif const int32_t binaural_latency_ns /* i : binaural renderer HRTF delay in ns */ ); diff --git a/lib_dec/ivas_binauralRenderer.c b/lib_dec/ivas_binauralRenderer.c index 153e159adc..c000016355 100644 --- a/lib_dec/ivas_binauralRenderer.c +++ b/lib_dec/ivas_binauralRenderer.c @@ -496,6 +496,10 @@ ivas_error ivas_binRenderer_open( st_ivas->binaural_latency_ns = (int32_t) ( FASTCONV_HOA3_latency_s * 1000000000.f ); } } +#ifdef FIX_I59 + /* Add CLDFB delay */ + st_ivas->binaural_latency_ns += IVAS_FB_DEC_DELAY_NS; +#endif /* Allocate memories needed for reverb module */ if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM && st_ivas->hRenderConfig->roomAcoustics.late_reverb_on ) diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index a103c9f45f..dcd5c68991 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -390,8 +390,13 @@ ivas_error ivas_dec( } if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) { +#ifdef FIX_I59 + ivas_binaural_cldfb( st_ivas, output ); + ivas_binaural_add_LFE( st_ivas, output_frame, output ); +#else ivas_binaural_add_LFE( st_ivas, output_frame, output ); ivas_binaural_cldfb( st_ivas, output ); +#endif } else if ( st_ivas->renderer_type == RENDERER_MC ) { diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index a682cd3c58..9092e42f0c 100755 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1277,7 +1277,11 @@ ivas_error ivas_init_decoder( if ( st_ivas->mc_mode == MC_MODE_MCT ) { +#ifdef FIX_I59 + if ( ( error = ivas_create_lfe_dec( &st_ivas->hLFE, output_Fs, st_ivas->binaural_latency_ns ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_create_lfe_dec( &st_ivas->hLFE, output_Fs, st_ivas->hHrtf != NULL ? st_ivas->hHrtf->latency_s : 0 ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_dec/ivas_lfe_dec.c b/lib_dec/ivas_lfe_dec.c index a909801b8f..8033782e86 100644 --- a/lib_dec/ivas_lfe_dec.c +++ b/lib_dec/ivas_lfe_dec.c @@ -352,7 +352,11 @@ void ivas_lfe_dec( ivas_error ivas_create_lfe_dec( LFE_DEC_HANDLE *hLFE_out, /* o : IVAS LFE decoder structure */ const int32_t output_Fs, /* i : output sampling rate */ +#ifdef FIX_I59 + const int32_t binaural_latency_ns /* i : additional LFE delay to sync with binaural renderer */ +#else const float add_delay_s /* i : additional LFE delay to sync with binaural filter */ +#endif ) { float low_pass_delay_dec_out, block_offset_s; @@ -361,6 +365,9 @@ ivas_error ivas_create_lfe_dec( LFE_DEC_HANDLE hLFE; float lfe_addl_delay_s; int16_t i, j; +#ifdef FIX_I59 + int16_t add_delay_sa; +#endif low_pass_delay_dec_out = 0; block_offset_s = 0; @@ -436,8 +443,14 @@ ivas_error ivas_create_lfe_dec( lfe_addl_delay_s = block_offset_s - hLFE->lfe_block_delay_s; lfe_addl_delay_s = max( 0.0f, lfe_addl_delay_s ); +#ifdef FIX_I59 + add_delay_sa = NS2SA( output_Fs, binaural_latency_ns + 0.5f ); + hLFE->lfe_addl_delay = (int16_t) ( lfe_addl_delay_s * output_Fs ) + add_delay_sa; + hLFE->lfe_block_delay_s += lfe_addl_delay_s + add_delay_sa / output_Fs; +#else hLFE->lfe_addl_delay = (int16_t) ( lfe_addl_delay_s * output_Fs ) + (int16_t) roundf( add_delay_s * output_Fs ); hLFE->lfe_block_delay_s += lfe_addl_delay_s + add_delay_s; +#endif if ( hLFE->lfe_addl_delay > 0 ) { diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index f8f1c5cb85..a65f30cfc9 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -2004,7 +2004,11 @@ typedef struct Decoder_Struct float *hoa_dec_mtx; /* Pointer to decoder matrix for SBA */ HEAD_TRACK_DATA_HANDLE hHeadTrackData; /* Head tracking data structure */ RENDER_CONFIG_DATA *hRenderConfig; /* Renderer config pointer */ +#ifdef FIX_I59 + int32_t binaural_latency_ns; /* Binaural renderer latency in ns */ +#else int32_t binaural_latency_ns; /* HRTF binauralization latency in ns */ +#endif #ifdef DEBUGGING int32_t noClipping; /* number of clipped samples */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index fd27442c37..92c02bbd8e 100755 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1060,8 +1060,11 @@ ivas_error IVAS_DEC_GetDelay( st_ivas = hIvasDec->st_ivas; hDecoderConfig = st_ivas->hDecoderConfig; - +#ifdef FIX_I59 + *nSamples = NS2SA( hDecoderConfig->output_Fs, get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->binaural_latency_ns ) + 0.5f ); +#else *nSamples = NS2SA( hDecoderConfig->output_Fs, (int32_t) ( get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], st_ivas->renderer_type, st_ivas->binaural_latency_ns ) + 0.5f ) ); +#endif *timeScale = hDecoderConfig->output_Fs; diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 760ae0d353..3a4beaf315 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -940,7 +940,11 @@ ivas_error IVAS_ENC_GetDelay( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } +#ifdef FIX_I59 + *delay = NS2SA( hEncoderConfig->input_Fs, get_delay( ENC, hEncoderConfig->input_Fs, hEncoderConfig->ivas_format, 0 ) + 0.5f ); +#else *delay = NS2SA( hEncoderConfig->input_Fs, (int32_t) ( get_delay( ENC, hEncoderConfig->input_Fs, hEncoderConfig->ivas_format, NULL, RENDERER_DISABLE, 0 ) + 0.5f ) ); +#endif *delay *= hEncoderConfig->nchan_inp; diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c index d993405b11..c47a0c86c3 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c @@ -1307,7 +1307,11 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl } if ( st_ivas.ivas_format == MC_FORMAT ) { +#ifdef FIX_I59 + ivas_create_lfe_dec( &st_ivas.hLFE, st_ivas.hDecoderConfig->output_Fs, (int32_t) ( pIo_params->latency_s * 1000000000.f ) ); +#else ivas_create_lfe_dec( &st_ivas.hLFE, st_ivas.hDecoderConfig->output_Fs, pIo_params->latency_s ); +#endif if ( st_ivas.hLFE->lfe_addl_delay > 0 ) { if ( st_ivas.hLFE->lfe_delay_buf != NULL ) -- GitLab From 95170560fd7df37fc08d62a456b4b92cf0e4a9d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20Toftg=C3=A5rd?= Date: Wed, 31 Aug 2022 07:12:29 +0200 Subject: [PATCH 02/13] Fix for non-binaural delay compensation. Adding filterbank delay when there is not binaural rendering (and it is used). Using binaural_latency_ns > 0 as indicator. --- lib_com/delay_comp.c | 10 ++++++++-- lib_com/prot.h | 2 +- lib_dec/lib_dec.c | 2 +- lib_enc/lib_enc.c | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib_com/delay_comp.c b/lib_com/delay_comp.c index 047b4d154c..e9c857b423 100644 --- a/lib_com/delay_comp.c +++ b/lib_com/delay_comp.c @@ -54,8 +54,8 @@ float get_delay( const int16_t what_delay, /* i : what delay? (ENC or DEC) */ const int32_t io_fs, /* i : input/output sampling frequency */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ -#ifndef FIX_I59 HANDLE_CLDFB_FILTER_BANK hCldfb, /* i : Handle of Cldfb analysis */ +#ifndef FIX_I59 RENDERER_TYPE renderer_type, /* i : IVAS rendering type */ #endif const int32_t binaural_latency_ns /* i : binaural renderer HRTF delay in ns */ @@ -97,10 +97,16 @@ float get_delay( { delay = IVAS_DEC_DELAY_NS; #ifdef FIX_I59 - /* compensate for binaural renderer delay */ + if ( binaural_latency_ns > 0 ) { + /* compensate for binaural renderer delay */ delay += binaural_latency_ns; } + else if ( hCldfb != NULL ) + { + /* compensate for filterbank delay */ + delay += IVAS_FB_DEC_DELAY_NS; + } #else if ( hCldfb != NULL || renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) { diff --git a/lib_com/prot.h b/lib_com/prot.h index 7b18b9ae49..4837495fe1 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -716,8 +716,8 @@ float get_delay( const int16_t what_delay, /* i : what delay? (ENC or DEC) */ const int32_t io_fs, /* i : input/output sampling frequency */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ -#ifndef FIX_I59 HANDLE_CLDFB_FILTER_BANK hCldfb, /* i : Handle of Cldfb analysis */ +#ifndef FIX_I59 RENDERER_TYPE renderer_type, /* i : IVAS rendering type */ #endif const int32_t binaural_latency_ns /* i : binaural renderer HRTF delay in ns */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 92c02bbd8e..77be1e198c 100755 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1061,7 +1061,7 @@ ivas_error IVAS_DEC_GetDelay( st_ivas = hIvasDec->st_ivas; hDecoderConfig = st_ivas->hDecoderConfig; #ifdef FIX_I59 - *nSamples = NS2SA( hDecoderConfig->output_Fs, get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->binaural_latency_ns ) + 0.5f ); + *nSamples = NS2SA( hDecoderConfig->output_Fs, get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], st_ivas->binaural_latency_ns ) + 0.5f ); #else *nSamples = NS2SA( hDecoderConfig->output_Fs, (int32_t) ( get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], st_ivas->renderer_type, st_ivas->binaural_latency_ns ) + 0.5f ) ); #endif diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 3a4beaf315..8a375269e7 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -941,7 +941,7 @@ ivas_error IVAS_ENC_GetDelay( } #ifdef FIX_I59 - *delay = NS2SA( hEncoderConfig->input_Fs, get_delay( ENC, hEncoderConfig->input_Fs, hEncoderConfig->ivas_format, 0 ) + 0.5f ); + *delay = NS2SA( hEncoderConfig->input_Fs, get_delay( ENC, hEncoderConfig->input_Fs, hEncoderConfig->ivas_format, NULL, 0 ) + 0.5f ); #else *delay = NS2SA( hEncoderConfig->input_Fs, (int32_t) ( get_delay( ENC, hEncoderConfig->input_Fs, hEncoderConfig->ivas_format, NULL, RENDERER_DISABLE, 0 ) + 0.5f ) ); #endif -- GitLab From ea0dc612a6a162f895b729b6402d0af5c9ab87e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20Toftg=C3=A5rd?= Date: Thu, 22 Sep 2022 10:34:02 +0200 Subject: [PATCH 03/13] Removed filterbank delay from binaural_latency_ns. --- lib_com/delay_comp.c | 14 +++++++------- lib_com/prot.h | 4 +++- lib_dec/ivas_init_dec.c | 11 ++++++++++- lib_dec/ivas_stat_dec.h | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/lib_com/delay_comp.c b/lib_com/delay_comp.c index e9c857b423..dd2584d40a 100644 --- a/lib_com/delay_comp.c +++ b/lib_com/delay_comp.c @@ -57,8 +57,10 @@ float get_delay( HANDLE_CLDFB_FILTER_BANK hCldfb, /* i : Handle of Cldfb analysis */ #ifndef FIX_I59 RENDERER_TYPE renderer_type, /* i : IVAS rendering type */ -#endif const int32_t binaural_latency_ns /* i : binaural renderer HRTF delay in ns */ +#else + const int32_t binaural_latency_ns /* i : binauralization delay in ns */ +#endif ) { float delay = 0; @@ -97,16 +99,14 @@ float get_delay( { delay = IVAS_DEC_DELAY_NS; #ifdef FIX_I59 - if ( binaural_latency_ns > 0 ) - { - /* compensate for binaural renderer delay */ - delay += binaural_latency_ns; - } - else if ( hCldfb != NULL ) + if ( hCldfb != NULL ) { /* compensate for filterbank delay */ delay += IVAS_FB_DEC_DELAY_NS; } + + /* compensate for binauralization delay */ + delay += binaural_latency_ns; #else if ( hCldfb != NULL || renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) { diff --git a/lib_com/prot.h b/lib_com/prot.h index 4837495fe1..3c2ecf2759 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -719,8 +719,10 @@ float get_delay( HANDLE_CLDFB_FILTER_BANK hCldfb, /* i : Handle of Cldfb analysis */ #ifndef FIX_I59 RENDERER_TYPE renderer_type, /* i : IVAS rendering type */ -#endif const int32_t binaural_latency_ns /* i : binaural renderer HRTF delay in ns */ +#else + const int32_t binaural_latency_ns /* i : binauralization delay in ns */ +#endif ); void decision_matrix_enc( diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 9092e42f0c..2b0f605514 100755 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -619,6 +619,9 @@ ivas_error ivas_init_decoder( AUDIO_CONFIG output_config; DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; +#ifdef FIX_I59 + int32_t lfe_delay; +#endif error = IVAS_ERR_OK; @@ -1278,7 +1281,13 @@ ivas_error ivas_init_decoder( if ( st_ivas->mc_mode == MC_MODE_MCT ) { #ifdef FIX_I59 - if ( ( error = ivas_create_lfe_dec( &st_ivas->hLFE, output_Fs, st_ivas->binaural_latency_ns ) ) != IVAS_ERR_OK ) + lfe_delay = st_ivas->binaural_latency_ns; + if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + { + /* Account for filterbank delay */ + lfe_delay += IVAS_FB_DEC_DELAY_NS; + } + if ( ( error = ivas_create_lfe_dec( &st_ivas->hLFE, output_Fs, lfe_delay ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_create_lfe_dec( &st_ivas->hLFE, output_Fs, st_ivas->hHrtf != NULL ? st_ivas->hHrtf->latency_s : 0 ) ) != IVAS_ERR_OK ) #endif diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index a65f30cfc9..92f4a699e3 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -2005,7 +2005,7 @@ typedef struct Decoder_Struct HEAD_TRACK_DATA_HANDLE hHeadTrackData; /* Head tracking data structure */ RENDER_CONFIG_DATA *hRenderConfig; /* Renderer config pointer */ #ifdef FIX_I59 - int32_t binaural_latency_ns; /* Binaural renderer latency in ns */ + int32_t binaural_latency_ns; /* Binauralization latency in ns */ #else int32_t binaural_latency_ns; /* HRTF binauralization latency in ns */ #endif -- GitLab From 6f1554c58950125b9d57050bc794a883c8977a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20Toftg=C3=A5rd?= Date: Mon, 17 Oct 2022 18:02:26 +0200 Subject: [PATCH 04/13] Removing incorrect delay component for CLDFB renderer. --- lib_dec/ivas_binauralRenderer.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib_dec/ivas_binauralRenderer.c b/lib_dec/ivas_binauralRenderer.c index 776c759171..b3d298b562 100644 --- a/lib_dec/ivas_binauralRenderer.c +++ b/lib_dec/ivas_binauralRenderer.c @@ -589,10 +589,6 @@ ivas_error ivas_binRenderer_open( st_ivas->binaural_latency_ns = (int32_t) ( FASTCONV_HOA3_latency_s * 1000000000.f ); } } -#ifdef FIX_I59 - /* Add CLDFB delay */ - st_ivas->binaural_latency_ns += IVAS_FB_DEC_DELAY_NS; -#endif /* Allocate memories needed for reverb module */ if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM && st_ivas->hRenderConfig->roomAcoustics.late_reverb_on ) -- GitLab From e1167220a8e7ab75c29c1d34bfb745c529915bb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20Toftg=C3=A5rd?= Date: Mon, 17 Oct 2022 18:04:48 +0200 Subject: [PATCH 05/13] - Dividing into separate defines for the three components of the fix. - Correcting delay compensation for case when render_lfe is 0. --- lib_com/delay_comp.c | 4 +-- lib_com/ivas_prot.h | 4 +-- lib_com/options.h | 4 ++- lib_com/prot.h | 2 +- lib_dec/ivas_dec.c | 2 +- lib_dec/ivas_init_dec.c | 27 +++++++++++++------ lib_dec/ivas_lfe_dec.c | 10 +++---- lib_dec/ivas_stat_dec.h | 2 +- lib_dec/lib_dec.c | 10 ++++++- lib_enc/lib_enc.c | 10 ++++++- .../unit_tests/crend/ivas_crend_utest_utils.c | 2 +- 11 files changed, 53 insertions(+), 24 deletions(-) diff --git a/lib_com/delay_comp.c b/lib_com/delay_comp.c index dd2584d40a..7d0ba19485 100644 --- a/lib_com/delay_comp.c +++ b/lib_com/delay_comp.c @@ -55,7 +55,7 @@ float get_delay( const int32_t io_fs, /* i : input/output sampling frequency */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ HANDLE_CLDFB_FILTER_BANK hCldfb, /* i : Handle of Cldfb analysis */ -#ifndef FIX_I59 +#ifndef FIX_I59_LFE_TD_DELAY RENDERER_TYPE renderer_type, /* i : IVAS rendering type */ const int32_t binaural_latency_ns /* i : binaural renderer HRTF delay in ns */ #else @@ -98,7 +98,7 @@ float get_delay( else /* IVAS */ { delay = IVAS_DEC_DELAY_NS; -#ifdef FIX_I59 +#ifdef FIX_I59_LFE_TD_DELAY if ( hCldfb != NULL ) { /* compensate for filterbank delay */ diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 0b8eea3487..a16cfec163 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4841,8 +4841,8 @@ void ivas_lfe_enc( ivas_error ivas_create_lfe_dec( LFE_DEC_HANDLE *hLFE_out, /* o : IVAS LFE decoder structure */ const int32_t output_Fs, /* i : output sampling rate */ -#ifdef FIX_I59 - const int32_t binaural_latency_ns /* i : additional LFE delay to sync with binaural renderer */ +#ifdef FIX_I59_LFE_TD_DELAY + const int32_t binauralization_delay_ns /* i : additional LFE delay to sync with binaural renderer */ #else const float add_delay_s /* i : additional LFE delay to sync with binaural filter */ #endif diff --git a/lib_com/options.h b/lib_com/options.h index 5db73b211c..bafd0e9e3c 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -155,7 +155,9 @@ #define SRAM_REDUCTION_BINRENDERER /* Issue 145: reduction of static RAM usage in fastconv binaural renderer */ #define SRAM_REDUCTION_BINRENDERER_ROOM /* Issue 145: reduction of static RAM usage in fastconv binaural room renderer */ #define FIX_I120_INV_SQRT /* Issue 120: inv_sqrt() shall be used instead of 1 / sqrt() to measure the correct complexity */ -#define FIX_I59 /* fix for issue 59: correcting delay of LFE and delay compensation */ +#define FIX_I59_LFE_TD_DELAY /* Issue 59: correcting delay of LFE for TD renderer */ +#define FIX_I59_LFE_CLDFB /* Issue 59: correcting LFE handling for fastconv binaural rendering */ +#define FIX_I59_DELAY_ROUNDING /* Issue 59: rounding in sample domain instead of nanosec for IVAS_ENC_GetDelay() and IVAS_DEC_GetDelay() */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_com/prot.h b/lib_com/prot.h index fb492ba3e7..5b9e3ddd36 100755 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -717,7 +717,7 @@ float get_delay( const int32_t io_fs, /* i : input/output sampling frequency */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ HANDLE_CLDFB_FILTER_BANK hCldfb, /* i : Handle of Cldfb analysis */ -#ifndef FIX_I59 +#ifndef FIX_I59_LFE_TD_DELAY RENDERER_TYPE renderer_type, /* i : IVAS rendering type */ const int32_t binaural_latency_ns /* i : binaural renderer HRTF delay in ns */ #else diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 62414bbc02..7ca4f8d8ec 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -389,7 +389,7 @@ ivas_error ivas_dec( } if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) { -#ifdef FIX_I59 +#ifdef FIX_I59_LFE_CLDFB ivas_binaural_cldfb( st_ivas, output ); ivas_binaural_add_LFE( st_ivas, output_frame, output ); #else diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 88b1cd8629..636f165684 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -606,8 +606,8 @@ ivas_error ivas_init_decoder( AUDIO_CONFIG output_config; DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; -#ifdef FIX_I59 - int32_t lfe_delay; +#ifdef FIX_I59_LFE_TD_DELAY + int32_t binauralization_delay_ns; #endif error = IVAS_ERR_OK; @@ -1228,14 +1228,25 @@ ivas_error ivas_init_decoder( if ( st_ivas->mc_mode == MC_MODE_MCT ) { -#ifdef FIX_I59 - lfe_delay = st_ivas->binaural_latency_ns; - if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) +#ifdef FIX_I59_LFE_TD_DELAY + binauralization_delay_ns = st_ivas->binaural_latency_ns; + if ( st_ivas->hBinRenderer != NULL ) { - /* Account for filterbank delay */ - lfe_delay += IVAS_FB_DEC_DELAY_NS; +#ifdef FIX_I59_LFE_CLDFB + if ( st_ivas->hBinRenderer->render_lfe ) + { + /* Account for filterbank delay */ + binauralization_delay_ns += IVAS_FB_DEC_DELAY_NS; + } + else + { + binauralization_delay_ns = 0; + } +#else + binauralization_delay_ns = 0; +#endif } - if ( ( error = ivas_create_lfe_dec( &st_ivas->hLFE, output_Fs, lfe_delay ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_create_lfe_dec( &st_ivas->hLFE, output_Fs, binauralization_delay_ns ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_create_lfe_dec( &st_ivas->hLFE, output_Fs, st_ivas->hHrtf != NULL ? st_ivas->hHrtf->latency_s : 0 ) ) != IVAS_ERR_OK ) #endif diff --git a/lib_dec/ivas_lfe_dec.c b/lib_dec/ivas_lfe_dec.c index 8033782e86..0782cccdb6 100644 --- a/lib_dec/ivas_lfe_dec.c +++ b/lib_dec/ivas_lfe_dec.c @@ -352,8 +352,8 @@ void ivas_lfe_dec( ivas_error ivas_create_lfe_dec( LFE_DEC_HANDLE *hLFE_out, /* o : IVAS LFE decoder structure */ const int32_t output_Fs, /* i : output sampling rate */ -#ifdef FIX_I59 - const int32_t binaural_latency_ns /* i : additional LFE delay to sync with binaural renderer */ +#ifdef FIX_I59_LFE_TD_DELAY + const int32_t binauralization_delay_ns /* i : additional LFE delay to sync with binaural renderer */ #else const float add_delay_s /* i : additional LFE delay to sync with binaural filter */ #endif @@ -365,7 +365,7 @@ ivas_error ivas_create_lfe_dec( LFE_DEC_HANDLE hLFE; float lfe_addl_delay_s; int16_t i, j; -#ifdef FIX_I59 +#ifdef FIX_I59_LFE_TD_DELAY int16_t add_delay_sa; #endif @@ -443,8 +443,8 @@ ivas_error ivas_create_lfe_dec( lfe_addl_delay_s = block_offset_s - hLFE->lfe_block_delay_s; lfe_addl_delay_s = max( 0.0f, lfe_addl_delay_s ); -#ifdef FIX_I59 - add_delay_sa = NS2SA( output_Fs, binaural_latency_ns + 0.5f ); +#ifdef FIX_I59_LFE_TD_DELAY + add_delay_sa = NS2SA( output_Fs, binauralization_delay_ns + 0.5f ); hLFE->lfe_addl_delay = (int16_t) ( lfe_addl_delay_s * output_Fs ) + add_delay_sa; hLFE->lfe_block_delay_s += lfe_addl_delay_s + add_delay_sa / output_Fs; #else diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index bafc4a3fa8..ddcc8ccf4f 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -2013,7 +2013,7 @@ typedef struct Decoder_Struct float *hoa_dec_mtx; /* Pointer to decoder matrix for SBA */ HEAD_TRACK_DATA_HANDLE hHeadTrackData; /* Head tracking data structure */ RENDER_CONFIG_DATA *hRenderConfig; /* Renderer config pointer */ -#ifdef FIX_I59 +#ifdef FIX_I59_LFE_TD_DELAY int32_t binaural_latency_ns; /* Binauralization latency in ns */ #else int32_t binaural_latency_ns; /* HRTF binauralization latency in ns */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 4ea06b5a75..cc28ff0b40 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1054,10 +1054,18 @@ ivas_error IVAS_DEC_GetDelay( st_ivas = hIvasDec->st_ivas; hDecoderConfig = st_ivas->hDecoderConfig; -#ifdef FIX_I59 +#ifdef FIX_I59_LFE_TD_DELAY +#ifdef FIX_I59_DELAY_ROUNDING *nSamples = NS2SA( hDecoderConfig->output_Fs, get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], st_ivas->binaural_latency_ns ) + 0.5f ); +#else + *nSamples = NS2SA( hDecoderConfig->output_Fs, (int32_t) ( get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], st_ivas->binaural_latency_ns ) + 0.5f ) ); +#endif +#else +#ifdef FIX_I59_DELAY_ROUNDING + *nSamples = NS2SA( hDecoderConfig->output_Fs, get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], st_ivas->renderer_type, st_ivas->binaural_latency_ns ) + 0.5f ); #else *nSamples = NS2SA( hDecoderConfig->output_Fs, (int32_t) ( get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], st_ivas->renderer_type, st_ivas->binaural_latency_ns ) + 0.5f ) ); +#endif #endif *timeScale = hDecoderConfig->output_Fs; diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 7f72fa920b..ef0108bcfa 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -946,10 +946,18 @@ ivas_error IVAS_ENC_GetDelay( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } -#ifdef FIX_I59 +#ifdef FIX_I59_LFE_TD_DELAY +#ifdef FIX_I59_DELAY_ROUNDING *delay = NS2SA( hEncoderConfig->input_Fs, get_delay( ENC, hEncoderConfig->input_Fs, hEncoderConfig->ivas_format, NULL, 0 ) + 0.5f ); +#else + *delay = NS2SA( hEncoderConfig->input_Fs, (int32_t) ( get_delay( ENC, hEncoderConfig->input_Fs, hEncoderConfig->ivas_format, NULL, 0 ) + 0.5f ) ); +#endif +#else +#ifdef FIX_I59_DELAY_ROUNDING + *delay = NS2SA( hEncoderConfig->input_Fs, get_delay( ENC, hEncoderConfig->input_Fs, hEncoderConfig->ivas_format, NULL, RENDERER_DISABLE, 0 ) + 0.5f ); #else *delay = NS2SA( hEncoderConfig->input_Fs, (int32_t) ( get_delay( ENC, hEncoderConfig->input_Fs, hEncoderConfig->ivas_format, NULL, RENDERER_DISABLE, 0 ) + 0.5f ) ); +#endif #endif *delay *= hEncoderConfig->nchan_inp; diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c index c47a0c86c3..b286ef93cc 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c @@ -1307,7 +1307,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl } if ( st_ivas.ivas_format == MC_FORMAT ) { -#ifdef FIX_I59 +#ifdef FIX_I59_LFE_TD_DELAY ivas_create_lfe_dec( &st_ivas.hLFE, st_ivas.hDecoderConfig->output_Fs, (int32_t) ( pIo_params->latency_s * 1000000000.f ) ); #else ivas_create_lfe_dec( &st_ivas.hLFE, st_ivas.hDecoderConfig->output_Fs, pIo_params->latency_s ); -- GitLab From 0fd7baab08c3c02a3c4615f1779456a6584fd505 Mon Sep 17 00:00:00 2001 From: muxe6256 Date: Wed, 26 Oct 2022 16:54:13 +0200 Subject: [PATCH 06/13] fix rounding on lfe delay computation, add test script and test item --- .gitignore | 4 + CMakeLists.txt | 5 + lib_com/options.h | 1 + lib_dec/ivas_binauralRenderer.c | 19 ++ lib_dec/ivas_init_dec.c | 7 +- lib_dec/ivas_lfe_dec.c | 6 +- run_test_bin_latencys.py | 175 +++++++++++++++++ .../unit_tests/crend/ivas_crend_utest_utils.c | 183 ++++++++++++++---- scripts/testv/dirac_12ch_16k.wav | 3 + scripts/testv/dirac_12ch_32k.wav | 3 + scripts/testv/dirac_12ch_48k.wav | 3 + scripts/testv/test_8ch_16k.wav | 3 + scripts/testv/test_8ch_32k.wav | 3 + scripts/testv/test_8ch_48k.wav | 3 + 14 files changed, 376 insertions(+), 42 deletions(-) create mode 100644 run_test_bin_latencys.py create mode 100644 scripts/testv/dirac_12ch_16k.wav create mode 100644 scripts/testv/dirac_12ch_32k.wav create mode 100644 scripts/testv/dirac_12ch_48k.wav create mode 100644 scripts/testv/test_8ch_16k.wav create mode 100644 scripts/testv/test_8ch_32k.wav create mode 100644 scripts/testv/test_8ch_48k.wav diff --git a/.gitignore b/.gitignore index aecd59fd31..a3a51e60f1 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,7 @@ tests/ref __pycache__/ *.py[cod] *$py.class + +# .history +.history/**/* + diff --git a/CMakeLists.txt b/CMakeLists.txt index ad70b85844..ed42fd70e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,6 +158,11 @@ if(WIN32) target_link_libraries(IVAS_dec Ws2_32) endif() +file(GLOB libCrendUnitTestSrcs "scripts/ivas_pytests/tests/unit_tests/crend/*.c") +file(GLOB libCrendUnitTestHeaders "scripts/ivas_pytests/tests/unit_tests/crend/*.h") +add_executable(IVAS_crend_unit_test ${libCrendUnitTestSrcs} ${libCrendUnitTestHeaders}) +target_link_libraries(IVAS_crend_unit_test lib_dec lib_util) + if(${IVAS_BUILD_PRERENDERER}) add_executable(IVAS_prerenderer scripts/prerenderer/prerenderer.c diff --git a/lib_com/options.h b/lib_com/options.h index c9eb38a9b6..4f3abf7ce1 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -154,6 +154,7 @@ #define FIX_I59_LFE_TD_DELAY /* Issue 59: correcting delay of LFE for TD renderer */ #define FIX_I59_LFE_CLDFB /* Issue 59: correcting LFE handling for fastconv binaural rendering */ #define FIX_I59_DELAY_ROUNDING /* Issue 59: rounding in sample domain instead of nanosec for IVAS_ENC_GetDelay() and IVAS_DEC_GetDelay() */ +#define FIX_FIX_I59 /* Issue 59: small fix concerning LFE delay rounding */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_binauralRenderer.c b/lib_dec/ivas_binauralRenderer.c index 45108a92fa..51f4db024b 100644 --- a/lib_dec/ivas_binauralRenderer.c +++ b/lib_dec/ivas_binauralRenderer.c @@ -567,6 +567,24 @@ ivas_error ivas_binRenderer_open( return error; } +#ifdef FIX_FIX_I59 + if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) + { + if ( hBinRenderer->ivas_format == MC_FORMAT ) + { + st_ivas->binaural_latency_ns = (int32_t) ( FASTCONV_HRIR_latency_s * 1000000000.f ); + } + else + { + st_ivas->binaural_latency_ns = (int32_t) ( FASTCONV_HOA3_latency_s * 1000000000.f ); + } + } + else + { + /* same value for MC or HOA both use MC BRIR*/ + st_ivas->binaural_latency_ns = (int32_t) ( FASTCONV_BRIR_latency_s * 1000000000.f ); + } +#else if ( hBinRenderer->ivas_format == MC_FORMAT ) { st_ivas->binaural_latency_ns = (int32_t) ( FASTCONV_HRIR_latency_s * 1000000000.f ); @@ -575,6 +593,7 @@ ivas_error ivas_binRenderer_open( { st_ivas->binaural_latency_ns = (int32_t) ( FASTCONV_HOA3_latency_s * 1000000000.f ); } +#endif } /* Allocate memories needed for reverb module */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 45bec1f769..dd900d6d6c 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1213,8 +1213,11 @@ ivas_error ivas_init_decoder( /*-----------------------------------------------------------------* * LFE handles for rendering after rendering to adjust LFE delay to binaural filter delay *-----------------------------------------------------------------*/ - - if ( st_ivas->mc_mode == MC_MODE_MCT ) +#ifdef FIX_FIX_I59 + if ( ( st_ivas->mc_mode == MC_MODE_MCT ) || ( st_ivas->mc_mode == MC_MODE_PARAMMC ) ) +#else + if ( st_ivas->mc_mode == MC_MODE_MCT ) +#endif { #ifdef FIX_I59_LFE_TD_DELAY binauralization_delay_ns = st_ivas->binaural_latency_ns; diff --git a/lib_dec/ivas_lfe_dec.c b/lib_dec/ivas_lfe_dec.c index 0782cccdb6..70e3a2fff4 100644 --- a/lib_dec/ivas_lfe_dec.c +++ b/lib_dec/ivas_lfe_dec.c @@ -355,7 +355,7 @@ ivas_error ivas_create_lfe_dec( #ifdef FIX_I59_LFE_TD_DELAY const int32_t binauralization_delay_ns /* i : additional LFE delay to sync with binaural renderer */ #else - const float add_delay_s /* i : additional LFE delay to sync with binaural filter */ + const float add_delay_s /* i : additional LFE delay to sync with binaural filter */ #endif ) { @@ -444,7 +444,11 @@ ivas_error ivas_create_lfe_dec( lfe_addl_delay_s = block_offset_s - hLFE->lfe_block_delay_s; lfe_addl_delay_s = max( 0.0f, lfe_addl_delay_s ); #ifdef FIX_I59_LFE_TD_DELAY +#ifdef FIX_FIX_I59 + add_delay_sa = (int16_t) roundf( (float) binauralization_delay_ns * output_Fs / 1000000000.f ); +#else add_delay_sa = NS2SA( output_Fs, binauralization_delay_ns + 0.5f ); +#endif hLFE->lfe_addl_delay = (int16_t) ( lfe_addl_delay_s * output_Fs ) + add_delay_sa; hLFE->lfe_block_delay_s += lfe_addl_delay_s + add_delay_sa / output_Fs; #else diff --git a/run_test_bin_latencys.py b/run_test_bin_latencys.py new file mode 100644 index 0000000000..c40f226af5 --- /dev/null +++ b/run_test_bin_latencys.py @@ -0,0 +1,175 @@ + + +import os +import subprocess +import errno +import tempfile as tf +import sys +from scipy.io.wavfile import read, write +import numpy as np + +ivas_path = 'D:/DEV/ivas-3gpp/' + +trunk_path = ivas_path + 'ivas-codec/' +script_path = trunk_path + 'scripts/' +inpath = script_path + 'testv/' +outpath = script_path + 'testv/out/' +trajpath = script_path + 'trajectories/' + +if sys.platform.startswith('win32'): + unit_test_exe = trunk_path + 'build/IVAS_crend_unit_test.exe' + ivas_cod_exe = trunk_path + 'build/IVAS_cod.exe' + ivas_dec_exe = trunk_path + 'build/IVAS_dec.exe' + +file_name_7_1_root = 'test_8ch_' + +file_name_7_1_4_root = 'dirac_12ch_' + +sampleRates = ['48', '16', '32'] + +for sr in sampleRates: + file_name_7_1_4 = inpath + file_name_7_1_4_root + sr + 'k' + inFileName_7_1_4 = file_name_7_1_4 + '.wav' + + file_name_7_1 = inpath + file_name_7_1_root + sr + 'k' + inFileName_7_1 = file_name_7_1 + '.wav' + + # encode 7.1.4 512kb + cmd = [ivas_cod_exe, '-MC', '7_1_4', '-max_band', 'FB', '512000', sr, + file_name_7_1_4 + '.wav', file_name_7_1_4 + '_512kb.ptk'] + + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) + + # encode 7.1 512kb + cmd = [ivas_cod_exe, '-MC', '7_1', '-max_band', 'FB', '512000', sr, + file_name_7_1 + '.wav', file_name_7_1 + '_512kb.ptk'] + + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) + + # encode 7.1.4 128kb PARAMMC + cmd = [ivas_cod_exe, '-MC', '7_1_4', '-max_band', 'FB', '128000', sr, + file_name_7_1_4 + '.wav', file_name_7_1_4 + '_128kb.ptk'] + + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) + + # encode 7.1 64kb PARAMMC + cmd = [ivas_cod_exe, '-MC', '7_1', '-max_band', 'FB', '128000', sr, + file_name_7_1 + '.wav', file_name_7_1 + '_64kb.ptk'] + + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) + + # decode 7_1_4 + cmd = [ivas_dec_exe, '7_1_4', sr, file_name_7_1_4 + + '_512kb.ptk', file_name_7_1_4 + '_enc_dec.wav'] + + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) + + # decode 7_1 + cmd = [ivas_dec_exe, '7_1', sr, file_name_7_1 + + '_512kb.ptk', file_name_7_1 + '_enc_dec.wav'] + + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) + + # decode binaural crend 7.1.4 + cmd = [ivas_dec_exe, 'BINAURAL', sr, file_name_7_1_4 + + '_512kb.ptk', file_name_7_1_4 + '-hrir.wav'] + + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) + + # decode binaural room crend 7.1.4 + cmd = [ivas_dec_exe, 'BINAURAL_ROOM', sr, + file_name_7_1_4 + '_512kb.ptk', file_name_7_1_4 + '-brir.wav'] + + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) + + # decode binaural crend 7.1 + cmd = [ivas_dec_exe, 'BINAURAL', sr, file_name_7_1 + + '_512kb.ptk', file_name_7_1 + '-hrir.wav'] + + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) + + # decode binaural room crend 7.1 + cmd = [ivas_dec_exe, 'BINAURAL_ROOM', sr, file_name_7_1 + + '_512kb.ptk', file_name_7_1 + '-brir.wav'] + + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) + + # decode binaural fastconv 7.1 + cmd = [ivas_dec_exe, 'BINAURAL', sr, file_name_7_1 + + '_64kb.ptk', file_name_7_1 + '-fastconv-hrir.wav'] + + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) + + # decode binaural room fastconv 7.1 + cmd = [ivas_dec_exe, 'BINAURAL_ROOM', sr, file_name_7_1 + + '_64kb.ptk', file_name_7_1 + '-fastconv-brir.wav'] + + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) + + # decode binaural TD 7.1.4 + cmd = [ivas_dec_exe, '-T', trajpath + '/const000.csv', 'BINAURAL', sr, + file_name_7_1_4 + '_512kb.ptk', file_name_7_1_4 + '-td-hrir.wav'] + + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) + + # decode binaural TD 7.1 + cmd = [ivas_dec_exe, '-T', trajpath + '/const000.csv', 'BINAURAL', sr, + file_name_7_1 + '_512kb.ptk', file_name_7_1 + '-td-hrir.wav'] + + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) + +# render CICP19 to binaural +sampleRates = ['16', '32', '48'] +# option = ['-limiter', '-lp_lfe'] +option = ['-lp_lfe'] + +for sr in sampleRates: + file_name_7_1_4 = inpath + file_name_7_1_4_root + sr + 'k' + inFileName_7_1_4 = file_name_7_1_4 + '.wav' + + file_name_7_1 = inpath + file_name_7_1_root + sr + 'k' + inFileName_7_1 = file_name_7_1 + '.wav' + + cmd = [unit_test_exe, '-test', '1', '-sr', sr, '-ifmt', '7', '-ofmt', '2', '-i', + inFileName_7_1_4, '-o', file_name_7_1_4 + '-hrir-crend-u.wav'] + cmd = cmd + option + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) + + cmd = [unit_test_exe, '-test', '1', '-sr', sr, '-ifmt', '7', '-ofmt', '2', '-BRIR', + '-i', inFileName_7_1_4, '-o', file_name_7_1_4 + '-brir-crend-u.wav'] + cmd = cmd + option + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) + + cmd = [unit_test_exe, '-test', '2', '-sr', sr, '-ifmt', '7', '-ofmt', '2', '-i', + inFileName_7_1_4, '-o', file_name_7_1_4 + '-hrir-fastconv-u.wav'] + cmd = cmd + option + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) + + cmd = [unit_test_exe, '-test', '2', '-sr', sr, '-ifmt', '7', '-ofmt', '2', '-BRIR', + '-i', inFileName_7_1_4, '-o', file_name_7_1_4 + '-brir-fastconv-u.wav'] + cmd = cmd + option + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) + + cmd = [unit_test_exe, '-test', '4', '-sr', sr, '-ifmt', '7', '-ofmt', '2', + '-i', inFileName_7_1_4, '-o', file_name_7_1_4 + '-hrir-td-u.wav'] + cmd = cmd + option + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c index b286ef93cc..dfec494779 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c @@ -64,6 +64,58 @@ #include "render_config_reader.h" +static int32_t ivas_check_rounding( float binaural_latencys_s[3], int16_t use_round_latency, int16_t use_round_for_lfe, int32_t *err_lfe, int32_t *err_dec, int16_t verbose ) +{ + // float delay_ns_float[3]; + int32_t delay_ns[3]; + + float sampleRates[3] = { 48000.f, 32000.f, 16000.f }; + + // float binaural_latencys_s[3] = { 1.f / 48000.f, 2.f / 48000.f, 3.f / 48000.f }; + + int32_t delay_lfe[3][3]; + + int32_t delay_dec[3][3]; + + int32_t wanted; + + *err_lfe = 0; + *err_dec = 0; + + for ( int ind1 = 0; ind1 < sizeof( sampleRates ) / sizeof( float ); ind1++ ) + { + if ( verbose ) + printf( "\nsample rate = %f", sampleRates[ind1] ); + for ( int ind2 = 0; ind2 < sizeof( binaural_latencys_s ) / sizeof( float ); ind2++ ) + { + wanted = (int32_t) roundf( binaural_latencys_s[ind2] * sampleRates[ind1] ); + if ( verbose ) + printf( "\nbinaural_latencys_s = %f wanted = %ld", binaural_latencys_s[ind2], wanted ); + if ( use_round_latency ) + delay_ns[ind2] = (int32_t) roundf( binaural_latencys_s[ind2] * 1000000000.f ); + else + delay_ns[ind2] = (int32_t) ( binaural_latencys_s[ind2] * 1000000000.f ); + if ( verbose ) + printf( "\n delay_ns[%d] = %ld \n", ind2, delay_ns[ind2] ); + + if ( use_round_for_lfe ) + delay_lfe[ind1][ind2] = (int32_t) roundf( delay_ns[ind2] * sampleRates[ind1] / 1000000000.f ); + else + delay_lfe[ind1][ind2] = (int32_t) ( delay_ns[ind2] * sampleRates[ind1] / 1000000000.f ); + if ( verbose ) + printf( "\ndelay_lfe[%d][%d] = %ld\n", ind1, ind2, delay_lfe[ind1][ind2] ); + *err_lfe += abs( delay_lfe[ind1][ind2] - wanted ); + + delay_dec[ind1][ind2] = NS2SA( sampleRates[ind1], (float) delay_ns[ind2] + 0.5f ); + + if ( verbose ) + printf( "\ndelay_dec[%d][%d] = %ld \n", ind1, ind2, delay_dec[ind1][ind2] ); + *err_dec += abs( delay_dec[ind1][ind2] - wanted ); + } + } + return *err_lfe + *err_dec; +} + static ivas_result_t ivas_dec_default_io_params( ivas_dec_io_params_t *pIO_params ) { @@ -103,7 +155,7 @@ static ivas_error ivas_hrtf_init( hHrtf->max_num_iterations = 0; hHrtf->gain_lfe = 0; hHrtf->index_frequency_max_diffuse = 0; - + for ( i = 0; i < IVAS_MAX_NUM_CH; i++ ) { hHrtf->inv_diffuse_weight[i] = 0; @@ -446,7 +498,7 @@ void ivas_open_files_crend( ivas_crend_io_params_t *pIo_params ) #ifdef USE_PCM_OUT if ( ( pIo_params->fIn[0] = fopen( pIo_params->in_path, "rb" ) ) == NULL ) #else - if ( AudioFileReader_open( &pIo_params->fIn[0] , pIo_params->in_path, pIo_params->sample_rate ) != IVAS_ERR_OK ) + if ( AudioFileReader_open( &pIo_params->fIn[0], pIo_params->in_path, pIo_params->sample_rate ) != IVAS_ERR_OK ) #endif { fprintf( stderr, "Error: Input audio file %s could not be opened\n\n", pIo_params->in_path ); @@ -861,7 +913,7 @@ static ivas_result_t ivas_wrapper_get_in_buf( ivas_crend_io_params_t *pIo_params int16_t tmp, read = 0; num_in_ch = ivas_get_num_channels( pIo_params->in_fmt ); - if ( pIo_params->test == CREND_BIN_TEST || pIo_params->test == FASTCONV_BIN_TEST || pIo_params->test == PARAM_BIN_TEST || pIo_params->test == TD_BIN_TEST || pIo_params->test == CREND_ACOUSTIC_PROXIMITY) + if ( pIo_params->test == CREND_BIN_TEST || pIo_params->test == FASTCONV_BIN_TEST || pIo_params->test == PARAM_BIN_TEST || pIo_params->test == TD_BIN_TEST || pIo_params->test == CREND_ACOUSTIC_PROXIMITY ) { /* Read in PCM */ for ( j = 0; j < input_frame_len; j++ ) @@ -871,7 +923,7 @@ static ivas_result_t ivas_wrapper_get_in_buf( ivas_crend_io_params_t *pIo_params #ifdef USE_PCM_OUT if ( ( read = (int16_t) fread( &tmp, sizeof( int16_t ), 1, pIo_params->fIn[0] ) ) > 0 ) #else - if ( (AudioFileReader_read( pIo_params->fIn[0], &tmp, 1, &read ) == IVAS_ERR_OK) && (read > 0) ) + if ( ( AudioFileReader_read( pIo_params->fIn[0], &tmp, 1, &read ) == IVAS_ERR_OK ) && ( read > 0 ) ) #endif { ppPcm_in[i][j] = (float) tmp; @@ -911,7 +963,7 @@ static ivas_result_t ivas_wrapper_get_in_buf( ivas_crend_io_params_t *pIo_params #else if ( ( AudioFileReader_read( pIo_params->fIn[i], &tmp, 1, &read ) == IVAS_ERR_OK ) && ( read > 0 ) ) #endif - { + { ppPcm_in[i][j] = (float) tmp; ppPcm_in[i][j] *= ( 1.0 / PCM16_TO_FLT_FAC ); samples_read += 1; @@ -943,14 +995,14 @@ static ivas_result_t ivas_wrapper_get_in_buf( ivas_crend_io_params_t *pIo_params *---------------------------------------------------------------------*/ static ivas_result_t ivas_feed_head_track_data( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ IVAS_QUATERNION *orientation /* i : head-tracking data */ ) { HEAD_TRACK_DATA_HANDLE hHeadTrackData; int16_t i; - + hHeadTrackData = st_ivas->hHeadTrackData; if ( hHeadTrackData == NULL ) @@ -1081,6 +1133,40 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl } } #endif + /* test rounding error + float binaural_latencys_fastconv_s[3] = { FASTCONV_HRIR_latency_s, FASTCONV_BRIR_latency_s, FASTCONV_BRIR_latency_s }; + float binaural_latencys_crend_s[3] = { 1.f / 48000.f, 2.f / 48000.f, 3.f / 48000.f }; + float binaural_latencys_td_s[3] = { BINAURAL_TD_LATENCY_S, BINAURAL_TD_LATENCY_S + 1.f / 48000.f, BINAURAL_TD_LATENCY_S + 2.f / 48000.f }; + + int32_t err = 0, err_lfe = 0, err_dec = 0; + err = ivas_check_rounding( binaural_latencys_fastconv_s, 0, 0, &err_lfe, &err_dec, 0 ); + printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); + err += ivas_check_rounding( binaural_latencys_crend_s, 0, 0, &err_lfe, &err_dec, 0 ); + printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); + err += ivas_check_rounding( binaural_latencys_td_s, 0, 0, &err_lfe, &err_dec, 0 ); + printf( "\n\nerr = %ld err_lfe = %ld err_dec = %ld\n\n", err, err_lfe, err_dec ); + + err = ivas_check_rounding( binaural_latencys_fastconv_s, 0, 1, &err_lfe, &err_dec, 0 ); + printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); + err += ivas_check_rounding( binaural_latencys_crend_s, 0, 1, &err_lfe, &err_dec, 0 ); + printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); + err += ivas_check_rounding( binaural_latencys_td_s, 0, 1, &err_lfe, &err_dec, 0 ); + printf( "\n\nerr = %ld err_lfe = %ld err_dec = %ld\n\n", err, err_lfe, err_dec ); + + err = ivas_check_rounding( binaural_latencys_fastconv_s, 1, 0, &err_lfe, &err_dec, 0 ); + printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); + err += ivas_check_rounding( binaural_latencys_crend_s, 1, 0, &err_lfe, &err_dec, 0 ); + printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); + err += ivas_check_rounding( binaural_latencys_td_s, 1, 0, &err_lfe, &err_dec, 0 ); + printf( "\n\nerr = %ld err_lfe = %ld err_dec = %ld\n\n", err, err_lfe, err_dec ); + + err = ivas_check_rounding( binaural_latencys_fastconv_s, 1, 1, &err_lfe, &err_dec, 0 ); + printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); + err += ivas_check_rounding( binaural_latencys_crend_s, 1, 1, &err_lfe, &err_dec, 0 ); + printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); + err += ivas_check_rounding( binaural_latencys_td_s, 1, 1, &err_lfe, &err_dec, 0 ); + printf( "\n\nerr = %ld err_lfe = %ld err_dec = %ld\n\n", err, err_lfe, err_dec ); +*/ ivas_render_config_open( &st_ivas.hRenderConfig ); ivas_render_config_init_from_rom( &st_ivas.hRenderConfig, 0 ); @@ -1109,7 +1195,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl { st_ivas.ivas_format = SBA_FORMAT; } - + if ( ( pIo_params->out_fmt == BIN_2 ) && ( pIo_params->in_fmt != pIo_params->out_fmt ) ) { if ( pIo_params->test == FASTCONV_BIN_TEST ) @@ -1118,16 +1204,28 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl { st_ivas.renderer_type = RENDERER_BINAURAL_FASTCONV_ROOM; st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL_ROOM; +#ifdef FIX_FIX_I59 + pIo_params->latency_s = roundf( IVAS_FB_DEC_DELAY_NS + FASTCONV_BRIR_latency_s * 1000000000.f ); +#else pIo_params->latency_s = ( (float) frame_len ) / (float) dec_io_params.out_sample_rate + FASTCONV_BRIR_latency_s; +#endif } else { st_ivas.renderer_type = RENDERER_BINAURAL_FASTCONV; st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL; - if (st_ivas.ivas_format == MC_FORMAT) - pIo_params->latency_s = ( (float) frame_len ) / (float) dec_io_params.out_sample_rate + FASTCONV_HRIR_latency_s ; + if ( st_ivas.ivas_format == MC_FORMAT ) +#ifdef FIX_FIX_I59 + pIo_params->latency_s = roundf( IVAS_FB_DEC_DELAY_NS + FASTCONV_HRIR_latency_s * 1000000000.f ); +#else + pIo_params->latency_s = ( (float) frame_len ) / (float) dec_io_params.out_sample_rate + FASTCONV_HRIR_latency_s; +#endif else +#ifdef FIX_FIX_I59 + pIo_params->latency_s = roundf( IVAS_FB_DEC_DELAY_NS + FASTCONV_HOA3_latency_s * 1000000000.f ); +#else pIo_params->latency_s = ( (float) frame_len ) / (float) dec_io_params.out_sample_rate + FASTCONV_HOA3_latency_s; +#endif } } else if ( pIo_params->test == TD_BIN_TEST ) @@ -1137,7 +1235,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl fprintf( stderr, "TD Renderer configuration wrong input format\n" ); exit( -1 ); } - + if ( st_ivas.hRenderConfig->roomAcoustics.use_brir ) { st_ivas.renderer_type = RENDERER_BINAURAL_OBJECTS_TD; @@ -1148,7 +1246,11 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl st_ivas.renderer_type = RENDERER_BINAURAL_OBJECTS_TD; st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL; } +#ifdef FIX_FIX_I59 + pIo_params->latency_s = roundf( BINAURAL_TD_LATENCY_S * 1000000000.f ); +#else pIo_params->latency_s = BINAURAL_TD_LATENCY_S; +#endif } else if ( pIo_params->test == PARAM_BIN_TEST ) { @@ -1162,9 +1264,13 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl st_ivas.renderer_type = RENDERER_BINAURAL_PARAMETRIC; st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL; } +#ifdef FIX_FIX_I59 + pIo_params->latency_s = IVAS_FB_DEC_DELAY_NS; +#else pIo_params->latency_s = ( (float) frame_len ) / (float) dec_io_params.out_sample_rate; +#endif } - else if( pIo_params->test == CREND_BIN_TEST ) + else if ( pIo_params->test == CREND_BIN_TEST ) { if ( st_ivas.hRenderConfig->roomAcoustics.use_brir ) { @@ -1205,11 +1311,10 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl { return error; } - if ( ( error = HeadRotationFileReader_open( pIo_params->csv_path , &headRotReader ) ) != IVAS_ERR_OK ) + if ( ( error = HeadRotationFileReader_open( pIo_params->csv_path, &headRotReader ) ) != IVAS_ERR_OK ) { return error; } - } st_ivas.nchan_transport = audioCfg2channels( st_ivas.transport_config ); @@ -1259,8 +1364,8 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl { if ( ( pIo_params->in_fmt != FOA_4 ) && ( pIo_params->in_fmt != HOA_9 ) && ( pIo_params->in_fmt != HOA_16 ) ) { - fprintf( stderr, "PARAM renderer configuration wrong format, must be FOA or HOA up to order 3\n" ); - exit( -1 ); + fprintf( stderr, "PARAM renderer configuration wrong format, must be FOA or HOA up to order 3\n" ); + exit( -1 ); } ivas_output_init( &st_ivas.hIntSetup, st_ivas.transport_config ); @@ -1303,11 +1408,15 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl if ( pIo_params->test == CREND_BIN_TEST ) { - pIo_params->latency_s = st_ivas.hHrtf->latency_s; +#ifdef FIX_FIX_I59 + pIo_params->latency_s = roundf( st_ivas.hHrtf->latency_s * 1000000000.f ); +#else + pIo_params->latency_s = st_ivas.hHrtf->latency_s; +#endif } if ( st_ivas.ivas_format == MC_FORMAT ) { -#ifdef FIX_I59_LFE_TD_DELAY +#ifdef FIX_FIX_I59 ivas_create_lfe_dec( &st_ivas.hLFE, st_ivas.hDecoderConfig->output_Fs, (int32_t) ( pIo_params->latency_s * 1000000000.f ) ); #else ivas_create_lfe_dec( &st_ivas.hLFE, st_ivas.hDecoderConfig->output_Fs, pIo_params->latency_s ); @@ -1357,7 +1466,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl delay_lp = 0; } } - + if ( pIo_params->limiter_enable ) { st_ivas.hLimiter = ivas_limiter_open( out_ch, pIo_params->sample_rate ); @@ -1384,20 +1493,20 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl { skip_samples = NS2SA( pIo_params->sample_rate, (int32_t) ( pIo_params->latency_s * 1000000000.f ) ); } - fprintf( stdout, "IVAS Common Renderer skip samples = %d\n", (int)skip_samples ); + fprintf( stdout, "IVAS Common Renderer skip samples = %d\n", (int) skip_samples ); frame_len = frame_len << 2; - int32_t frame_dec=0; - IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = {0}; + int32_t frame_dec = 0; + IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { 0 }; /* process loop */ - while ( ( ( result = ivas_wrapper_get_in_buf( pIo_params, ppPcm_in ) ) == IVAS_SUCCESS ) && ( (st_ivas.hDecoderConfig->Opt_Headrotation == 0) || ( (st_ivas.hDecoderConfig->Opt_Headrotation == 1) && (HeadRotationFileReading( headRotReader, Quaternions, frame_dec ) == IVAS_ERR_OK ) ) ) ) + while ( ( ( result = ivas_wrapper_get_in_buf( pIo_params, ppPcm_in ) ) == IVAS_SUCCESS ) && ( ( st_ivas.hDecoderConfig->Opt_Headrotation == 0 ) || ( ( st_ivas.hDecoderConfig->Opt_Headrotation == 1 ) && ( HeadRotationFileReading( headRotReader, Quaternions, frame_dec ) == IVAS_ERR_OK ) ) ) ) { int16_t pcm[MAX_OUTPUT_CHANNELS]; frame_dec++; result = IVAS_SUCCESS; - if ( ( st_ivas.hDecoderConfig->Opt_Headrotation == 1 ) && (ivas_feed_head_track_data( &st_ivas, Quaternions ) != IVAS_SUCCESS )) + if ( ( st_ivas.hDecoderConfig->Opt_Headrotation == 1 ) && ( ivas_feed_head_track_data( &st_ivas, Quaternions ) != IVAS_SUCCESS ) ) { return IVAS_IO_ERROR; } @@ -1424,7 +1533,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl { mvr2r( ppPcm_in[i], ppPcm_out[i], frame_len ); } - } + } else if ( pIo_params->test == TD_BIN_TEST ) { ObjRenderIVASFrame( &st_ivas, ppPcm_in, frame_len ); @@ -1445,7 +1554,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl /* Implement a 5 msec loops */ maxBand = (int16_t) ( ( CLDFB_NO_CHANNELS_MAX * st_ivas.hDecoderConfig->output_Fs ) / 48000 ); - for ( slot_idx = 0; slot_idx < (int16_t)CLDFB_NO_COL_MAX; slot_idx++ ) + for ( slot_idx = 0; slot_idx < (int16_t) CLDFB_NO_COL_MAX; slot_idx++ ) { for ( ch = 0; ch < in_ch; ch++ ) @@ -1457,7 +1566,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl } } - for ( slot_idx = 0; slot_idx < (int16_t)CLDFB_NO_COL_MAX ; slot_idx++ ) + for ( slot_idx = 0; slot_idx < (int16_t) CLDFB_NO_COL_MAX; slot_idx++ ) { /* Implement binaural rendering */ for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) @@ -1474,7 +1583,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl { filterTapsRealPtr = hrtfShCoeffsRe[ch][chIdx]; filterTapsImagPtr = hrtfShCoeffsIm[ch][chIdx]; - + for ( bandIdx = 0; bandIdx < maxBand; bandIdx++ ) { RealBuffer[bandIdx] += gain * ( Cldfb_RealBuffer[chIdx][slot_idx][bandIdx] * filterTapsRealPtr[bandIdx] ) - ( Cldfb_ImagBuffer[chIdx][slot_idx][bandIdx] * filterTapsImagPtr[bandIdx] ); @@ -1486,12 +1595,11 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl cldfbSynthesis( &outSlotRePr, &outSlotImPr, &( ppPcm_in[ch][slot_idx * maxBand] ), maxBand, st_ivas.cldfbSynDec[ch] ); } } - + for ( i = 0; i < out_ch; i++ ) { mvr2r( ppPcm_in[i], ppPcm_out[i], frame_len ); } - } else { @@ -1504,7 +1612,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl ivas_crend_process( &st_ivas, ppPcm_in ); } } - + if ( mixer == NULL ) { if ( st_ivas.hLFE ) @@ -1554,14 +1662,12 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl valEner += ppPcm_out[i][j] * ppPcm_out[i][j]; #endif pcm[i] = ( temp > MAX16B ) ? MAX16B : ( temp < MIN16B_FLT ) ? MIN16B - : (short) temp; + : (short) temp; clip = max( clip, fabs( ppPcm_out[i][j] ) ); - - } if ( write_flag == 1 ) { -#ifdef USE_PCM_OUT +#ifdef USE_PCM_OUT fwrite( pcm, sizeof( int16_t ), out_ch, pIo_params->fOut ); #else AudioFileWriter_write( pIo_params->fOut, pcm, out_ch ); @@ -1577,10 +1683,9 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl fprintf( stdout, "Processed frame: %ld\r", (long) frame_count ); frame_count++; - } - int16_t pcm[MAX_OUTPUT_CHANNELS] = {0}; + int16_t pcm[MAX_OUTPUT_CHANNELS] = { 0 }; while ( skipped_samples > 0 ) { AudioFileWriter_write( pIo_params->fOut, pcm, out_ch ); @@ -1598,7 +1703,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl ivas_lfe_dec_close( st_ivas.hLFE ); } - if ( st_ivas.hDirAC != NULL ) + if ( st_ivas.hDirAC != NULL ) ivas_dirac_dec_close( st_ivas.hDirAC ); if ( st_ivas.hBinRenderer != NULL ) ivas_binRenderer_close( &st_ivas.hBinRenderer ); @@ -1789,7 +1894,7 @@ ivas_result_t ivas_object_mixer_renderer( ivas_crend_io_params_t *pIo_params, in #ifdef USE_PCM_OUT pcm = ( temp > MAX16B_FLT ) ? MAX16B : ( temp < MIN16B_FLT ) ? MIN16B - : (short) temp; + : (short) temp; fwrite( &pcm, sizeof( int16_t ), 1, pIo_params->fOut ); #else pcm[i] = ( temp > MAX16B_FLT ) ? MAX16B : ( temp < MIN16B_FLT ) ? MIN16B diff --git a/scripts/testv/dirac_12ch_16k.wav b/scripts/testv/dirac_12ch_16k.wav new file mode 100644 index 0000000000..770a096292 --- /dev/null +++ b/scripts/testv/dirac_12ch_16k.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1480c94da2e6c1337dd8a6cf2394283a28739be9fd02f4a598c7c2fef578882e +size 4992156 diff --git a/scripts/testv/dirac_12ch_32k.wav b/scripts/testv/dirac_12ch_32k.wav new file mode 100644 index 0000000000..e363158e34 --- /dev/null +++ b/scripts/testv/dirac_12ch_32k.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b9adc43c1031a4799ad66c46a68d26ab34b4b4052aa05755f7081f06fd3b3a42 +size 9984132 diff --git a/scripts/testv/dirac_12ch_48k.wav b/scripts/testv/dirac_12ch_48k.wav new file mode 100644 index 0000000000..e6c45bcab5 --- /dev/null +++ b/scripts/testv/dirac_12ch_48k.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3cfbf8de4b0792f6a9155b048fb45bf56f907c1cb6446a2f7428cc50d6ba19d7 +size 14976044 diff --git a/scripts/testv/test_8ch_16k.wav b/scripts/testv/test_8ch_16k.wav new file mode 100644 index 0000000000..112985edbc --- /dev/null +++ b/scripts/testv/test_8ch_16k.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4b4a5f2c895033427626ce2cc05199cdcfbdd266cc8b2d75f8480bf0d051b54a +size 2304148 diff --git a/scripts/testv/test_8ch_32k.wav b/scripts/testv/test_8ch_32k.wav new file mode 100644 index 0000000000..abd795767b --- /dev/null +++ b/scripts/testv/test_8ch_32k.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f6a7ade09d04d823320157061558a177d00270bba789edff8bf554805ac35c61 +size 4608132 diff --git a/scripts/testv/test_8ch_48k.wav b/scripts/testv/test_8ch_48k.wav new file mode 100644 index 0000000000..dc170a11b9 --- /dev/null +++ b/scripts/testv/test_8ch_48k.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:83cec3fb6760866285003140f482b9b8b1f52045072bdf8f6814973bbbea2d35 +size 6912044 -- GitLab From adc274ab66793a50880267a2c4060dbb41ea397f Mon Sep 17 00:00:00 2001 From: muxe6256 Date: Thu, 10 Nov 2022 14:06:29 +0100 Subject: [PATCH 07/13] bugs corrections, warnings removal --- lib_dec/ivas_init_dec.c | 6 +- run_test_bin_latencys.py | 37 ++++++- .../unit_tests/crend/ivas_crend_io_parse.h | 16 ++- .../unit_tests/crend/ivas_crend_public.h | 10 +- .../unit_tests/crend/ivas_crend_unit_test.c | 103 ++++++++++-------- .../unit_tests/crend/ivas_crend_utest_utils.c | 80 ++++++++------ .../unit_tests/crend/ivas_dec_parse_io.h | 24 ++-- 7 files changed, 165 insertions(+), 111 deletions(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index dd900d6d6c..9579401ce5 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1213,11 +1213,7 @@ ivas_error ivas_init_decoder( /*-----------------------------------------------------------------* * LFE handles for rendering after rendering to adjust LFE delay to binaural filter delay *-----------------------------------------------------------------*/ -#ifdef FIX_FIX_I59 - if ( ( st_ivas->mc_mode == MC_MODE_MCT ) || ( st_ivas->mc_mode == MC_MODE_PARAMMC ) ) -#else - if ( st_ivas->mc_mode == MC_MODE_MCT ) -#endif + if ( st_ivas->mc_mode == MC_MODE_MCT ) { #ifdef FIX_I59_LFE_TD_DELAY binauralization_delay_ns = st_ivas->binaural_latency_ns; diff --git a/run_test_bin_latencys.py b/run_test_bin_latencys.py index c40f226af5..36101cdac8 100644 --- a/run_test_bin_latencys.py +++ b/run_test_bin_latencys.py @@ -26,6 +26,7 @@ file_name_7_1_root = 'test_8ch_' file_name_7_1_4_root = 'dirac_12ch_' sampleRates = ['48', '16', '32'] +# sampleRates = ['48'] for sr in sampleRates: file_name_7_1_4 = inpath + file_name_7_1_4_root + sr + 'k' @@ -56,7 +57,7 @@ for sr in sampleRates: subprocess.call(cmd, shell=False) # encode 7.1 64kb PARAMMC - cmd = [ivas_cod_exe, '-MC', '7_1', '-max_band', 'FB', '128000', sr, + cmd = [ivas_cod_exe, '-MC', '7_1', '-max_band', 'FB', '64000', sr, file_name_7_1 + '.wav', file_name_7_1 + '_64kb.ptk'] print(' '.join(cmd)) @@ -76,6 +77,21 @@ for sr in sampleRates: print(' '.join(cmd)) subprocess.call(cmd, shell=False) +# -render_config testv/config_renderer.cfg +# # decode binaural crend 7.1.4 +# cmd = [ivas_dec_exe, '-render_config', 'script/testv/config_renderer_fastconv.cfg', 'BINAURAL', sr, file_name_7_1_4 + +# '_512kb.ptk', file_name_7_1_4 + '-hrir.wav'] + +# print(' '.join(cmd)) +# subprocess.call(cmd, shell=False) + +# # decode binaural room crend 7.1.4 +# cmd = [ivas_dec_exe, 'BINAURAL_ROOM', sr, +# file_name_7_1_4 + '_128kb.ptk', file_name_7_1_4 + '-parammc_brir.wav'] + +# print(' '.join(cmd)) +# subprocess.call(cmd, shell=False) + # decode binaural crend 7.1.4 cmd = [ivas_dec_exe, 'BINAURAL', sr, file_name_7_1_4 + '_512kb.ptk', file_name_7_1_4 + '-hrir.wav'] @@ -85,11 +101,24 @@ for sr in sampleRates: # decode binaural room crend 7.1.4 cmd = [ivas_dec_exe, 'BINAURAL_ROOM', sr, - file_name_7_1_4 + '_512kb.ptk', file_name_7_1_4 + '-brir.wav'] + file_name_7_1_4 + '_128kb.ptk', file_name_7_1_4 + '-parammc_brir.wav'] print(' '.join(cmd)) subprocess.call(cmd, shell=False) + # decode binaural crend 7.1.4 + cmd = [ivas_dec_exe, 'BINAURAL', sr, file_name_7_1_4 + + '_128kb.ptk', file_name_7_1_4 + '-parammc_hrir.wav'] + + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) + + # decode binaural room crend 7.1.4 + cmd = [ivas_dec_exe, 'BINAURAL_ROOM', sr, + file_name_7_1_4 + '_512kb.ptk', file_name_7_1_4 + '-brir.wav'] + + print(' '.join(cmd)) + subprocess.call(cmd, shell=False) # decode binaural crend 7.1 cmd = [ivas_dec_exe, 'BINAURAL', sr, file_name_7_1 + '_512kb.ptk', file_name_7_1 + '-hrir.wav'] @@ -106,14 +135,14 @@ for sr in sampleRates: # decode binaural fastconv 7.1 cmd = [ivas_dec_exe, 'BINAURAL', sr, file_name_7_1 + - '_64kb.ptk', file_name_7_1 + '-fastconv-hrir.wav'] + '_64kb.ptk', file_name_7_1 + '-parammc-hrir.wav'] print(' '.join(cmd)) subprocess.call(cmd, shell=False) # decode binaural room fastconv 7.1 cmd = [ivas_dec_exe, 'BINAURAL_ROOM', sr, file_name_7_1 + - '_64kb.ptk', file_name_7_1 + '-fastconv-brir.wav'] + '_64kb.ptk', file_name_7_1 + '-parammc-brir.wav'] print(' '.join(cmd)) subprocess.call(cmd, shell=False) diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_io_parse.h b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_io_parse.h index abc8b1e463..dd6280d6e9 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_io_parse.h +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_io_parse.h @@ -31,9 +31,9 @@ *******************************************************************************************************/ /**************************************************************************** -* File description - -* This source file contains definitions specific to IVAS common renderer -****************************************************************************/ + * File description - + * This source file contains definitions specific to IVAS common renderer + ****************************************************************************/ #ifndef IVAS_CREND_IO_PARSE_H #define IVAS_CREND_IO_PARSE_H @@ -110,10 +110,14 @@ typedef struct ivas_crend_io_params_t char out_path[IVAS_MAX_PATH_LEN]; char prox_path[IVAS_MAX_PATH_LEN]; char csv_path[IVAS_MAX_PATH_LEN]; +#ifdef FIX_FIX_I59 + int32_t latency_ns; +#else float latency_s; - int32_t use_brir; - int32_t lfe_lp_enable; - int32_t limiter_enable; +#endif + int16_t use_brir; + int16_t lfe_lp_enable; + int16_t limiter_enable; ivas_crend_sanity_test_inp_t sanity_test; float no_diegetic_pan; float tol; diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_public.h b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_public.h index 057cfba10a..38b02c6df3 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_public.h +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_public.h @@ -31,9 +31,9 @@ *******************************************************************************************************/ /**************************************************************************** -* File description - -* This source file contains definitions specific to IVAS common renderer -****************************************************************************/ + * File description - + * This source file contains definitions specific to IVAS common renderer + ****************************************************************************/ #include "ivas_crend_io_parse.h" #include "ivas_dec_parse_io.h" @@ -62,7 +62,7 @@ #define IVAS_SOFA_THR_VAL ( 1e-15f ) AUDIO_CONFIG ivas_crend_map_out_fmt( IVAS_IN_OUT_FMT_CONFIG fmt ); -const char * ivas_crend_map_in_fmt( IVAS_IN_OUT_FMT_CONFIG fmt ); +const char *ivas_crend_map_in_fmt( IVAS_IN_OUT_FMT_CONFIG fmt ); ivas_result_t ivas_crend_default_io_params( ivas_crend_io_params_t *pIO_params ); ivas_result_t ivas_crend_parse_io_params( int argc, char **argv, ivas_crend_io_params_t *pIo_params ); @@ -74,7 +74,7 @@ int16_t ivas_get_num_channels( const int16_t ch_format ); ivas_result_t ivas_crend_copy_hrtf_data( HRTFS_DATA *hHrtf, HRTFS_DATA *pCrend_hrtfs ); -int32_t ivas_wrapper_get_frame_len( int32_t sample_rate ); +int16_t ivas_wrapper_get_frame_len( int32_t sample_rate ); ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, float *mixer ); diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_unit_test.c b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_unit_test.c index b2a24534c0..5ad498f38e 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_unit_test.c +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_unit_test.c @@ -85,31 +85,31 @@ { \ fclose( io_params.fOut ); \ } -#else -#define FILES_CLOSE \ - if ( NULL != io_params.fIn ) \ - { \ - for ( i = 0; i < IVAS_MAX_NUM_CH; i++ ) \ - { \ - if ( NULL != io_params.fIn[i] ) \ - { \ - AudioFileReader_close( &io_params.fIn[i] ); \ - io_params.fIn[i] = NULL; \ - } \ - } \ - } \ - if ( NULL != io_params.fRef ) \ - { \ - if ( NULL != io_params.fRef ) \ - { \ - AudioFileReader_close( &io_params.fRef ); \ - io_params.fRef = NULL; \ - } \ - } \ - if ( io_params.fOut != NULL ) \ - { \ - AudioFileWriter_close( &io_params.fOut ); \ - } +#else +#define FILES_CLOSE \ + if ( NULL != io_params.fIn ) \ + { \ + for ( i = 0; i < IVAS_MAX_NUM_CH; i++ ) \ + { \ + if ( NULL != io_params.fIn[i] ) \ + { \ + AudioFileReader_close( &io_params.fIn[i] ); \ + io_params.fIn[i] = NULL; \ + } \ + } \ + } \ + if ( NULL != io_params.fRef ) \ + { \ + if ( NULL != io_params.fRef ) \ + { \ + AudioFileReader_close( &io_params.fRef ); \ + io_params.fRef = NULL; \ + } \ + } \ + if ( io_params.fOut != NULL ) \ + { \ + AudioFileWriter_close( &io_params.fOut ); \ + } #endif /* temp change : to silence the compilation error */ int32_t frame = 0; /* Counter of frames */ @@ -200,7 +200,7 @@ static ivas_result_t ivas_crend_reverb_test( ivas_crend_io_params_t *pIo_params #else AudioFileWriter_close( &pIo_params->fOut ); AudioFileReader *fOut; - AudioFileReader_open( &fOut , pIo_params->out_path, pIo_params->sample_rate); + AudioFileReader_open( &fOut, pIo_params->out_path, pIo_params->sample_rate ); int16_t numRead; /* Compare */ if ( pIo_params->fRef ) @@ -277,7 +277,7 @@ static ivas_result_t ivas_crend_proximity_test( ivas_crend_io_params_t *pIo_para userLoc = (int16_t *) calloc( in_ch, sizeof( int16_t ) ); /* load bitstream data */ - num = (int16_t)fread( bitstream, sizeof( uint8_t ), MAX_BITSTREAM_LEN, pIo_params->fProx ); + num = (int16_t) fread( bitstream, sizeof( uint8_t ), MAX_BITSTREAM_LEN, pIo_params->fProx ); /* using bitstream information fill in the location in the userLoc vector */ get_users_locations( bitstream, num, userLoc ); @@ -289,10 +289,10 @@ static ivas_result_t ivas_crend_proximity_test( ivas_crend_io_params_t *pIo_para #ifdef USE_PCM_OUT int32_t i; - for (i = 0; i < in_ch; i++) + for ( i = 0; i < in_ch; i++ ) { - fseek(pIo_params->fRef, 0, SEEK_SET); - ivas_wav_header_skip(pIo_params->fRef); + fseek( pIo_params->fRef, 0, SEEK_SET ); + ivas_wav_header_skip( pIo_params->fRef ); } #endif #ifdef USE_PCM_OUT @@ -343,12 +343,12 @@ static ivas_result_t ivas_crend_proximity_test( ivas_crend_io_params_t *pIo_para { acc_0f = 0.0f; /* read reference channel correspnding to the given user in USER_ID */ - if ( (AudioFileReader_read( fRef , &ref, 1, &numRead ) != IVAS_ERR_OK) || (numRead == 0) ) + if ( ( AudioFileReader_read( fRef, &ref, 1, &numRead ) != IVAS_ERR_OK ) || ( numRead == 0 ) ) { printf( "Ref file finished\n" ); goto DONE; } - acc_0f = (float) ( ref ) * ( 1.0 / PCM16_TO_FLT_FAC ); + acc_0f = (float) ( ref ) * ( 1.0f / PCM16_TO_FLT_FAC ); /* compare to output from object mixer-renderer call above */ if ( ( AudioFileReader_read( fOut, &out, 1, &numRead ) != IVAS_ERR_OK ) || ( numRead == 0 ) ) @@ -356,7 +356,7 @@ static ivas_result_t ivas_crend_proximity_test( ivas_crend_io_params_t *pIo_para printf( "Output file finished\n" ); goto DONE; } - out_0f = (float) ( out ) * ( 1.0 / PCM16_TO_FLT_FAC ); + out_0f = (float) ( out ) * ( 1.0f / PCM16_TO_FLT_FAC ); /* check if much different.. */ if ( fabs( out_0f - acc_0f ) > TC_TOL ) @@ -369,7 +369,6 @@ static ivas_result_t ivas_crend_proximity_test( ivas_crend_io_params_t *pIo_para } - #endif DONE: if ( test == PASS ) @@ -445,7 +444,11 @@ static ivas_result_t ivas_crend_binaural_test( ivas_crend_io_params_t *pIo_param if ( pIo_params->fRef ) { ivas_wav_header_skip( pIo_params->fRef ); - skip_samples = (int32_t)( pIo_params->latency_s * pIo_params->sample_rate ); +#ifdef FIX_FIX_I59 + skip_samples = NS2SA( pIo_params->sample_rate, (float) Io_params->latency_ns + 0.5f ); +#else + skip_samples = (int32_t) ( pIo_params->latency_s * pIo_params->sample_rate ); +#endif if ( pIo_params->no_delay_cmp == 0 ) { skip_bytes = skip_samples * ivas_get_num_channels( BIN_2 ) * sizeof( int16_t ); @@ -499,11 +502,15 @@ static ivas_result_t ivas_crend_binaural_test( ivas_crend_io_params_t *pIo_param AudioFileReader_open( &fOut, pIo_params->out_path, pIo_params->sample_rate ); AudioFileReader_open( &fRef, pIo_params->ref_path, pIo_params->sample_rate ); +#ifdef FIX_FIX_I59 + skip_samples = NS2SA( pIo_params->sample_rate, (float) pIo_params->latency_ns + 0.5f ); +#else skip_samples = (int32_t) ( pIo_params->latency_s * pIo_params->sample_rate ); +#endif /* skip intial samples based on latency */ int16_t tail = 0; int32_t tail_zeros = 0; - + while ( ( AudioFileReader_read( fOut, &out, 1, &numRead ) == IVAS_ERR_OK ) && ( numRead > 0 ) && ( AudioFileReader_read( fRef, &ref, 1, &numRead ) == IVAS_ERR_OK ) && ( numRead > 0 ) ) { if ( fabs( (float) ( out ) * ( 1.0 / PCM16_TO_FLT_FAC ) - (float) ( ref ) * ( 1.0 / PCM16_TO_FLT_FAC ) ) > pIo_params->tol ) @@ -570,7 +577,7 @@ static ivas_result_t ivas_crend_no_diegetic_test( ivas_crend_io_params_t *pIo_pa if ( pIo_params->out_fmt != STEREO_2 ) return IVAS_FAILED; - no_diegetic_pan = pIo_params->no_diegetic_pan; + no_diegetic_pan = pIo_params->no_diegetic_pan; if ( no_diegetic_pan > 1 ) no_diegetic_pan = 1; if ( no_diegetic_pan < -1 ) @@ -589,7 +596,7 @@ static ivas_result_t ivas_crend_no_diegetic_test( ivas_crend_io_params_t *pIo_pa } #ifdef USE_PCM_OUT - int32_t in_ch,i; + int32_t in_ch, i; in_ch = ivas_get_num_channels( pIo_params->in_fmt ); /* Compare */ @@ -622,7 +629,7 @@ static ivas_result_t ivas_crend_no_diegetic_test( ivas_crend_io_params_t *pIo_pa #else /* Compare */ - int16_t numRead; + int16_t numRead; AudioFileReader_close( &pIo_params->fRef ); AudioFileWriter_close( &pIo_params->fOut ); AudioFileReader *fRef, *fOut; @@ -635,11 +642,11 @@ static ivas_result_t ivas_crend_no_diegetic_test( ivas_crend_io_params_t *pIo_pa { if ( ( AudioFileReader_read( fRef, &ref, 1, &numRead ) != IVAS_ERR_OK ) || ( numRead == 0 ) ) goto DONE; - ref_f = (float) ( ref ) * ( 1.0 / PCM16_TO_FLT_FAC ); + ref_f = (float) ( ref ) * ( 1.0f / PCM16_TO_FLT_FAC ); - if (( AudioFileReader_read( fOut, &out, 1, &numRead ) != IVAS_ERR_OK ) || (numRead == 0) ) + if ( ( AudioFileReader_read( fOut, &out, 1, &numRead ) != IVAS_ERR_OK ) || ( numRead == 0 ) ) goto DONE; - out_f = (float) ( out ) * ( 1.0 / PCM16_TO_FLT_FAC ); + out_f = (float) ( out ) * ( 1.0f / PCM16_TO_FLT_FAC ); if ( fabs( out_f - ref_f ) > TC_TOL ) test = FAIL; @@ -686,12 +693,12 @@ int main( int argc, char **argv ) if ( io_params.in_path[0] != '\0' ) { if ( - io_params.test == CREND_ACOUSTIC_PROXIMITY || - io_params.test == CREND_BIN_TEST || - io_params.test == FASTCONV_BIN_TEST || - io_params.test == PARAM_BIN_TEST || - io_params.test == TD_BIN_TEST || - io_params.test == CREND_TEST_NO_DIEGETIC ) + io_params.test == CREND_ACOUSTIC_PROXIMITY || + io_params.test == CREND_BIN_TEST || + io_params.test == FASTCONV_BIN_TEST || + io_params.test == PARAM_BIN_TEST || + io_params.test == TD_BIN_TEST || + io_params.test == CREND_TEST_NO_DIEGETIC ) { ivas_open_files_crend( &io_params ); } diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c index dfec494779..39224ed7ea 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c @@ -101,12 +101,13 @@ static int32_t ivas_check_rounding( float binaural_latencys_s[3], int16_t use_ro if ( use_round_for_lfe ) delay_lfe[ind1][ind2] = (int32_t) roundf( delay_ns[ind2] * sampleRates[ind1] / 1000000000.f ); else - delay_lfe[ind1][ind2] = (int32_t) ( delay_ns[ind2] * sampleRates[ind1] / 1000000000.f ); + delay_lfe[ind1][ind2] = (int32_t) NS2SA( sampleRates[ind1], delay_ns[ind2] ); if ( verbose ) printf( "\ndelay_lfe[%d][%d] = %ld\n", ind1, ind2, delay_lfe[ind1][ind2] ); *err_lfe += abs( delay_lfe[ind1][ind2] - wanted ); delay_dec[ind1][ind2] = NS2SA( sampleRates[ind1], (float) delay_ns[ind2] + 0.5f ); + // delay_dec[ind1][ind2] = NS2SA( sampleRates[ind1], (float) delay_ns[ind2] ); if ( verbose ) printf( "\ndelay_dec[%d][%d] = %ld \n", ind1, ind2, delay_dec[ind1][ind2] ); @@ -279,8 +280,8 @@ int16_t ivas_get_num_channels( static ivas_result_t ivas_crend_mixer( float ppPcm_in[][L_FRAME48k], float ppPcm_out[][L_FRAME48k], - int32_t in_ch, - int32_t out_ch, + int16_t in_ch, + int16_t out_ch, const float *pMixer_gain, const int16_t frame_len ) { @@ -384,9 +385,9 @@ ivas_result_t ivas_crend_default_io_params( ivas_crend_io_params_t *pIO_params ) * Outputs - * *-----------------------------------------------------------------------------------------*/ -int32_t ivas_wrapper_get_frame_len( int32_t sample_rate ) +int16_t ivas_wrapper_get_frame_len( int32_t sample_rate ) { - return ( (int32_t) ( sample_rate / FRAMES_PER_SEC ) ); + return ( (int16_t) ( sample_rate / FRAMES_PER_SEC ) ); } /*-----------------------------------------------------------------------------------------* @@ -431,8 +432,11 @@ static ivas_result_t ivas_crend_set_config_params( *-----------------------------------------------------------------------------------------*/ ivas_result_t ivas_crend_copy_latencies_to_io_params( ivas_crend_io_params_t *pIo_params, HRTFS_DATA *pCrend_hrtfs ) { - +#ifdef FIX_FIX_I59 + pIo_params->latency_ns = (int32_t) ( pCrend_hrtfs->latency_s * 1000000000.f ); +#else pIo_params->latency_s = pCrend_hrtfs->latency_s; +#endif return IVAS_SUCCESS; } @@ -820,7 +824,7 @@ ivas_result_t ivas_crend_parse_io_params( int argc, char **argv, ivas_crend_io_p } else { - pIo_params->no_diegetic_pan = atof( param ); + pIo_params->no_diegetic_pan = (float) atof( param ); } optional_args++; } @@ -907,9 +911,9 @@ ivas_result_t ivas_wav_header_skip( FILE *in_file ) *-----------------------------------------------------------------------------------------*/ static ivas_result_t ivas_wrapper_get_in_buf( ivas_crend_io_params_t *pIo_params, float ppPcm_in[][L_FRAME48k] ) { - int32_t i = 0, j = 0, samples_read = 0, num_in_ch = 0; - int32_t offset; - int32_t input_frame_len = ivas_wrapper_get_frame_len( pIo_params->sample_rate ); + int16_t i = 0, j = 0, samples_read = 0, num_in_ch = 0; + int16_t offset; + int16_t input_frame_len = ivas_wrapper_get_frame_len( pIo_params->sample_rate ); int16_t tmp, read = 0; num_in_ch = ivas_get_num_channels( pIo_params->in_fmt ); @@ -1092,8 +1096,8 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl int64_t frame_count = 0; - int32_t i = 0, j = 0; - int32_t frame_len = 0; + int16_t i = 0, j = 0; + int16_t frame_len = 0; ivas_dec_io_params_t dec_io_params; int16_t in_format; @@ -1133,7 +1137,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl } } #endif - /* test rounding error + /* test rounding error */ float binaural_latencys_fastconv_s[3] = { FASTCONV_HRIR_latency_s, FASTCONV_BRIR_latency_s, FASTCONV_BRIR_latency_s }; float binaural_latencys_crend_s[3] = { 1.f / 48000.f, 2.f / 48000.f, 3.f / 48000.f }; float binaural_latencys_td_s[3] = { BINAURAL_TD_LATENCY_S, BINAURAL_TD_LATENCY_S + 1.f / 48000.f, BINAURAL_TD_LATENCY_S + 2.f / 48000.f }; @@ -1166,7 +1170,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); err += ivas_check_rounding( binaural_latencys_td_s, 1, 1, &err_lfe, &err_dec, 0 ); printf( "\n\nerr = %ld err_lfe = %ld err_dec = %ld\n\n", err, err_lfe, err_dec ); -*/ + ivas_render_config_open( &st_ivas.hRenderConfig ); ivas_render_config_init_from_rom( &st_ivas.hRenderConfig, 0 ); @@ -1205,7 +1209,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl st_ivas.renderer_type = RENDERER_BINAURAL_FASTCONV_ROOM; st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL_ROOM; #ifdef FIX_FIX_I59 - pIo_params->latency_s = roundf( IVAS_FB_DEC_DELAY_NS + FASTCONV_BRIR_latency_s * 1000000000.f ); + pIo_params->latency_ns = ( IVAS_FB_DEC_DELAY_NS + (int32_t) ( FASTCONV_BRIR_latency_s * 1000000000.f ) ); #else pIo_params->latency_s = ( (float) frame_len ) / (float) dec_io_params.out_sample_rate + FASTCONV_BRIR_latency_s; #endif @@ -1216,13 +1220,13 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL; if ( st_ivas.ivas_format == MC_FORMAT ) #ifdef FIX_FIX_I59 - pIo_params->latency_s = roundf( IVAS_FB_DEC_DELAY_NS + FASTCONV_HRIR_latency_s * 1000000000.f ); + pIo_params->latency_ns = ( IVAS_FB_DEC_DELAY_NS + (int32_t) ( FASTCONV_HRIR_latency_s * 1000000000.f ) ); #else pIo_params->latency_s = ( (float) frame_len ) / (float) dec_io_params.out_sample_rate + FASTCONV_HRIR_latency_s; #endif else #ifdef FIX_FIX_I59 - pIo_params->latency_s = roundf( IVAS_FB_DEC_DELAY_NS + FASTCONV_HOA3_latency_s * 1000000000.f ); + pIo_params->latency_ns = ( IVAS_FB_DEC_DELAY_NS + (int32_t) ( FASTCONV_HOA3_latency_s * 1000000000.f ) ); #else pIo_params->latency_s = ( (float) frame_len ) / (float) dec_io_params.out_sample_rate + FASTCONV_HOA3_latency_s; #endif @@ -1247,7 +1251,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL; } #ifdef FIX_FIX_I59 - pIo_params->latency_s = roundf( BINAURAL_TD_LATENCY_S * 1000000000.f ); + pIo_params->latency_ns = (int32_t) ( BINAURAL_TD_LATENCY_S * 1000000000.f ); #else pIo_params->latency_s = BINAURAL_TD_LATENCY_S; #endif @@ -1265,7 +1269,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl st_ivas.hOutSetup.output_config = st_ivas.hDecoderConfig->output_config = AUDIO_CONFIG_BINAURAL; } #ifdef FIX_FIX_I59 - pIo_params->latency_s = IVAS_FB_DEC_DELAY_NS; + pIo_params->latency_ns = IVAS_FB_DEC_DELAY_NS; #else pIo_params->latency_s = ( (float) frame_len ) / (float) dec_io_params.out_sample_rate; #endif @@ -1294,8 +1298,8 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl ivas_hrtf_init( st_ivas.hHrtf ); } - int32_t in_ch = audioCfg2channels( st_ivas.transport_config ); - int32_t out_ch = audioCfg2channels( st_ivas.hDecoderConfig->output_config ); + int16_t in_ch = audioCfg2channels( st_ivas.transport_config ); + int16_t out_ch = audioCfg2channels( st_ivas.hDecoderConfig->output_config ); /*------------------------------------------------------------------------------------------* * State memory allocation for Common renderer @@ -1409,7 +1413,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl if ( pIo_params->test == CREND_BIN_TEST ) { #ifdef FIX_FIX_I59 - pIo_params->latency_s = roundf( st_ivas.hHrtf->latency_s * 1000000000.f ); + pIo_params->latency_ns = (int32_t) ( st_ivas.hHrtf->latency_s * 1000000000.f ); #else pIo_params->latency_s = st_ivas.hHrtf->latency_s; #endif @@ -1417,7 +1421,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl if ( st_ivas.ivas_format == MC_FORMAT ) { #ifdef FIX_FIX_I59 - ivas_create_lfe_dec( &st_ivas.hLFE, st_ivas.hDecoderConfig->output_Fs, (int32_t) ( pIo_params->latency_s * 1000000000.f ) ); + ivas_create_lfe_dec( &st_ivas.hLFE, st_ivas.hDecoderConfig->output_Fs, pIo_params->latency_ns ); #else ivas_create_lfe_dec( &st_ivas.hLFE, st_ivas.hDecoderConfig->output_Fs, pIo_params->latency_s ); #endif @@ -1428,9 +1432,15 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl count_free( st_ivas.hLFE->lfe_delay_buf ); st_ivas.hLFE->lfe_delay_buf = NULL; } +#ifdef FIX_FIX_I59 + if ( pIo_params->latency_ns > 0 ) + { + st_ivas.hLFE->lfe_addl_delay = (int16_t) roundf( (float) pIo_params->latency_ns * (float) dec_io_params.out_sample_rate / 1000000000.f ); +#else if ( pIo_params->latency_s > 0 ) { st_ivas.hLFE->lfe_addl_delay = (int16_t) roundf( pIo_params->latency_s * dec_io_params.out_sample_rate ); +#endif if ( st_ivas.hLFE->lfe_addl_delay > 0 ) { if ( ( st_ivas.hLFE->lfe_delay_buf = (float *) count_malloc( st_ivas.hLFE->lfe_addl_delay * sizeof( float ) ) ) == NULL ) @@ -1459,7 +1469,11 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl } ivas_lfe_lpf_select_filt_coeff( pIo_params->sample_rate, IVAS_FILTER_ORDER_4, &filt_coeff ); ivas_filters_init( &st_ivas.hLFE->filter_state, filt_coeff, IVAS_FILTER_ORDER_4 ); +#ifdef FIX_FIX_I59 + pIo_params->latency_ns = pIo_params->latency_ns + (int32_t) ( ivas_lfe_lpf_delay[1] * 1000000000.f ); +#else pIo_params->latency_s = pIo_params->latency_s + ivas_lfe_lpf_delay[1]; +#endif } else { @@ -1491,7 +1505,11 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl int16_t write_flag = 0; if ( ( pIo_params->out_fmt == BIN_2 ) && ( pIo_params->no_delay_cmp == 0 ) ) { +#ifdef FIX_FIX_I59 + skip_samples = NS2SA( pIo_params->sample_rate, (float) pIo_params->latency_ns + 0.5f ); +#else skip_samples = NS2SA( pIo_params->sample_rate, (int32_t) ( pIo_params->latency_s * 1000000000.f ) ); +#endif } fprintf( stdout, "IVAS Common Renderer skip samples = %d\n", (int) skip_samples ); @@ -1519,7 +1537,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl { if ( i != lfe_ch_idx ) { - delay_signal( ppPcm_in[idx], frame_len, ppDelay_lines[idx], delay_lp ); + delay_signal( ppPcm_in[i], frame_len, ppDelay_lines[idx], delay_lp ); idx++; } } @@ -1663,7 +1681,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl #endif pcm[i] = ( temp > MAX16B ) ? MAX16B : ( temp < MIN16B_FLT ) ? MIN16B : (short) temp; - clip = max( clip, fabs( ppPcm_out[i][j] ) ); + clip = max( clip, fabsf( ppPcm_out[i][j] ) ); } if ( write_flag == 1 ) { @@ -1693,7 +1711,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl } #ifdef _FIND_MAX_ - valEner = sqrt( valEner / ( frame_count * frame_len ) ); + valEner = sqrtf( valEner / ( frame_count * frame_len ) ); printf( "valMax = %f valEner = %f \n", 20.f * log10( valMax ), 20.f * log10( valEner ) ); #endif printf( "Total Frames Processed : %lld\n", (long long int) frame_count ); @@ -1771,8 +1789,8 @@ ivas_result_t ivas_object_mixer_renderer( ivas_crend_io_params_t *pIo_params, in int64_t frame_count = 0; - int32_t i = 0, j = 0; - int32_t frame_len = 0; + int16_t i = 0, j = 0; + int16_t frame_len = 0; float *Smixer; float *powvec; @@ -1824,8 +1842,8 @@ ivas_result_t ivas_object_mixer_renderer( ivas_crend_io_params_t *pIo_params, in /*------------------------------------------------------------------------------------------* * In/out buffer memory allocation for encoder *------------------------------------------------------------------------------------------*/ - int32_t in_ch = ivas_get_num_channels( pIo_params->in_fmt ); - int32_t out_ch = ivas_get_num_channels( pIo_params->out_fmt ); + int16_t in_ch = ivas_get_num_channels( pIo_params->in_fmt ); + int16_t out_ch = ivas_get_num_channels( pIo_params->out_fmt ); Smixer = (float *) calloc( in_ch, sizeof( float ) ); powvec = (float *) calloc( in_ch, sizeof( float ) ); @@ -1913,7 +1931,7 @@ ivas_result_t ivas_object_mixer_renderer( ivas_crend_io_params_t *pIo_params, in free( Smixer ); #ifdef _FIND_MAX_ - valEner = sqrt( valEner / ( frame_count * frame_len ) ); + valEner = sqrtf( valEner / ( frame_count * frame_len ) ); printf( "valMax = %f valEner = %f \n", 20.f * log10( valMax ), 20.f * log10( valEner ) ); #endif printf( "Total Frames Processed : %lld\n", (long long int) frame_count ); diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_dec_parse_io.h b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_dec_parse_io.h index ed4071d8ca..0871946999 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_dec_parse_io.h +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_dec_parse_io.h @@ -34,13 +34,13 @@ #define IVAS_DEC_PARSE_IO_H /**************************************************************************** -* File description - -* This header file contains declarations for IO/cmd line params parsing of IVAS decoder -****************************************************************************/ + * File description - + * This header file contains declarations for IO/cmd line params parsing of IVAS decoder + ****************************************************************************/ /*------------------------------------------------------------------------------------------* -* include header files -*------------------------------------------------------------------------------------------*/ + * include header files + *------------------------------------------------------------------------------------------*/ #include #include #include @@ -48,8 +48,8 @@ #include "audio_file_writer.h" /*------------------------------------------------------------------------------------------* -* PreProcessor -*------------------------------------------------------------------------------------------*/ + * PreProcessor + *------------------------------------------------------------------------------------------*/ #define IVAS_IN_FMT_COMBINED "Combined" #define IVAS_IN_FMT_HOA_3 "HOA3S" @@ -64,8 +64,8 @@ #define MAX_CH_IDX_TAG_LEN ( 10 ) /*------------------------------------------------------------------------------------------* -* Global variables -*------------------------------------------------------------------------------------------*/ + * Global variables + *------------------------------------------------------------------------------------------*/ /* IVAS bitstream formats */ #define IVAS_G192 ( 0 ) #define IVAS_MIME ( 1 ) @@ -92,11 +92,11 @@ #define IVAS_MAX_NUM_CH 16 /*------------------------------------------------------------------------------------------* -* Structure definitions -*------------------------------------------------------------------------------------------*/ + * Structure definitions + *------------------------------------------------------------------------------------------*/ typedef struct ivas_dec_io_params_t { - int32_t in_fmt; + int16_t in_fmt; int32_t out_sample_rate; int32_t out_fmt; int32_t crend_enable; -- GitLab From 6f17811674259bca2c514a3b6fdc5ca3428ec1fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20Toftg=C3=A5rd?= Date: Thu, 24 Nov 2022 11:14:18 +0100 Subject: [PATCH 08/13] Using roundf() instead of NS2SA for nanosec to sample conversion to get rounding in sample domain. --- lib_dec/lib_dec.c | 4 ++-- .../tests/unit_tests/crend/ivas_crend_unit_test.c | 4 ++-- .../tests/unit_tests/crend/ivas_crend_utest_utils.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index cc28ff0b40..cbe3d995dc 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1056,13 +1056,13 @@ ivas_error IVAS_DEC_GetDelay( hDecoderConfig = st_ivas->hDecoderConfig; #ifdef FIX_I59_LFE_TD_DELAY #ifdef FIX_I59_DELAY_ROUNDING - *nSamples = NS2SA( hDecoderConfig->output_Fs, get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], st_ivas->binaural_latency_ns ) + 0.5f ); + *nSamples = (int16_t) roundf( get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], st_ivas->binaural_latency_ns ) * hDecoderConfig->output_Fs / 1000000000.f ); #else *nSamples = NS2SA( hDecoderConfig->output_Fs, (int32_t) ( get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], st_ivas->binaural_latency_ns ) + 0.5f ) ); #endif #else #ifdef FIX_I59_DELAY_ROUNDING - *nSamples = NS2SA( hDecoderConfig->output_Fs, get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], st_ivas->renderer_type, st_ivas->binaural_latency_ns ) + 0.5f ); + *nSamples = (int16_t) roundf( get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], st_ivas->renderer_type, st_ivas->binaural_latency_ns ) * hDecoderConfig->output_Fs / 1000000000.f ); #else *nSamples = NS2SA( hDecoderConfig->output_Fs, (int32_t) ( get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], st_ivas->renderer_type, st_ivas->binaural_latency_ns ) + 0.5f ) ); #endif diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_unit_test.c b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_unit_test.c index 5ad498f38e..9623c59fad 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_unit_test.c +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_unit_test.c @@ -445,7 +445,7 @@ static ivas_result_t ivas_crend_binaural_test( ivas_crend_io_params_t *pIo_param { ivas_wav_header_skip( pIo_params->fRef ); #ifdef FIX_FIX_I59 - skip_samples = NS2SA( pIo_params->sample_rate, (float) Io_params->latency_ns + 0.5f ); + skip_samples = (int32_t) roundf( (float) pIo_params->latency_ns * pIo_params->sample_rate / 1000000000.f ); #else skip_samples = (int32_t) ( pIo_params->latency_s * pIo_params->sample_rate ); #endif @@ -503,7 +503,7 @@ static ivas_result_t ivas_crend_binaural_test( ivas_crend_io_params_t *pIo_param AudioFileReader_open( &fRef, pIo_params->ref_path, pIo_params->sample_rate ); #ifdef FIX_FIX_I59 - skip_samples = NS2SA( pIo_params->sample_rate, (float) pIo_params->latency_ns + 0.5f ); + skip_samples = (int32_t) roundf( (float) pIo_params->latency_ns * pIo_params->sample_rate / 1000000000.f ); #else skip_samples = (int32_t) ( pIo_params->latency_s * pIo_params->sample_rate ); #endif diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c index 39224ed7ea..3770e0eed5 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c @@ -1506,7 +1506,7 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl if ( ( pIo_params->out_fmt == BIN_2 ) && ( pIo_params->no_delay_cmp == 0 ) ) { #ifdef FIX_FIX_I59 - skip_samples = NS2SA( pIo_params->sample_rate, (float) pIo_params->latency_ns + 0.5f ); + skip_samples = (int32_t) roundf( (float) pIo_params->latency_ns * pIo_params->sample_rate / 1000000000.f ); #else skip_samples = NS2SA( pIo_params->sample_rate, (int32_t) ( pIo_params->latency_s * 1000000000.f ) ); #endif -- GitLab From b6abbbd14285705c50c25fc71c322fd01a389a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20Toftg=C3=A5rd?= Date: Thu, 24 Nov 2022 18:52:47 +0100 Subject: [PATCH 09/13] Applied clang formatting. --- lib_com/delay_comp.c | 8 +- lib_com/prot.h | 8 +- lib_dec/ivas_lfe_dec.c | 2 +- .../unit_tests/crend/ivas_crend_io_parse.h | 6 +- .../unit_tests/crend/ivas_crend_public.h | 8 +- .../unit_tests/crend/ivas_crend_unit_test.c | 87 +++++++++---------- .../unit_tests/crend/ivas_crend_unit_test.h | 6 +- .../unit_tests/crend/ivas_dec_parse_io.h | 22 ++--- .../tests/unit_tests/crend/ivas_prox_mix.c | 72 +++++++-------- .../tests/unit_tests/crend/ivas_prox_mix.h | 16 ++-- 10 files changed, 117 insertions(+), 118 deletions(-) diff --git a/lib_com/delay_comp.c b/lib_com/delay_comp.c index 7d0ba19485..cce609a00d 100644 --- a/lib_com/delay_comp.c +++ b/lib_com/delay_comp.c @@ -51,10 +51,10 @@ /*! r: delay value in ns */ float get_delay( - const int16_t what_delay, /* i : what delay? (ENC or DEC) */ - const int32_t io_fs, /* i : input/output sampling frequency */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - HANDLE_CLDFB_FILTER_BANK hCldfb, /* i : Handle of Cldfb analysis */ + const int16_t what_delay, /* i : what delay? (ENC or DEC) */ + const int32_t io_fs, /* i : input/output sampling frequency */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + HANDLE_CLDFB_FILTER_BANK hCldfb, /* i : Handle of Cldfb analysis */ #ifndef FIX_I59_LFE_TD_DELAY RENDERER_TYPE renderer_type, /* i : IVAS rendering type */ const int32_t binaural_latency_ns /* i : binaural renderer HRTF delay in ns */ diff --git a/lib_com/prot.h b/lib_com/prot.h index 1e8df861b0..b3b31e24fa 100755 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -713,10 +713,10 @@ int16_t lev_dur( /*! r: delay value in ns */ float get_delay( - const int16_t what_delay, /* i : what delay? (ENC or DEC) */ - const int32_t io_fs, /* i : input/output sampling frequency */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - HANDLE_CLDFB_FILTER_BANK hCldfb, /* i : Handle of Cldfb analysis */ + const int16_t what_delay, /* i : what delay? (ENC or DEC) */ + const int32_t io_fs, /* i : input/output sampling frequency */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + HANDLE_CLDFB_FILTER_BANK hCldfb, /* i : Handle of Cldfb analysis */ #ifndef FIX_I59_LFE_TD_DELAY RENDERER_TYPE renderer_type, /* i : IVAS rendering type */ const int32_t binaural_latency_ns /* i : binaural renderer HRTF delay in ns */ diff --git a/lib_dec/ivas_lfe_dec.c b/lib_dec/ivas_lfe_dec.c index b6b7b46c37..70e3a2fff4 100644 --- a/lib_dec/ivas_lfe_dec.c +++ b/lib_dec/ivas_lfe_dec.c @@ -355,7 +355,7 @@ ivas_error ivas_create_lfe_dec( #ifdef FIX_I59_LFE_TD_DELAY const int32_t binauralization_delay_ns /* i : additional LFE delay to sync with binaural renderer */ #else - const float add_delay_s /* i : additional LFE delay to sync with binaural filter */ + const float add_delay_s /* i : additional LFE delay to sync with binaural filter */ #endif ) { diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_io_parse.h b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_io_parse.h index deeb400926..bcdbd84487 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_io_parse.h +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_io_parse.h @@ -31,9 +31,9 @@ *******************************************************************************************************/ /**************************************************************************** -* File description - -* This source file contains definitions specific to IVAS common renderer -****************************************************************************/ + * File description - + * This source file contains definitions specific to IVAS common renderer + ****************************************************************************/ #ifndef IVAS_CREND_IO_PARSE_H #define IVAS_CREND_IO_PARSE_H diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_public.h b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_public.h index d6fbf9f3ca..38b02c6df3 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_public.h +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_public.h @@ -31,9 +31,9 @@ *******************************************************************************************************/ /**************************************************************************** -* File description - -* This source file contains definitions specific to IVAS common renderer -****************************************************************************/ + * File description - + * This source file contains definitions specific to IVAS common renderer + ****************************************************************************/ #include "ivas_crend_io_parse.h" #include "ivas_dec_parse_io.h" @@ -62,7 +62,7 @@ #define IVAS_SOFA_THR_VAL ( 1e-15f ) AUDIO_CONFIG ivas_crend_map_out_fmt( IVAS_IN_OUT_FMT_CONFIG fmt ); -const char * ivas_crend_map_in_fmt( IVAS_IN_OUT_FMT_CONFIG fmt ); +const char *ivas_crend_map_in_fmt( IVAS_IN_OUT_FMT_CONFIG fmt ); ivas_result_t ivas_crend_default_io_params( ivas_crend_io_params_t *pIO_params ); ivas_result_t ivas_crend_parse_io_params( int argc, char **argv, ivas_crend_io_params_t *pIo_params ); diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_unit_test.c b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_unit_test.c index e94a0d4793..0c8d7590a3 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_unit_test.c +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_unit_test.c @@ -85,31 +85,31 @@ { \ fclose( io_params.fOut ); \ } -#else -#define FILES_CLOSE \ - if ( NULL != io_params.fIn ) \ - { \ - for ( i = 0; i < IVAS_MAX_NUM_CH; i++ ) \ - { \ - if ( NULL != io_params.fIn[i] ) \ - { \ - AudioFileReader_close( &io_params.fIn[i] ); \ - io_params.fIn[i] = NULL; \ - } \ - } \ - } \ - if ( NULL != io_params.fRef ) \ - { \ - if ( NULL != io_params.fRef ) \ - { \ - AudioFileReader_close( &io_params.fRef ); \ - io_params.fRef = NULL; \ - } \ - } \ - if ( io_params.fOut != NULL ) \ - { \ - AudioFileWriter_close( &io_params.fOut ); \ - } +#else +#define FILES_CLOSE \ + if ( NULL != io_params.fIn ) \ + { \ + for ( i = 0; i < IVAS_MAX_NUM_CH; i++ ) \ + { \ + if ( NULL != io_params.fIn[i] ) \ + { \ + AudioFileReader_close( &io_params.fIn[i] ); \ + io_params.fIn[i] = NULL; \ + } \ + } \ + } \ + if ( NULL != io_params.fRef ) \ + { \ + if ( NULL != io_params.fRef ) \ + { \ + AudioFileReader_close( &io_params.fRef ); \ + io_params.fRef = NULL; \ + } \ + } \ + if ( io_params.fOut != NULL ) \ + { \ + AudioFileWriter_close( &io_params.fOut ); \ + } #endif /* temp change : to silence the compilation error */ int32_t frame = 0; /* Counter of frames */ @@ -200,7 +200,7 @@ static ivas_result_t ivas_crend_reverb_test( ivas_crend_io_params_t *pIo_params #else AudioFileWriter_close( &pIo_params->fOut ); AudioFileReader *fOut; - AudioFileReader_open( &fOut , pIo_params->out_path, &pIo_params->sample_rate); + AudioFileReader_open( &fOut, pIo_params->out_path, &pIo_params->sample_rate ); int16_t numRead; /* Compare */ if ( pIo_params->fRef ) @@ -277,7 +277,7 @@ static ivas_result_t ivas_crend_proximity_test( ivas_crend_io_params_t *pIo_para userLoc = (int16_t *) calloc( in_ch, sizeof( int16_t ) ); /* load bitstream data */ - num = (int16_t)fread( bitstream, sizeof( uint8_t ), MAX_BITSTREAM_LEN, pIo_params->fProx ); + num = (int16_t) fread( bitstream, sizeof( uint8_t ), MAX_BITSTREAM_LEN, pIo_params->fProx ); /* using bitstream information fill in the location in the userLoc vector */ get_users_locations( bitstream, num, userLoc ); @@ -289,10 +289,10 @@ static ivas_result_t ivas_crend_proximity_test( ivas_crend_io_params_t *pIo_para #ifdef USE_PCM_OUT int32_t i; - for (i = 0; i < in_ch; i++) + for ( i = 0; i < in_ch; i++ ) { - fseek(pIo_params->fRef, 0, SEEK_SET); - ivas_wav_header_skip(pIo_params->fRef); + fseek( pIo_params->fRef, 0, SEEK_SET ); + ivas_wav_header_skip( pIo_params->fRef ); } #endif #ifdef USE_PCM_OUT @@ -343,7 +343,7 @@ static ivas_result_t ivas_crend_proximity_test( ivas_crend_io_params_t *pIo_para { acc_0f = 0.0f; /* read reference channel correspnding to the given user in USER_ID */ - if ( (AudioFileReader_read( fRef , &ref, 1, &numRead ) != IVAS_ERR_OK) || (numRead == 0) ) + if ( ( AudioFileReader_read( fRef, &ref, 1, &numRead ) != IVAS_ERR_OK ) || ( numRead == 0 ) ) { printf( "Ref file finished\n" ); goto DONE; @@ -369,7 +369,6 @@ static ivas_result_t ivas_crend_proximity_test( ivas_crend_io_params_t *pIo_para } - #endif DONE: if ( test == PASS ) @@ -452,7 +451,7 @@ static ivas_result_t ivas_crend_binaural_test( ivas_crend_io_params_t *pIo_param #ifdef FIX_FIX_I59 skip_samples = (int32_t) roundf( (float) pIo_params->latency_ns * pIo_params->sample_rate / 1000000000.f ); #else - skip_samples = (int32_t)( pIo_params->latency_s * pIo_params->sample_rate ); + skip_samples = (int32_t) ( pIo_params->latency_s * pIo_params->sample_rate ); #endif if ( pIo_params->no_delay_cmp == 0 ) { @@ -515,7 +514,7 @@ static ivas_result_t ivas_crend_binaural_test( ivas_crend_io_params_t *pIo_param /* skip intial samples based on latency */ int16_t tail = 0; int32_t tail_zeros = 0; - + while ( ( AudioFileReader_read( fOut, &out, 1, &numRead ) == IVAS_ERR_OK ) && ( numRead > 0 ) && ( AudioFileReader_read( fRef, &ref, 1, &numRead ) == IVAS_ERR_OK ) && ( numRead > 0 ) ) { if ( fabs( (float) ( out ) * ( 1.0 / PCM16_TO_FLT_FAC ) - (float) ( ref ) * ( 1.0 / PCM16_TO_FLT_FAC ) ) > pIo_params->tol ) @@ -582,7 +581,7 @@ static ivas_result_t ivas_crend_no_diegetic_test( ivas_crend_io_params_t *pIo_pa if ( pIo_params->out_fmt != STEREO_2 ) return IVAS_FAILED; - no_diegetic_pan = pIo_params->no_diegetic_pan; + no_diegetic_pan = pIo_params->no_diegetic_pan; if ( no_diegetic_pan > 1 ) no_diegetic_pan = 1; if ( no_diegetic_pan < -1 ) @@ -601,7 +600,7 @@ static ivas_result_t ivas_crend_no_diegetic_test( ivas_crend_io_params_t *pIo_pa } #ifdef USE_PCM_OUT - int32_t in_ch,i; + int32_t in_ch, i; in_ch = ivas_get_num_channels( pIo_params->in_fmt ); /* Compare */ @@ -634,7 +633,7 @@ static ivas_result_t ivas_crend_no_diegetic_test( ivas_crend_io_params_t *pIo_pa #else /* Compare */ - int16_t numRead; + int16_t numRead; AudioFileReader_close( &pIo_params->fRef ); AudioFileWriter_close( &pIo_params->fOut ); AudioFileReader *fRef, *fOut; @@ -649,7 +648,7 @@ static ivas_result_t ivas_crend_no_diegetic_test( ivas_crend_io_params_t *pIo_pa goto DONE; ref_f = (float) ( ref ) * ( 1.0f / PCM16_TO_FLT_FAC ); - if (( AudioFileReader_read( fOut, &out, 1, &numRead ) != IVAS_ERR_OK ) || (numRead == 0) ) + if ( ( AudioFileReader_read( fOut, &out, 1, &numRead ) != IVAS_ERR_OK ) || ( numRead == 0 ) ) goto DONE; out_f = (float) ( out ) * ( 1.0f / PCM16_TO_FLT_FAC ); @@ -698,12 +697,12 @@ int main( int argc, char **argv ) if ( io_params.in_path[0] != '\0' ) { if ( - io_params.test == CREND_ACOUSTIC_PROXIMITY || - io_params.test == CREND_BIN_TEST || - io_params.test == FASTCONV_BIN_TEST || - io_params.test == PARAM_BIN_TEST || - io_params.test == TD_BIN_TEST || - io_params.test == CREND_TEST_NO_DIEGETIC ) + io_params.test == CREND_ACOUSTIC_PROXIMITY || + io_params.test == CREND_BIN_TEST || + io_params.test == FASTCONV_BIN_TEST || + io_params.test == PARAM_BIN_TEST || + io_params.test == TD_BIN_TEST || + io_params.test == CREND_TEST_NO_DIEGETIC ) { ivas_open_files_crend( &io_params ); } diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_unit_test.h b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_unit_test.h index c26134aba1..379a23ce2b 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_unit_test.h +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_unit_test.h @@ -31,9 +31,9 @@ *******************************************************************************************************/ /**************************************************************************** -* File description - -* This source file contains definitions specific to IVAS common renderer -****************************************************************************/ + * File description - + * This source file contains definitions specific to IVAS common renderer + ****************************************************************************/ #ifndef IVAS_CREND_UNIT_TEST_H #define IVAS_CREND_UNIT_TEST_H diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_dec_parse_io.h b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_dec_parse_io.h index 4cec7e1d6f..ca18f63be1 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_dec_parse_io.h +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_dec_parse_io.h @@ -34,13 +34,13 @@ #define IVAS_DEC_PARSE_IO_H /**************************************************************************** -* File description - -* This header file contains declarations for IO/cmd line params parsing of IVAS decoder -****************************************************************************/ + * File description - + * This header file contains declarations for IO/cmd line params parsing of IVAS decoder + ****************************************************************************/ /*------------------------------------------------------------------------------------------* -* include header files -*------------------------------------------------------------------------------------------*/ + * include header files + *------------------------------------------------------------------------------------------*/ #include #include #include @@ -48,8 +48,8 @@ #include "audio_file_writer.h" /*------------------------------------------------------------------------------------------* -* PreProcessor -*------------------------------------------------------------------------------------------*/ + * PreProcessor + *------------------------------------------------------------------------------------------*/ #define IVAS_IN_FMT_COMBINED "Combined" #define IVAS_IN_FMT_HOA_3 "HOA3S" @@ -64,8 +64,8 @@ #define MAX_CH_IDX_TAG_LEN ( 10 ) /*------------------------------------------------------------------------------------------* -* Global variables -*------------------------------------------------------------------------------------------*/ + * Global variables + *------------------------------------------------------------------------------------------*/ /* IVAS bitstream formats */ #define IVAS_G192 ( 0 ) #define IVAS_MIME ( 1 ) @@ -93,8 +93,8 @@ #define IVAS_MAX_NUM_CH 16 /*------------------------------------------------------------------------------------------* -* Structure definitions -*------------------------------------------------------------------------------------------*/ + * Structure definitions + *------------------------------------------------------------------------------------------*/ typedef struct ivas_dec_io_params_t { int16_t in_fmt; diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_prox_mix.c b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_prox_mix.c index 2bf19080e5..b55c43b6f8 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_prox_mix.c +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_prox_mix.c @@ -31,14 +31,14 @@ *******************************************************************************************************/ /*-----------------------------------------------------------------------------------------* -* File description - -* This file contains funciton definitions which are common between IVAS spatial decoding -* tools -*-----------------------------------------------------------------------------------------*/ + * File description - + * This file contains funciton definitions which are common between IVAS spatial decoding + * tools + *-----------------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------------------* -* include header files -*------------------------------------------------------------------------------------------*/ + * include header files + *------------------------------------------------------------------------------------------*/ #include #include "options.h" #ifdef DEBUGGING @@ -48,16 +48,16 @@ #include "wmops.h" /*------------------------------------------------------------------------------------------* -* PreProcessor -*------------------------------------------------------------------------------------------*/ + * PreProcessor + *------------------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------------------* * Global variables *------------------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------------------* - * Static functions declaration - *------------------------------------------------------------------------------------------*/ + * Static functions declaration + *------------------------------------------------------------------------------------------*/ static float get_block_power( float *vec, int32_t frame_len ); @@ -66,23 +66,23 @@ static float get_block_power( float *vec, int32_t frame_len ); *------------------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------------* - * Function description - Returns mixer to combine uplink signals in an intelligent way to - * prevent unnecessary reproduction of certain signals and prevent acoustic feedback. - * - * Inputs - - * userID: a given user ID - * bitstream: float of bitstream data containing co-located user IDs - * pMixer: a 1-d mixer to be used in ivas_crend to combine the multichannel audio data into - * a single Mono signal. - * Outputs - - * - * - * - *-----------------------------------------------------------------------------------------*/ - -ivas_result_t get_users_locations( - uint8_t *bitstream, - int32_t len, + * Function description - Returns mixer to combine uplink signals in an intelligent way to + * prevent unnecessary reproduction of certain signals and prevent acoustic feedback. + * + * Inputs - + * userID: a given user ID + * bitstream: float of bitstream data containing co-located user IDs + * pMixer: a 1-d mixer to be used in ivas_crend to combine the multichannel audio data into + * a single Mono signal. + * Outputs - + * + * + * + *-----------------------------------------------------------------------------------------*/ + +ivas_result_t get_users_locations( + uint8_t *bitstream, + int32_t len, int16_t *userLoc ) { /* userID = channelID starting from index=0 */ @@ -107,13 +107,13 @@ ivas_result_t get_users_locations( } -ivas_result_t get_prox_downmix_mixer( - int16_t userID, - float *sMixer, - int16_t *userLoc, - int32_t nChan, - float ppPcm_in[][L_FRAME48k], - int32_t frame_len, +ivas_result_t get_prox_downmix_mixer( + int16_t userID, + float *sMixer, + int16_t *userLoc, + int32_t nChan, + float ppPcm_in[][L_FRAME48k], + int32_t frame_len, float *powvec ) { /* userID = channelID starting from index=0 */ @@ -213,8 +213,8 @@ ivas_result_t get_prox_downmix_mixer( } -static float get_block_power( - float *vec, +static float get_block_power( + float *vec, int32_t frame_len ) { int32_t i; diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_prox_mix.h b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_prox_mix.h index 8aa4b57130..3da8f9a268 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_prox_mix.h +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_prox_mix.h @@ -35,14 +35,14 @@ #define IVAS_PROX_MIX_H /**************************************************************************** -* File description - -* This header file contains declarations which are common between IVAS -* spatial decoding tools -****************************************************************************/ + * File description - + * This header file contains declarations which are common between IVAS + * spatial decoding tools + ****************************************************************************/ /*------------------------------------------------------------------------------------------* -* include header files -*------------------------------------------------------------------------------------------*/ + * include header files + *------------------------------------------------------------------------------------------*/ #include "stdio.h" #include "stdlib.h" #include "string.h" @@ -50,8 +50,8 @@ #include "ivas_result_t.h" /*------------------------------------------------------------------------------------------* -* PreProcessor -*------------------------------------------------------------------------------------------*/ + * PreProcessor + *------------------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------------------* * Global variables -- GitLab From 3057562367aea9881011bea8da8c89cb7488633a Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Thu, 15 Dec 2022 15:38:22 +0100 Subject: [PATCH 10/13] Restore comment --- lib_com/prot.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_com/prot.h b/lib_com/prot.h index 7144c9fce2..de6a5774d1 100755 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -719,9 +719,9 @@ int32_t get_delay( HANDLE_CLDFB_FILTER_BANK hCldfb, /* i : Handle of Cldfb analysis */ #ifndef FIX_I59_LFE_TD_DELAY RENDERER_TYPE renderer_type, /* i : IVAS rendering type */ - const int32_t binaural_latency_ns /* i : binaural renderer HRTF delay in ns */ + const int32_t binaural_latency_ns /* i : binaural renderer HRTF delay in ns */ #else - const int32_t binaural_latency_ns /* i : binaural renderer HRTF delay in ns */ + const int32_t binaural_latency_ns /* i : binauralization delay in ns */ #endif ); -- GitLab From b7ce0dd4bcc710de720c88fc0ee89ecb8ee46882 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Fri, 16 Dec 2022 10:52:16 +0100 Subject: [PATCH 11/13] Resolve gcc compiler warnings in ivas_crend_utest_utils.c --- .../unit_tests/crend/ivas_crend_utest_utils.c | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c index 5378c88b55..dd1c8c8249 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c @@ -82,35 +82,37 @@ static int32_t ivas_check_rounding( float binaural_latencys_s[3], int16_t use_ro *err_lfe = 0; *err_dec = 0; - for ( int ind1 = 0; ind1 < sizeof( sampleRates ) / sizeof( float ); ind1++ ) + // for ( int ind1 = 0; ind1 < sizeof( sampleRates ) / sizeof( float ); ind1++ ) // gcc complains it cannot resolve the number of array elements this way -- changed to hard-coded loop below + for ( int ind1 = 0; ind1 < 3; ind1++ ) { if ( verbose ) printf( "\nsample rate = %f", sampleRates[ind1] ); - for ( int ind2 = 0; ind2 < sizeof( binaural_latencys_s ) / sizeof( float ); ind2++ ) + // for ( int ind2 = 0; ind2 < sizeof( binaural_latencys_s ) / sizeof( float ); ind2++ ) // gcc complains it cannot resolve the number of array elements this way -- changed to hard-coded loop below + for ( int ind2 = 0; ind2 < 3; ind2++ ) { wanted = (int32_t) roundf( binaural_latencys_s[ind2] * sampleRates[ind1] ); if ( verbose ) - printf( "\nbinaural_latencys_s = %f wanted = %ld", binaural_latencys_s[ind2], wanted ); + printf( "\nbinaural_latencys_s = %f wanted = %d", binaural_latencys_s[ind2], wanted ); if ( use_round_latency ) delay_ns[ind2] = (int32_t) roundf( binaural_latencys_s[ind2] * 1000000000.f ); else delay_ns[ind2] = (int32_t) ( binaural_latencys_s[ind2] * 1000000000.f ); if ( verbose ) - printf( "\n delay_ns[%d] = %ld \n", ind2, delay_ns[ind2] ); + printf( "\n delay_ns[%d] = %d \n", ind2, delay_ns[ind2] ); if ( use_round_for_lfe ) delay_lfe[ind1][ind2] = (int32_t) roundf( delay_ns[ind2] * sampleRates[ind1] / 1000000000.f ); else delay_lfe[ind1][ind2] = (int32_t) NS2SA( sampleRates[ind1], delay_ns[ind2] ); if ( verbose ) - printf( "\ndelay_lfe[%d][%d] = %ld\n", ind1, ind2, delay_lfe[ind1][ind2] ); + printf( "\ndelay_lfe[%d][%d] = %d\n", ind1, ind2, delay_lfe[ind1][ind2] ); *err_lfe += abs( delay_lfe[ind1][ind2] - wanted ); delay_dec[ind1][ind2] = NS2SA( sampleRates[ind1], (float) delay_ns[ind2] + 0.5f ); // delay_dec[ind1][ind2] = NS2SA( sampleRates[ind1], (float) delay_ns[ind2] ); if ( verbose ) - printf( "\ndelay_dec[%d][%d] = %ld \n", ind1, ind2, delay_dec[ind1][ind2] ); + printf( "\ndelay_dec[%d][%d] = %d \n", ind1, ind2, delay_dec[ind1][ind2] ); *err_dec += abs( delay_dec[ind1][ind2] - wanted ); } } @@ -1151,32 +1153,32 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl int32_t err = 0, err_lfe = 0, err_dec = 0; err = ivas_check_rounding( binaural_latencys_fastconv_s, 0, 0, &err_lfe, &err_dec, 0 ); - printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); + printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); err += ivas_check_rounding( binaural_latencys_crend_s, 0, 0, &err_lfe, &err_dec, 0 ); - printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); + printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); err += ivas_check_rounding( binaural_latencys_td_s, 0, 0, &err_lfe, &err_dec, 0 ); - printf( "\n\nerr = %ld err_lfe = %ld err_dec = %ld\n\n", err, err_lfe, err_dec ); + printf( "\n\nerr = %d err_lfe = %d err_dec = %d\n\n", err, err_lfe, err_dec ); err = ivas_check_rounding( binaural_latencys_fastconv_s, 0, 1, &err_lfe, &err_dec, 0 ); - printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); + printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); err += ivas_check_rounding( binaural_latencys_crend_s, 0, 1, &err_lfe, &err_dec, 0 ); - printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); + printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); err += ivas_check_rounding( binaural_latencys_td_s, 0, 1, &err_lfe, &err_dec, 0 ); - printf( "\n\nerr = %ld err_lfe = %ld err_dec = %ld\n\n", err, err_lfe, err_dec ); + printf( "\n\nerr = %d err_lfe = %d err_dec = %d\n\n", err, err_lfe, err_dec ); err = ivas_check_rounding( binaural_latencys_fastconv_s, 1, 0, &err_lfe, &err_dec, 0 ); - printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); + printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); err += ivas_check_rounding( binaural_latencys_crend_s, 1, 0, &err_lfe, &err_dec, 0 ); - printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); + printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); err += ivas_check_rounding( binaural_latencys_td_s, 1, 0, &err_lfe, &err_dec, 0 ); - printf( "\n\nerr = %ld err_lfe = %ld err_dec = %ld\n\n", err, err_lfe, err_dec ); + printf( "\n\nerr = %d err_lfe = %d err_dec = %d\n\n", err, err_lfe, err_dec ); err = ivas_check_rounding( binaural_latencys_fastconv_s, 1, 1, &err_lfe, &err_dec, 0 ); - printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); + printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); err += ivas_check_rounding( binaural_latencys_crend_s, 1, 1, &err_lfe, &err_dec, 0 ); - printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); + printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); err += ivas_check_rounding( binaural_latencys_td_s, 1, 1, &err_lfe, &err_dec, 0 ); - printf( "\n\nerr = %ld err_lfe = %ld err_dec = %ld\n\n", err, err_lfe, err_dec ); + printf( "\n\nerr = %d err_lfe = %d err_dec = %d\n\n", err, err_lfe, err_dec ); ivas_render_config_open( &st_ivas.hRenderConfig ); -- GitLab From 3c64506701671c6e3ebef4fefbb07aa76cd2219d Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Fri, 16 Dec 2022 14:43:35 +0100 Subject: [PATCH 12/13] Add parenthesis in delay calculation that caused overflow --- lib_dec/lib_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 2d28ab6772..5234a5a6c9 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1057,7 +1057,7 @@ ivas_error IVAS_DEC_GetDelay( #ifdef FIX_I59_LFE_TD_DELAY #ifdef FIX_I59_DELAY_ROUNDING - *nSamples = (int16_t) roundf( get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], st_ivas->binaural_latency_ns ) * hDecoderConfig->output_Fs / 1000000000.f ); + *nSamples = (int16_t) roundf( get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], st_ivas->binaural_latency_ns ) * ( hDecoderConfig->output_Fs / 1000000000.f ) ); #else *nSamples = NS2SA( hDecoderConfig->output_Fs, (int32_t) ( get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], st_ivas->binaural_latency_ns ) + 0.5f ) ); #endif -- GitLab From 5a44c58eb1c677a940aa55a909b766ff0bffb4ba Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Fri, 16 Dec 2022 15:07:18 +0100 Subject: [PATCH 13/13] Add define FIX_I59_CREND for gcc compiler fixes in ivas_crend_utest_utils.c --- lib_com/options.h | 1 + .../unit_tests/crend/ivas_crend_utest_utils.c | 75 ++++++++++++++++++- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index a5ed399f14..1c3a0c2ce6 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -166,6 +166,7 @@ #define FIX_I59_LFE_CLDFB /* Issue 59: correcting LFE handling for fastconv binaural rendering */ #define FIX_I59_DELAY_ROUNDING /* Issue 59: rounding in sample domain instead of nanosec for IVAS_ENC_GetDelay() and IVAS_DEC_GetDelay() */ #define FIX_FIX_I59 /* Issue 59: small fix concerning LFE delay rounding */ +#define FIX_I59_CREND /* Issue 59: Fixes for gcc compiler warnings in ivas_crend_utest_utils.c */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c index dd1c8c8249..c8772f7ec1 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c @@ -82,37 +82,60 @@ static int32_t ivas_check_rounding( float binaural_latencys_s[3], int16_t use_ro *err_lfe = 0; *err_dec = 0; - // for ( int ind1 = 0; ind1 < sizeof( sampleRates ) / sizeof( float ); ind1++ ) // gcc complains it cannot resolve the number of array elements this way -- changed to hard-coded loop below +#ifdef FIX_I59_CREND for ( int ind1 = 0; ind1 < 3; ind1++ ) +#else + for ( int ind1 = 0; ind1 < sizeof( sampleRates ) / sizeof( float ); ind1++ ) +#endif { if ( verbose ) printf( "\nsample rate = %f", sampleRates[ind1] ); - // for ( int ind2 = 0; ind2 < sizeof( binaural_latencys_s ) / sizeof( float ); ind2++ ) // gcc complains it cannot resolve the number of array elements this way -- changed to hard-coded loop below + +#ifdef FIX_I59_CREND for ( int ind2 = 0; ind2 < 3; ind2++ ) +#else + for ( int ind2 = 0; ind2 < sizeof( binaural_latencys_s ) / sizeof( float ); ind2++ ) +#endif { wanted = (int32_t) roundf( binaural_latencys_s[ind2] * sampleRates[ind1] ); if ( verbose ) +#ifdef FIX_I59_CREND printf( "\nbinaural_latencys_s = %f wanted = %d", binaural_latencys_s[ind2], wanted ); +#else + printf( "\nbinaural_latencys_s = %f wanted = %ld", binaural_latencys_s[ind2], wanted ); +#endif if ( use_round_latency ) delay_ns[ind2] = (int32_t) roundf( binaural_latencys_s[ind2] * 1000000000.f ); else delay_ns[ind2] = (int32_t) ( binaural_latencys_s[ind2] * 1000000000.f ); if ( verbose ) +#ifdef FIX_I59_CREND printf( "\n delay_ns[%d] = %d \n", ind2, delay_ns[ind2] ); +#else + printf( "\n delay_ns[%d] = %ld \n", ind2, delay_ns[ind2] ); +#endif if ( use_round_for_lfe ) delay_lfe[ind1][ind2] = (int32_t) roundf( delay_ns[ind2] * sampleRates[ind1] / 1000000000.f ); else delay_lfe[ind1][ind2] = (int32_t) NS2SA( sampleRates[ind1], delay_ns[ind2] ); if ( verbose ) +#ifdef FIX_I59_CREND printf( "\ndelay_lfe[%d][%d] = %d\n", ind1, ind2, delay_lfe[ind1][ind2] ); +#else + printf( "\ndelay_lfe[%d][%d] = %ld\n", ind1, ind2, delay_lfe[ind1][ind2] ); +#endif *err_lfe += abs( delay_lfe[ind1][ind2] - wanted ); delay_dec[ind1][ind2] = NS2SA( sampleRates[ind1], (float) delay_ns[ind2] + 0.5f ); // delay_dec[ind1][ind2] = NS2SA( sampleRates[ind1], (float) delay_ns[ind2] ); if ( verbose ) +#ifdef FIX_I59_CREND printf( "\ndelay_dec[%d][%d] = %d \n", ind1, ind2, delay_dec[ind1][ind2] ); +#else + printf( "\ndelay_dec[%d][%d] = %ld \n", ind1, ind2, delay_dec[ind1][ind2] ); +#endif *err_dec += abs( delay_dec[ind1][ind2] - wanted ); } } @@ -1153,32 +1176,80 @@ ivas_result_t ivas_common_mixer_renderer( ivas_crend_io_params_t *pIo_params, fl int32_t err = 0, err_lfe = 0, err_dec = 0; err = ivas_check_rounding( binaural_latencys_fastconv_s, 0, 0, &err_lfe, &err_dec, 0 ); +#ifdef FIX_I59_CREND printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); +#else + printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); +#endif err += ivas_check_rounding( binaural_latencys_crend_s, 0, 0, &err_lfe, &err_dec, 0 ); +#ifdef FIX_I59_CREND printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); +#else + printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); +#endif err += ivas_check_rounding( binaural_latencys_td_s, 0, 0, &err_lfe, &err_dec, 0 ); +#ifdef FIX_I59_CREND printf( "\n\nerr = %d err_lfe = %d err_dec = %d\n\n", err, err_lfe, err_dec ); +#else + printf( "\n\nerr = %ld err_lfe = %ld err_dec = %ld\n\n", err, err_lfe, err_dec ); +#endif err = ivas_check_rounding( binaural_latencys_fastconv_s, 0, 1, &err_lfe, &err_dec, 0 ); +#ifdef FIX_I59_CREND printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); +#else + printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); +#endif err += ivas_check_rounding( binaural_latencys_crend_s, 0, 1, &err_lfe, &err_dec, 0 ); +#ifdef FIX_I59_CREND printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); +#else + printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); +#endif err += ivas_check_rounding( binaural_latencys_td_s, 0, 1, &err_lfe, &err_dec, 0 ); +#ifdef FIX_I59_CREND printf( "\n\nerr = %d err_lfe = %d err_dec = %d\n\n", err, err_lfe, err_dec ); +#else + printf( "\n\nerr = %ld err_lfe = %ld err_dec = %ld\n\n", err, err_lfe, err_dec ); +#endif err = ivas_check_rounding( binaural_latencys_fastconv_s, 1, 0, &err_lfe, &err_dec, 0 ); +#ifdef FIX_I59_CREND printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); +#else + printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); +#endif err += ivas_check_rounding( binaural_latencys_crend_s, 1, 0, &err_lfe, &err_dec, 0 ); +#ifdef FIX_I59_CREND printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); +#else + printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); +#endif err += ivas_check_rounding( binaural_latencys_td_s, 1, 0, &err_lfe, &err_dec, 0 ); +#ifdef FIX_I59_CREND printf( "\n\nerr = %d err_lfe = %d err_dec = %d\n\n", err, err_lfe, err_dec ); +#else + printf( "\n\nerr = %ld err_lfe = %ld err_dec = %ld\n\n", err, err_lfe, err_dec ); +#endif err = ivas_check_rounding( binaural_latencys_fastconv_s, 1, 1, &err_lfe, &err_dec, 0 ); +#ifdef FIX_I59_CREND printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); +#else + printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); +#endif err += ivas_check_rounding( binaural_latencys_crend_s, 1, 1, &err_lfe, &err_dec, 0 ); +#ifdef FIX_I59_CREND printf( "\nerr_lfe = %d err_dec = %d", err_lfe, err_dec ); +#else + printf( "\nerr_lfe = %ld err_dec = %ld", err_lfe, err_dec ); +#endif err += ivas_check_rounding( binaural_latencys_td_s, 1, 1, &err_lfe, &err_dec, 0 ); +#ifdef FIX_I59_CREND printf( "\n\nerr = %d err_lfe = %d err_dec = %d\n\n", err, err_lfe, err_dec ); +#else + printf( "\n\nerr = %ld err_lfe = %ld err_dec = %ld\n\n", err, err_lfe, err_dec ); +#endif ivas_render_config_open( &st_ivas.hRenderConfig ); -- GitLab