Commit 6efbc98f authored by multrus's avatar multrus
Browse files

Merge branch...

Merge branch 'basop-2283-isar-post-renderer-broken-for-externally-rendered-omasa-input-and-binaural_split_coded' into 'main'

[rend-non-be][split-non-be] Resolve "ISAR post-renderer broken for externally rendered OMASA input and BINAURAL_SPLIT_CODED format"

Closes #2283

See merge request !2648
parents 15b390a2 6a2b1e97
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -105,6 +105,9 @@
#define NONBE_MR2809
#define FIX_2432_ISM_SPIKES_16KHZ                       /* VA: basop issue 2432: fix spikes in ISM decoding at 16kHz output sampling rate */
#define FIX_2448_RENDERER_MSAN_ERROR                    /* FhG: basop issue 2448: fix MSAN error with MSA rendering */
#define FIX_2283_ISM_MD_DELAY                           /* Dolby: Fix ISM metadata delay round-off */
#define FIX_2283_Q_CLDFB                                /* FhG: Fix Q format issue in CLDFB */
#define FIX_2283_ACCU_CLDFB                             /* FhG: Fix to consider Q-format differences in accumulateCLDFBArrayToBuffer_fx() */

/* ##################### End NON-BE switches ########################### */

+124 −1
Original line number Diff line number Diff line
@@ -413,6 +413,7 @@ static void copyBufferToCLDFBarray_fx(
    return;
}

