Commit bf5bf105 authored by sagnowski's avatar sagnowski
Browse files

Refactor CLDFB analysis on audio buffers into a helper function

parent aeab2abc
Loading
Loading
Loading
Loading
+66 −28
Original line number Diff line number Diff line
@@ -454,6 +454,65 @@ static void accumulate2dArrayToBuffer(
    return;
}


#ifdef FIX_BASOP_2283_OMASA_SR
/*-------------------------------------------------------------------*
 * audio_buffer_td_to_cldfb()
 *
 * Performs CLDFB analysis on contents of td_buffer and mixes the result into cldfb_buffer.
 *
 * This function **does not** clear the destination buffer before writing.
 *
 * The number of valid CLDFB handles in cldfbAna must be a least equal to the number of channels
 * in the audio buffers.
 *-------------------------------------------------------------------*/
static void audio_buffer_td_to_cldfb(
    IVAS_REND_AudioBuffer td_buffer,
    IVAS_REND_AudioBuffer cldfb_buffer,
    int32_t fs,
    HANDLE_CLDFB_FILTER_BANK* cldfbAna
)
{
    int16_t ch, slot_idx;
    float *td_read_ptr;
    float *cldfb_write_ptr;
    int16_t num_bands;

    assert( !td_buffer.config.is_cldfb );
    assert( cldfb_buffer.config.is_cldfb );

    assert( td_buffer.config.numChannels == cldfb_buffer.config.numChannels );
    assert( td_buffer.config.numSamplesPerChannel == cldfb_buffer.config.numSamplesPerChannel * 2 );

    td_read_ptr = td_buffer.data;
    cldfb_write_ptr = cldfb_buffer.data;
    num_bands = (int16_t) ( ( BINAURAL_MAXBANDS * fs ) / 48000 );

    for ( ch = 0; ch < cldfb_buffer.config.numChannels; ++ch )
    {
        for ( slot_idx = 0; slot_idx < IVAS_CLDFB_NO_COL_MAX; ++slot_idx )
        {
            float re[CLDFB_NO_CHANNELS_MAX];
            float im[CLDFB_NO_CHANNELS_MAX];

            cldfbAnalysis_ts( td_read_ptr,
                              re,
                              im,
                              num_bands,
                              cldfbAna[ch] );

            td_read_ptr += CLDFB_NO_CHANNELS_MAX;

            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


/*-------------------------------------------------------------------*
 * limitRendererOutput()
 *
@@ -6314,7 +6373,9 @@ static ivas_error renderActiveInputsIsm(
        }

#ifdef FIX_BASOP_2283_OMASA_SR
        if ( ( error = renderInputIsm( pCurrentInput, hIvasRend->outputConfig, outAudio.config.is_cldfb ? tmp_td_audio_buf : outAudio ) ) != IVAS_ERR_OK )
        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
@@ -6326,33 +6387,10 @@ static ivas_error renderActiveInputsIsm(
#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 num_bands = (int16_t) ( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 );

        for ( ch = 0; ch < outAudio.config.numChannels; ++ch )
        {
            for ( slot_idx = 0; slot_idx < IVAS_CLDFB_NO_COL_MAX; ++slot_idx )
            {
                float re[CLDFB_NO_CHANNELS_MAX];
                float im[CLDFB_NO_CHANNELS_MAX];

                cldfbAnalysis_ts( td_read_ptr,
                                  re,
                                  im,
                                  num_bands,
                                  hIvasRend->splitRendWrapper->hCldfbHandles->cldfbAna[ch] );

                td_read_ptr += CLDFB_NO_CHANNELS_MAX;

                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;
            }
        }
        audio_buffer_td_to_cldfb( tmp_td_audio_buf,
                                  outAudio,
                                  hIvasRend->sampleRateOut,
                                  hIvasRend->splitRendWrapper->hCldfbHandles->cldfbAna );
    }
#endif