Commit ba11fad6 authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

[fix] missing set_zero and introduce FIX_BASOP_2283_OMASA_SR

parent cb742fd1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -171,6 +171,7 @@
/* any switch which is non-be wrt. TS 26.258 V3.0 */

#define FIX_2432_ISM_SPIKES_16KHZ                       /* VA: basop issue 2432: fix spikes in ISM decoding at 16kHz output sampling rate */
#define FIX_BASOP_2283_OMASA_SR                         /* FhG: basop issue 2283: fix garbage output for >1 object OMASA with extrend as ISAR prerenderer */

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

+56 −38
Original line number Diff line number Diff line
@@ -6067,9 +6067,11 @@ static ivas_error renderIsmToSplitBinaural(

    push_wmops( "renderIsmToSplitBinaural" );

#ifdef FIX_BASOP_2283_OMASA_SR
    assert( !outAudio.config.is_cldfb &&
            "ISM renderering only supports TD output. If CLDFB output was requested, "
            "we convert to CLDFB higher up the stack after rendering all ISMs" );
#endif

    pSplitRendWrapper = ismInput->base.ctx.pSplitRendWrapper;
    pMultiBinPoseData = &pSplitRendWrapper->multiBinPoseData;
@@ -6131,30 +6133,33 @@ static ivas_error renderIsmToSplitBinaural(
            return error;
        }

        // if ( outAudio.config.is_cldfb )
        // {
        //     /* Perform CLDFB analysis on rendered audio, since the output buffer is CLDFB domain */
        //     num_bands = (int16_t) ( ( BINAURAL_MAXBANDS * *ismInput->base.ctx.pOutSampleRate ) / 48000 );
        //     for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
        //     {
        //         fprintf( stderr, "    channel %d, using CLDFB handle %d\n", ch, BINAURAL_CHANNELS * pos_idx + ch );
        //         for ( slot_idx = 0; slot_idx < IVAS_CLDFB_NO_COL_MAX; slot_idx++ )
        //         {
        //             cldfbAnalysis_ts( &tmpProcessing[ch][num_bands * slot_idx],
        //                               &tmpBinaural_CldfbRe[BINAURAL_CHANNELS * pos_idx + ch][slot_idx][0],
        //                               &tmpBinaural_CldfbIm[BINAURAL_CHANNELS * pos_idx + ch][slot_idx][0],
        //                               num_bands,
        //                               ismInput->base.ctx.pSplitRendWrapper->hCldfbHandles->cldfbAna[BINAURAL_CHANNELS * pos_idx + ch] );
        //         }
        //     }
        // }
        // else
        // {
#ifndef FIX_BASOP_2283_OMASA_SR
        if ( outAudio.config.is_cldfb )
        {
            /* Perform CLDFB analysis on rendered audio, since the output buffer is CLDFB domain */
            num_bands = (int16_t) ( ( BINAURAL_MAXBANDS * *ismInput->base.ctx.pOutSampleRate ) / 48000 );
            for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
            {
                for ( slot_idx = 0; slot_idx < IVAS_CLDFB_NO_COL_MAX; slot_idx++ )
                {
                    cldfbAnalysis_ts( &tmpProcessing[ch][num_bands * slot_idx],
                                      &tmpBinaural_CldfbRe[BINAURAL_CHANNELS * pos_idx + ch][slot_idx][0],
                                      &tmpBinaural_CldfbIm[BINAURAL_CHANNELS * pos_idx + ch][slot_idx][0],
                                      num_bands,
                                      ismInput->base.ctx.pSplitRendWrapper->hCldfbHandles->cldfbAna[pos_idx + ch] );
                }
            }
        }
        else
        {
#endif
            /* Copy rendered audio to tmp storage buffer. Copying directly to output would
             * overwrite original audio, which is still needed for rendering next head pose. */
            mvr2r( tmpProcessing[0], tmpBinaural[BINAURAL_CHANNELS * pos_idx], output_frame );
            mvr2r( tmpProcessing[1], tmpBinaural[BINAURAL_CHANNELS * pos_idx + 1], output_frame );
        // }
#ifndef FIX_BASOP_2283_OMASA_SR
        }
#endif

        /* Overwrite processing buffer with original input audio again */
        copyBufferTo2dArray( ismInput->base.inputBuffer, tmpProcessing );
@@ -6166,14 +6171,18 @@ static ivas_error renderIsmToSplitBinaural(
        pCombinedOrientationData->Quaternions[i] = originalHeadRot[i];
    }

    // if ( outAudio.config.is_cldfb )
    // {
    //     accumulateCLDFBArrayToBuffer( tmpBinaural_CldfbRe, tmpBinaural_CldfbIm, &outAudio );
    // }
    // else
    // {
#ifndef FIX_BASOP_2283_OMASA_SR
    if ( outAudio.config.is_cldfb )
    {
        accumulateCLDFBArrayToBuffer( tmpBinaural_CldfbRe, tmpBinaural_CldfbIm, &outAudio );
    }
    else
    {
#endif
        accumulate2dArrayToBuffer( tmpBinaural, &outAudio );
    // }
#ifndef FIX_BASOP_2283_OMASA_SR
    }
#endif
    pop_wmops();

    /* Encoding to split rendering bitstream done at a higher level */
@@ -6280,6 +6289,7 @@ static ivas_error renderActiveInputsIsm(
    int16_t i;
    input_ism *pCurrentInput;
    ivas_error error;
#ifdef FIX_BASOP_2283_OMASA_SR
    IVAS_REND_AudioBuffer tmp_td_audio_buf;
    float tmpBinaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS * L_FRAME48k];

@@ -6291,7 +6301,9 @@ static ivas_error renderActiveInputsIsm(
        tmp_td_audio_buf.config.numSamplesPerChannel /= 2;
        tmp_td_audio_buf.config.is_cldfb = false;
        tmp_td_audio_buf.data = tmpBinaural;
        set_zero( tmpBinaural, MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS * L_FRAME48k );
    }
#endif

    for ( i = 0, pCurrentInput = hIvasRend->inputsIsm; i < RENDERER_MAX_ISM_INPUTS; ++i, ++pCurrentInput )
    {
@@ -6301,19 +6313,24 @@ static ivas_error renderActiveInputsIsm(
            continue;
        }

#ifdef FIX_BASOP_2283_OMASA_SR
        if ( ( error = renderInputIsm( pCurrentInput, hIvasRend->outputConfig, outAudio.config.is_cldfb ? tmp_td_audio_buf : outAudio ) ) != IVAS_ERR_OK )
#else
        if ( ( error = renderInputIsm( pCurrentInput, hIvasRend->outputConfig, outAudio ) ) != IVAS_ERR_OK )
#endif
        {
            return error;
        }
    }

#ifdef FIX_BASOP_2283_OMASA_SR
    if ( outAudio.config.is_cldfb )
    {
        // TODO: move up
        int16_t ch, slot_idx;
        float *td_read_ptr = tmp_td_audio_buf.data;
        float *cldfb_write_ptr = outAudio.data;
        int16_t slot_len = 60; // TODO: compute?
        int16_t num_bands = (int16_t) ( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 );

        for ( ch = 0; ch < outAudio.config.numChannels; ++ch )
        {
@@ -6325,18 +6342,19 @@ static ivas_error renderActiveInputsIsm(
                cldfbAnalysis_ts( td_read_ptr,
                                  re,
                                  im,
                                  slot_len,
                                  num_bands,
                                  hIvasRend->splitRendWrapper->hCldfbHandles->cldfbAna[ch] );

                td_read_ptr += slot_len;
                td_read_ptr += CLDFB_NO_CHANNELS_MAX;

                v_add( re, cldfb_write_ptr, cldfb_write_ptr, slot_len );
                cldfb_write_ptr += slot_len;
                v_add( im, cldfb_write_ptr, cldfb_write_ptr, slot_len );
                cldfb_write_ptr += slot_len;
                v_add( re, cldfb_write_ptr, cldfb_write_ptr, num_bands );
                cldfb_write_ptr += CLDFB_NO_CHANNELS_MAX;
                v_add( im, cldfb_write_ptr, cldfb_write_ptr, num_bands );
                cldfb_write_ptr += CLDFB_NO_CHANNELS_MAX;
            }
        }
    }
#endif

    return IVAS_ERR_OK;
}