Commit 3176d843 authored by multrus's avatar multrus
Browse files

Merge branch '2049_fix_difference_in_the_decorrelator_tail' into 'main'

[non-BE][split non-BE][rend non-BE] Resolve #2049: "Difference in the decorrelator tail in the IVAS_rend MASA binaural output"

Closes #2049

See merge request !2312
parents c4f46c08 76f7ef25
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -107,6 +107,7 @@
#define FIX_1962_FORMAT_CONV_SPECTRAL_DIFF                   /* FhG: Improved precision of targetEnergy in ivas_ls_setup_conversion_process_mdct_fx() */
#define FIX_2003_CON_TCX_OVERFLOW                            /* FhG: Use a dynamic scaling factor for the synth buffer at the output of con_tcx_ivas_fx() */
#define OPT_TCXLTP_FILTER_LOOP                               /* FhG: optimize loop in tcx_ltp_synth_filter */
#define FIX_2049_DIFF_IN_DECORR_TAIL                         /* FhG: correct scale values in ivas_dirac_dec_binaural_process_output_fx() */
#define FIX_2602_NONBE_SAT_IN_SWB_TBE_SCALE                  /* Dolby/FhG: fix for issue 2026: Saturation in SWB TBE re-scaling function preventing StereoDownmix complexity job to complete */

/* #################### Start BASOP porting switches ############################ */
+89 −14
Original line number Diff line number Diff line
@@ -109,8 +109,11 @@ typedef struct parambin_rend_config_data
 *------------------------------------------------------------------------*/

static void ivas_dirac_dec_binaural_internal_fx( Decoder_Struct *st_ivas, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, Word32 *output_f[] /*Q11*/, const Word16 nchan_transport, const Word16 subframe );

#ifdef FIX_2049_DIFF_IN_DECORR_TAIL
static void ivas_dirac_dec_decorrelate_slot_fx( DIRAC_DEC_BIN_HANDLE hDiracDecBin, const Word16 num_freq_bands, const Word16 slot, Word32 inRe[][CLDFB_SLOTS_PER_SUBFRAME] /*q_inp*/[CLDFB_NO_CHANNELS_MAX], Word32 inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX] /*q_inp*/, Word16 q_inp, Word32 decRe[][CLDFB_NO_CHANNELS_MAX], Word32 decIm[][CLDFB_NO_CHANNELS_MAX], Word16 *q_out );
#else
static void ivas_dirac_dec_decorrelate_slot_fx( DIRAC_DEC_BIN_HANDLE hDiracDecBin, const Word16 num_freq_bands, const Word16 slot, Word32 inRe[][CLDFB_SLOTS_PER_SUBFRAME] /*q_inp*/[CLDFB_NO_CHANNELS_MAX], Word32 inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX] /*q_inp*/, Word16 q_inp, Word32 decRe[][CLDFB_NO_CHANNELS_MAX] /*q_inp*/, Word32 decIm[] /*q_inp*/[CLDFB_NO_CHANNELS_MAX] );
#endif

static void ivas_dirac_dec_binaural_formulate_input_covariance_matrices_fx( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, PARAMBIN_REND_CONFIG_HANDLE hConfig, Word32 inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const Word16 subframe, Word32 *subFrameTotalEne, Word16 *subFrameTotalEne_e, Word32 *IIReneLimiter, Word16 q );

@@ -1261,8 +1264,15 @@ static void ivas_dirac_dec_decorrelate_slot_fx(
    Word32 inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /*q_inp*/
    Word32 inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /*q_inp*/
    Word16 q_inp,
#ifdef FIX_2049_DIFF_IN_DECORR_TAIL
    Word32 decRe[][CLDFB_NO_CHANNELS_MAX],
    Word32 decIm[][CLDFB_NO_CHANNELS_MAX],
    Word16 *q_out
#else
    Word32 decRe[][CLDFB_NO_CHANNELS_MAX], /*q_inp*/
    Word32 decIm[][CLDFB_NO_CHANNELS_MAX] /*q_inp*/ )
    Word32 decIm[][CLDFB_NO_CHANNELS_MAX]  /*q_inp*/
#endif
)
{
    Word16 offset, ch, bin;
    Word32 onset_filter_fx[BINAURAL_CHANNELS * CLDFB_NO_CHANNELS_MAX];                     /* 2 ch, 60 bins */
@@ -1314,7 +1324,11 @@ static void ivas_dirac_dec_decorrelate_slot_fx(
            move32();
        }
    }
#ifdef FIX_2049_DIFF_IN_DECORR_TAIL
    *q_out = q_decorrelatedFrameInterleaved;
#else
    // q_decorrelatedFrameInterleaved will be same as q_inp/q_protoFrame //
#endif
    return;
}

