diff --git a/lib_com/delay_comp.c b/lib_com/delay_comp.c index 4bcac1555e942ac298a10fc7035d3bae06fa0e40..3589d32d479d659d31cdbb003fc4490994b17f33 100644 --- a/lib_com/delay_comp.c +++ b/lib_com/delay_comp.c @@ -50,13 +50,18 @@ *--------------------------------------------------------------------------*/ /*! r: delay value in ns */ + int32_t get_delay( - const int16_t enc_dec, /* i : encoder/decoder flag */ - 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 enc_dec, /* i : encoder/decoder flag */ + 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 */ +#else + const int32_t binaural_latency_ns /* i : binauralization delay in ns */ +#endif ) { int32_t delay = 0; @@ -94,7 +99,16 @@ int32_t get_delay( else /* IVAS */ { delay = IVAS_DEC_DELAY_NS; +#ifdef FIX_I59_LFE_TD_DELAY + 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 ) { delay += IVAS_FB_DEC_DELAY_NS; @@ -104,6 +118,7 @@ int32_t get_delay( { delay += binaural_latency_ns; } +#endif } } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 9869c4bb0f401c1f5b2502eff51e6d9b7832c517..406fbcd27d810326b6eb597d060a4a5e9b3112ff 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4917,7 +4917,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_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 ); void ivas_lfe_dec_close( diff --git a/lib_com/options.h b/lib_com/options.h old mode 100644 new mode 100755 index a98dadd11984dc80eabadd728a44fe2cd10711d0..7ef067e7bab9b5ed06e589f9d5e8c00a7677ea69 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -150,7 +150,11 @@ #define FIX_150 /* Issue 150: Crash in EVS mono, HQ_HARMONIC mode, related to BASOP_NOGLOB */ #define FIX_VBR_COMPLEXITY /* Issue 234: fix extremely high complexity numbers for IVAS EVS mode */ #define SBA_DIRAC_RENDERER_TYPE_CLEANUP /* Remove leftovers in renderer_type logic in SBA DirAC decoder */ - +#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 */ +#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/lib_com/prot.h b/lib_com/prot.h old mode 100644 new mode 100755 index 760571cb46537c628bcdd80e9c6b9906ac31f227..b0476efdb3930211f5ab92e8a9b8c08724a8691c --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -713,12 +713,16 @@ int16_t lev_dur( /*! r: delay value in ns */ int32_t get_delay( - const int16_t enc_dec, /* i : encoder/decoder flag */ - 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 enc_dec, /* i : encoder/decoder flag */ + 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 */ + 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_dec.c b/lib_dec/ivas_dec.c index c3deb7103f872426d92b39a56614fab8fd6f843f..676c84fc7a9f44b28f03bc221bd965dbb87e8254 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -389,8 +389,13 @@ ivas_error ivas_dec( } if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) { +#ifdef FIX_I59_LFE_CLDFB + 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 7adef840c284047525578a26a07b85499dcfd5ef..9e693150c058bf3096683af34459ac0ac750a0be 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -625,6 +625,9 @@ ivas_error ivas_init_decoder( AUDIO_CONFIG output_config; DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; +#ifdef FIX_I59_LFE_TD_DELAY + int32_t binauralization_delay_ns; +#endif error = IVAS_ERR_OK; @@ -1237,7 +1240,28 @@ ivas_error ivas_init_decoder( if ( st_ivas->mc_mode == MC_MODE_MCT ) { +#ifdef FIX_I59_LFE_TD_DELAY + binauralization_delay_ns = st_ivas->binaural_latency_ns; + if ( st_ivas->hBinRenderer != NULL ) + { +#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, 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 { return error; } diff --git a/lib_dec/ivas_lfe_dec.c b/lib_dec/ivas_lfe_dec.c index a909801b8f939c1e9cfd3057144393257d4b9da3..70e3a2fff48952a3ea4fdefff65a2e5053f6e468 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 */ - const float add_delay_s /* i : additional LFE delay to sync with binaural filter */ +#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 ) { 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_LFE_TD_DELAY + int16_t add_delay_sa; +#endif low_pass_delay_dec_out = 0; block_offset_s = 0; @@ -436,8 +443,18 @@ 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 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 9baa77d4b9d0ed5d9afca730192fd789c83735be..eae30908ab645a813d4ac5aa150eb5fa9daf6c15 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1896,7 +1896,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_LFE_TD_DELAY + int32_t binaural_latency_ns; /* Binauralization 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 d45527b740d6a8faa80fddabf11d9d5688203bea..5234a5a6c9803869c5dfd71f0cc98bfa0c33dd9c 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1055,7 +1055,19 @@ ivas_error IVAS_DEC_GetDelay( st_ivas = hIvasDec->st_ivas; hDecoderConfig = st_ivas->hDecoderConfig; +#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 ) ); +#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 = (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, get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], st_ivas->renderer_type, st_ivas->binaural_latency_ns ) ); +#endif +#endif *timeScale = hDecoderConfig->output_Fs; diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index b4eb85915e3d878b70b8d4bee72dc22209ebce52..0401df16e4578b4c97aed15c3f30b681179bbdda 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -951,7 +951,19 @@ ivas_error IVAS_ENC_GetDelay( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } +#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, get_delay( ENC, hEncoderConfig->input_Fs, hEncoderConfig->ivas_format, NULL, RENDERER_DISABLE, 0 ) ); +#endif +#endif *delay *= hEncoderConfig->nchan_inp; diff --git a/lib_rend/ivas_binauralRenderer.c b/lib_rend/ivas_binauralRenderer.c index 09713a6f5cc8a26c96c4f030c3f67aa205022507..b31ee4e00dc679f6cee5c6e86f141bd8de18cdd6 100644 --- a/lib_rend/ivas_binauralRenderer.c +++ b/lib_rend/ivas_binauralRenderer.c @@ -574,6 +574,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 ); @@ -582,6 +600,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/run_test_bin_latencys.py b/run_test_bin_latencys.py new file mode 100644 index 0000000000000000000000000000000000000000..36101cdac8970d6dd2f3890e953263f7dd925945 --- /dev/null +++ b/run_test_bin_latencys.py @@ -0,0 +1,204 @@ + + +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'] +# sampleRates = ['48'] + +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', '64000', 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) + +# -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'] + + 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 + + '_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'] + + 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 + '-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 + '-parammc-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_io_parse.h b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_io_parse.h index bc719cd4a6912d96c07a7ba4edfad499b57c381e..bcdbd84487250f65cc67c819afaab474c05fe195 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 @@ -112,10 +112,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 057cfba10abf7c66749ab046029d43a17200a01a..38b02c6df34ef8ec5b125d3be1d98dbf85ab531b 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 baa953bc7dab37e0accf84b05e969f86b122a1cc..0c8d7590a32f9e8a429fa5556a9afe279f98b059 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 ) @@ -449,7 +448,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 = (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 if ( pIo_params->no_delay_cmp == 0 ) { skip_bytes = skip_samples * ivas_get_num_channels( BIN_2 ) * sizeof( int16_t ); @@ -503,11 +506,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 = (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 /* 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 ) @@ -574,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 ) @@ -593,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 */ @@ -626,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; @@ -639,11 +646,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; @@ -690,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 c26134aba1fb810968e6bc9622670718a2a893cd..379a23ce2b198e91c939151ca5a0d4491d98932a 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_crend_utest_utils.c b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c index be5e4839278b560a2abe35995e0d5c235378cf7b..c8772f7ec1471e5f2ca30bb528efc74e87fecd9f 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,85 @@ #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; + +#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] ); + +#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 ); + } + } + return *err_lfe + *err_dec; +} + + static ivas_result_t ivas_dec_default_io_params( ivas_dec_io_params_t *pIO_params ) { memset( pIO_params, 0, sizeof( ivas_dec_io_params_t ) ); @@ -232,8 +311,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 ) { @@ -337,9 +416,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 ) ); } /*-----------------------------------------------------------------------------------------* @@ -384,8 +463,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; } @@ -773,7 +855,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++; } @@ -860,9 +942,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 ); @@ -1046,8 +1128,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; @@ -1087,6 +1169,88 @@ 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 ); +#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 ); ivas_render_config_init_from_rom( &st_ivas.hRenderConfig, 0 ); @@ -1124,16 +1288,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_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 } 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 ) +#ifdef FIX_FIX_I59 + 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_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 } } else if ( pIo_params->test == TD_BIN_TEST ) @@ -1154,7 +1330,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_ns = (int32_t) ( BINAURAL_TD_LATENCY_S * 1000000000.f ); +#else pIo_params->latency_s = BINAURAL_TD_LATENCY_S; +#endif } else if ( pIo_params->test == PARAM_BIN_TEST ) { @@ -1168,7 +1348,11 @@ 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_ns = 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 ) { @@ -1194,8 +1378,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 @@ -1308,11 +1492,19 @@ 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_ns = (int32_t) ( 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_FIX_I59 + 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 if ( st_ivas.hLFE->lfe_addl_delay > 0 ) { if ( st_ivas.hLFE->lfe_delay_buf != NULL ) @@ -1320,9 +1512,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 ) @@ -1353,7 +1551,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 { @@ -1385,7 +1587,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 = (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 } fprintf( stdout, "IVAS Common Renderer skip samples = %d\n", (int) skip_samples ); @@ -1566,7 +1772,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 ); @@ -1646,8 +1852,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; @@ -1699,8 +1905,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 ) ); @@ -1789,7 +1995,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 97962a785b442aaa61f9e26ccf2c0d3290df75bd..ca18f63be18aa31334c0fafc3508a766020d4d61 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,11 +93,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; 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 2bf19080e5f47a64fe793ec6ef4f3701056c0461..b55c43b6f8e1666583467236b2947ff9d297f3f8 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 8aa4b5713007eda8d72c05f64b9f8cb2b15909b3..3da8f9a2682cd1a33feed1594e456396a75c4e3c 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 diff --git a/scripts/testv/dirac_12ch_16k.wav b/scripts/testv/dirac_12ch_16k.wav new file mode 100644 index 0000000000000000000000000000000000000000..770a0962929995d549724b694b8ba9976685f061 --- /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 0000000000000000000000000000000000000000..e363158e34523c8aaae5eb96accb3bd102950a23 --- /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 0000000000000000000000000000000000000000..e6c45bcab5d722f4d788d0ef4e9be12845ccf71c --- /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 0000000000000000000000000000000000000000..112985edbc8c48385a93f276266457851c951fa1 --- /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 0000000000000000000000000000000000000000..abd795767ba2f89375179f56d870b20b674c6b14 --- /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 0000000000000000000000000000000000000000..dc170a11b9c962dae329e8a019b6eccc75b57c8a --- /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