From f768a7f86635165590b07e518934b83ec891efe7 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 8 Sep 2023 16:08:56 +0200 Subject: [PATCH 1/2] issue 779: fix Crash in ISM rate switching with BINAURAL_ROOM_REVERB; under NONBE_FIX_779_ISM_FREE_REVERB_HANDLE --- lib_com/options.h | 1 + lib_rend/ivas_reverb.c | 115 +++++++++++++++++++++++------------------ 2 files changed, 65 insertions(+), 51 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index dadd57e9bd..9d54195d2f 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -176,6 +176,7 @@ #define NONBE_FIX_770_PLANAR_SBA_JBM /* FhG : Issue #770: Crash in planar FOA decoding with JBM caused by uninitialized value */ #define NONBE_FIX_760_COHERENCE_MASA /* Nokia: Issue 760: fixes decoder crash for some cases when all energy ratios are 1 */ #define NONBE_FIX_752_OSBA_MISCONFIG_MCT /* FhG: issue 752: misconfiguration of MCT causes crashes for coding with sampling rate under 48kHz at 256kbps*/ +#define NONBE_FIX_779_ISM_FREE_REVERB_HANDLE /* VA: issue 779: fix Crash in ISM rate switching with BINAURAL_ROOM_REVERB */ /* ##################### End NON-BE switches ############################# */ diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index ee00cb30c8..0e153e65c2 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -1286,33 +1286,46 @@ void ivas_reverb_close( hReverb = *hReverb_in; +#ifdef NONBE_FIX_779_ISM_FREE_REVERB_HANDLE + if ( *hReverb_in == NULL || hReverb_in == NULL ) + { + return; + } + +#else if ( hReverb != NULL ) { - for ( loop_idx = 0; loop_idx < IVAS_REV_MAX_NR_BRANCHES; loop_idx++ ) +#endif + for ( loop_idx = 0; loop_idx < IVAS_REV_MAX_NR_BRANCHES; loop_idx++ ) + { + if ( hReverb->loop_delay_buffer[loop_idx] != NULL ) { - if ( hReverb->loop_delay_buffer[loop_idx] != NULL ) - { - free( hReverb->loop_delay_buffer[loop_idx] ); - hReverb->loop_delay_buffer[loop_idx] = NULL; - } + free( hReverb->loop_delay_buffer[loop_idx] ); + hReverb->loop_delay_buffer[loop_idx] = NULL; } + } - free( hReverb->pPredelay_buffer ); - hReverb->pPredelay_buffer = NULL; + free( hReverb->pPredelay_buffer ); + hReverb->pPredelay_buffer = NULL; +#ifdef NONBE_FIX_779_ISM_FREE_REVERB_HANDLE + free( *hReverb_in ); + *hReverb_in = NULL; +#else free( hReverb ); hReverb = NULL; } +#endif return; } /*-----------------------------------------------------------------------------------------* - * Function post_fft_filter() - * - * - *-----------------------------------------------------------------------------------------*/ + * Function post_fft_filter() + * + * + *-----------------------------------------------------------------------------------------*/ static void post_fft_filter( REVERB_HANDLE hReverb, @@ -1342,10 +1355,10 @@ static void post_fft_filter( /*-----------------------------------------------------------------------------------------* - * Function reverb_block() - * - * Input a block (mono) and calculate the 2 output blocks. - *-----------------------------------------------------------------------------------------*/ + * Function reverb_block() + * + * Input a block (mono) and calculate the 2 output blocks. + *-----------------------------------------------------------------------------------------*/ static void reverb_block( REVERB_HANDLE hReverb, @@ -1435,10 +1448,10 @@ static void reverb_block( /*-----------------------------------------------------------------------------------------* - * Function downmix_input_block() - * - * Downmix input to mono, taking also DSR gain into account - *-----------------------------------------------------------------------------------------*/ + * Function downmix_input_block() + * + * Downmix input to mono, taking also DSR gain into account + *-----------------------------------------------------------------------------------------*/ static ivas_error downmix_input_block( const REVERB_HANDLE hReverb, @@ -1496,10 +1509,10 @@ static ivas_error downmix_input_block( /*-----------------------------------------------------------------------------------------* - * Function predelay_block() - * - * Perform a predelay - *-----------------------------------------------------------------------------------------*/ + * Function predelay_block() + * + * Perform a predelay + *-----------------------------------------------------------------------------------------*/ static void predelay_block( const REVERB_HANDLE hReverb, @@ -1550,10 +1563,10 @@ static void predelay_block( /*-----------------------------------------------------------------------------------------* - * Function mix_output_block() - * - * mix one block of *pInL and *pInR samples into *pOutL and *pOutL respectively - *-----------------------------------------------------------------------------------------*/ + * Function mix_output_block() + * + * mix one block of *pInL and *pInR samples into *pOutL and *pOutL respectively + *-----------------------------------------------------------------------------------------*/ static void mix_output_block( const REVERB_HANDLE hReverb, @@ -1575,10 +1588,10 @@ static void mix_output_block( /*-----------------------------------------------------------------------------------------* - * ivas_reverb_process() - * - * Process the input PCM audio into output PCM audio, applying reverb - *-----------------------------------------------------------------------------------------*/ + * ivas_reverb_process() + * + * Process the input PCM audio into output PCM audio, applying reverb + *-----------------------------------------------------------------------------------------*/ ivas_error ivas_reverb_process( const REVERB_HANDLE hReverb, /* i : Reverberator handle */ @@ -1616,10 +1629,10 @@ ivas_error ivas_reverb_process( /*------------------------------------------------------------------------- - * ivas_binaural_reverb_processSubFrame() - * - * Compute the reverberation - room effect - *------------------------------------------------------------------------*/ + * ivas_binaural_reverb_processSubFrame() + * + * Compute the reverberation - room effect + *------------------------------------------------------------------------*/ void ivas_binaural_reverb_processSubframe( REVERB_STRUCT_HANDLE hReverb, /* i/o: binaural reverb handle */ @@ -1637,8 +1650,8 @@ void ivas_binaural_reverb_processSubframe( push_wmops( "binaural_reverb" ); /* 1) Rotate the data in the loop buffer of the reverberator. - * Notice that the audio at the loop buffers is at time-inverted order - * for convolution purposes later on. */ + * Notice that the audio at the loop buffers is at time-inverted order + * for convolution purposes later on. */ for ( bin = 0; bin < hReverb->numBins; bin++ ) { /* Move the data forwards by blockSize (i.e. by the frame size of 16 CLDFB slots) */ @@ -1646,8 +1659,8 @@ void ivas_binaural_reverb_processSubframe( mvr2r( hReverb->loopBufImag[bin], hReverb->loopBufImag[bin] + numSlots, hReverb->loopBufLength[bin] ); /* Add the data from the end of the loop to the beginning, with an attenuation factor - * according to RT60. This procedure generates an IIR decaying response. The response - * is decorrelated later on. */ + * according to RT60. This procedure generates an IIR decaying response. The response + * is decorrelated later on. */ v_multc( hReverb->loopBufReal[bin] + hReverb->loopBufLength[bin], hReverb->loopAttenuationFactor[bin], hReverb->loopBufReal[bin], numSlots ); v_multc( hReverb->loopBufImag[bin] + hReverb->loopBufLength[bin], hReverb->loopAttenuationFactor[bin], hReverb->loopBufImag[bin], numSlots ); } @@ -1661,7 +1674,7 @@ void ivas_binaural_reverb_processSubframe( for ( bin = 0; bin < hReverb->numBins; bin++ ) { /* Add from pre-delay buffer a sample to the loop buffer, in a time-inverted order. - * Also apply the spectral gains determined for the reverberation */ + * Also apply the spectral gains determined for the reverberation */ hReverb->loopBufReal[bin][invertSampleIndex] += hReverb->preDelayBufferReal[idx][bin] * hReverb->reverbEqGains[bin]; hReverb->loopBufImag[bin][invertSampleIndex] += hReverb->preDelayBufferImag[idx][bin] * hReverb->reverbEqGains[bin]; hReverb->preDelayBufferReal[idx][bin] = 0.0f; @@ -1669,7 +1682,7 @@ void ivas_binaural_reverb_processSubframe( } /* Add every second input channel as is to the pre-delay buffer, and every second input channel with - * 90 degrees phase shift to reduce energy imbalances between coherent and incoherent sounds */ + * 90 degrees phase shift to reduce energy imbalances between coherent and incoherent sounds */ for ( ch = 0; ch < numInChannels; ch++ ) { if ( ch % 2 ) @@ -1777,10 +1790,10 @@ void ivas_binaural_reverb_processSubframe( /*------------------------------------------------------------------------- - * ivas_binaural_reverb_open() - * - * Allocate and initialize binaural room reverberator handle - *------------------------------------------------------------------------*/ + * ivas_binaural_reverb_open() + * + * Allocate and initialize binaural room reverberator handle + *------------------------------------------------------------------------*/ ivas_error ivas_binaural_reverb_open( REVERB_STRUCT_HANDLE *hReverbPr, /* i/o: binaural reverb handle */ @@ -1856,7 +1869,7 @@ ivas_error ivas_binaural_reverb_open( set_f( hReverb->loopBufImag[bin], 0.0f, len ); /* Determine loop buffer length. The following formula is manually tuned to generate sufficiently long - * but not excessively long loops to generate reverberation. */ + * but not excessively long loops to generate reverberation. */ /* Note: the resulted length is very sensitive to the precision of the constants below (e.g. 1.45 vs. 1.45f) */ hReverb->loopBufLength[bin] = (int16_t) ( 1.45 * (int16_t) ( revTimes[bin] * 150.0 ) + 1 ); hReverb->loopBufLength[bin] = min( hReverb->loopBufLength[bin], hReverb->loopBufLengthMax[bin] ); @@ -1923,10 +1936,10 @@ ivas_error ivas_binaural_reverb_open( /*------------------------------------------------------------------------- - * ivas_binaural_reverb_close() - * - * Close binaural room reverberator handle - *------------------------------------------------------------------------*/ + * ivas_binaural_reverb_close() + * + * Close binaural room reverberator handle + *------------------------------------------------------------------------*/ void ivas_binaural_reverb_close( REVERB_STRUCT_HANDLE *hReverb /* i/o: binaural reverb handle */ -- GitLab From b2658a81b6f82f0c6140a52cef542c4c6902db77 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 8 Sep 2023 16:52:08 +0200 Subject: [PATCH 2/2] clang=format --- lib_rend/ivas_reverb.c | 86 +++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index 0e153e65c2..80dc3d5b4f 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -1322,10 +1322,10 @@ void ivas_reverb_close( /*-----------------------------------------------------------------------------------------* - * Function post_fft_filter() - * - * - *-----------------------------------------------------------------------------------------*/ + * Function post_fft_filter() + * + * + *-----------------------------------------------------------------------------------------*/ static void post_fft_filter( REVERB_HANDLE hReverb, @@ -1355,10 +1355,10 @@ static void post_fft_filter( /*-----------------------------------------------------------------------------------------* - * Function reverb_block() - * - * Input a block (mono) and calculate the 2 output blocks. - *-----------------------------------------------------------------------------------------*/ + * Function reverb_block() + * + * Input a block (mono) and calculate the 2 output blocks. + *-----------------------------------------------------------------------------------------*/ static void reverb_block( REVERB_HANDLE hReverb, @@ -1448,10 +1448,10 @@ static void reverb_block( /*-----------------------------------------------------------------------------------------* - * Function downmix_input_block() - * - * Downmix input to mono, taking also DSR gain into account - *-----------------------------------------------------------------------------------------*/ + * Function downmix_input_block() + * + * Downmix input to mono, taking also DSR gain into account + *-----------------------------------------------------------------------------------------*/ static ivas_error downmix_input_block( const REVERB_HANDLE hReverb, @@ -1509,10 +1509,10 @@ static ivas_error downmix_input_block( /*-----------------------------------------------------------------------------------------* - * Function predelay_block() - * - * Perform a predelay - *-----------------------------------------------------------------------------------------*/ + * Function predelay_block() + * + * Perform a predelay + *-----------------------------------------------------------------------------------------*/ static void predelay_block( const REVERB_HANDLE hReverb, @@ -1563,10 +1563,10 @@ static void predelay_block( /*-----------------------------------------------------------------------------------------* - * Function mix_output_block() - * - * mix one block of *pInL and *pInR samples into *pOutL and *pOutL respectively - *-----------------------------------------------------------------------------------------*/ + * Function mix_output_block() + * + * mix one block of *pInL and *pInR samples into *pOutL and *pOutL respectively + *-----------------------------------------------------------------------------------------*/ static void mix_output_block( const REVERB_HANDLE hReverb, @@ -1588,10 +1588,10 @@ static void mix_output_block( /*-----------------------------------------------------------------------------------------* - * ivas_reverb_process() - * - * Process the input PCM audio into output PCM audio, applying reverb - *-----------------------------------------------------------------------------------------*/ + * ivas_reverb_process() + * + * Process the input PCM audio into output PCM audio, applying reverb + *-----------------------------------------------------------------------------------------*/ ivas_error ivas_reverb_process( const REVERB_HANDLE hReverb, /* i : Reverberator handle */ @@ -1629,10 +1629,10 @@ ivas_error ivas_reverb_process( /*------------------------------------------------------------------------- - * ivas_binaural_reverb_processSubFrame() - * - * Compute the reverberation - room effect - *------------------------------------------------------------------------*/ + * ivas_binaural_reverb_processSubFrame() + * + * Compute the reverberation - room effect + *------------------------------------------------------------------------*/ void ivas_binaural_reverb_processSubframe( REVERB_STRUCT_HANDLE hReverb, /* i/o: binaural reverb handle */ @@ -1650,8 +1650,8 @@ void ivas_binaural_reverb_processSubframe( push_wmops( "binaural_reverb" ); /* 1) Rotate the data in the loop buffer of the reverberator. - * Notice that the audio at the loop buffers is at time-inverted order - * for convolution purposes later on. */ + * Notice that the audio at the loop buffers is at time-inverted order + * for convolution purposes later on. */ for ( bin = 0; bin < hReverb->numBins; bin++ ) { /* Move the data forwards by blockSize (i.e. by the frame size of 16 CLDFB slots) */ @@ -1659,8 +1659,8 @@ void ivas_binaural_reverb_processSubframe( mvr2r( hReverb->loopBufImag[bin], hReverb->loopBufImag[bin] + numSlots, hReverb->loopBufLength[bin] ); /* Add the data from the end of the loop to the beginning, with an attenuation factor - * according to RT60. This procedure generates an IIR decaying response. The response - * is decorrelated later on. */ + * according to RT60. This procedure generates an IIR decaying response. The response + * is decorrelated later on. */ v_multc( hReverb->loopBufReal[bin] + hReverb->loopBufLength[bin], hReverb->loopAttenuationFactor[bin], hReverb->loopBufReal[bin], numSlots ); v_multc( hReverb->loopBufImag[bin] + hReverb->loopBufLength[bin], hReverb->loopAttenuationFactor[bin], hReverb->loopBufImag[bin], numSlots ); } @@ -1674,7 +1674,7 @@ void ivas_binaural_reverb_processSubframe( for ( bin = 0; bin < hReverb->numBins; bin++ ) { /* Add from pre-delay buffer a sample to the loop buffer, in a time-inverted order. - * Also apply the spectral gains determined for the reverberation */ + * Also apply the spectral gains determined for the reverberation */ hReverb->loopBufReal[bin][invertSampleIndex] += hReverb->preDelayBufferReal[idx][bin] * hReverb->reverbEqGains[bin]; hReverb->loopBufImag[bin][invertSampleIndex] += hReverb->preDelayBufferImag[idx][bin] * hReverb->reverbEqGains[bin]; hReverb->preDelayBufferReal[idx][bin] = 0.0f; @@ -1682,7 +1682,7 @@ void ivas_binaural_reverb_processSubframe( } /* Add every second input channel as is to the pre-delay buffer, and every second input channel with - * 90 degrees phase shift to reduce energy imbalances between coherent and incoherent sounds */ + * 90 degrees phase shift to reduce energy imbalances between coherent and incoherent sounds */ for ( ch = 0; ch < numInChannels; ch++ ) { if ( ch % 2 ) @@ -1790,10 +1790,10 @@ void ivas_binaural_reverb_processSubframe( /*------------------------------------------------------------------------- - * ivas_binaural_reverb_open() - * - * Allocate and initialize binaural room reverberator handle - *------------------------------------------------------------------------*/ + * ivas_binaural_reverb_open() + * + * Allocate and initialize binaural room reverberator handle + *------------------------------------------------------------------------*/ ivas_error ivas_binaural_reverb_open( REVERB_STRUCT_HANDLE *hReverbPr, /* i/o: binaural reverb handle */ @@ -1869,7 +1869,7 @@ ivas_error ivas_binaural_reverb_open( set_f( hReverb->loopBufImag[bin], 0.0f, len ); /* Determine loop buffer length. The following formula is manually tuned to generate sufficiently long - * but not excessively long loops to generate reverberation. */ + * but not excessively long loops to generate reverberation. */ /* Note: the resulted length is very sensitive to the precision of the constants below (e.g. 1.45 vs. 1.45f) */ hReverb->loopBufLength[bin] = (int16_t) ( 1.45 * (int16_t) ( revTimes[bin] * 150.0 ) + 1 ); hReverb->loopBufLength[bin] = min( hReverb->loopBufLength[bin], hReverb->loopBufLengthMax[bin] ); @@ -1936,10 +1936,10 @@ ivas_error ivas_binaural_reverb_open( /*------------------------------------------------------------------------- - * ivas_binaural_reverb_close() - * - * Close binaural room reverberator handle - *------------------------------------------------------------------------*/ + * ivas_binaural_reverb_close() + * + * Close binaural room reverberator handle + *------------------------------------------------------------------------*/ void ivas_binaural_reverb_close( REVERB_STRUCT_HANDLE *hReverb /* i/o: binaural reverb handle */ -- GitLab