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

Generated by: LCOV version 1.14