Commit 740ab8e3 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

ivas_omasa_com functions converted to fixed point.

[x] Below functions present in ivas_omasa_com file are converted
to fixed point.
ivas_omasa_ism_mode_select
ivas_set_omasa_TC
ivas_interformat_brate
ivas_combined_format_brate_sanity
bits_index_ism_ratio
calculate_nbits_meta
ivas_get_stereo_panning_gains - does not get hit by any test stream,
test is done through unit testing.
parent 4902c702
Loading
Loading
Loading
Loading
Loading
+676 −5
Original line number Diff line number Diff line
@@ -35,7 +35,9 @@
#include "ivas_cnst.h"
#include "ivas_prot.h"
#include "prot.h"
#include "prot_fx1.h"
#include "ivas_rom_com.h"
#include "rom_com.h"
#include <math.h>

/*---------------------------------------------------------------
@@ -58,6 +60,23 @@
#define GAMMA_ISM_MEDIUM_IMP4 1.0f
#define GAMMA_ISM_HIGH_IMP4   1.2f

#ifdef IVAS_FLOAT_FIXED
#define GAMMA_ISM_LOW_IMP_FX    26215 /*0.8f in Q15*/
#define GAMMA_ISM_MEDIUM_IMP_FX 39322 /*1.2f in Q15*/
#define GAMMA_ISM_HIGH_IMP_FX   45876 /*1.4f in Q15*/

#define GAMMA_ISM_LOW_IMP2_FX    29492 /*0.9f in Q15*/
#define GAMMA_ISM_MEDIUM_IMP2_FX 39322 /*1.2f in Q15*/
#define GAMMA_ISM_HIGH_IMP2_FX   44237 /*1.35f in Q15*/

#define GAMMA_ISM_LOW_IMP3_FX    27853 /*0.85f in Q15*/
#define GAMMA_ISM_MEDIUM_IMP3_FX 37684 /*1.15f in Q15*/
#define GAMMA_ISM_HIGH_IMP3_FX   42599 /*1.3f in Q15*/

#define GAMMA_ISM_LOW_IMP4_FX    26215 /*0.8f in Q15*/
#define GAMMA_ISM_MEDIUM_IMP4_FX 32768 /*1.0f in Q15*/
#define GAMMA_ISM_HIGH_IMP4_FX   39322 /*1.2f in Q15*/
#endif

/*---------------------------------------------------------------
 * ivas_omasa_ism_mode_select()
@@ -67,6 +86,94 @@
 * ---------------------------------------------------------------*/

/*! r : ISM format mode */
#ifdef IVAS_FLOAT_FIXED
ISM_MODE ivas_omasa_ism_mode_select(
    const Word32 ivas_total_brate, /* i  : IVAS total bitrate      */
    const Word16 nchan_ism         /* i  : number of input ISM's   */
)
{
    ISM_MODE ism_mode = ISM_MODE_NONE;
	move16();

    SWITCH( nchan_ism )
    {
        case 1:
            IF( GE_32( ivas_total_brate, IVAS_24k4 ) )
            {
                ism_mode = ISM_MASA_MODE_DISC;
				move16();
            }
            ELSE
            {
                ism_mode = ISM_MODE_NONE;
				move16();
            }
            BREAK;
        case 2:
            IF( GE_32( ivas_total_brate, IVAS_48k ) )
            {
                ism_mode = ISM_MASA_MODE_DISC;
				move16();
            }
            ELSE IF( GE_32( ivas_total_brate, IVAS_32k ) )
            {
                ism_mode = ISM_MASA_MODE_PARAM_ONE_OBJ;
				move16();
            }
            ELSE
            {
                ism_mode = ISM_MODE_NONE;
				move16();
            }
            BREAK;
        case 3:
            IF( GE_32( ivas_total_brate, IVAS_96k ) )
            {
                ism_mode = ISM_MASA_MODE_DISC;
				move16();
            }
            ELSE IF( GE_32( ivas_total_brate, IVAS_64k ) )
            {
                ism_mode = ISM_MASA_MODE_PARAM_ONE_OBJ;
				move16();
            }
            ELSE IF( GE_32( ivas_total_brate, IVAS_32k ) )
            {
                ism_mode = ISM_MASA_MODE_MASA_ONE_OBJ;
				move16();
            }
            ELSE
            {
                ism_mode = ISM_MODE_NONE;
				move16();
            }
            BREAK;
        case 4:
            IF( GE_32( ivas_total_brate, IVAS_128k ) )
            {
                ism_mode = ISM_MASA_MODE_DISC;
				move16();
            }
            ELSE IF( GE_32( ivas_total_brate, IVAS_64k ) )
            {
                ism_mode = ISM_MASA_MODE_PARAM_ONE_OBJ;
				move16();
            }
            ELSE IF( GE_32( ivas_total_brate, IVAS_32k ) )
            {
                ism_mode = ISM_MASA_MODE_MASA_ONE_OBJ;
				move16();
            }
            ELSE
            {
                ism_mode = ISM_MODE_NONE;
            }
            BREAK;
    }

    return ism_mode;
}
#else
ISM_MODE ivas_omasa_ism_mode_select(
    const int32_t ivas_total_brate, /* i  : IVAS total bitrate      */
    const int16_t nchan_ism         /* i  : number of input ISM's   */
@@ -140,7 +247,7 @@ ISM_MODE ivas_omasa_ism_mode_select(

    return ism_mode;
}

#endif

/*---------------------------------------------------------------
 * ivas_set_omasa_TC()
@@ -148,6 +255,42 @@ ISM_MODE ivas_omasa_ism_mode_select(
 * set number of transport channels in OMASA format
 * ---------------------------------------------------------------*/

#ifdef IVAS_FLOAT_FIXED
void ivas_set_omasa_TC(
    const ISM_MODE ism_mode, /* i  : ISM mode                   */
    const Word16 nchan_ism,  /* i  : number of input ISMs       */
    Word16 *nSCE,            /* o  : number of SCEs             */
    Word16 *nCPE             /* o  : number of CPEs             */
)
{
    SWITCH( ism_mode )
    {
        case ISM_MASA_MODE_MASA_ONE_OBJ:
        case ISM_MASA_MODE_PARAM_ONE_OBJ:
            *nCPE = 1;
            move16();
            *nSCE = 1;
            move16();
            BREAK;
        case ISM_MASA_MODE_DISC:
            *nCPE = 1;
            move16();
            *nSCE = nchan_ism;
            move16();
            BREAK;
        case ISM_MODE_NONE:
            *nCPE = 1;
            move16();
            *nSCE = 0;
            move16();
            BREAK;
        default:
            BREAK;
    }

    return;
}
#else
void ivas_set_omasa_TC(
    const ISM_MODE ism_mode, /* i  : ISM mode                   */
    const int16_t nchan_ism, /* i  : number of input ISMs       */
@@ -176,7 +319,7 @@ void ivas_set_omasa_TC(

    return;
}

#endif

/*---------------------------------------------------------------
 * ivas_interformat_brate()
@@ -185,6 +328,149 @@ void ivas_set_omasa_TC(
 * ---------------------------------------------------------------*/

/*! r: adjusted bitrate */
#ifdef IVAS_FLOAT_FIXED
Word32 ivas_interformat_brate(
    const ISM_MODE ism_mode,    /* i  : ISM mode                           */
    const Word16 nchan_ism,     /* i  : number of ISM channels             */
    const Word32 element_brate, /* i  : element bitrate                    */
    const Word16 ism_imp,       /* i  : ISM importance flag                */
    const Word16 limit_flag     /* i  : flag to limit the bitrate increase */
)
{
    Word32 element_brate_out;
    Word16 nBits, limit_low, limit_high;

    nBits = extract_l( div_l( element_brate, shr( FRAMES_PER_SEC, 1 ) ) );

    IF( EQ_16( ism_imp, ISM_INACTIVE_IMP ) )
    {
        nBits = BITS_ISM_INACTIVE;
        move16();
    }
    ELSE
    {
        IF( EQ_16( (Word16) ism_mode, (Word16) ISM_MASA_MODE_DISC ) && ( ( EQ_16( nchan_ism, 4 ) && EQ_32( element_brate, 24000 ) ) || ( EQ_16( nchan_ism, 3 ) && LE_32( element_brate, 24000 ) ) || ( EQ_16( nchan_ism, 2 ) && LE_32( element_brate, 11000 ) ) ) ) /* for border case in DISC mode */
        {
            IF( EQ_16( limit_flag, 1 ) && ( ( EQ_16( nchan_ism, 4 ) && EQ_32( element_brate, 24000 ) ) || ( EQ_16( nchan_ism, 3 ) && EQ_32( element_brate, 20000 ) ) || ( EQ_16( nchan_ism, 2 ) && LE_32( element_brate, 11000 ) ) ) )
            {
                return element_brate;
            }

            IF( EQ_16( ism_imp, ISM_LOW_IMP ) )
            {
                nBits = extract_l( Mpy_32_16_1( GAMMA_ISM_LOW_IMP4_FX, nBits ) );
            }
            ELSE IF( EQ_16( ism_imp, ISM_MEDIUM_IMP ) )
            {
                nBits = extract_l( Mpy_32_16_1( GAMMA_ISM_MEDIUM_IMP4_FX, nBits ) );
                IF( EQ_16( limit_flag, -1 ) )
                {
                    nBits = extract_l( Mpy_32_16_1( GAMMA_ISM_HIGH_IMP4_FX, nBits ) );
                }
            }
            ELSE /* ISM_HIGH_IMP */
            {
                nBits = extract_l( Mpy_32_16_1( GAMMA_ISM_HIGH_IMP4_FX, nBits ) );
                IF( EQ_16( limit_flag, -1 ) )
                {
                    nBits = extract_l( Mpy_32_16_1( GAMMA_ISM_HIGH_IMP4_FX, nBits ) );
                }
            }
        }
        ELSE IF( EQ_16( (Word16) ism_mode, (Word16) ISM_MASA_MODE_PARAM_ONE_OBJ ) ||
                 ( EQ_16( (Word16) ism_mode, (Word16) ISM_MASA_MODE_DISC ) && EQ_32( element_brate, 9600 ) ) /* this condition corresponds to the ivas_total_brate = 24400 and 1 object */
        )
        {
            IF( EQ_16( (Word16) ism_mode, (Word16) ISM_MASA_MODE_PARAM_ONE_OBJ ) && EQ_32( element_brate, IVAS_13k2 ) )
            {
                IF( EQ_16( ism_imp, ISM_LOW_IMP ) )
                {
                    nBits = extract_l( Mpy_32_16_1( GAMMA_ISM_LOW_IMP3_FX, nBits ) );
                }
                ELSE IF( EQ_16( ism_imp, ISM_MEDIUM_IMP ) )
                {
                    nBits = extract_l( Mpy_32_16_1( GAMMA_ISM_MEDIUM_IMP3_FX, nBits ) );
                }
                ELSE /* ISM_HIGH_IMP */
                {
                    nBits = extract_l( Mpy_32_16_1( GAMMA_ISM_HIGH_IMP4_FX, nBits ) );
                }
            }
            ELSE
            {
                IF( EQ_16( ism_imp, ISM_LOW_IMP ) )
                {
                    nBits = extract_l( Mpy_32_16_1( GAMMA_ISM_LOW_IMP3_FX, nBits ) );
                }
                ELSE IF( EQ_16( ism_imp, ISM_MEDIUM_IMP ) )
                {
                    nBits = extract_l( Mpy_32_16_1( GAMMA_ISM_MEDIUM_IMP3_FX, nBits ) );
                }
                ELSE /* ISM_HIGH_IMP */
                {
                    nBits = extract_l( Mpy_32_16_1( GAMMA_ISM_HIGH_IMP3_FX, nBits ) );
                }
            }
        }
        ELSE IF( EQ_16( (Word16) ism_mode, (Word16) ISM_MASA_MODE_MASA_ONE_OBJ ) && EQ_32( element_brate, 16000 ) )
        {
            IF( EQ_16( ism_imp, ISM_LOW_IMP ) )
            {
                nBits = extract_l( Mpy_32_16_1( GAMMA_ISM_LOW_IMP_FX, nBits ) );
            }
            ELSE IF( EQ_16( ism_imp, ISM_MEDIUM_IMP ) )
            {
                nBits = extract_l( Mpy_32_16_1( GAMMA_ISM_MEDIUM_IMP_FX, nBits ) );
            }
            ELSE /* ISM_HIGH_IMP */
            {
                nBits = extract_l( Mpy_32_16_1( GAMMA_ISM_HIGH_IMP3_FX, nBits ) );
            }
        }
        ELSE
        {
            IF( EQ_16( ism_imp, ISM_LOW_IMP ) )
            {
                nBits = extract_l( Mpy_32_16_1( GAMMA_ISM_LOW_IMP_FX, nBits ) );
            }
            ELSE IF( EQ_16( ism_imp, ISM_MEDIUM_IMP ) )
            {
                nBits = extract_l( Mpy_32_16_1( GAMMA_ISM_MEDIUM_IMP_FX, nBits ) );
            }
            ELSE /* ISM_HIGH_IMP */
            {
                nBits = extract_l( Mpy_32_16_1( GAMMA_ISM_HIGH_IMP_FX, nBits ) );
            }
        }
    }

    limit_low = MIN_BRATE_SWB_BWE / FRAMES_PER_SEC;
    IF( EQ_16( ism_imp, ISM_INACTIVE_IMP ) )
    {
        limit_low = BITS_ISM_INACTIVE;
        move16();
    }
    ELSE IF( GE_32( element_brate, SCE_CORE_16k_LOW_LIMIT ) )
    {
        limit_low = SCE_CORE_16k_LOW_LIMIT / FRAMES_PER_SEC;
        move16();
    }

    limit_high = IVAS_512k / FRAMES_PER_SEC;
    move16();
    IF( LE_32( element_brate, SCE_CORE_16k_LOW_LIMIT ) )
    {
        limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC;
        move16();
    }

    nBits = check_bounds_s( nBits, limit_low, limit_high );

    element_brate_out = L_mult0( nBits, FRAMES_PER_SEC );

    return element_brate_out;
}
#else
int32_t ivas_interformat_brate(
    const ISM_MODE ism_mode,     /* i  : ISM mode                           */
    const int16_t nchan_ism,     /* i  : number of ISM channels             */
@@ -321,7 +607,7 @@ int32_t ivas_interformat_brate(

    return element_brate_out;
}

#endif

/*---------------------------------------------------------------
 * ivas_combined_format_brate_sanity()
@@ -329,6 +615,64 @@ int32_t ivas_interformat_brate(
 * Sanity check in combined format coding
 * ---------------------------------------------------------------*/

#ifdef IVAS_FLOAT_FIXED
void ivas_combined_format_brate_sanity(
    const Word32 element_brate,       /* i  : element bitrate                */
    const Word16 core,                /* i  : core                           */
    const Word32 total_brate,         /* i  : total bitrate                  */
    Word32 *core_brate,               /* i/o: core bitrate                   */
    Word16 *inactive_coder_type_flag, /* o  : inactive coder_type flag       */
    Word16 *diff_nBits                /* o  : number of differential bits    */
)
{
    Word16 limit_high, nBits;
    Word32 brate_diff;

    brate_diff = L_sub( total_brate, *core_brate );

    /* sanity check: at lowest IVAS bit-rates and one ISM channel coded by
    low-rate core-coder mode, it can happen that the CPE (MASA) bit-budget
    for ACELP core-coding @12.8 kHz is too high */

    IF( LT_32( element_brate, ACELP_12k8_HIGH_LIMIT ) )
    {
        limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC;
		move16();
        nBits = extract_l( div_l( *core_brate, shr( FRAMES_PER_SEC, 1 ) ) );

        *diff_nBits = sub( nBits, limit_high );
        IF( GT_16( *diff_nBits, 0 ) )
        {
            IF( EQ_16( core, TCX_20_CORE ) || EQ_16( core, TCX_10_CORE ) )
            {
                *diff_nBits = 0;
                move16();
            }
            ELSE /* ACELP core */
            {
                *core_brate = L_sub( *core_brate, L_mult0( *diff_nBits, FRAMES_PER_SEC ) );
            }
        }
    }

    /*-----------------------------------------------------------------*
     * set inactive coder_type flag in ACELP core
     *-----------------------------------------------------------------*/

    IF( EQ_16( core, ACELP_CORE ) )
    {
        *inactive_coder_type_flag = 0; /* AVQ by default */
		move16();
        IF( LE_32( L_add( *core_brate, brate_diff ), MAX_GSC_INACTIVE_BRATE ) )
        {
            *inactive_coder_type_flag = 1; /* GSC */
            move16();
        }
    }

    return;
}
#else
void ivas_combined_format_brate_sanity(
    const int32_t element_brate,       /* i  : element bitrate                */
    const int16_t core,                /* i  : core                           */
@@ -381,7 +725,7 @@ void ivas_combined_format_brate_sanity(

    return;
}

#endif

/*---------------------------------------------------------------
 * bits_index_ism_ratio()
@@ -390,6 +734,38 @@ void ivas_combined_format_brate_sanity(
 * ---------------------------------------------------------------*/

/*!r : number of bits for ISM ratio index */
#ifdef IVAS_FLOAT_FIXED
Word16 bits_index_ism_ratio(
    const Word16 nchan_ism /* i  : number of objects    */
)
{
    Word16 bits_index;

    bits_index = 0;
    move16();
    IF( EQ_16( nchan_ism, 2 ) )
    {
        bits_index = 3;
        move16();
    }
    ELSE IF( EQ_16( nchan_ism, 3 ) )
    {
        bits_index = 6;
        move16();
    }
    ELSE IF( EQ_16( nchan_ism, 4 ) )
    {
        bits_index = 7;
        move16();
    }
    ELSE
    {
        assert( ( nchan_ism >= 2 && nchan_ism <= 4 ) && "Wrong number of objects for MASA_ISM." );
    }

    return bits_index;
}
#else
int16_t bits_index_ism_ratio(
    const int16_t nchan_ism /* i  : number of objects    */
)
@@ -416,7 +792,7 @@ int16_t bits_index_ism_ratio(

    return bits_index;
}

#endif

/*---------------------------------------------------------------
 * calculate_nbits_meta()
@@ -424,6 +800,7 @@ int16_t bits_index_ism_ratio(
 *
 * ---------------------------------------------------------------*/


void calculate_nbits_meta(
    const int16_t nchan_ism,
    float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS],
@@ -476,12 +853,116 @@ void calculate_nbits_meta(
            }
        }
        bits_ism[obj] = bits_direction_masa[0] - (int16_t) ( ( 1 - ( (int16_t) ( priority[obj] * 1000.0f ) ) * 0.001f ) * 6 );
        // bits_ism[obj] = bits_direction_masa[0] - (int16_t) ( ( 1 -  ( priority[obj] ) ) * 6 );
    }

    return;
}
#ifdef IVAS_FLOAT_FIXED
static Word16 get_bits_ism( Word32 val )
{
    Word16 res;
    IF( LE_32( val, 536870912 ) && GT_32( val, 447750340 ) )
    {
        res = 0;
        move16();
    }
    ELSE IF( LE_32( val, 447750340 ) && GT_32( val, 358092897 ) )
    {
        res = 1;
        move16();
    }
    ELSE IF( LE_32( val, 358092897 ) && GT_32( val, 268972326 ) )
    {
        res = 2;
        move16();
    }
    ELSE IF( LE_32( val, 268972326 ) && GT_32( val, 179314884 ) )
    {
        res = 3;
        move16();
    }
    ELSE IF( LE_32( val, 179314884 ) && GT_32( val, 89657442 ) )
    {
        res = 4;
        move16();
    }
    ELSE IF( LE_32( val, 89657442 ) && GT_32( val, 536870 ) )
    {
        res = 5;
        move16();
    }
    ELSE
    {
        res = 6;
        move16();
    }
    return res;
}


void calculate_nbits_meta_fx(
    const Word16 nchan_ism,
    Word32 q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], // Qx
    Word32 masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS],          // Qx
    const Word16 numSf,
    const Word16 numCodingBands,
    Word16 *bits_ism,
    const Word16 idx_sep_obj,
    const Word16 ism_imp )
{
    Word16 sf, band, obj;
    Word32 priority[MAX_NUM_OBJECTS], max_p;

    IF( GT_16( nchan_ism, 1 ) )
    {
        set32_fx( priority, 0, nchan_ism );
        FOR( sf = 0; sf < numSf; sf++ )
        {
            FOR( band = 0; band < numCodingBands; band++ )
            {
                FOR( obj = 0; obj < nchan_ism; obj++ )
                {
                    priority[obj] = max( priority[obj], ( Mpy_32_32( q_energy_ratio_ism[sf][band][obj], L_sub( 1073741824, masa_to_total_energy_ratio[sf][band] ) ) ) ); // Qx - 1
                    move32();
                }
            }
        }
    }
    ELSE
    {
        priority[0] = 536870912;
    }

    /* decide parameters for ISM metadata quantization */
    maximum_32_fx( priority, nchan_ism, &max_p );
    FOR( obj = 0; obj < nchan_ism; obj++ )
    {
        IF( EQ_16( obj, idx_sep_obj ) )
        {
            IF( EQ_16( ism_imp, 3 ) )
            {
                priority[obj] = 536870912;
                move32();
            }
            ELSE IF( EQ_16( ism_imp, 2 ) )
            {
                priority[obj] = L_shr( L_add( 536870912, max_p ), 1 );
                move32();
            }
            ELSE
            {
                priority[obj] = max_p;
                move32();
            }
        }
        bits_ism[obj] = sub( bits_direction_masa[0], get_bits_ism( priority[obj] ) );
        move16();
    }
    return;
}
#endif

