LCOV - code coverage report
Current view: top level - lib_dec - ivas_cpe_dec_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ e70d960493906e094628337ac73d3c408863a5e6 Lines: 654 696 94.0 %
Date: 2025-09-17 02:22:58 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : #include <assert.h>
      34             : #include <stdint.h>
      35             : #include "options.h"
      36             : #include "cnst.h"
      37             : #include "ivas_cnst.h"
      38             : #include "rom_com.h"
      39             : #include "prot_fx.h"
      40             : #include "ivas_prot_fx.h"
      41             : #include "ivas_rom_com.h"
      42             : #include "wmc_auto.h"
      43             : #include <math.h>
      44             : 
      45             : 
      46             : /*--------------------------------------------------------------------------*
      47             :  * Local function prototypes
      48             :  *--------------------------------------------------------------------------*/
      49             : 
      50             : static void read_stereo_mode_and_bwidth_fx( CPE_DEC_HANDLE hCPE, const Decoder_Struct *st_ivas );
      51             : 
      52             : static void stereo_mode_combined_format_dec_fx( const Decoder_Struct *st_ivas, CPE_DEC_HANDLE hCPE );
      53             : 
      54             : #ifdef FIX_1320_STACK_CPE_DECODER
      55             : static ivas_error stereo_dft_dec_main( CPE_DEC_HANDLE hCPE, const Word32 ivas_total_brate, const Word16 n_channels, Word32 *p_res_buf_fx, Word32 *output[], Word32 outputHB[][L_FRAME48k], const Word16 output_frame, const Word32 output_Fs );
      56             : #endif
      57             : 
      58             : 
      59             : /*--------------------------------------------------------------------------*
      60             :  * ivas_cpe_dec_fx()
      61             :  *
      62             :  * Channel Pair Element (CPE) decoding routine
      63             :  *--------------------------------------------------------------------------*/
      64             : 
      65      410720 : ivas_error ivas_cpe_dec_fx(
      66             :     Decoder_Struct *st_ivas,      /* i/o: IVAS decoder structure          */
      67             :     const Word16 cpe_id,          /* i  : CPE # identifier                */
      68             :     Word32 *output[CPE_CHANNELS], /* o  : output synthesis signal         Q11*/
      69             :     const Word16 output_frame,    /* i  : output frame length per channel */
      70             :     const Word16 nb_bits_metadata /* i  : number of metadata bits         */
      71             : )
      72             : {
      73             :     Word16 i, n, n_channels;
      74             :     Word16 nb_bits, last_core;
      75             :     Word16 last_bwidth;
      76             :     Word16 tdm_ratio_idx;
      77             :     Word32 outputHB_fx[CPE_CHANNELS][L_FRAME48k]; /* buffer for output HB synthesis, both channels */ /* Q11 */
      78             : #ifdef FIX_1320_STACK_CPE_DECODER
      79      410720 :     Word32 *res_buf_fx = NULL; /* Q8 */
      80             : #else
      81             :     Word16 q_res_buf;
      82             :     Word32 res_buf_fx[STEREO_DFT_N_8k];                  /* Q(q_res_buf) */
      83             : #endif
      84             :     CPE_DEC_HANDLE hCPE;
      85             :     STEREO_DFT_CONFIG_DATA_HANDLE hConfigDft;
      86             :     Decoder_State **sts;
      87             :     Word32 ivas_total_brate;
      88             :     ivas_error error;
      89             :     Word32 cpe_brate;
      90             :     Word32 element_brate_ref;
      91             :     Word32 quo, rem;
      92             : 
      93      410720 :     error = IVAS_ERR_OK;
      94      410720 :     move32();
      95             : #ifndef FIX_1320_STACK_CPE_DECODER
      96             :     q_res_buf = Q8;
      97             :     move16();
      98             : #endif
      99             : 
     100      410720 :     push_wmops( "ivas_cpe_dec" );
     101             : 
     102      410720 :     ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
     103      410720 :     move32();
     104             : 
     105      410720 :     hCPE = st_ivas->hCPE[cpe_id];
     106      410720 :     sts = hCPE->hCoreCoder;
     107             : 
     108      410720 :     last_core = sts[0]->last_core;
     109      410720 :     move16();
     110      410720 :     last_bwidth = sts[0]->last_bwidth;
     111      410720 :     move16();
     112             : 
     113      410720 :     sts[0]->BER_detect = s_or( sts[0]->BER_detect, st_ivas->BER_detect );
     114      410720 :     sts[1]->BER_detect = s_or( sts[1]->BER_detect, st_ivas->BER_detect );
     115      410720 :     move16();
     116      410720 :     move16();
     117             : 
     118      410720 :     element_brate_ref = hCPE->element_brate;
     119      410720 :     move32();
     120             : 
     121             :     /*------------------------------------------------------------------*
     122             :      * Read stereo technology info & audio bandwidth
     123             :      *-----------------------------------------------------------------*/
     124             : 
     125      410720 :     stereo_mode_combined_format_dec_fx( st_ivas, hCPE );
     126             : 
     127      410720 :     read_stereo_mode_and_bwidth_fx( hCPE, st_ivas );
     128             : 
     129             :     /*----------------------------------------------------------------*
     130             :      * dynamically allocate data structures depending on the actual stereo mode
     131             :      *----------------------------------------------------------------*/
     132             : 
     133     1232160 :     FOR( Word16 ind1 = 0; ind1 < 2; ind1++ )
     134             :     {
     135      821440 :         test();
     136      821440 :         IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core )
     137             :         {
     138      758045 :             Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx32, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda ) ); // Q11
     139             :         }
     140             :     }
     141     1232160 :     FOR( Word16 ind1 = 0; ind1 < 2; ind1++ )
     142             :     {
     143      821440 :         IF( hCPE->hCoreCoder[ind1]->hHQ_core )
     144             :         {
     145      758045 :             Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB ) ); // Q11
     146      758045 :             hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_out_fx32 = Q11;
     147      758045 :             move16();
     148             :         }
     149             :     }
     150             : 
     151      410720 :     IF( NE_32( ( error = stereo_memory_dec_fx( ivas_total_brate, hCPE, nb_bits_metadata, st_ivas->hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->nchan_transport ) ), IVAS_ERR_OK ) )
     152             :     {
     153           0 :         return error;
     154             :     }
     155             : 
     156     1232160 :     FOR( Word16 ind1 = 0; ind1 < 2; ind1++ )
     157             :     {
     158      821440 :         test();
     159      821440 :         IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core )
     160             :         {
     161      758062 :             Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda, Q11 ) ); // Q_old_wtda
     162             :         }
     163             :     }
     164     1232160 :     FOR( Word16 ind1 = 0; ind1 < 2; ind1++ )
     165             :     {
     166      821440 :         test();
     167      821440 :         IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core )
     168             :         {
     169      758062 :             Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB, Q11 ) ); // Q_old_wtda_LB
     170             :         }
     171             :     }
     172             : 
     173      410720 :     hConfigDft = NULL;
     174      410720 :     if ( hCPE->hStereoDft != NULL )
     175             :     {
     176       65862 :         hConfigDft = hCPE->hStereoDft->hConfig;
     177             :     }
     178             : 
     179             :     /*------------------------------------------------------------------*
     180             :      * Initialization
     181             :      *-----------------------------------------------------------------*/
     182             : 
     183      410720 :     n_channels = CPE_CHANNELS;
     184      410720 :     move16();
     185      410720 :     if ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
     186             :     {
     187       59583 :         n_channels = 1; /* in DFT stereo, only M channel is coded */
     188       59583 :         move16();
     189             :     }
     190             : 
     191      410720 :     tdm_ratio_idx = LRTD_STEREO_RIGHT_IS_PRIM;
     192      410720 :     move16();
     193             : 
     194     1172577 :     FOR( n = 0; n < n_channels; n++ )
     195             :     {
     196      761857 :         sts[n]->idchan = n;
     197      761857 :         move16();
     198      761857 :         sts[n]->element_mode = hCPE->element_mode;
     199      761857 :         move16();
     200             : 
     201      761857 :         if ( !st_ivas->bfi )
     202             :         {
     203      749359 :             sts[n]->tdm_LRTD_flag = 0;
     204      749359 :             move16();
     205             :         }
     206             : 
     207             :         /* TD stereo parameters */
     208      761857 :         IF( hCPE->hStereoTD != NULL )
     209             :         {
     210        7590 :             hCPE->hStereoTD->tdm_lp_reuse_flag = 0;
     211        7590 :             move16();
     212        7590 :             hCPE->hStereoTD->tdm_low_rate_mode = 0;
     213        7590 :             move16();
     214        7590 :             hCPE->hStereoTD->tdm_Pitch_reuse_flag = 0;
     215        7590 :             move16();
     216             :         }
     217             :     }
     218             : 
     219             :     /*----------------------------------------------------------------*
     220             :      * Resets/updates in case of stereo switching
     221             :      *----------------------------------------------------------------*/
     222             : 
     223      410720 :     stereo_switching_dec( hCPE, ivas_total_brate );
     224             : 
     225             :     /*----------------------------------------------------------------*
     226             :      * Configuration of stereo decoder
     227             :      *----------------------------------------------------------------*/
     228             : 
     229             :     /* Force to MODE1 in IVAS */
     230     1172577 :     FOR( n = 0; n < n_channels; n++ )
     231             :     {
     232      761857 :         sts[n]->codec_mode = MODE1;
     233      761857 :         move16();
     234             :     }
     235             : 
     236      410720 :     test();
     237      410720 :     test();
     238      410720 :     test();
     239      410720 :     test();
     240      410720 :     IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && ( NE_32( hCPE->element_brate, hCPE->last_element_brate ) || NE_16( hCPE->last_element_mode, hCPE->element_mode ) || sts[0]->ini_frame == 0 || ( NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) ) )
     241             :     {
     242        4630 :         test();
     243        4630 :         IF( st_ivas->hQMetaData != NULL && GT_32( ivas_total_brate, IVAS_SID_5k2 ) )
     244             :         {
     245        1138 :             IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
     246             :             {
     247         461 :                 stereo_dft_config_fx( hConfigDft, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, 35 /* 0.7f * FRAMES_PER_SEC */ ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
     248             :             }
     249             :             ELSE
     250             :             {
     251         677 :                 stereo_dft_config_fx( hConfigDft, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
     252             :             }
     253             :         }
     254             :         ELSE
     255             :         {
     256             :             /* Note: This only works for stereo operation. If DTX would be applied for multiple CPEs a different bitrate signaling is needed */
     257        3492 :             IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) )
     258             :             {
     259        2895 :                 stereo_dft_config_fx( hConfigDft, ivas_total_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
     260             :             }
     261             :             ELSE
     262             :             {
     263         597 :                 stereo_dft_config_fx( hConfigDft, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
     264             :             }
     265             :         }
     266             :     }
     267             : 
     268      410720 :     IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) )
     269             :     {
     270        3795 :         IF( hCPE->hStereoTD->tdm_LRTD_flag )
     271             :         {
     272        3674 :             iDiv_and_mod_32( L_shr( hCPE->element_brate, 1 ), FRAMES_PER_SEC, &quo, &rem, 0 );
     273        3674 :             sts[0]->bits_frame_nominal = extract_l( quo );
     274        3674 :             sts[1]->bits_frame_nominal = extract_l( quo );
     275        3674 :             move16();
     276        3674 :             move16();
     277             :         }
     278             :         ELSE
     279             :         {
     280         121 :             stereo_dft_config_fx( NULL, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
     281             :         }
     282             :     }
     283             : 
     284             :     /*----------------------------------------------------------------*
     285             :      * Set bitrates per channel
     286             :      * Set bitstream buffers per channel
     287             :      *----------------------------------------------------------------*/
     288             : 
     289      410720 :     IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
     290             :     {
     291       59583 :         IF( !st_ivas->bfi )
     292             :         {
     293             :             /* Update DFT Stereo memories */
     294       58695 :             stereo_dft_dec_update_fx( hCPE->hStereoDft, output_frame, 0 );
     295             : 
     296       58695 :             test();
     297       58695 :             IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && LE_32( ivas_total_brate, IVAS_SID_5k2 ) )
     298             :             {
     299         528 :                 IF( ivas_total_brate == FRAME_NO_DATA )
     300             :                 {
     301         454 :                     hCPE->hCoreCoder[n]->core_brate = ivas_total_brate;
     302         454 :                     move32();
     303         454 :                     hCPE->hCoreCoder[0]->total_brate = ivas_total_brate;
     304         454 :                     move32();
     305             :                 }
     306             :                 ELSE
     307             :                 {
     308          74 :                     hCPE->hCoreCoder[n]->core_brate = SID_2k40;
     309          74 :                     move32();
     310             :                 }
     311             :             }
     312             : 
     313             :             /* read DFT Stereo side info */
     314       58695 :             nb_bits = extract_h( L_msu( Mpy_32_16_1( L_shl( hCPE->element_brate, 15 ), 1311 /* 1/FRAMES_PER_SEC in Q16*/ ), 26214, sts[0]->bits_frame_nominal ) );
     315       58695 :             cpe_brate = st_ivas->hCPE[0]->element_brate;
     316       58695 :             move32();
     317       58695 :             IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
     318             :             {
     319        2683 :                 iDiv_and_mod_32( cpe_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
     320        2683 :                 sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( extract_l( quo ), 1 ), nb_bits_metadata );
     321        2683 :                 IF( hCPE->brate_surplus < 0 )
     322             :                 {
     323        2201 :                     iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 );
     324        2201 :                     quo = L_negate( quo );
     325             :                 }
     326             :                 ELSE
     327             :                 {
     328         482 :                     iDiv_and_mod_32( hCPE->brate_surplus, FRAMES_PER_SEC, &quo, &rem, 0 );
     329             :                 }
     330        2683 :                 sts[1]->bit_stream = sts[1]->bit_stream + extract_l( quo );
     331             :             }
     332             :             ELSE
     333             :             {
     334       56012 :                 iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
     335       56012 :                 sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( extract_l( quo ), 1 ), nb_bits_metadata );
     336             :             }
     337             : 
     338       58695 :             IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) )
     339             :             {
     340        1506 :                 nb_bits = sub( nb_bits, SID_FORMAT_NBITS );
     341        1506 :                 sts[1]->bit_stream = sts[1]->bit_stream - SID_FORMAT_NBITS;
     342             :                 /* set total bitrate of Stereo CNG parameters for BER detection */
     343        1506 :                 sts[1]->total_brate = IVAS_SID_5k2 - SID_2k40;
     344        1506 :                 move32();
     345             :             }
     346             : 
     347       58695 :             test();
     348       58695 :             test();
     349       58695 :             test();
     350       58695 :             test();
     351       58695 :             IF( ( ( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) ) || ( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && LT_32( cpe_brate, MASA_STEREO_MIN_BITRATE ) ) ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) )
     352             :             {
     353        5471 :                 sts[0]->total_brate = hCPE->element_brate; /* Only mono downmix was transmitted in this case */
     354        5471 :                 move32();
     355             :             }
     356             :             ELSE
     357             :             {
     358             : #ifdef FIX_1320_STACK_CPE_DECODER
     359       53224 :                 res_buf_fx = outputHB_fx[0]; /* note: temporarily reused buffer */
     360             : 
     361             : #endif
     362       53224 :                 test();
     363       53224 :                 IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
     364             :                 {
     365        6196 :                     nb_bits = sub( nb_bits, nb_bits_metadata );
     366        6196 :                     IF( hCPE->brate_surplus < 0 )
     367             :                     {
     368         930 :                         iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 );
     369         930 :                         quo = L_negate( quo );
     370         930 :                         nb_bits = add( nb_bits, extract_l( quo ) );
     371             :                     }
     372             :                 }
     373             : 
     374       53224 :                 stereo_dft_dec_read_BS_fx( ivas_total_brate, hCPE->element_brate, &sts[0]->total_brate, sts[1], hCPE->hStereoDft, sts[0]->bwidth, output_frame, res_buf_fx, &nb_bits, hCPE->hStereoCng->coh_fx, st_ivas->ivas_format );
     375             :             }
     376             : 
     377             :             /* subtract metadata bitbudget */
     378       58695 :             sts[0]->total_brate = L_sub( sts[0]->total_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); // Q0
     379       58695 :             move32();
     380             : 
     381             :             /* subtract bit-rate for combined format coding */
     382       58695 :             test();
     383       58695 :             test();
     384       58695 :             test();
     385       58695 :             IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) )
     386             :             {
     387        2683 :                 sts[0]->total_brate = L_add( sts[0]->total_brate, hCPE->brate_surplus );
     388        2683 :                 move32();
     389             :             }
     390             :         }
     391             :         ELSE
     392             :         {
     393         888 :             hCPE->hStereoDft->sg_mem_corrupt = 1;
     394         888 :             move16();
     395             :         }
     396             :     }
     397      351137 :     ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) )
     398             :     {
     399             :         /* signal bitrate for BW selection in the SCh */
     400        3795 :         sts[0]->bits_frame_channel = 0;
     401        3795 :         move16();
     402        3795 :         iDiv_and_mod_32( hCPE->element_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
     403        3795 :         sts[1]->bits_frame_channel = extract_l( quo );
     404        3795 :         move16();
     405        3795 :         IF( hCPE->brate_surplus < 0 )
     406             :         {
     407           0 :             iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 );
     408           0 :             quo = L_negate( quo );
     409             :         }
     410             :         ELSE
     411             :         {
     412        3795 :             iDiv_and_mod_32( hCPE->brate_surplus, FRAMES_PER_SEC, &quo, &rem, 0 );
     413             :         }
     414        3795 :         sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, extract_l( quo ) );
     415        3795 :         move16();
     416        3795 :         IF( st_ivas->hQMetaData != NULL )
     417             :         {
     418          60 :             sts[1]->bits_frame_channel = sub( sts[1]->bits_frame_channel, st_ivas->hQMetaData->metadata_max_bits );
     419          60 :             move16();
     420             :         }
     421             :     }
     422      347342 :     ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) )
     423             :     {
     424             :         /* compute bit-rate surplus per channel in combined format coding */
     425             :         Word32 brate_surplus[CPE_CHANNELS];
     426      347342 :         test();
     427      347342 :         test();
     428      347342 :         IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
     429             :         {
     430        3793 :             IF( hCPE->brate_surplus < 0 )
     431             :             {
     432        3611 :                 iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 );
     433        3611 :                 quo = L_negate( quo );
     434             :             }
     435             :             ELSE
     436             :             {
     437         182 :                 iDiv_and_mod_32( hCPE->brate_surplus, FRAMES_PER_SEC, &quo, &rem, 0 );
     438             :             }
     439        3793 :             brate_surplus[0] = L_shr( L_mult( extract_l( L_shr( quo, 1 ) ), FRAMES_PER_SEC ), 1 );
     440        3793 :             move32();
     441        3793 :             brate_surplus[1] = L_sub( hCPE->brate_surplus, brate_surplus[0] );
     442        3793 :             move32();
     443             :         }
     444             : 
     445      347342 :         test();
     446      347342 :         test();
     447      347342 :         IF( EQ_16( is_DTXrate( ivas_total_brate ), 1 ) && ( sts[0]->first_CNG == 0 || sts[1]->first_CNG == 0 ) )
     448             :         {
     449          29 :             IF( NE_32( ( error = initMdctStereoDtxData_fx( hCPE ) ), IVAS_ERR_OK ) )
     450             :             {
     451           0 :                 return error;
     452             :             }
     453             :         }
     454             : 
     455             :         /* this is just for initialization, the true values of "total_brate" and "bits_frame_channel" are set later */
     456     1042026 :         FOR( n = 0; n < n_channels; n++ )
     457             :         {
     458      694684 :             IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) )
     459             :             {
     460         912 :                 sts[n]->total_brate = SID_2k40;
     461         912 :                 move32();
     462         912 :                 sts[1]->bit_stream = sts[0]->bit_stream + SID_2k40 / FRAMES_PER_SEC;
     463             :             }
     464             :             ELSE
     465             :             {
     466             :                 /*total bitrate must be set to the element bitrate to avoid false BER IF bits read are larger than half the bitrate*/
     467      693772 :                 sts[n]->total_brate = hCPE->element_brate;
     468      693772 :                 move32();
     469             :             }
     470      694684 :             iDiv_and_mod_32( sts[n]->total_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
     471      694684 :             sts[n]->bits_frame_nominal = extract_l( quo );
     472      694684 :             iDiv_and_mod_32( hCPE->element_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
     473      694684 :             sts[n]->bits_frame_channel = extract_l( L_shr( quo, sub( n_channels, 1 ) ) );
     474      694684 :             move16();
     475      694684 :             move16();
     476             : 
     477             :             /* subtract bit-rate for combined format coding */
     478      694684 :             test();
     479      694684 :             test();
     480      694684 :             IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
     481             :             {
     482        7586 :                 IF( brate_surplus[n] < 0 )
     483             :                 {
     484        7222 :                     iDiv_and_mod_32( L_abs( brate_surplus[n] ), FRAMES_PER_SEC, &quo, &rem, 0 );
     485        7222 :                     quo = L_negate( quo );
     486             :                 }
     487             :                 ELSE
     488             :                 {
     489         364 :                     iDiv_and_mod_32( brate_surplus[n], FRAMES_PER_SEC, &quo, &rem, 0 );
     490             :                 }
     491        7586 :                 sts[n]->bits_frame_channel = add( sts[n]->bits_frame_channel, extract_l( quo ) );
     492        7586 :                 sts[n]->total_brate = L_add( sts[n]->total_brate, brate_surplus[n] );
     493        7586 :                 move16();
     494        7586 :                 move32();
     495             :             }
     496             :         }
     497             : 
     498      347342 :         IF( !st_ivas->hMCT )
     499             :         {
     500       85898 :             test();
     501       85898 :             IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) )
     502             :             {
     503         138 :                 FOR( n = 0; n < n_channels; n++ )
     504             :                 {
     505          92 :                     sts[n]->bits_frame_channel = sub( sts[n]->bits_frame_channel, shr( nb_bits_metadata, sub( n_channels, 1 ) ) );
     506          92 :                     move16();
     507             :                 }
     508             :             }
     509             :             ELSE
     510             :             {
     511             :                 /* subtract metadata bitbudget */
     512       85852 :                 sts[0]->bits_frame_channel = sub( sts[0]->bits_frame_channel, nb_bits_metadata );
     513       85852 :                 move16();
     514             :             }
     515             :         }
     516             :     }
     517             : 
     518             :     /*----------------------------------------------------------------*
     519             :      * Core codec configuration
     520             :      *----------------------------------------------------------------*/
     521             : 
     522     1172577 :     FOR( n = 0; n < n_channels; n++ )
     523             :     {
     524             :         /* set ACELP12k8 / ACELP16k flag for flexible ACELP core */
     525      761857 :         IF( hCPE->hStereoTD != NULL )
     526             :         {
     527        7590 :             sts[n]->flag_ACELP16k = set_ACELP_flag_IVAS( hCPE->element_mode, hCPE->element_brate, sts[n]->total_brate, n, hCPE->hStereoTD->tdm_LRTD_flag, sts[n]->bwidth, sts[n]->cng_type );
     528        7590 :             move16();
     529             :         }
     530             :         ELSE
     531             :         {
     532      754267 :             sts[n]->flag_ACELP16k = set_ACELP_flag_IVAS( hCPE->element_mode, hCPE->element_brate, sts[n]->total_brate, n, 0, sts[n]->bwidth, sts[n]->cng_type );
     533      754267 :             move16();
     534             :         }
     535             :     }
     536             : 
     537     1172577 :     FOR( n = 0; n < n_channels; n++ )
     538             :     {
     539             :         /* set VAD flag */
     540      761857 :         IF( EQ_16( is_DTXrate( ivas_total_brate ), 1 ) )
     541             :         {
     542       16808 :             sts[n]->VAD = 0;
     543       16808 :             move16();
     544       16808 :             sts[n]->active_cnt = 0;
     545       16808 :             move16();
     546       16808 :             IF( sts[1] != NULL )
     547             :             {
     548       16808 :                 sts[1]->active_cnt = 0;
     549       16808 :                 move16();
     550       16808 :                 if ( sts[1]->ini_frame == 0 )
     551             :                 {
     552       10125 :                     sts[1]->active_cnt = CNG_TYPE_HO;
     553       10125 :                     move16();
     554             :                 }
     555             :             }
     556             :         }
     557             :         ELSE
     558             :         {
     559      745049 :             sts[n]->VAD = 1;
     560      745049 :             move16();
     561      745049 :             sts[n]->active_cnt = add( sts[n]->active_cnt, 1 );
     562      745049 :             sts[n]->active_cnt = s_min( sts[n]->active_cnt, 200 );
     563      745049 :             move16();
     564      745049 :             move16();
     565             :         }
     566             : 
     567             :         /* set CNA flag */
     568      761857 :         test();
     569      761857 :         test();
     570      761857 :         IF( ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && LE_32( hCPE->element_brate, CNA_MAX_BRATE_DFT_STEREO ) ) || LE_32( hCPE->element_brate, CNA_MAX_BRATE_STEREO ) )
     571             :         {
     572       66787 :             sts[n]->flag_cna = 1;
     573       66787 :             move16();
     574             :         }
     575             :         ELSE
     576             :         {
     577      695070 :             sts[n]->flag_cna = 0;
     578      695070 :             move16();
     579             :         }
     580             :     }
     581             : 
     582             :     /* configure TD stereo decoder */
     583      410720 :     IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) )
     584             :     {
     585        3795 :         IF( !st_ivas->bfi )
     586             :         {
     587        3739 :             tdm_configure_dec_fx( st_ivas->ivas_format, st_ivas->ism_mode, hCPE, &tdm_ratio_idx, nb_bits_metadata );
     588             : 
     589        3739 :             iDiv_and_mod_32( sts[0]->total_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
     590        3739 :             sts[1]->bit_stream = sts[0]->bit_stream + extract_l( quo );
     591             :         }
     592             :         ELSE
     593             :         {
     594          56 :             sts[1]->coder_type = sts[1]->last_coder_type;
     595          56 :             move16();
     596          56 :             tdm_ratio_idx = hCPE->hStereoTD->tdm_last_ratio_idx;
     597          56 :             move16();
     598             :         }
     599             :     }
     600             : 
     601             :     /*----------------------------------------------------------------*
     602             :      * Core Decoder
     603             :      *----------------------------------------------------------------*/
     604             : 
     605      410720 :     test();
     606      410720 :     test();
     607      410720 :     IF( NE_16( hCPE->element_mode, IVAS_CPE_DFT ) || ( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hConfigDft->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) )
     608             :     {
     609      368177 :         IF( NE_32( ( error = ivas_core_dec_fx( st_ivas, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, NULL, st_ivas->sba_dirac_stereo_flag ) ), IVAS_ERR_OK ) )
     610             :         {
     611           0 :             return error;
     612             :         }
     613             :     }
     614             : 
     615      410720 :     IF( st_ivas->hMCT )
     616             :     {
     617      261444 :         pop_wmops();
     618             : 
     619      261444 :         return error;
     620             :     }
     621             : 
     622             :     /*----------------------------------------------------------------*
     623             :      * Stereo decoder & upmixing
     624             :      *----------------------------------------------------------------*/
     625             : 
     626      149276 :     test();
     627      149276 :     test();
     628      149276 :     IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && !( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hConfigDft->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) )
     629             :     {
     630             : #ifdef FIX_1320_STACK_CPE_DECODER
     631       42543 :         IF( NE_32( ( error = stereo_dft_dec_main( hCPE, ivas_total_brate, n_channels, res_buf_fx, output, outputHB_fx, output_frame, st_ivas->hDecoderConfig->output_Fs ) ), IVAS_ERR_OK ) )
     632             :         {
     633           0 :             return error;
     634             :         }
     635             : #else
     636             :         Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX]; // q_dft
     637             :         set32_fx( DFT_fx[0], 0, STEREO_DFT_BUF_MAX );
     638             :         set32_fx( DFT_fx[1], 0, STEREO_DFT_BUF_MAX );
     639             : 
     640             :         /* core decoder */
     641             :         IF( NE_32( ( error = ivas_core_dec_fx( NULL, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, DFT_fx, 0 ) ), IVAS_ERR_OK ) )
     642             :         {
     643             :             return error;
     644             :         }
     645             : 
     646             :         // Scaling of DFT's
     647             :         Word16 shift;
     648             :         Word32 tmp1, tmp2;
     649             :         Word16 shift1, shift2;
     650             :         maximum_abs_32_fx( DFT_fx[0], STEREO_DFT_BUF_MAX, &tmp1 );
     651             :         maximum_abs_32_fx( DFT_fx[1], STEREO_DFT_BUF_MAX, &tmp2 );
     652             : 
     653             :         IF( tmp1 == 0 )
     654             :         {
     655             :             shift1 = Q31;
     656             :             move16();
     657             :         }
     658             :         ELSE
     659             :         {
     660             :             shift1 = norm_l( tmp1 );
     661             :         }
     662             :         IF( tmp2 == 0 )
     663             :         {
     664             :             shift2 = Q31;
     665             :             move16();
     666             :         }
     667             :         ELSE
     668             :         {
     669             :             shift2 = norm_l( tmp2 );
     670             :         }
     671             :         shift = s_min( shift1, shift2 );
     672             : 
     673             :         IF( NE_16( shift, 31 ) )
     674             :         {
     675             : #ifdef FIX_1946_CRASH_JBM_PROCESSING
     676             :             shift = sub( add( hCPE->hStereoDft->q_dft, shift ), Q17 ); /* Q17 for guard bits */
     677             : #else
     678             :             shift = sub( add( hCPE->hStereoDft->q_dft, shift ), Q16 ); /* Q16 for guard bits */
     679             : #endif
     680             : 
     681             :             IF( GT_16( shift, hCPE->hStereoDft->q_dft ) )
     682             :             {
     683             :                 Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); // shift
     684             :                 Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); // shift
     685             :                 hCPE->hStereoDft->q_dft = shift;
     686             :                 move16();
     687             :             }
     688             :         }
     689             :         ELSE
     690             :         {
     691             :             hCPE->hStereoDft->q_dft = Q8;
     692             :             move16();
     693             :         }
     694             : 
     695             :         /* DFT Stereo residual decoding */
     696             :         test();
     697             :         IF( hCPE->hStereoDft->res_cod_band_max > 0 && !st_ivas->bfi )
     698             :         {
     699             :             Word16 q;
     700             :             Word16 q_out_DFT[2];
     701             : 
     702             :             q = Q11;
     703             :             move16();
     704             : 
     705             :             Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, ( ( 2 * NB_SUBFR16k ) + 2 ), -( Q10 ) ); // Q16->Q6
     706             : 
     707             :             stereo_dft_dec_res_fx( hCPE, res_buf_fx, q_res_buf, output[1] );
     708             : 
     709             :             Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, ( ( 2 * NB_SUBFR16k ) + 2 ), 10 ); // Q6->Q16
     710             : 
     711             :             Scale_sig32( output[1], L_FRAME8k, ( Q11 - Q15 ) ); // Q15 -> Q11
     712             : 
     713             :             q_out_DFT[0] = q_out_DFT[1] = hCPE->hStereoDft->q_dft;
     714             :             move16();
     715             :             move16();
     716             : 
     717             :             stereo_dft_dec_analyze_fx( hCPE, output[1], DFT_fx, 1, L_FRAME8k, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0, &q, q_out_DFT );
     718             : 
     719             :             Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_out_DFT[1] ) ); // q_dft
     720             :         }
     721             : 
     722             :         /* DFT stereo CNG */
     723             :         {
     724             :             Word16 q_dft;
     725             : 
     726             :             q_dft = hCPE->hStereoDft->q_dft;
     727             :             move16();
     728             : 
     729             :             stereo_dtf_cng_fx( hCPE, ivas_total_brate, DFT_fx, output_frame, q_dft );
     730             :         }
     731             : 
     732             :         /* decoding */
     733             :         IF( EQ_16( hCPE->nchan_out, 1 ) )
     734             :         {
     735             :             IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) )
     736             :             {
     737             :                 hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft;
     738             :                 move16();
     739             :                 FOR( Word16 ii = 0; ii < (Word16) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ )
     740             :                 {
     741             :                     hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft;
     742             :                     move16();
     743             :                 }
     744             :                 hCPE->hStereoDft->first_frame = 0;
     745             :                 move16();
     746             :             }
     747             : 
     748             :             scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // q_dft
     749             :             hCPE->hStereoDft->q_res_cod_mem_fx = hCPE->hStereoDft->q_dft;
     750             :             move16();
     751             :             stereo_dft_unify_dmx_fx( hCPE->hStereoDft, sts[0], DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng->prev_sid_nodata );
     752             :             scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q15, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // Q15
     753             :             hCPE->hStereoDft->q_res_cod_mem_fx = Q15;
     754             :             move16();
     755             :         }
     756             :         ELSE
     757             :         {
     758             :             {
     759             :                 IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) )
     760             :                 {
     761             :                     hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft;
     762             :                     move16();
     763             :                     FOR( Word16 ii = 0; ii < (Word16) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ )
     764             :                     {
     765             :                         hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft;
     766             :                         move16();
     767             :                     }
     768             :                     hCPE->hStereoDft->first_frame = 0;
     769             :                     move16();
     770             :                 }
     771             : 
     772             :                 scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // q_dft
     773             :                 hCPE->hStereoDft->q_res_cod_mem_fx = hCPE->hStereoDft->q_dft;
     774             :                 move16();
     775             :             }
     776             :             stereo_dft_dec_fx( hCPE->hStereoDft, sts[0], DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng, 0, 0, 0, 0, 0, 0, MAX_PARAM_SPATIAL_SUBFRAMES );
     777             :             scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q15, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // Q15
     778             :             hCPE->hStereoDft->q_res_cod_mem_fx = Q15;
     779             :             move16();
     780             :         }
     781             : 
     782             :         FOR( n = 0; n < hCPE->nchan_out; n++ )
     783             :         {
     784             :             Scale_sig32( output[n], L_FRAME48k, sub( hCPE->hStereoDft->q_dft, Q11 ) );                                                                          // q_dft
     785             :             scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
     786             :             hCPE->q_output_mem_fx[n] = hCPE->hStereoDft->q_dft;
     787             :             move16();
     788             :         }
     789             : 
     790             :         /* synthesis iFFT */
     791             :         FOR( n = 0; n < hCPE->nchan_out; n++ )
     792             :         {
     793             :             stereo_dft_dec_synthesize_fx( hCPE, DFT_fx, n, output[n], output_frame );
     794             :         }
     795             : 
     796             :         // delete below
     797             :         FOR( n = 0; n < hCPE->nchan_out; n++ )
     798             :         {
     799             :             Scale_sig32( output[n], L_FRAME48k, sub( Q11, hCPE->hStereoDft->q_dft ) );                                                                          // Q11
     800             :             scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
     801             :             hCPE->q_output_mem_fx[n] = Q11;
     802             :             move16();
     803             :         }
     804             : #endif
     805             :     }
     806      106733 :     ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) )
     807             :     {
     808        3795 :         test();
     809        3795 :         if ( NE_16( hCPE->last_element_mode, IVAS_CPE_TD ) && sts[0]->tdm_LRTD_flag )
     810             :         {
     811          60 :             hCPE->hStereoTD->tdm_last_ratio_idx = tdm_ratio_idx;
     812          60 :             move16();
     813             :         }
     814             : 
     815             :         /* TD stereo upmixing */
     816        3795 :         stereo_tdm_combine_fx( hCPE, output[0], output[1], output_frame, 0, tdm_ratio_idx );
     817        3795 :         IF( sts[0]->tdm_LRTD_flag )
     818             :         {
     819        3674 :             stereo_tdm_combine_fx( hCPE, outputHB_fx[0], outputHB_fx[1], output_frame, 0, tdm_ratio_idx );
     820             :         }
     821             : 
     822        3795 :         hCPE->hStereoCng->last_tdm_idx = hCPE->hStereoTD->tdm_last_ratio_idx;
     823        3795 :         move16();
     824        3795 :         hCPE->hStereoTD->tdm_last_ratio_idx = tdm_ratio_idx;
     825        3795 :         move16();
     826             : 
     827        3795 :         IF( EQ_16( hCPE->nchan_out, 1 ) )
     828             :         {
     829             :             /* Scale the Right channel with the gain */
     830        1349 :             stereo_tca_scale_R_channel_fx( hCPE, output[1], output_frame );
     831             :             /* stereo to mono downmix */
     832      809349 :             FOR( i = 0; i < output_frame; i++ )
     833             :             {
     834      808000 :                 output[0][i] = L_shr( L_add( output[0][i], output[1][i] ), 1 );
     835      808000 :                 move32();
     836             :             }
     837             :         }
     838             :     }
     839             : 
     840             :     /*----------------------------------------------------------------*
     841             :      * Update parameters for stereo CNA
     842             :      *----------------------------------------------------------------*/
     843             : 
     844      149276 :     stereo_cna_update_params_fx( hCPE, output, output_frame, tdm_ratio_idx );
     845             : 
     846             :     /*----------------------------------------------------------------*
     847             :      * Synthesis synchronization between CPE modes
     848             :      *----------------------------------------------------------------*/
     849             : 
     850      149276 :     IF( !st_ivas->sba_dirac_stereo_flag )
     851             :     {
     852      147938 :         synchro_synthesis_fx( ivas_total_brate, hCPE, output, output_frame, 0, Q11 );
     853             :     }
     854             : 
     855      149276 :     test();
     856      149276 :     test();
     857      149276 :     test();
     858      149276 :     test();
     859      149276 :     IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->nchan_out, 1 ) && ( is_DTXrate( ivas_total_brate ) == 0 || ( EQ_16( is_DTXrate( ivas_total_brate ), 1 ) && is_DTXrate( st_ivas->hDecoderConfig->last_ivas_total_brate ) == 0 ) ) )
     860             :     {
     861        5909 :         applyDmxMdctStereo_fx( hCPE, output, output_frame );
     862             :     }
     863             : 
     864             :     /*----------------------------------------------------------------*
     865             :      * IC-BWE: output LB and HB mix in ACELP mode
     866             :      *----------------------------------------------------------------*/
     867             : 
     868      149276 :     stereo_icBWE_decproc_fx( hCPE, output, outputHB_fx, last_core, last_bwidth, output_frame );
     869      149276 :     smooth_dft2td_transition_fx( hCPE, output, output_frame );
     870             : 
     871             :     /*----------------------------------------------------------------*
     872             :      * Temporal ICA, stereo adjustment and upmix
     873             :      *----------------------------------------------------------------*/
     874             : 
     875      149276 :     stereo_tca_dec_fx( hCPE, output, output_frame );
     876             : 
     877             :     /*----------------------------------------------------------------*
     878             :      * Common Stereo updates
     879             :      *----------------------------------------------------------------*/
     880             : 
     881      149276 :     hCPE->last_element_brate = hCPE->element_brate;
     882      149276 :     move32();
     883      149276 :     hCPE->last_element_mode = hCPE->element_mode;
     884      149276 :     move32();
     885             : 
     886      149276 :     if ( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
     887             :     {
     888        6529 :         hCPE->element_brate = element_brate_ref;
     889        6529 :         move32();
     890             :     }
     891             : 
     892      149276 :     test();
     893      149276 :     IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || EQ_16( hCPE->element_mode, IVAS_CPE_TD ) )
     894             :     {
     895       63378 :         stereo_cng_dec_update( hCPE, ivas_total_brate );
     896             :     }
     897             : 
     898      149276 :     st_ivas->BER_detect = s_or( st_ivas->BER_detect, sts[0]->BER_detect );
     899      149276 :     st_ivas->BER_detect = s_or( st_ivas->BER_detect, sts[1]->BER_detect );
     900      149276 :     move16();
     901      149276 :     move16();
     902             : 
     903             : 
     904      149276 :     pop_wmops();
     905      149276 :     return error;
     906             : }
     907             : 
     908             : #ifdef FIX_1320_STACK_CPE_DECODER
     909             : 
     910             : /*-------------------------------------------------------------------------
     911             :  * stereo_dft_dec_main()
     912             :  *
     913             :  * DFT decoder main function
     914             :  *-------------------------------------------------------------------------*/
     915             : 
     916       42543 : static ivas_error stereo_dft_dec_main(
     917             :     CPE_DEC_HANDLE hCPE,              /* i/o: CPE decoder structure               */
     918             :     const Word32 ivas_total_brate,    /* i  : IVAS total bitrate                  */
     919             :     const Word16 n_channels,          /* i  : number of channels to be decoded    */
     920             :     Word32 *p_res_buf_fx,             /* i  : DFT stereo residual S signal        */
     921             :     Word32 *output[],                 /* o  : output synthesis signal             */
     922             :     Word32 outputHB_fx[][L_FRAME48k], /* o  : output HB synthesis signal          */
     923             :     const Word16 output_frame,        /* i  : output frame length per channel     */
     924             :     const Word32 output_Fs            /* i  : output sampling rate                */
     925             : )
     926             : {
     927             :     Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX];
     928             :     Word32 res_buf_fx[STEREO_DFT_N_8k]; /* Q(q_res_buf) */
     929             :     Word16 n;
     930             :     Word16 q_res_buf, q_dft;
     931             :     Decoder_State *st0;
     932             :     ivas_error error;
     933             :     Word16 shift;
     934             :     Word32 tmp1, tmp2;
     935             :     Word16 shift1, shift2;
     936             : 
     937       42543 :     st0 = hCPE->hCoreCoder[0];
     938             : 
     939       42543 :     q_res_buf = Q8;
     940       42543 :     move16();
     941             : 
     942       42543 :     set32_fx( DFT_fx[0], 0, STEREO_DFT_BUF_MAX );
     943       42543 :     set32_fx( DFT_fx[1], 0, STEREO_DFT_BUF_MAX );
     944             : 
     945             :     /* copy from temporary buffer */
     946       42543 :     test();
     947       42543 :     IF( hCPE->hStereoDft->res_cod_band_max > 0 && !st0->bfi )
     948             :     {
     949       16950 :         Copy32( p_res_buf_fx, res_buf_fx, STEREO_DFT_N_8k );
     950             :     }
     951             : 
     952             :     /* core decoder */
     953       42543 :     IF( NE_32( ( error = ivas_core_dec_fx( NULL, NULL, hCPE, NULL, n_channels, output, outputHB_fx, DFT_fx, 0 ) ), IVAS_ERR_OK ) )
     954             :     {
     955           0 :         return error;
     956             :     }
     957             : 
     958             :     /* Scaling of DFT's */
     959       42543 :     maximum_abs_32_fx( DFT_fx[0], STEREO_DFT_BUF_MAX, &tmp1 );
     960       42543 :     maximum_abs_32_fx( DFT_fx[1], STEREO_DFT_BUF_MAX, &tmp2 );
     961             : 
     962       42543 :     IF( tmp1 == 0 )
     963             :     {
     964        5534 :         shift1 = Q31;
     965        5534 :         move16();
     966             :     }
     967             :     ELSE
     968             :     {
     969       37009 :         shift1 = norm_l( tmp1 );
     970             :     }
     971       42543 :     IF( tmp2 == 0 )
     972             :     {
     973       22934 :         shift2 = Q31;
     974       22934 :         move16();
     975             :     }
     976             :     ELSE
     977             :     {
     978       19609 :         shift2 = norm_l( tmp2 );
     979             :     }
     980       42543 :     shift = s_min( shift1, shift2 );
     981             : 
     982       42543 :     IF( NE_16( shift, 31 ) )
     983             :     {
     984             : #ifdef FIX_1946_CRASH_JBM_PROCESSING
     985       37012 :         shift = sub( add( hCPE->hStereoDft->q_dft, shift ), Q17 ); /* Q17 for guard bits */
     986             : #else
     987             :         shift = sub( add( hCPE->hStereoDft->q_dft, shift ), Q16 ); /* Q16 for guard bits */
     988             : #endif
     989             : 
     990       37012 :         IF( GT_16( shift, hCPE->hStereoDft->q_dft ) )
     991             :         {
     992         247 :             Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); // shift
     993         247 :             Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); // shift
     994         247 :             hCPE->hStereoDft->q_dft = shift;
     995         247 :             move16();
     996             :         }
     997             :     }
     998             :     ELSE
     999             :     {
    1000        5531 :         hCPE->hStereoDft->q_dft = Q8;
    1001        5531 :         move16();
    1002             :     }
    1003             : 
    1004             :     /* DFT Stereo residual decoding */
    1005       42543 :     test();
    1006       42543 :     IF( hCPE->hStereoDft->res_cod_band_max > 0 && !st0->bfi )
    1007             :     {
    1008             :         Word16 q;
    1009             :         Word16 q_out_DFT[2];
    1010             : 
    1011       16950 :         q = Q11;
    1012       16950 :         move16();
    1013             : 
    1014       16950 :         Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, ( ( 2 * NB_SUBFR16k ) + 2 ), -( Q10 ) ); // Q16->Q6
    1015             : 
    1016       16950 :         stereo_dft_dec_res_fx( hCPE, res_buf_fx, q_res_buf, output[1] );
    1017             : 
    1018       16950 :         Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, ( ( 2 * NB_SUBFR16k ) + 2 ), 10 ); // Q6->Q16
    1019             : 
    1020       16950 :         Scale_sig32( output[1], L_FRAME8k, ( Q11 - Q15 ) ); // Q15 -> Q11
    1021             : 
    1022       16950 :         q_out_DFT[0] = q_out_DFT[1] = hCPE->hStereoDft->q_dft;
    1023       16950 :         move16();
    1024       16950 :         move16();
    1025             : 
    1026       16950 :         stereo_dft_dec_analyze_fx( hCPE, output[1], DFT_fx, 1, L_FRAME8k, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0, &q, q_out_DFT );
    1027             : 
    1028       16950 :         Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_out_DFT[1] ) ); // q_dft
    1029             :     }
    1030             : 
    1031             :     /* DFT stereo CNG */
    1032       42543 :     q_dft = hCPE->hStereoDft->q_dft;
    1033       42543 :     move16();
    1034       42543 :     stereo_dtf_cng_fx( hCPE, ivas_total_brate, DFT_fx, output_frame, q_dft );
    1035             : 
    1036             :     /* decoding */
    1037       42543 :     IF( EQ_16( hCPE->nchan_out, 1 ) )
    1038             :     {
    1039        5348 :         IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) )
    1040             :         {
    1041          21 :             hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft;
    1042          21 :             move16();
    1043         105 :             FOR( Word16 ii = 0; ii < (Word16) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ )
    1044             :             {
    1045          84 :                 hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft;
    1046          84 :                 move16();
    1047             :             }
    1048          21 :             hCPE->hStereoDft->first_frame = 0;
    1049          21 :             move16();
    1050             :         }
    1051             : 
    1052        5348 :         scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // q_dft
    1053        5348 :         hCPE->hStereoDft->q_res_cod_mem_fx = hCPE->hStereoDft->q_dft;
    1054        5348 :         move16();
    1055        5348 :         stereo_dft_unify_dmx_fx( hCPE->hStereoDft, st0, DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng->prev_sid_nodata );
    1056        5348 :         scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q15, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // Q15
    1057        5348 :         hCPE->hStereoDft->q_res_cod_mem_fx = Q15;
    1058        5348 :         move16();
    1059             :     }
    1060             :     ELSE
    1061             :     {
    1062       37195 :         IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) )
    1063             :         {
    1064         453 :             hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft;
    1065         453 :             move16();
    1066        2265 :             FOR( Word16 ii = 0; ii < (Word16) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ )
    1067             :             {
    1068        1812 :                 hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft;
    1069        1812 :                 move16();
    1070             :             }
    1071         453 :             hCPE->hStereoDft->first_frame = 0;
    1072         453 :             move16();
    1073             :         }
    1074             : 
    1075       37195 :         scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // q_dft
    1076       37195 :         hCPE->hStereoDft->q_res_cod_mem_fx = hCPE->hStereoDft->q_dft;
    1077       37195 :         move16();
    1078             : 
    1079       37195 :         stereo_dft_dec_fx( hCPE->hStereoDft, st0, DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng, 0, 0, 0, 0, 0, 0, MAX_PARAM_SPATIAL_SUBFRAMES );
    1080       37195 :         scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q15, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // Q15
    1081       37195 :         hCPE->hStereoDft->q_res_cod_mem_fx = Q15;
    1082       37195 :         move16();
    1083             :     }
    1084             : 
    1085      122281 :     FOR( n = 0; n < hCPE->nchan_out; n++ )
    1086             :     {
    1087       79738 :         Scale_sig32( output[n], L_FRAME48k, sub( hCPE->hStereoDft->q_dft, Q11 ) );                                                 // q_dft
    1088       79738 :         scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
    1089       79738 :         hCPE->q_output_mem_fx[n] = hCPE->hStereoDft->q_dft;
    1090       79738 :         move16();
    1091             :     }
    1092             : 
    1093             :     /* synthesis iFFT */
    1094      122281 :     FOR( n = 0; n < hCPE->nchan_out; n++ )
    1095             :     {
    1096       79738 :         stereo_dft_dec_synthesize_fx( hCPE, DFT_fx, n, output[n], output_frame );
    1097             :     }
    1098             : 
    1099      122281 :     FOR( n = 0; n < hCPE->nchan_out; n++ )
    1100             :     {
    1101       79738 :         Scale_sig32( output[n], L_FRAME48k, sub( Q11, hCPE->hStereoDft->q_dft ) );                                                 // Q11
    1102       79738 :         scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
    1103       79738 :         hCPE->q_output_mem_fx[n] = Q11;
    1104       79738 :         move16();
    1105             :     }
    1106             : 
    1107       42543 :     return IVAS_ERR_OK;
    1108             : }
    1109             : 
    1110             : #endif
    1111             : 
    1112             : /*-------------------------------------------------------------------------
    1113             :  * create_cpe_dec_fx()
    1114             :  *
    1115             :  * Create, allocate and initialize IVAS decoder CPE handle
    1116             :  *-------------------------------------------------------------------------*/
    1117             : 
    1118        2826 : ivas_error create_cpe_dec(
    1119             :     Decoder_Struct *st_ivas,   /* i/o: IVAS decoder structure      */
    1120             :     const Word16 cpe_id,       /* i  : CPE # identifier            */
    1121             :     const Word32 element_brate /* i  : element bitrate             */
    1122             : )
    1123             : {
    1124             :     Word16 i, n;
    1125             :     CPE_DEC_HANDLE hCPE;
    1126             :     Decoder_State *st;
    1127             :     Word32 output_Fs;
    1128             :     ivas_error error;
    1129             :     Word32 cpe_brate;
    1130             : 
    1131        2826 :     error = IVAS_ERR_OK;
    1132        2826 :     move32();
    1133             : 
    1134             :     /*-----------------------------------------------------------------*
    1135             :      * Allocate CPE handle
    1136             :      *-----------------------------------------------------------------*/
    1137             : 
    1138        2826 :     IF( ( hCPE = (CPE_DEC_HANDLE) malloc( sizeof( CPE_DEC_DATA ) ) ) == NULL )
    1139             :     {
    1140           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CPE\n" ) );
    1141             :     }
    1142             : 
    1143             :     /*-----------------------------------------------------------------*
    1144             :      * Initialization - general parameters
    1145             :      *-----------------------------------------------------------------*/
    1146             : 
    1147        2826 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
    1148        2826 :     move32();
    1149        2826 :     hCPE->cpe_id = cpe_id;
    1150        2826 :     move16();
    1151        2826 :     hCPE->element_brate = element_brate;
    1152        2826 :     move32();
    1153        2826 :     hCPE->last_element_brate = hCPE->element_brate;
    1154        2826 :     move32();
    1155        2826 :     hCPE->element_mode = st_ivas->element_mode_init;
    1156        2826 :     move16();
    1157        2826 :     hCPE->last_element_mode = st_ivas->element_mode_init;
    1158        2826 :     move16();
    1159             : 
    1160        2826 :     hCPE->hStereoDft = NULL;
    1161        2826 :     hCPE->hStereoDftDmx = NULL;
    1162        2826 :     hCPE->hStereoTD = NULL;
    1163        2826 :     hCPE->hStereoMdct = NULL;
    1164        2826 :     hCPE->hStereoTCA = NULL;
    1165        2826 :     hCPE->hStereoICBWE = NULL;
    1166        2826 :     hCPE->hStereoCng = NULL;
    1167             : 
    1168        2826 :     hCPE->stereo_switching_counter = 10;
    1169        2826 :     move16();
    1170        2826 :     hCPE->NbFrameMod = 7;
    1171        2826 :     move16();
    1172        2826 :     hCPE->lt_es_em_fx = 0;
    1173        2826 :     move32();
    1174             : 
    1175             :     /* Note: nchan_out is considered to be related to the structure. This is nchan_out for CPE and for MASA_format is always 2. */
    1176        2826 :     test();
    1177        2826 :     test();
    1178        2826 :     test();
    1179        2826 :     IF( EQ_16( (Word16) st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MC_FORMAT ) )
    1180             :     {
    1181        2087 :         hCPE->nchan_out = CPE_CHANNELS;
    1182        2087 :         move16();
    1183             :     }
    1184             :     ELSE
    1185             :     {
    1186         739 :         hCPE->nchan_out = s_min( CPE_CHANNELS, st_ivas->hDecoderConfig->nchan_out );
    1187         739 :         move16();
    1188             :     }
    1189             : 
    1190        2826 :     test();
    1191        2826 :     test();
    1192        2826 :     test();
    1193        2826 :     IF( EQ_16( extract_l( st_ivas->ivas_format ), MASA_ISM_FORMAT ) && ( EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) )
    1194             :     {
    1195          33 :         cpe_brate = element_brate;
    1196          33 :         move32();
    1197             :     }
    1198             :     ELSE
    1199             :     {
    1200        2793 :         cpe_brate = st_ivas->hDecoderConfig->ivas_total_brate;
    1201        2793 :         move32();
    1202             :     }
    1203             : 
    1204        2826 :     test();
    1205        2826 :     test();
    1206        2826 :     test();
    1207        2826 :     test();
    1208        5633 :     if ( ( ( EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) && LT_32( st_ivas->hDecoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) ) ||
    1209        2868 :            ( EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) && LT_32( cpe_brate, MASA_STEREO_MIN_BITRATE ) ) ) &&
    1210          28 :          GT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) )
    1211             :     {
    1212          28 :         hCPE->nchan_out = 1;
    1213          28 :         move16();
    1214             :     }
    1215             : 
    1216        8478 :     FOR( n = 0; n < CPE_CHANNELS; n++ )
    1217             :     {
    1218        5652 :         set32_fx( hCPE->prev_hb_synth_fx[n], 0, NS2SA_FX2( output_Fs, L_sub( IVAS_DEC_DELAY_NS, DELAY_BWE_TOTAL_NS ) ) );
    1219        5652 :         set32_fx( hCPE->prev_synth_fx[n], 0, NS2SA_FX2( output_Fs, L_sub( IVAS_DEC_DELAY_NS, STEREO_DFT32MS_OVL_NS ) ) );
    1220             :     }
    1221        2826 :     hCPE->q_prev_synth_fx = 0;
    1222        2826 :     move16();
    1223        2826 :     hCPE->brate_surplus = 0;
    1224        2826 :     move32();
    1225             : 
    1226             :     /*-----------------------------------------------------------------*
    1227             :      * DFT stereo I/O Buffers: allocate and initialize
    1228             :      *-----------------------------------------------------------------*/
    1229             : 
    1230        8478 :     FOR( i = 0; i < CPE_CHANNELS; i++ )
    1231             :     {
    1232        5652 :         test();
    1233        5652 :         test();
    1234        5652 :         test();
    1235        5652 :         test();
    1236        5652 :         test();
    1237        5652 :         IF( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) ||
    1238             :             ( EQ_16( (Word16) st_ivas->ivas_format, MC_FORMAT ) && EQ_16( (Word16) st_ivas->mc_mode, MC_MODE_MCMASA ) ) || st_ivas->sba_dirac_stereo_flag )
    1239             :         {
    1240         778 :             IF( ( hCPE->input_mem_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) ) ) == NULL )
    1241             :             {
    1242           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) );
    1243             :             }
    1244         778 :             set32_fx( hCPE->input_mem_fx[i], 0, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) );
    1245             : 
    1246         778 :             IF( ( hCPE->input_mem_LB_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * STEREO_DFT32MS_OVL_16k ) ) == NULL )
    1247             :             {
    1248           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) );
    1249             :             }
    1250         778 :             set32_fx( hCPE->input_mem_LB_fx[i], 0, STEREO_DFT32MS_OVL_16k );
    1251             : 
    1252         778 :             IF( i == 0 )
    1253             :             {
    1254         389 :                 IF( ( hCPE->input_mem_BPF_fx[0] = (Word32 *) malloc( sizeof( Word32 ) * STEREO_DFT32MS_OVL_16k ) ) == NULL )
    1255             :                 {
    1256           0 :                     return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) );
    1257             :                 }
    1258         389 :                 set32_fx( hCPE->input_mem_BPF_fx[0], 0, STEREO_DFT32MS_OVL_16k );
    1259             :             }
    1260             : 
    1261         778 :             IF( ( hCPE->output_mem_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) ) ) == NULL )
    1262             :             {
    1263           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) );
    1264             :             }
    1265         778 :             set32_fx( hCPE->output_mem_fx[i], 0, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) );
    1266         778 :             hCPE->q_output_mem_fx[i] = Q11;
    1267         778 :             move16();
    1268         778 :             IF( LT_16( i, hCPE->nchan_out ) )
    1269             :             {
    1270         728 :                 IF( ( hCPE->prev_synth_chs_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * NS2SA_FX2( output_Fs, FRAME_SIZE_NS ) ) ) == NULL )
    1271             :                 {
    1272           0 :                     return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) );
    1273             :                 }
    1274         728 :                 set32_fx( hCPE->prev_synth_chs_fx[i], 0, NS2SA_FX2( output_Fs, FRAME_SIZE_NS ) );
    1275             :             }
    1276             :             ELSE
    1277             :             {
    1278          50 :                 hCPE->prev_synth_chs_fx[i] = NULL;
    1279             :             }
    1280             :         }
    1281             :         ELSE
    1282             :         {
    1283        4874 :             hCPE->input_mem_fx[i] = NULL;
    1284        4874 :             hCPE->input_mem_LB_fx[i] = NULL;
    1285        4874 :             if ( i == 0 )
    1286             :             {
    1287        2437 :                 hCPE->input_mem_BPF_fx[0] = NULL;
    1288             :             }
    1289        4874 :             hCPE->output_mem_fx[i] = NULL;
    1290        4874 :             hCPE->q_output_mem_fx[i] = 0;
    1291        4874 :             move16();
    1292        4874 :             hCPE->prev_synth_chs_fx[i] = NULL;
    1293             :         }
    1294             :     }
    1295             : 
    1296             :     /*-----------------------------------------------------------------*
    1297             :      * CoreCoder, 2 instances: allocate and initialize
    1298             :      *-----------------------------------------------------------------*/
    1299             : 
    1300        8404 :     FOR( n = 0; n < CPE_CHANNELS; n++ )
    1301             :     {
    1302        5615 :         IF( st_ivas->sba_dirac_stereo_flag && EQ_16( st_ivas->nchan_transport, 1 ) )
    1303             :         {
    1304             :             /* for SBA DirAC stereo output CPE element is only used for upmix, core coder is found in SCE element used for core decoding */
    1305          37 :             BREAK;
    1306             :         }
    1307             : 
    1308        5578 :         IF( ( st = (DEC_CORE_HANDLE) malloc( sizeof( Decoder_State ) ) ) == NULL )
    1309             :         {
    1310           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) );
    1311             :         }
    1312             : 
    1313        5578 :         copy_decoder_config( st_ivas, st );
    1314             : 
    1315             :         // st->total_brate = hCPE->element_brate / ( CPE_CHANNELS );
    1316        5578 :         st->total_brate = L_shr( hCPE->element_brate, 1 ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
    1317        5578 :         move32();
    1318        5578 :         st->mct_chan_mode = MCT_CHAN_MODE_REGULAR;
    1319        5578 :         move32();
    1320        5578 :         st->is_ism_format = 0;
    1321        5578 :         move16();
    1322             : 
    1323        5578 :         IF( NE_32( ( error = init_decoder_ivas_fx( st, n, st_ivas->mc_mode ) ), IVAS_ERR_OK ) )
    1324             :         {
    1325           0 :             return error;
    1326             :         }
    1327             : 
    1328        5578 :         hCPE->hCoreCoder[n] = st;
    1329             :     }
    1330             : 
    1331             :     /*-----------------------------------------------------------------*
    1332             :      * DFT stereo initialization
    1333             :      *-----------------------------------------------------------------*/
    1334             : 
    1335             : 
    1336        2826 :     test();
    1337        2826 :     IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || ( st_ivas->sba_dirac_stereo_flag && hCPE->cpe_id == 0 ) )
    1338             :     {
    1339         194 :         IF( NE_32( ( error = stereo_dft_dec_create_fx( &( hCPE->hStereoDft ), hCPE->element_brate, output_Fs, st_ivas->sba_dirac_stereo_flag, st_ivas->nchan_transport ) ), IVAS_ERR_OK ) )
    1340             :         {
    1341           0 :             return error;
    1342             :         }
    1343             :     }
    1344             : 
    1345             :     /*-----------------------------------------------------------------*
    1346             :      * DFT stereo mono DMX initialization
    1347             :      *-----------------------------------------------------------------*/
    1348             : 
    1349        2826 :     test();
    1350        2826 :     IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->nchan_out, 1 ) )
    1351             :     {
    1352          45 :         IF( ( hCPE->hStereoDftDmx = (STEREO_DFT_DMX_DATA_HANDLE) malloc( sizeof( STEREO_DFT_DMX_DATA ) ) ) == NULL )
    1353             :         {
    1354           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo DFT mono output\n" ) );
    1355             :         }
    1356             : 
    1357          45 :         stereo_dft_dmx_out_reset_fx( hCPE->hStereoDftDmx );
    1358             :     }
    1359             : 
    1360             :     /*-----------------------------------------------------------------*
    1361             :      * Temporal inter-channel alignment initialization
    1362             :      *-----------------------------------------------------------------*/
    1363             : 
    1364        2826 :     test();
    1365        2826 :     test();
    1366        2826 :     test();
    1367        2826 :     IF( ( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) && LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) ) ) && NE_16( hCPE->nchan_out, 1 ) )
    1368             :     {
    1369          99 :         IF( ( hCPE->hStereoTCA = (STEREO_TCA_DEC_HANDLE) malloc( sizeof( STEREO_TCA_DEC_DATA ) ) ) == NULL )
    1370             :         {
    1371           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) );
    1372             :         }
    1373             : 
    1374          99 :         stereo_tca_init_dec_fx( hCPE->hStereoTCA );
    1375             :     }
    1376             : 
    1377             :     /*-----------------------------------------------------------------*
    1378             :      * Stereo IC BWE initialization
    1379             :      *-----------------------------------------------------------------*/
    1380             : 
    1381        2826 :     test();
    1382        2826 :     test();
    1383        2826 :     IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && !( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) ) )
    1384             :     {
    1385          90 :         IF( ( hCPE->hStereoICBWE = (STEREO_ICBWE_DEC_HANDLE) malloc( sizeof( STEREO_ICBWE_DEC_DATA ) ) ) == NULL )
    1386             :         {
    1387           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE\n" ) );
    1388             :         }
    1389             : 
    1390          90 :         stereo_icBWE_init_dec_fx( hCPE->hStereoICBWE );
    1391             :     }
    1392             : 
    1393             :     /*-----------------------------------------------------------------*
    1394             :      * TD stereo initialization
    1395             :      *-----------------------------------------------------------------*/
    1396             : 
    1397        2826 :     IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) )
    1398             :     {
    1399           0 :         IF( ( hCPE->hStereoTD = (STEREO_TD_DEC_DATA_HANDLE) malloc( sizeof( STEREO_TD_DEC_DATA ) ) ) == NULL )
    1400             :         {
    1401           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD Stereo\n" ) );
    1402             :         }
    1403             : 
    1404           0 :         stereo_td_init_dec_fx( hCPE->hStereoTD, hCPE->last_element_mode );
    1405             :     }
    1406             : 
    1407             :     /*-----------------------------------------------------------------*
    1408             :      * MDCT stereo initialization
    1409             :      *-----------------------------------------------------------------*/
    1410             : 
    1411        2826 :     test();
    1412        2826 :     IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( st_ivas->nCPE, 1 ) )
    1413             :     {
    1414         371 :         IF( ( hCPE->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL )
    1415             :         {
    1416           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo MDCT\n" ) );
    1417             :         }
    1418             : 
    1419         371 :         test();
    1420         371 :         IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) && LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) )
    1421             :         {
    1422          13 :             hCPE->hStereoMdct->use_itd = 1;
    1423          13 :             move16();
    1424             :         }
    1425             :         ELSE
    1426             :         {
    1427         358 :             hCPE->hStereoMdct->use_itd = 0;
    1428         358 :             move16();
    1429             :         }
    1430             : 
    1431         371 :         hCPE->hStereoMdct->reverse_dmx = 0;
    1432         371 :         move16();
    1433         371 :         hCPE->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26;
    1434         371 :         move32();
    1435         371 :         set16_fx( hCPE->hStereoMdct->prev_ms_mask[0], 0, MAX_SFB );
    1436         371 :         set16_fx( hCPE->hStereoMdct->prev_ms_mask[1], 0, MAX_SFB );
    1437         371 :         hCPE->hStereoMdct->lastCoh_fx = ONE_IN_Q14;
    1438         371 :         move16();
    1439         371 :         hCPE->hStereoMdct->mdct_stereo_mode[0] = SMDCT_DUAL_MONO;
    1440         371 :         move16();
    1441         371 :         hCPE->hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO;
    1442         371 :         move16();
    1443         371 :         hCPE->hStereoMdct->IGFStereoMode[0] = -1;
    1444         371 :         move16();
    1445         371 :         hCPE->hStereoMdct->IGFStereoMode[1] = -1;
    1446         371 :         move16();
    1447             :     }
    1448             : 
    1449             :     /*-----------------------------------------------------------------*
    1450             :      * Stereo CNG initialization
    1451             :      *-----------------------------------------------------------------*/
    1452             : 
    1453        2826 :     test();
    1454        2826 :     IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
    1455             :     {
    1456          98 :         IF( ( hCPE->hStereoCng = (STEREO_CNG_DEC_HANDLE) malloc( sizeof( STEREO_CNG_DEC ) ) ) == NULL )
    1457             :         {
    1458           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo CNG\n" ) );
    1459             :         }
    1460          98 :         stereo_cng_init_dec_fx( hCPE->hStereoCng, &hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->frameSize );
    1461             :     }
    1462             : 
    1463        2826 :     st_ivas->hCPE[cpe_id] = hCPE;
    1464             : 
    1465        2826 :     return error;
    1466             : }
    1467             : 
    1468             : 
    1469             : /*-------------------------------------------------------------------------
    1470             :  * destroy_cpe_dec_fx()
    1471             :  *
    1472             :  * Destroy and deallocate IVAS decoder CPE handle
    1473             :  *-------------------------------------------------------------------------*/
    1474             : 
    1475        2826 : void destroy_cpe_dec(
    1476             :     CPE_DEC_HANDLE hCPE /* i/o: CPE decoder structure       */
    1477             : )
    1478             : {
    1479             :     Word16 n;
    1480             :     Decoder_State *st;
    1481             : 
    1482        8478 :     FOR( n = 0; n < CPE_CHANNELS; n++ )
    1483             :     {
    1484        5652 :         st = hCPE->hCoreCoder[n];
    1485             : 
    1486        5652 :         IF( st != NULL )
    1487             :         {
    1488        5474 :             destroy_core_dec_fx( st );
    1489             : 
    1490        5474 :             free( st );
    1491        5474 :             st = NULL;
    1492             :         }
    1493             :     }
    1494             : 
    1495        2826 :     IF( hCPE->hStereoDft != NULL )
    1496             :     {
    1497         176 :         stereo_dft_dec_destroy_fx( &( hCPE->hStereoDft ) );
    1498         176 :         hCPE->hStereoDft = NULL;
    1499             :     }
    1500             : 
    1501        2826 :     IF( hCPE->hStereoDftDmx != NULL )
    1502             :     {
    1503          31 :         free( hCPE->hStereoDftDmx );
    1504          31 :         hCPE->hStereoDftDmx = NULL;
    1505             :     }
    1506             : 
    1507        2826 :     IF( hCPE->hStereoTD != NULL )
    1508             :     {
    1509           1 :         free( hCPE->hStereoTD );
    1510           1 :         hCPE->hStereoTD = NULL;
    1511             :     }
    1512             : 
    1513        2826 :     IF( hCPE->hStereoMdct != NULL )
    1514             :     {
    1515         401 :         free( hCPE->hStereoMdct );
    1516         401 :         hCPE->hStereoMdct = NULL;
    1517             :     }
    1518             : 
    1519        2826 :     IF( hCPE->hStereoTCA != NULL )
    1520             :     {
    1521          98 :         free( hCPE->hStereoTCA );
    1522          98 :         hCPE->hStereoTCA = NULL;
    1523             :     }
    1524             : 
    1525        2826 :     IF( hCPE->hStereoICBWE != NULL )
    1526             :     {
    1527         103 :         free( hCPE->hStereoICBWE );
    1528         103 :         hCPE->hStereoICBWE = NULL;
    1529             :     }
    1530             : 
    1531        2826 :     IF( hCPE->input_mem_LB_fx[0] != NULL )
    1532             :     {
    1533        1167 :         FOR( n = 0; n < CPE_CHANNELS; n++ )
    1534             :         {
    1535         778 :             free( hCPE->input_mem_LB_fx[n] );
    1536         778 :             hCPE->input_mem_LB_fx[n] = NULL;
    1537         778 :             free( hCPE->input_mem_fx[n] );
    1538         778 :             hCPE->input_mem_fx[n] = NULL;
    1539         778 :             free( hCPE->output_mem_fx[n] );
    1540         778 :             hCPE->output_mem_fx[n] = NULL;
    1541             : 
    1542         778 :             IF( hCPE->prev_synth_chs_fx[n] != NULL )
    1543             :             {
    1544         741 :                 free( hCPE->prev_synth_chs_fx[n] );
    1545         741 :                 hCPE->prev_synth_chs_fx[n] = NULL;
    1546             :             }
    1547             :         }
    1548         389 :         free( hCPE->input_mem_BPF_fx[0] );
    1549         389 :         hCPE->input_mem_BPF_fx[0] = NULL;
    1550             :     }
    1551             : 
    1552        2826 :     IF( hCPE->hStereoCng != NULL )
    1553             :     {
    1554          81 :         free( hCPE->hStereoCng );
    1555          81 :         hCPE->hStereoCng = NULL;
    1556             :     }
    1557             : 
    1558        2826 :     free( hCPE );
    1559             : 
    1560        2826 :     return;
    1561             : }
    1562             : 
    1563             : 
    1564             : /*-------------------------------------------------------------------------
    1565             :  * read_stereo_mode_and_bwidth_fx()
    1566             :  *
    1567             :  * Read stereo technology info & audio bandwidth
    1568             :  *-------------------------------------------------------------------------*/
    1569             : 
    1570      410720 : static void read_stereo_mode_and_bwidth_fx(
    1571             :     CPE_DEC_HANDLE hCPE,          /* i/o: CPE handle             */
    1572             :     const Decoder_Struct *st_ivas /* i  : decoder main structure */
    1573             : )
    1574             : {
    1575             :     Decoder_State **sts;
    1576             : 
    1577             :     /*-----------------------------------------------------------------*
    1578             :      * BFI or NO_DATA frame: Use stereo parameters from last (active) frame
    1579             :      *-----------------------------------------------------------------*/
    1580             : 
    1581      410720 :     test();
    1582      410720 :     if ( st_ivas->bfi || LT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) )
    1583             :     {
    1584       18332 :         hCPE->element_mode = hCPE->last_element_mode;
    1585       18332 :         move16();
    1586             :     }
    1587             : 
    1588             :     /*-----------------------------------------------------------------*
    1589             :      * SID frame: get element mode from SID side info
    1590             :      *-----------------------------------------------------------------*/
    1591             : 
    1592      392388 :     ELSE IF( EQ_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) )
    1593             :     {
    1594        1962 :         SWITCH( st_ivas->sid_format )
    1595             :         {
    1596        1432 :             case SID_DFT_STEREO:
    1597        1432 :                 hCPE->element_mode = IVAS_CPE_DFT;
    1598        1432 :                 move16();
    1599             :                 /* Read CNG type */
    1600        1432 :                 hCPE->hCoreCoder[0]->cng_type = get_next_indice_fx( hCPE->hCoreCoder[0], 1 );
    1601             : 
    1602             :                 /* Read BW information in SID */
    1603        1432 :                 hCPE->hCoreCoder[0]->bwidth = get_next_indice_fx( hCPE->hCoreCoder[0], 2 );
    1604        1432 :                 move16();
    1605        1432 :                 move16();
    1606             : 
    1607        1432 :                 BREAK;
    1608         456 :             case SID_MDCT_STEREO:
    1609             :                 /* 2TC SBA DTX also uses MDCT-Stereo DTX */
    1610             :             case SID_SBA_2TC:
    1611         456 :                 hCPE->element_mode = IVAS_CPE_MDCT;
    1612         456 :                 move16();
    1613         456 :                 BREAK;
    1614           0 :             case SID_SBA_1TC:
    1615           0 :                 assert( !"Forbidden value for SID format in CPE (SBA 1TC), should have already been adressed earlier" );
    1616             :                 BREAK;
    1617           0 :             case SID_MASA_1TC:
    1618           0 :                 hCPE->element_mode = IVAS_SCE;
    1619           0 :                 move16();
    1620           0 :                 BREAK;
    1621          74 :             case SID_MASA_2TC:
    1622             :                 /* 2TC MASA DTX uses MDCT or DFT based core */
    1623          74 :                 if ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) )
    1624             :                 {
    1625           0 :                     hCPE->element_mode = IVAS_CPE_DFT;
    1626           0 :                     move16();
    1627             :                 }
    1628          74 :                 IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
    1629             :                 {
    1630             :                     /* Read CNG type */
    1631          74 :                     hCPE->hCoreCoder[0]->cng_type = get_next_indice_fx( hCPE->hCoreCoder[0], 1 );
    1632             : 
    1633             :                     /* Read BW information in SID */
    1634          74 :                     hCPE->hCoreCoder[0]->bwidth = get_next_indice_fx( hCPE->hCoreCoder[0], 2 );
    1635          74 :                     move16();
    1636          74 :                     move16();
    1637             :                 }
    1638          74 :                 BREAK;
    1639           0 :             default:
    1640             :                 /* this is what has been done for all modes previously, may need adaptation in the future */
    1641           0 :                 hCPE->element_mode = hCPE->last_element_mode;
    1642           0 :                 move16();
    1643           0 :                 BREAK;
    1644             :         }
    1645             :     }
    1646             : 
    1647             :     /*-----------------------------------------------------------------*
    1648             :      * active frame: read element mode and audio bandwidth info
    1649             :      *-----------------------------------------------------------------*/
    1650             : 
    1651             :     ELSE
    1652             :     {
    1653      390426 :         sts = hCPE->hCoreCoder;
    1654      390426 :         test();
    1655      390426 :         IF( st_ivas->hMCT && hCPE->cpe_id != 0 )
    1656             :         {
    1657      161050 :             sts[0]->bwidth = st_ivas->hCPE[0]->hCoreCoder[0]->bwidth;
    1658      161050 :             move16();
    1659      161050 :             sts[1]->bwidth = st_ivas->hCPE[0]->hCoreCoder[0]->bwidth;
    1660      161050 :             move16();
    1661             :         }
    1662             :         ELSE
    1663             :         {
    1664             :             /* read stereo technology info */
    1665      229376 :             test();
    1666      229376 :             IF( LT_32( hCPE->element_brate, MIN_BRATE_MDCT_STEREO ) && st_ivas->hMCT == NULL )
    1667             :             {
    1668       52040 :                 hCPE->element_mode = add( get_next_indice_fx( sts[0], NBITS_ELEMENT_MODE ), IVAS_CPE_DFT );
    1669       52040 :                 move16();
    1670             :             }
    1671             :             ELSE
    1672             :             {
    1673      177336 :                 hCPE->element_mode = IVAS_CPE_MDCT;
    1674      177336 :                 move16();
    1675             :             }
    1676             : 
    1677             :             /* read the bandwidth */
    1678      229376 :             IF( LT_32( hCPE->element_brate, MIN_BRATE_FB_STEREO ) )
    1679             :             {
    1680             :                 /* WB and SWB are supported */
    1681       32066 :                 sts[0]->bwidth = add( get_next_indice_fx( sts[0], 1 ), WB );
    1682       32066 :                 move16();
    1683       32066 :                 sts[1]->bwidth = sts[0]->bwidth;
    1684       32066 :                 move16();
    1685             :             }
    1686             :             ELSE
    1687             :             {
    1688             :                 /* WB, SWB and FB are supported */
    1689      197310 :                 sts[0]->bwidth = get_next_indice_fx( sts[0], NBITS_BWIDTH );
    1690      197310 :                 move16();
    1691      197310 :                 sts[1]->bwidth = sts[0]->bwidth;
    1692      197310 :                 move16();
    1693             :             }
    1694             :         }
    1695             :     }
    1696             : 
    1697      410720 :     return;
    1698             : }
    1699             : 
    1700             : 
    1701             : /*-------------------------------------------------------------------------
    1702             :  * stereo_mode_combined_format_dec_fx()
    1703             :  *
    1704             :  * Set stereo format in a combined format
    1705             :  *-------------------------------------------------------------------------*/
    1706             : 
    1707      410720 : static void stereo_mode_combined_format_dec_fx(
    1708             :     const Decoder_Struct *st_ivas, /* i  : decoder main structure */
    1709             :     CPE_DEC_HANDLE hCPE            /* i/o: CPE handle             */
    1710             : )
    1711             : {
    1712             :     Word32 element_brate_ref;
    1713             : 
    1714      410720 :     IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
    1715             :     {
    1716        6529 :         element_brate_ref = hCPE->element_brate;
    1717        6529 :         move32();
    1718             : 
    1719        6529 :         test();
    1720        6529 :         test();
    1721        6529 :         test();
    1722        6529 :         test();
    1723        6529 :         IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) &&
    1724             :             ( ( EQ_16( st_ivas->nchan_ism, 3 ) && EQ_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_96k ) ) ||
    1725             :               ( EQ_16( st_ivas->nchan_ism, 4 ) && EQ_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_128k ) ) ) )
    1726             :         {
    1727         428 :             IF( !st_ivas->bfi )
    1728             :             {
    1729             :                 /* read OMASA stereo mode signalling */
    1730         426 :                 IF( get_next_indice_fx( hCPE->hCoreCoder[0], NBITS_ELEMENT_MODE ) )
    1731             :                 {
    1732           0 :                     hCPE->element_mode = IVAS_CPE_MDCT;
    1733           0 :                     move16();
    1734             :                 }
    1735             :                 ELSE
    1736             :                 {
    1737         426 :                     hCPE->element_mode = IVAS_CPE_DFT;
    1738         426 :                     move16();
    1739             :                 }
    1740             :             }
    1741             : 
    1742         428 :             IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) )
    1743             :             {
    1744           0 :                 hCPE->element_brate = IVAS_64k;
    1745           0 :                 move32();
    1746           0 :                 hCPE->brate_surplus = L_sub( hCPE->brate_surplus, L_sub( hCPE->element_brate, element_brate_ref ) );
    1747           0 :                 move32();
    1748             :             }
    1749             :         }
    1750             :     }
    1751             : 
    1752      410720 :     return;
    1753             : }

Generated by: LCOV version 1.14