Commit 687751da authored by vaclav's avatar vaclav
Browse files

port MR, part 3

parent 164a7c9d
Loading
Loading
Loading
Loading
+217 −150
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ struct IVAS_DEC
    Word16 prev_ft_speech;     /* RXDTX handler: previous frametype flag for  G.192 format AMRWB SID_FIRST detection */
    Word16 CNG;                /* RXDTX handler: CNG=1, nonCNG=0 */

    uint16_t nSamplesFlushed;
    UWord16 nSamplesFlushed;
    void *flushbuffer;
    bool hasBeenPreparedRendering;
};
@@ -128,16 +128,16 @@ static ivas_error evs_dec_main_fx( Decoder_Struct *st_ivas, const Word16 nOutSam
static ivas_error input_format_API_to_internal( IVAS_DEC_INPUT_FORMAT input_format, Word16 *bitstream_format_internal, Word16 *sdp_hf_only, const bool is_voip_enabled );
static void init_decoder_config( DECODER_CONFIG_HANDLE hDecoderConfig );
#ifdef LIB_DEC_REVISION
static ivas_error ivas_dec_setup_all_fx( IVAS_DEC_HANDLE hIvasDec, uint8_t *nTransportChannels, const int16_t isSplitRend, ISAR_SPLIT_REND_BITS_DATA *splitRendBits );
static ivas_error apa_setup_fx( IVAS_DEC_HANDLE hIvasDec, const bool isInitialized_voip, const uint16_t nTransportChannels );
static ivas_error ivas_dec_setup_all_fx( IVAS_DEC_HANDLE hIvasDec, UWord8 *nTransportChannels, const Word16 isSplitRend, ISAR_SPLIT_REND_BITS_DATA *splitRendBits );
static ivas_error apa_setup_fx( IVAS_DEC_HANDLE hIvasDec, const bool isInitialized_voip, const UWord16 nTransportChannels );
#else
static ivas_error IVAS_DEC_VoIP_reconfigure( IVAS_DEC_HANDLE hIvasDec, const UWord16 nTransportChannels, const UWord16 l_ts );
static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, UWord16 *nTcBufferGranularity, UWord8 *nTransportChannels, UWord8 *nOutChannels, UWord16 *nSamplesRendered, Word16 *data );
#endif
static ivas_error IVAS_DEC_GetTcSamples( IVAS_DEC_HANDLE hIvasDec, Word32 *pcmBuf_fx, Word16 *nOutSamples );
static ivas_error IVAS_DEC_RendererFeedTcSamples( IVAS_DEC_HANDLE hIvasDec, const Word16 nSamplesForRendering, Word16 *nSamplesResidual, Word32 *pcmBuf );
static ivas_error IVAS_DEC_GetRenderedSamples( IVAS_DEC_HANDLE hIvasDec, const UWord16 nSamplesForRendering, UWord16 *nSamplesRendered, UWord16 *nSamplesAvailableNext, Word16 *pcmBuf );
static ivas_error IVAS_DEC_GetBufferedNumberOfSamples( IVAS_DEC_HANDLE hIvasDec, Word16 *nSamplesBuffered );
#endif
static Word16 get_render_frame_size_ms( IVAS_RENDER_FRAMESIZE render_framesize );
static void update_voip_rendered20ms( IVAS_DEC_HANDLE hIvasDec, const Word16 nSamplesRendered );
static ivas_error isar_set_split_rend_setup( ISAR_DEC_SPLIT_REND_WRAPPER *hSplitBinRend, const ISAR_SPLIT_REND_CONFIG_DATA *hSplitBinConfig, const COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, ISAR_SPLIT_REND_BITS_DATA *splitRendBits );
@@ -187,7 +187,9 @@ ivas_error IVAS_DEC_Open(
    hIvasDec->needNewFrame = false;
    hIvasDec->nTransportChannelsOld = 0;
    hIvasDec->nSamplesAvailableNext = 0;
#ifndef LIB_DEC_REVISION
    hIvasDec->nSamplesRendered = 0;
#endif
    hIvasDec->nSamplesFrame = 0;
    hIvasDec->hasBeenFedFrame = false;
    hIvasDec->hasBeenFedFirstGoodFrame = false;
@@ -212,15 +214,17 @@ ivas_error IVAS_DEC_Open(
    move16();

    hIvasDec->bitstreamformat = G192;
    move16();
#ifdef DEBUGGING
    hIvasDec->Opt_VOIP = 0;
    move16();
#endif
    hIvasDec->amrwb_rfc4867_flag = -1;
    hIvasDec->prev_ft_speech = 1; /* RXDTX handler previous frametype flag for G.192 format AMRWB SID_FIRST detection */
    hIvasDec->CNG = 0;            /* RXDTX handler CNG = 1, no CNG = 0*/
    move16();
    move16();
    move16();
    move16();
    move16();

    /*-----------------------------------------------------------------*
     * Initialize IVAS-codec decoder state
@@ -485,13 +489,13 @@ static ivas_error create_flush_buffer(
    IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle            */
)
{
    hIvasDec->flushbuffer = (void *) malloc( CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( int16_t ) );
    hIvasDec->flushbuffer = (void *) malloc( CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word16 ) );
    if ( hIvasDec->flushbuffer == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate JBM flush buffer" );
    }

    set_s( (int16_t *) hIvasDec->flushbuffer, 0, CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES );
    set16_fx( (Word16 *) hIvasDec->flushbuffer, 0, CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES );

    return IVAS_ERR_OK;
}
@@ -703,7 +707,9 @@ ivas_error IVAS_DEC_Configure(

    hIvasDec->nSamplesFrame = (UWord16) Mpy_32_16_1( hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 );
    hIvasDec->nSamplesAvailableNext = 0;
#ifndef LIB_DEC_REVISION
    hIvasDec->nSamplesRendered = 0;
#endif
    hIvasDec->tsm_scale = 100;
    hIvasDec->tsm_max_scaling = 0;
    hIvasDec->tsm_quality = ONE_IN_Q14 /*1.0f Q14*/;
@@ -1187,7 +1193,7 @@ ivas_error IVAS_DEC_GetSamples(
)
{
    ivas_error error;
    Word16 nOutSamplesElse, nSamplesToRender;
    Word16 /*nOutSamplesElse,*/ nSamplesToRender;
    UWord16 nSamplesRendered, nSamplesRendered_loop, l_ts, nTimeScalerOutSamples;
    UWord8 nTransportChannels, nOutChannels;
    Decoder_Struct *st_ivas;
@@ -1258,7 +1264,11 @@ ivas_error IVAS_DEC_GetSamples(
        hIvasDec->hasBeenFedFrame = false;
        move16();
        set16_fx( pcmBuf, 0, imult1616( st_ivas->hDecoderConfig->nchan_out, nSamplesAsked ) );
#ifdef LIB_DEC_REVISION
        nSamplesRendered = nSamplesAsked;
#else
        hIvasDec->nSamplesRendered = add( hIvasDec->nSamplesRendered, nSamplesAsked );
#endif
        move16();
        *nOutSamples = nSamplesAsked;
        move16();
@@ -1278,9 +1288,13 @@ ivas_error IVAS_DEC_GetSamples(
        test();
        IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ){
        /* setup */

            IF( NE_32( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &nSamplesRendered_loop, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ), IVAS_ERR_OK ) ){
                return error;
#ifdef LIB_DEC_REVISION // TODO: !!! \
                        //if ( ( error = ivas_dec_setup_all_fx( hIvasDec, &nTransportChannels, isSplitRend, splitRendBits ) ) != IVAS_ERR_OK )
#else
            IF( NE_32( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &nSamplesRendered_loop, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ), IVAS_ERR_OK ) )
#endif
            {
                //return error;
            }
        }
        {
@@ -1316,7 +1330,7 @@ ivas_error IVAS_DEC_GetSamples(
                }
                else if ( hIvasDec->mode == IVAS_DEC_MODE_IVAS )
                {
            if ( ( error = ivas_jbm_dec_tc( st_ivas ) ) != IVAS_ERR_OK )
                    if ( ( error = ivas_jbm_dec_tc_fx( st_ivas ) ) != IVAS_ERR_OK )
                    {
                        return error;
                    }
@@ -1342,12 +1356,12 @@ ivas_error IVAS_DEC_GetSamples(

                IF( st_ivas->hDecoderConfig->Opt_tsm )
                {
#ifdef LIB_DEC_REVISION
            if ( nTransportChannels != hIvasDec->nTransportChannelsOld )
#ifdef LIB_DEC_REVISION // TODO: !!!
                    IF( NE_16( nTransportChannels, hIvasDec->nTransportChannelsOld ) )
                    {
                if ( ( error = apa_setup_fx( hIvasDec, isInitialized_voip, nTransportChannels ) ) != IVAS_ERR_OK )
                        // if ( ( error = apa_setup_fx( hIvasDec, isInitialized_voip, nTransportChannels ) ) != IVAS_ERR_OK )
                        {
                    return error;
                            //return error;
                        }
                    }

@@ -1383,7 +1397,7 @@ ivas_error IVAS_DEC_GetSamples(
                        }

#ifdef LIB_DEC_REVISION
                ivas_syn_output_f( hIvasDec->st_ivas->p_output_fx, hIvasDec->nSamplesFrame, nTransportChannels, hIvasDec->apaExecBuffer_fx );
                        ivas_syn_output_f_fx( hIvasDec->st_ivas->p_output_fx, hIvasDec->nSamplesFrame, nTransportChannels, hIvasDec->apaExecBuffer_fx );

#endif
                    }
@@ -1712,7 +1726,7 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream(
            ivas_limiter_dec_fx( st_ivas->hLimiter, pOutput, st_ivas->hDecoderConfig->nchan_out, numSamplesPerChannelToDecode, st_ivas->BER_detect, Q11 );
        }

        ivas_syn_output_fx( pOutput, Q11, numSamplesPerChannelToDecode, st_ivas->hDecoderConfig->nchan_out, (int16_t *) pcmBuf_out );
        ivas_syn_output_fx( pOutput, Q11, numSamplesPerChannelToDecode, st_ivas->hDecoderConfig->nchan_out, (Word16 *) pcmBuf_out );
    }

    free( st_ivas->hSplitBinRend->hMultiBinCldfbData );
@@ -1953,6 +1967,7 @@ static ivas_error IVAS_DEC_GetTcSamples(
    IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
    {
#ifdef LIB_DEC_REVISION
        pcmBuf_fx[0] = 0; // TODO !!!
        IF( NE_32( ( error = evs_dec_main_fx( st_ivas ) ), IVAS_ERR_OK ) )
#else
        IF( NE_32( ( error = evs_dec_main_fx( st_ivas, *nOutSamples, pcmBuf_fx, NULL ) ), IVAS_ERR_OK ) )
@@ -3769,7 +3784,11 @@ ivas_error IVAS_DEC_VoIP_GetSamples(
            Word16 nSamplesToZero = s_min( nSamplesPerChannel, hIvasDec->nSamplesAvailableNext );
            set16_fx( pcmBuf + imult1616( nSamplesRendered, nOutChannels ), 0, imult1616( nSamplesToZero, nOutChannels ) );
            nSamplesRendered = add( nSamplesRendered, nSamplesToZero );
#ifdef LIB_DEC_REVISION
            nSamplesRendered = add( nSamplesRendered, nSamplesToZero );
#else
            hIvasDec->nSamplesRendered = add( hIvasDec->nSamplesRendered, nSamplesToZero );
#endif
            hIvasDec->nSamplesAvailableNext = sub( hIvasDec->nSamplesAvailableNext, nSamplesToZero );
            move16();
            move16();
@@ -3824,9 +3843,17 @@ static void update_voip_rendered20ms(
    /* float code was: hIvasDec->hVoIP->nSamplesRendered20ms = nSamplesRenderedTotal % hIvasDec->hVoIP->nSamplesFrame; */
    hIvasDec->hVoIP->nSamplesRendered20ms = nSamplesRenderedTotal;
    move16();
#ifdef LIB_DEC_REVISION
    WHILE( GE_16( hIvasDec->hVoIP->nSamplesRendered20ms, hIvasDec->nSamplesFrame ) )
#else
    WHILE( GE_16( hIvasDec->hVoIP->nSamplesRendered20ms, hIvasDec->hVoIP->nSamplesFrame ) )
#endif
    {
#ifdef LIB_DEC_REVISION
        hIvasDec->hVoIP->nSamplesRendered20ms = sub( hIvasDec->hVoIP->nSamplesRendered20ms, hIvasDec->nSamplesFrame );
#else
        hIvasDec->hVoIP->nSamplesRendered20ms = sub( hIvasDec->hVoIP->nSamplesRendered20ms, hIvasDec->hVoIP->nSamplesFrame );
#endif
    }

    return;
@@ -4310,16 +4337,22 @@ void IVAS_DEC_PrintDisclaimer( void )
 *---------------------------------------------------------------------*/

static ivas_error evs_dec_main_fx(
    Decoder_Struct *st_ivas,
    Decoder_Struct *st_ivas
#ifndef LIB_DEC_REVISION
    const Word16 nOutSamples,
    Word32 *Buf_fx, // Q11
    Word16 *pcmBuf  // Q0
#endif
)
{
    DEC_CORE_HANDLE *hCoreCoder;
    Word16 mixer_left_fx, mixer_right_fx;
    Word32 *p_output_fx[MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN];
#ifdef LIB_DEC_REVISION
    Word16 ch, i, nOutSamples;
#else
    Word16 ch, n, i;
#endif
    Word16 output_16[L_FRAME48k];
    ivas_error error;

@@ -4328,6 +4361,10 @@ static ivas_error evs_dec_main_fx(
    move32();
    hCoreCoder[0]->output_frame_fx = extract_l( Mult_32_16( hCoreCoder[0]->output_Fs, 0x0290 /*Q0*/ ) ); // Q0
    move16();
#ifdef LIB_DEC_REVISION
    nOutSamples = hCoreCoder[0]->output_frame_fx;
    move16();
#endif

    mdct_switching_dec_fx( hCoreCoder[0] );

@@ -4395,6 +4432,27 @@ static ivas_error evs_dec_main_fx(
        v_multc_fixed_16( p_output_fx[0], mixer_left_fx, p_output_fx[0], nOutSamples );  /* Q11 */
    }

#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 */
        Word32 pcm_buf_local[L_FRAME48k];

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

            Copy32( pcm_buf_local, p_output_fx[ch], nOutSamples );
        }
    }
    ELSE // ToDo: the 'else' branch can be removed once UNIFIED_DECODING_PATHS_LEFTOVERS is merged
    {
        ivas_jbm_dec_copy_tc_no_tsm_fx( st_ivas, p_output_fx, nOutSamples );
    }
#else
    IF( !st_ivas->hDecoderConfig->Opt_tsm )
    {
        ivas_jbm_dec_copy_tc_no_tsm_fx( st_ivas, p_output_fx, nOutSamples );
@@ -4422,6 +4480,7 @@ static ivas_error evs_dec_main_fx(
            }
        }
    }
#endif

    return IVAS_ERR_OK;
}
@@ -4486,7 +4545,7 @@ static ivas_error input_format_API_to_internal(
static ivas_error apa_setup_fx(
    IVAS_DEC_HANDLE hIvasDec,
    const bool isInitialized_voip,
    const uint16_t nTransportChannels )
    const UWord16 nTransportChannels )
#else
/*---------------------------------------------------------------------*
 * IVAS_DEC_VoIP_reconfigure()
@@ -4501,11 +4560,19 @@ static ivas_error IVAS_DEC_VoIP_reconfigure(
#endif
{
    Word16 apa_buffer_size;
    UWord16 l_ts;

    apa_buffer_size = hIvasDec->nSamplesFrame;
    move16();

    l_ts = (UWord16) hIvasDec->st_ivas->hTcBuffer->n_samples_granularity;
    move16();

#ifdef LIB_DEC_REVISION
    IF( !isInitialized_voip )
#else
    IF( hIvasDec->apaExecBuffer_fx == NULL )
#endif
    {
        DECODER_CONFIG_HANDLE hDecoderConfig;
#ifndef LIB_DEC_REVISION
@@ -4670,7 +4737,7 @@ ivas_error IVAS_DEC_GetCldfbSamples(
        IF( hSplitBinRend->hCldfbDataOut->config != IVAS_AUDIO_CONFIG_INVALID )
        {
            num_chs = audioCfg2channels( hSplitBinRend->hCldfbDataOut->config );
            maxBand = (int16_t) ( ( CLDFB_NO_CHANNELS_MAX * hIvasDec->st_ivas->hDecoderConfig->output_Fs ) / 48000 );
            maxBand = (Word16) ( ( CLDFB_NO_CHANNELS_MAX * hIvasDec->st_ivas->hDecoderConfig->output_Fs ) / 48000 );

            FOR( slot_idx = 0; slot_idx < CLDFB_NO_COL_MAX; slot_idx++ )
            {
@@ -4760,7 +4827,7 @@ static void ivas_destroy_handle_isar(
 *
 *---------------------------------------------------------------------*/

int16_t IVAS_DEC_is_split_rendering_enabled(
Word16 IVAS_DEC_is_split_rendering_enabled(
    IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle                               */
    Word16 *isSplitRend       /* o  : flag to indicate if split rendering is enabled    */
)
@@ -4991,7 +5058,7 @@ static ivas_error ivas_dec_init_split_rend(

Word16 IVAS_DEC_is_split_rendering_coded_out(
    IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle                               */
    int16_t *isSplitCoded     /* o  : flag to indicate if split rendering is enabled    */
    Word16 *isSplitCoded      /* o  : flag to indicate if split rendering is enabled    */
)
{
    Decoder_Struct *st_ivas;