Commit cb488f62 authored by emerit's avatar emerit
Browse files

Merge branch 'main' into update_crend

parents c812e1b6 40966946
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -1273,9 +1273,13 @@ enum
#define MASA_NO_POINTS_EQUATOR                  430
#define MASA_NO_CIRCLES                         121
#define MASA_ASIN_OFFSET                        0.0064471690266724975f
#define MASA_ASIN_OFFSET_Q15                    ( 211 )
#define MASA_NTOT2_FAC                          32768.00566947353f
#define MASA_NTOT2_FAC_Q15                      ( 1073741952 )
#define MASA_ANGLE_AT_EQUATOR                   0.012894427382667f
#define MASA_ANGLE_AT_EQUATOR_Q31               ( 27690572 )
#define MASA_ANGLE_AT_EQUATOR_DEG               0.738796268264740f
#define MASA_ANGLE_AT_EQUATOR_DEG_Q31           ( 1586552905l )
#define MASA_INV_ANGLE_AT_EQUATOR_DEG           1.353553128183453f
#define MASA_STEREO_MIN_BITRATE                 IVAS_24k4
#define MAXIMUM_OMASA_FREQ_BANDS                8                           /* Corresponds to maximum number of coding bands at 32 kbps */
@@ -1285,7 +1289,6 @@ enum
#define NBITS_HR_COH                            4

#define MASA_INV_ANGLE_AT_EQUATOR_DEG_Q30       (1453366656l)
#define MASA_ANGLE_AT_EQUATOR_DEG_Q31           (1586552905l)


#define MASA_JBM_RINGBUFFER_FRAMES              3
+132 −73
Original line number Diff line number Diff line
@@ -1416,153 +1416,212 @@ void deindex_sph_idx(
}

