Commit fe8a2eb7 authored by TYAGIRIS's avatar TYAGIRIS
Browse files

renderer static mem opt

parent ad1223e5
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -153,6 +153,8 @@

#define SBA2MONO                                        /* FhG: Issue 365: Adapt processing of SBA mono output to be in line with stereo output (less delay, lower complexity) */

#define REND_STATIC_MEM_OPT

/* ################## End DEVELOPMENT switches ######################### */
/* clang-format on */
#endif
+120 −13
Original line number Diff line number Diff line
@@ -103,7 +103,9 @@ typedef struct
    IVAS_REND_AudioConfig inConfig;
    IVAS_REND_InputId id;
    IVAS_REND_AudioBuffer inputBuffer;
#ifndef REND_STATIC_MEM_OPT
    float bufferData[MAX_BUFFER_LENGTH];
#endif
    float gain; /* Linear, not in dB */
    rendering_context ctx;
    int32_t numNewSamplesPerChannel; /* Used to keep track how much new audio was fed before rendering current frame */
@@ -979,11 +981,39 @@ static void initRotGains(
    return;
}

#ifdef REND_STATIC_MEM_OPT
static ivas_error allocateInputBaseBufferData( float **data )
{
    *data = (float *) malloc( MAX_BUFFER_LENGTH * sizeof( float ) );
    if ( *data == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for input base buffer data" );
    }

    return IVAS_ERR_OK;
}
static void freeInputBaseBufferData( float **data )
{
    if ( *data != NULL )
    {
        free( *data );
        *data = NULL;
    }

    return;
}
#endif

static void initRendInputBase(
    input_base *inputBase,
    const IVAS_REND_AudioConfig inConfig,
    const IVAS_REND_InputId id,
    const rendering_context rendCtx )
    const rendering_context rendCtx
#ifdef REND_STATIC_MEM_OPT
    ,
    const int16_t data_buf_size