/*---------------------------------------------------------------
 * ivas_get_stereo_panning_gains()
 *
@@ -525,6 +1006,149 @@ void ivas_get_stereo_panning_gains(
    return;
}

#ifdef IVAS_FLOAT_FIXED

#define SIN_NEG_30_DEGREES_Q15 ( (Word16) 0xC000 )
#define SIN_30_DEGREES_Q15     ( (Word16) 0x4000 )

static void get_panning_gain(
    const Word16 sinAngleMapped,
    Word16 *panningGains )
{
    Word16 tbl_len = 601;
    Word16 idx = shr( tbl_len, 1 );
    const Word16 *ptr_sin = &ivas_sine_panning_tbl_fx[0];
    const Word16 *ptr_tan_0 = ivas_tan_panning_gain_tbl_fx;

    Word16 lim_l = 0;
    move16();
    Word16 lim_r = tbl_len;
    move16();

    WHILE( 1 )
    {
        idx = shr( add( lim_l, lim_r ), 1 );
        IF( GE_16( idx, tbl_len ) )
        {
            panningGains[0] = ptr_tan_0[tbl_len - 1];
            move16();
            panningGains[1] = ptr_tan_0[0];
            move16();
            BREAK;
        }
        ELSE IF( LT_16( idx, 0 ) )
        {
            panningGains[0] = ptr_tan_0[0];
            move16();
            panningGains[1] = ptr_tan_0[tbl_len - 1];
            move16();
            BREAK;
        }
        ELSE IF( LE_16( sinAngleMapped, ptr_sin[idx + 1] ) && GE_16( sinAngleMapped, ptr_sin[idx] ) )
        {
            IF( EQ_16( sinAngleMapped, ptr_sin[idx + 1] ) )
            {
                panningGains[0] = ptr_tan_0[idx + 1];
                move16();
                panningGains[1] = ptr_tan_0[tbl_len - idx - 2];
                move16();
                BREAK;
            }
            ELSE IF( EQ_16( sinAngleMapped, ptr_sin[idx] ) )
            {
                panningGains[0] = ptr_tan_0[idx];
                move16();
                panningGains[1] = ptr_tan_0[tbl_len - idx - 1];
                move16();
                BREAK;
            }
            ELSE
            {
                Word16 mid = extract_l( L_shr( L_add( L_deposit_l( ptr_sin[idx] ), L_deposit_l( ptr_sin[idx + 1] ) ), 1 ) );
                IF( LE_16( sinAngleMapped, mid ) )
                {
                    panningGains[0] = ptr_tan_0[idx];
                    move16();
                    panningGains[1] = ptr_tan_0[tbl_len - idx - 1];
                    move16();
                }
                ELSE
                {
                    panningGains[0] = ptr_tan_0[idx + 1];
                    move16();
                    panningGains[1] = ptr_tan_0[tbl_len - idx - 2];
                    move16();
                }
                BREAK;
            }
        }
        ELSE IF( GT_16( sinAngleMapped, ptr_sin[idx] ) )
        {
            lim_l = add( idx, 1 );
            move16();
        }
        ELSE IF( LT_16( sinAngleMapped, ptr_sin[idx] ) )
        {
            lim_r = sub( idx, 1 );
            move16();
        }
    }
}


void ivas_get_stereo_panning_gains_fx(
    const Word16 aziDeg,
    const Word16 eleDeg,
    Word16 panningGains[2] )
{
    /* Convert azi and ele to an azi value of the cone of confusion */
    Word16 azAddEl = add( aziDeg, eleDeg );
    Word16 azSubEl = sub( aziDeg, eleDeg );

    const Word16 *ptr_sin_az = ivas_sin_az_fx;

    WHILE( GT_16( azAddEl, 180 ) )
    {
        azAddEl = sub( azAddEl, 360 );
    }
    WHILE( LT_16( azAddEl, -180 ) )
    {
        azAddEl = add( azAddEl, 360 );
    }
    WHILE( GT_16( azSubEl, 180 ) )
    {
        azSubEl = sub( azSubEl, 360 );
    }
    WHILE( LT_16( azSubEl, -180 ) )
    {
        azSubEl = sub( azSubEl, 360 );
    }
    // sin_az_cos_el = (ptr_sin_az[azAddEl] + ptr_sin_az[azSubEl])/2;
    Word16 sin_az_cos_el = extract_l( L_shr( L_add( L_deposit_l( ptr_sin_az[azAddEl] ), L_deposit_l( ptr_sin_az[azSubEl] ) ), 1 ) );

    IF( GE_16( sin_az_cos_el, SIN_30_DEGREES_Q15 ) )
    { /* Left side */
        panningGains[0] = (Word16) 0x7fff;
        move16();
        panningGains[1] = 0;
        move16();
    }
    ELSE IF( LE_16( sin_az_cos_el, SIN_NEG_30_DEGREES_Q15 ) )
    { /* Right side */
        panningGains[0] = 0;
        move16();
        panningGains[1] = (Word16) 0x7fff;
        move16();
    }
    ELSE /* Tangent panning law */
    {
        get_panning_gain( sin_az_cos_el, panningGains );
    }

    return;
}
#endif


