Commit 90b3674f authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'ivas_crend_funcs_fxd' into 'main'

renderSbaToSba and renderSbaToMC functions converted to fxd

See merge request !133
parents c96945c1 6e56a74c
Loading
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1373,6 +1373,12 @@ int main(
                fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
                exit( -1 );
            }
#else
            if ( ( error = IVAS_REND_FeedInputAudio( hIvasRend, sbaIds[i], tmpBuffer ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
                exit( -1 );
            }
#endif
        }

+2 −2
Original line number Diff line number Diff line
@@ -775,7 +775,7 @@ void rotateFrame_sd(

                /* output channel index without LFE */
                ch_out_woLFE = ( ch_out >= index_lfe ) ? ch_out - 1 : ch_out;
                gains_prev_fx[ch_in][ch_out] = tmp_gains_fx[ch_out_woLFE]; // Adjusting Q30 -> Q28
                gains_prev_fx[ch_in][ch_out] = tmp_gains_fx[ch_out_woLFE]; // Q30 
            }
        }

@@ -800,7 +800,7 @@ void rotateFrame_sd(
                /* output channel index without LFE */
                ch_out_woLFE = ( ch_out >= index_lfe ) ? ch_out - 1 : ch_out;

                gains_fx[ch_in][ch_out] = tmp_gains_fx[ch_out_woLFE]; // Adjusting Q30 -> Q28
                gains_fx[ch_in][ch_out] = tmp_gains_fx[ch_out_woLFE]; // Q30 
            }
        }
    }
+275 −76
Original line number Diff line number Diff line
@@ -1786,7 +1786,6 @@ static void copyLsConversionMatrixToPanMatrix(
    return;
}


static void setZeroPanMatrix(
    pan_matrix panMatrix )
{
@@ -1799,8 +1798,35 @@ static void setZeroPanMatrix(

    return;
}
#ifdef IVAS_FLOAT_FIXED
static void setZeroPanMatrix_fx(
    pan_matrix_fx panMatrix )
{
    Word16 i;

    FOR( i = 0; i < MAX_INPUT_CHANNELS; ++i )
    {
        set_val_Word32( panMatrix[i], 0, MAX_OUTPUT_CHANNELS );
    }

    return;
}
#endif
#ifdef IVAS_FLOAT_FIXED
/* Note: this only sets non-zero elements, call setZeroPanMatrix() to init first. */
static void fillIdentityPanMatrix_fx(
    pan_matrix_fx panMatrix )
{
    Word16 i;

    FOR( i = 0; i < min( MAX_INPUT_CHANNELS, MAX_OUTPUT_CHANNELS ); ++i )
    {
        panMatrix[i][i] = ONE_IN_Q31;
    }

    return;
}
#endif
/* Note: this only sets non-zero elements, call setZeroPanMatrix() to init first. */
static void fillIdentityPanMatrix(
    pan_matrix panMatrix )
@@ -2750,25 +2776,35 @@ static ivas_error initSbaPanGainsForMcOut(
#ifndef IVAS_FLOAT_FIXED
            inputSba->hoaDecMtx[chInIdx][chOutIdx] = *readPtr++;
#else
            inputSba->hoaDecMtx_fx[chInIdx][chOutIdx] = ( ( *readPtr ) == ONE_IN_Q29 ) ? ONE_IN_Q31 : *readPtr << 2;
            inputSba->hoaDecMtx[chInIdx][chOutIdx] = ( (float) *readPtr++ ) / ONE_IN_Q29;
#endif
        }
    }
#ifdef IVAS_FLOAT_FIXED
    for ( chOutIdx = 0; chOutIdx < MAX_OUTPUT_CHANNELS; ++chOutIdx )
    {
        for ( chInIdx = 0; chInIdx < MAX_INPUT_CHANNELS; ++chInIdx )
        {
            inputSba->hoaDecMtx_fx[chInIdx][chOutIdx] = (Word32)(inputSba->hoaDecMtx[chInIdx][chOutIdx] * ONE_IN_Q31);
        }
    }
#endif
    free( tmpDecMtx );

    return IVAS_ERR_OK;
}

#ifdef IVAS_FLOAT_FIXED
static ivas_error initSbaPanGainsForSbaOut(
    input_sba *inputSba,
    const AUDIO_CONFIG outConfig )
{
    ivas_error error;
    error = IVAS_ERR_OK;

    if ( getAudioConfigType( outConfig ) != IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS )
    {
        assert( !"Invalid configuration" );
        return IVAS_ERR_WRONG_PARAMS;
    }

    fillIdentityPanMatrix_fx( inputSba->hoaDecMtx_fx );

    return error;
}
#else
static ivas_error initSbaPanGainsForSbaOut(
    input_sba *inputSba,
    const AUDIO_CONFIG outConfig )