void deindex_sph_idx_fx(
    const uint16_t sphIndex,             /* i  : Spherical index            */
    const UWord16 sphIndex,              /* i  : Spherical index            */
    const SPHERICAL_GRID_DATA *gridData, /* i  : Prepared spherical grid    */
    Word32 *theta_fx,                    /* o  : Elevation                  */
    Word32 *phi_fx                       /* o  : Azimuth                    */
)
{
    // temp conversion as function using sin and cos
    float theta = (float) *theta_fx / ( 1 << 22 );
    float phi = (float) *phi_fx / ( 1 << 22 );


    float ba_crt, del_crt, div_crt, a4_crt;
    float estim;
    int32_t base_low, base_up;
    int16_t n_crt;
    int16_t id_th;
    int16_t sign_theta;
    int16_t id_phi;
    int16_t no_th = gridData->no_theta;
    const int16_t *n = gridData->no_phi;
    const float ba[3] = { 2.137991118026424e+02f, 1.244854404591542e+02f, 1.228408647140870e+02f };
    const float del[3] = { 7.998262115303199e+05f, 1.300883976959332e+06f, 1.424072242426373e+06f };
    const float div[3] = { -0.237662341081474f, -0.100938185496887f, -0.092050209205032f };
    const float a4[3] = { -8.415300425381099f, -19.814106922515204f, -21.727272727270197f };
    const uint16_t limit_index1 = 64964, limit_index2 = 47870;
    Word32 ba_crt_fx, del_crt_fx, div_crt_fx, a4_crt_fx;
    Word32 estim_fx;
    Word32 base_low, base_up;
    Word16 n_crt;
    Word16 id_th;
    Word16 sign_theta;
    Word16 id_phi;
    Word16 no_th = gridData->no_theta;
    const Word16 *n = gridData->no_phi;
    const Word32 ba_fx[3] = { 1793476992, 1044259584, 1030463872 };   /* Q23 */
    const Word32 del_fx[3] = { 819022016, 1332105216, 1458249984 };   /* Q10 */
    const Word32 div_fx[3] = { -510376000, -216763104, -197676320 };  /* Q31 */
    const Word32 a4_fx[3] = { -564741248, -1329702144, -1458092544 }; /* Q26 */
    const UWord16 limit_index1 = 64964, limit_index2 = 47870;
    Word32 tmp32;
    Word16 tmp16, tmp_e;
    move16();
    move16();

    if ( sphIndex >= limit_index1 )
    IF( GE_32( sphIndex, limit_index1 ) )
    {
        ba_crt = ba[2];
        div_crt = div[2];
        a4_crt = a4[2];
        del_crt = del[2];
        ba_crt_fx = ba_fx[2];
        move32();
        div_crt_fx = div_fx[2];
        move32();
        a4_crt_fx = a4_fx[2];
        move32();
        del_crt_fx = del_fx[2];
        move32();
    }
    else if ( sphIndex >= limit_index2 )
    ELSE IF( GE_32( sphIndex, limit_index2 ) )
    {
        ba_crt = ba[1];
        div_crt = div[1];
        a4_crt = a4[1];
        del_crt = del[1];
        ba_crt_fx = ba_fx[1];
        move32();
        div_crt_fx = div_fx[1];
        move32();
        a4_crt_fx = a4_fx[1];
        move32();
        del_crt_fx = del_fx[1];
        move32();
    }
    else
    ELSE
    {
        ba_crt = ba[0];
        div_crt = div[0];
        a4_crt = a4[0];
        del_crt = del[0];
        ba_crt_fx = ba_fx[0];
        move32();
        div_crt_fx = div_fx[0];
        move32();
        a4_crt_fx = a4_fx[0];
        move32();
        del_crt_fx = del_fx[0];
        move32();
    }
    estim = ba_crt + div_crt * sqrtf( del_crt + a4_crt * sphIndex );
    tmp32 = Mpy_32_32( a4_crt_fx, L_shl_sat( sphIndex, Q15 ) ); /* Q10 */
    tmp32 = L_add( del_crt_fx, tmp32 );                         /* Q10 */
    tmp16 = Q31 - Q10;
    tmp32 = Sqrt32( tmp32, &tmp16 );
    tmp32 = Mpy_32_32( div_crt_fx, tmp32 );
    tmp32 = L_shr( tmp32, sub( Q8, tmp16 ) ); /* Q23 */
    estim_fx = L_add( ba_crt_fx, tmp32 );     /* Q23 */

    if ( estim > MASA_NO_CIRCLES )
    if ( GT_32( estim_fx, MASA_NO_CIRCLES << Q23 ) )
    {
        estim = MASA_NO_CIRCLES;
        estim_fx = MASA_NO_CIRCLES << Q23;
        move32();
    }

    assert( estim > 0 );
    id_th = (int16_t) roundf( estim ) - 1;
    assert( estim_fx > 0 );
    id_th = sub( extract_l( L_shr_r( estim_fx, Q23 ) ), 1 ); /* Q0 */
    if ( id_th < 0 )
    {
        id_th = 0;
        move16();
    }

    if ( id_th == 0 )
    IF( id_th == 0 )
    {
        base_low = 0;
        move32();
        base_up = n[0];
        move32();
    }
    else
    ELSE
    {
        estim = MASA_ANGLE_AT_EQUATOR * (float) ( id_th - 0.5f );
        estim_fx = Mpy_32_32( MASA_ANGLE_AT_EQUATOR_Q31, L_sub( L_shl( id_th, Q22 ), 2097152 ) /* 0.5f in Q22 */ ); /* Q22 */
        base_low = n[0];
        if ( id_th >= 2 )
        move32();
        IF( GE_16( id_th, 2 ) )
        {
            if ( id_th == 2 )
            tmp32 = estim_fx % 26353590;                                     /* 2 * PI in Q22 */
            tmp32 = Mpy_32_32( tmp32, 341782638 /* 2147483647 / 2 * PI */ ); /* Q7 */
            tmp16 = extract_l( L_shr( tmp32, Q7 ) );

            tmp16 = getSineWord16R2( tmp16 );
            tmp16 = sub( tmp16, MASA_ASIN_OFFSET_Q15 );
            tmp32 = Mpy_32_16_1( MASA_NTOT2_FAC_Q15, tmp16 ); /* Q15 */

            IF( EQ_16( id_th, 2 ) )
            {
                base_low += 2 * (int16_t) ceilf( MASA_NTOT2_FAC * ( sinf( estim ) - MASA_ASIN_OFFSET ) );
                base_low = L_add( base_low, L_shl( extract_l( L_shr( ceil_fixed( tmp32, Q15 ), Q15 ) ), 1 ) ); /* Q0 */
            }
            else
            ELSE
            {
                base_low += 2 * (int16_t) roundf( MASA_NTOT2_FAC * ( sinf( estim ) - MASA_ASIN_OFFSET ) );
                base_low = L_add( base_low, L_shl( extract_l( L_shr_r( tmp32, Q15 ) ), 1 ) ); /* Q0 */
            }
        }
        base_up = base_low + 2 * n[id_th];
        base_up = L_add( base_low, L_shl( n[id_th], 1 ) );
    }

    sign_theta = 1;
    move16();

    n_crt = n[id_th];
    if ( sphIndex < base_low )
    move16();
    IF( LT_32( sphIndex, base_low ) )
    {
        id_th--;
        n_crt = n[id_th];
        if ( id_th == 0 )
        move16();
        IF( id_th == 0 )
        {
            base_low = 0;
            move32();
            base_up = n_crt;
            move32();
        }
        else
        ELSE
        {
            base_up = base_low;
            base_low -= 2 * n[id_th];
            move32();
            base_low = L_sub( base_low, shl( n[id_th], 1 ) );
        }
        assert( sphIndex >= base_low );
    }
    else if ( sphIndex >= base_up )
    ELSE IF( GE_32( sphIndex, base_up ) )
    {
        id_th++;
        n_crt = n[id_th];
        move16();
        base_low = base_up;
        base_up += 2 * n_crt;
        move32();
        base_up = L_add( base_up, shl( n_crt, 1 ) );
        assert( sphIndex < base_up );
    }

    id_phi = (int16_t) ( sphIndex - base_low );
    if ( sphIndex - base_low >= n_crt )
    id_phi = extract_l( L_sub( sphIndex, base_low ) );
    IF( GE_32( L_sub( sphIndex, base_low ), n_crt ) )
    {
        id_phi -= n_crt;
        id_phi = sub( id_phi, n_crt );
        sign_theta = -1;
        move16();
    }

    if ( id_th == 0 )
    IF( id_th == 0 )
    {
        theta = 0.f;
        phi = (float) sphIndex * 360 / (float) n_crt - 180;
        *theta_fx = 0;
        move32();
        tmp32 = imult3216( sphIndex, 360 );
        tmp16 = BASOP_Util_Divide3232_Scale( tmp32, n_crt, &tmp_e );
        tmp32 = L_shl( tmp16, add( Q7, tmp_e ) ); /* Q22 */
        *phi_fx = L_sub( tmp32, 180 << Q22 );     /* Q22 */
        move32();
    }
    else
    ELSE
    {
        if ( id_th == no_th - 1 )
        IF( EQ_16( id_th, sub( no_th, 1 ) ) )
        {
            id_phi = 0;
            phi = -180;
            theta = 90 * (float) sign_theta;
            move16();
            *phi_fx = -754974720; /* -180 in Q22 */
            move32();
            *theta_fx = L_shl( L_mult0( 90, sign_theta ), Q22 ); /* Q22 */
            move32();
        }
        else
        ELSE
        {
            theta = id_th * MASA_ANGLE_AT_EQUATOR_DEG * (float) sign_theta;
            if ( id_th % 2 == 0 )
            *theta_fx = Mpy_32_32( L_shl( id_th, Q22 ), MASA_ANGLE_AT_EQUATOR_DEG_Q31 ); /* Q22 */
            move32();
            if ( EQ_16( sign_theta, -1 ) )
            {
                phi = (float) id_phi * 360 / (float) n_crt - 180;
                *theta_fx = L_negate( *theta_fx ); /* Q22 */
                move32();
            }
            else
            IF( id_th % 2 == 0 )
            {
                tmp32 = L_mult0( id_phi, 360 );
                tmp16 = BASOP_Util_Divide3232_Scale( tmp32, n_crt, &tmp_e );
                tmp32 = L_shl( tmp16, add( Q7, tmp_e ) ); /* Q22 */
                *phi_fx = L_sub( tmp32, 180 << Q22 );     /* Q22 */
                move32();
            }
            ELSE
            {
                phi = ( (float) id_phi + 0.5f ) * 360 / (float) n_crt - 180;
                tmp32 = L_add( L_mult0( id_phi, 360 ), 180 );
                tmp16 = BASOP_Util_Divide3232_Scale( tmp32, n_crt, &tmp_e );
                tmp32 = L_shl( tmp16, add( Q7, tmp_e ) ); /* Q22 */
                *phi_fx = L_sub( tmp32, 180 << Q22 );     /* Q22 */
                move32();
            }
        }
    }
    *theta_fx = (Word32) ( theta * ( 1 << 22 ) );
    *phi_fx = (Word32) ( phi * ( 1 << 22 ) );
    return;
}

