Commit c2efd75f authored by vaclav's avatar vaclav
Browse files

port MR, part 1

parent 957cd45f
Loading
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -822,8 +822,10 @@ void ivas_apply_non_diegetic_panning(
 *----------------------------------------------------------------------------------*/

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

ivas_error ivas_jbm_dec_render(
+1 −0
Original line number Diff line number Diff line
@@ -221,6 +221,7 @@
#define FIX_1369_HQ_LR_OVERFLOW                         /* FhG: fix BASOP overflow in hq_lr_enc(), brings floating-point code inline with FX */
#define NONBE_1118_EVS_LR_HQ_BITERROR                   /* VA: issue 1118: fix EVS decoder crash in LR-HQ in case of bit errors */
#define FIX_1139_REV_COLORATION_SHORT_T60               /* Nokia,FhG: Fix issue 1139, prevent sound coloration artefacts at very low reverberation times */
#define LIB_DEC_REVISION                                /* VA: cleaning and simplification of lib_dec.c */

/* #################### End BASOP porting switches ############################ */

+8 −2
Original line number Diff line number Diff line
@@ -66,8 +66,10 @@ static void ivas_jbm_masa_sf_to_slot_map( Decoder_Struct *st_ivas, const int16_t
 *--------------------------------------------------------------------------*/

ivas_error ivas_jbm_dec_tc(
    Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure         */
    Decoder_Struct *st_ivas /* i/o: IVAS decoder structure         */
#ifndef LIB_DEC_REVISION
    float *data /* o  : transport channel signals      */
#endif
)
{
    int16_t n, output_frame, nchan_out;
@@ -746,11 +748,15 @@ 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 );
+220 −80
Original line number Diff line number Diff line
@@ -78,7 +78,9 @@ struct IVAS_DEC
    bool isInitialized;

    int16_t bitstreamformat; /* Bitstream format flag (G.192/MIME/VOIP_G192_RTP/VOIP_RTPDUMP) */
#ifdef DEBUGGING
    bool Opt_VOIP; /* flag indicating VOIP mode with JBM */
#endif
    int16_t tsm_scale; /* scale for TSM operation */
    int16_t tsm_max_scaling;
    int16_t timeScalingDone; /* have we done already one TSM in a 20ms frame? */
@@ -89,7 +91,9 @@ struct IVAS_DEC
    bool hasBeenFedFrame;
    bool updateOrientation;
    uint16_t nSamplesAvailableNext;
#ifndef LIB_DEC_REVISION
    int16_t nSamplesRendered;
#endif
    int16_t nTransportChannelsOld;
    int16_t amrwb_rfc4867_flag; /* MIME from rfc4867 is used */
    int16_t sdp_hf_only;        /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */
@@ -102,19 +106,32 @@ struct IVAS_DEC
 * Local function declarations
 *---------------------------------------------------------------------*/

#ifdef LIB_DEC_REVISION
static void ivas_destroy_handle_VoIP( IVAS_DEC_VOIP *hVoIP );
#else
static void IVAS_DEC_Close_VoIP( IVAS_DEC_VOIP *hVoIP );
#endif
#ifdef SUPPORT_JBM_TRACEFILE
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 );
#else
static ivas_error evs_dec_main( Decoder_Struct *st_ivas, const int16_t nOutSamples, float *floatBuf, int16_t *pcmBuf );
#endif
static ivas_error input_format_API_to_internal( IVAS_DEC_INPUT_FORMAT input_format, int16_t *bitstream_format_internal, int16_t *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( IVAS_DEC_HANDLE hIvasDec, uint8_t *nTransportChannels, const int16_t isSplitRend, ISAR_SPLIT_REND_BITS_DATA *splitRendBits );
static ivas_error apa_setup( IVAS_DEC_HANDLE hIvasDec, const bool isInitialized_voip, const uint16_t nTransportChannels );
#else
static ivas_error IVAS_DEC_VoIP_reconfigure( IVAS_DEC_HANDLE hIvasDec, const uint16_t nTransportChannels, const uint16_t l_ts );
static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, uint16_t *nTcBufferGranularity, uint8_t *nTransportChannels, uint8_t *nOutChannels, uint16_t *nSamplesRendered, const IVAS_DEC_PCM_TYPE pcmType, void *data );
static ivas_error IVAS_DEC_GetTcSamples( IVAS_DEC_HANDLE hIvasDec, float *pcmBuf, int16_t *nOutSamples );
static ivas_error IVAS_DEC_RendererFeedTcSamples( IVAS_DEC_HANDLE hIvasDec, const int16_t nSamplesForRendering, int16_t *nSamplesResidual, float *pcmBuf );
static ivas_error IVAS_DEC_GetRenderedSamples( IVAS_DEC_HANDLE hIvasDec, const uint16_t nSamplesForRendering, uint16_t *nSamplesRendered, uint16_t *nSamplesAvailableNext, const IVAS_DEC_PCM_TYPE pcmType, void *pcmBuf );
static ivas_error IVAS_DEC_GetBufferedNumberOfSamples( IVAS_DEC_HANDLE hIvasDec, int16_t *nSamplesBuffered );
#endif
static PCM_RESOLUTION pcm_type_API_to_internal( const IVAS_DEC_PCM_TYPE pcmType );
static void *pcm_buffer_offset( void *buffer, const IVAS_DEC_PCM_TYPE pcmType, const int32_t offset );
static ivas_error set_pcm_buffer_to_zero( void *buffer, const IVAS_DEC_PCM_TYPE pcmType, const int16_t nZeroSamples );
@@ -165,7 +182,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;
@@ -176,7 +195,9 @@ ivas_error IVAS_DEC_Open(
    hIvasDec->mode = mode;

    hIvasDec->bitstreamformat = G192;
#ifdef DEBUGGING
    hIvasDec->Opt_VOIP = 0;
#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*/
@@ -315,7 +336,7 @@ static void init_decoder_config(
/*---------------------------------------------------------------------*
 * IVAS_DEC_Close( )
 *
 *
 * Deallocate IVAS decoder memory handles
 *---------------------------------------------------------------------*/

void IVAS_DEC_Close(
@@ -330,7 +351,11 @@ void IVAS_DEC_Close(

    if ( ( *phIvasDec )->hVoIP )
    {
#ifdef LIB_DEC_REVISION
        ivas_destroy_handle_VoIP( ( *phIvasDec )->hVoIP );
#else
        IVAS_DEC_Close_VoIP( ( *phIvasDec )->hVoIP );
#endif
        ( *phIvasDec )->hVoIP = NULL;
    }

@@ -391,12 +416,37 @@ static IVAS_DEC_BS_FORMAT mapIvasFormat(
    return IVAS_DEC_BS_UNKOWN;
}

#ifdef LIB_DEC_REVISION

/*---------------------------------------------------------------------*
 * create_flush_buffer()
 *
 * Create flush buffer - needed for binaural outputs with TSM or in VoIP mode
 *---------------------------------------------------------------------*/

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 ) );
    if ( hIvasDec->flushbuffer == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate JBM flush buffer" );
    }

    hIvasDec->pcmType = IVAS_DEC_PCM_INT16;
    set_s( (int16_t *) hIvasDec->flushbuffer, 0, CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES );

    return IVAS_ERR_OK;
}

#endif

/*---------------------------------------------------------------------*
 * IVAS_DEC_Configure( )
 *
 * Decoder configuration
 * legacy code behavior: if no output format set, then it's EVS mono
 * legacy behavior: if no output format set, then it's EVS mono
 *---------------------------------------------------------------------*/

ivas_error IVAS_DEC_Configure(
@@ -404,7 +454,9 @@ ivas_error IVAS_DEC_Configure(
    IVAS_DEC_HANDLE hIvasDec,             /* i/o: IVAS decoder handle                                 */
    const uint32_t sampleRate,            /* i  : output sampling frequency                           */
    const IVAS_AUDIO_CONFIG outputConfig, /* i  : output configuration                                */
#ifndef LIB_DEC_REVISION
    const bool tsmEnabled, /* i  : enable time scale modification                      */
#endif
    const IVAS_RENDER_FRAMESIZE renderFramesize,       /* i  : rendering frame size                                */
    const bool customLsOutputEnabled,                  /* i  : enable custom loudspeaker setup handle              */
    const bool hrtfReaderEnabled,                      /* i  : enable HRTF binary file input                       */
@@ -486,7 +538,9 @@ ivas_error IVAS_DEC_Configure(
    }

#ifdef FIX_745_FIX_DATA_TYPE_CONVERSION
#ifndef LIB_DEC_REVISION
    hDecoderConfig->Opt_tsm = (int16_t) tsmEnabled;
#endif
    hDecoderConfig->Opt_LsCustom = (int16_t) customLsOutputEnabled;
    hDecoderConfig->Opt_Headrotation = (int16_t) enableHeadRotation;
#else
@@ -558,11 +612,13 @@ ivas_error IVAS_DEC_Configure(
    }

    hIvasDec->nSamplesFrame = (uint16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC );
#ifndef LIB_DEC_REVISION
    hIvasDec->nSamplesAvailableNext = 0;
    hIvasDec->nSamplesRendered = 0;
    hIvasDec->tsm_scale = 100;
    hIvasDec->tsm_max_scaling = 0;
    hIvasDec->tsm_quality = 1.0f;
#endif

    return IVAS_ERR_OK;
}
@@ -767,7 +823,9 @@ ivas_error IVAS_DEC_EnableVoIP(

    hDecoderConfig = hIvasDec->st_ivas->hDecoderConfig;

#ifdef DEBUGGING
    hIvasDec->Opt_VOIP = 1;
#endif
    hDecoderConfig->Opt_tsm = 1;
    if ( hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_EXTERNAL )
    {
@@ -792,7 +850,9 @@ ivas_error IVAS_DEC_EnableVoIP(

    hIvasDec->hVoIP->lastDecodedWasActive = 0;
    hIvasDec->hVoIP->hCurrentDataUnit = NULL;
#ifndef LIB_DEC_REVISION
    hIvasDec->hVoIP->nSamplesFrame = (uint16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC );
#endif
    hIvasDec->hVoIP->nSamplesRendered20ms = 0;

#define WMC_TOOL_SKIP
@@ -905,7 +965,9 @@ ivas_error IVAS_DEC_FeedFrame_Serial(

    hIvasDec->needNewFrame = false;
    hIvasDec->hasBeenFedFrame = true;
#ifndef LIB_DEC_REVISION
    hIvasDec->nSamplesRendered = 0;
#endif
    hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame;

    return IVAS_ERR_OK;
@@ -929,6 +991,13 @@ ivas_error IVAS_DEC_GetSamples(
)
{
    ivas_error error;
    Decoder_Struct *st_ivas;
#ifdef LIB_DEC_REVISION
    uint16_t nTimeScalerOutSamples;
    uint8_t nTransportChannels;
    int16_t nResidualSamples, nSamplesTcsScaled;
    bool isInitialized_voip;
#endif
    int16_t nOutSamplesElse, nSamplesToRender;
    uint16_t nSamplesRendered, nSamplesRendered_loop, l_ts, nTimeScalerOutSamples;
    uint8_t nTransportChannels, nOutChannels;
@@ -991,6 +1060,24 @@ ivas_error IVAS_DEC_GetSamples(
        }
    }
    else
    {
        st_ivas = hIvasDec->st_ivas;

#ifdef LIB_DEC_REVISION
        isInitialized_voip = hIvasDec->apaExecBuffer != NULL;
#endif

#ifdef LIB_DEC_REVISION
        /*-----------------------------------------------------------------*
             * Setup all decoder parts (IVAS decoder, ISAR)
             *-----------------------------------------------------------------*/

        if ( ( error = ivas_dec_setup_all( hIvasDec, &nTransportChannels, isSplitRend, splitRendBits ) ) != IVAS_ERR_OK )
        {
            return error;
        }
#else
        if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) /* wait for the first good frame */
        {
            /* check if we need to run the setup function */
            if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame )
@@ -1017,21 +1104,67 @@ ivas_error IVAS_DEC_GetSamples(
                            return error;
                        }
                    }
#endif

#ifdef LIB_DEC_REVISION
        /*-----------------------------------------------------------------*
             * IVAS decoder: decode transport channels and metadata
             *-----------------------------------------------------------------*/

        if ( hIvasDec->mode == IVAS_DEC_MODE_EVS )
        {
            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 ) ) != IVAS_ERR_OK )
            {
                return error;
            }

            hIvasDec->isInitialized = true; /* Initialization done in ivas_dec() */
        }

        if ( hIvasDec->hasBeenFedFirstGoodFrame )
        {
            hIvasDec->hasDecodedFirstGoodFrame = true;
        }
#else
                    /* IVAS decoder */
                    if ( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer, &nOutSamplesElse ) ) != IVAS_ERR_OK )
                    {
                        return error;
                    }
#endif

                /* JBM */
                if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
        /*-----------------------------------------------------------------*
             * JBM
             *-----------------------------------------------------------------*/

        if ( st_ivas->hDecoderConfig->Opt_tsm )
        {
#ifdef LIB_DEC_REVISION
            if ( nTransportChannels != hIvasDec->nTransportChannelsOld )
            {
                if ( ( error = apa_setup( hIvasDec, isInitialized_voip, nTransportChannels ) ) != IVAS_ERR_OK )
                {
                    return error;
                }
            }

#endif
            if ( apa_set_scale( hIvasDec->hTimeScaler, hIvasDec->tsm_scale ) != 0 )
            {
                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;
@@ -1049,16 +1182,23 @@ ivas_error IVAS_DEC_GetSamples(
#ifdef DEBUG_MODE_JBM
        dbgwrite( &nTimeScalerOutSamples, sizeof( uint16_t ), 1, 1, "./res/JBM_nTimeScaleOutSamples.dat" );
#endif
                /* Feed decoded transport channels samples to the renderer */
        /*-----------------------------------------------------------------*
             * Feed decoded transport channels samples to the renderer
             *-----------------------------------------------------------------*/

#ifdef LIB_DEC_REVISION
        ivas_jbm_dec_feed_tc_to_renderer( st_ivas, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer );
#else
                    if ( ( error = IVAS_DEC_RendererFeedTcSamples( hIvasDec, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer ) ) != IVAS_ERR_OK )
                    {
                        return error;
                    }
#endif

#ifdef DEBUG_MODE_JBM
        dbgwrite( &nResidualSamples, sizeof( int16_t ), 1, 1, "./res/JBM_nResidualSamples.dat" );
#endif
                if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
        if ( st_ivas->hDecoderConfig->Opt_tsm )
        {
            /* feed residual samples to TSM for the next call */
            if ( apa_set_renderer_residual_samples( hIvasDec->hTimeScaler, (uint16_t) nResidualSamples ) != 0 )
+14 −3
Original line number Diff line number Diff line
@@ -122,7 +122,9 @@ ivas_error IVAS_DEC_Configure(
    IVAS_DEC_HANDLE hIvasDec,                           /* i/o: IVAS decoder handle                                 */
    const uint32_t sampleRate,                          /* i  : output sampling frequency                           */
    const IVAS_AUDIO_CONFIG outputConfig,               /* i  : output configuration                                */
#ifndef LIB_DEC_REVISION
    const bool tsmEnabled,                              /* i  : enable time scale modification                      */
#endif
    const IVAS_RENDER_FRAMESIZE renderFramesize,        /* i  : rendering frame size                                */
    const bool customLsOutputEnabled,                   /* i  : enable custom loudspeaker setup handle              */
    const bool hrtfReaderEnabled,                       /* i  : enable HRTF binary file input                       */
@@ -282,6 +284,14 @@ ivas_error IVAS_DEC_VoIP_SetScale(
    const int16_t scale                         /* i  : TSM scale to set                                                        */
);

#ifdef VARIABLE_SPEED_DECODING
#ifdef LIB_DEC_REVISION
ivas_error IVAS_DEC_EnableTsm(
    IVAS_DEC_HANDLE hIvasDec                    /* i/o: IVAS decoder handle                                                     */
);

#endif
#endif
ivas_error IVAS_DEC_TSM_SetQuality(
    IVAS_DEC_HANDLE hIvasDec,                   /* i/o: IVAS decoder handle                                                     */
	const float quality                         /* i  : target TSM quality                                                      */
@@ -470,12 +480,13 @@ ivas_error IVAS_DEC_HasDecodedFirstGoodFrame(
    bool *hasDecodedFirstGoodFrame              /* o  : flag indicating if the decoder has decoded a good frame since it was configured */
);

#ifndef LIB_DEC_REVISION
/*! r: error code */
ivas_error IVAS_DEC_GetPcmFrameSize(
    IVAS_DEC_HANDLE hIvasDec,                   /* i/o: IVAS decoder handle                                                     */
    int32_t *pcmFrameSize                       /* o  : total size of the PCM output frame. This takes into account the number of output channels */
);

#endif
/*! r: true if decoder has no data in VoIP jitter buffer */
bool IVAS_DEC_VoIP_IsEmpty(
    IVAS_DEC_HANDLE hIvasDec,                   /* i/o: IVAS decoder handle                                                     */