Commit db6fead2 authored by vaclav's avatar vaclav
Browse files

formal improvements to the Param Upmx MC code

parent 9c792502
Loading
Loading
Loading
Loading
Loading
+25 −29
Original line number Diff line number Diff line
@@ -3960,7 +3960,8 @@ void ivas_dirac_dec_compute_directional_responses(
void ivas_dirac_dec_get_frequency_axis( 
    float *frequency_axis,                                      /* o  : array of center frequencies of a real filter bank */
    const int32_t output_Fs,                                    /* i  : sampling frequency                                */
    const int16_t num_freq_bands );                             /* i  : number of frequency bands                         */
    const int16_t num_freq_bands                                /* i  : number of frequency bands                         */
);

void calculate_hodirac_sector_parameters(
#ifdef FIX_485_STATIC_BUFFERS
@@ -3991,7 +3992,7 @@ ivas_error ivas_mc_paramupmix_enc_open(

void ivas_mc_paramupmix_enc_close(
    MC_PARAMUPMIX_ENC_HANDLE *hMCParamUpmix,                    /* i/o: MC Param-Upmix encoder handle                   */
    const int32_t sampling_rate
    const int32_t input_Fs                                      /* i  : input sampling rate                             */
);

void ivas_mc_paramupmix_dec(
@@ -3999,10 +4000,6 @@ void ivas_mc_paramupmix_dec(
    float output_f[][L_FRAME48k]                                /* i/o: synthesized core-coder transport channels/DirAC output  */
);

int16_t ivas_mc_paramupmix_getNumTransportChannels(
    void
);

ivas_error ivas_mc_paramupmix_dec_open(
    Decoder_Struct *st_ivas                                     /* i/o: IVAS decoder structure                          */
);
@@ -4012,9 +4009,8 @@ void ivas_mc_paramupmix_dec_close(
);

void ivas_mc_paramupmix_dec_read_BS(
    const int32_t ivas_total_brate,                                 /* i  : IVAS total bitrate                              */
    Decoder_State *st,                                              /* i/o: decoder state structure                         */
    Decoder_Struct *st_ivas,                                    /* i/o: IVAS decoder structure                          */
    Decoder_State *st,                                          /* i/o: decoder state structure                         */
    MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix,                     /* i/o: decoder MC Param-Upmix handle                   */
    int16_t *nb_bits                                            /* o  : number of bits written                          */
);
+11 −0
Original line number Diff line number Diff line
@@ -2535,6 +2535,17 @@ const uint16_t ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_
};
/*----------------------------------------------------------------------------------*
 * Parametric Upmix MC ROM tables
 *----------------------------------------------------------------------------------*/
const int16_t ivas_param_upmx_mx_qmap[2][33] =
{ 
    { 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
                              { 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0 } 
};
/*----------------------------------------------------------------------------------*
 * MASA ROM tables
 *----------------------------------------------------------------------------------*/
+7 −0
Original line number Diff line number Diff line
@@ -261,6 +261,13 @@ extern const uint16_t ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[2 * PA
extern const uint16_t ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1];


/*----------------------------------------------------------------------------------*
 * Parametric Upmix MC ROM tables
 *----------------------------------------------------------------------------------*/

extern const int16_t ivas_param_upmx_mx_qmap[2][33];


/*----------------------------------------------------------------------------------*
 * MASA ROM tables
 *----------------------------------------------------------------------------------*/
+1 −1
Original line number Diff line number Diff line
@@ -627,7 +627,7 @@ ivas_error ivas_dec(
        {
            ivas_lfe_dec( st_ivas->hLFE, st, output_frame, st_ivas->bfi, output_lfe_ch );

            ivas_mc_paramupmix_dec_read_BS( ivas_total_brate, st, st_ivas, st_ivas->hMCParamUpmix, &nb_bits_metadata[0] );
            ivas_mc_paramupmix_dec_read_BS( st_ivas, st, st_ivas->hMCParamUpmix, &nb_bits_metadata[0] );

            if ( ( error = ivas_mct_dec( st_ivas, output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
            {
+68 −60
Original line number Diff line number Diff line
@@ -52,19 +52,21 @@
/*-----------------------------------------------------------------------*
 * Local function prototypes
 *-----------------------------------------------------------------------*/
static void ps_pred_process( MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, float qmf_mod_re[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float qmf_mod_im[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float qmf_side_re[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float qmf_side_im[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], int16_t ch );

static void ps_pred_process( MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, float qmf_mod_re[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float qmf_mod_im[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float qmf_side_re[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float qmf_side_im[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], const int16_t ch );

static void paramupmix_td_decorr_process( ivas_td_decorr_state_t *hTdDecorr[], float pcm_in[][L_FRAME48k], float **pp_out_pcm, const int16_t output_frame );

static int huff_read( Decoder_State *st, const int16_t ( *ht )[2] );

static void huffman_decode( Decoder_State *st, int16_t nv, int16_t ivStart, PAR_TYPE parType, QUANT_TYPE quant_type, int16_t bNoDt, int32_t *vq );
static void huffman_decode( Decoder_State *st, const int16_t nv, const int16_t ivStart, PAR_TYPE parType, QUANT_TYPE quant_type, const int16_t bNoDt, int32_t *vq );

static void dequant_alpha( const int16_t nv, const int16_t ivStart, const QUANT_TYPE quant_type, int32_t *vq, float *v );

static void dequant_alpha( int16_t nv, int16_t ivStart, QUANT_TYPE quant_type, int32_t *vq, float *v );
static void dequant_beta( const int16_t nv, const int16_t ivStart, const QUANT_TYPE quant_type, int32_t *aq, int32_t *bq, float *beta );

static void dequant_beta( int16_t nv, int16_t ivStart, QUANT_TYPE quant_type, int32_t *aq, int32_t *bq, float *beta );
static void get_ec_data( Decoder_State *st, const PAR_TYPE parType, const QUANT_TYPE quant_type, const int16_t nParBand, const int16_t parBandStart, int32_t *parQ, int32_t *alphaQEnv, float ab[IVAS_MAX_NUM_BANDS] );

static void get_ec_data( Decoder_State *st, PAR_TYPE parType, QUANT_TYPE quant_type, int16_t nParBand, int16_t parBandStart, int32_t *parQ, int32_t *alphaQEnv, float ab[IVAS_MAX_NUM_BANDS] );

/*-------------------------------------------------------------------------
 * ivas_mc_paramupmix_dec_read_BS()
@@ -73,9 +75,8 @@ static void get_ec_data( Decoder_State *st, PAR_TYPE parType, QUANT_TYPE quant_t
 *------------------------------------------------------------------------*/

void ivas_mc_paramupmix_dec_read_BS(
    const int32_t ivas_total_brate,         /* i  : IVAS total bitrate      */
    Decoder_State *st,                      /* i/o: decoder state structure */
    Decoder_Struct *st_ivas,                /* i/o: IVAS decoder structure          */
    Decoder_State *st0,                     /* i/o: decoder state structure         */
    MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, /* i/o: decoder MC Param-Upmix handle   */
    int16_t *nb_bits                        /* o  : number of bits written          */
)
@@ -89,7 +90,7 @@ void ivas_mc_paramupmix_dec_read_BS(
    push_wmops( "mc_paramupmix_read_bs" );
    *nb_bits = 0;

    if ( st->bfi )
    if ( st0->bfi )
    {
        for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
        {
@@ -103,31 +104,31 @@ void ivas_mc_paramupmix_dec_read_BS(
    }
    else /*  if (!st->bfi) */
    {
        bit_stream_orig = st->bit_stream;
        next_bit_pos_orig = st->next_bit_pos;
        last_bit_pos = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 );
        bit_stream_orig = st0->bit_stream;
        next_bit_pos_orig = st0->next_bit_pos;
        last_bit_pos = (int16_t) ( ( st_ivas->hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC ) - 1 );
        nb_bits_read_orig = 0;
        last_bit_pos -= nb_bits_read_orig; /* reverse the bitstream for easier reading of indices */
        for ( i = 0; i < min( MAX_BITS_METADATA, last_bit_pos ); i++ )
        {
            bstr_meta[i] = st_ivas->bit_stream[last_bit_pos - i];
        }
        st->bit_stream = bstr_meta;
        st->next_bit_pos = 0;
        st->bits_frame = min( MAX_BITS_METADATA, last_bit_pos + 1 );
        st->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* to avoid BER detect */
        st0->bit_stream = bstr_meta;
        st0->next_bit_pos = 0;
        st0->bits_frame = min( MAX_BITS_METADATA, last_bit_pos + 1 );
        st0->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* to avoid BER detect */

        for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
        {
            get_ec_data( st, ALPHA, FINE /*quant_type*/, IVAS_MAX_NUM_BANDS /*nParBand*/,
            get_ec_data( st0, ALPHA, FINE /*quant_type*/, IVAS_MAX_NUM_BANDS /*nParBand*/,
                         0 /*parBandStart*/, hMCParamUpmix->alpha_quant[i], alpha_quant, hMCParamUpmix->alphas[i] );

            get_ec_data( st, BETA, FINE /*quant_type*/, IVAS_MAX_NUM_BANDS /*nParBand*/,
            get_ec_data( st0, BETA, FINE /*quant_type*/, IVAS_MAX_NUM_BANDS /*nParBand*/,
                         0 /*parBandStart*/, hMCParamUpmix->beta_quant[i], alpha_quant, hMCParamUpmix->betas[i] );
        }
        *nb_bits += st->next_bit_pos;
        st->bit_stream = bit_stream_orig;
        st->next_bit_pos = next_bit_pos_orig;
        *nb_bits += st0->next_bit_pos;
        st0->bit_stream = bit_stream_orig;
        st0->next_bit_pos = next_bit_pos_orig;

        if ( hMCParamUpmix->first_frame )
        {
@@ -145,11 +146,13 @@ void ivas_mc_paramupmix_dec_read_BS(
    return;
}


/*-------------------------------------------------------------------------
 * ivas_mc_paramupmix_dec()
 *
 * MC ParamUpmix decoding process
 *------------------------------------------------------------------------*/

void ivas_mc_paramupmix_dec(
    Decoder_Struct *st_ivas,     /* i/o: IVAS decoder handle                        */
    float output_f[][L_FRAME48k] /* i/o: synthesized core-coder transport channels  */
@@ -288,17 +291,6 @@ void ivas_mc_paramupmix_dec(
    return;
}

/*-------------------------------------------------------------------------
 * ivas_mc_paramupmix_getNumTransportChannels()
 *
 *
 *------------------------------------------------------------------------*/
int16_t ivas_mc_paramupmix_getNumTransportChannels()
{
    int16_t nchan_transport;
    nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; /* 5.1.2 */
    return nchan_transport;
}

/*-------------------------------------------------------------------------
 * ivas_mc_paramupmix_dec_open()
@@ -329,7 +321,7 @@ ivas_error ivas_mc_paramupmix_dec_open(
    output_Fs = st_ivas->hDecoderConfig->output_Fs;
    hMCParamUpmix->first_frame = 1;

    st_ivas->nchan_transport = ivas_mc_paramupmix_getNumTransportChannels();
    st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS;
    nchan_transport = st_ivas->nchan_transport;

    switch ( nchan_transport )
@@ -344,6 +336,7 @@ ivas_error ivas_mc_paramupmix_dec_open(
            assert( 0 && "Number of TC not supported for MC ParamUpmix!" );
#endif
    }

    /*-----------------------------------------------------------------*
     * set input parameters
     *-----------------------------------------------------------------*/
@@ -369,6 +362,7 @@ ivas_error ivas_mc_paramupmix_dec_open(
    return error;
}


/*-------------------------------------------------------------------------
 * ivas_mc_paramupmix_dec_close()
 *
@@ -403,6 +397,7 @@ void ivas_mc_paramupmix_dec_close(
    return;
}


/*****************************************************************************************/
/* local functions                                                                       */
/*****************************************************************************************/
@@ -413,7 +408,7 @@ static void ps_pred_process(
    float qmf_mod_im[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
    float qmf_side_re[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* in/out */
    float qmf_side_im[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
    int16_t ch )
    const int16_t ch )
{
    float vmre, vmim, vsre, vsim;
    int16_t iqmf, ipar, ismp, iismp;
@@ -423,7 +418,7 @@ static void ps_pred_process(
    float *alpha_prev = hMCParamUpmix->alpha_prev[ch];
    float *beta_prev = hMCParamUpmix->beta_prev[ch];

    int16_t qmf_to_par_band[] = {
    const int16_t qmf_to_par_band[] = {
        0, 1, 2, 3, 4, 5, 5, 6, 6, 7,
        7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
        9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
@@ -466,8 +461,11 @@ static void ps_pred_process(
        alpha1 = alpha2;
        beta1 = beta2;
    }

    return;
}


static void paramupmix_td_decorr_process(
    ivas_td_decorr_state_t *hTdDecorr[], /* i/o: SPAR Covar. decoder handle   */
    float pcm_in[][L_FRAME48k],          /* i  : input audio channels         */
@@ -514,6 +512,7 @@ static void paramupmix_td_decorr_process(
    return;
}


static int huff_read(
    Decoder_State *st,
    const int16_t ( *ht )[2] )
@@ -531,19 +530,19 @@ static int huff_read(
    return -( node + 1 );
}


static void huffman_decode(
    Decoder_State *st,
    int16_t nv,
    int16_t ivStart,
    PAR_TYPE parType,
    QUANT_TYPE quant_type,
    int16_t bNoDt,
    const int16_t nv,
    const int16_t ivStart,
    const PAR_TYPE parType,
    const QUANT_TYPE quant_type,
    const int16_t bNoDt,
    int32_t *vq )
{
    const int16_t( *huff_node_table )[2];
    int16_t iv, bdt, nquant, offset;


    nquant = 0;
    switch ( parType )
    {
@@ -568,6 +567,7 @@ static void huffman_decode(
        bdt = st->bit_stream[st->next_bit_pos];
        st->next_bit_pos++;
    }

    if ( bdt )
    { /* Get dt */
        switch ( parType )
@@ -620,12 +620,15 @@ static void huffman_decode(
            vq[iv] = huff_read( st, huff_node_table ) + vq[iv - 1] - offset;
        }
    }

    return;
}


static void dequant_alpha(
    int16_t nv,
    int16_t ivStart,
    QUANT_TYPE quant_type,
    const int16_t nv,
    const int16_t ivStart,
    const QUANT_TYPE quant_type,
    int32_t *vq,
    float *v )
{
@@ -641,22 +644,21 @@ static void dequant_alpha(
    {
        v[iv] = quant_table->data[vq[iv]];
    }

    return;
}


static void dequant_beta(
    int16_t nv,
    int16_t ivStart,
    QUANT_TYPE quant_type,
    const int16_t nv,
    const int16_t ivStart,
    const QUANT_TYPE quant_type,
    int32_t *aq,
    int32_t *bq,
    float *beta )
{
    int16_t iv;
    ACPL_QUANT_TABLE *quant_table;
    const int16_t qmap[2][33] = {
        { 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
        { 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0 }
    };

    for ( iv = 0; iv < ivStart; iv++ )
    {
@@ -665,22 +667,26 @@ static void dequant_beta(

    for ( iv = ivStart; iv < nv; iv++ )
    {
        quant_table = &beta_quant_table[quant_type][qmap[quant_type][aq[iv]]];
        quant_table = &beta_quant_table[quant_type][ivas_param_upmx_mx_qmap[quant_type][aq[iv]]];
        beta[iv] = quant_table->data[bq[iv]];
    }

    return;
}


static void get_ec_data(
    Decoder_State *st,
    PAR_TYPE parType,
    QUANT_TYPE quant_type,
    int16_t nParBand,
    int16_t parBandStart,
    const PAR_TYPE parType,
    const QUANT_TYPE quant_type,
    const int16_t nParBand,
    const int16_t parBandStart,
    int32_t *parQ,
    int32_t *alphaQEnv,
    float ab[IVAS_MAX_NUM_BANDS] )
{
    huffman_decode( st, nParBand, parBandStart, parType, quant_type, 0, parQ );

    if ( parType == ALPHA )
    {
        dequant_alpha( nParBand, parBandStart, quant_type, parQ, ab );
@@ -690,4 +696,6 @@ static void get_ec_data(
    {
        dequant_beta( nParBand, parBandStart, quant_type, alphaQEnv, parQ, ab );
    }

    return;
}
Loading