+2 −2
Original line number Diff line number Diff line
@@ -2109,7 +2109,7 @@ void ivas_jbm_dec_feed_tc_to_renderer(
    Word32 data_f_fx[MAX_CLDFB_DIGEST_CHANNELS][MAX_JBM_L_FRAME48k] = { 0 }; /* 'float' buffer for transport channels that will be directly converted with the CLDFB */
    Word32 *p_data_f_fx[MAX_CLDFB_DIGEST_CHANNELS];
    Word32 *data_fx;
    data_fx = (Word32 *) malloc( 8640 * sizeof( Word32 ) );
    data_fx = (Word32 *) malloc( ( add( imult1616( nSamplesForRendering, st_ivas->hTcBuffer->nchan_transport_jbm ), s_min( st_ivas->hTcBuffer->nchan_transport_jbm, st_ivas->hTcBuffer->nchan_buffer_full ) ) ) * sizeof( Word32 ) );

    IF( st_ivas->hTcBuffer )
    {
@@ -2135,7 +2135,7 @@ void ivas_jbm_dec_feed_tc_to_renderer(
    {
#ifdef IVAS_FLOAT_FIXED
#if 1
        floatToFixed_arrL( data, data_fx, 11, s_min( 3, st_ivas->hTcBuffer->nchan_transport_jbm ) * 2880 );
        floatToFixed_arrL( data, data_fx, 11, add( imult1616( nSamplesForRendering, st_ivas->hTcBuffer->nchan_transport_jbm ), s_min( st_ivas->hTcBuffer->nchan_transport_jbm, st_ivas->hTcBuffer->nchan_buffer_full ) ) );
#endif
        ivas_jbm_dec_copy_tc( st_ivas, nSamplesForRendering, nSamplesResidual, data_fx, p_data_f_fx, 11 );

+1 −1
Original line number Diff line number Diff line
@@ -388,7 +388,7 @@ void stereo_mdct_core_dec_fx(
            st = sts[ch];
            FOR( k = 0; k < nSubframes[ch]; k++ )
            {
                sns_interpolate_scalefactors_fx( sns_int_scf_fx, Aq_fx_32[ch], DEC );
                sns_interpolate_scalefactors_fx( sns_int_scf_fx, &Aq_fx_32[ch][k * M], DEC );

                IF( st->hTonalMDCTConc != NULL && EQ_16( add( k, 1 ), nSubframes[ch] ) )
                {
+18 −0
Original line number Diff line number Diff line
@@ -427,6 +427,7 @@ static void LoadBSplineBinaryITD(
    {
        modelITD->elevKSeq_dyn_fx[i] = float_to_fix( elevKSeq_dyn_local[i], Q22 );
    }
    free( elevKSeq_dyn_local );

    fread( &modelITD->azimDim3, sizeof( Word16 ), 1, f_hrtf );

@@ -437,6 +438,7 @@ static void LoadBSplineBinaryITD(
    {
        modelITD->azimKSeq_dyn_fx[i] = float_to_fix( azimKSeq_dyn_local[i], Q22 );
    }
    free( azimKSeq_dyn_local );

    fread( &tmp, sizeof( Word16 ), 1, f_hrtf );
    float *W_dyn_local = (float *) malloc( tmp * sizeof( float ) );
@@ -444,6 +446,7 @@ static void LoadBSplineBinaryITD(

    modelITD->W_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) );
    f2me_buf( W_dyn_local, modelITD->W_dyn_fx, &modelITD->W_dyn_e, tmp );
    free( W_dyn_local );

    /* azimuth */
    fread( modelITD->azimBsLen_dyn_fx, sizeof( Word16 ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf );
@@ -459,6 +462,7 @@ static void LoadBSplineBinaryITD(
    {
        modelITD->azimBsShape_dyn_fx[i] = float_to_fix( azimBsShape_dyn_local[i], Q30 );
    }
    free( azimBsShape_dyn_local );

    fread( &modelITD->azimSegSamples, sizeof( Word16 ), 1, f_hrtf );

@@ -476,6 +480,7 @@ static void LoadBSplineBinaryITD(
    {
        modelITD->elevBsShape_dyn_fx[i] = float_to_fix( elevBsShape_dyn_local[i], Q30 );
    }
    free( elevBsShape_dyn_local );

    fread( &modelITD->elevSegSamples, sizeof( Word16 ), 1, f_hrtf );

@@ -979,6 +984,7 @@ static ivas_error LoadBSplineBinary(
    {
        model->elevKSeq_dyn_fx[i] = float_to_fix( elevKSeq_dyn_local[i], Q22 );
    }
    free( elevKSeq_dyn_local );
#else
    model->elevKSeq_dyn = (float *) malloc( ( model->elevDim3 - 2 ) * sizeof( float ) );
    fread( model->elevKSeq_dyn, sizeof( float ), model->elevDim3 - 2, f_hrtf );
@@ -1009,11 +1015,16 @@ static ivas_error LoadBSplineBinary(
        {
            model->azimKSeq_fx[i][j] = float_to_fix( azimKSeq_local[i][j], Q22 );
        }
        free( azimKSeq_local[i] );
#else
        model->azimKSeq[i] = (float *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( float ) );
        fread( model->azimKSeq[i], sizeof( float ), ( model->azimDim3_dyn[i] + 1 ), f_hrtf );
#endif
    }
#ifdef IVAS_FLOAT_FIXED
    free( azimKSeq_local );
#endif

    fread( &model->AlphaN, sizeof( int16_t ), 1, f_hrtf );
#ifdef IVAS_FLOAT_FIXED
    float *AlphaL_dyn_local = (float *) malloc( model->AlphaN * model->K * sizeof( float ) );
@@ -1021,6 +1032,7 @@ static ivas_error LoadBSplineBinary(

    model->AlphaL_dyn_fx = (Word32 *) malloc( model->AlphaN * model->K * sizeof( Word32 ) );
    f2me_buf( AlphaL_dyn_local, model->AlphaL_dyn_fx, &model->AlphaL_dyn_e, model->AlphaN * model->K );
    free( AlphaL_dyn_local );
#else
    model->AlphaL_dyn = (float *) malloc( model->AlphaN * model->K * sizeof( float ) );
    fread( model->AlphaL_dyn, sizeof( float ), model->AlphaN * model->K, f_hrtf );
@@ -1032,6 +1044,7 @@ static ivas_error LoadBSplineBinary(

    model->AlphaR_dyn_fx = (Word32 *) malloc( model->AlphaN * model->K * sizeof( Word32 ) );
    f2me_buf( AlphaR_dyn_local, model->AlphaR_dyn_fx, &model->AlphaR_dyn_e, model->AlphaN * model->K );
    free( AlphaR_dyn_local );
#else
    model->AlphaR_dyn = (float *) malloc( model->AlphaN * model->K * sizeof( float ) );
    fread( model->AlphaR_dyn, sizeof( float ), model->AlphaN * model->K, f_hrtf );
@@ -1060,12 +1073,16 @@ static ivas_error LoadBSplineBinary(
        {
            model->azimBsShape_dyn_fx[i][j] = float_to_fix( azimBsShape_dyn_local[i][j], Q30 );
        }
        free( azimBsShape_dyn_local[i] );
#else
        model->azimBsShape_dyn[i] = (float *) malloc( tmp * sizeof( float ) );
        fread( model->azimBsShape_dyn[i], sizeof( float ), tmp, f_hrtf );
#endif
        fread( &model->azimSegSamples_dyn[i], sizeof( int16_t ), 1, f_hrtf );
    }
#ifdef IVAS_FLOAT_FIXED
    free( azimBsShape_dyn_local );
#endif // IVAS_FLOAT_FIXED

    model->azimShapeIdx_dyn = (int16_t *) malloc( model->elevDim3 * sizeof( int16_t ) );
    fread( model->azimShapeIdx_dyn, sizeof( int16_t ), model->elevDim3, f_hrtf );
@@ -1091,6 +1108,7 @@ static ivas_error LoadBSplineBinary(
    {
        model->elevBsShape_dyn_fx[i] = float_to_fix( elevBsShape_dyn_local[i], Q30 );
    }
    free( elevBsShape_dyn_local );
#else
    model->elevBsShape_dyn = (float *) malloc( tmp * sizeof( float ) );
    fread( model->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf );