Commit 1246130b authored by vaclav's avatar vaclav
Browse files

simplify APA buffer handling

parent e67fa63e
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -806,8 +806,12 @@ void ivas_apply_non_diegetic_panning(
 *----------------------------------------------------------------------------------*/

ivas_error ivas_jbm_dec_tc(
#ifdef LIB_DEC_REVISION
    Decoder_Struct *st_ivas                                     /* i/o: IVAS decoder structure                                      */
#else
    Decoder_Struct *st_ivas,                                    /* i/o: IVAS decoder structure                                      */
    float *data                                                 /* o  : output synthesis signals                                    */
#endif
);

ivas_error ivas_jbm_dec_render(
+9 −0
Original line number Diff line number Diff line
@@ -66,8 +66,12 @@ static void ivas_jbm_masa_sf_to_slot_map( Decoder_Struct *st_ivas, const int16_t
 *--------------------------------------------------------------------------*/

ivas_error ivas_jbm_dec_tc(
#ifdef LIB_DEC_REVISION
    Decoder_Struct *st_ivas /* i/o: IVAS decoder structure         */
#else
    Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure         */
    float *data              /* o  : transport channel signals      */
#endif
)
{
    int16_t n, output_frame, nchan_out;
@@ -727,11 +731,16 @@ ivas_error ivas_jbm_dec_tc(
     * Write IVAS transport channels
     *----------------------------------------------------------------*/

#ifdef LIB_DEC_REVISION
    if ( st_ivas->hDecoderConfig->Opt_tsm == 0 )
#else
    if ( st_ivas->hDecoderConfig->Opt_tsm == 1 )
    {

        ivas_syn_output_f( p_output, output_frame, st_ivas->hTcBuffer->nchan_transport_jbm, data );
    }
    else
#endif
    {
        /* directly copy to tc buffers */
        ivas_jbm_dec_copy_tc_no_tsm( st_ivas, p_output, output_frame );
+43 −38
Original line number Diff line number Diff line
@@ -121,7 +121,7 @@ static void IVAS_DEC_Close_VoIP( IVAS_DEC_VOIP *hVoIP );
static void store_JbmData( IVAS_DEC_VOIP *hVoIP, JB4_DATAUNIT_HANDLE dataUnit, const uint32_t systemTimestamp_ms, const uint16_t extBufferedSamples, const int32_t output_Fs );
#endif
#ifdef LIB_DEC_REVISION
static ivas_error evs_dec_main( Decoder_Struct *st_ivas, float *floatBuf, int16_t *pcmBuf );
static ivas_error evs_dec_main( Decoder_Struct *st_ivas );
#else
static ivas_error evs_dec_main( Decoder_Struct *st_ivas, const int16_t nOutSamples, float *floatBuf, int16_t *pcmBuf );
#endif
@@ -1303,14 +1303,14 @@ ivas_error IVAS_DEC_GetSamplesDecoder(

        if ( hIvasDec->mode == IVAS_DEC_MODE_EVS )
        {
            if ( ( error = evs_dec_main( st_ivas, hIvasDec->apaExecBuffer, NULL ) ) != IVAS_ERR_OK )
            if ( ( error = evs_dec_main( st_ivas ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }
        else if ( hIvasDec->mode == IVAS_DEC_MODE_IVAS )
        {
            if ( ( error = ivas_jbm_dec_tc( st_ivas, hIvasDec->apaExecBuffer ) ) != IVAS_ERR_OK )
            if ( ( error = ivas_jbm_dec_tc( st_ivas ) ) != IVAS_ERR_OK )
            {
                return error;
            }
@@ -1351,6 +1351,10 @@ ivas_error IVAS_DEC_GetSamplesDecoder(
                return IVAS_ERR_UNKNOWN;
            }

#ifdef LIB_DEC_REVISION
            ivas_syn_output_f( hIvasDec->st_ivas->p_output_f, hIvasDec->nSamplesFrame, nTransportChannels, hIvasDec->apaExecBuffer );

#endif
            if ( apa_exec( hIvasDec->hTimeScaler, hIvasDec->apaExecBuffer, hIvasDec->nSamplesFrame * nTransportChannels, (uint16_t) hIvasDec->tsm_max_scaling, hIvasDec->apaExecBuffer, &nTimeScalerOutSamples ) != 0 )
            {
                return IVAS_ERR_UNKNOWN;
@@ -2364,25 +2368,6 @@ static ivas_error IVAS_DEC_Setup(
        }
    }

#ifdef LIB_DEC_REVISION
    /* allocate/reallocate APA buffer */
    // ToDo: this memory should be harmonized with st_ivas->p_output_f[] and st_ivas->hTcBuffer->tc_buffer[] - see issue #916
    // ToDo: this part is also related to cleaning of NONBE_UNIFIED_DECODING_PATHS leftovers (see MR !1246)
    if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && *nTransportChannels != hIvasDec->nTransportChannelsOld )
    {
        if ( hIvasDec->apaExecBuffer != NULL )
        {
            free( hIvasDec->apaExecBuffer );
        }

        if ( ( hIvasDec->apaExecBuffer = malloc( sizeof( float ) * APA_BUF_PER_CHANNEL * *nTransportChannels ) ) == NULL )
        {
            return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" );
        }
        set_zero( hIvasDec->apaExecBuffer, APA_BUF_PER_CHANNEL * *nTransportChannels );
    }

#endif
    return IVAS_ERR_OK;
}

@@ -4610,24 +4595,32 @@ void IVAS_DEC_PrintDisclaimer( void )
 *---------------------------------------------------------------------*/

static ivas_error evs_dec_main(
#ifdef LIB_DEC_REVISION
    Decoder_Struct *st_ivas /* i  : IVAS decoder structure      */
#else
    Decoder_Struct *st_ivas,
#ifndef LIB_DEC_REVISION
    const int16_t nOutSamples,
#endif
    float *floatBuf,
    int16_t *pcmBuf )
    int16_t *pcmBuf
#endif

)
{
    DEC_CORE_HANDLE *hCoreCoder;
    float mixer_left, mixer_rigth;
    float *p_output[MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN];
    int16_t ch;
#ifdef LIB_DEC_REVISION
    int16_t nOutSamples;
    int16_t ch, nOutSamples;
#else
    int16_t ch;
#endif
    ivas_error error;

    hCoreCoder = st_ivas->hSCE[0]->hCoreCoder;
    hCoreCoder[0]->total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
#ifdef LIB_DEC_REVISION
    nOutSamples = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC );
#endif

    mdct_switching_dec( hCoreCoder[0] );

@@ -4680,10 +4673,6 @@ static ivas_error evs_dec_main(
    }

    st_ivas->BER_detect = hCoreCoder[0]->BER_detect;
#ifdef LIB_DEC_REVISION

    nOutSamples = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC );
#endif

    if ( st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX )
    {
@@ -4693,6 +4682,23 @@ static ivas_error evs_dec_main(
        v_multc( p_output[0], mixer_left, p_output[0], nOutSamples );
    }

#ifdef LIB_DEC_REVISION
    if ( st_ivas->hDecoderConfig->Opt_tsm )
    {
        /* BE workaround: in order to keep EVS bit-exact wrt. TS 26.443, convert 'float' output data to 'short' before the TSM */
        int16_t pcm_buf_local[L_FRAME48k];

        for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
        {
#ifdef DEBUGGING
            st_ivas->noClipping +=
#endif
                ivas_syn_output( &p_output[ch], nOutSamples, 1, pcm_buf_local );

            mvs2r( pcm_buf_local, p_output[ch], nOutSamples );
        }
    }
#else
    if ( !st_ivas->hDecoderConfig->Opt_tsm )
    {
        ivas_jbm_dec_copy_tc_no_tsm( st_ivas, p_output, nOutSamples );
@@ -4717,6 +4723,7 @@ static ivas_error evs_dec_main(
#endif
            ivas_syn_output( p_output, nOutSamples, st_ivas->hDecoderConfig->nchan_out, pcmBuf );
    }
#endif

    return IVAS_ERR_OK;
}
@@ -4937,6 +4944,7 @@ static ivas_error IVAS_DEC_VoIP_reconfigure(
    const uint16_t l_ts )
#endif
{
    int16_t apa_buffer_size;
#ifdef LIB_DEC_REVISION
    uint16_t l_ts;

@@ -4944,8 +4952,6 @@ static ivas_error IVAS_DEC_VoIP_reconfigure(

    if ( isInitialized_voip == false )
#else
    int16_t apa_buffer_size;

    apa_buffer_size = hIvasDec->nSamplesFrame;

    if ( hIvasDec->apaExecBuffer == NULL )
@@ -4961,9 +4967,7 @@ static ivas_error IVAS_DEC_VoIP_reconfigure(
            float startQuality;

            startQuality = hIvasDec->tsm_quality;
#ifndef LIB_DEC_REVISION
            apa_buffer_size = APA_BUF_PER_CHANNEL;
#endif

            /* get current renderer type*/
            hDecoderConfig = hIvasDec->st_ivas->hDecoderConfig;
@@ -5009,14 +5013,13 @@ static ivas_error IVAS_DEC_VoIP_reconfigure(
                    return IVAS_ERR_INIT_ERROR;
                }
            }
#ifndef LIB_DEC_REVISION

            if ( ( hIvasDec->apaExecBuffer = malloc( sizeof( float ) * apa_buffer_size * nTransportChannels ) ) == NULL )
            {
                return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" );
            }

            set_zero( hIvasDec->apaExecBuffer, apa_buffer_size * nTransportChannels );
#ifndef LIB_DEC_REVISION
        }
#endif
    }
@@ -5030,7 +5033,8 @@ static ivas_error IVAS_DEC_VoIP_reconfigure(
            {
                return IVAS_ERR_INIT_ERROR;
            }
#ifndef LIB_DEC_REVISION

            /* realloc apa_exe_buffer */
            apa_buffer_size = APA_BUF_PER_CHANNEL;
            free( hIvasDec->apaExecBuffer );
            if ( ( hIvasDec->apaExecBuffer = malloc( sizeof( float ) * apa_buffer_size * nTransportChannels ) ) == NULL )
@@ -5038,6 +5042,7 @@ static ivas_error IVAS_DEC_VoIP_reconfigure(
                return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" );
            }
            set_zero( hIvasDec->apaExecBuffer, apa_buffer_size * nTransportChannels );
#ifndef LIB_DEC_REVISION
        }
        /* realloc apa_exe_buffer */
#endif