Commit 8f54e30b authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'enc_funcs_fxd_9' into 'main'

MASA, OMASA, MC-paramupmix path functions and float code cleanup [allow regression]

See merge request !630
parents 6e7e3396 eaa9284d
Loading
Loading
Loading
Loading
+195 −1
Original line number Diff line number Diff line
@@ -359,6 +359,18 @@ ivas_error ivas_FB_mixer_open(
            {
                return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
            }

#ifdef IVAS_FLOAT_FIXED
            if ( ( hFbMixer->ppFilterbank_inFR_re_fx[j] = (Word32 *) malloc( sizeof( Word32 ) * frame_len ) ) == NULL )
            {
                return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
            }

            if ( ( hFbMixer->ppFilterbank_inFR_im_fx[j] = (Word32 *) malloc( sizeof( Word32 ) * frame_len ) ) == NULL )
            {
                return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
            }
#endif
        }
    }

@@ -378,7 +390,25 @@ ivas_error ivas_FB_mixer_open(
            return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
        }
        set_f( hFbMixer->ppFilterbank_prior_input[i], 0, fb_cfg->prior_input_length );
#ifdef IVAS_FLOAT_FIXED
        IF( ( hFbMixer->ppFilterbank_prior_input_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * fb_cfg->prior_input_length ) ) == NULL )
        {
            return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
        }
        set32_fx( hFbMixer->ppFilterbank_prior_input_fx[i], 0, fb_cfg->prior_input_length );
#endif
    }

#ifdef IVAS_FLOAT_FIXED
    FOR( i = 0; i < num_chs_alloc; i++ )
    {
        IF( ( hFbMixer->ppFilterbank_prior_input_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * fb_cfg->prior_input_length ) ) == NULL )
        {
            return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
        }
        set32_fx( hFbMixer->ppFilterbank_prior_input_fx[i], 0, fb_cfg->prior_input_length );
    }
#endif

    if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) )
    {
@@ -788,6 +818,13 @@ void ivas_FB_mixer_close(

                free( hFbMixer->ppFilterbank_inFR_im[j] );
                hFbMixer->ppFilterbank_inFR_im[j] = NULL;
#ifdef IVAS_FLOAT_FIXED
                free( hFbMixer->ppFilterbank_inFR_re_fx[j] );
                hFbMixer->ppFilterbank_inFR_re_fx[j] = NULL;

                free( hFbMixer->ppFilterbank_inFR_im_fx[j] );
                hFbMixer->ppFilterbank_inFR_im_fx[j] = NULL;
#endif
            }
        }

@@ -805,7 +842,13 @@ void ivas_FB_mixer_close(
            free( hFbMixer->ppFilterbank_prior_input[i] );
            hFbMixer->ppFilterbank_prior_input[i] = NULL;
        }

#ifdef IVAS_FLOAT_FIXED
        for ( i = 0; i < num_chs_alloc; i++ )
        {
            free( hFbMixer->ppFilterbank_prior_input_fx[i] );
            hFbMixer->ppFilterbank_prior_input_fx[i] = NULL;
        }
