From bbb21274ab243489433c6bbe11e4cbc734a9650a Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 22 Feb 2023 16:49:13 +0100 Subject: [PATCH] Issue 255 - Changes the way the decoder delay is reported; under BINAURALIZATION_DELAY_REPORT --- apps/decoder.c | 86 +++++++++++++++++++++++++++++++++++++++----- lib_com/delay_comp.c | 13 ++++--- lib_com/options.h | 3 ++ lib_com/prot.h | 11 +++--- lib_dec/lib_dec.c | 6 ++++ lib_enc/lib_enc.c | 4 +++ 6 files changed, 106 insertions(+), 17 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index bbbee76c88..d7efdf7301 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1142,9 +1142,17 @@ static ivas_error initOnFirstGoodFrame( } else { +#ifdef BINAURALIZATION_DELAY_REPORT + pFullDelayNumSamples[0] = 0; +#else *pFullDelayNumSamples = 0; +#endif } +#ifdef BINAURALIZATION_DELAY_REPORT + *pRemainingDelayNumSamples = pFullDelayNumSamples[0]; +#else *pRemainingDelayNumSamples = *pFullDelayNumSamples; +#endif if ( ( error = IVAS_DEC_GetNumOutputChannels( hIvasDec, pNumOutChannels ) ) != IVAS_ERR_OK ) { @@ -1295,7 +1303,11 @@ static ivas_error decodeG192( int16_t numInitialBadFrames = 0; /* Number of bad frames received until first good frame is decoded */ int16_t nOutChannels = 0; int16_t delayNumSamples = -1; +#ifdef BINAURALIZATION_DELAY_REPORT + int16_t delayNumSamples_orig[3]; /* stores: overall delay, dec+rend delay, and binauralization delay */ +#else int16_t delayNumSamples_orig = 0; +#endif int16_t nOutSamples = 0; int32_t delayTimeScale = 0; ivas_error error = IVAS_ERR_UNKNOWN; @@ -1318,6 +1330,10 @@ static ivas_error decodeG192( fprintf( stdout, "\n-- Start the decoder (quiet mode) --\n\n" ); } +#ifdef BINAURALIZATION_DELAY_REPORT + delayNumSamples_orig[0] = -1; +#endif + #ifdef WMOPS reset_stack(); reset_wmops(); @@ -1408,7 +1424,11 @@ static ivas_error decodeG192( arg, numInitialBadFrames, nOutSamples, +#ifdef BINAURALIZATION_DELAY_REPORT + delayNumSamples_orig, +#else &delayNumSamples_orig, +#endif &delayNumSamples, &delayTimeScale, &bsFormat, @@ -1509,13 +1529,39 @@ static ivas_error decodeG192( #endif } + /*------------------------------------------------------------------------------------------* + * Add zeros at the end to have equal length of synthesized signals + *------------------------------------------------------------------------------------------*/ + +#ifdef BINAURALIZATION_DELAY_REPORT + memset( pcmBuf, 0, delayNumSamples_orig[0] * nOutChannels * sizeof( int16_t ) ); + if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig[0] * nOutChannels ) ) != IVAS_ERR_OK ) +#else + memset( pcmBuf, 0, delayNumSamples_orig * nOutChannels * sizeof( int16_t ) ); + if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig * nOutChannels ) ) != IVAS_ERR_OK ) +#endif + { + fprintf( stderr, "\nError writing output file: %s\n", ivas_error_to_string( error ) ); + goto cleanup; + } + /*------------------------------------------------------------------------------------------* * Printouts after decoding has finished *------------------------------------------------------------------------------------------*/ if ( !arg.quietModeEnabled ) { +#ifdef BINAURALIZATION_DELAY_REPORT + printf( "\n\nDecoder+renderer delay: %4.2f ms (%3u samples at timescale %5u)\n", 1000.f * delayNumSamples_orig[1] / (float) delayTimeScale, delayNumSamples_orig[1], delayTimeScale ); + + if ( delayNumSamples_orig[2] > 0 ) + { + printf( "HRIR/BRIR delay: %4.2f ms (%3u samples at timescale %5u)\n", 1000.f * delayNumSamples_orig[2] / (float) delayTimeScale, delayNumSamples_orig[2], delayTimeScale ); + printf( "Total delay: %4.2f ms (%3u samples at timescale %5u)\n", 1000.f * delayNumSamples_orig[0] / (float) delayTimeScale, delayNumSamples_orig[0], delayTimeScale ); + } +#else fprintf( stdout, "\nDecoder delay: %-5u [samples] - Timescale: %5u\n", delayNumSamples_orig, delayTimeScale ); +#endif } /* Print output metadata file name(s) */ @@ -1535,14 +1581,6 @@ static ivas_error decodeG192( } } - /* add zeros at the end to have equal length of synthesized signals */ - memset( pcmBuf, 0, delayNumSamples_orig * nOutChannels * sizeof( int16_t ) ); - if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig * nOutChannels ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError writing output file: %s\n", ivas_error_to_string( error ) ); - goto cleanup; - } - /*------------------------------------------------------------------------------------------* * Close files and deallocate resources *------------------------------------------------------------------------------------------*/ @@ -1712,7 +1750,11 @@ static ivas_error decodeVoIP( #endif JbmOffsetFileWriter *jbmOffsetWriter = NULL; +#ifdef BINAURALIZATION_DELAY_REPORT + int16_t delayNumSamples_orig[3]; /* stores: overall delay, dec+rend delay, and binauralization delay */ +#else int16_t delayNumSamples_orig = -1; +#endif int16_t delayNumSamples = -1; int32_t delayTimeScale = -1; @@ -1726,11 +1768,15 @@ static ivas_error decodeVoIP( IVAS_DEC_BS_FORMAT bsFormat = IVAS_DEC_BS_UNKOWN; IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS]; + for ( int16_t i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i ) { ismWriters[i] = NULL; } +#ifdef BINAURALIZATION_DELAY_REPORT + delayNumSamples_orig[0] = -1; +#endif rtpdumpDepacker.rtpdump = NULL; switch ( arg.inputFormat ) @@ -1927,7 +1973,11 @@ static ivas_error decodeVoIP( arg, numInitialBadFrames, nOutSamples, +#ifdef BINAURALIZATION_DELAY_REPORT + delayNumSamples_orig, +#else &delayNumSamples_orig, +#endif &delayNumSamples, &delayTimeScale, &bsFormat, @@ -1980,9 +2030,17 @@ static ivas_error decodeVoIP( #endif } - /* add zeros at the end to have equal length of synthesized signals */ + /*------------------------------------------------------------------------------------------* + * Add zeros at the end to have equal length of synthesized signals + *------------------------------------------------------------------------------------------*/ + +#ifdef BINAURALIZATION_DELAY_REPORT + memset( pcmBuf, 0, delayNumSamples_orig[0] * nOutChannels * sizeof( int16_t ) ); + if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig[0] * nOutChannels ) ) != IVAS_ERR_OK ) +#else memset( pcmBuf, 0, delayNumSamples_orig * nOutChannels * sizeof( int16_t ) ); if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig * nOutChannels ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nError writing output file: %s\n", ivas_error_to_string( error ) ); goto cleanup; @@ -1994,7 +2052,17 @@ static ivas_error decodeVoIP( if ( !arg.quietModeEnabled ) { +#ifdef BINAURALIZATION_DELAY_REPORT + printf( "\n\nDecoder+renderer delay: %4.2f ms (%3u samples at timescale %5u)\n", 1000.f * delayNumSamples_orig[1] / (float) delayTimeScale, delayNumSamples_orig[1], delayTimeScale ); + + if ( delayNumSamples_orig[2] > 0 ) + { + printf( "HRIR/BRIR delay: %4.2f ms (%3u samples at timescale %5u)\n", 1000.f * delayNumSamples_orig[2] / (float) delayTimeScale, delayNumSamples_orig[2], delayTimeScale ); + printf( "Total delay: %4.2f ms (%3u samples at timescale %5u)\n", 1000.f * delayNumSamples_orig[0] / (float) delayTimeScale, delayNumSamples_orig[0], delayTimeScale ); + } +#else printf( "\nDecoder delay: %5u [samples] - Timescale: %5u\n", delayNumSamples_orig, delayTimeScale ); +#endif } /*------------------------------------------------------------------------------------------* diff --git a/lib_com/delay_comp.c b/lib_com/delay_comp.c index 194b4b2919..09a642bbaa 100644 --- a/lib_com/delay_comp.c +++ b/lib_com/delay_comp.c @@ -51,11 +51,14 @@ /*! 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 BINAURALIZATION_DELAY_REPORT + , const int32_t binaural_latency_ns /* i : binaural renderer HRTF delay in ns */ +#endif ) { int32_t delay = 0; @@ -100,8 +103,10 @@ int32_t get_delay( delay += IVAS_FB_DEC_DELAY_NS; } +#ifndef BINAURALIZATION_DELAY_REPORT /* compensate for binauralization delay */ delay += binaural_latency_ns; +#endif } } diff --git a/lib_com/options.h b/lib_com/options.h index 9a6a9d4c5b..a04271b8b1 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -158,6 +158,9 @@ #define SMOOTH_WITH_TRANS_DET #endif +#define BINAURALIZATION_DELAY_REPORT /* VA: Issue 255 - Changes the way the decoder delay is reported */ + + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ #endif diff --git a/lib_com/prot.h b/lib_com/prot.h index f47c2d65b2..1cb722eea9 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -677,11 +677,14 @@ 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 BINAURALIZATION_DELAY_REPORT + , const int32_t binaural_latency_ns /* i : binauralization delay in ns */ +#endif ); void decision_matrix_enc( diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index a1fee7f0fd..110f583279 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1177,7 +1177,13 @@ ivas_error IVAS_DEC_GetDelay( st_ivas = hIvasDec->st_ivas; hDecoderConfig = st_ivas->hDecoderConfig; +#ifdef BINAURALIZATION_DELAY_REPORT + nSamples[1] = NS2SA( hDecoderConfig->output_Fs, get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0] ) ); + nSamples[2] = (int16_t) roundf( (float) st_ivas->binaural_latency_ns * hDecoderConfig->output_Fs / 1000000000.f ); + nSamples[0] = nSamples[1] + nSamples[2]; +#else *nSamples = (int16_t) roundf( (float) get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], st_ivas->binaural_latency_ns ) * hDecoderConfig->output_Fs / 1000000000.f ); +#endif *timeScale = hDecoderConfig->output_Fs; diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 33f1d02437..f56dd0d9e3 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -969,7 +969,11 @@ ivas_error IVAS_ENC_GetDelay( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } +#ifdef BINAURALIZATION_DELAY_REPORT + *delay = NS2SA( hEncoderConfig->input_Fs, get_delay( ENC, hEncoderConfig->input_Fs, hEncoderConfig->ivas_format, NULL ) ); +#else *delay = NS2SA( hEncoderConfig->input_Fs, get_delay( ENC, hEncoderConfig->input_Fs, hEncoderConfig->ivas_format, NULL, 0 ) ); +#endif *delay *= hEncoderConfig->nchan_inp; -- GitLab