/*---------------------------------------------------------------
 * calculate_brate_limit_flag()
@@ -533,6 +1157,52 @@ void ivas_get_stereo_panning_gains(
 *---------------------------------------------------------------*/

/*! r: limitation flag */
#ifdef IVAS_FLOAT_FIXED
Word16 calculate_brate_limit_flag(
    const Word16 ism_imp[], /* i  : ISM importance flags   */
    const Word16 nchan_ism  /* i  : number of objects      */
)
{
    Word16 n;
    Word16 brate_limit_flag;
    Word16 nzeros;
    Word16 nchan_ism_sat;

    brate_limit_flag = 0;
    move16();
    nzeros = 0;
    move16();
    FOR( n = 0; n < nchan_ism; n++ )
    {
        brate_limit_flag = add( brate_limit_flag, ism_imp[n] );
        IF( EQ_16( ism_imp[n], 0 ) )
        {
            nzeros = add( nzeros, 1 );
        }
    }
    nchan_ism_sat = nchan_ism;
    IF( EQ_16( nchan_ism & 1, 1 ) )
    {
        nchan_ism_sat = sub( nchan_ism, 1 );
    }

    IF( GE_16( i_mult( 2, brate_limit_flag ), add( i_mult( 4, nchan_ism ), nchan_ism_sat ) ) )
    {
        brate_limit_flag = 1;
        move16();
    }
    ELSE
    {
        IF( GE_16( i_mult( 2, nzeros ), nchan_ism ) )
        {
            brate_limit_flag = -1; /* there is no limitation, on the contrary */
            move16();
        }
    }

    return brate_limit_flag;
}
#else
int16_t calculate_brate_limit_flag(
    const int16_t ism_imp[], /* i  : ISM importance flags   */
    const int16_t nchan_ism  /* i  : number of objects      */
@@ -567,3 +1237,4 @@ int16_t calculate_brate_limit_flag(

    return brate_limit_flag;
}
#endif
 No newline at end of file
+14 −0
Original line number Diff line number Diff line
@@ -8127,4 +8127,18 @@ void save_synthesis_hq_fec_fx(
    const Word16 output_frame, /* i  : decoded synthesis           */
    CPE_DEC_HANDLE hCPE        /* i  : CPE decoder structure       */
);
void calculate_nbits_meta_fx(
    const Word16 nchan_ism,
    Word32 q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], // Qx
    Word32 masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS],          // Qx
    const Word16 numSf,
    const Word16 numCodingBands,
    Word16 *bits_ism,
    const Word16 idx_sep_obj,
    const Word16 ism_imp );

void ivas_get_stereo_panning_gains_fx(
    const Word16 aziDeg,
    const Word16 eleDeg,
    Word16 panningGains[2] );
#endif
+213 −4

File changed.

Preview size limit exceeded, changes collapsed.

+4 −0
Original line number Diff line number Diff line
@@ -2053,4 +2053,8 @@ extern const Word16 pow_tilt_32k[64]; /* Q7 */

//ivas_lfe_dec_fx.c
extern const Word32 tbl_two_pow_shift_by_4[35]; /* Q30 */

extern const Word16 ivas_tan_panning_gain_tbl_fx[601];
extern const Word16 ivas_sine_panning_tbl_fx[601];
extern const Word16 ivas_sin_az_fx[361];
#endif
+18 −2

File changed.

Preview size limit exceeded, changes collapsed.

Loading