Commit 4365a5e3 authored by fotopoulou's avatar fotopoulou
Browse files

Merge branch 'disable_bwd_for_mct' into 'main'

[non-BE]fix bandwidth detection for MCT/MDCT Stereo

See merge request !504
parents bacb1e53 f59e05be
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -2716,7 +2716,9 @@ void ivas_mct_core_enc(
    CPE_ENC_HANDLE hCPE[MCT_MAX_BLOCKS],                        /* i/o: CPE encoder structures                  */
    const int16_t nChannels,                                    /* i  : number of channels to be coded          */
    const int32_t ivas_total_brate,                             /* i  : IVAS total bitrate                      */
#ifndef DISABLE_BWD_MCT
    const int16_t switch_bw,                                    /* i  : flag bandwidth switch occurance         */
#endif
    const int16_t lfe_bits,                                     /* i  : bits spent for LFE                      */
    const int16_t sba_order                                     /* i  : Ambisonic (SBA) order                   */
);
+1 −0
Original line number Diff line number Diff line
@@ -159,6 +159,7 @@
#endif

#define FIX_380_BFI_PARAMISM                            /* VA: issue 380 - fix metadata recovery in ParamISM BFI */
#define FIX_MDCT_BASED_BWD                              /* FhG: fixes for BWD for issues with reaction to transients for MDCT-stereo and MCT */


/* ################## End DEVELOPMENT switches ######################### */
+5 −0
Original line number Diff line number Diff line
@@ -3827,8 +3827,13 @@ void bw_detect(
    const float signal_in[], /* i  : input signal                                */
    float *spectrum,         /* i  : MDCT spectrum                               */
    const float *enerBuffer  /* i  : energy buffer                               */
#ifdef FIX_MDCT_BASED_BWD
    ,
    const int16_t mct_on /* i  : flag MCT mode */
#endif
);


void set_bw(
    const int16_t element_mode,  /* i  : element mode                                */
    const int32_t element_brate, /* i  : element bitrate                             */

lib_enc/amr_wb_enc.c

100644 → 100755
+6 −1
Original line number Diff line number Diff line
@@ -342,7 +342,12 @@ void amr_wb_enc(
     * WB, SWB and FB bandwidth detector
     *----------------------------------------------------------------*/

    bw_detect( st, st->input, NULL, NULL );
    bw_detect( st, st->input, NULL, NULL
#ifdef FIX_MDCT_BASED_BWD
               ,
               0
#endif
    );

    /* in AMR_WB IO, limit the maximum band-width to WB */
    if ( st->bwidth > WB )

lib_enc/bw_detect.c

100644 → 100755
+51 −0
Original line number Diff line number Diff line
@@ -57,6 +57,9 @@

#define BWD_COUNT_MAX      100
#define BWD_COUNT_WIDER_BW 10
#ifdef FIX_MDCT_BASED_BWD
#define BWD_COUNT_WIDER_BW_MDCT 0
#endif

#define CLDFB_ENER_OFFSET 1.6f

@@ -71,6 +74,10 @@ void bw_detect(
    const float signal_in[], /* i  : input signal        */
    float *spectrum,         /* i  : MDCT spectrum       */
    const float *enerBuffer  /* i  : energy buffer       */
#ifdef FIX_MDCT_BASED_BWD
    ,
    const int16_t mct_on /* i  : flag MCT mode */
#endif
)
{
    int16_t i, j, k, bw_max, bin_width, n_bins;
@@ -80,6 +87,15 @@ void bw_detect(
    const float *pt, *pt1;
    float max_NB, max_WB, max_SWB, max_FB, mean_NB, mean_WB, mean_SWB, mean_FB;
    int16_t cldfb_bin_width = 4;
#ifdef FIX_MDCT_BASED_BWD
    int16_t bwd_count_wider_bw, l_frame;

    bwd_count_wider_bw = BWD_COUNT_WIDER_BW;
    if ( st->element_mode == IVAS_CPE_MDCT && ( st->element_brate > IVAS_64k || mct_on ) )
    {
        bwd_count_wider_bw = BWD_COUNT_WIDER_BW_MDCT;
    }
#endif

    if ( st->input_Fs > 8000 )
    {
@@ -173,8 +189,19 @@ void bw_detect(
            }
            else
            {
#ifndef FIX_MDCT_BASED_BWD
                bin_width *= (int16_t) ( ( st->input_Fs / FRAMES_PER_SEC ) / BWD_TOTAL_WIDTH );
                mvr2r( spectrum, spect, (int16_t) ( st->input_Fs / FRAMES_PER_SEC ) );
#else
                l_frame = (int16_t) ( st->input_Fs / FRAMES_PER_SEC );
                if ( st->core == TCX_10_CORE )
                {
                    l_frame /= 2;
                }

                bin_width *= ( l_frame / BWD_TOTAL_WIDTH );
                mvr2r( spectrum, spect, l_frame );
#endif
            }
            /*---------------------------------------------------------------------*
             * compute energy per spectral bins
@@ -392,17 +419,29 @@ void bw_detect(
            /* switching to a higher BW */
            if ( st->last_input_bwidth == NB )
            {
#ifdef FIX_MDCT_BASED_BWD
                if ( st->count_WB > bwd_count_wider_bw )
#else
                if ( st->count_WB > BWD_COUNT_WIDER_BW )
#endif
                {
                    st->input_bwidth = WB;
                    st->count_WB = BWD_COUNT_MAX;

#ifdef FIX_MDCT_BASED_BWD
                    if ( st->count_SWB > bwd_count_wider_bw )
#else
                    if ( st->count_SWB > BWD_COUNT_WIDER_BW )
#endif
                    {
                        st->input_bwidth = SWB;
                        st->count_SWB = BWD_COUNT_MAX;

#ifdef FIX_MDCT_BASED_BWD
                        if ( st->count_FB > bwd_count_wider_bw )
#else
                        if ( st->count_FB > BWD_COUNT_WIDER_BW )
#endif
                        {
                            st->input_bwidth = FB;
                            st->count_FB = BWD_COUNT_MAX;
@@ -413,12 +452,20 @@ void bw_detect(

            if ( st->last_input_bwidth == WB && st->input_Fs > 16000 )
            {
#ifdef FIX_MDCT_BASED_BWD
                if ( st->count_SWB > bwd_count_wider_bw )
#else
                if ( st->count_SWB > BWD_COUNT_WIDER_BW )
#endif
                {
                    st->input_bwidth = SWB;
                    st->count_SWB = BWD_COUNT_MAX;

#ifdef FIX_MDCT_BASED_BWD
                    if ( st->count_FB > bwd_count_wider_bw )
#else
                    if ( st->count_FB > BWD_COUNT_WIDER_BW )
#endif
                    {
                        st->input_bwidth = FB;
                        st->count_FB = BWD_COUNT_MAX;
@@ -428,7 +475,11 @@ void bw_detect(

            if ( st->last_input_bwidth == SWB && st->input_Fs > 32000 )
            {
#ifdef FIX_MDCT_BASED_BWD
                if ( st->count_FB > bwd_count_wider_bw )
#else
                if ( st->count_FB > BWD_COUNT_WIDER_BW )
#endif
                {
                    st->input_bwidth = FB;
                    st->count_FB = BWD_COUNT_MAX;
Loading