Commit 2caf64d2 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

omasa_ana, masa_merge conversion and lib_rend.c cleanup

[x] lib_rend.c float dependencies cleanup
[x] Functions in ivas_omasa_ana.c converted to fixed point.
[x] Functions in ivas_masa_merge.c converted to fixed point.
[x] Few other miscellaneous cleanup
parent 4b0124e7
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -566,7 +566,7 @@ enum

#define FRAMES_PER_SEC                      50
#ifdef IVAS_FLOAT_FIXED
#define MAX_PARAM__SPATIAL_SUB_FRAMES_PER_SEC              200 //(FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES)
#define MAX_PARAM_SPATIAL_SUB_FRAMES_PER_SEC              200 //(FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES)
#define ONE_BY_FRAMES_PER_SEC               ((Word32)(0x028F5C29))
#define FRAMES_PER_SEC_BY_2                 (FRAMES_PER_SEC >> 1)
#endif
+3 −0
Original line number Diff line number Diff line
@@ -6577,12 +6577,15 @@ void ivas_ism_render_sf(
    const int16_t n_samples_to_render                           /* i  : output frame length per channel                 */
);

#ifndef IVAS_FLOAT_FIXED
void ivas_ism_get_stereo_gains(
    const float azimuth,                                        /* i  : object azimuth                                  */
    const float elevation,                                      /* i  : object elevation                                */
    float *left_gain,                                           /* o  : left channel gain                               */
    float *right_gain                                           /* o  : right channel gain                              */
);
#endif

