Commit d9ce8968 authored by vaclav's avatar vaclav
Browse files

Replace divisions with constant denominator by multiplications

parent ad827404
Loading
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -199,14 +199,13 @@ ivas_error ivas_FB_mixer_open_fx(
{
    IVAS_FB_MIXER_HANDLE hFbMixer;
    Word16 i, j, frame_len, num_bands;
    Word16 num_chs_alloc, exp;
    Word16 num_chs_alloc;
    ivas_error error;

    error = IVAS_ERR_OK;
    move32();

    frame_len = BASOP_Util_Divide3232_Scale( sampling_rate, FRAMES_PER_SEC, &exp );
    frame_len = shr( frame_len, sub( 15, exp ) );
    frame_len = extract_l( Mpy_32_32_r( sampling_rate, ONE_BY_FRAMES_PER_SEC_Q31 ) );

    hFbMixer = *hFbMixer_out;

@@ -936,8 +935,9 @@ static Word16 ivas_calculate_abs_fr_fx(
        move64();
        Word16 short_stride = pFb->fb_bin_to_band.short_stride;
        move16();

        Word32 res_dec1, res_frac, res_dec2;
        iDiv_and_mod_32( sampling_rate, FRAMES_PER_SEC, &res_dec1, &res_frac, 0 );
        res_dec1 = Mpy_32_32_r( sampling_rate, ONE_BY_FRAMES_PER_SEC_Q31 );
        iDiv_and_mod_32( res_dec1, short_stride, &res_dec2, &res_frac, 0 );
        const Word16 num_bins_per_short_stride_bin = extract_l( res_dec2 );
        iDiv_and_mod_32( res_dec1, pFb->fb_bin_to_band.num_cldfb_bands, &res_dec2, &res_frac, 0 );
@@ -1259,7 +1259,7 @@ static ivas_error ivas_filterbank_setup_fx(
    const Word32 sampling_rate,
    Word16 *index )
{
    Word16 i, j, exp, tmp;
    Word16 i, j, tmp;
    const Word32 *pAll_fb_fr_fx[2];
    const Word16 *pAll_bins_start_offset = NULL;
    const Word16 *pAll_bins_per_band = NULL;
@@ -1342,9 +1342,8 @@ static ivas_error ivas_filterbank_setup_fx(

        /*pFb->fb_bin_to_band.cldfb_stride = ( int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX );*/ /* equals num_cldfb_bands*/
        // pFb->fb_bin_to_band.short_stride = extract_l( ( sampling_rate / FRAMES_PER_SEC ) / 4 );
        tmp = BASOP_Util_Divide3232_Scale( sampling_rate, FRAMES_PER_SEC, &exp );
        pFb->fb_bin_to_band.short_stride = shr( tmp, add( sub( 15, exp ), 2 ) );

        tmp = extract_l( Mpy_32_32_r( sampling_rate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
        pFb->fb_bin_to_band.short_stride = shr( tmp, 2 );
        move16();

        set32_fx( pFb->fb_bin_to_band.p_short_stride_bin_to_band_fx, 0, 2 * MDFT_FB_BANDS_240 );
+7 −8
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include "prot_fx.h"
#include "ivas_stat_com.h"
#include "ivas_rom_com.h"
#include "ivas_rom_com_fx.h"
#include "wmc_auto.h"
#include "ivas_prot_fx.h"

@@ -144,9 +145,9 @@ ivas_error ivas_ism_config_fx(
    {
        /* combined format: decision about bitrates per channel - variable during the session (at one ivas_total_brate) */
        // bits_ism = (Word16) ( ism_total_brate / FRAMES_PER_SEC );
        bits_ism = extract_l( Mpy_32_32( 42949673, ism_total_brate ) ); // 42949673 is 1/FRAMES_PER_SEC in Q31
        tmp1 = BASOP_Util_Divide1616_Scale( bits_ism, n_ISms, &exp );   // Q15 - exp
        set16_fx( bits_element, shr( tmp1, sub( 15, exp ) ), n_ISms );
        bits_ism = extract_l( Mpy_32_32_r( ONE_BY_FRAMES_PER_SEC_Q31, ism_total_brate ) ); // Q0
        tmp1 = extract_l( Mpy_32_32_r( sub( bits_ism, bits_ism % n_ISms ), one_by_q_level[n_ISms] ) );
        set16_fx( bits_element, tmp1, n_ISms );
        bits_element[n_ISms - 1] = add( bits_element[n_ISms - 1], bits_ism % n_ISms ); // Q0
        move16();

@@ -156,11 +157,9 @@ ivas_error ivas_ism_config_fx(
    {
        /* ISM format: decision about bitrates per channel - constant during the session (at one ivas_total_brate) */
        // bits_ism = (Word16) ( ism_total_brate / FRAMES_PER_SEC );
        //  1 / 50 * 2 ^ 31 -- > 42949673, --> Q31,
        //(Q31 +Q0) - Q31 --> Q0
        bits_ism = extract_l( Mpy_32_32( 42949673, ism_total_brate ) ); // 42949673 is 1/FRAMES_PER_SEC in Q31
        tmp1 = BASOP_Util_Divide1616_Scale( bits_ism, n_ISms, &exp );   // Q15 - exp
        set16_fx( bits_element, shr( tmp1, sub( 15, exp ) ), n_ISms );
        bits_ism = extract_l( Mpy_32_32_r( ONE_BY_FRAMES_PER_SEC_Q31, ism_total_brate ) ); // Q0
        tmp1 = extract_l( Mpy_32_32_r( sub( bits_ism, bits_ism % n_ISms ), one_by_q_level[n_ISms] ) );
        set16_fx( bits_element, tmp1, n_ISms );
        bits_element[n_ISms - 1] = add( bits_element[n_ISms - 1], bits_ism % n_ISms ); // Q0
        move16();
        bitbudget_to_brate( bits_element, element_brate, n_ISms );
+6 −4
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include "options.h"
#include "ivas_cnst.h"
#include "ivas_prot_fx.h"
#include "ivas_rom_com_fx.h"
#include "prot_fx.h"
#include <stdint.h>
#include "wmc_auto.h"
@@ -56,7 +57,7 @@ ivas_error ivas_corecoder_dec_reconfig_fx(
{
    Word16 n, sce_id, cpe_id, output_frame;
    Word16 nSCE_existing, nCPE_existing;
    Word32 ivas_total_brate;
    Word32 tmp_br, ivas_total_brate;
    Word16 nchan_transport_real;
    MC_MODE last_mc_mode;
    DECODER_CONFIG_HANDLE hDecoderConfig;
@@ -409,9 +410,10 @@ ivas_error ivas_corecoder_dec_reconfig_fx(
        /* otherwise create extra dummy CPE */
        ELSE
        {
            Word32 quo, rem;
            iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &quo, &rem, 0 );
            IF( NE_32( ( error = create_cpe_dec( st_ivas, 0, quo ) ), IVAS_ERR_OK ) )
            /* i = ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) */
            n = add( st_ivas->nSCE, st_ivas->nCPE );
            tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[n] );
            IF( NE_32( ( error = create_cpe_dec( st_ivas, 0, tmp_br ) ), IVAS_ERR_OK ) )
            {
                return error;
            }
+27 −35
Original line number Diff line number Diff line
@@ -79,7 +79,6 @@ ivas_error ivas_cpe_dec_fx(
    ivas_error error;
    Word32 cpe_brate;
    Word32 element_brate_ref;
    Word32 quo, rem;

    error = IVAS_ERR_OK;
    move32();
@@ -261,9 +260,9 @@ ivas_error ivas_cpe_dec_fx(
    {
        IF( hCPE->hStereoTD->tdm_LRTD_flag )
        {
            iDiv_and_mod_32( L_shr( hCPE->element_brate, 1 ), FRAMES_PER_SEC, &quo, &rem, 0 );
            sts[0]->bits_frame_nominal = extract_l( quo );
            sts[1]->bits_frame_nominal = extract_l( quo );
            i = extract_l( Mpy_32_32_r( L_shr( hCPE->element_brate, 1 ), ONE_BY_FRAMES_PER_SEC_Q31 ) );
            sts[0]->bits_frame_nominal = i;
            sts[1]->bits_frame_nominal = i;
            move16();
            move16();
        }
@@ -308,23 +307,22 @@ ivas_error ivas_cpe_dec_fx(
            move32();
            IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
            {
                iDiv_and_mod_32( cpe_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
                sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( extract_l( quo ), 1 ), nb_bits_metadata );
                i = extract_l( Mpy_32_32_r( cpe_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
                sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( i, 1 ), nb_bits_metadata );
                IF( hCPE->brate_surplus < 0 )
                {
                    iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 );
                    quo = L_negate( quo );
                    i = negate( extract_l( Mpy_32_32_r( L_abs( hCPE->brate_surplus ), ONE_BY_FRAMES_PER_SEC_Q31 ) ) );
                }
                ELSE
                {
                    iDiv_and_mod_32( hCPE->brate_surplus, FRAMES_PER_SEC, &quo, &rem, 0 );
                    i = extract_l( Mpy_32_32_r( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ) );
                }
                sts[1]->bit_stream = sts[1]->bit_stream + extract_l( quo );
                sts[1]->bit_stream = sts[1]->bit_stream + i;
            }
            ELSE
            {
                iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
                sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( extract_l( quo ), 1 ), nb_bits_metadata );
                i = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
                sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( i, 1 ), nb_bits_metadata );
            }

            IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) )
@@ -353,9 +351,8 @@ ivas_error ivas_cpe_dec_fx(
                    nb_bits = sub( nb_bits, nb_bits_metadata );
                    IF( hCPE->brate_surplus < 0 )
                    {
                        iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 );
                        quo = L_negate( quo );
                        nb_bits = add( nb_bits, extract_l( quo ) );
                        i = negate( extract_l( Mpy_32_32_r( L_abs( hCPE->brate_surplus ), ONE_BY_FRAMES_PER_SEC_Q31 ) ) );
                        nb_bits = add( nb_bits, i );
                    }
                }

@@ -387,19 +384,17 @@ ivas_error ivas_cpe_dec_fx(
        /* signal bitrate for BW selection in the SCh */
        sts[0]->bits_frame_channel = 0;
        move16();
        iDiv_and_mod_32( hCPE->element_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
        sts[1]->bits_frame_channel = extract_l( quo );
        sts[1]->bits_frame_channel = extract_l( Mpy_32_32_r( hCPE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
        move16();
        IF( hCPE->brate_surplus < 0 )
        {
            iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 );
            quo = L_negate( quo );
            i = negate( extract_l( Mpy_32_32_r( L_abs( hCPE->brate_surplus ), ONE_BY_FRAMES_PER_SEC_Q31 ) ) );
        }
        ELSE
        {
            iDiv_and_mod_32( hCPE->brate_surplus, FRAMES_PER_SEC, &quo, &rem, 0 );
            i = extract_l( Mpy_32_32_r( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ) );
        }
        sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, extract_l( quo ) );
        sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, i );
        move16();
        IF( st_ivas->hQMetaData != NULL )
        {
@@ -417,14 +412,13 @@ ivas_error ivas_cpe_dec_fx(
        {
            IF( hCPE->brate_surplus < 0 )
            {
                iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 );
                quo = L_negate( quo );
                i = negate( extract_l( Mpy_32_32_r( L_abs( hCPE->brate_surplus ), ONE_BY_FRAMES_PER_SEC_Q31 ) ) );
            }
            ELSE
            {
                iDiv_and_mod_32( hCPE->brate_surplus, FRAMES_PER_SEC, &quo, &rem, 0 );
                i = extract_l( Mpy_32_32_r( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ) );
            }
            brate_surplus[0] = L_shr( L_mult( extract_l( L_shr( quo, 1 ) ), FRAMES_PER_SEC ), 1 );
            brate_surplus[0] = L_shr( L_mult( shr( i, 1 ), FRAMES_PER_SEC ), 1 );
            move32();
            brate_surplus[1] = L_sub( hCPE->brate_surplus, brate_surplus[0] );
            move32();
@@ -455,10 +449,9 @@ ivas_error ivas_cpe_dec_fx(
                sts[n]->total_brate = hCPE->element_brate;
                move32();
            }
            iDiv_and_mod_32( sts[n]->total_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
            sts[n]->bits_frame_nominal = extract_l( quo );
            iDiv_and_mod_32( hCPE->element_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
            sts[n]->bits_frame_channel = extract_l( L_shr( quo, sub( n_channels, 1 ) ) );
            sts[n]->bits_frame_nominal = extract_l( Mpy_32_32_r( sts[n]->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
            i = extract_l( Mpy_32_32_r( hCPE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
            sts[n]->bits_frame_channel = shr( i, sub( n_channels, 1 ) );
            move16();
            move16();

@@ -469,14 +462,13 @@ ivas_error ivas_cpe_dec_fx(
            {
                IF( brate_surplus[n] < 0 )
                {
                    iDiv_and_mod_32( L_abs( brate_surplus[n] ), FRAMES_PER_SEC, &quo, &rem, 0 );
                    quo = L_negate( quo );
                    i = negate( extract_l( Mpy_32_32_r( L_abs( brate_surplus[n] ), ONE_BY_FRAMES_PER_SEC_Q31 ) ) );
                }
                ELSE
                {
                    iDiv_and_mod_32( brate_surplus[n], FRAMES_PER_SEC, &quo, &rem, 0 );
                    i = extract_l( Mpy_32_32_r( brate_surplus[n], ONE_BY_FRAMES_PER_SEC_Q31 ) );
                }
                sts[n]->bits_frame_channel = add( sts[n]->bits_frame_channel, extract_l( quo ) );
                sts[n]->bits_frame_channel = add( sts[n]->bits_frame_channel, i );
                sts[n]->total_brate = L_add( sts[n]->total_brate, brate_surplus[n] );
                move16();
                move32();
@@ -580,8 +572,8 @@ ivas_error ivas_cpe_dec_fx(
        {
            tdm_configure_dec_fx( st_ivas->ivas_format, st_ivas->ism_mode, hCPE, &tdm_ratio_idx, nb_bits_metadata );

            iDiv_and_mod_32( sts[0]->total_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
            sts[1]->bit_stream = sts[0]->bit_stream + extract_l( quo );
            i = extract_l( Mpy_32_32_r( sts[0]->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
            sts[1]->bit_stream = sts[0]->bit_stream + i;
        }
        ELSE
        {
+4 −6
Original line number Diff line number Diff line
@@ -1254,7 +1254,6 @@ void ivas_dirac_dec_read_BS_fx(
{
    Word16 i, j, b, dir, orig_dirac_bands;
    Word16 next_bit_pos_orig;
    Word32 quo, rem;

    test();
    test();
@@ -1262,8 +1261,7 @@ void ivas_dirac_dec_read_BS_fx(
    {
        next_bit_pos_orig = st->next_bit_pos;
        move16();
        iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
        st->next_bit_pos = extract_l( L_sub( quo, 1 ) );
        st->next_bit_pos = sub( extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ), 1 );
        move16();
        if ( last_bit_pos > 0 )
        {
@@ -1358,11 +1356,11 @@ void ivas_dirac_dec_read_BS_fx(
        move16();

        /* subtract mode signaling bits, since bitstream was moved after mode reading */
        iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
        i = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
#ifdef NONBE_FIX_1052_SBA_EXT
        st->next_bit_pos = extract_l( L_sub( L_sub( quo, 1 ), SID_FORMAT_NBITS + SBA_PLANAR_BITS + SBA_ORDER_BITS ) );
        st->next_bit_pos = sub( sub( i, 1 ), SID_FORMAT_NBITS + SBA_PLANAR_BITS + SBA_ORDER_BITS );
#else
        st->next_bit_pos = extract_l( L_sub( L_sub( quo, 1 ), SID_FORMAT_NBITS ) );
        st->next_bit_pos = sub( sub( i, 1 ), SID_FORMAT_NBITS );
#endif

        move16();
Loading