Commit 73eeb573 authored by emerit's avatar emerit
Browse files

Merge branch 'main' into update_crend

parents 48153876 1da67e09
Loading
Loading
Loading
Loading
+160 −8
Original line number Diff line number Diff line
@@ -601,6 +601,158 @@ static ivas_error acelp_FCB_allocator(
    return error;
}

static ivas_error acelp_FCB_allocator_ivas(
    Word16 *nBits,            /* i/o: available bit-budget    */
    Word16 fixed_cdk_index[], /* o  : codebook index          */
    Word16 nb_subfr,          /* i  : number of subframes     */
    const Word16 L_subfr,     /* i  : subframe length         */
    const Word16 coder_type,  /* i  : coder type              */
    const Word16 tc_subfr,    /* i  : TC subframe index       */
    const Word16 fix_first    /* i  : flag to indicate whether the first subframe bit-budget was fixed */
)
{
    Word16 cdbk, sfr, step;
    Word16 nBits_tmp;
    Word16 *p_fixed_cdk_index;
    Word16 max_n;
    ivas_error error;
    // PMT("Not floating point computation, but fixed point operator are still missing ")

    error = IVAS_ERR_OK;
    move32();

    cdbk = coder_type; /* just to avoid warning when DEBUGGING is deactivated */
    move16();

    p_fixed_cdk_index = fixed_cdk_index;
    move16();

    /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse not in the first subframe */
    test();
    IF( GE_16( tc_subfr, L_SUBFR ) && fix_first )
    {
        Word16 i;

        FOR( i = 0; i < nb_subfr; i++ )
        {
            *nBits = sub( *nBits, ACELP_FIXED_CDK_BITS( fixed_cdk_index[i] ) );
            move16();
        }
        return error;
    }

    /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse in the first subframe */
    sfr = 0;
    move16();
    IF( fix_first )
    {
        *nBits = sub( *nBits, ACELP_FIXED_CDK_BITS( fixed_cdk_index[0] ) );
        move16();
        sfr = 1;
        move16();
        p_fixed_cdk_index++;
        nb_subfr = 3;
        move16();
    }

    /* distribute the bit-budget equally between subframes */
    IF( GT_16( L_subfr, L_SUBFR ) ) /* access fast_FCB_bits_2sfr */
    {
        max_n = 6;
        move16();
    }
    ELSE
    {
        max_n = ACELP_FIXED_CDK_NB;
        move16();
    }
    FOR( cdbk = 0; cdbk < max_n; cdbk++ )
    {
        IF( GT_32( L_mult0( fcb_table( cdbk, L_subfr ), nb_subfr ), L_deposit_l( *nBits ) ) )
        {
            BREAK;
        }
    }
    cdbk = sub( cdbk, 1 );

    set16_fx( p_fixed_cdk_index, cdbk, nb_subfr );
    nBits_tmp = 0;
    move16();
    IF( cdbk >= 0 )
    {
        nBits_tmp = fcb_table( cdbk, L_subfr );
        move16();
    }
    ELSE
    {
        nBits_tmp = 0;
        move16();
    }
    *nBits = sub( *nBits, i_mult( nBits_tmp, nb_subfr ) );
    move16();

    /* try to increase the FCB bit-budget of the first subframe(s) */
    IF( LT_16( cdbk, ACELP_FIXED_CDK_NB - 1 ) )
    {
        step = sub( fcb_table( add( cdbk, 1 ), L_subfr ), nBits_tmp );
        WHILE( GE_16( *nBits, step ) )
        {
            ( *p_fixed_cdk_index )++;
            *nBits = sub( *nBits, step );
            move16();
            p_fixed_cdk_index++;
        }

        /* try to increase the FCB of the first subframe in cases when the next step is lower than the current step */
        IF( LT_16( fixed_cdk_index[sfr], ACELP_FIXED_CDK_NB - 1 ) )
        {
            step = sub( fcb_table( add( fixed_cdk_index[sfr], 1 ), L_subfr ), fcb_table( fixed_cdk_index[sfr], L_subfr ) );
            test();
            IF( GE_16( *nBits, step ) && cdbk >= 0 )
            {
                fixed_cdk_index[sfr]++;
                *nBits = sub( *nBits, step );
                move16();
                test();
                IF( GE_16( *nBits, step ) && EQ_16( fixed_cdk_index[sfr + 1], sub( fixed_cdk_index[sfr], 1 ) ) )
                {
                    sfr++;
                    fixed_cdk_index[sfr]++;
                    *nBits = sub( *nBits, step );
                    move16();
                }
            }
        }
    }
    /* TRANSITION coding: allocate highest FCBQ bit-budget to the subframe with the glottal-shape codebook */
    IF( GE_16( tc_subfr, L_SUBFR ) )
    {
        Word16 tempr;

        SWAP( fixed_cdk_index[0], fixed_cdk_index[tc_subfr / L_SUBFR] );

        /* TRANSITION coding: allocate second highest FCBQ bit-budget to the last subframe */
        IF( idiv1616( tc_subfr, L_SUBFR ) < sub( nb_subfr, 1 ) )
        {
            SWAP( fixed_cdk_index[sub( tc_subfr, L_SUBFR ) / L_SUBFR], fixed_cdk_index[nb_subfr - 1] );
        }
    }

    /* when subframe length > L_SUBFR, number of bits instead of codebook index is signalled */
    IF( GT_16( L_subfr, L_SUBFR ) )
    {
        Word16 i, j;
        FOR( i = 0; i < nb_subfr; i++ )
        {
            j = fixed_cdk_index[i];
            move16();
            fixed_cdk_index[i] = fast_FCB_bits_2sfr[j];
            move16();
        }
    }

    return error;
}