#ifndef FIX_2283_ACCU_CLDFB
static void accumulateCLDFBArrayToBuffer_fx(
    Word32 re[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
    Word32 im[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
@@ -445,6 +446,79 @@ static void accumulateCLDFBArrayToBuffer_fx(

    return;
}
#else
static void accumulateCLDFBArrayToBuffer_fx(
    Word32 re[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
    Word32 im[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
    Word16 Q_new,
    const IVAS_REND_AudioBuffer *buffer )
{
    UWord32 smplIdx, slotIdx;
    UWord32 numCldfbSamples, num_bands;
    Word16 chnlIdx;
    Word32 *writePtr;
    Word16 Q_old, Q_diff;

    Q_old = *( buffer->pq_fact );
    move16();

    Q_diff = sub( Q_new, Q_old );

    assert( ( buffer->config.is_cldfb == 1 ) && "for time domain input call copyBufferTo2dArray()" );
    writePtr = buffer->data_fx;
    numCldfbSamples = (UWord32) shr( buffer->config.numSamplesPerChannel, 1 );
    num_bands = (UWord32) Mpy_32_32( numCldfbSamples, ONE_BY_CLDFB_NO_COL_MAX_Q31 );

    IF( LE_16( Q_diff, 0 ) )
    {
        /*Shift-right the accumulator to avoid overflows*/
        FOR( chnlIdx = 0; chnlIdx < buffer->config.numChannels; ++chnlIdx )
        {
            FOR( slotIdx = 0; slotIdx < CLDFB_NO_COL_MAX; ++slotIdx )
            {
                FOR( smplIdx = 0; smplIdx < num_bands; ++smplIdx )
                {
                    *writePtr = L_add( L_shl( *writePtr, Q_diff ), re[chnlIdx][slotIdx][smplIdx] );
                    writePtr++;
                }
                FOR( smplIdx = 0; smplIdx < num_bands; ++smplIdx )
                {
                    *writePtr = L_add( L_shl( *writePtr, Q_diff ), im[chnlIdx][slotIdx][smplIdx] );
                    writePtr++;
                }
            }
        }

        *( buffer->pq_fact ) = Q_new;
        move16();
    }
    ELSE
    {
        /*Shift-right the operand to avoid overflows*/
        FOR( chnlIdx = 0; chnlIdx < buffer->config.numChannels; ++chnlIdx )
        {
            FOR( slotIdx = 0; slotIdx < CLDFB_NO_COL_MAX; ++slotIdx )
            {
                FOR( smplIdx = 0; smplIdx < num_bands; ++smplIdx )
                {
                    *writePtr = L_add( *writePtr, L_shr( re[chnlIdx][slotIdx][smplIdx], Q_diff ) );
                    writePtr++;
                }
                FOR( smplIdx = 0; smplIdx < num_bands; ++smplIdx )
                {
                    *writePtr = L_add( *writePtr, L_shr( im[chnlIdx][slotIdx][smplIdx], Q_diff ) );
                    writePtr++;
                }
            }
        }

        *( buffer->pq_fact ) = Q_old;
        move16();
    }

    return;
}
#endif

static void copyBufferTo2dArray_fx(
    const IVAS_REND_AudioBuffer buffer,
@@ -469,6 +543,7 @@ static void copyBufferTo2dArray_fx(

    return;
}

static void accumulate2dArrayToBuffer_fx(
    Word32 array[][L_FRAME48k],
    const IVAS_REND_AudioBuffer *buffer )
@@ -1682,8 +1757,13 @@ static ivas_error alignInputDelay(
                Word64 tmp;
                inputIsm = (input_ism *) inputBase;

#ifdef FIX_2283_ISM_MD_DELAY
                tmp = W_mult0_32_32( L_add( maxGlobalDelayNs, 500000 /* + 0.5ms for rounding */ ) /* Q0 */, 4295 /* (1 / 1e6f) in Q32 */ ); // Q32
                inputIsm->ism_metadata_delay_ms_fx = add( inputIsm->ism_metadata_delay_ms_fx, extract_l( W_extract_h( tmp ) ) );
#else
                tmp = W_mult0_32_32( L_add( maxGlobalDelayNs, 500000 /* + 0.5ms for rounding */ ) /* Q0 */, 2147 /* (1 / 1e6f) in Q31 */ ); // Q31
                inputIsm->ism_metadata_delay_ms_fx = add( inputIsm->ism_metadata_delay_ms_fx, extract_h( W_extract_h( tmp ) ) );
#endif
            }
        }
    }
@@ -7004,7 +7084,6 @@ static ivas_error renderIsmToSba(
    return error;
}


static ivas_error renderIsmToSplitBinaural(
    input_ism *ismInput,
    const IVAS_REND_AudioBuffer outAudio )
@@ -7124,6 +7203,31 @@ static ivas_error renderIsmToSplitBinaural(
                                         num_bands,
                                         ismInput->base.ctx.pSplitRendWrapper->hCldfbHandles->cldfbAna[pos_idx + ch],
                                         &q_cldfb );
#ifdef FIX_2283_Q_CLDFB
                    /* scale re and im according to exp-q_cldfb */
                    {
                        Word32 *realBuffer_fx = &tmpBinaural_CldfbRe[BINAURAL_CHANNELS * pos_idx + ch][slot_idx][0];
                        Word32 *imagBuffer_fx = &tmpBinaural_CldfbIm[BINAURAL_CHANNELS * pos_idx + ch][slot_idx][0];
                        Word16 noChannels = ismInput->base.ctx.pSplitRendWrapper->hCldfbHandles->cldfbAna[pos_idx + ch]->no_channels;

#ifdef FIX_2283_ACCU_CLDFB
                        Word16 scale = sub( exp, q_cldfb );
                        FOR( Word16 j = 0; j < noChannels; j++ )
                        {
                            realBuffer_fx[j] = L_shl( realBuffer_fx[j], scale ); /*Q(exp)*/
                            imagBuffer_fx[j] = L_shl( imagBuffer_fx[j], scale ); /*Q(exp)*/
                        }
#else
                        Word16 scale = sub( sub( exp, q_cldfb ), 1 );
                        FOR( Word16 j = 0; j < noChannels; j++ )
                        {
                            realBuffer_fx[j] = L_shl( realBuffer_fx[j], scale ); /*Q(exp)*/
                            imagBuffer_fx[j] = L_shl( imagBuffer_fx[j], scale ); /*Q(exp)*/
                        }
#endif
                        q_cldfb = exp;
                    }
#endif
                }
            }
        }
@@ -7148,7 +7252,11 @@ static ivas_error renderIsmToSplitBinaural(

    if ( outAudio.config.is_cldfb )
    {
#ifdef FIX_2283_ACCU_CLDFB
        accumulateCLDFBArrayToBuffer_fx( tmpBinaural_CldfbRe, tmpBinaural_CldfbIm, exp, &outAudio );
#else
        accumulateCLDFBArrayToBuffer_fx( tmpBinaural_CldfbRe, tmpBinaural_CldfbIm, &outAudio );
#endif
    }
    else
    {
@@ -8372,7 +8480,11 @@ static ivas_error renderSbaToSplitBinaural(
            return error;
        }

#ifdef FIX_2283_ACCU_CLDFB
        accumulateCLDFBArrayToBuffer_fx( Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, *outAudio.pq_fact, &outAudio );
#else
        accumulateCLDFBArrayToBuffer_fx( Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, &outAudio );
#endif
    }
    ELSE
    {
@@ -8422,7 +8534,11 @@ static ivas_error renderSbaToBinaural(
            return error;
        }

#ifdef FIX_2283_ACCU_CLDFB
        accumulateCLDFBArrayToBuffer_fx( Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, *outAudio.pq_fact, &outAudio );
#else
        accumulateCLDFBArrayToBuffer_fx( Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, &outAudio );
#endif
    }
    ELSE
    {
@@ -9093,10 +9209,14 @@ static ivas_error renderInputMasa(

            ivas_masa_ext_rend_parambin_render_fx( masaInput->hMasaExtRend, *masaInput->base.ctx.pCombinedOrientationData, tmpBuffer_fx, num_subframes, masaInput->base.ctx.pSplitRendWrapper, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural );

#ifdef FIX_2283_ACCU_CLDFB
            accumulateCLDFBArrayToBuffer_fx( Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, Q6, &outAudio );
#else
            accumulateCLDFBArrayToBuffer_fx( Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, &outAudio );

            *outAudio.pq_fact = Q6;
            move16();
#endif
        }
        ELSE
        {
@@ -9530,14 +9650,17 @@ static ivas_error getSamplesInternal(
    {
        return error;
    }

    IF( NE_32( ( error = renderActiveInputsMc( hIvasRend, outAudio ) ), IVAS_ERR_OK ) )
    {
        return error;
    }

    IF( NE_32( ( error = renderActiveInputsSba( hIvasRend, outAudio ) ), IVAS_ERR_OK ) )
    {
        return error;
    }

    IF( NE_32( ( error = renderActiveInputsMasa( hIvasRend, outAudio ) ), IVAS_ERR_OK ) )
    {
        return error;