@@ -2734,8 +2748,11 @@ static void ivas_dirac_dec_binaural_process_output_fx(
    move16();
    move16();
    move16();

#ifdef FIX_2049_DIFF_IN_DECORR_TAIL
    Word32 decSlotRe_fx[CLDFB_SLOTS_PER_SUBFRAME][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX], decSlotIm_fx[CLDFB_SLOTS_PER_SUBFRAME][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX];
#else
    Word32 decSlotRe_fx[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX], decSlotIm_fx[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX];
#endif
    Word32 outSlotRe_fx[CLDFB_NO_CHANNELS_MAX], outSlotIm_fx[CLDFB_NO_CHANNELS_MAX];
    Word16 q_inp[6][CLDFB_SLOTS_PER_SUBFRAME];
    Word16 interpVal_fx;
@@ -2745,7 +2762,11 @@ static void ivas_dirac_dec_binaural_process_output_fx(
    move16();
    Word16 ch_len = s_max( 4, numInChannels );
    Word16 eff_q;

#ifdef FIX_2049_DIFF_IN_DECORR_TAIL
    Word16 q_decSlot[CLDFB_SLOTS_PER_SUBFRAME];
    Word16 q_decSlotMin = 31;
    move16();
#endif

    IF( processReverb )
    {
@@ -2792,15 +2813,55 @@ static void ivas_dirac_dec_binaural_process_output_fx(
            move16();
        }

#ifdef FIX_2049_DIFF_IN_DECORR_TAIL
        IF( !hDiracDecBin->useTdDecorr && ( max_band_decorr > 0 ) )
        {
            FOR( slot = 0; slot < nSlots; slot++ )
            {
                ivas_dirac_dec_decorrelate_slot_fx( hDiracDecBin, nBins, slot, inRe_fx, inIm_fx, q_input, decSlotRe_fx[slot], decSlotIm_fx[slot], &q_decSlot[slot] );

                Word16 scf = s_min( getScaleFactor32( decSlotRe_fx[slot][0], nBins ), getScaleFactor32( decSlotRe_fx[slot][1], nBins ) );
                scf = s_min( scf, getScaleFactor32( decSlotIm_fx[slot][0], nBins ) );
                scf = s_min( scf, getScaleFactor32( decSlotIm_fx[slot][1], nBins ) );

                scale_sig32( decSlotRe_fx[slot][0], nBins, scf );
                scale_sig32( decSlotRe_fx[slot][1], nBins, scf );
                scale_sig32( decSlotIm_fx[slot][0], nBins, scf );
                scale_sig32( decSlotIm_fx[slot][1], nBins, scf );
                q_decSlot[slot] += scf;

                q_decSlotMin = s_min( q_decSlotMin, q_decSlot[slot] );
            }

            Word16 q_tmp = add( q_input, sub( add( q_inp_mix, q_mat ), hDiracDecBin->q_processMtxPrev ) );
            Word16 q_shift = sub( q_decSlotMin, q_tmp );

            IF( GT_32( q_decSlotMin, q_tmp ) )
            {
                q_decSlotMin = sub( q_decSlotMin, q_shift );
            }
            ELSE
            {
                q_inp_mix = add( q_inp_mix, q_shift );
                cldfb_state_shift = add( cldfb_state_shift, q_shift );
            }

            FOR( Word16 ch = 0; ch < BINAURAL_CHANNELS; ch++ )
            {
                FOR( slot = 0; slot < nSlots; slot++ )
                {
                    scale_sig32( decSlotRe_fx[slot][ch], nBins, sub( q_decSlotMin, q_decSlot[slot] ) );
                    scale_sig32( decSlotIm_fx[slot][ch], nBins, sub( q_decSlotMin, q_decSlot[slot] ) );
                }
            }
        }
#endif
        eff_q = sub( add( q_inp_mix, q_mat ), 15 );

        FOR( Word16 i = 0; i < ch_len; i++ )

        {
            FOR( Word16 j = 0; j < nSlots; j++ )
            {

                scale_sig32( inRe_fx[i][j], nBins, q_inp_mix ); /*q_input + q_inp_mix*/
                scale_sig32( inIm_fx[i][j], nBins, q_inp_mix ); /*q_input + q_inp_mix*/
                test();
@@ -2853,19 +2914,31 @@ static void ivas_dirac_dec_binaural_process_output_fx(
        {
            if ( recompute == 1 )
            {
#ifndef FIX_2049_DIFF_IN_DECORR_TAIL
                ivas_dirac_dec_decorrelate_slot_fx( hDiracDecBin, nBins, slot, inRe_fx, inIm_fx, q_inp_mix, decSlotRe_fx, decSlotIm_fx );
#endif
                FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ )
                {
#ifdef FIX_2049_DIFF_IN_DECORR_TAIL
                    Copy32( decSlotRe_fx[slot][chA], decorrRe_fx[chA][slot], CLDFB_NO_CHANNELS_MAX );
                    Copy32( decSlotIm_fx[slot][chA], decorrIm_fx[chA][slot], CLDFB_NO_CHANNELS_MAX );
#else
                    Copy32( decSlotRe_fx[chA], decorrRe_fx[chA][slot], CLDFB_NO_CHANNELS_MAX );
                    Copy32( decSlotIm_fx[chA], decorrIm_fx[chA][slot], CLDFB_NO_CHANNELS_MAX );
#endif
                }
            }
            else
            {
                FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ )
                {
#ifdef FIX_2049_DIFF_IN_DECORR_TAIL
                    Copy32( decorrRe_fx[chA][slot], decSlotRe_fx[slot][chA], CLDFB_NO_CHANNELS_MAX );
                    Copy32( decorrIm_fx[chA][slot], decSlotIm_fx[slot][chA], CLDFB_NO_CHANNELS_MAX );
#else
                    Copy32( decorrRe_fx[chA][slot], decSlotRe_fx[chA], CLDFB_NO_CHANNELS_MAX );
                    Copy32( decorrIm_fx[chA][slot], decSlotIm_fx[chA], CLDFB_NO_CHANNELS_MAX );
#endif
                }
            }
        }
@@ -2893,8 +2966,13 @@ static void ivas_dirac_dec_binaural_process_output_fx(
                    }
                    ELSE
                    {
#ifdef FIX_2049_DIFF_IN_DECORR_TAIL
                        decSlotRePointer_fx = decSlotRe_fx[slot][chB];
                        decSlotImPointer_fx = decSlotIm_fx[slot][chB];
#else
                        decSlotRePointer_fx = decSlotRe_fx[chB];
                        decSlotImPointer_fx = decSlotIm_fx[chB];
#endif
                    }
                }
                ELSE
@@ -2903,7 +2981,6 @@ static void ivas_dirac_dec_binaural_process_output_fx(
                    decSlotImPointer_fx = NULL;
                }


                FOR( bin = 0; bin < nBins; bin++ )
                {
                    Word16 gain;
@@ -2916,11 +2993,9 @@ static void ivas_dirac_dec_binaural_process_output_fx(
                    move32();

                    gain = add( mult( sub( 32767, interpVal_fx ), hDiracDecBin->processMtxImPrev_fx[chA][chB][bin] ), mult( interpVal_fx, hDiracDecBin->processMtxIm_fx[chA][chB][bin] ) ); // Q11

                    // interpVal * hDiracDecBin->processMtxIm[chA][chB][bin];
                    outSlotRe_fx[bin] = Msub_32_16( outSlotRe_fx[bin], inIm_fx[chB][slot][bin], gain ); // q_inp_mix-4//q_result
                    outSlotIm_fx[bin] = Madd_32_16( outSlotIm_fx[bin], inRe_fx[chB][slot][bin], gain ); // q_inp_mix-4//q_result

                    move32();
                    move32();

@@ -2930,13 +3005,14 @@ static void ivas_dirac_dec_binaural_process_output_fx(
                    {
                        gain = add( mult( sub( 32767, interpVal_fx ), hDiracDecBin->processMtxDecRePrev_fx[chA][chB][bin] ), mult( interpVal_fx, hDiracDecBin->processMtxDecRe_fx[chA][chB][bin] ) ); // Q11
                        // interpVal * hDiracDecBin->processMtxDecRe[chA][chB][bin];

                        outSlotRe_fx[bin] = Madd_32_16( outSlotRe_fx[bin], decSlotRePointer_fx[bin], gain ); // q_inp_mix-4//q_result
                        outSlotIm_fx[bin] = Madd_32_16( outSlotIm_fx[bin], decSlotImPointer_fx[bin], gain ); // q_inp_mix-4//q_result
                        move32();
                        move32();


                        gain = add( mult( sub( 32767, interpVal_fx ), hDiracDecBin->processMtxDecImPrev_fx[chA][chB][bin] ), mult( interpVal_fx, hDiracDecBin->processMtxDecIm_fx[chA][chB][bin] ) ); // Q11

                        outSlotRe_fx[bin] = Msub_32_16( outSlotRe_fx[bin], decSlotImPointer_fx[bin], gain ); // q_inp_mix-4//q_result
                        outSlotIm_fx[bin] = Madd_32_16( outSlotIm_fx[bin], decSlotRePointer_fx[bin], gain ); // q_inp_mix-4//q_result
                        move32();
@@ -2945,7 +3021,6 @@ static void ivas_dirac_dec_binaural_process_output_fx(
                }
            }


            IF( processReverb )
            {
                /* Combine second (reverb) part with the first (HRTF) part to obtain binaural output signal with room effect */
@@ -2953,7 +3028,6 @@ static void ivas_dirac_dec_binaural_process_output_fx(
                v_add_fx( outSlotIm_fx, reverbIm_fx[chA][slot], outSlotIm_fx, CLDFB_NO_CHANNELS_MAX );
            }


            outSlotRePr_fx = &( outSlotRe_fx[0] );
            outSlotImPr_fx = &( outSlotIm_fx[0] );

@@ -2974,6 +3048,7 @@ static void ivas_dirac_dec_binaural_process_output_fx(
            }
        }
    }

    if ( recompute == 1 )
    {
        *q_out = sub( q_result, 1 );