LCOV - code coverage report
Current view: top level - lib_dec - ivas_mc_paramupmix_dec_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 442 473 93.4 %
Date: 2025-05-03 01:55:50 Functions: 14 14 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 "prot_fx.h"
      38             : #include "ivas_prot_fx.h"
      39             : #include "ivas_prot_rend_fx.h"
      40             : #include "ivas_cnst.h"
      41             : #include "rom_com.h"
      42             : #include "ivas_rom_com.h"
      43             : #include "ivas_rom_dec.h"
      44             : #include "math.h"
      45             : #include "wmc_auto.h"
      46             : #include "rom_dec.h"
      47             : #include "ivas_rom_com_fx.h"
      48             : 
      49             : /*-----------------------------------------------------------------------*
      50             :  * Local arrays
      51             :  *-----------------------------------------------------------------------*/
      52             : 
      53             : /*  boxes = { 0 1 2 3 [4 6] [5 7] [8 10] [9 11] }; */
      54             : const Word16 MC_PARAMUPMIX_CHIDX1[MC_PARAMUPMIX_COMBINATIONS] = { 0, 1, 4, 5 };
      55             : const Word16 MC_PARAMUPMIX_CHIDX2[MC_PARAMUPMIX_COMBINATIONS] = { 2, 3, 6, 7 };
      56             : const Word16 qmf_to_par_band[] = {
      57             :     0, 1, 2, 3, 4, 5, 5, 6, 6, 7,
      58             :     7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
      59             :     9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
      60             :     10, 10, 11, 11, 11, 11, 11, 11, 11, 11,
      61             :     11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
      62             :     11, 11, 11, 11, 11, 11, 11, 11, 11, 11
      63             : };
      64             : 
      65             : /*-----------------------------------------------------------------------*
      66             :  * Local function prototypes
      67             :  *-----------------------------------------------------------------------*/
      68             : 
      69             : static void ps_pred_process_sf( MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, DECODER_TC_BUFFER_HANDLE hTcBuffer, Word32 qmf_mod_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 qmf_mod_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 qmf_side_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 qmf_side_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word16 *param_interpol_fx, const Word16 ch, const Word16 slots_rendered );
      70             : 
      71             : static void ivas_mc_paramupmix_dec_sf( Decoder_Struct *st_ivas, Word32 *output_fx[MAX_OUTPUT_CHANNELS] );
      72             : 
      73             : static void ivas_param_upmix_dec_decorr_subframes( Decoder_Struct *st_ivas, const Word16 nSamplesForRendering );
      74             : 
      75             : static Word16 huff_read( Decoder_State *st, const Word16 ( *ht )[2] );
      76             : 
      77             : static void huffman_decode( Decoder_State *st, const PAR_TYPE parType, Word32 *vq );
      78             : 
      79             : static void dequant_alpha( Word32 *vq, Word32 *v );
      80             : 
      81             : static void dequant_beta( Word32 *aq, Word32 *bq, Word32 *beta );
      82             : 
      83             : static void get_ec_data( Decoder_State *st, const PAR_TYPE parType, Word32 *parQ, Word32 *alphaQEnv, Word32 ab[IVAS_MAX_NUM_BANDS] );
      84             : 
      85             : 
      86             : /*-------------------------------------------------------------------------
      87             :  * ivas_mc_paramupmix_dec_read_BS()
      88             :  *
      89             :  * Read the ParamUpmix MC metadata
      90             :  *------------------------------------------------------------------------*/
      91             : 
      92         780 : void ivas_mc_paramupmix_dec_read_BS(
      93             :     Decoder_Struct *st_ivas,                /* i/o: IVAS decoder structure          */
      94             :     Decoder_State *st0,                     /* i/o: decoder state structure         */
      95             :     MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, /* i/o: decoder MC Param-Upmix handle   */
      96             :     Word16 *nb_bits                         /* o  : number of bits written          */
      97             : )
      98             : {
      99             :     Word16 i, k;
     100             :     Word32 alpha_quant[IVAS_MAX_NUM_BANDS];
     101             :     Word16 nb_bits_read_orig;
     102             :     Word16 next_bit_pos_orig, last_bit_pos;
     103             :     UWord16 bstr_meta[MAX_BITS_METADATA], *bit_stream_orig;
     104             : 
     105         780 :     push_wmops( "mc_paramupmix_read_bs" );
     106         780 :     *nb_bits = 0;
     107         780 :     move16();
     108             : 
     109         780 :     IF( st0->bfi )
     110             :     {
     111           0 :         FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     112             :         {
     113           0 :             FOR( k = 0; k < IVAS_MAX_NUM_BANDS; k++ )
     114             :             {
     115           0 :                 hMCParamUpmix->alphas_fx[i][k] = hMCParamUpmix->alpha_prev_fx[i][k]; // Q28
     116           0 :                 hMCParamUpmix->betas_fx[i][k] = hMCParamUpmix->beta_prev_fx[i][k];   // Q28
     117           0 :                 move32();
     118           0 :                 move32();
     119             :             }
     120             :         }
     121           0 :         hMCParamUpmix->first_frame = 1;
     122           0 :         move16();
     123             :     }
     124             :     ELSE /*  IF (!st->bfi) */
     125             :     {
     126         780 :         bit_stream_orig = st0->bit_stream;
     127         780 :         next_bit_pos_orig = st0->next_bit_pos;
     128         780 :         move16();
     129         780 :         Word32 L_temp = Mpy_32_32( st_ivas->hDecoderConfig->ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 );
     130         780 :         last_bit_pos = extract_l( L_sub( L_temp, 1 ) );
     131         780 :         nb_bits_read_orig = 0;
     132         780 :         move16();
     133         780 :         last_bit_pos = sub( last_bit_pos, nb_bits_read_orig ); /* reverse the bitstream for easier reading of indices */
     134         780 :         Word16 len = s_min( MAX_BITS_METADATA, last_bit_pos );
     135     1950780 :         FOR( i = 0; i < len; i++ )
     136             :         {
     137     1950000 :             bstr_meta[i] = st_ivas->bit_stream[last_bit_pos - i];
     138     1950000 :             move16();
     139             :         }
     140         780 :         st0->bit_stream = bstr_meta;
     141         780 :         st0->next_bit_pos = 0;
     142         780 :         move16();
     143         780 :         st0->bits_frame = s_min( MAX_BITS_METADATA, add( last_bit_pos, 1 ) );
     144         780 :         move16();
     145         780 :         st0->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* to avoid BER detect */
     146         780 :         move32();
     147             : 
     148        3900 :         FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     149             :         {
     150        3120 :             get_ec_data( st0, ALPHA, hMCParamUpmix->alpha_quant[i], alpha_quant, hMCParamUpmix->alphas_fx[i] );
     151             : 
     152        3120 :             get_ec_data( st0, BETA, hMCParamUpmix->beta_quant[i], alpha_quant, hMCParamUpmix->betas_fx[i] );
     153             :         }
     154         780 :         *nb_bits = add( *nb_bits, st0->next_bit_pos );
     155         780 :         move16();
     156         780 :         st0->bit_stream = bit_stream_orig;
     157         780 :         st0->next_bit_pos = next_bit_pos_orig;
     158         780 :         move16();
     159             : 
     160         780 :         IF( hMCParamUpmix->first_frame )
     161             :         {
     162          50 :             FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     163             :             {
     164          40 :                 Copy32( hMCParamUpmix->alphas_fx[i], hMCParamUpmix->alpha_prev_fx[i], IVAS_MAX_NUM_BANDS );
     165          40 :                 Copy32( hMCParamUpmix->betas_fx[i], hMCParamUpmix->beta_prev_fx[i], IVAS_MAX_NUM_BANDS );
     166             :             }
     167          10 :             hMCParamUpmix->first_frame = 0;
     168          10 :             move16();
     169             :         }
     170             :     }
     171             : 
     172         780 :     pop_wmops();
     173         780 :     return;
     174             : }
     175             : 
     176             : 
     177             : /*-------------------------------------------------------------------------
     178             :  * ivas_mc_paramupmix_dec_digest_tc()
     179             :  *
     180             :  *
     181             :  *------------------------------------------------------------------------*/
     182             : 
     183         770 : void ivas_mc_paramupmix_dec_digest_tc(
     184             :     Decoder_Struct *st_ivas,          /* i/o: IVAS decoder handle                            */
     185             :     const UWord8 nCldfbSlots,         /* i  : number of CLFBS slots in the transport channels*/
     186             :     const Word16 nSamplesForRendering /* i  : number of samples provided                     */
     187             : )
     188             : {
     189             :     MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
     190         770 :     hMCParamUpmix = st_ivas->hMCParamUpmix;
     191         770 :     assert( hMCParamUpmix );
     192         770 :     push_wmops( "ivas_mc_paramupmix_dec_digest_tc" );
     193             : 
     194         770 :     ivas_param_upmix_dec_decorr_subframes( st_ivas, nSamplesForRendering );
     195             : 
     196             :     /* adapt subframes */
     197         770 :     ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
     198             : 
     199         770 :     ivas_jbm_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hMCParamUpmix->param_interpolator_fx );
     200             : 
     201         770 :     pop_wmops();
     202         770 :     return;
     203             : }
     204             : 
     205             : 
     206             : /*-------------------------------------------------------------------------
     207             :  * ivas_mc_paramupmix_dec_render()
     208             :  *
     209             :  *
     210             :  *------------------------------------------------------------------------*/
     211             : 
     212         770 : void ivas_mc_paramupmix_dec_render(
     213             :     Decoder_Struct *st_ivas,     /* i/o: IVAS decoder handle                       */
     214             :     const UWord16 nSamplesAsked, /* i  : number of CLDFB slots requested           */
     215             :     UWord16 *nSamplesRendered,   /* o  : number of CLDFB slots rendered            */
     216             :     UWord16 *nSamplesAvailable,  /* o  : number of CLDFB slots still to render     */
     217             :     Word32 *input_fx[],          /* i  : core-coder transport channels             Qx*/
     218             :     Word32 *output_fx[]          /* i/o: synthesized core-coder transport channels Qx*/
     219             : )
     220             : {
     221             :     Word16 slots_to_render, first_sf, last_sf, subframe_idx;
     222             :     UWord16 slot_size, ch;
     223             :     Word32 *output_local_fx[MAX_OUTPUT_CHANNELS];
     224             :     MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
     225             : 
     226         770 :     hMCParamUpmix = st_ivas->hMCParamUpmix;
     227         770 :     assert( hMCParamUpmix );
     228             : 
     229         770 :     push_wmops( "ivas_mc_paramupmix_dec_render" );
     230             : 
     231       13090 :     FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ )
     232             :     {
     233       12320 :         output_local_fx[ch] = output_fx[ch];
     234             :     }
     235             : 
     236         770 :     slot_size = st_ivas->hTcBuffer->n_samples_granularity;
     237         770 :     move16();
     238             : 
     239             :     /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
     240         770 :     slots_to_render = s_min( sub( st_ivas->hTcBuffer->num_slots, st_ivas->hTcBuffer->slots_rendered ), idiv1616( nSamplesAsked, slot_size ) );
     241         770 :     *nSamplesRendered = imult1616( slots_to_render, (Word16) slot_size );
     242         770 :     move16();
     243         770 :     first_sf = st_ivas->hTcBuffer->subframes_rendered;
     244         770 :     move16();
     245         770 :     last_sf = first_sf;
     246         770 :     move16();
     247             : 
     248       10010 :     FOR( ch = 0; ch < MAX_TRANSPORT_CHANNELS; ch++ )
     249             :     {
     250        9240 :         Copy32( input_fx[ch], output_local_fx[ch], *nSamplesRendered );
     251             :     }
     252             : 
     253        3850 :     WHILE( slots_to_render > 0 )
     254             :     {
     255        3080 :         slots_to_render = sub( slots_to_render, st_ivas->hTcBuffer->subframe_nbslots[last_sf] );
     256        3080 :         last_sf = add( last_sf, 1 );
     257             :     }
     258             :     {
     259             : 
     260        3850 :         FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
     261             :         {
     262        3080 :             Copy32( hMCParamUpmix->alpha_prev_fx[ch], hMCParamUpmix->alpha_sf_fx[ch], IVAS_MAX_NUM_BANDS );
     263        3080 :             Copy32( hMCParamUpmix->beta_prev_fx[ch], hMCParamUpmix->beta_sf_fx[ch], IVAS_MAX_NUM_BANDS );
     264             :         }
     265             : 
     266        3850 :         FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
     267             :         {
     268        3080 :             Word16 n_samples_sf = imult1616( (Word16) slot_size, st_ivas->hTcBuffer->subframe_nbslots[subframe_idx] );
     269             : 
     270        3080 :             ivas_mc_paramupmix_dec_sf( st_ivas, output_local_fx );
     271             : 
     272        3080 :             Word16 num_ch = s_min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ) );
     273       47400 :             FOR( ch = 0; ch < num_ch; ch++ )
     274             :             {
     275       44320 :                 output_local_fx[ch] += n_samples_sf;
     276             :             }
     277             : 
     278             :             /* update combined orientation access index */
     279        3080 :             ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf );
     280             :         }
     281        3850 :         FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
     282             :         {
     283        3080 :             Copy32( hMCParamUpmix->alphas_fx[ch], hMCParamUpmix->alpha_prev_fx[ch], IVAS_MAX_NUM_BANDS );
     284        3080 :             Copy32( hMCParamUpmix->betas_fx[ch], hMCParamUpmix->beta_prev_fx[ch], IVAS_MAX_NUM_BANDS );
     285             :         }
     286             :     }
     287             : 
     288         770 :     *nSamplesAvailable = imult1616( sub( st_ivas->hTcBuffer->num_slots, st_ivas->hTcBuffer->slots_rendered ), (Word16) slot_size );
     289         770 :     move16();
     290             : 
     291         770 :     pop_wmops();
     292         770 :     return;
     293             : }
     294             : 
     295             : 
     296             : /*-------------------------------------------------------------------------
     297             :  * ivas_mc_paramupmix_dec_open()
     298             :  *
     299             :  * Open Parametric MC decoder handle
     300             :  *-------------------------------------------------------------------------*/
     301             : 
     302          10 : ivas_error ivas_mc_paramupmix_dec_open(
     303             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure  */
     304             : )
     305             : {
     306             :     MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
     307             :     Word32 output_Fs;
     308             :     Word16 nchan_transport;
     309             :     UWord16 i;
     310             :     ivas_error error;
     311             : 
     312          10 :     error = IVAS_ERR_OK;
     313          10 :     move32();
     314             : 
     315             :     /*-----------------------------------------------------------------*
     316             :      * prepare library opening
     317             :      *-----------------------------------------------------------------*/
     318             : 
     319          10 :     IF( ( hMCParamUpmix = (MC_PARAMUPMIX_DEC_HANDLE) malloc( sizeof( MC_PARAMUPMIX_DEC_DATA ) ) ) == NULL )
     320             :     {
     321           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param-Upmix MC\n" ) );
     322             :     }
     323          10 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
     324          10 :     move32();
     325          10 :     hMCParamUpmix->first_frame = 1;
     326          10 :     move16();
     327          10 :     st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS;
     328          10 :     move16();
     329          10 :     nchan_transport = st_ivas->nchan_transport;
     330          10 :     move16();
     331             : 
     332          10 :     SWITCH( nchan_transport )
     333             :     {
     334          10 :         case 8:
     335          10 :             st_ivas->nCPE = 4;
     336          10 :             move16();
     337          10 :             st_ivas->nSCE = 0;
     338          10 :             move16();
     339          10 :             st_ivas->element_mode_init = IVAS_CPE_MDCT;
     340          10 :             move16();
     341          10 :             BREAK;
     342             :     }
     343             : 
     344          10 :     hMCParamUpmix->hoa_encoder_fx = NULL;
     345             : 
     346             :     /*-----------------------------------------------------------------*
     347             :      * set input parameters
     348             :      *-----------------------------------------------------------------*/
     349             : 
     350          10 :     hMCParamUpmix->num_freq_bands = (Word16) Mpy_32_32_r( output_Fs, INV_CLDFB_BANDWIDTH_Q31 );
     351          10 :     move16();
     352             : 
     353          50 :     FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     354             :     {
     355          40 :         ivas_td_decorr_dec_open_fx( &( hMCParamUpmix->hTdDecorr[i] ), output_Fs, 2, 1 );
     356             :     }
     357             : 
     358          90 :     FOR( i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++ )
     359             :     {
     360          80 :         IF( ( hMCParamUpmix->pcm_delay_fx[i] = (Word32 *) malloc( NS2SA_FX2( output_Fs, IVAS_FB_DEC_DELAY_NS ) * sizeof( Word32 ) ) ) == NULL )
     361             :         {
     362           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for delay buffer\n" ) );
     363             :         }
     364          80 :         set32_fx( hMCParamUpmix->pcm_delay_fx[i], 0, NS2SA_FX2( output_Fs, IVAS_FB_DEC_DELAY_NS ) );
     365             :     }
     366             : 
     367             :     /* Head or external rotation */
     368          10 :     IF( ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) )
     369             :     {
     370             : 
     371           3 :         IF( ( hMCParamUpmix->hoa_encoder_fx = (Word32 *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( Word32 ) ) ) == NULL )
     372             :         {
     373           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
     374             :         }
     375           3 :         compute_hoa_encoder_mtx_fx( st_ivas->hTransSetup.ls_azimuth_fx, st_ivas->hTransSetup.ls_elevation_fx, hMCParamUpmix->hoa_encoder_fx, st_ivas->hTransSetup.nchan_out_woLFE, HEAD_ROTATION_HOA_ORDER );
     376             :     }
     377             : 
     378             :     /* allocate transport channels*/
     379          10 :     hMCParamUpmix->free_param_interpolator = 0;
     380          10 :     move16();
     381             : 
     382          10 :     IF( ( hMCParamUpmix->param_interpolator_fx = (Word16 *) malloc( MAX_JBM_CLDFB_TIMESLOTS * sizeof( Word16 ) ) ) == NULL )
     383             :     {
     384           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for interpolator\n" ) );
     385             :     }
     386          10 :     hMCParamUpmix->free_param_interpolator = 1;
     387          10 :     move16();
     388             : 
     389          10 :     ivas_jbm_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, DEFAULT_JBM_CLDFB_TIMESLOTS, hMCParamUpmix->param_interpolator_fx );
     390             : 
     391          10 :     IF( st_ivas->hTcBuffer == NULL )
     392             :     {
     393             :         Word16 nchan_to_allocate;
     394             :         Word16 nchan_tc;
     395             :         TC_BUFFER_MODE buffer_mode;
     396             : 
     397           5 :         buffer_mode = TC_BUFFER_MODE_RENDERER;
     398           5 :         nchan_tc = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas );
     399           5 :         nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS;
     400           5 :         move16();
     401           5 :         move16();
     402             : 
     403           5 :         test();
     404           5 :         test();
     405           5 :         test();
     406           5 :         IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) )
     407             :         {
     408           0 :             buffer_mode = TC_BUFFER_MODE_BUFFER;
     409           0 :             move32();
     410           0 :             nchan_tc = st_ivas->hDecoderConfig->nchan_out;
     411           0 :             move16();
     412           0 :             nchan_to_allocate = nchan_tc;
     413           0 :             move16();
     414             :         }
     415           5 :         ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
     416             :         {
     417           4 :             nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS;
     418           4 :             move16();
     419             :         }
     420             : 
     421           5 :         IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ), IVAS_ERR_OK ) )
     422             :         {
     423           0 :             return error;
     424             :         }
     425             :     }
     426          10 :     st_ivas->hMCParamUpmix = hMCParamUpmix;
     427             : 
     428          10 :     return error;
     429             : }
     430             : 
     431             : 
     432             : /*-------------------------------------------------------------------------
     433             :  * ivas_mc_paramupmix_dec_close()
     434             :  *
     435             :  * Close ParamUpmix MC memories
     436             :  *------------------------------------------------------------------------*/
     437             : 
     438         814 : void ivas_mc_paramupmix_dec_close(
     439             :     MC_PARAMUPMIX_DEC_HANDLE *hMCParamUpmix /* i/o: Parametric MC decoder handle   */
     440             : )
     441             : {
     442             :     Word16 i;
     443             : 
     444         814 :     IF( hMCParamUpmix == NULL || *hMCParamUpmix == NULL )
     445             :     {
     446         804 :         return;
     447             :     }
     448          50 :     FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     449             :     {
     450          40 :         ivas_td_decorr_dec_close( &( ( *hMCParamUpmix )->hTdDecorr[i] ) );
     451             :     }
     452          90 :     FOR( i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++ )
     453             :     {
     454          80 :         IF( ( *hMCParamUpmix )->pcm_delay_fx[i] != NULL )
     455             :         {
     456          80 :             free( ( *hMCParamUpmix )->pcm_delay_fx[i] );
     457             :         }
     458             :     }
     459          10 :     IF( ( *hMCParamUpmix )->param_interpolator_fx != NULL )
     460             :     {
     461          10 :         IF( EQ_16( ( *hMCParamUpmix )->free_param_interpolator, 1 ) )
     462             :         {
     463          10 :             free( ( *hMCParamUpmix )->param_interpolator_fx );
     464             :         }
     465             :     }
     466          10 :     IF( ( *hMCParamUpmix )->hoa_encoder_fx != NULL )
     467             :     {
     468           3 :         free( ( *hMCParamUpmix )->hoa_encoder_fx );
     469           3 :         ( *hMCParamUpmix )->hoa_encoder_fx = NULL;
     470             :     }
     471          10 :     free( *hMCParamUpmix );
     472             : 
     473          10 :     *hMCParamUpmix = NULL;
     474             : 
     475          10 :     return;
     476             : }
     477             : 
     478             : 
     479             : /*-------------------------------------------------------------------------
     480             :  * paramupmix_td_decorr_process_jbm_fx()
     481             :  *
     482             :  *
     483             :  *------------------------------------------------------------------------*/
     484             : 
     485         770 : static void paramupmix_td_decorr_process_jbm_fx(
     486             :     ivas_td_decorr_state_t *hTdDecorr[], /* i/o: SPAR Covar. decoder handle   */
     487             :     Word32 *pcm_in[],                    /* i  : input audio channels         */
     488             :     Word32 **pp_out_pcm,                 /* o  : output audio channels        */
     489             :     const Word16 output_frame,           /* i  : output frame length          */
     490             :     Word16 *q_format )
     491             : {
     492             :     Word16 j, k;
     493             :     Word16 offset;
     494             :     Word32 in_duck_gain[L_FRAME48k], out_duck_gain[L_FRAME48k]; // Q30
     495             : 
     496         770 :     offset = idiv1616( output_frame, 10 );
     497             : 
     498             :     /* Look-ahead delay */
     499        3850 :     FOR( k = 0; k < MC_PARAMUPMIX_COMBINATIONS; k++ )
     500             :     {
     501        3080 :         Copy32( pcm_in[k], pp_out_pcm[k], output_frame );
     502        3080 :         delay_signal32_fx( pp_out_pcm[k], output_frame, hTdDecorr[k]->look_ahead_buf, offset );
     503             : 
     504             :         /* In ducking gains */
     505        3080 :         IF( hTdDecorr[k]->ducking_flag )
     506             :         {
     507        3080 :             ivas_td_decorr_get_ducking_gains_fx( hTdDecorr[k]->pTrans_det, pcm_in[k], in_duck_gain, out_duck_gain, output_frame, 0 );
     508             : 
     509     2575880 :             FOR( j = 0; j < output_frame; j++ )
     510             :             {
     511     2572800 :                 pp_out_pcm[k][j] = Mpy_32_32( pp_out_pcm[k][j], in_duck_gain[j] );
     512     2572800 :                 move16();
     513             :             }
     514        3080 :             q_format[k] = sub( q_format[k], Q1 ); // q_format--
     515        3080 :             move16();
     516             :         }
     517             : 
     518             :         /* All pass delay section */
     519        3080 :         ivas_td_decorr_APD_iir_filter_fx( &hTdDecorr[k]->APD_filt_state[0], pp_out_pcm[k], hTdDecorr[k]->num_apd_sections, output_frame );
     520             : 
     521             :         /* Out ducking gains */
     522        3080 :         IF( hTdDecorr[k]->ducking_flag )
     523             :         {
     524     2575880 :             FOR( j = 0; j < output_frame; j++ )
     525             :             {
     526     2572800 :                 pp_out_pcm[k][j] = Mpy_32_32( pp_out_pcm[k][j], out_duck_gain[j] );
     527     2572800 :                 move32();
     528             :             }
     529        3080 :             q_format[k] = sub( q_format[k], Q1 ); // q_format--
     530        3080 :             move16();
     531             :         }
     532             :     }
     533             : 
     534         770 :     return;
     535             : }
     536             : 
     537             : 
     538             : /*-------------------------------------------------------------------------
     539             :  * ivas_param_upmix_dec_decorr_subframes()
     540             :  *
     541             :  *
     542             :  *------------------------------------------------------------------------*/
     543             : 
     544         770 : static void ivas_param_upmix_dec_decorr_subframes(
     545             :     Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle    */
     546             :     const Word16 nSamplesForRendering )
     547             : {
     548             :     MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
     549             :     Word32 *pPcm_tmp_fx[MC_PARAMUPMIX_COMBINATIONS];
     550             :     Word32 *p_tc_fx[MC_PARAMUPMIX_COMBINATIONS];
     551             :     Word16 nchan_internal, ch;
     552             :     Word16 nSamplesLeftForTD, default_frame;
     553             : 
     554         770 :     hMCParamUpmix = st_ivas->hMCParamUpmix;
     555         770 :     assert( hMCParamUpmix );
     556             : 
     557         770 :     push_wmops( "ivas_param_upmix_dec_decorr_subframes" );
     558             : 
     559             :     /* TD decorrelator */
     560         770 :     default_frame = extract_l( Mpy_32_32( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) );
     561         770 :     nSamplesLeftForTD = nSamplesForRendering;
     562         770 :     move16();
     563         770 :     nchan_internal = MC_PARAMUPMIX_COMBINATIONS;
     564         770 :     move16();
     565             : 
     566        3850 :     FOR( ch = 0; ch < nchan_internal; ch++ )
     567             :     {
     568        3080 :         pPcm_tmp_fx[ch] = st_ivas->hTcBuffer->tc_fx[ch + 8]; // Q11
     569        3080 :         p_tc_fx[ch] = st_ivas->hTcBuffer->tc_fx[ch + 4];     // Q11
     570             :     }
     571             : 
     572        1540 :     WHILE( nSamplesLeftForTD )
     573             :     {
     574         770 :         Word16 nSamplesToDecorr = s_min( nSamplesLeftForTD, default_frame );
     575             : 
     576             :         {
     577             :             Word16 i, q_format[MC_PARAMUPMIX_COMBINATIONS];
     578             : 
     579        3850 :             FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     580             :             {
     581        3080 :                 q_format[i] = Q11;
     582        3080 :                 move16();
     583             :             }
     584             : 
     585         770 :             paramupmix_td_decorr_process_jbm_fx( hMCParamUpmix->hTdDecorr, p_tc_fx, pPcm_tmp_fx, nSamplesToDecorr, q_format );
     586             : 
     587        3850 :             FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     588             :             {
     589        3080 :                 Scale_sig32( pPcm_tmp_fx[i], nSamplesToDecorr, sub( Q11, q_format[i] ) ); // Setting Q to changed q in q_format
     590             :             }
     591             :         }
     592        3850 :         FOR( ch = 0; ch < nchan_internal; ch++ )
     593             :         {
     594        3080 :             p_tc_fx[ch] += nSamplesToDecorr;
     595             :         }
     596             : 
     597         770 :         nSamplesLeftForTD = sub( nSamplesLeftForTD, nSamplesToDecorr );
     598             :     }
     599             : 
     600         770 :     pop_wmops();
     601         770 :     return;
     602             : }
     603             : 
     604             : 
     605             : /*****************************************************************************************/
     606             : /* local functions                                                                       */
     607             : /*****************************************************************************************/
     608             : 
     609       12320 : static void ps_pred_process_sf(
     610             :     MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix,
     611             :     DECODER_TC_BUFFER_HANDLE hTcBuffer,
     612             :     Word32 qmf_mod_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
     613             :     /* in/out */                                                              // Q6
     614             :     Word32 qmf_mod_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], // Q6
     615             :     Word32 qmf_side_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
     616             :     /* in/out */                                                               // Q6
     617             :     Word32 qmf_side_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], // Q6
     618             :     Word16 *param_interpol_fx,                                                 // Q15
     619             :     const Word16 ch,
     620             :     const Word16 slots_rendered )
     621             : {
     622             :     Word32 vmre_fx, vmim_fx, vsre_fx, vsim_fx;
     623             :     Word16 iqmf, ipar, ismp, iismp;
     624             :     Word32 alpha_smp_fx, beta_smp_fx;
     625             :     Word32 *alpha1_fx, *alpha2_fx;
     626             :     Word32 *beta1_fx, *beta2_fx;
     627       12320 :     Word32 *alpha_prev_fx = hMCParamUpmix->alpha_prev_fx[ch]; // Q28
     628       12320 :     Word32 *beta_prev_fx = hMCParamUpmix->beta_prev_fx[ch];   // Q28
     629       12320 :     Word32 *alpha_sf_fx = hMCParamUpmix->alpha_sf_fx[ch];     // Q28
     630       12320 :     Word32 *beta_sf_fx = hMCParamUpmix->beta_sf_fx[ch];       // Q28
     631             :     Word32 dalpha_fx, dbeta_fx;
     632             :     Word16 ifac_fx;
     633             :     Word32 alpha_start_fx[IVAS_MAX_NUM_BANDS], beta_start_fx[IVAS_MAX_NUM_BANDS];
     634             :     Word32 res_a, res_b;
     635             : 
     636             : 
     637       12320 :     Copy32( alpha_sf_fx, alpha_start_fx, IVAS_MAX_NUM_BANDS ); // Q28
     638       12320 :     Copy32( beta_sf_fx, beta_start_fx, IVAS_MAX_NUM_BANDS );   // Q28
     639      751520 :     FOR( iqmf = 0; iqmf < CLDFB_NO_CHANNELS_MAX; iqmf++ )
     640             :     {
     641      739200 :         ipar = qmf_to_par_band[iqmf];
     642      739200 :         move16();
     643      739200 :         alpha1_fx = alpha_prev_fx; // Q28
     644      739200 :         move16();
     645      739200 :         beta1_fx = beta_prev_fx; // Q28
     646      739200 :         move16();
     647             : 
     648      739200 :         ismp = 0;
     649      739200 :         move16();
     650      739200 :         alpha2_fx = hMCParamUpmix->alphas_fx[ch];
     651      739200 :         beta2_fx = hMCParamUpmix->betas_fx[ch];
     652      739200 :         alpha_smp_fx = alpha_start_fx[ipar]; // Q28
     653      739200 :         move32();
     654      739200 :         beta_smp_fx = beta_start_fx[ipar]; // Q28
     655      739200 :         move32();
     656             : 
     657     3696000 :         FOR( iismp = 0; iismp < hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered]; iismp++ )
     658             :         {
     659     2956800 :             IF( ( slots_rendered == 0 ) && ( iismp == 0 ) )
     660             :             {
     661      184800 :                 ifac_fx = param_interpol_fx[iismp]; // Q15
     662      184800 :                 move16();
     663             :             }
     664             :             ELSE
     665             :             {
     666     2772000 :                 ifac_fx = sub( param_interpol_fx[iismp], param_interpol_fx[iismp - 1] ); // Q15
     667             :             }
     668     2956800 :             dalpha_fx = Mpy_32_16_1( L_sub( alpha2_fx[ipar], alpha1_fx[ipar] ), ifac_fx ); // Q28
     669     2956800 :             dbeta_fx = Mpy_32_16_1( L_sub( beta2_fx[ipar], beta1_fx[ipar] ), ifac_fx );
     670             : 
     671     2956800 :             alpha_smp_fx = L_add( alpha_smp_fx, dalpha_fx );
     672     2956800 :             beta_smp_fx = L_add( dbeta_fx, beta_smp_fx );
     673             : 
     674     2956800 :             vmre_fx = qmf_mod_re_fx[ismp][iqmf]; // Q6
     675     2956800 :             move32();
     676     2956800 :             vmim_fx = qmf_mod_im_fx[ismp][iqmf]; // Q6
     677     2956800 :             move32();
     678     2956800 :             vsre_fx = qmf_side_re_fx[ismp][iqmf]; // Q6
     679     2956800 :             move32();
     680     2956800 :             vsim_fx = qmf_side_im_fx[ismp][iqmf]; // Q6
     681     2956800 :             move32();
     682             : 
     683     2956800 :             res_a = L_shl( Mpy_32_32( alpha_smp_fx, vmre_fx ), Q31 - Q28 ); // Q6
     684     2956800 :             res_b = L_shl( Mpy_32_32( beta_smp_fx, vsre_fx ), Q31 - Q28 );  // Q6
     685     2956800 :             qmf_side_re_fx[ismp][iqmf] = L_add( res_a, res_b );             // Q6
     686     2956800 :             move32();
     687             : 
     688     2956800 :             res_a = L_shl( Mpy_32_32( alpha_smp_fx, vmim_fx ), Q31 - Q28 ); // Q6
     689     2956800 :             res_b = L_shl( Mpy_32_32( beta_smp_fx, vsim_fx ), Q31 - Q28 );  // Q6
     690     2956800 :             qmf_side_im_fx[ismp][iqmf] = L_add( res_a, res_b );
     691     2956800 :             move32();
     692             : 
     693     2956800 :             ismp = add( ismp, 1 );
     694             :         }
     695      739200 :         alpha_sf_fx[ipar] = alpha_smp_fx;
     696      739200 :         move32();
     697      739200 :         beta_sf_fx[ipar] = beta_smp_fx;
     698      739200 :         move32();
     699             :     }
     700             : 
     701       12320 :     return;
     702             : }
     703             : 
     704             : 
     705        3080 : static void ivas_mc_paramupmix_dec_sf(
     706             :     Decoder_Struct *st_ivas,               /* i/o: IVAS decoder handle                        */
     707             :     Word32 *output_fx[MAX_OUTPUT_CHANNELS] /* i/o: synthesized core-coder transport channels  Q11*/
     708             : )
     709             : {
     710             :     Word16 i, ch, slot_idx, k;
     711             :     Word32 *pPcm_temp_fx[MC_PARAMUPMIX_COMBINATIONS * 2]; /* decorrelated and undecorrelated*/
     712             :     /*CLDFB*/
     713        3080 :     Word32 Cldfb_RealBuffer_fx[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX] = { 0 }; // Q6
     714        3080 :     Word32 Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX] = { 0 }; // Q6
     715             : 
     716             :     Word16 noparamupmix_delay, n_samples_rendered;
     717             :     MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
     718             :     Word16 subframeIdx, idx_in, maxBand;
     719        3080 :     Word32 Cldfb_RealBuffer_subfr_fx[MAX_INTERN_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX] = { 0 };
     720        3080 :     Word32 Cldfb_ImagBuffer_subfr_fx[MAX_INTERN_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX] = { 0 };
     721             :     Word32 Cldfb_RealBuffer_Binaural_fx[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
     722             :     Word32 Cldfb_ImagBuffer_Binaural_fx[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
     723             : 
     724        3080 :     hMCParamUpmix = st_ivas->hMCParamUpmix;
     725        3080 :     assert( hMCParamUpmix );
     726        3080 :     push_wmops( "ivas_mc_paramupmix_dec_sf" );
     727             : 
     728       15400 :     FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     729             :     {
     730       12320 :         pPcm_temp_fx[2 * i] = output_fx[i + 4];     /* un-decorrelated Q11*/
     731       12320 :         pPcm_temp_fx[2 * i + 1] = output_fx[i + 8]; /* decorrelated Q11*/
     732             :     }
     733             : 
     734             :     /* CLDFB Analysis*/
     735       27720 :     FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ )
     736             :     {
     737             :         /* slot loop for gathering the input data */
     738      123200 :         FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     739             :         {
     740       98560 :             Word16 q_cldfb = 11;
     741       98560 :             move16();
     742       98560 :             cldfbAnalysis_ts_fx_fixed_q( &( pPcm_temp_fx[ch][hMCParamUpmix->num_freq_bands * slot_idx] ), Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][slot_idx], hMCParamUpmix->num_freq_bands, st_ivas->cldfbAnaDec[ch], &q_cldfb );
     743             :         }
     744             :     }
     745             : 
     746       15400 :     FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
     747             :     {
     748       12320 :         ps_pred_process_sf( hMCParamUpmix,
     749             :                             st_ivas->hTcBuffer,
     750       12320 :                             Cldfb_RealBuffer_fx[2 * ch], /* in/out */
     751       12320 :                             Cldfb_ImagBuffer_fx[2 * ch],
     752       12320 :                             Cldfb_RealBuffer_fx[2 * ch + 1], /* in/out decorr */
     753       12320 :                             Cldfb_ImagBuffer_fx[2 * ch + 1],
     754       12320 :                             &hMCParamUpmix->param_interpolator_fx[st_ivas->hTcBuffer->slots_rendered],
     755             :                             ch,
     756       12320 :                             st_ivas->hTcBuffer->slots_rendered );
     757             : 
     758             :         /*-- m, s -> l, r ----------------------------*/
     759       61600 :         FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     760             :         {
     761     3006080 :             FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ )
     762             :             {
     763     2956800 :                 Word32 qlre_fx = Cldfb_RealBuffer_fx[2 * ch][slot_idx][k];     // Q6
     764     2956800 :                 Word32 qlim_fx = Cldfb_ImagBuffer_fx[2 * ch][slot_idx][k];     // Q6
     765     2956800 :                 Word32 qrre_fx = Cldfb_RealBuffer_fx[2 * ch + 1][slot_idx][k]; // Q6
     766     2956800 :                 Word32 qrim_fx = Cldfb_ImagBuffer_fx[2 * ch + 1][slot_idx][k]; // Q6
     767     2956800 :                 move32();
     768     2956800 :                 move32();
     769     2956800 :                 move32();
     770     2956800 :                 move32();
     771             : 
     772     2956800 :                 Cldfb_RealBuffer_fx[2 * ch][slot_idx][k] = L_add( qlre_fx, qrre_fx );
     773     2956800 :                 Cldfb_ImagBuffer_fx[2 * ch][slot_idx][k] = L_add( qlim_fx, qrim_fx );
     774     2956800 :                 Cldfb_RealBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub( qlre_fx, qrre_fx );
     775     2956800 :                 Cldfb_ImagBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub( qlim_fx, qrim_fx );
     776     2956800 :                 move32();
     777     2956800 :                 move32();
     778     2956800 :                 move32();
     779     2956800 :                 move32();
     780             :             }
     781             :         }
     782             :     }
     783             : 
     784        3080 :     test();
     785        3080 :     IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
     786        2440 :     {
     787             :         Word16 temp_e;
     788        2440 :         maxBand = BASOP_Util_Divide3232_Scale( (Word32) W_mult0_32_32( CLDFB_NO_CHANNELS_MAX, st_ivas->hDecoderConfig->output_Fs ), 48000, &temp_e );
     789        2440 :         maxBand = shr( maxBand, sub( 15, temp_e ) );
     790        2440 :         subframeIdx = st_ivas->hTcBuffer->subframes_rendered;
     791        2440 :         move16();
     792             :         /* fastconv binaural rendering and CLDFB synthesis */
     793             :         /* cldfb analysis of non-coupled, non-LFE channels */
     794        2440 :         idx_in = 0;
     795        2440 :         move16();
     796       12200 :         FOR( ch = 0; ch < MC_PARAMUPMIX_MAX_INPUT_CHANS - 2 * MC_PARAMUPMIX_COMBINATIONS; ch++ )
     797             :         {
     798        9760 :             IF( st_ivas->hIntSetup.index_lfe[0] != ch )
     799             :             {
     800        9120 :                 pPcm_temp_fx[ch] = output_fx[ch];
     801             :                 /* slot loop for gathering the input data */
     802       45600 :                 FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     803             :                 {
     804       36480 :                     Word16 q_cldfb = 11;
     805       36480 :                     move16();
     806             : 
     807       36480 :                     cldfbAnalysis_ts_fx_fixed_q( &( pPcm_temp_fx[ch][L_mult0( hMCParamUpmix->num_freq_bands, slot_idx )] ),
     808       36480 :                                                  Cldfb_RealBuffer_subfr_fx[idx_in][slot_idx],
     809       36480 :                                                  Cldfb_ImagBuffer_subfr_fx[idx_in][slot_idx],
     810       36480 :                                                  maxBand, st_ivas->cldfbAnaDec[2 * MC_PARAMUPMIX_COMBINATIONS + idx_in], &q_cldfb );
     811             :                 }
     812        9120 :                 idx_in = add( idx_in, 1 );
     813             :             }
     814             :         }
     815             : 
     816             : 
     817             :         /* copy and reorder cldfb analysis of coupled channels */
     818       12200 :         FOR( ch = 0; ch < MAX_PARAM_SPATIAL_SUBFRAMES; ch++ )
     819             :         {
     820       48800 :             FOR( slot_idx = 0; slot_idx < MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ )
     821             :             {
     822       39040 :                 Copy32( Cldfb_RealBuffer_fx[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_RealBuffer_subfr_fx[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX );     // Q6
     823       39040 :                 Copy32( Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX );     // Q6
     824       39040 :                 Copy32( Cldfb_RealBuffer_fx[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_RealBuffer_subfr_fx[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX ); // Q6
     825       39040 :                 Copy32( Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX ); // Q6
     826             :             }
     827        9760 :             idx_in = add( idx_in, 2 );
     828             :         }
     829             : 
     830        2440 :         IF( st_ivas->hCombinedOrientationData && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
     831             :         {
     832        9000 :             FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     833             :             {
     834        7200 :                 ivas_param_mc_mc2sba_cldfb_fx( st_ivas->hTransSetup, hMCParamUpmix->hoa_encoder_fx, slot_idx, Cldfb_RealBuffer_subfr_fx, Cldfb_ImagBuffer_subfr_fx, maxBand, GAIN_LFE_FX );
     835             :             }
     836             :         }
     837             : 
     838             :         /* Implement binaural rendering */
     839             : 
     840        2440 :         Word16 input_q = 6;
     841        2440 :         move16();
     842             :         /* Implement binaural rendering */
     843        2440 :         ivas_binRenderer_fx( st_ivas->hBinRenderer,
     844             :                              st_ivas->hCombinedOrientationData,
     845        2440 :                              st_ivas->hTcBuffer->subframe_nbslots[subframeIdx],
     846             :                              Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx,
     847             :                              Cldfb_RealBuffer_subfr_fx,
     848             :                              Cldfb_ImagBuffer_subfr_fx, &input_q );
     849             : 
     850        7320 :         FOR( Word16 idx1 = 0; idx1 < BINAURAL_CHANNELS; idx1++ )
     851             :         {
     852       24400 :             FOR( Word16 idx2 = 0; idx2 < MAX_PARAM_SPATIAL_SUBFRAMES; idx2++ )
     853             :             {
     854       19520 :                 Scale_sig32( Cldfb_RealBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( 6, input_q ) ); // Q6
     855       19520 :                 Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( 6, input_q ) ); // Q6
     856             :             }
     857             :         }
     858             :         /* Implement CLDFB synthesis */
     859        7320 :         FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
     860             :         {
     861             :             Word32 *RealBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
     862             :             Word32 *ImagBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
     863             : 
     864       24400 :             FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[subframeIdx]; slot_idx++ )
     865             :             {
     866       19520 :                 RealBuffer_fx[slot_idx] = Cldfb_RealBuffer_Binaural_fx[ch][slot_idx]; // Q6
     867       19520 :                 ImagBuffer_fx[slot_idx] = Cldfb_ImagBuffer_Binaural_fx[ch][slot_idx]; // Q6
     868             :             }
     869             : #ifndef OPT_AVOID_STATE_BUF_RESCALE
     870             :             scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q5 - Q11 ); // Q11 -> Q5
     871             :             st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5;
     872             :             move16();
     873             :             cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_fx[ch][0] ), imult1616( maxBand, st_ivas->hTcBuffer->subframe_nbslots[subframeIdx] ), 0, st_ivas->cldfbSynDec[ch] ); // output_fx returned in Q5
     874             : #else                                                                                                                                                                                            /* OPT_AVOID_STATE_BUF_RESCALE */
     875        4880 :             cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_fx[ch][0] ), imult1616( maxBand, st_ivas->hTcBuffer->subframe_nbslots[subframeIdx] ), 6, 0, st_ivas->cldfbSynDec[ch] ); // output_fx returned in Q11
     876             : #endif                                                                                                                                                                                           /* OPT_AVOID_STATE_BUF_RESCALE */
     877             : 
     878             : #ifndef OPT_AVOID_STATE_BUF_RESCALE
     879             :             scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q11 - Q5 ); // Q5 -> Q11
     880             :             st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11;
     881             :             move16();
     882             : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
     883             :         }
     884             : 
     885             : #ifndef OPT_AVOID_STATE_BUF_RESCALE
     886             :         FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
     887             :         {
     888             :             Scale_sig32( output_fx[ch], imult1616( maxBand, st_ivas->hTcBuffer->subframe_nbslots[subframeIdx] ), 6 ); // Q5 -> Q11
     889             :         }
     890             : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
     891             :     }
     892             :     ELSE
     893             :     {
     894             :         /*  boxes = { 0 1 2 3 [4 6] [5 7] [8 10] [9 11] }; */
     895         640 :         pPcm_temp_fx[0] = output_fx[4];
     896         640 :         pPcm_temp_fx[1] = output_fx[6];
     897         640 :         pPcm_temp_fx[2] = output_fx[5];
     898         640 :         pPcm_temp_fx[3] = output_fx[7];
     899         640 :         pPcm_temp_fx[4] = output_fx[8];
     900         640 :         pPcm_temp_fx[5] = output_fx[10];
     901         640 :         pPcm_temp_fx[6] = output_fx[9];
     902         640 :         pPcm_temp_fx[7] = output_fx[11];
     903             : 
     904             :         /* CLDFB synthesis */
     905        5760 :         FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ )
     906             :         {
     907        5120 :             scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q5, st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); // Q11 -> Q5
     908        5120 :             st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5;
     909        5120 :             move16();
     910       25600 :             FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     911             :             {
     912             :                 Word32 *ptr_im_fx[1], *ptr_re_fx[1];
     913             : 
     914       20480 :                 ptr_re_fx[0] = Cldfb_RealBuffer_fx[ch][slot_idx]; // Q6
     915       20480 :                 ptr_im_fx[0] = Cldfb_ImagBuffer_fx[ch][slot_idx]; // Q6
     916             : #ifdef OPT_AVOID_STATE_BUF_RESCALE
     917       20480 :                 cldfbSynthesis_ivas_fx( ptr_re_fx, ptr_im_fx, &( pPcm_temp_fx[ch][L_mult0( hMCParamUpmix->num_freq_bands, slot_idx )] ),
     918       20480 :                                         hMCParamUpmix->num_freq_bands, 0, 0, st_ivas->cldfbSynDec[ch] );
     919             : #else  /* OPT_AVOID_STATE_BUF_RESCALE */
     920             :                 cldfbSynthesis_ivas_fx( ptr_re_fx, ptr_im_fx, &( pPcm_temp_fx[ch][L_mult0( hMCParamUpmix->num_freq_bands, slot_idx )] ),
     921             :                                         hMCParamUpmix->num_freq_bands, 0, st_ivas->cldfbSynDec[ch] );
     922             : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
     923             :             }
     924        5120 :             scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); // Q6 -> Q11
     925        5120 :             st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11;
     926        5120 :             move16();
     927             :         }
     928             :         // Done to keep entire buffer in q11
     929        5760 :         FOR( ch = 4; ch < 12; ch++ )
     930             :         {
     931        5120 :             Scale_sig32( output_fx[ch], imult1616( hMCParamUpmix->num_freq_bands, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered] ), 6 ); // Q11
     932             :         }
     933             :         /* adjust delay of other channels */
     934         640 :         noparamupmix_delay = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_FB_DEC_DELAY_NS );
     935         640 :         n_samples_rendered = imult1616( st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered], hMCParamUpmix->num_freq_bands );
     936         640 :         IF( n_samples_rendered > noparamupmix_delay )
     937             :         {
     938           0 :             FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
     939             :             {
     940             :                 Word32 tmp_buf_fx[L_SUBFRAME5MS_48k];
     941           0 :                 Copy32( &output_fx[ch][n_samples_rendered - noparamupmix_delay], tmp_buf_fx, noparamupmix_delay );
     942           0 :                 Copy32( output_fx[ch], &output_fx[ch][noparamupmix_delay], sub( n_samples_rendered, noparamupmix_delay ) );
     943           0 :                 Copy32( hMCParamUpmix->pcm_delay_fx[ch], output_fx[ch], noparamupmix_delay );
     944           0 :                 Copy32( tmp_buf_fx, hMCParamUpmix->pcm_delay_fx[ch], noparamupmix_delay );
     945             :             }
     946             :         }
     947             :         ELSE
     948             :         {
     949        3200 :             FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
     950             :             {
     951             :                 Word32 tmp_buf_fx[L_SUBFRAME5MS_48k];
     952        2560 :                 Copy32( &output_fx[ch][0], tmp_buf_fx, n_samples_rendered );
     953        2560 :                 Copy32( hMCParamUpmix->pcm_delay_fx[ch], output_fx[ch], n_samples_rendered );
     954        2560 :                 Copy32( &hMCParamUpmix->pcm_delay_fx[ch][n_samples_rendered], &hMCParamUpmix->pcm_delay_fx[ch][0], sub( noparamupmix_delay, n_samples_rendered ) );
     955        2560 :                 Copy32( tmp_buf_fx, &hMCParamUpmix->pcm_delay_fx[ch][noparamupmix_delay - n_samples_rendered], n_samples_rendered );
     956             :             }
     957             :         }
     958             :     }
     959             : 
     960        3080 :     st_ivas->hTcBuffer->slots_rendered = add( st_ivas->hTcBuffer->slots_rendered, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered] );
     961        3080 :     st_ivas->hTcBuffer->subframes_rendered = add( st_ivas->hTcBuffer->subframes_rendered, 1 );
     962        3080 :     move16();
     963        3080 :     move16();
     964             : 
     965        3080 :     pop_wmops();
     966        3080 :     return;
     967             : }
     968             : 
     969             : 
     970       74880 : static Word16 huff_read(
     971             :     Decoder_State *st,
     972             :     const Word16 ( *ht )[2] )
     973             : {
     974       74880 :     Word16 node = 0;
     975       74880 :     UWord16 next_bit = 0;
     976       74880 :     move16();
     977       74880 :     move16();
     978             : 
     979             :     DO
     980             :     {
     981      157461 :         next_bit = st->bit_stream[st->next_bit_pos];
     982      157461 :         move16();
     983      157461 :         st->next_bit_pos = add( st->next_bit_pos, 1 );
     984      157461 :         move16();
     985      157461 :         node = ht[node][next_bit];
     986      157461 :         move16();
     987             :     }
     988      157461 :     WHILE( node > 0 );
     989             : 
     990       74880 :     return negate( add( node, 1 ) );
     991             : }
     992             : 
     993             : 
     994        6240 : static void huffman_decode(
     995             :     Decoder_State *st,
     996             :     const PAR_TYPE parType,
     997             :     Word32 *vq )
     998             : {
     999             :     const Word16( *huff_node_table )[2];
    1000             :     Word16 iv, nquant, offset;
    1001             : 
    1002        6240 :     nquant = 0;
    1003        6240 :     move16();
    1004        6240 :     SWITCH( parType )
    1005             :     {
    1006        3120 :         case ALPHA:
    1007        3120 :             nquant = ivas_mc_paramupmix_alpha_quant_table_fx.nquant;
    1008        3120 :             move16();
    1009        3120 :             BREAK;
    1010        3120 :         case BETA:
    1011        3120 :             nquant = ivas_mc_paramupmix_beta_quant_table_fx[0].nquant;
    1012        3120 :             move16();
    1013        3120 :             BREAK;
    1014           0 :         default:
    1015           0 :             assert( 0 );
    1016             :     }
    1017             : 
    1018        6240 :     offset = sub( nquant, 1 ); /* range of df [-(nquant - 1), nquant - 1] */
    1019             : 
    1020        6240 :     st->next_bit_pos++;
    1021        6240 :     SWITCH( parType )
    1022             :     {
    1023        3120 :         case ALPHA:
    1024        3120 :             huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.alpha;
    1025        3120 :             BREAK;
    1026        3120 :         case BETA:
    1027        3120 :             huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.beta;
    1028        3120 :             BREAK;
    1029           0 :         default:
    1030           0 :             huff_node_table = NULL;
    1031           0 :             assert( 0 );
    1032             :     }
    1033        6240 :     vq[0] = huff_read( st, huff_node_table );
    1034        6240 :     move32();
    1035             : 
    1036        6240 :     SWITCH( parType )
    1037             :     {
    1038        3120 :         case ALPHA:
    1039        3120 :             huff_node_table = ivas_mc_paramupmix_huff_nodes_df.alpha;
    1040        3120 :             BREAK;
    1041        3120 :         case BETA:
    1042        3120 :             huff_node_table = ivas_mc_paramupmix_huff_nodes_df.beta;
    1043        3120 :             BREAK;
    1044           0 :         default:
    1045           0 :             assert( 0 );
    1046             :     }
    1047             : 
    1048       74880 :     FOR( iv = 1; iv < IVAS_MAX_NUM_BANDS; iv++ )
    1049             :     {
    1050       68640 :         vq[iv] = L_sub( L_add( huff_read( st, huff_node_table ), vq[iv - 1] ), offset );
    1051       68640 :         move32();
    1052             :     }
    1053             : 
    1054        6240 :     return;
    1055             : }
    1056             : 
    1057             : 
    1058        3120 : static void dequant_alpha(
    1059             :     Word32 *vq,
    1060             :     Word32 *v )
    1061             : {
    1062             :     Word16 iv;
    1063        3120 :     const ACPL_QUANT_TABLE_FX *quant_table = &ivas_mc_paramupmix_alpha_quant_table_fx; // Q28
    1064             : 
    1065       40560 :     FOR( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ )
    1066             :     {
    1067       37440 :         v[iv] = quant_table->data[vq[iv]]; // Q28
    1068       37440 :         move32();
    1069             :     }
    1070             : 
    1071        3120 :     return;
    1072             : }
    1073             : 
    1074             : 
    1075        3120 : static void dequant_beta(
    1076             :     Word32 *aq,
    1077             :     Word32 *bq,
    1078             :     Word32 *beta )
    1079             : {
    1080             :     Word16 iv;
    1081             :     const ACPL_QUANT_TABLE_FX *quant_table;
    1082             : 
    1083       40560 :     FOR( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ )
    1084             :     {
    1085       37440 :         quant_table = &ivas_mc_paramupmix_beta_quant_table_fx[ivas_param_upmx_mx_qmap[aq[iv]]]; // Q28
    1086       37440 :         beta[iv] = quant_table->data[bq[iv]];                                                   // Q28
    1087       37440 :         move32();
    1088             :     }
    1089             : 
    1090        3120 :     return;
    1091             : }
    1092             : 
    1093             : 
    1094        6240 : static void get_ec_data(
    1095             :     Decoder_State *st,
    1096             :     const PAR_TYPE parType,
    1097             :     Word32 *parQ,
    1098             :     Word32 *alphaQEnv,
    1099             :     Word32 ab[IVAS_MAX_NUM_BANDS] )
    1100             : {
    1101        6240 :     huffman_decode( st, parType, parQ );
    1102             : 
    1103        6240 :     IF( EQ_32( parType, ALPHA ) )
    1104             :     {
    1105        3120 :         dequant_alpha( parQ, ab ); // Qab = Q28
    1106        3120 :         Copy32( parQ, alphaQEnv, (Word16) IVAS_MAX_NUM_BANDS );
    1107             :     }
    1108             :     ELSE
    1109             :     {
    1110        3120 :         dequant_beta( alphaQEnv, parQ, ab ); // Qab = Q28
    1111             :     }
    1112             : 
    1113        6240 :     return;
    1114             : }

Generated by: LCOV version 1.14