/*-------------------------------------------------------------------*
 * config_acelp1()
@@ -2373,11 +2525,11 @@ ivas_error config_acelp1_IVAS(

        IF( GE_16( bits, 16 ) )
        {
            acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 );
            acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 );
        }
        ELSE
        {
            acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 );
            acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 );
            acelp_cfg->fixed_cdk_index[1] = -1;
            move16();
        }
@@ -2492,17 +2644,17 @@ ivas_error config_acelp1_IVAS(
                {
                    IF( GE_16( bits, imult1616( ACELP_FIXED_CDK_BITS( 0 ), nb_subfr ) ) ) /* enough bits for all fcb */
                    {
                        acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first );
                        acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first );
                    }
                    ELSE IF( GE_16( bits, imult1616( ACELP_FIXED_CDK_BITS( 0 ), sub( nb_subfr, 1 ) ) ) )
                    {
                        acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 1 ), L_SUBFR, coder_type, tc_subfr, fix_first );
                        acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 1 ), L_SUBFR, coder_type, tc_subfr, fix_first );
                        acelp_cfg->fixed_cdk_index[3] = -1;
                        move16();
                    }
                    ELSE IF( GE_32( bits, imult1616( ACELP_FIXED_CDK_BITS( 0 ), sub( nb_subfr, 2 ) ) ) )
                    {
                        acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 2 ), L_SUBFR, coder_type, tc_subfr, fix_first );
                        acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 2 ), L_SUBFR, coder_type, tc_subfr, fix_first );
                        acelp_cfg->fixed_cdk_index[2] = acelp_cfg->fixed_cdk_index[1];
                        move16();
                        acelp_cfg->fixed_cdk_index[1] = -1;
@@ -2512,7 +2664,7 @@ ivas_error config_acelp1_IVAS(
                    }
                    ELSE IF( GE_32( bits, ACELP_FIXED_CDK_BITS( 0 ) ) )
                    {
                        acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 1, L_SUBFR, coder_type, tc_subfr, fix_first );
                        acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, 1, L_SUBFR, coder_type, tc_subfr, fix_first );
                        acelp_cfg->fixed_cdk_index[1] = acelp_cfg->fixed_cdk_index[0];
                        move16();
                        acelp_cfg->fixed_cdk_index[0] = -1;
@@ -2538,11 +2690,11 @@ ivas_error config_acelp1_IVAS(
                {
                    bits = 100; /* 9 kbps for fcb */
                    move16();
                    acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first );
                    acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first );
                }
                ELSE
                {
                    acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first );
                    acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first );
                }
            }
        }
+3 −0
Original line number Diff line number Diff line
@@ -2251,8 +2251,11 @@ typedef enum _DCTTYPE
#define HVQ_NSUB_24k                        7                       /* HVQ Classifier number of subbands */

#define HQ_CREST_THRESHOLD 7.0f                                     /* HQ harmonic high band classifier, crest threshold */
#define HQ_CREST_THRESHOLD_FX 1879048192 //7.0f in Q28                                   /* HQ harmonic high band classifier, crest threshold */
#define HQ_CREST_MOD_THRESHOLD 2.128f                               /* HQ harmonic high band classifier, modified crest threshold */
#define HQ_CREST_MOD_THRESHOLD_FX 1142461301 //2.128f in Q29                               /* HQ harmonic high band classifier, modified crest threshold */
#define HQ_CREST_FAC_SM 0.97f                                       /* HQ harmonic high band classifier, smoothing factor */
#define HQ_CREST_FAC_SM_FX 2083059139 //0.97f in Q31                                      /* HQ harmonic high band classifier, smoothing factor */

