Commit 1f51477b authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

[opt] only allocate the delay ring buffer if needed + fix typo

parent ce28c851
Loading
Loading
Loading
Loading
Loading
+38 −23
Original line number Diff line number Diff line
@@ -1470,26 +1470,30 @@ static ivas_error alignInputDelay(
    input_ism *inputIsm;
    int16_t maxGlobalDelaySamples;
    int32_t numSamplesToPush, numSamplesToPop;
    uint32_t tmpSize;
    uint32_t ringBufferSize, preDelay;

    maxGlobalDelaySamples = latencyNsToSamples( sampleRateOut, maxGlobalDelayNs );
    maxGlobalDelaySamples *= cldfb2tdSampleFact;

    /* open the delay buffer if it isn't already */
    /* check if we need to open the delay buffer */
    if ( inputBase->delayBuffer == NULL )
    {
        /* buffer has to accomodate maxGlobalDelaySamples + 2 * frameSize */
        tmpSize = maxGlobalDelaySamples;
        tmpSize += 2 * inputAudio.config.numSamplesPerChannel;
        if ( ( error = ivas_TD_RINGBUF_Open( &inputBase->delayBuffer, tmpSize, inputAudio.config.numChannels ) ) != IVAS_ERR_OK )
        ringBufferSize = maxGlobalDelaySamples + 2 * inputAudio.config.numSamplesPerChannel;

        /* pre delay for this input is maximum delay - input delay */
        preDelay = maxGlobalDelaySamples - inputBase->delayNumSamples * cldfb2tdSampleFact;

        if ( preDelay > 0 )
        {
            if ( ( error = ivas_TD_RINGBUF_Open( &inputBase->delayBuffer, ringBufferSize, inputAudio.config.numChannels ) ) != IVAS_ERR_OK )
            {
                return error;
            }

            /* for the first frame we need to push zeros to align the input delay to the global delay
             * and then push a frame of actual data */
        tmpSize = maxGlobalDelaySamples - inputBase->delayNumSamples * cldfb2tdSampleFact;
        ivas_TD_RINGBUF_PushZeros( inputBase->delayBuffer, tmpSize );
            ivas_TD_RINGBUF_PushZeros( inputBase->delayBuffer, preDelay );

            /* for ISM inputs, ensure the metadata sync delay is updated */
            if ( getAudioConfigType( inputBase->inConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED )
@@ -1498,7 +1502,10 @@ static ivas_error alignInputDelay(
                inputIsm->ism_metadata_delay_ms = maxGlobalDelayNs / 1e6f;
            }
        }
    }

    if ( inputBase->delayBuffer != NULL )
    {
        /* push in the new input data and pop to retrieve a complete input frame
         * if we are flushing the inputs, we don't push in any new data */
        numSamplesToPush = flushInputs ? 0 : inputAudio.config.numSamplesPerChannel;
@@ -1506,6 +1513,14 @@ static ivas_error alignInputDelay(

        ivas_TD_RINGBUF_Push( inputBase->delayBuffer, inputAudio.data, numSamplesToPush );
        ivas_TD_RINGBUF_Pop( inputBase->delayBuffer, inputBase->inputBuffer.data, numSamplesToPop );
    }
    else
    {
        /* delay buffer isn't open - we don't need it */
        mvr2r( inputAudio.data,
               inputBase->inputBuffer.data,
               inputAudio.config.numSamplesPerChannel * inputAudio.config.numChannels );
    }

    return IVAS_ERR_OK;
}
@@ -3715,7 +3730,7 @@ static ivas_error isar_pre_rend_init(
        return IVAS_ERR_OK;
    }

    /* these function should only be called once during initial allocation */
    /* these functions should only be called once during initial allocation */
    if ( pSplitRendEncBuffer->data == NULL )
    {
        if ( pSplit_rend_config->poseCorrectionMode == ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB )