LCOV - code coverage report
Current view: top level - lib_dec - ivas_mc_paramupmix_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- conformance test test_26252.py @ a21f94bc6bac334fe001a5bad2f7b32b79038097 Lines: 356 377 94.4 %
Date: 2025-11-01 05:07:43 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 "options.h"
      35             : #include <stdint.h>
      36             : #include "cnst.h"
      37             : #include "prot.h"
      38             : #include "ivas_prot.h"
      39             : #include "ivas_prot_rend.h"
      40             : #include "ivas_cnst.h"
      41             : #include "ivas_rom_com.h"
      42             : #include "ivas_rom_dec.h"
      43             : #include "math.h"
      44             : #ifdef DEBUGGING
      45             : #include "debug.h"
      46             : #endif
      47             : #ifdef DEBUG_PLOT
      48             : #include "deb_out.h"
      49             : #endif
      50             : #include "wmc_auto.h"
      51             : #include "rom_dec.h"
      52             : 
      53             : 
      54             : /*-----------------------------------------------------------------------*
      55             :  * Local arrays
      56             :  *-----------------------------------------------------------------------*/
      57             : 
      58             : /*  boxes = { 0 1 2 3 [4 6] [5 7] [8 10] [9 11] }; */
      59             : const int16_t MC_PARAMUPMIX_CHIDX1[MC_PARAMUPMIX_COMBINATIONS] = { 0, 1, 4, 5 };
      60             : const int16_t MC_PARAMUPMIX_CHIDX2[MC_PARAMUPMIX_COMBINATIONS] = { 2, 3, 6, 7 };
      61             : 
      62             : 
      63             : /*-----------------------------------------------------------------------*
      64             :  * Local function prototypes
      65             :  *-----------------------------------------------------------------------*/
      66             : 
      67             : static void ps_pred_process_sf( MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, DECODER_TC_BUFFER_HANDLE hTcBuffer, float qmf_mod_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float qmf_mod_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float qmf_side_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float qmf_side_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float *param_interpol, const int16_t ch, const int16_t slots_rendered );
      68             : 
      69             : static void ivas_mc_paramupmix_dec_sf( Decoder_Struct *st_ivas, float *output_f[MAX_OUTPUT_CHANNELS] );
      70             : 
      71             : static void ivas_param_upmix_dec_decorr_subframes( Decoder_Struct *st_ivas, const int16_t nSamplesForRendering );
      72             : 
      73             : static int16_t huff_read( Decoder_State *st, const int16_t ( *ht )[2] );
      74             : 
      75             : static void huffman_decode( Decoder_State *st, const PAR_TYPE parType, int32_t *vq );
      76             : 
      77             : static void dequant_alpha( int32_t *vq, float *v );
      78             : 
      79             : static void dequant_beta( int32_t *aq, int32_t *bq, float *beta );
      80             : 
      81             : static void get_ec_data( Decoder_State *st, const PAR_TYPE parType, int32_t *parQ, int32_t *alphaQEnv, float ab[IVAS_MAX_NUM_BANDS] );
      82             : 
      83             : 
      84             : /*-------------------------------------------------------------------------
      85             :  * ivas_mc_paramupmix_dec_read_BS()
      86             :  *
      87             :  * Read the ParamUpmix MC metadata
      88             :  *------------------------------------------------------------------------*/
      89             : 
      90        5924 : void ivas_mc_paramupmix_dec_read_BS(
      91             :     Decoder_Struct *st_ivas,                /* i/o: IVAS decoder structure          */
      92             :     Decoder_State *st0,                     /* i/o: decoder state structure         */
      93             :     MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, /* i/o: decoder MC Param-Upmix handle   */
      94             :     int16_t *nb_bits                        /* o  : number of bits written          */
      95             : )
      96             : {
      97             :     int16_t i, k;
      98             :     int32_t alpha_quant[IVAS_MAX_NUM_BANDS];
      99             :     int16_t nb_bits_read_orig;
     100             :     int16_t next_bit_pos_orig, last_bit_pos;
     101             :     uint16_t bstr_meta[MAX_BITS_METADATA], *bit_stream_orig;
     102             : 
     103        5924 :     push_wmops( "mc_paramupmix_read_bs" );
     104        5924 :     *nb_bits = 0;
     105             : 
     106        5924 :     if ( st0->bfi )
     107             :     {
     108         850 :         for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     109             :         {
     110        8840 :             for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ )
     111             :             {
     112        8160 :                 hMCParamUpmix->alphas[i][k] = hMCParamUpmix->alpha_prev[i][k];
     113        8160 :                 hMCParamUpmix->betas[i][k] = hMCParamUpmix->beta_prev[i][k];
     114             :             }
     115             :         }
     116             : 
     117         850 :         for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     118             :         {
     119         680 :             mvr2r( hMCParamUpmix->alpha_prev[i], hMCParamUpmix->alpha_sf[i], IVAS_MAX_NUM_BANDS );
     120         680 :             mvr2r( hMCParamUpmix->beta_prev[i], hMCParamUpmix->beta_sf[i], IVAS_MAX_NUM_BANDS );
     121             :         }
     122             : 
     123         170 :         hMCParamUpmix->first_frame = 1;
     124             :     }
     125             :     else /*  if (!st->bfi) */
     126             :     {
     127        5754 :         bit_stream_orig = st0->bit_stream;
     128        5754 :         next_bit_pos_orig = st0->next_bit_pos;
     129        5754 :         last_bit_pos = (int16_t) ( ( st_ivas->hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC ) - 1 );
     130        5754 :         nb_bits_read_orig = 0;
     131        5754 :         last_bit_pos -= nb_bits_read_orig; /* reverse the bitstream for easier reading of indices */
     132    14390754 :         for ( i = 0; i < min( MAX_BITS_METADATA, last_bit_pos ); i++ )
     133             :         {
     134    14385000 :             bstr_meta[i] = st_ivas->bit_stream[last_bit_pos - i];
     135             :         }
     136        5754 :         st0->bit_stream = bstr_meta;
     137        5754 :         st0->next_bit_pos = 0;
     138        5754 :         st0->bits_frame = min( MAX_BITS_METADATA, last_bit_pos + 1 );
     139        5754 :         st0->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* to avoid BER detect */
     140             : 
     141        5754 :         if ( hMCParamUpmix->first_frame == 0 )
     142             :         {
     143       27690 :             for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     144             :             {
     145       22152 :                 mvr2r( hMCParamUpmix->alphas[i], hMCParamUpmix->alpha_prev[i], IVAS_MAX_NUM_BANDS );
     146       22152 :                 mvr2r( hMCParamUpmix->betas[i], hMCParamUpmix->beta_prev[i], IVAS_MAX_NUM_BANDS );
     147             :             }
     148             :         }
     149             : 
     150       28770 :         for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     151             :         {
     152       23016 :             get_ec_data( st0, ALPHA, hMCParamUpmix->alpha_quant[i], alpha_quant, hMCParamUpmix->alphas[i] );
     153             : 
     154       23016 :             get_ec_data( st0, BETA, hMCParamUpmix->beta_quant[i], alpha_quant, hMCParamUpmix->betas[i] );
     155             :         }
     156        5754 :         *nb_bits += st0->next_bit_pos;
     157        5754 :         st0->bit_stream = bit_stream_orig;
     158        5754 :         st0->next_bit_pos = next_bit_pos_orig;
     159             : 
     160        5754 :         if ( hMCParamUpmix->first_frame )
     161             :         {
     162        1080 :             for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     163             :             {
     164         864 :                 mvr2r( hMCParamUpmix->alphas[i], hMCParamUpmix->alpha_prev[i], IVAS_MAX_NUM_BANDS );
     165         864 :                 mvr2r( hMCParamUpmix->betas[i], hMCParamUpmix->beta_prev[i], IVAS_MAX_NUM_BANDS );
     166             :             }
     167         216 :             hMCParamUpmix->first_frame = 0;
     168             :         }
     169             : 
     170       28770 :         for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     171             :         {
     172       23016 :             mvr2r( hMCParamUpmix->alpha_prev[i], hMCParamUpmix->alpha_sf[i], IVAS_MAX_NUM_BANDS );
     173       23016 :             mvr2r( hMCParamUpmix->beta_prev[i], hMCParamUpmix->beta_sf[i], IVAS_MAX_NUM_BANDS );
     174             :         }
     175             :     }
     176             : 
     177        5924 :     pop_wmops();
     178        5924 :     return;
     179             : }
     180             : 
     181             : 
     182             : /*-------------------------------------------------------------------------
     183             :  * ivas_mc_paramupmix_dec_digest_tc()
     184             :  *
     185             :  *
     186             :  *------------------------------------------------------------------------*/
     187             : 
     188        5914 : void ivas_mc_paramupmix_dec_digest_tc(
     189             :     Decoder_Struct *st_ivas,           /* i/o: IVAS decoder handle                          */
     190             :     const uint8_t nCldfbSlots,         /* i  : number of CLDFB slots in transport channels  */
     191             :     const int16_t nSamplesForRendering /* i  : number of samples provided                   */
     192             : )
     193             : {
     194             :     MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
     195        5914 :     hMCParamUpmix = st_ivas->hMCParamUpmix;
     196        5914 :     assert( hMCParamUpmix );
     197        5914 :     push_wmops( "ivas_mc_paramupmix_dec_digest_tc" );
     198             : 
     199        5914 :     ivas_param_upmix_dec_decorr_subframes( st_ivas, nSamplesForRendering );
     200             : 
     201             :     /* adapt subframes */
     202        5914 :     ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
     203             : 
     204        5914 :     ivas_jbm_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hMCParamUpmix->param_interpolator );
     205             : 
     206        5914 :     pop_wmops();
     207        5914 :     return;
     208             : }
     209             : 
     210             : 
     211             : /*-------------------------------------------------------------------------
     212             :  * ivas_mc_paramupmix_dec_render()
     213             :  *
     214             :  *
     215             :  *------------------------------------------------------------------------*/
     216             : 
     217        7954 : void ivas_mc_paramupmix_dec_render(
     218             :     Decoder_Struct *st_ivas,      /* i/o: IVAS decoder handle                       */
     219             :     const uint16_t nSamplesAsked, /* i  : number of CLDFB slots requested           */
     220             :     uint16_t *nSamplesRendered,   /* o  : number of CLDFB slots rendered            */
     221             :     uint16_t *nSamplesAvailable,  /* o  : number of CLDFB slots still to render     */
     222             :     float *input_f[],             /* i  : core-coder transport channels             */
     223             :     float *output_f[]             /* i/o: synthesized core-coder transport channels */
     224             : )
     225             : {
     226             :     int16_t slots_to_render, first_sf, last_sf, subframe_idx;
     227             :     uint16_t slot_size, ch;
     228             :     float *output_f_local[MAX_OUTPUT_CHANNELS];
     229             :     MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
     230             : 
     231        7954 :     hMCParamUpmix = st_ivas->hMCParamUpmix;
     232        7954 :     assert( hMCParamUpmix );
     233             : 
     234        7954 :     push_wmops( "ivas_mc_paramupmix_dec_render" );
     235             : 
     236      135218 :     for ( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ )
     237             :     {
     238      127264 :         output_f_local[ch] = output_f[ch];
     239             :     }
     240             : 
     241        7954 :     slot_size = st_ivas->hTcBuffer->n_samples_granularity;
     242             : 
     243             :     /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
     244        7954 :     slots_to_render = min( st_ivas->hTcBuffer->num_slots - st_ivas->hTcBuffer->slots_rendered, nSamplesAsked / slot_size );
     245        7954 :     *nSamplesRendered = slots_to_render * slot_size;
     246        7954 :     first_sf = st_ivas->hTcBuffer->subframes_rendered;
     247        7954 :     last_sf = first_sf;
     248             : 
     249      103402 :     for ( ch = 0; ch < MAX_TRANSPORT_CHANNELS; ch++ )
     250             :     {
     251       95448 :         mvr2r( input_f[ch], output_f_local[ch], *nSamplesRendered );
     252             :     }
     253             : 
     254       33633 :     while ( slots_to_render > 0 )
     255             :     {
     256       25679 :         slots_to_render -= st_ivas->hTcBuffer->subframe_nbslots[last_sf];
     257       25679 :         last_sf++;
     258             :     }
     259             : #ifdef DEBUGGING
     260             :     assert( slots_to_render == 0 );
     261             : #endif
     262             :     {
     263       33633 :         for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
     264             :         {
     265       25679 :             int16_t n_samples_sf = slot_size * st_ivas->hTcBuffer->subframe_nbslots[subframe_idx];
     266       25679 :             ivas_mc_paramupmix_dec_sf( st_ivas, output_f_local );
     267             : 
     268      431423 :             for ( ch = 0; ch < min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ) ); ch++ )
     269             :             {
     270      405744 :                 output_f_local[ch] += n_samples_sf;
     271             :             }
     272             : 
     273             :             /* update combined orientation access index */
     274       25679 :             ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf );
     275             :         }
     276             :     }
     277             : 
     278        7954 :     *nSamplesAvailable = ( st_ivas->hTcBuffer->num_slots - st_ivas->hTcBuffer->slots_rendered ) * slot_size;
     279             : 
     280        7954 :     pop_wmops();
     281        7954 :     return;
     282             : }
     283             : 
     284             : 
     285             : /*-------------------------------------------------------------------------
     286             :  * ivas_mc_paramupmix_dec_open()
     287             :  *
     288             :  * Open Parametric MC decoder handle
     289             :  *-------------------------------------------------------------------------*/
     290             : 
     291          46 : ivas_error ivas_mc_paramupmix_dec_open(
     292             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure  */
     293             : )
     294             : {
     295             :     MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
     296             :     int32_t output_Fs;
     297             :     int16_t nchan_transport;
     298             :     uint16_t i;
     299             :     ivas_error error;
     300             : 
     301          46 :     error = IVAS_ERR_OK;
     302             : 
     303             :     /*-----------------------------------------------------------------*
     304             :      * prepare library opening
     305             :      *-----------------------------------------------------------------*/
     306             : 
     307          46 :     if ( ( hMCParamUpmix = (MC_PARAMUPMIX_DEC_HANDLE) malloc( sizeof( MC_PARAMUPMIX_DEC_DATA ) ) ) == NULL )
     308             :     {
     309           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param-Upmix MC\n" ) );
     310             :     }
     311          46 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
     312          46 :     hMCParamUpmix->first_frame = 1;
     313          46 :     st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS;
     314          46 :     nchan_transport = st_ivas->nchan_transport;
     315             : 
     316          46 :     switch ( nchan_transport )
     317             :     {
     318          46 :         case 8:
     319          46 :             st_ivas->nCPE = 4;
     320          46 :             st_ivas->nSCE = 0;
     321          46 :             st_ivas->element_mode_init = IVAS_CPE_MDCT;
     322          46 :             break;
     323             : #ifdef DEBUGGING
     324             :         default:
     325             :             assert( 0 && "Number of TC not supported for MC ParamUpmix!" );
     326             : #endif
     327             :     }
     328             : 
     329          46 :     hMCParamUpmix->hoa_encoder = NULL;
     330             : 
     331             :     /*-----------------------------------------------------------------*
     332             :      * set input parameters
     333             :      *-----------------------------------------------------------------*/
     334             : 
     335          46 :     hMCParamUpmix->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f );
     336             : 
     337         230 :     for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     338             :     {
     339         184 :         ivas_td_decorr_dec_open( &( hMCParamUpmix->hTdDecorr[i] ), output_Fs, 2, 1 );
     340             :     }
     341             : 
     342         414 :     for ( i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++ )
     343             :     {
     344         368 :         if ( ( hMCParamUpmix->pcm_delay[i] = (float *) malloc( NS2SA( output_Fs, IVAS_FB_DEC_DELAY_NS ) * sizeof( float ) ) ) == NULL )
     345             :         {
     346           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for delay buffer\n" ) );
     347             :         }
     348         368 :         set_zero( hMCParamUpmix->pcm_delay[i], NS2SA( output_Fs, IVAS_FB_DEC_DELAY_NS ) );
     349             :     }
     350             : 
     351             :     /* Head or external rotation */
     352             : #ifdef IVAS_RTPDUMP
     353          46 :     if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation || st_ivas->hCombinedOrientationData ) )
     354             : #else
     355             :     if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) )
     356             : #endif
     357             :     {
     358          37 :         if ( ( hMCParamUpmix->hoa_encoder = (float *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( float ) ) ) == NULL )
     359             :         {
     360           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
     361             :         }
     362          37 :         compute_hoa_encoder_mtx( st_ivas->hTransSetup.ls_azimuth, st_ivas->hTransSetup.ls_elevation, hMCParamUpmix->hoa_encoder, st_ivas->hTransSetup.nchan_out_woLFE, HEAD_ROTATION_HOA_ORDER );
     363             :     }
     364             : 
     365             :     /* allocate transport channels*/
     366          46 :     hMCParamUpmix->free_param_interpolator = 0;
     367          46 :     hMCParamUpmix->param_interpolator = NULL;
     368             : 
     369          46 :     if ( ( hMCParamUpmix->param_interpolator = (float *) malloc( MAX_JBM_CLDFB_TIMESLOTS * sizeof( float ) ) ) == NULL )
     370             :     {
     371           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for interpolator\n" ) );
     372             :     }
     373          46 :     hMCParamUpmix->free_param_interpolator = 1;
     374             : 
     375          46 :     ivas_jbm_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, DEFAULT_JBM_CLDFB_TIMESLOTS, hMCParamUpmix->param_interpolator );
     376             : 
     377          46 :     if ( st_ivas->hTcBuffer == NULL )
     378             :     {
     379             :         int16_t nchan_to_allocate;
     380             :         int16_t nchan_tc;
     381             :         int16_t granularity;
     382             :         TC_BUFFER_MODE buffer_mode;
     383             : 
     384          39 :         buffer_mode = TC_BUFFER_MODE_RENDERER;
     385          39 :         nchan_tc = ivas_jbm_dec_get_num_tc_channels( st_ivas );
     386          39 :         nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS;
     387             : 
     388          39 :         if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO )
     389             :         {
     390           0 :             buffer_mode = TC_BUFFER_MODE_BUFFER;
     391           0 :             nchan_tc = st_ivas->hDecoderConfig->nchan_out;
     392           0 :             nchan_to_allocate = nchan_tc;
     393             :         }
     394          39 :         else if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
     395             :         {
     396          38 :             nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS;
     397             :         }
     398             : 
     399          39 :         granularity = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, output_Fs );
     400             : 
     401          39 :         if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, granularity ) ) != IVAS_ERR_OK )
     402             :         {
     403           0 :             return error;
     404             :         }
     405             :     }
     406             : 
     407          46 :     st_ivas->hMCParamUpmix = hMCParamUpmix;
     408             : 
     409          46 :     return error;
     410             : }
     411             : 
     412             : 
     413             : /*-------------------------------------------------------------------------
     414             :  * ivas_mc_paramupmix_dec_close()
     415             :  *
     416             :  * Close ParamUpmix MC memories
     417             :  *------------------------------------------------------------------------*/
     418             : 
     419        1977 : void ivas_mc_paramupmix_dec_close(
     420             :     MC_PARAMUPMIX_DEC_HANDLE *hMCParamUpmix /* i/o: Parametric MC decoder handle   */
     421             : )
     422             : {
     423             :     int16_t i;
     424             : 
     425        1977 :     if ( hMCParamUpmix == NULL || *hMCParamUpmix == NULL )
     426             :     {
     427        1931 :         return;
     428             :     }
     429         230 :     for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     430             :     {
     431         184 :         ivas_td_decorr_dec_close( &( ( *hMCParamUpmix )->hTdDecorr[i] ) );
     432             :     }
     433         414 :     for ( i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++ )
     434             :     {
     435         368 :         if ( ( *hMCParamUpmix )->pcm_delay[i] != NULL )
     436             :         {
     437         368 :             free( ( *hMCParamUpmix )->pcm_delay[i] );
     438             :         }
     439             :     }
     440          46 :     if ( ( *hMCParamUpmix )->param_interpolator != NULL )
     441             :     {
     442          46 :         if ( ( *hMCParamUpmix )->free_param_interpolator == 1 )
     443             :         {
     444          46 :             free( ( *hMCParamUpmix )->param_interpolator );
     445             :         }
     446             :     }
     447          46 :     if ( ( *hMCParamUpmix )->hoa_encoder != NULL )
     448             :     {
     449          37 :         free( ( *hMCParamUpmix )->hoa_encoder );
     450          37 :         ( *hMCParamUpmix )->hoa_encoder = NULL;
     451             :     }
     452          46 :     free( *hMCParamUpmix );
     453             : 
     454          46 :     *hMCParamUpmix = NULL;
     455             : 
     456          46 :     return;
     457             : }
     458             : 
     459             : 
     460             : /*-------------------------------------------------------------------------
     461             :  * paramupmix_td_decorr_process_jbm()
     462             :  *
     463             :  *
     464             :  *------------------------------------------------------------------------*/
     465             : 
     466        5982 : static void paramupmix_td_decorr_process_jbm(
     467             :     ivas_td_decorr_state_t *hTdDecorr[], /* i/o: SPAR Covar. decoder handle   */
     468             :     float *pcm_in[],                     /* i  : input audio channels         */
     469             :     float **pp_out_pcm,                  /* o  : output audio channels        */
     470             :     const int16_t output_frame           /* i  : output frame length          */
     471             : )
     472             : {
     473             :     int16_t j, k;
     474             :     int16_t offset;
     475             :     float in_duck_gain[L_FRAME48k], out_duck_gain[L_FRAME48k];
     476             : 
     477        5982 :     offset = (int16_t) ( output_frame * FRAMES_PER_SEC * IVAS_DECORR_PARM_LOOKAHEAD_TAU );
     478             : 
     479             :     /* Look-ahead delay */
     480       29910 :     for ( k = 0; k < MC_PARAMUPMIX_COMBINATIONS; k++ )
     481             :     {
     482       23928 :         mvr2r( pcm_in[k], pp_out_pcm[k], output_frame );
     483       23928 :         delay_signal( pp_out_pcm[k], output_frame, hTdDecorr[k]->look_ahead_buf, offset );
     484             : 
     485             :         /* In ducking gains */
     486       23928 :         if ( hTdDecorr[k]->ducking_flag )
     487             :         {
     488       23928 :             ivas_td_decorr_get_ducking_gains( hTdDecorr[k]->pTrans_det, pcm_in[k], in_duck_gain, out_duck_gain, output_frame, 0 );
     489             : 
     490    22419048 :             for ( j = 0; j < output_frame; j++ )
     491             :             {
     492    22395120 :                 pp_out_pcm[k][j] = pp_out_pcm[k][j] * in_duck_gain[j];
     493             :             }
     494             :         }
     495             : 
     496             :         /* All pass delay section */
     497       23928 :         ivas_td_decorr_APD_iir_filter( &hTdDecorr[k]->APD_filt_state[0], pp_out_pcm[k], hTdDecorr[k]->num_apd_sections, output_frame );
     498             : 
     499             :         /* Out ducking gains */
     500       23928 :         if ( hTdDecorr[k]->ducking_flag )
     501             :         {
     502    22419048 :             for ( j = 0; j < output_frame; j++ )
     503             :             {
     504    22395120 :                 pp_out_pcm[k][j] = pp_out_pcm[k][j] * out_duck_gain[j];
     505             :             }
     506             :         }
     507             :     }
     508             : 
     509        5982 :     return;
     510             : }
     511             : 
     512             : 
     513             : /*-------------------------------------------------------------------------
     514             :  * ivas_param_upmix_dec_decorr_subframes()
     515             :  *
     516             :  *
     517             :  *------------------------------------------------------------------------*/
     518             : 
     519        5914 : static void ivas_param_upmix_dec_decorr_subframes(
     520             :     Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle    */
     521             :     const int16_t nSamplesForRendering )
     522             : {
     523             :     MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
     524             :     float *pPcm_tmp[MC_PARAMUPMIX_COMBINATIONS];
     525             :     float *p_tc[MC_PARAMUPMIX_COMBINATIONS];
     526             :     int16_t nchan_internal, ch;
     527             :     int16_t nSamplesLeftForTD, default_frame;
     528             : 
     529        5914 :     hMCParamUpmix = st_ivas->hMCParamUpmix;
     530        5914 :     assert( hMCParamUpmix );
     531             : 
     532        5914 :     push_wmops( "ivas_param_upmix_dec_decorr_subframes" );
     533             : 
     534             :     /* TD decorrelator */
     535        5914 :     default_frame = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC );
     536        5914 :     nSamplesLeftForTD = nSamplesForRendering;
     537        5914 :     nchan_internal = MC_PARAMUPMIX_COMBINATIONS;
     538             : 
     539       29570 :     for ( ch = 0; ch < nchan_internal; ch++ )
     540             :     {
     541       23656 :         pPcm_tmp[ch] = st_ivas->hTcBuffer->tc[ch + 8];
     542       23656 :         p_tc[ch] = st_ivas->hTcBuffer->tc[ch + 4];
     543             :     }
     544             : 
     545       11896 :     while ( nSamplesLeftForTD )
     546             :     {
     547        5982 :         int16_t nSamplesToDecorr = min( nSamplesLeftForTD, default_frame );
     548             : 
     549        5982 :         paramupmix_td_decorr_process_jbm( hMCParamUpmix->hTdDecorr, p_tc, pPcm_tmp, nSamplesToDecorr );
     550             : 
     551       29910 :         for ( ch = 0; ch < nchan_internal; ch++ )
     552             :         {
     553       23928 :             p_tc[ch] += nSamplesToDecorr;
     554             :         }
     555             : 
     556        5982 :         nSamplesLeftForTD -= nSamplesToDecorr;
     557             :     }
     558             : 
     559        5914 :     pop_wmops();
     560        5914 :     return;
     561             : }
     562             : 
     563             : 
     564             : /*****************************************************************************************/
     565             : /* local functions                                                                       */
     566             : /*****************************************************************************************/
     567             : 
     568      102716 : static void ps_pred_process_sf(
     569             :     MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix,
     570             :     DECODER_TC_BUFFER_HANDLE hTcBuffer,
     571             :     float qmf_mod_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* in/out */
     572             :     float qmf_mod_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
     573             :     float qmf_side_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* in/out */
     574             :     float qmf_side_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
     575             :     float *param_interpol,
     576             :     const int16_t ch,
     577             :     const int16_t slots_rendered )
     578             : {
     579             :     float vmre, vmim, vsre, vsim;
     580             :     int16_t iqmf, ipar, ismp, iismp;
     581             :     float alpha_smp, beta_smp;
     582             :     float *alpha1, *alpha2;
     583             :     float *beta1, *beta2;
     584      102716 :     float *alpha_prev = hMCParamUpmix->alpha_prev[ch];
     585      102716 :     float *beta_prev = hMCParamUpmix->beta_prev[ch];
     586      102716 :     float *alpha_sf = hMCParamUpmix->alpha_sf[ch];
     587      102716 :     float *beta_sf = hMCParamUpmix->beta_sf[ch];
     588             :     float dalpha, dbeta, ifac;
     589             :     float alpha_start[IVAS_MAX_NUM_BANDS], beta_start[IVAS_MAX_NUM_BANDS];
     590             : 
     591      102716 :     const int16_t qmf_to_par_band[] = {
     592             :         0, 1, 2, 3, 4, 5, 5, 6, 6, 7,
     593             :         7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
     594             :         9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
     595             :         10, 10, 11, 11, 11, 11, 11, 11, 11, 11,
     596             :         11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
     597             :         11, 11, 11, 11, 11, 11, 11, 11, 11, 11
     598             :     };
     599             : 
     600      102716 :     mvr2r( alpha_sf, alpha_start, IVAS_MAX_NUM_BANDS );
     601      102716 :     mvr2r( beta_sf, beta_start, IVAS_MAX_NUM_BANDS );
     602     6265676 :     for ( iqmf = 0; iqmf < CLDFB_NO_CHANNELS_MAX; iqmf++ )
     603             :     {
     604     6162960 :         ipar = qmf_to_par_band[iqmf];
     605     6162960 :         alpha1 = alpha_prev;
     606     6162960 :         beta1 = beta_prev;
     607             : 
     608     6162960 :         ismp = 0;
     609     6162960 :         alpha2 = hMCParamUpmix->alphas[ch];
     610     6162960 :         beta2 = hMCParamUpmix->betas[ch];
     611     6162960 :         alpha_smp = alpha_start[ipar];
     612     6162960 :         beta_smp = beta_start[ipar];
     613             : 
     614    28942080 :         for ( iismp = 0; iismp < hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered]; iismp++ )
     615             :         {
     616    22779120 :             if ( ( slots_rendered == 0 ) && ( iismp == 0 ) )
     617             :             {
     618     1419360 :                 ifac = param_interpol[iismp];
     619             :             }
     620             :             else
     621             :             {
     622    21359760 :                 ifac = param_interpol[iismp] - param_interpol[iismp - 1];
     623             :             }
     624    22779120 :             dalpha = ( alpha2[ipar] - alpha1[ipar] ) * ifac;
     625    22779120 :             dbeta = ( beta2[ipar] - beta1[ipar] ) * ifac;
     626             : 
     627    22779120 :             alpha_smp += dalpha;
     628    22779120 :             beta_smp += dbeta;
     629             : 
     630    22779120 :             vmre = qmf_mod_re[ismp][iqmf];
     631    22779120 :             vmim = qmf_mod_im[ismp][iqmf];
     632    22779120 :             vsre = qmf_side_re[ismp][iqmf];
     633    22779120 :             vsim = qmf_side_im[ismp][iqmf];
     634             : 
     635    22779120 :             qmf_side_re[ismp][iqmf] = alpha_smp * vmre + beta_smp * vsre;
     636    22779120 :             qmf_side_im[ismp][iqmf] = alpha_smp * vmim + beta_smp * vsim;
     637             : 
     638    22779120 :             ismp++;
     639             :         }
     640     6162960 :         alpha_sf[ipar] = alpha_smp;
     641     6162960 :         beta_sf[ipar] = beta_smp;
     642             :     }
     643             : 
     644      102716 :     return;
     645             : }
     646             : 
     647       25679 : static void ivas_mc_paramupmix_dec_sf(
     648             :     Decoder_Struct *st_ivas,             /* i/o: IVAS decoder handle                        */
     649             :     float *output_f[MAX_OUTPUT_CHANNELS] /* i/o: synthesized core-coder transport channels  */
     650             : )
     651             : {
     652             :     int16_t i, ch, slot_idx, k;
     653             :     float *pPcm_temp[MC_PARAMUPMIX_COMBINATIONS * 2]; /* decorrelated and undecorrelated*/
     654             :     /*CLDFB*/
     655             :     float Cldfb_RealBuffer[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
     656             :     float Cldfb_ImagBuffer[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
     657             :     int16_t noparamupmix_delay, n_samples_rendered;
     658             :     MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
     659             :     int16_t subframeIdx, idx_in, maxBand;
     660             :     float Cldfb_RealBuffer_subfr[MAX_INTERN_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
     661             :     float Cldfb_ImagBuffer_subfr[MAX_INTERN_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
     662             :     float Cldfb_RealBuffer_Binaural[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
     663             :     float Cldfb_ImagBuffer_Binaural[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
     664             :     int16_t slot_index_start;
     665             : 
     666       25679 :     hMCParamUpmix = st_ivas->hMCParamUpmix;
     667       25679 :     assert( hMCParamUpmix );
     668       25679 :     push_wmops( "ivas_mc_paramupmix_dec_sf" );
     669             : 
     670       25679 :     slot_index_start = st_ivas->hTcBuffer->slots_rendered;
     671      128395 :     for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     672             :     {
     673      102716 :         pPcm_temp[2 * i] = output_f[i + 4];     /* un-decorrelated */
     674      102716 :         pPcm_temp[2 * i + 1] = output_f[i + 8]; /* decorrelated */
     675             :     }
     676             : 
     677             :     /* CLDFB Analysis*/
     678      231111 :     for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ )
     679             :     {
     680             :         /* slot loop for gathering the input data */
     681      964736 :         for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     682             :         {
     683      759304 :             cldfbAnalysis_ts( &( pPcm_temp[ch][hMCParamUpmix->num_freq_bands * slot_idx] ), Cldfb_RealBuffer[ch][slot_idx], Cldfb_ImagBuffer[ch][slot_idx], hMCParamUpmix->num_freq_bands, st_ivas->cldfbAnaDec[ch] );
     684             :         }
     685             :     }
     686             : 
     687      128395 :     for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
     688             :     {
     689      102716 :         ps_pred_process_sf( hMCParamUpmix,
     690             :                             st_ivas->hTcBuffer,
     691      102716 :                             Cldfb_RealBuffer[2 * ch], /* in/out */
     692      102716 :                             Cldfb_ImagBuffer[2 * ch],
     693      102716 :                             Cldfb_RealBuffer[2 * ch + 1], /* in/out decorr */
     694      102716 :                             Cldfb_ImagBuffer[2 * ch + 1],
     695      102716 :                             &hMCParamUpmix->param_interpolator[st_ivas->hTcBuffer->slots_rendered],
     696             :                             ch,
     697      102716 :                             st_ivas->hTcBuffer->slots_rendered );
     698             : 
     699             :         /*-- m, s -> l, r ----------------------------*/
     700      482368 :         for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     701             :         {
     702    23158772 :             for ( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ )
     703             :             {
     704    22779120 :                 float qlre = Cldfb_RealBuffer[2 * ch][slot_idx][k];
     705    22779120 :                 float qlim = Cldfb_ImagBuffer[2 * ch][slot_idx][k];
     706    22779120 :                 float qrre = Cldfb_RealBuffer[2 * ch + 1][slot_idx][k];
     707    22779120 :                 float qrim = Cldfb_ImagBuffer[2 * ch + 1][slot_idx][k];
     708             : 
     709    22779120 :                 Cldfb_RealBuffer[2 * ch][slot_idx][k] = qlre + qrre;
     710    22779120 :                 Cldfb_ImagBuffer[2 * ch][slot_idx][k] = qlim + qrim;
     711    22779120 :                 Cldfb_RealBuffer[2 * ch + 1][slot_idx][k] = qlre - qrre;
     712    22779120 :                 Cldfb_ImagBuffer[2 * ch + 1][slot_idx][k] = qlim - qrim;
     713             :             }
     714             :         }
     715             :     }
     716             : 
     717       25679 :     if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM )
     718             :     {
     719       24999 :         maxBand = (int16_t) ( ( CLDFB_NO_CHANNELS_MAX * st_ivas->hDecoderConfig->output_Fs ) / 48000 );
     720       24999 :         subframeIdx = st_ivas->hTcBuffer->subframes_rendered;
     721             :         /* fastconv binaural rendering and CLDFB synthesis */
     722             :         /* cldfb analysis of non-coupled, non-LFE channels */
     723       24999 :         idx_in = 0;
     724      124995 :         for ( ch = 0; ch < MC_PARAMUPMIX_MAX_INPUT_CHANS - 2 * MC_PARAMUPMIX_COMBINATIONS; ch++ )
     725             :         {
     726       99996 :             if ( st_ivas->hIntSetup.index_lfe[0] != ch )
     727             :             {
     728       99356 :                 pPcm_temp[ch] = output_f[ch];
     729             :                 /* slot loop for gathering the input data */
     730      465568 :                 for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     731             :                 {
     732      366212 :                     cldfbAnalysis_ts( &( pPcm_temp[ch][hMCParamUpmix->num_freq_bands * slot_idx] ),
     733      366212 :                                       Cldfb_RealBuffer_subfr[idx_in][slot_idx],
     734      366212 :                                       Cldfb_ImagBuffer_subfr[idx_in][slot_idx],
     735      366212 :                                       maxBand, st_ivas->cldfbAnaDec[2 * MC_PARAMUPMIX_COMBINATIONS + idx_in] );
     736             :                 }
     737       99356 :                 idx_in++;
     738             :             }
     739             :         }
     740             : 
     741             :         /* copy and reorder cldfb analysis of coupled channels */
     742      124995 :         for ( ch = 0; ch < MAX_PARAM_SPATIAL_SUBFRAMES; ch++ )
     743             :         {
     744      499980 :             for ( slot_idx = 0; slot_idx < MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ )
     745             :             {
     746      399984 :                 mvr2r( Cldfb_RealBuffer[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_RealBuffer_subfr[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX );
     747      399984 :                 mvr2r( Cldfb_ImagBuffer[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_ImagBuffer_subfr[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX );
     748      399984 :                 mvr2r( Cldfb_RealBuffer[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_RealBuffer_subfr[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX );
     749      399984 :                 mvr2r( Cldfb_ImagBuffer[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_ImagBuffer_subfr[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX );
     750             :             }
     751       99996 :             idx_in += 2;
     752             :         }
     753             : 
     754       24999 :         if ( st_ivas->hCombinedOrientationData && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
     755             :         {
     756      113992 :             for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     757             :             {
     758       89633 :                 ivas_param_mc_mc2sba_cldfb( st_ivas->hTransSetup, hMCParamUpmix->hoa_encoder, slot_idx, Cldfb_RealBuffer_subfr, Cldfb_ImagBuffer_subfr, maxBand, GAIN_LFE );
     759             :             }
     760             :         }
     761             : 
     762             :         /*LFE handling for split rendering cases*/
     763       24999 :         if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     764             :         {
     765       22559 :             if ( st_ivas->hSplitBinRend->hCldfbDataOut != NULL )
     766             :             {
     767       30880 :                 for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     768             :                 {
     769      412165 :                     for ( ch = 0; ch < ( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ); ch++ )
     770             :                     {
     771      387920 :                         mvr2r( Cldfb_RealBuffer_subfr[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_RealBuffer[ch][slot_index_start + slot_idx], maxBand );
     772      387920 :                         mvr2r( Cldfb_ImagBuffer_subfr[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_ImagBuffer[ch][slot_index_start + slot_idx], maxBand );
     773             :                     }
     774             :                 }
     775             : 
     776        6635 :                 st_ivas->hSplitBinRend->hCldfbDataOut->config = st_ivas->hIntSetup.output_config;
     777             :             }
     778             :         }
     779             : 
     780             :         /* Implement binaural rendering */
     781       24999 :         ivas_binRenderer( st_ivas->hBinRenderer,
     782       22559 :                           ( st_ivas->hSplitBinRend == NULL ) ? NULL : &st_ivas->hSplitBinRend->splitrend.multiBinPoseData,
     783             :                           st_ivas->hCombinedOrientationData,
     784       24999 :                           st_ivas->hTcBuffer->subframe_nbslots[subframeIdx],
     785             :                           Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural,
     786             :                           Cldfb_RealBuffer_subfr,
     787             :                           Cldfb_ImagBuffer_subfr );
     788             : 
     789       24999 :         if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     790             :         {
     791             :             int16_t pos_idx;
     792      114122 :             for ( pos_idx = 0; pos_idx < st_ivas->hBinRenderer->numPoses; pos_idx++ )
     793             :             {
     794      426144 :                 for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[subframeIdx]; slot_idx++ )
     795             :                 {
     796     1003743 :                     for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
     797             :                     {
     798             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
     799      669162 :                         ivas_CLDFB_RINGBUF_Push(
     800      669162 :                             st_ivas->hSplitBinRend->hMultiBinCldfbData[pos_idx * BINAURAL_CHANNELS + ch],
     801      669162 :                             Cldfb_RealBuffer_Binaural[pos_idx][ch][slot_idx],
     802      669162 :                             Cldfb_ImagBuffer_Binaural[pos_idx][ch][slot_idx],
     803             :                             maxBand );
     804             : #else
     805             :                         mvr2r( Cldfb_RealBuffer_Binaural[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_index_start + slot_idx], maxBand );
     806             :                         mvr2r( Cldfb_ImagBuffer_Binaural[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_index_start + slot_idx], maxBand );
     807             : #endif
     808             :                     }
     809             :                 }
     810             :             }
     811             :         }
     812             : 
     813             :         /* Implement CLDFB synthesis */
     814       74997 :         for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
     815             :         {
     816             :             float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES];
     817             :             float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES];
     818             : 
     819      234384 :             for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[subframeIdx]; slot_idx++ )
     820             :             {
     821      184386 :                 RealBuffer[slot_idx] = Cldfb_RealBuffer_Binaural[0][ch][slot_idx];
     822      184386 :                 ImagBuffer[slot_idx] = Cldfb_ImagBuffer_Binaural[0][ch][slot_idx];
     823             :             }
     824             : 
     825       49998 :             cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][0] ), maxBand * st_ivas->hTcBuffer->subframe_nbslots[subframeIdx], st_ivas->cldfbSynDec[ch] );
     826             :         }
     827             :     }
     828             :     else
     829             :     {
     830             :         /*  boxes = { 0 1 2 3 [4 6] [5 7] [8 10] [9 11] }; */
     831         680 :         pPcm_temp[0] = output_f[4];
     832         680 :         pPcm_temp[1] = output_f[6];
     833         680 :         pPcm_temp[2] = output_f[5];
     834         680 :         pPcm_temp[3] = output_f[7];
     835         680 :         pPcm_temp[4] = output_f[8];
     836         680 :         pPcm_temp[5] = output_f[10];
     837         680 :         pPcm_temp[6] = output_f[9];
     838         680 :         pPcm_temp[7] = output_f[11];
     839             : 
     840             :         /* CLDFB synthesis */
     841        6120 :         for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ )
     842             :         {
     843       27200 :             for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     844             :             {
     845             :                 float *ptr_im[1], *ptr_re[1];
     846       21760 :                 ptr_re[0] = Cldfb_RealBuffer[ch][slot_idx];
     847       21760 :                 ptr_im[0] = Cldfb_ImagBuffer[ch][slot_idx];
     848             : 
     849       21760 :                 cldfbSynthesis( ptr_re, ptr_im, &( pPcm_temp[ch][hMCParamUpmix->num_freq_bands * slot_idx] ),
     850       21760 :                                 hMCParamUpmix->num_freq_bands, st_ivas->cldfbSynDec[ch] );
     851             :             }
     852             :         }
     853             : 
     854             :         /* adjust delay of other channels */
     855         680 :         noparamupmix_delay = NS2SA( st_ivas->hDecoderConfig->output_Fs, IVAS_FB_DEC_DELAY_NS );
     856         680 :         n_samples_rendered = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered] * hMCParamUpmix->num_freq_bands;
     857         680 :         if ( n_samples_rendered > noparamupmix_delay )
     858             :         {
     859           0 :             for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
     860             :             {
     861             :                 /*delay is handled within LFE decoder*/
     862           0 :                 if ( st_ivas->hIntSetup.index_lfe[0] != ch )
     863             :                 {
     864             :                     float tmp_buf[L_SUBFRAME5MS_48k];
     865           0 :                     mvr2r( &output_f[ch][n_samples_rendered - noparamupmix_delay], tmp_buf, noparamupmix_delay );
     866           0 :                     mvr2r( output_f[ch], &output_f[ch][noparamupmix_delay], n_samples_rendered - noparamupmix_delay );
     867           0 :                     mvr2r( hMCParamUpmix->pcm_delay[ch], output_f[ch], noparamupmix_delay );
     868           0 :                     mvr2r( tmp_buf, hMCParamUpmix->pcm_delay[ch], noparamupmix_delay );
     869             :                 }
     870             :             }
     871             :         }
     872             :         else
     873             :         {
     874        3400 :             for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
     875             :             {
     876        2720 :                 if ( st_ivas->hIntSetup.index_lfe[0] != ch )
     877             :                 {
     878             :                     float tmp_buf[L_SUBFRAME5MS_48k];
     879        2040 :                     mvr2r( &output_f[ch][0], tmp_buf, n_samples_rendered );
     880        2040 :                     mvr2r( hMCParamUpmix->pcm_delay[ch], output_f[ch], n_samples_rendered );
     881        2040 :                     mvr2r( &hMCParamUpmix->pcm_delay[ch][n_samples_rendered], &hMCParamUpmix->pcm_delay[ch][0], noparamupmix_delay - n_samples_rendered );
     882        2040 :                     mvr2r( tmp_buf, &hMCParamUpmix->pcm_delay[ch][noparamupmix_delay - n_samples_rendered], n_samples_rendered );
     883             :                 }
     884             :             }
     885             :         }
     886             :     }
     887             : 
     888       25679 :     st_ivas->hTcBuffer->slots_rendered += st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered];
     889       25679 :     st_ivas->hTcBuffer->subframes_rendered++;
     890             : 
     891       25679 :     pop_wmops();
     892       25679 :     return;
     893             : }
     894             : 
     895             : 
     896      552384 : static int16_t huff_read(
     897             :     Decoder_State *st,
     898             :     const int16_t ( *ht )[2] )
     899             : {
     900      552384 :     int16_t node = 0;
     901      552384 :     uint16_t next_bit = 0;
     902             : 
     903             :     do
     904             :     {
     905     1162123 :         next_bit = st->bit_stream[st->next_bit_pos];
     906     1162123 :         st->next_bit_pos++;
     907     1162123 :         node = ht[node][next_bit];
     908     1162123 :     } while ( node > 0 );
     909             : 
     910      552384 :     return -( node + 1 );
     911             : }
     912             : 
     913             : 
     914       46032 : static void huffman_decode(
     915             :     Decoder_State *st,
     916             :     const PAR_TYPE parType,
     917             :     int32_t *vq )
     918             : {
     919             :     const int16_t( *huff_node_table )[2];
     920             :     int16_t iv, nquant, offset;
     921             : 
     922       46032 :     nquant = 0;
     923       46032 :     switch ( parType )
     924             :     {
     925       23016 :         case ALPHA:
     926       23016 :             nquant = ivas_mc_paramupmix_alpha_quant_table.nquant;
     927       23016 :             break;
     928       23016 :         case BETA:
     929       23016 :             nquant = ivas_mc_paramupmix_beta_quant_table[0].nquant;
     930       23016 :             break;
     931           0 :         default:
     932           0 :             assert( 0 );
     933             :     }
     934             : 
     935       46032 :     offset = nquant - 1; /* range of df [-(nquant - 1), nquant - 1] */
     936             : 
     937       46032 :     st->next_bit_pos++;
     938       46032 :     switch ( parType )
     939             :     {
     940       23016 :         case ALPHA:
     941       23016 :             huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.alpha;
     942       23016 :             break;
     943       23016 :         case BETA:
     944       23016 :             huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.beta;
     945       23016 :             break;
     946           0 :         default:
     947           0 :             huff_node_table = NULL;
     948           0 :             assert( 0 );
     949             :     }
     950       46032 :     vq[0] = huff_read( st, huff_node_table );
     951             : 
     952       46032 :     switch ( parType )
     953             :     {
     954       23016 :         case ALPHA:
     955       23016 :             huff_node_table = ivas_mc_paramupmix_huff_nodes_df.alpha;
     956       23016 :             break;
     957       23016 :         case BETA:
     958       23016 :             huff_node_table = ivas_mc_paramupmix_huff_nodes_df.beta;
     959       23016 :             break;
     960           0 :         default:
     961           0 :             assert( 0 );
     962             :     }
     963             : 
     964      552384 :     for ( iv = 1; iv < IVAS_MAX_NUM_BANDS; iv++ )
     965             :     {
     966      506352 :         vq[iv] = huff_read( st, huff_node_table ) + vq[iv - 1] - offset;
     967             :     }
     968             : 
     969       46032 :     return;
     970             : }
     971             : 
     972             : 
     973       23016 : static void dequant_alpha(
     974             :     int32_t *vq,
     975             :     float *v )
     976             : {
     977             :     int16_t iv;
     978       23016 :     const ACPL_QUANT_TABLE *quant_table = &ivas_mc_paramupmix_alpha_quant_table;
     979             : 
     980      299208 :     for ( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ )
     981             :     {
     982      276192 :         v[iv] = quant_table->data[vq[iv]];
     983             :     }
     984             : 
     985       23016 :     return;
     986             : }
     987             : 
     988             : 
     989       23016 : static void dequant_beta(
     990             :     int32_t *aq,
     991             :     int32_t *bq,
     992             :     float *beta )
     993             : {
     994             :     int16_t iv;
     995             :     const ACPL_QUANT_TABLE *quant_table;
     996             : 
     997      299208 :     for ( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ )
     998             :     {
     999      276192 :         quant_table = &ivas_mc_paramupmix_beta_quant_table[ivas_param_upmx_mx_qmap[aq[iv]]];
    1000      276192 :         beta[iv] = quant_table->data[bq[iv]];
    1001             :     }
    1002             : 
    1003       23016 :     return;
    1004             : }
    1005             : 
    1006             : 
    1007       46032 : static void get_ec_data(
    1008             :     Decoder_State *st,
    1009             :     const PAR_TYPE parType,
    1010             :     int32_t *parQ,
    1011             :     int32_t *alphaQEnv,
    1012             :     float ab[IVAS_MAX_NUM_BANDS] )
    1013             : {
    1014       46032 :     huffman_decode( st, parType, parQ );
    1015             : 
    1016       46032 :     if ( parType == ALPHA )
    1017             :     {
    1018       23016 :         dequant_alpha( parQ, ab );
    1019       23016 :         mvl2l( parQ, alphaQEnv, (int16_t) IVAS_MAX_NUM_BANDS );
    1020             :     }
    1021             :     else
    1022             :     {
    1023       23016 :         dequant_beta( alphaQEnv, parQ, ab );
    1024             :     }
    1025             : 
    1026       46032 :     return;
    1027             : }

Generated by: LCOV version 1.14