diff --git a/apps/decoder.c b/apps/decoder.c index c29a85f40dd963ca8ee4140c65e92b502d98a70e..3b312b95f69fb164947ddeb2e93f4037c54e4776 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1154,9 +1154,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 ) { @@ -1307,7 +1315,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; @@ -1330,6 +1342,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(); @@ -1420,7 +1436,11 @@ static ivas_error decodeG192( arg, numInitialBadFrames, nOutSamples, +#ifdef BINAURALIZATION_DELAY_REPORT + delayNumSamples_orig, +#else &delayNumSamples_orig, +#endif &delayNumSamples, &delayTimeScale, &bsFormat, @@ -1521,13 +1541,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) */ @@ -1547,14 +1593,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 *------------------------------------------------------------------------------------------*/ @@ -1724,7 +1762,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; @@ -1738,11 +1780,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 ) @@ -1939,7 +1985,11 @@ static ivas_error decodeVoIP( arg, numInitialBadFrames, nOutSamples, +#ifdef BINAURALIZATION_DELAY_REPORT + delayNumSamples_orig, +#else &delayNumSamples_orig, +#endif &delayNumSamples, &delayTimeScale, &bsFormat, @@ -1992,9 +2042,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; @@ -2006,7 +2064,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 194b4b29194abb7f561608d4b764916684694474..09a642bbaa4c558048ce79077430ac8de01ea25b 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 6b22caab021a2a21191828476291a47d51897c0c..61b96cd1ee187786fa1e962d90d9778634427b17 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -160,6 +160,7 @@ #define SMOOTH_WITH_TRANS_DET #endif +#define BINAURALIZATION_DELAY_REPORT /* VA: Issue 255 - Changes the way the decoder delay is reported */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_com/prot.h b/lib_com/prot.h index 12ae8a3c6ff740113338b5d6c3413beedf0a66f1..f9ec0e4b9f62a5f51cc1274429021a200ce5586f 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 a6a4778bea8381df0b30182b4c797e2eb8b9af8c..dba7cbedca0cddc267cabea66064d084f3f9d5a0 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1183,7 +1183,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 33f1d0243788f63e56b10a888dc27933438af8c7..f56dd0d9e3c1c243374a7c6768cfae1c428c11bf 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;