LCOV - code coverage report
Current view: top level - lib_dec - ivas_mc_paramupmix_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 333 373 89.3 %
Date: 2025-05-23 08:37:30 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        2370 : 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        2370 :     push_wmops( "mc_paramupmix_read_bs" );
     104        2370 :     *nb_bits = 0;
     105             : 
     106        2370 :     if ( st0->bfi )
     107             :     {
     108           0 :         for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     109             :         {
     110           0 :             for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ )
     111             :             {
     112           0 :                 hMCParamUpmix->alphas[i][k] = hMCParamUpmix->alpha_prev[i][k];
     113           0 :                 hMCParamUpmix->betas[i][k] = hMCParamUpmix->beta_prev[i][k];
     114             :             }
     115             :         }
     116             : 
     117           0 :         for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     118             :         {
     119           0 :             mvr2r( hMCParamUpmix->alpha_prev[i], hMCParamUpmix->alpha_sf[i], IVAS_MAX_NUM_BANDS );
     120           0 :             mvr2r( hMCParamUpmix->beta_prev[i], hMCParamUpmix->beta_sf[i], IVAS_MAX_NUM_BANDS );
     121             :         }
     122             : 
     123           0 :         hMCParamUpmix->first_frame = 1;
     124             :     }
     125             :     else /*  if (!st->bfi) */
     126             :     {
     127        2370 :         bit_stream_orig = st0->bit_stream;
     128        2370 :         next_bit_pos_orig = st0->next_bit_pos;
     129        2370 :         last_bit_pos = (int16_t) ( ( st_ivas->hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC ) - 1 );
     130        2370 :         nb_bits_read_orig = 0;
     131        2370 :         last_bit_pos -= nb_bits_read_orig; /* reverse the bitstream for easier reading of indices */
     132     5927370 :         for ( i = 0; i < min( MAX_BITS_METADATA, last_bit_pos ); i++ )
     133             :         {
     134     5925000 :             bstr_meta[i] = st_ivas->bit_stream[last_bit_pos - i];
     135             :         }
     136        2370 :         st0->bit_stream = bstr_meta;
     137        2370 :         st0->next_bit_pos = 0;
     138        2370 :         st0->bits_frame = min( MAX_BITS_METADATA, last_bit_pos + 1 );
     139        2370 :         st0->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* to avoid BER detect */
     140             : 
     141        2370 :         if ( hMCParamUpmix->first_frame == 0 )
     142             :         {
     143       11670 :             for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     144             :             {
     145        9336 :                 mvr2r( hMCParamUpmix->alphas[i], hMCParamUpmix->alpha_prev[i], IVAS_MAX_NUM_BANDS );
     146        9336 :                 mvr2r( hMCParamUpmix->betas[i], hMCParamUpmix->beta_prev[i], IVAS_MAX_NUM_BANDS );
     147             :             }
     148             :         }
     149             : 
     150       11850 :         for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     151             :         {
     152        9480 :             get_ec_data( st0, ALPHA, hMCParamUpmix->alpha_quant[i], alpha_quant, hMCParamUpmix->alphas[i] );
     153             : 
     154        9480 :             get_ec_data( st0, BETA, hMCParamUpmix->beta_quant[i], alpha_quant, hMCParamUpmix->betas[i] );
     155             :         }
     156        2370 :         *nb_bits += st0->next_bit_pos;
     157        2370 :         st0->bit_stream = bit_stream_orig;
     158        2370 :         st0->next_bit_pos = next_bit_pos_orig;
     159             : 
     160        2370 :         if ( hMCParamUpmix->first_frame )
     161             :         {
     162         180 :             for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     163             :             {
     164         144 :                 mvr2r( hMCParamUpmix->alphas[i], hMCParamUpmix->alpha_prev[i], IVAS_MAX_NUM_BANDS );
     165         144 :                 mvr2r( hMCParamUpmix->betas[i], hMCParamUpmix->beta_prev[i], IVAS_MAX_NUM_BANDS );
     166             :             }
     167          36 :             hMCParamUpmix->first_frame = 0;
     168             :         }
     169             : 
     170       11850 :         for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     171             :         {
     172        9480 :             mvr2r( hMCParamUpmix->alpha_prev[i], hMCParamUpmix->alpha_sf[i], IVAS_MAX_NUM_BANDS );
     173        9480 :             mvr2r( hMCParamUpmix->beta_prev[i], hMCParamUpmix->beta_sf[i], IVAS_MAX_NUM_BANDS );
     174             :         }
     175             :     }
     176             : 
     177        2370 :     pop_wmops();
     178        2370 :     return;
     179             : }
     180             : 
     181             : 
     182             : /*-------------------------------------------------------------------------
     183             :  * ivas_mc_paramupmix_dec_digest_tc()
     184             :  *
     185             :  *
     186             :  *------------------------------------------------------------------------*/
     187             : 
     188        2340 : 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        2340 :     hMCParamUpmix = st_ivas->hMCParamUpmix;
     196        2340 :     assert( hMCParamUpmix );
     197        2340 :     push_wmops( "ivas_mc_paramupmix_dec_digest_tc" );
     198             : 
     199        2340 :     ivas_param_upmix_dec_decorr_subframes( st_ivas, nSamplesForRendering );
     200             : 
     201             :     /* adapt subframes */
     202        2340 :     ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
     203             : 
     204        2340 :     ivas_jbm_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hMCParamUpmix->param_interpolator );
     205             : 
     206        2340 :     pop_wmops();
     207        2340 :     return;
     208             : }
     209             : 
     210             : 
     211             : /*-------------------------------------------------------------------------
     212             :  * ivas_mc_paramupmix_dec_render()
     213             :  *
     214             :  *
     215             :  *------------------------------------------------------------------------*/
     216             : 
     217        5420 : 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        5420 :     hMCParamUpmix = st_ivas->hMCParamUpmix;
     232        5420 :     assert( hMCParamUpmix );
     233             : 
     234        5420 :     push_wmops( "ivas_mc_paramupmix_dec_render" );
     235             : 
     236       92140 :     for ( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ )
     237             :     {
     238       86720 :         output_f_local[ch] = output_f[ch];
     239             :     }
     240             : 
     241        5420 :     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        5420 :     slots_to_render = min( st_ivas->hTcBuffer->num_slots - st_ivas->hTcBuffer->slots_rendered, nSamplesAsked / slot_size );
     245        5420 :     *nSamplesRendered = slots_to_render * slot_size;
     246        5420 :     first_sf = st_ivas->hTcBuffer->subframes_rendered;
     247        5420 :     last_sf = first_sf;
     248             : 
     249       70460 :     for ( ch = 0; ch < MAX_TRANSPORT_CHANNELS; ch++ )
     250             :     {
     251       65040 :         mvr2r( input_f[ch], output_f_local[ch], *nSamplesRendered );
     252             :     }
     253             : 
     254       14780 :     while ( slots_to_render > 0 )
     255             :     {
     256        9360 :         slots_to_render -= st_ivas->hTcBuffer->subframe_nbslots[last_sf];
     257        9360 :         last_sf++;
     258             :     }
     259             : #ifdef DEBUGGING
     260             :     assert( slots_to_render == 0 );
     261             : #endif
     262             :     {
     263       14780 :         for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
     264             :         {
     265        9360 :             int16_t n_samples_sf = slot_size * st_ivas->hTcBuffer->subframe_nbslots[subframe_idx];
     266        9360 :             ivas_mc_paramupmix_dec_sf( st_ivas, output_f_local );
     267             : 
     268      143760 :             for ( ch = 0; ch < min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ) ); ch++ )
     269             :             {
     270      134400 :                 output_f_local[ch] += n_samples_sf;
     271             :             }
     272             : 
     273             :             /* update combined orientation access index */
     274        9360 :             ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf );
     275             :         }
     276             :     }
     277             : 
     278        5420 :     *nSamplesAvailable = ( st_ivas->hTcBuffer->num_slots - st_ivas->hTcBuffer->slots_rendered ) * slot_size;
     279             : 
     280        5420 :     pop_wmops();
     281        5420 :     return;
     282             : }
     283             : 
     284             : 
     285             : /*-------------------------------------------------------------------------
     286             :  * ivas_mc_paramupmix_dec_open()
     287             :  *
     288             :  * Open Parametric MC decoder handle
     289             :  *-------------------------------------------------------------------------*/
     290             : 
     291          36 : 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          36 :     error = IVAS_ERR_OK;
     302             : 
     303             :     /*-----------------------------------------------------------------*
     304             :      * prepare library opening
     305             :      *-----------------------------------------------------------------*/
     306             : 
     307          36 :     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          36 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
     312          36 :     hMCParamUpmix->first_frame = 1;
     313          36 :     st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS;
     314          36 :     nchan_transport = st_ivas->nchan_transport;
     315             : 
     316          36 :     switch ( nchan_transport )
     317             :     {
     318          36 :         case 8:
     319          36 :             st_ivas->nCPE = 4;
     320          36 :             st_ivas->nSCE = 0;
     321          36 :             st_ivas->element_mode_init = IVAS_CPE_MDCT;
     322          36 :             break;
     323             : #ifdef DEBUGGING
     324             :         default:
     325             :             assert( 0 && "Number of TC not supported for MC ParamUpmix!" );
     326             : #endif
     327             :     }
     328             : 
     329          36 :     hMCParamUpmix->hoa_encoder = NULL;
     330             : 
     331             :     /*-----------------------------------------------------------------*
     332             :      * set input parameters
     333             :      *-----------------------------------------------------------------*/
     334             : 
     335          36 :     hMCParamUpmix->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f );
     336             : 
     337         180 :     for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     338             :     {
     339         144 :         ivas_td_decorr_dec_open( &( hMCParamUpmix->hTdDecorr[i] ), output_Fs, 2, 1 );
     340             :     }
     341             : 
     342         324 :     for ( i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++ )
     343             :     {
     344         288 :         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         288 :         set_zero( hMCParamUpmix->pcm_delay[i], NS2SA( output_Fs, IVAS_FB_DEC_DELAY_NS ) );
     349             :     }
     350             : 
     351             :     /* Head or external rotation */
     352          36 :     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 ) )
     353             :     {
     354           9 :         if ( ( hMCParamUpmix->hoa_encoder = (float *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( float ) ) ) == NULL )
     355             :         {
     356           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
     357             :         }
     358           9 :         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 );
     359             :     }
     360             : 
     361             :     /* allocate transport channels*/
     362          36 :     hMCParamUpmix->free_param_interpolator = 0;
     363          36 :     hMCParamUpmix->param_interpolator = NULL;
     364             : 
     365          36 :     if ( ( hMCParamUpmix->param_interpolator = (float *) malloc( MAX_JBM_CLDFB_TIMESLOTS * sizeof( float ) ) ) == NULL )
     366             :     {
     367           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for interpolator\n" ) );
     368             :     }
     369          36 :     hMCParamUpmix->free_param_interpolator = 1;
     370             : 
     371          36 :     ivas_jbm_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, DEFAULT_JBM_CLDFB_TIMESLOTS, hMCParamUpmix->param_interpolator );
     372             : 
     373          36 :     if ( st_ivas->hTcBuffer == NULL )
     374             :     {
     375             :         int16_t nchan_to_allocate;
     376             :         int16_t nchan_tc;
     377             :         int16_t granularity;
     378             :         TC_BUFFER_MODE buffer_mode;
     379             : 
     380          15 :         buffer_mode = TC_BUFFER_MODE_RENDERER;
     381          15 :         nchan_tc = ivas_jbm_dec_get_num_tc_channels( st_ivas );
     382          15 :         nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS;
     383             : 
     384          15 :         if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO )
     385             :         {
     386           0 :             buffer_mode = TC_BUFFER_MODE_BUFFER;
     387           0 :             nchan_tc = st_ivas->hDecoderConfig->nchan_out;
     388           0 :             nchan_to_allocate = nchan_tc;
     389             :         }
     390          15 :         else if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
     391             :         {
     392          12 :             nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS;
     393             :         }
     394             : 
     395          15 :         granularity = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, output_Fs );
     396             : 
     397          15 :         if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, granularity ) ) != IVAS_ERR_OK )
     398             :         {
     399           0 :             return error;
     400             :         }
     401             :     }
     402             : 
     403          36 :     st_ivas->hMCParamUpmix = hMCParamUpmix;
     404             : 
     405          36 :     return error;
     406             : }
     407             : 
     408             : 
     409             : /*-------------------------------------------------------------------------
     410             :  * ivas_mc_paramupmix_dec_close()
     411             :  *
     412             :  * Close ParamUpmix MC memories
     413             :  *------------------------------------------------------------------------*/
     414             : 
     415        2688 : void ivas_mc_paramupmix_dec_close(
     416             :     MC_PARAMUPMIX_DEC_HANDLE *hMCParamUpmix /* i/o: Parametric MC decoder handle   */
     417             : )
     418             : {
     419             :     int16_t i;
     420             : 
     421        2688 :     if ( hMCParamUpmix == NULL || *hMCParamUpmix == NULL )
     422             :     {
     423        2652 :         return;
     424             :     }
     425         180 :     for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     426             :     {
     427         144 :         ivas_td_decorr_dec_close( &( ( *hMCParamUpmix )->hTdDecorr[i] ) );
     428             :     }
     429         324 :     for ( i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++ )
     430             :     {
     431         288 :         if ( ( *hMCParamUpmix )->pcm_delay[i] != NULL )
     432             :         {
     433         288 :             free( ( *hMCParamUpmix )->pcm_delay[i] );
     434             :         }
     435             :     }
     436          36 :     if ( ( *hMCParamUpmix )->param_interpolator != NULL )
     437             :     {
     438          36 :         if ( ( *hMCParamUpmix )->free_param_interpolator == 1 )
     439             :         {
     440          36 :             free( ( *hMCParamUpmix )->param_interpolator );
     441             :         }
     442             :     }
     443          36 :     if ( ( *hMCParamUpmix )->hoa_encoder != NULL )
     444             :     {
     445           9 :         free( ( *hMCParamUpmix )->hoa_encoder );
     446           9 :         ( *hMCParamUpmix )->hoa_encoder = NULL;
     447             :     }
     448          36 :     free( *hMCParamUpmix );
     449             : 
     450          36 :     *hMCParamUpmix = NULL;
     451             : 
     452          36 :     return;
     453             : }
     454             : 
     455             : 
     456             : /*-------------------------------------------------------------------------
     457             :  * paramupmix_td_decorr_process_jbm()
     458             :  *
     459             :  *
     460             :  *------------------------------------------------------------------------*/
     461             : 
     462        2340 : static void paramupmix_td_decorr_process_jbm(
     463             :     ivas_td_decorr_state_t *hTdDecorr[], /* i/o: SPAR Covar. decoder handle   */
     464             :     float *pcm_in[],                     /* i  : input audio channels         */
     465             :     float **pp_out_pcm,                  /* o  : output audio channels        */
     466             :     const int16_t output_frame           /* i  : output frame length          */
     467             : )
     468             : {
     469             :     int16_t j, k;
     470             :     int16_t offset;
     471             :     float in_duck_gain[L_FRAME48k], out_duck_gain[L_FRAME48k];
     472             : 
     473        2340 :     offset = (int16_t) ( output_frame * FRAMES_PER_SEC * IVAS_DECORR_PARM_LOOKAHEAD_TAU );
     474             : 
     475             :     /* Look-ahead delay */
     476       11700 :     for ( k = 0; k < MC_PARAMUPMIX_COMBINATIONS; k++ )
     477             :     {
     478        9360 :         mvr2r( pcm_in[k], pp_out_pcm[k], output_frame );
     479        9360 :         delay_signal( pp_out_pcm[k], output_frame, hTdDecorr[k]->look_ahead_buf, offset );
     480             : 
     481             :         /* In ducking gains */
     482        9360 :         if ( hTdDecorr[k]->ducking_flag )
     483             :         {
     484        9360 :             ivas_td_decorr_get_ducking_gains( hTdDecorr[k]->pTrans_det, pcm_in[k], in_duck_gain, out_duck_gain, output_frame, 0 );
     485             : 
     486     7842960 :             for ( j = 0; j < output_frame; j++ )
     487             :             {
     488     7833600 :                 pp_out_pcm[k][j] = pp_out_pcm[k][j] * in_duck_gain[j];
     489             :             }
     490             :         }
     491             : 
     492             :         /* All pass delay section */
     493        9360 :         ivas_td_decorr_APD_iir_filter( &hTdDecorr[k]->APD_filt_state[0], pp_out_pcm[k], hTdDecorr[k]->num_apd_sections, output_frame );
     494             : 
     495             :         /* Out ducking gains */
     496        9360 :         if ( hTdDecorr[k]->ducking_flag )
     497             :         {
     498     7842960 :             for ( j = 0; j < output_frame; j++ )
     499             :             {
     500     7833600 :                 pp_out_pcm[k][j] = pp_out_pcm[k][j] * out_duck_gain[j];
     501             :             }
     502             :         }
     503             :     }
     504             : 
     505        2340 :     return;
     506             : }
     507             : 
     508             : 
     509             : /*-------------------------------------------------------------------------
     510             :  * ivas_param_upmix_dec_decorr_subframes()
     511             :  *
     512             :  *
     513             :  *------------------------------------------------------------------------*/
     514             : 
     515        2340 : static void ivas_param_upmix_dec_decorr_subframes(
     516             :     Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle    */
     517             :     const int16_t nSamplesForRendering )
     518             : {
     519             :     MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
     520             :     float *pPcm_tmp[MC_PARAMUPMIX_COMBINATIONS];
     521             :     float *p_tc[MC_PARAMUPMIX_COMBINATIONS];
     522             :     int16_t nchan_internal, ch;
     523             :     int16_t nSamplesLeftForTD, default_frame;
     524             : 
     525        2340 :     hMCParamUpmix = st_ivas->hMCParamUpmix;
     526        2340 :     assert( hMCParamUpmix );
     527             : 
     528        2340 :     push_wmops( "ivas_param_upmix_dec_decorr_subframes" );
     529             : 
     530             :     /* TD decorrelator */
     531        2340 :     default_frame = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC );
     532        2340 :     nSamplesLeftForTD = nSamplesForRendering;
     533        2340 :     nchan_internal = MC_PARAMUPMIX_COMBINATIONS;
     534             : 
     535       11700 :     for ( ch = 0; ch < nchan_internal; ch++ )
     536             :     {
     537        9360 :         pPcm_tmp[ch] = st_ivas->hTcBuffer->tc[ch + 8];
     538        9360 :         p_tc[ch] = st_ivas->hTcBuffer->tc[ch + 4];
     539             :     }
     540             : 
     541        4680 :     while ( nSamplesLeftForTD )
     542             :     {
     543        2340 :         int16_t nSamplesToDecorr = min( nSamplesLeftForTD, default_frame );
     544             : 
     545        2340 :         paramupmix_td_decorr_process_jbm( hMCParamUpmix->hTdDecorr, p_tc, pPcm_tmp, nSamplesToDecorr );
     546             : 
     547       11700 :         for ( ch = 0; ch < nchan_internal; ch++ )
     548             :         {
     549        9360 :             p_tc[ch] += nSamplesToDecorr;
     550             :         }
     551             : 
     552        2340 :         nSamplesLeftForTD -= nSamplesToDecorr;
     553             :     }
     554             : 
     555        2340 :     pop_wmops();
     556        2340 :     return;
     557             : }
     558             : 
     559             : 
     560             : /*****************************************************************************************/
     561             : /* local functions                                                                       */
     562             : /*****************************************************************************************/
     563             : 
     564       37440 : static void ps_pred_process_sf(
     565             :     MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix,
     566             :     DECODER_TC_BUFFER_HANDLE hTcBuffer,
     567             :     float qmf_mod_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* in/out */
     568             :     float qmf_mod_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
     569             :     float qmf_side_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* in/out */
     570             :     float qmf_side_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
     571             :     float *param_interpol,
     572             :     const int16_t ch,
     573             :     const int16_t slots_rendered )
     574             : {
     575             :     float vmre, vmim, vsre, vsim;
     576             :     int16_t iqmf, ipar, ismp, iismp;
     577             :     float alpha_smp, beta_smp;
     578             :     float *alpha1, *alpha2;
     579             :     float *beta1, *beta2;
     580       37440 :     float *alpha_prev = hMCParamUpmix->alpha_prev[ch];
     581       37440 :     float *beta_prev = hMCParamUpmix->beta_prev[ch];
     582       37440 :     float *alpha_sf = hMCParamUpmix->alpha_sf[ch];
     583       37440 :     float *beta_sf = hMCParamUpmix->beta_sf[ch];
     584             :     float dalpha, dbeta, ifac;
     585             :     float alpha_start[IVAS_MAX_NUM_BANDS], beta_start[IVAS_MAX_NUM_BANDS];
     586             : 
     587       37440 :     const int16_t qmf_to_par_band[] = {
     588             :         0, 1, 2, 3, 4, 5, 5, 6, 6, 7,
     589             :         7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
     590             :         9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
     591             :         10, 10, 11, 11, 11, 11, 11, 11, 11, 11,
     592             :         11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
     593             :         11, 11, 11, 11, 11, 11, 11, 11, 11, 11
     594             :     };
     595             : 
     596       37440 :     mvr2r( alpha_sf, alpha_start, IVAS_MAX_NUM_BANDS );
     597       37440 :     mvr2r( beta_sf, beta_start, IVAS_MAX_NUM_BANDS );
     598     2283840 :     for ( iqmf = 0; iqmf < CLDFB_NO_CHANNELS_MAX; iqmf++ )
     599             :     {
     600     2246400 :         ipar = qmf_to_par_band[iqmf];
     601     2246400 :         alpha1 = alpha_prev;
     602     2246400 :         beta1 = beta_prev;
     603             : 
     604     2246400 :         ismp = 0;
     605     2246400 :         alpha2 = hMCParamUpmix->alphas[ch];
     606     2246400 :         beta2 = hMCParamUpmix->betas[ch];
     607     2246400 :         alpha_smp = alpha_start[ipar];
     608     2246400 :         beta_smp = beta_start[ipar];
     609             : 
     610    11232000 :         for ( iismp = 0; iismp < hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered]; iismp++ )
     611             :         {
     612     8985600 :             if ( ( slots_rendered == 0 ) && ( iismp == 0 ) )
     613             :             {
     614      561600 :                 ifac = param_interpol[iismp];
     615             :             }
     616             :             else
     617             :             {
     618     8424000 :                 ifac = param_interpol[iismp] - param_interpol[iismp - 1];
     619             :             }
     620     8985600 :             dalpha = ( alpha2[ipar] - alpha1[ipar] ) * ifac;
     621     8985600 :             dbeta = ( beta2[ipar] - beta1[ipar] ) * ifac;
     622             : 
     623     8985600 :             alpha_smp += dalpha;
     624     8985600 :             beta_smp += dbeta;
     625             : 
     626     8985600 :             vmre = qmf_mod_re[ismp][iqmf];
     627     8985600 :             vmim = qmf_mod_im[ismp][iqmf];
     628     8985600 :             vsre = qmf_side_re[ismp][iqmf];
     629     8985600 :             vsim = qmf_side_im[ismp][iqmf];
     630             : 
     631     8985600 :             qmf_side_re[ismp][iqmf] = alpha_smp * vmre + beta_smp * vsre;
     632     8985600 :             qmf_side_im[ismp][iqmf] = alpha_smp * vmim + beta_smp * vsim;
     633             : 
     634     8985600 :             ismp++;
     635             :         }
     636     2246400 :         alpha_sf[ipar] = alpha_smp;
     637     2246400 :         beta_sf[ipar] = beta_smp;
     638             :     }
     639             : 
     640       37440 :     return;
     641             : }
     642             : 
     643        9360 : static void ivas_mc_paramupmix_dec_sf(
     644             :     Decoder_Struct *st_ivas,             /* i/o: IVAS decoder handle                        */
     645             :     float *output_f[MAX_OUTPUT_CHANNELS] /* i/o: synthesized core-coder transport channels  */
     646             : )
     647             : {
     648             :     int16_t i, ch, slot_idx, k;
     649             :     float *pPcm_temp[MC_PARAMUPMIX_COMBINATIONS * 2]; /* decorrelated and undecorrelated*/
     650             :     /*CLDFB*/
     651             :     float Cldfb_RealBuffer[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
     652             :     float Cldfb_ImagBuffer[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
     653             :     int16_t noparamupmix_delay, n_samples_rendered;
     654             :     MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
     655             :     int16_t subframeIdx, idx_in, maxBand;
     656             :     float Cldfb_RealBuffer_subfr[MAX_INTERN_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
     657             :     float Cldfb_ImagBuffer_subfr[MAX_INTERN_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
     658             :     float Cldfb_RealBuffer_Binaural[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
     659             :     float Cldfb_ImagBuffer_Binaural[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
     660             :     int16_t slot_index_start;
     661             : 
     662        9360 :     hMCParamUpmix = st_ivas->hMCParamUpmix;
     663        9360 :     assert( hMCParamUpmix );
     664        9360 :     push_wmops( "ivas_mc_paramupmix_dec_sf" );
     665             : 
     666        9360 :     slot_index_start = st_ivas->hTcBuffer->slots_rendered;
     667       46800 :     for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     668             :     {
     669       37440 :         pPcm_temp[2 * i] = output_f[i + 4];     /* un-decorrelated */
     670       37440 :         pPcm_temp[2 * i + 1] = output_f[i + 8]; /* decorrelated */
     671             :     }
     672             : 
     673             :     /* CLDFB Analysis*/
     674       84240 :     for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ )
     675             :     {
     676             :         /* slot loop for gathering the input data */
     677      374400 :         for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     678             :         {
     679      299520 :             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] );
     680             :         }
     681             :     }
     682       46800 :     for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
     683             :     {
     684       37440 :         ps_pred_process_sf( hMCParamUpmix,
     685             :                             st_ivas->hTcBuffer,
     686       37440 :                             Cldfb_RealBuffer[2 * ch], /* in/out */
     687       37440 :                             Cldfb_ImagBuffer[2 * ch],
     688       37440 :                             Cldfb_RealBuffer[2 * ch + 1], /* in/out decorr */
     689       37440 :                             Cldfb_ImagBuffer[2 * ch + 1],
     690       37440 :                             &hMCParamUpmix->param_interpolator[st_ivas->hTcBuffer->slots_rendered],
     691             :                             ch,
     692       37440 :                             st_ivas->hTcBuffer->slots_rendered );
     693             : 
     694             :         /*-- m, s -> l, r ----------------------------*/
     695      187200 :         for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     696             :         {
     697     9135360 :             for ( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ )
     698             :             {
     699     8985600 :                 float qlre = Cldfb_RealBuffer[2 * ch][slot_idx][k];
     700     8985600 :                 float qlim = Cldfb_ImagBuffer[2 * ch][slot_idx][k];
     701     8985600 :                 float qrre = Cldfb_RealBuffer[2 * ch + 1][slot_idx][k];
     702     8985600 :                 float qrim = Cldfb_ImagBuffer[2 * ch + 1][slot_idx][k];
     703             : 
     704     8985600 :                 Cldfb_RealBuffer[2 * ch][slot_idx][k] = qlre + qrre;
     705     8985600 :                 Cldfb_ImagBuffer[2 * ch][slot_idx][k] = qlim + qrim;
     706     8985600 :                 Cldfb_RealBuffer[2 * ch + 1][slot_idx][k] = qlre - qrre;
     707     8985600 :                 Cldfb_ImagBuffer[2 * ch + 1][slot_idx][k] = qlim - qrim;
     708             :             }
     709             :         }
     710             :     }
     711             : 
     712        9360 :     if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM )
     713             :     {
     714        7320 :         maxBand = (int16_t) ( ( CLDFB_NO_CHANNELS_MAX * st_ivas->hDecoderConfig->output_Fs ) / 48000 );
     715        7320 :         subframeIdx = st_ivas->hTcBuffer->subframes_rendered;
     716             :         /* fastconv binaural rendering and CLDFB synthesis */
     717             :         /* cldfb analysis of non-coupled, non-LFE channels */
     718        7320 :         idx_in = 0;
     719       36600 :         for ( ch = 0; ch < MC_PARAMUPMIX_MAX_INPUT_CHANS - 2 * MC_PARAMUPMIX_COMBINATIONS; ch++ )
     720             :         {
     721       29280 :             if ( st_ivas->hIntSetup.index_lfe[0] != ch )
     722             :             {
     723       27360 :                 pPcm_temp[ch] = output_f[ch];
     724             :                 /* slot loop for gathering the input data */
     725      136800 :                 for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     726             :                 {
     727      109440 :                     cldfbAnalysis_ts( &( pPcm_temp[ch][hMCParamUpmix->num_freq_bands * slot_idx] ),
     728      109440 :                                       Cldfb_RealBuffer_subfr[idx_in][slot_idx],
     729      109440 :                                       Cldfb_ImagBuffer_subfr[idx_in][slot_idx],
     730      109440 :                                       maxBand, st_ivas->cldfbAnaDec[2 * MC_PARAMUPMIX_COMBINATIONS + idx_in] );
     731             :                 }
     732       27360 :                 idx_in++;
     733             :             }
     734             :         }
     735             : 
     736             :         /* copy and reorder cldfb analysis of coupled channels */
     737       36600 :         for ( ch = 0; ch < MAX_PARAM_SPATIAL_SUBFRAMES; ch++ )
     738             :         {
     739      146400 :             for ( slot_idx = 0; slot_idx < MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ )
     740             :             {
     741      117120 :                 mvr2r( Cldfb_RealBuffer[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_RealBuffer_subfr[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX );
     742      117120 :                 mvr2r( Cldfb_ImagBuffer[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_ImagBuffer_subfr[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX );
     743      117120 :                 mvr2r( Cldfb_RealBuffer[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_RealBuffer_subfr[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX );
     744      117120 :                 mvr2r( Cldfb_ImagBuffer[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_ImagBuffer_subfr[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX );
     745             :             }
     746       29280 :             idx_in += 2;
     747             :         }
     748             : 
     749        7320 :         if ( st_ivas->hCombinedOrientationData && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
     750             :         {
     751       27000 :             for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     752             :             {
     753       21600 :                 ivas_param_mc_mc2sba_cldfb( st_ivas->hTransSetup, hMCParamUpmix->hoa_encoder, slot_idx, Cldfb_RealBuffer_subfr, Cldfb_ImagBuffer_subfr, maxBand, GAIN_LFE );
     754             :             }
     755             :         }
     756             : 
     757             :         /*LFE handling for split rendering cases*/
     758        7320 :         if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     759             :         {
     760           0 :             if ( st_ivas->hSplitBinRend->hCldfbDataOut != NULL )
     761             :             {
     762           0 :                 for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     763             :                 {
     764           0 :                     for ( ch = 0; ch < ( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ); ch++ )
     765             :                     {
     766           0 :                         mvr2r( Cldfb_RealBuffer_subfr[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_RealBuffer[ch][slot_index_start + slot_idx], maxBand );
     767           0 :                         mvr2r( Cldfb_ImagBuffer_subfr[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_ImagBuffer[ch][slot_index_start + slot_idx], maxBand );
     768             :                     }
     769             :                 }
     770             : 
     771           0 :                 st_ivas->hSplitBinRend->hCldfbDataOut->config = st_ivas->hIntSetup.output_config;
     772             :             }
     773             :         }
     774             : 
     775             :         /* Implement binaural rendering */
     776        7320 :         ivas_binRenderer( st_ivas->hBinRenderer,
     777           0 :                           ( st_ivas->hSplitBinRend == NULL ) ? NULL : &st_ivas->hSplitBinRend->splitrend.multiBinPoseData,
     778             :                           st_ivas->hCombinedOrientationData,
     779        7320 :                           st_ivas->hTcBuffer->subframe_nbslots[subframeIdx],
     780             :                           Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural,
     781             :                           Cldfb_RealBuffer_subfr,
     782             :                           Cldfb_ImagBuffer_subfr );
     783             : 
     784        7320 :         if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     785             :         {
     786             :             int16_t pos_idx;
     787           0 :             for ( pos_idx = 0; pos_idx < st_ivas->hBinRenderer->numPoses; pos_idx++ )
     788             :             {
     789           0 :                 for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[subframeIdx]; slot_idx++ )
     790             :                 {
     791           0 :                     for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
     792             :                     {
     793           0 :                         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 );
     794           0 :                         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 );
     795             :                     }
     796             :                 }
     797             :             }
     798             :         }
     799             : 
     800             :         /* Implement CLDFB synthesis */
     801       21960 :         for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
     802             :         {
     803             :             float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES];
     804             :             float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES];
     805             : 
     806       73200 :             for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[subframeIdx]; slot_idx++ )
     807             :             {
     808       58560 :                 RealBuffer[slot_idx] = Cldfb_RealBuffer_Binaural[0][ch][slot_idx];
     809       58560 :                 ImagBuffer[slot_idx] = Cldfb_ImagBuffer_Binaural[0][ch][slot_idx];
     810             :             }
     811             : 
     812       14640 :             cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][0] ), maxBand * st_ivas->hTcBuffer->subframe_nbslots[subframeIdx], st_ivas->cldfbSynDec[ch] );
     813             :         }
     814             :     }
     815             :     else
     816             :     {
     817             :         /*  boxes = { 0 1 2 3 [4 6] [5 7] [8 10] [9 11] }; */
     818        2040 :         pPcm_temp[0] = output_f[4];
     819        2040 :         pPcm_temp[1] = output_f[6];
     820        2040 :         pPcm_temp[2] = output_f[5];
     821        2040 :         pPcm_temp[3] = output_f[7];
     822        2040 :         pPcm_temp[4] = output_f[8];
     823        2040 :         pPcm_temp[5] = output_f[10];
     824        2040 :         pPcm_temp[6] = output_f[9];
     825        2040 :         pPcm_temp[7] = output_f[11];
     826             : 
     827             :         /* CLDFB synthesis */
     828       18360 :         for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ )
     829             :         {
     830       81600 :             for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     831             :             {
     832             :                 float *ptr_im[1], *ptr_re[1];
     833       65280 :                 ptr_re[0] = Cldfb_RealBuffer[ch][slot_idx];
     834       65280 :                 ptr_im[0] = Cldfb_ImagBuffer[ch][slot_idx];
     835             : 
     836       65280 :                 cldfbSynthesis( ptr_re, ptr_im, &( pPcm_temp[ch][hMCParamUpmix->num_freq_bands * slot_idx] ),
     837       65280 :                                 hMCParamUpmix->num_freq_bands, st_ivas->cldfbSynDec[ch] );
     838             :             }
     839             :         }
     840             :         /* adjust delay of other channels */
     841        2040 :         noparamupmix_delay = NS2SA( st_ivas->hDecoderConfig->output_Fs, IVAS_FB_DEC_DELAY_NS );
     842        2040 :         n_samples_rendered = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered] * hMCParamUpmix->num_freq_bands;
     843        2040 :         if ( n_samples_rendered > noparamupmix_delay )
     844             :         {
     845           0 :             for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
     846             :             {
     847             :                 float tmp_buf[L_SUBFRAME5MS_48k];
     848           0 :                 mvr2r( &output_f[ch][n_samples_rendered - noparamupmix_delay], tmp_buf, noparamupmix_delay );
     849           0 :                 mvr2r( output_f[ch], &output_f[ch][noparamupmix_delay], n_samples_rendered - noparamupmix_delay );
     850           0 :                 mvr2r( hMCParamUpmix->pcm_delay[ch], output_f[ch], noparamupmix_delay );
     851           0 :                 mvr2r( tmp_buf, hMCParamUpmix->pcm_delay[ch], noparamupmix_delay );
     852             :             }
     853             :         }
     854             :         else
     855             :         {
     856       10200 :             for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
     857             :             {
     858             :                 float tmp_buf[L_SUBFRAME5MS_48k];
     859        8160 :                 mvr2r( &output_f[ch][0], tmp_buf, n_samples_rendered );
     860        8160 :                 mvr2r( hMCParamUpmix->pcm_delay[ch], output_f[ch], n_samples_rendered );
     861        8160 :                 mvr2r( &hMCParamUpmix->pcm_delay[ch][n_samples_rendered], &hMCParamUpmix->pcm_delay[ch][0], noparamupmix_delay - n_samples_rendered );
     862        8160 :                 mvr2r( tmp_buf, &hMCParamUpmix->pcm_delay[ch][noparamupmix_delay - n_samples_rendered], n_samples_rendered );
     863             :             }
     864             :         }
     865             :     }
     866             : 
     867        9360 :     st_ivas->hTcBuffer->slots_rendered += st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered];
     868        9360 :     st_ivas->hTcBuffer->subframes_rendered++;
     869             : 
     870        9360 :     pop_wmops();
     871        9360 :     return;
     872             : }
     873             : 
     874             : 
     875      227520 : static int16_t huff_read(
     876             :     Decoder_State *st,
     877             :     const int16_t ( *ht )[2] )
     878             : {
     879      227520 :     int16_t node = 0;
     880      227520 :     uint16_t next_bit = 0;
     881             : 
     882             :     do
     883             :     {
     884      478389 :         next_bit = st->bit_stream[st->next_bit_pos];
     885      478389 :         st->next_bit_pos++;
     886      478389 :         node = ht[node][next_bit];
     887      478389 :     } while ( node > 0 );
     888             : 
     889      227520 :     return -( node + 1 );
     890             : }
     891             : 
     892             : 
     893       18960 : static void huffman_decode(
     894             :     Decoder_State *st,
     895             :     const PAR_TYPE parType,
     896             :     int32_t *vq )
     897             : {
     898             :     const int16_t( *huff_node_table )[2];
     899             :     int16_t iv, nquant, offset;
     900             : 
     901       18960 :     nquant = 0;
     902       18960 :     switch ( parType )
     903             :     {
     904        9480 :         case ALPHA:
     905        9480 :             nquant = ivas_mc_paramupmix_alpha_quant_table.nquant;
     906        9480 :             break;
     907        9480 :         case BETA:
     908        9480 :             nquant = ivas_mc_paramupmix_beta_quant_table[0].nquant;
     909        9480 :             break;
     910           0 :         default:
     911           0 :             assert( 0 );
     912             :     }
     913             : 
     914       18960 :     offset = nquant - 1; /* range of df [-(nquant - 1), nquant - 1] */
     915             : 
     916       18960 :     st->next_bit_pos++;
     917       18960 :     switch ( parType )
     918             :     {
     919        9480 :         case ALPHA:
     920        9480 :             huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.alpha;
     921        9480 :             break;
     922        9480 :         case BETA:
     923        9480 :             huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.beta;
     924        9480 :             break;
     925           0 :         default:
     926           0 :             huff_node_table = NULL;
     927           0 :             assert( 0 );
     928             :     }
     929       18960 :     vq[0] = huff_read( st, huff_node_table );
     930             : 
     931       18960 :     switch ( parType )
     932             :     {
     933        9480 :         case ALPHA:
     934        9480 :             huff_node_table = ivas_mc_paramupmix_huff_nodes_df.alpha;
     935        9480 :             break;
     936        9480 :         case BETA:
     937        9480 :             huff_node_table = ivas_mc_paramupmix_huff_nodes_df.beta;
     938        9480 :             break;
     939           0 :         default:
     940           0 :             assert( 0 );
     941             :     }
     942             : 
     943      227520 :     for ( iv = 1; iv < IVAS_MAX_NUM_BANDS; iv++ )
     944             :     {
     945      208560 :         vq[iv] = huff_read( st, huff_node_table ) + vq[iv - 1] - offset;
     946             :     }
     947             : 
     948       18960 :     return;
     949             : }
     950             : 
     951             : 
     952        9480 : static void dequant_alpha(
     953             :     int32_t *vq,
     954             :     float *v )
     955             : {
     956             :     int16_t iv;
     957        9480 :     const ACPL_QUANT_TABLE *quant_table = &ivas_mc_paramupmix_alpha_quant_table;
     958             : 
     959      123240 :     for ( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ )
     960             :     {
     961      113760 :         v[iv] = quant_table->data[vq[iv]];
     962             :     }
     963             : 
     964        9480 :     return;
     965             : }
     966             : 
     967             : 
     968        9480 : static void dequant_beta(
     969             :     int32_t *aq,
     970             :     int32_t *bq,
     971             :     float *beta )
     972             : {
     973             :     int16_t iv;
     974             :     const ACPL_QUANT_TABLE *quant_table;
     975             : 
     976      123240 :     for ( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ )
     977             :     {
     978      113760 :         quant_table = &ivas_mc_paramupmix_beta_quant_table[ivas_param_upmx_mx_qmap[aq[iv]]];
     979      113760 :         beta[iv] = quant_table->data[bq[iv]];
     980             :     }
     981             : 
     982        9480 :     return;
     983             : }
     984             : 
     985             : 
     986       18960 : static void get_ec_data(
     987             :     Decoder_State *st,
     988             :     const PAR_TYPE parType,
     989             :     int32_t *parQ,
     990             :     int32_t *alphaQEnv,
     991             :     float ab[IVAS_MAX_NUM_BANDS] )
     992             : {
     993       18960 :     huffman_decode( st, parType, parQ );
     994             : 
     995       18960 :     if ( parType == ALPHA )
     996             :     {
     997        9480 :         dequant_alpha( parQ, ab );
     998        9480 :         mvl2l( parQ, alphaQEnv, (int16_t) IVAS_MAX_NUM_BANDS );
     999             :     }
    1000             :     else
    1001             :     {
    1002        9480 :         dequant_beta( alphaQEnv, parQ, ab );
    1003             :     }
    1004             : 
    1005       18960 :     return;
    1006             : }

Generated by: LCOV version 1.14