#define HVQ_BWE_NOISE_BANDS                 2                       /* Number of BWE noise bands */
#define HVQ_BWE_WEIGHT1                     0.95f
+0 −1
Original line number Diff line number Diff line
@@ -227,7 +227,6 @@ move16();

return;
}

void hq_bit_allocation_fx(
    const Word32 core_brate,   /* i  : Core bit-rate                    Q0  */
    const Word16 length,       /* i  : Frame length                     Q0  */
+85 −0
Original line number Diff line number Diff line
@@ -212,6 +212,91 @@ void interleave_spectrum_fx(

    return;
}

void interleave_spectrum_ivas_fx(
    Word32 *coefs,      /* i/o: input and output coefficients   Q12  */
    const Word16 length /* i  : length of spectrum              Q0   */
)
{
    Word16 i, j, k;
    Word32 *p1, *p2, *p3, *p4;
    Word32 *p_out;
    Word32 coefs_out[L_FRAME48k];
    Word16 sublen[3] = { 240, 160, 80 };
    move16();
    move16();
    move16();
    Word16 grps;
    const Word16 *bw;
    const Word16 *cnt;

    /* Common inits */
    p1 = coefs;
    p_out = coefs_out;

    IF( EQ_16( length, L_SPEC48k ) )
    {
        bw = intl_bw_48;
        cnt = intl_cnt_48;
        grps = N_INTL_GRP_48;
        move16();
        p2 = p1 + sublen[0];
        p3 = p2 + sublen[0];
        p4 = p3 + sublen[0];
    }
    ELSE IF( EQ_16( length, L_SPEC32k ) )
    {
        bw = intl_bw_32;
        cnt = intl_cnt_32;
        grps = N_INTL_GRP_32;
        move16();
        p2 = p1 + sublen[1];
        p3 = p2 + sublen[1];
        p4 = p3 + sublen[1];
    }
    ELSE /* length == L_SPEC16k */
    {
        bw = intl_bw_16;
        cnt = intl_cnt_16;
        grps = N_INTL_GRP_16;
        move16();
        p2 = p1 + sublen[2];
        p3 = p2 + sublen[2];
        p4 = p3 + sublen[2];
    }

    FOR( i = 0; i < grps; i++ )
    {
        FOR( j = 0; j < cnt[i]; j++ )
        {
            FOR( k = 0; k < bw[i]; k++ )
            {
                *p_out++ = *p1++;
                move32();
            }
            FOR( k = 0; k < bw[i]; k++ )
            {
                *p_out++ = *p2++;
                move32();
            }
            FOR( k = 0; k < bw[i]; k++ )
            {
                *p_out++ = *p3++;
                move32();
            }
            FOR( k = 0; k < bw[i]; k++ )
            {
                *p_out++ = *p4++;
                move32();
            }
        }
    }

    /* For FB the interleaved spectrum is 800 samples */
    Copy32( coefs_out, coefs, (Word16) ( p_out - coefs_out ) );

    return;
}
#endif

/*--------------------------------------------------------------------------*
+8 −0
Original line number Diff line number Diff line
@@ -1760,12 +1760,14 @@ float stereo_dft_enc_synthesize(
    const int16_t L_frame                                       /* i  : frame length at internal Fs         */
);

#ifndef IVAS_FLOAT_FIXED
void stereo_dft_enc_process(
    CPE_ENC_HANDLE hCPE,                                        /* i  : CPE encoder structure               */
    const int16_t vad_flag_dtx[],                               /* i  : VAD dtx flags                       */
    const int16_t vad_hover_flag[],                             /* i  : VAD hangover flags                  */
    const int16_t input_frame                                   /* i  : input frame length                  */
);
#endif

void stereo_dft_enc_res(
    STEREO_DFT_ENC_DATA_HANDLE hStereoDft,                      /* i/o: encoder DFT stereo handle           */
@@ -2640,9 +2642,15 @@ void stereo_classifier_features(
    const int16_t clas                                          /* i  : signal class                                    */
);

#ifdef IVAS_FLOAT_FIXED
void unclr_classifier_dft_fx(
    CPE_ENC_HANDLE hCPE                                         /* i/o: CPE encoder structure                           */
);
#else
void unclr_classifier_dft(
    CPE_ENC_HANDLE hCPE                                         /* i/o: CPE encoder structure                           */
);
#endif

void unclr_classifier_td(
    CPE_ENC_HANDLE hCPE                                         /* i/o: CPE encoder structure                           */
Loading