#endif
        if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) )
        {
            free( hFbMixer->prior_mixer[0][0] );
@@ -1043,7 +1086,77 @@ void ivas_fb_mixer_pcm_ingest(

    return;
}
#ifdef IVAS_FLOAT_FIXED
void ivas_fb_mixer_pcm_ingest_fx(
    IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle             */
    Word32 *pcm_in[],              /* i  : input audio channels     Qq_data_fix[]   */
    Word32 **ppOut_pcm,            /* o  : output audio channels    Qq_ppOut_pcm[]  */
    const Word16 frame_len,        /* i  : frame length                */
    const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH],
    Word16 q_data_fix[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS],
    Word16 *q_ppOut_pcm )
{
    Word16 i;
    Word16 num_chs_ingest;
    IVAS_FB_CFG *fb_cfg = hFbMixer->fb_cfg;

    IF( fb_cfg->active_w_mixing )
    {
        num_chs_ingest = fb_cfg->num_in_chans;
        move16();
    }
    ELSE
    {
        num_chs_ingest = 1; /* forward Filterbank MDFT only on W */
        move16();
    }


    FOR( i = 0; i < fb_cfg->num_in_chans; i++ )
    {
        Word16 q_temp = s_min( hFbMixer->q_ppFilterbank_prior_input_fx[i], q_data_fix[HOA_md_ind[i]] );


        // mvr2r(&hFbMixer->ppFilterbank_prior_input[i][fb_cfg->prior_input_length - frame_len], ppOut_pcm[i], frame_len);
        Copy32( &hFbMixer->ppFilterbank_prior_input_fx[i][fb_cfg->prior_input_length - frame_len], ppOut_pcm[i], frame_len );

        IF( LT_16( q_temp, hFbMixer->q_ppFilterbank_prior_input_fx[i] ) )
        {
            FOR( Word16 x = 0; x < frame_len; x++ )
            {
                ppOut_pcm[i][x] = L_shr( ppOut_pcm[i][x], sub( hFbMixer->q_ppFilterbank_prior_input_fx[i], q_temp ) );
                move32();
            }
        }
        // mvr2r(pcm_in[HOA_md_ind[i]], &ppOut_pcm[i][frame_len], frame_len);
        Copy32( pcm_in[HOA_md_ind[i]], &ppOut_pcm[i][frame_len], frame_len );

        IF( LT_16( q_temp, q_data_fix[HOA_md_ind[i]] ) )
        {
            FOR( Word16 x = frame_len; x < shl( frame_len, 1 ); x++ )
            {
                ppOut_pcm[i][x] = L_shr( ppOut_pcm[i][x], sub( q_data_fix[HOA_md_ind[i]], q_temp ) );
                move32();
            }
        }
        q_ppOut_pcm[i] = q_temp;
        move16();
    }

    Word16 guard_bits = find_guarded_bits_fx( shl( frame_len, 1 ) );

    FOR( i = 0; i < num_chs_ingest; i++ )
    {
        Word16 q_shift = sub( getScaleFactor32( ppOut_pcm[fb_cfg->remix_order[i]], shl( frame_len, 1 ) ), guard_bits );
        Scale_sig32( ppOut_pcm[fb_cfg->remix_order[i]], shl( frame_len, 1 ), q_shift );
        q_ppOut_pcm[fb_cfg->remix_order[i]] = add( q_ppOut_pcm[fb_cfg->remix_order[i]], q_shift );

        ivas_mdft_fx( ppOut_pcm[fb_cfg->remix_order[i]], hFbMixer->ppFilterbank_inFR_re_fx[fb_cfg->remix_order[i]], hFbMixer->ppFilterbank_inFR_im_fx[fb_cfg->remix_order[i]], shl( frame_len, 1 ), frame_len );
    }

    return;
}
#endif

/*-----------------------------------------------------------------------------------------*
 * Function ivas_fb_mixer_update_prior_input()
@@ -1069,6 +1182,26 @@ void ivas_fb_mixer_update_prior_input(
    return;
}

#ifdef IVAS_FLOAT_FIXED
void ivas_fb_mixer_update_prior_input_fx(
    IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle              */
    Word32 *pcm_in_fx[],           /* i  : input audio channels         */
    const Word16 length,           /* i  : length of time slot          */
    const Word16 nchan_fb_in       /* i  : number of analysis channels  */
)
{
    Word16 i;

    FOR( i = 0; i < nchan_fb_in; i++ )
    {
        Copy32( &hFbMixer->ppFilterbank_prior_input_fx[i][length], hFbMixer->ppFilterbank_prior_input_fx[i], hFbMixer->fb_cfg->prior_input_length - length );
        Copy32( pcm_in_fx[i], &hFbMixer->ppFilterbank_prior_input_fx[i][hFbMixer->fb_cfg->prior_input_length - length], length );
    }

    return;
}
#endif


/*-----------------------------------------------------------------------------------------*
 * Function ivas_fb_mixer_get_windowed_fr()
@@ -1076,6 +1209,61 @@ void ivas_fb_mixer_update_prior_input(
 *
 *-----------------------------------------------------------------------------------------*/

#ifdef IVAS_FLOAT_FIXED
void ivas_fb_mixer_get_windowed_fr_fx(
    IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle                    */
    Word32 *pcm_in_fx[],
    Word32 *frame_f_real_fx[],
    Word32 *frame_f_imag_fx[],
    const Word16 length,      /* i  : number of new samples in time slot */
    const Word16 mdft_len,    /* i  : MDFT frame length                  */
    const Word16 nchan_fb_in, /* i  : number of analysis channels        */
    Word16 gb )
{
    Word16 ch_idx, j, offset, rev_offset;
    Word16 n_old_samples;
    Word16 n_new_samples;
    Word32 fr_in_block_fx[L_FRAME48k * 2];
    const Word16 *win_ptr_fx;

    n_old_samples = s_min( ( sub( hFbMixer->fb_cfg->prior_input_length, hFbMixer->fb_cfg->windowed_fr_offset ) ), ( shl( mdft_len, 1 ) ) );
    n_new_samples = s_max( 0, sub( shl( length, 1 ), n_old_samples ) );
    offset = (Word16) ( sub( sub( shl( mdft_len, 1 ), length ), hFbMixer->ana_window_offset ) );
    rev_offset = (Word16) ( sub( shl( mdft_len, 1 ), hFbMixer->ana_window_offset ) );
    set32_fx( fr_in_block_fx, 0, offset );

    FOR( ch_idx = 0; ch_idx < nchan_fb_in; ch_idx++ )
    {
        Copy32( &hFbMixer->ppFilterbank_prior_input_fx[ch_idx][offset + hFbMixer->fb_cfg->windowed_fr_offset], &fr_in_block_fx[offset], n_old_samples - offset );
        Copy32( pcm_in_fx[ch_idx], &fr_in_block_fx[n_old_samples], n_new_samples );

        win_ptr_fx = hFbMixer->pAna_window_fx; /*Q15*/

        FOR( j = offset; j < sub( shl( mdft_len, 1 ), length ); j++ )
        {
            fr_in_block_fx[j] = Mpy_32_16_1( fr_in_block_fx[j], ( *( win_ptr_fx++ ) ) );
            move16();
        }

        FOR( j = rev_offset; j < shl( mdft_len, 1 ); j++ )
        {
            fr_in_block_fx[j] = Mpy_32_16_1( fr_in_block_fx[j], ( *( --win_ptr_fx ) ) );
            move16();
        }

        FOR( Word16 i = 0; i < shl( mdft_len, 1 ); i++ )
        {
            fr_in_block_fx[i] = L_shr( fr_in_block_fx[i], gb );
            move16();
        }

        ivas_mdft_fx( fr_in_block_fx, frame_f_real_fx[ch_idx], frame_f_imag_fx[ch_idx], mdft_len << 1, mdft_len );
    }

    return;
}
#endif