#ifdef IVAS_FLOAT_FIXED
void ivas_mc2sba_fx(
    IVAS_OUTPUT_SETUP hIntSetup, /* i  : Format of decoder output                         */
+0 −8
Original line number Diff line number Diff line
@@ -735,10 +735,6 @@ static ivas_error ivas_dirac_rend_config_fx(
    IF( ( EQ_16( flag_config, DIRAC_OPEN) && hDirACRend->proto_signal_decorr_on ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirACRend->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) )
    {
#ifdef IVAS_FLOAT_FIXED
        FOR( int ii = 0; ii < st_ivas->hSpatParamRendCom->num_freq_bands; ii++ )
        {
            hDirACRend->frequency_axis_fx[ii] = (Word16) hDirACRend->frequency_axis[ii];
        }
        IF( ( error = ivas_dirac_dec_decorr_open_fx( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff,
                                                     hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis_fx, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK )
        {
@@ -763,10 +759,6 @@ static ivas_error ivas_dirac_rend_config_fx(
            /* close and reopen the decorrelator */
            ivas_dirac_dec_decorr_close( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state );
#ifdef IVAS_FLOAT_FIXED
            FOR( int ii = 0; ii < st_ivas->hSpatParamRendCom->num_freq_bands; ii++ )
            {
                hDirACRend->frequency_axis_fx[ii] = (Word16) hDirACRend->frequency_axis[ii];
            }
            IF( ( error = ivas_dirac_dec_decorr_open_fx( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff,
                                                         hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis_fx, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK )
            {
+1 −1
Original line number Diff line number Diff line
@@ -385,7 +385,7 @@ ivas_error create_sce_dec(

    IF( EQ_16( (Word16) st_ivas->ivas_format, SBA_FORMAT ) && ( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) || ( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) && EQ_16( st_ivas->nchan_transport, 1 ) ) ) )
    {
        IF( ( error = openCldfb_ivas( &st->cldfbSynHB, CLDFB_SYNTHESIS, st->output_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK )
        IF( ( error = openCldfb_ivas_fx( &st->cldfbSynHB, CLDFB_SYNTHESIS, st->output_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK )
        {
            return error;
        }
+397 −136
Original line number Diff line number Diff line
@@ -56,6 +56,9 @@
#ifdef IVAS_FLOAT_FIXED
#include "prot_fx2.h"
#endif

#define IVAS_FLOAT_FIXED_TO_BE_REMOVED

/*---------------------------------------------------------------------*
 * Local state structure
 *---------------------------------------------------------------------*/
@@ -68,66 +71,72 @@ struct apa_state_t
{
    Word16 signalScaleForCorrelation;
    Word16 frmInScaled[6 * 2 * 48000 / 50 * 2 ];

    /* output buffer */
    bool evs_compat_mode;

    float *buf_out;
    uint16_t buf_out_capacity;
    uint16_t l_buf_out;
    Word16 win_incrementor;
    const Word16 *win_fx;
    Word16 *buf_out_fx;
    UWord16 buf_out_capacity;
    UWord16 l_buf_out;

    /* Hann window */
    float win[APA_BUF_PER_CHANNEL];
    uint16_t l_halfwin;
	Word16 l_halfwin_fx;
    Word16 *win_fx;
    //const Word16 *win_fx;
    UWord16 l_halfwin;

    Word16 win_incrementor;

    /* sampling rate [Hz] */
    uint16_t rate;
    UWord16 rate;

    /* length of a segment [samples] */
    uint16_t l_seg;
    UWord16 l_seg;

    /* length of a frame [samples] */
    uint16_t l_frm;
    UWord16 l_frm;

    /* total number of processed input samples since apa_reset() */
    uint32_t l_in_total;
    UWord32 l_in_total;

    /* time resolution in samples of the IVAS renderer*/
    uint16_t l_ts;
    UWord16 l_ts;

    /* samples already available in the renderer buffer */
    uint16_t l_r_buf;
    UWord16 l_r_buf;

    /* sum of inserted/removed samples since last apa_set_scale() */
    int32_t diffSinceSetScale;
    Word32 diffSinceSetScale;
    /* number of input frames since last apa_set_scale() */
    uint32_t nFramesSinceSetScale;
    UWord32 nFramesSinceSetScale;

    /* current and previous  scaling ratio [%] */
    uint16_t scale;
    UWord16 scale;

    /* minimum pitch length [samples] */
    uint16_t p_min;
    UWord16 p_min;

    /* search length [samples] */
    uint16_t l_search;
    UWord16 l_search;

    uint16_t wss; /* waveform subsampling per channel */
    uint16_t css; /* correlation subsampling per channel */
    UWord16 wss; /* waveform subsampling per channel */
    UWord16 css; /* correlation subsampling per channel */

    float targetQuality;
    uint16_t qualityred;  /* quality reduction threshold */
    uint16_t qualityrise; /* quality rising for adaptive quality thresholds */
    Word32 targetQualityQ16;
    UWord16 qualityred;  /* quality reduction threshold */
    UWord16 qualityrise; /* quality rising for adaptive quality thresholds */

    uint16_t last_pitch;       /* last pitch/sync position */
    uint16_t bad_frame_count;  /* # frames before quality threshold is lowered */
    uint16_t good_frame_count; /* # scaled frames */
    UWord16 last_pitch;       /* last pitch/sync position */
    UWord16 bad_frame_count;  /* # frames before quality threshold is lowered */
    UWord16 good_frame_count; /* # scaled frames */

    uint16_t num_channels; /* number of input/output channels */
    UWord16 num_channels; /* number of input/output channels */
};



/*---------------------------------------------------------------------*
 * Local function prototypes
 *---------------------------------------------------------------------*/
@@ -158,11 +167,78 @@ static bool shrink_frm( apa_state_t *ps, const float frm_in[], uint16_t maxScali

static bool extend_frm( apa_state_t *ps, const float frm_in[], float frm_out[], uint16_t *l_frm_out );

static Word16 find_synch_fx( apa_state_t *ps,
                          const Word16 *in,
                          Word16 l_in,
                          Word16 s_start,
                          Word16 s_len,
                          Word16 fixed_pos,
                          Word16 corr_len,
                          Word16 offset,
                          Word16 *energydBQ8,
                          Word32 *qualityQ16,
                          Word16 *synch_pos );

static Word16 norm(float num);


static Word16 norm(float num) {
    if( ( Word16 ) num ==  0 ) {
        return 15;
    }
    else 
        return norm_s(( Word16 ) num);
}


/*---------------------------------------------------------------------*
 * Public functions
 *---------------------------------------------------------------------*/

/* Allocates memory for state struct and initializes elements. */
#ifdef IVAS_FLOAT_FIXED
ivas_error apa_init(
    apa_state_t **pps,
    const Word32 num_channels )
{
    apa_state_t *ps = NULL;

    /* make sure pointer is valid */
    IF ( !pps )
    {
        return 1;
    }

    /* allocate state struct */
    IF ( ( ps = (apa_state_t *) malloc( sizeof( apa_state_t ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) );
    }

    ps->num_channels = (UWord16) num_channels;
    move16();
    ps->buf_out_capacity = (UWord16) ( APA_BUF_PER_CHANNEL * num_channels );

#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED
    IF ( ( ps->buf_out = malloc( sizeof( float ) * ps->buf_out_capacity ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) );
    }
#endif

    IF ( ( ps->buf_out_fx = malloc( sizeof( Word16 ) * ps->buf_out_capacity ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) );
    }

    ps->evs_compat_mode = false;

    apa_reset( ps );
    *pps = ps;

    return IVAS_ERR_OK;
}
#else
ivas_error apa_init(
    apa_state_t **pps,
    const int32_t num_channels )
@@ -196,8 +272,65 @@ ivas_error apa_init(
    return IVAS_ERR_OK;
}

#endif


/* Sets state variables to initial value. */
#ifdef IVAS_FLOAT_FIXED
void apa_reset(
    apa_state_t *ps )
{
    /* init state struct */
    ps->signalScaleForCorrelation = 0;
    move16();
    ps->l_buf_out = 0;
    move16();
    ps->l_halfwin = 0;
    move16();
    ps->rate = 0;
    move16();
    ps->l_seg = 0;
    move16();
    ps->l_frm = 0;
    move16();
    ps->l_in_total = 0;
    move32();
    ps->diffSinceSetScale = 0;
    move32();
    ps->nFramesSinceSetScale = 0;
    move32();
    ps->scale = 100;
    move32();
    ps->p_min = 0;
    move16();
    ps->l_search = 0;
    move16();
    ps->wss = 1;
    move16();
    ps->css = 1;
    move16();
    ps->targetQuality = 0.0f;
    ps->targetQualityQ16 = 0;
    move32();

    ps->qualityred = 0;
    move16();
    ps->qualityrise = 0;
    move16();
    ps->last_pitch = 0;
    move16();
    ps->bad_frame_count = 0;
    move16();
    ps->good_frame_count = 0;
    move16();

    ps->l_ts = 1;
    move16();
    ps->l_r_buf = 0;
    move16();
    return;
}
#else
void apa_reset(
    apa_state_t *ps )
{
@@ -229,6 +362,7 @@ void apa_reset(
    ps->l_r_buf = 0;
    return;
}
#endif

uint8_t apa_reconfigure(
    apa_state_t *ps,
@@ -241,7 +375,8 @@ uint8_t apa_reconfigure(
    ps->num_channels = (uint16_t) num_channels;
    ps->buf_out_capacity = (uint16_t) ( APA_BUF_PER_CHANNEL * num_channels );
    ps->buf_out = (float *) malloc( sizeof( float ) * ps->buf_out_capacity );
    if ( !ps->buf_out )
    ps->buf_out_fx = (Word16 *)malloc(sizeof(float) * ps->buf_out_capacity);
    if ( !ps->buf_out || !ps->buf_out_fx )
    {
        return 2;
    }
@@ -341,7 +476,7 @@ bool apa_set_rate(
#ifdef IVAS_FLOAT_FIXED
    ps->win_fx = pcmdsp_window_hann_640;
    move16();
    ps->l_halfwin_fx = 320;
    ps->l_halfwin = 320;
    move16();
    ps->win_incrementor = 1;
    move16();
@@ -349,14 +484,14 @@ bool apa_set_rate(
    {
        ps->win_fx = pcmdsp_window_hann_960;
        move16();
        ps->l_halfwin_fx = 480;
        ps->l_halfwin = 480;
        move16();
    }
    IF( EQ_32( ps->rate, 24000 ) )
    {
        ps->win_fx = pcmdsp_window_hann_960;
        move16();
        ps->l_halfwin_fx = 480;
        ps->l_halfwin = 480;
        move16();
        ps->win_incrementor = 2;
        move16();
@@ -382,6 +517,43 @@ bool apa_set_rate(


/* Set scaling. */
#ifdef IVAS_FLOAT_FIXED
bool apa_set_scale(
    apa_state_t *ps,
    UWord16 scale )
{
    /* make sure pointer is valid */
    IF ( ps == NULL )
    {
        return 1;
    }

    /* check range */
    IF ( ( LT_32( (Word32) scale, APA_MIN_SCALE ) ) || GT_32( (Word32) scale, APA_MAX_SCALE ) )
    {
        return 1;
    }

    /* do nothing if same scale is set multiple times */
    /* (otherwise scale control is confused) */
    IF ( EQ_32( (Word32 ) ps->scale, ( Word32 ) scale ) )
    {
        return 0;
    }

    /* copy to state struct */
    ps->scale = scale;
    move16();

    /* reset scaling statistics */
    ps->diffSinceSetScale = 0;
    move32();
    ps->nFramesSinceSetScale = 0;
    move32();

    return 0;
}
#else
bool apa_set_scale(
    apa_state_t *ps,
    uint16_t scale )
@@ -414,7 +586,25 @@ bool apa_set_scale(

    return 0;
}
#endif

#ifdef IVAS_FLOAT_FIXED
bool apa_set_renderer_granularity(
    apa_state_t *ps,
    UWord16 l_ts )
{
    /* make sure pointer is valid */
    IF ( ps == NULL )
    {
        return 1;
    }


    /* copy to state struct */
    ps->l_ts = l_ts * ps->num_channels;
    return 0;
}
#else
bool apa_set_renderer_granularity(
    apa_state_t *ps,
    uint16_t l_ts )
@@ -430,7 +620,25 @@ bool apa_set_renderer_granularity(
    ps->l_ts = l_ts * ps->num_channels;
    return 0;
}
#endif

#ifdef IVAS_FLOAT_FIXED
bool apa_set_renderer_residual_samples(
    apa_state_t *ps,
    UWord16 l_r_buf )
{
    /* make sure pointer is valid */
    IF ( ps == NULL )
    {
        return 1;
    }


    /* copy to state struct */
    ps->l_r_buf = l_r_buf * ps->num_channels;
    return 0;
}
#else
bool apa_set_renderer_residual_samples(
    apa_state_t *ps,
    uint16_t l_r_buf )
@@ -446,7 +654,24 @@ bool apa_set_renderer_residual_samples(
    ps->l_r_buf = l_r_buf * ps->num_channels;
    return 0;
}
#endif

#ifdef IVAS_FLOAT_FIXED
bool apa_set_evs_compat_mode(
    apa_state_t *ps,
    bool mode )
{
    /* make sure pointer is valid */
    IF ( ps == NULL )
    {
        return 1;
    }

    ps->evs_compat_mode = mode;

    return 0;
}
#else
bool apa_set_evs_compat_mode(
    apa_state_t *ps,
    bool mode )
@@ -462,6 +687,8 @@ bool apa_set_evs_compat_mode(
    return 0;
}

#endif

/*
********************************************************************************
*
@@ -520,6 +747,36 @@ bool apa_set_quality(
*
********************************************************************************
*/
#ifdef IVAS_FLOAT_FIXED
bool apa_set_complexity_options(
    apa_state_t *ps,
    UWord16 wss,
    UWord16 css )
{
    /* make sure pointer is valid */
    IF ( ps == NULL )
    {
        return 1;
    }

    IF ( wss == 0 || wss > 1000 )
    {
        return 1;
    }

    IF ( css == 0 || css > 1000 )
    {
        return 1;
    }

    ps->wss = wss;
    move16();
    ps->css = css;
    move16();

    return 0;
}
#else
bool apa_set_complexity_options(
    apa_state_t *ps,
    uint16_t wss,
@@ -546,6 +803,7 @@ bool apa_set_complexity_options(

    return 0;
}
#endif

/*
********************************************************************************
@@ -848,6 +1106,7 @@ static void get_scaling_quality(
        offset = 0;

        pitch_cn = normalized_cross_correlation_self( signal, pitch + offset, offset, corr_len, ps->num_channels * 2, &pitch_energy );

        if ( pitch_cn > 0.0f )
        {
            /* calculate correlation for double pitch */
@@ -1012,6 +1271,7 @@ static void get_scaling_quality_fx(const apa_state_t * ps,
    *energydBQ8 = apa_corrEnergy2dB_fx(maxEnergy, shl(ps->signalScaleForCorrelation, 1), corr_len);
    *qualityQ16 = L_add(*qualityQ16, L_shl(L_deposit_l(apa_getQualityIncreaseForLowEnergy_fx(*energydBQ8)), 8));
}

Word16 apa_corrEnergy2dB_fx(Word32 energy, Word16 energyExp, Word16 corr_len)
{

@@ -1029,6 +1289,7 @@ static void get_scaling_quality_fx(const apa_state_t * ps,
    result = BASOP_Util_lin2dB(L_deposit_l(result), energyExp, 1);
    return result;
}

/* Converts the correlation energy to dB. */
static float apa_corrEnergy2dB(
    float energy,
@@ -1601,11 +1862,11 @@ static bool shrink_frm(
        IF ( ps->evs_compat_mode == true )
        {
          //overlapAddEvs_fx( frm_in_fx, frm_in_fx + xtract, frm_out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin_fx, ps->win_fx );
          overlapAdd( frm_in_fx, frm_in_fx + xtract, frm_out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin_fx, ps->win_fx , ps->win_incrementor);
          overlapAdd( frm_in_fx, frm_in_fx + xtract, frm_out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin, ps->win_fx , ps->win_incrementor);
        }
        ELSE
        {
          overlapAdd( frm_in_fx, frm_in_fx + xtract, frm_out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin_fx, ps->win_fx , ps->win_incrementor);
          overlapAdd( frm_in_fx, frm_in_fx + xtract, frm_out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin, ps->win_fx , ps->win_incrementor);
        }
        for ( i = 0; i < l_seg; i++ )
            frm_out[i] = (float)frm_out_fx[i];
@@ -2018,11 +2279,11 @@ static bool extend_frm(
            IF ( ps->evs_compat_mode == true )
            {
              //overlapAddEvs_fx( fadeOut_fx, fadeIn_fx, out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin_fx, ps->win_fx );
              overlapAdd( fadeOut_fx, fadeIn_fx, out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin_fx, ps->win_fx ,ps->win_incrementor);
              overlapAdd( fadeOut_fx, fadeIn_fx, out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin, ps->win_fx ,ps->win_incrementor);
            }
            ELSE
            {
              overlapAdd( fadeOut_fx, fadeIn_fx, out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin_fx, ps->win_fx ,ps->win_incrementor);
              overlapAdd( fadeOut_fx, fadeIn_fx, out_fx, l_seg, ps->num_channels, ps->win_fx + ps->l_halfwin, ps->win_fx ,ps->win_incrementor);
            }
            for ( i = 0; i < l_seg; i++ )
                out[i] = (float) out_fx[i];
Loading