#endif
)
{
    inputBase->inConfig = inConfig;
    inputBase->id = id;
@@ -993,9 +1023,24 @@ static void initRendInputBase(

    inputBase->inputBuffer.config.numSamplesPerChannel = 0;
    inputBase->inputBuffer.config.numChannels = 0;
#ifndef REND_STATIC_MEM_OPT
    inputBase->inputBuffer.data = inputBase->bufferData;

    set_zero( inputBase->bufferData, MAX_BUFFER_LENGTH );
#else
    if ( data_buf_size < 0 )
    {
        inputBase->inputBuffer.data = NULL;
    }
    else
    {
        freeInputBaseBufferData( &inputBase->inputBuffer.data );
        if ( data_buf_size > 0 )
        {
            allocateInputBaseBufferData( &inputBase->inputBuffer.data );
        }
    }
#endif

    return;
}
@@ -1090,7 +1135,12 @@ static ivas_error setRendInputActiveIsm(
        return IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED;
    }

    initRendInputBase( &inputIsm->base, inConfig, id, rendCtx );
    initRendInputBase( &inputIsm->base, inConfig, id, rendCtx
#ifdef REND_STATIC_MEM_OPT
                       ,
                       MAX_BUFFER_LENGTH
#endif
    );

    inputIsm->currentPos = defaultObjectPosition();
    inputIsm->previousPos = defaultObjectPosition();
@@ -1141,7 +1191,12 @@ static void clearInputIsm(

    rendCtx = inputIsm->base.ctx;

    initRendInputBase( &inputIsm->base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, rendCtx );
    initRendInputBase( &inputIsm->base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, rendCtx
#ifdef REND_STATIC_MEM_OPT
                       ,
                       0
#endif
    );

    /* Free input's internal handles */

@@ -1928,7 +1983,13 @@ static ivas_error setRendInputActiveMc(
        return IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED;
    }

    initRendInputBase( &inputMc->base, inConfig, id, rendCtx );
    initRendInputBase( &inputMc->base, inConfig, id, rendCtx
#ifdef REND_STATIC_MEM_OPT
                       ,
                       MAX_BUFFER_LENGTH
#endif
    );

    setZeroPanMatrix( inputMc->panGains );
    inputMc->customLsInput = defaultCustomLs();
    inputMc->tdRendWrapper = defaultTdRendWrapper();
@@ -1960,7 +2021,12 @@ static void clearInputMc(

    rendCtx = inputMc->base.ctx;

    initRendInputBase( &inputMc->base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, rendCtx );
    initRendInputBase( &inputMc->base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, rendCtx
#ifdef REND_STATIC_MEM_OPT
                       ,
                       0
#endif
    );

    /* Free input's internal handles */
    if ( inputMc->efapInWrapper.hEfap != NULL )
@@ -2152,7 +2218,13 @@ static ivas_error setRendInputActiveSba(
        return IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED;
    }

    initRendInputBase( &inputSba->base, inConfig, id, rendCtx );
    initRendInputBase( &inputSba->base, inConfig, id, rendCtx
#ifdef REND_STATIC_MEM_OPT
                       ,
                       MAX_BUFFER_LENGTH
#endif
    );

    setZeroPanMatrix( inputSba->hoaDecMtx );
    inputSba->crendWrapper = NULL;
    initRotGains( inputSba->rot_gains_prev );
@@ -2172,7 +2244,12 @@ static void clearInputSba(

    rendCtx = inputSba->base.ctx;

    initRendInputBase( &inputSba->base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, rendCtx );
    initRendInputBase( &inputSba->base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, rendCtx
#ifdef REND_STATIC_MEM_OPT
                       ,
                       0
#endif
    );

    /* Free input's internal handles */
    ivas_rend_closeCrend( &inputSba->crendWrapper );
@@ -2518,7 +2595,12 @@ static ivas_error setRendInputActiveMasa(
        return IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED;
    }

    initRendInputBase( &inputMasa->base, inConfig, id, rendCtx );
    initRendInputBase( &inputMasa->base, inConfig, id, rendCtx
#ifdef REND_STATIC_MEM_OPT
                       ,
                       MAX_BUFFER_LENGTH
#endif
    );

    if ( ( error = getAudioConfigNumChannels( inConfig, &numInChannels ) ) != IVAS_ERR_OK )
    {
@@ -2611,7 +2693,12 @@ static void clearInputMasa(

    rendCtx = inputMasa->base.ctx;

    initRendInputBase( &inputMasa->base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, rendCtx );
    initRendInputBase( &inputMasa->base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, rendCtx
#ifdef REND_STATIC_MEM_OPT
                       ,
                       0
#endif
    );
    freeDecoderDummy( &inputMasa->decDummy );

    return;
@@ -2686,7 +2773,12 @@ ivas_error IVAS_REND_Open(
    /* Initialize inputs */
    for ( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i )
    {
        initRendInputBase( &hIvasRend->inputsIsm[i].base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, getRendCtx( hIvasRend ) );
        initRendInputBase( &hIvasRend->inputsIsm[i].base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, getRendCtx( hIvasRend )
#ifdef REND_STATIC_MEM_OPT
                                                                                                 ,
                           -1
#endif
        );
        hIvasRend->inputsIsm[i].crendWrapper = NULL;
        hIvasRend->inputsIsm[i].hReverb = NULL;
        hIvasRend->inputsIsm[i].tdRendWrapper.hBinRendererTd = NULL;
@@ -2694,7 +2786,12 @@ ivas_error IVAS_REND_Open(

    for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i )
    {
        initRendInputBase( &hIvasRend->inputsMc[i].base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, getRendCtx( hIvasRend ) );
        initRendInputBase( &hIvasRend->inputsMc[i].base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, getRendCtx( hIvasRend )
#ifdef REND_STATIC_MEM_OPT
                                                                                                ,
                           -1
#endif
        );
        hIvasRend->inputsMc[i].efapInWrapper.hEfap = NULL;
        hIvasRend->inputsMc[i].crendWrapper = NULL;
        hIvasRend->inputsMc[i].hReverb = NULL;
@@ -2703,13 +2800,23 @@ ivas_error IVAS_REND_Open(

    for ( i = 0; i < RENDERER_MAX_SBA_INPUTS; ++i )
    {
        initRendInputBase( &hIvasRend->inputsSba[i].base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, getRendCtx( hIvasRend ) );
        initRendInputBase( &hIvasRend->inputsSba[i].base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, getRendCtx( hIvasRend )
#ifdef REND_STATIC_MEM_OPT
                                                                                                 ,
                           -1
#endif
        );
        hIvasRend->inputsSba[i].crendWrapper = NULL;
    }

    for ( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i )
    {
        initRendInputBase( &hIvasRend->inputsMasa[i].base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, getRendCtx( hIvasRend ) );
        initRendInputBase( &hIvasRend->inputsMasa[i].base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, getRendCtx( hIvasRend )
#ifdef REND_STATIC_MEM_OPT
                                                                                                  ,
                           -1
#endif
        );
        hIvasRend->inputsMasa[i].decDummy = NULL;
        hIvasRend->inputsMasa[i].metadataHasBeenFed = false;
    }