void ivas_fb_mixer_get_windowed_fr(
    IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle                    */
    float *pcm_in[],               /* i  : input audio channels               */
@@ -2056,6 +2244,12 @@ static ivas_error ivas_filterbank_setup(
    {
        return error;
    }
#ifdef IVAS_FLOAT_FIXED
    IF( ( error = ivas_fb_mixer_get_window_fx( pCfg->fb_latency, sampling_rate, &( hFbMixer->pAna_window_fx ) ) ) != IVAS_ERR_OK )
    {
        return error;
    }
#endif

    if ( ( error = ivas_fb_mixer_get_window( pCfg->fade_len, sampling_rate, &( hFbMixer->pFilterbank_cross_fade ) ) ) != IVAS_ERR_OK )
    {
+25 −0
Original line number Diff line number Diff line
@@ -5155,12 +5155,22 @@ void calculate_hodirac_sector_parameters(
    float *ene                                                  /* o  : array of sector energy values, flat             */
);

#ifdef IVAS_FLOAT_FIXED
void ivas_mc_paramupmix_enc(
    Encoder_Struct *st_ivas,                                    /* i/o: IVAS Encoder handle                             */
    BSTR_ENC_HANDLE hMetaData,                                  /* i/o: IVAS Metadata bitstream handle                  */
    float *data_f[],                                            /* i/o: input/transport MC data                         */
	Word32 *data_fx[],
    const int16_t input_frame                                   /* i  : input frame length                              */
);
#else
void ivas_mc_paramupmix_enc(
    Encoder_Struct *st_ivas,                                    /* i/o: IVAS Encoder handle                             */
    BSTR_ENC_HANDLE hMetaData,                                  /* i/o: IVAS Metadata bitstream handle                  */
    float *data_f[],                                            /* i/o: input/transport MC data                         */
    const int16_t input_frame                                   /* i  : input frame length                              */
);
#endif

ivas_error ivas_mc_paramupmix_enc_open(
    Encoder_Struct *st_ivas                                     /* i/o: IVAS encoder handle                             */
@@ -7932,12 +7942,15 @@ ivas_error ivas_omasa_dec_config(
    int16_t *data                                               /* o  : output synthesis signal                 */
);

#ifndef IVAS_FLOAT_FIXED
void ivas_omasa_set_config(
    OMASA_ENC_HANDLE hOMasa,                                    /* i/o: OMASA encoder handle                    */
    MASA_ENCODER_HANDLE hMasa,                                  /* i  : MASA encoder handle                     */
    const int32_t input_Fs,                                     /* i  : Input sample rate                       */
    const ISM_MODE ism_mode                                     /* i  : ISM mode                                */
);
#endif // !IVAS_FLOAT_FIXED


void ivas_omasa_enc(
    OMASA_ENC_HANDLE hOMasa,                                    /* i/o: OMASA encoder handle                    */
@@ -7985,6 +7998,7 @@ void ivas_set_ism_importance_interformat(
    int16_t ism_imp[]                                           /* o  : ISM importance flags                    */
);

#ifndef IVAS_FLOAT_FIXED
/*! r: flag for using less bitrate for objects in OMASA */
int16_t ivas_omasa_ener_brate(
    const int16_t nchan_ism,                                    /* i  : number of ISMs                          */
@@ -7992,6 +8006,7 @@ int16_t ivas_omasa_ener_brate(
    float *data_f[],                                            /* i  : Input / transport audio signals         */
    const int16_t input_frame                                   /* i  : Input frame size                        */
);
#endif // !IVAS_FLOAT_FIXED

/*! r: adjusted bitrate */
int32_t ivas_interformat_brate(
@@ -8220,6 +8235,16 @@ void ivas_fb_mixer_pcm_ingest(
    const int16_t frame_length,                                 /* i  : frame length                                */
    const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH]
);
#ifdef IVAS_FLOAT_FIXED
void ivas_fb_mixer_pcm_ingest_fx(
    IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle             */
    Word32 *pcm_in[],              /* i  : input audio channels     Qq_data_fix[]   */
    Word32 **ppOut_pcm,            /* o  : output audio channels    Qq_ppOut_pcm[]  */
    const Word16 frame_len,        /* i  : frame length                */
    const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH],
    Word16 q_data_fix[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS],
    Word16 *q_ppOut_pcm );
#endif

void ivas_fb_mixer_update_prior_input(
    IVAS_FB_MIXER_HANDLE hFbMixer,                              /* i/o: FB mixer handle                             */
+30 −0
Original line number Diff line number Diff line
@@ -3092,4 +3092,34 @@ ISM_MODE ivas_ism_mode_select(
    const Word16 nchan_inp,       /* i  : number of input objects  */
    const Word32 ivas_total_brate /* i  : IVAS total bitrate       */
);

void ivas_fb_mixer_update_prior_input_fx(
    IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle                             */
    Word32 *pcm_in_fx[],           /* i  : input audio channels                        */
    const Word16 length,           /* i  : length of time slot                         */
    const Word16 nchan_fb_in       /* i  : number of analysis channels                 */
);

void ivas_fb_mixer_get_windowed_fr_fx(
    IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle                    */
    Word32 *pcm_in_fx[],
    Word32 *frame_f_real_fx[],
    Word32 *frame_f_imag_fx[],
    const int16_t length,      /* i  : number of new samples in time slot */
    const int16_t mdft_len,    /* i  : MDFT frame length                  */
    const int16_t nchan_fb_in, /* i  : number of analysis channels        */
    Word16 gb );
void ivas_omasa_set_config_fx(
    OMASA_ENC_HANDLE hOMasa,   /* i/o: OMASA encoder handle */
    MASA_ENCODER_HANDLE hMasa, /* i  : MASA encoder handle  */
    const Word32 input_Fs,     /* i  : Input sample rate    */
    const ISM_MODE ism_mode    /* i  : ISM mode             */
);
Word16 ivas_omasa_ener_brate_fx(
    const Word16 nchan_ism,        /* i  : number of ISMs                   */
    const Word32 ivas_total_brate, /* i  : IVAS total bitrate               */
    Word32 *data_f[],              /* i  : Input / transport audio signals  */
    const Word16 input_frame,      /* i  : Input frame size                 */
    Word16 data_e                  /*i:exponent for data_f                  */
);
#endif
+7 −0
Original line number Diff line number Diff line
@@ -552,6 +552,10 @@ typedef struct ivas_qdirection_band_data_struct
    uint16_t elevation_index[MAX_PARAM_SPATIAL_SUBFRAMES];
    float q_azimuth[MAX_PARAM_SPATIAL_SUBFRAMES];
    float q_elevation[MAX_PARAM_SPATIAL_SUBFRAMES];
#ifdef IVAS_FLOAT_FIXED
    Word32 q_azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES];   /* Q22 */
    Word32 q_elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */
#endif

} IVAS_QDIRECTION_BAND_DATA;

@@ -855,6 +859,9 @@ typedef struct ivas_fb_mixer_state_structure
    Word32 *ppFilterbank_inFR_re_fx[IVAS_MAX_FB_MIXER_IN_CH];
    Word32 *ppFilterbank_inFR_im_fx[IVAS_MAX_FB_MIXER_IN_CH];
    Word32 *ppFilterbank_prior_input_fx[IVAS_MAX_FB_MIXER_IN_CH];
    Word16 q_ppFilterbank_inFR_re_fx[IVAS_MAX_FB_MIXER_IN_CH];
    Word16 q_ppFilterbank_inFR_im_fx[IVAS_MAX_FB_MIXER_IN_CH];
    Word16 q_ppFilterbank_prior_input_fx[IVAS_MAX_FB_MIXER_IN_CH];
    Word32 *prior_mixer_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH];
#endif

+7 −0
Original line number Diff line number Diff line
@@ -10138,6 +10138,13 @@ Word16 squant_fx( /* o: index of the winning codeword */
                  const Word16 cbsize /* i: codebook size                   */
);
Word16 squant_int_fx(
    UWord8 x,           /* i  : scalar value to quantize  */
    UWord8 *xq,         /* o  : quantized value           */
    const UWord8 *cb,   /* i  : codebook                  */
    const Word16 cbsize /* i  : codebook size             */
);
void pz_filter_dp_fx(
    const Word16 b[],
    const Word16 a[],
Loading