@@ -2786,8 +2822,76 @@ static ivas_error initSbaPanGainsForSbaOut(

    return error;
}
#endif
#ifdef IVAS_FLOAT_FIXED
static ivas_error updateSbaPanGains(
    input_sba *inputSba,
    const AUDIO_CONFIG outConfig,
    RENDER_CONFIG_DATA *hRendCfg )
{
    ivas_error error;
    AUDIO_CONFIG inConfig;
    rendering_context rendCtx;

    /* Reset to all zeros - some functions below only write non-zero elements. */
    setZeroPanMatrix( inputSba->hoaDecMtx );
    setZeroPanMatrix_fx( inputSba->hoaDecMtx_fx );

    inConfig = inputSba->base.inConfig;
    rendCtx = inputSba->base.ctx;

    switch ( getAudioConfigType( outConfig ) )
    {
        case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED:
            error = initSbaPanGainsForMcOut( inputSba, outConfig, inputSba->base.ctx.pCustomLsOut );
            break;
        case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS:
            error = initSbaPanGainsForSbaOut( inputSba, outConfig );
            break;
        case IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL:
            switch ( outConfig )
            {
                case IVAS_AUDIO_CONFIG_BINAURAL:
                {
                    if ( ( error = ivas_rend_openCrend( &inputSba->crendWrapper, inConfig, outConfig, hRendCfg, NULL, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK )

                    {
                        return error;
                    }
                }
                break;
                case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR:
                case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB:
                    if ( ( error = initSbaPanGainsForMcOut( inputSba, IVAS_AUDIO_CONFIG_7_1_4, NULL ) ) != IVAS_ERR_OK )
                    {
                        return error;
                    }

                    if ( ( error = ivas_rend_openCrend( &inputSba->crendWrapper, IVAS_AUDIO_CONFIG_7_1_4, outConfig, hRendCfg, NULL, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK )
                    {
                        return error;
                    }
                    break;
                default:
                    return IVAS_ERR_INVALID_OUTPUT_FORMAT;
            }
            break;
        case IVAS_REND_AUDIO_CONFIG_TYPE_MASA:
            error = IVAS_ERR_OK;
            break; /* Do nothing */
        default:
            return IVAS_ERR_INVALID_OUTPUT_FORMAT;
    }

    /* Check error here to keep switch statement more compact */
    if ( error != IVAS_ERR_OK )
    {
        return error;
    }

    return IVAS_ERR_OK;
}
#else
static ivas_error updateSbaPanGains(
    input_sba *inputSba,
    const AUDIO_CONFIG outConfig,
@@ -2854,7 +2958,7 @@ static ivas_error updateSbaPanGains(

    return IVAS_ERR_OK;
}

#endif

static ivas_error initSbaMasaRendering(
    input_sba *inputSba,
@@ -5119,8 +5223,8 @@ static void renderBufferChannelLerp_fx(
                    *outSmpl = L_add( Mpy_32_32( currentGain, ( *inSmpl ) ), *outSmpl );
                    ++outSmpl;
                    ++inSmpl;

                } WHILE ( inSmpl != lastInSmpl );
                }
                WHILE( inSmpl != lastInSmpl );
            }
            ELSE
            {
@@ -5153,7 +5257,8 @@ static void renderBufferChannelLerp_fx(
                    ++outSmpl;
                    ++inSmpl;
                    ++i;
                } WHILE ( inSmpl != lastInSmpl );
                }
                WHILE( inSmpl != lastInSmpl );
            }
        }
    }
@@ -6258,7 +6363,35 @@ static ivas_error renderInputIsm(
    return error;
}

#ifdef IVAS_FLOAT_FIXED
static ivas_error renderActiveInputsIsm(
    IVAS_REND_HANDLE hIvasRend,
    IVAS_REND_AudioBuffer outAudio )
{
    int16_t i;
    input_ism *pCurrentInput;
    ivas_error error;

    for ( i = 0, pCurrentInput = hIvasRend->inputsIsm; i < RENDERER_MAX_ISM_INPUTS; ++i, ++pCurrentInput )
    {
        if ( pCurrentInput->base.inConfig == IVAS_AUDIO_CONFIG_INVALID )
        {
            /* Skip inactive inputs */
            continue;
        }

        if ( ( error = renderInputIsm( pCurrentInput, hIvasRend->outputConfig, outAudio ) ) != IVAS_ERR_OK )
        {
            return error;
        }
    }
    for ( i = 0; i < outAudio.config.numSamplesPerChannel * outAudio.config.numChannels; ++i )
    {
        outAudio.data_fx[i] = (Word32) ( outAudio.data[i] * ( 1 << (*outAudio.pq_fact-1) ) );
    }
    return IVAS_ERR_OK;
}
#else
static ivas_error renderActiveInputsIsm(
    IVAS_REND_HANDLE hIvasRend,
    IVAS_REND_AudioBuffer outAudio )
@@ -6283,7 +6416,7 @@ static ivas_error renderActiveInputsIsm(

    return IVAS_ERR_OK;
}

#endif

static ivas_error renderLfeToBinaural(
    const input_mc *mcInput,
@@ -7208,7 +7341,35 @@ static ivas_error renderInputMc(
    return error;
}

#ifdef IVAS_FLOAT_FIXED
static ivas_error renderActiveInputsMc(
    IVAS_REND_HANDLE hIvasRend,
    IVAS_REND_AudioBuffer outAudio )
{
    int16_t i;
    input_mc *pCurrentInput;
    ivas_error error;

    for ( i = 0, pCurrentInput = hIvasRend->inputsMc; i < RENDERER_MAX_MC_INPUTS; ++i, ++pCurrentInput )
    {
        if ( pCurrentInput->base.inConfig == IVAS_AUDIO_CONFIG_INVALID )
        {
            /* Skip inactive inputs */
            continue;
        }

        if ( ( error = renderInputMc( pCurrentInput, hIvasRend->outputConfig, outAudio ) ) != IVAS_ERR_OK )
        {
            return error;
        }
    }
    for ( i = 0; i < outAudio.config.numSamplesPerChannel * outAudio.config.numChannels; ++i )
    {
        outAudio.data_fx[i] = (Word32) ( outAudio.data[i] * ( 1 << ( *outAudio.pq_fact - 1 ) ) );// to make the output buffer Q same as input when it reaches renderActiveInputsSba
    }
    return IVAS_ERR_OK;
}
#else
static ivas_error renderActiveInputsMc(
    IVAS_REND_HANDLE hIvasRend,
    IVAS_REND_AudioBuffer outAudio )
@@ -7233,8 +7394,47 @@ static ivas_error renderActiveInputsMc(

    return IVAS_ERR_OK;
}
#endif
#ifdef IVAS_FLOAT_FIXED
static void renderSbaToMc(
    const input_sba *sbaInput,
    IVAS_REND_AudioBuffer outAudio )
{
    Word16 i;
    IVAS_REND_AudioBuffer inAudio;

    push_wmops( "renderSbaToMc" );
    inAudio = sbaInput->base.inputBuffer;

    FOR ( i = 0; i < inAudio.config.numChannels; ++i )
    {
        renderBufferChannel_fx( inAudio, i, sbaInput->hoaDecMtx_fx[i], outAudio );
    }

    pop_wmops();
    return;
}


static void renderSbaToSba(
    const input_sba *sbaInput,
    IVAS_REND_AudioBuffer outAudio )
{
    Word16 i;
    IVAS_REND_AudioBuffer inAudio;

    push_wmops( "renderSbaToSba" );
    inAudio = sbaInput->base.inputBuffer;

    FOR ( i = 0; i < inAudio.config.numChannels; ++i )
    {
        renderBufferChannel_fx( inAudio, i, sbaInput->hoaDecMtx_fx[i], outAudio );
    }

    pop_wmops();
    return;
}
#else
static void renderSbaToMc(
    const input_sba *sbaInput,
    IVAS_REND_AudioBuffer outAudio )
@@ -7273,7 +7473,7 @@ static void renderSbaToSba(
    pop_wmops();
    return;
}

#endif
#ifdef IVAS_FLOAT_FIXED
static ivas_error renderSbaToBinaural(
    input_sba *sbaInput,
@@ -7494,7 +7694,6 @@ static ivas_error renderSbaToBinauralRoom(
        {
            return error;
        }
       
    }

    /* intermediate rendering to 7_1_4 */
@@ -8339,7 +8538,6 @@ static ivas_error getSamplesInternal(
    {
        return error;
    }

    if ( ( error = renderActiveInputsMc( hIvasRend, outAudio ) ) != IVAS_ERR_OK )
    {
        return error;
@@ -8353,7 +8551,7 @@ static ivas_error getSamplesInternal(
        return error;
    }

    if ( ( hIvasRend->inputsSba[0].base.inConfig != IVAS_AUDIO_CONFIG_INVALID ) && ( getAudioConfigType( hIvasRend->outputConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL ) )
    if ( ( ( hIvasRend->inputsSba[0].base.inConfig != IVAS_AUDIO_CONFIG_INVALID ) && ( ( getAudioConfigType( hIvasRend->outputConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL ) || ( getAudioConfigType( hIvasRend->outputConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) || ( getAudioConfigType( hIvasRend->outputConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) ) ) )
    {

#ifndef DISABLE_LIMITER
@@ -9040,7 +9238,8 @@ static ivas_error ivas_masa_ext_rend_parambin_init(
    Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX];
    ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, nBins );

    for (int i = 0; i < nBins; i++) {
    for ( int i = 0; i < nBins; i++ )
    {
        frequency_axis[i] = frequency_axis_fx[i];
    }
#else