LCOV - code coverage report
Current view: top level - lib_dec - ivas_mc_paramupmix_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main @ fec202a8f89be4a2f278a9fc377bfb58b58fab11 Lines: 345 375 92.0 %
Date: 2025-09-14 08:49:17 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       44076 : 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       44076 :     push_wmops( "mc_paramupmix_read_bs" );
     104       44076 :     *nb_bits = 0;
     105             : 
     106       44076 :     if ( st0->bfi )
     107             :     {
     108        2810 :         for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     109             :         {
     110       29224 :             for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ )
     111             :             {
     112       26976 :                 hMCParamUpmix->alphas[i][k] = hMCParamUpmix->alpha_prev[i][k];
     113       26976 :                 hMCParamUpmix->betas[i][k] = hMCParamUpmix->beta_prev[i][k];
     114             :             }
     115             :         }
     116             : 
     117        2810 :         for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     118             :         {
     119        2248 :             mvr2r( hMCParamUpmix->alpha_prev[i], hMCParamUpmix->alpha_sf[i], IVAS_MAX_NUM_BANDS );
     120        2248 :             mvr2r( hMCParamUpmix->beta_prev[i], hMCParamUpmix->beta_sf[i], IVAS_MAX_NUM_BANDS );
     121             :         }
     122             : 
     123         562 :         hMCParamUpmix->first_frame = 1;
     124             :     }
     125             :     else /*  if (!st->bfi) */
     126             :     {
     127       43514 :         bit_stream_orig = st0->bit_stream;
     128       43514 :         next_bit_pos_orig = st0->next_bit_pos;
     129       43514 :         last_bit_pos = (int16_t) ( ( st_ivas->hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC ) - 1 );
     130       43514 :         nb_bits_read_orig = 0;
     131       43514 :         last_bit_pos -= nb_bits_read_orig; /* reverse the bitstream for easier reading of indices */
     132   108828514 :         for ( i = 0; i < min( MAX_BITS_METADATA, last_bit_pos ); i++ )
     133             :         {
     134   108785000 :             bstr_meta[i] = st_ivas->bit_stream[last_bit_pos - i];
     135             :         }
     136       43514 :         st0->bit_stream = bstr_meta;
     137       43514 :         st0->next_bit_pos = 0;
     138       43514 :         st0->bits_frame = min( MAX_BITS_METADATA, last_bit_pos + 1 );
     139       43514 :         st0->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* to avoid BER detect */
     140             : 
     141       43514 :         if ( hMCParamUpmix->first_frame == 0 )
     142             :         {
     143      212530 :             for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     144             :             {
     145      170024 :                 mvr2r( hMCParamUpmix->alphas[i], hMCParamUpmix->alpha_prev[i], IVAS_MAX_NUM_BANDS );
     146      170024 :                 mvr2r( hMCParamUpmix->betas[i], hMCParamUpmix->beta_prev[i], IVAS_MAX_NUM_BANDS );
     147             :             }
     148             :         }
     149             : 
     150      217570 :         for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     151             :         {
     152      174056 :             get_ec_data( st0, ALPHA, hMCParamUpmix->alpha_quant[i], alpha_quant, hMCParamUpmix->alphas[i] );
     153             : 
     154      174056 :             get_ec_data( st0, BETA, hMCParamUpmix->beta_quant[i], alpha_quant, hMCParamUpmix->betas[i] );
     155             :         }
     156       43514 :         *nb_bits += st0->next_bit_pos;
     157       43514 :         st0->bit_stream = bit_stream_orig;
     158       43514 :         st0->next_bit_pos = next_bit_pos_orig;
     159             : 
     160       43514 :         if ( hMCParamUpmix->first_frame )
     161             :         {
     162        5040 :             for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     163             :             {
     164        4032 :                 mvr2r( hMCParamUpmix->alphas[i], hMCParamUpmix->alpha_prev[i], IVAS_MAX_NUM_BANDS );
     165        4032 :                 mvr2r( hMCParamUpmix->betas[i], hMCParamUpmix->beta_prev[i], IVAS_MAX_NUM_BANDS );
     166             :             }
     167        1008 :             hMCParamUpmix->first_frame = 0;
     168             :         }
     169             : 
     170      217570 :         for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     171             :         {
     172      174056 :             mvr2r( hMCParamUpmix->alpha_prev[i], hMCParamUpmix->alpha_sf[i], IVAS_MAX_NUM_BANDS );
     173      174056 :             mvr2r( hMCParamUpmix->beta_prev[i], hMCParamUpmix->beta_sf[i], IVAS_MAX_NUM_BANDS );
     174             :         }
     175             :     }
     176             : 
     177       44076 :     pop_wmops();
     178       44076 :     return;
     179             : }
     180             : 
     181             : 
     182             : /*-------------------------------------------------------------------------
     183             :  * ivas_mc_paramupmix_dec_digest_tc()
     184             :  *
     185             :  *
     186             :  *------------------------------------------------------------------------*/
     187             : 
     188       42252 : 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       42252 :     hMCParamUpmix = st_ivas->hMCParamUpmix;
     196       42252 :     assert( hMCParamUpmix );
     197       42252 :     push_wmops( "ivas_mc_paramupmix_dec_digest_tc" );
     198             : 
     199       42252 :     ivas_param_upmix_dec_decorr_subframes( st_ivas, nSamplesForRendering );
     200             : 
     201             :     /* adapt subframes */
     202       42252 :     ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
     203             : 
     204       42252 :     ivas_jbm_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hMCParamUpmix->param_interpolator );
     205             : 
     206       42252 :     pop_wmops();
     207       42252 :     return;
     208             : }
     209             : 
     210             : 
     211             : /*-------------------------------------------------------------------------
     212             :  * ivas_mc_paramupmix_dec_render()
     213             :  *
     214             :  *
     215             :  *------------------------------------------------------------------------*/
     216             : 
     217       46093 : 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       46093 :     hMCParamUpmix = st_ivas->hMCParamUpmix;
     232       46093 :     assert( hMCParamUpmix );
     233             : 
     234       46093 :     push_wmops( "ivas_mc_paramupmix_dec_render" );
     235             : 
     236      783581 :     for ( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ )
     237             :     {
     238      737488 :         output_f_local[ch] = output_f[ch];
     239             :     }
     240             : 
     241       46093 :     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       46093 :     slots_to_render = min( st_ivas->hTcBuffer->num_slots - st_ivas->hTcBuffer->slots_rendered, nSamplesAsked / slot_size );
     245       46093 :     *nSamplesRendered = slots_to_render * slot_size;
     246       46093 :     first_sf = st_ivas->hTcBuffer->subframes_rendered;
     247       46093 :     last_sf = first_sf;
     248             : 
     249      599209 :     for ( ch = 0; ch < MAX_TRANSPORT_CHANNELS; ch++ )
     250             :     {
     251      553116 :         mvr2r( input_f[ch], output_f_local[ch], *nSamplesRendered );
     252             :     }
     253             : 
     254      215862 :     while ( slots_to_render > 0 )
     255             :     {
     256      169769 :         slots_to_render -= st_ivas->hTcBuffer->subframe_nbslots[last_sf];
     257      169769 :         last_sf++;
     258             :     }
     259             : #ifdef DEBUGGING
     260             :     assert( slots_to_render == 0 );
     261             : #endif
     262             :     {
     263      215862 :         for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
     264             :         {
     265      169769 :             int16_t n_samples_sf = slot_size * st_ivas->hTcBuffer->subframe_nbslots[subframe_idx];
     266      169769 :             ivas_mc_paramupmix_dec_sf( st_ivas, output_f_local );
     267             : 
     268     2523625 :             for ( ch = 0; ch < min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ) ); ch++ )
     269             :             {
     270     2353856 :                 output_f_local[ch] += n_samples_sf;
     271             :             }
     272             : 
     273             :             /* update combined orientation access index */
     274      169769 :             ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf );
     275             :         }
     276             :     }
     277             : 
     278       46093 :     *nSamplesAvailable = ( st_ivas->hTcBuffer->num_slots - st_ivas->hTcBuffer->slots_rendered ) * slot_size;
     279             : 
     280       46093 :     pop_wmops();
     281       46093 :     return;
     282             : }
     283             : 
     284             : 
     285             : /*-------------------------------------------------------------------------
     286             :  * ivas_mc_paramupmix_dec_open()
     287             :  *
     288             :  * Open Parametric MC decoder handle
     289             :  *-------------------------------------------------------------------------*/
     290             : 
     291         784 : 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         784 :     error = IVAS_ERR_OK;
     302             : 
     303             :     /*-----------------------------------------------------------------*
     304             :      * prepare library opening
     305             :      *-----------------------------------------------------------------*/
     306             : 
     307         784 :     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         784 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
     312         784 :     hMCParamUpmix->first_frame = 1;
     313         784 :     st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS;
     314         784 :     nchan_transport = st_ivas->nchan_transport;
     315             : 
     316         784 :     switch ( nchan_transport )
     317             :     {
     318         784 :         case 8:
     319         784 :             st_ivas->nCPE = 4;
     320         784 :             st_ivas->nSCE = 0;
     321         784 :             st_ivas->element_mode_init = IVAS_CPE_MDCT;
     322         784 :             break;
     323             : #ifdef DEBUGGING
     324             :         default:
     325             :             assert( 0 && "Number of TC not supported for MC ParamUpmix!" );
     326             : #endif
     327             :     }
     328             : 
     329         784 :     hMCParamUpmix->hoa_encoder = NULL;
     330             : 
     331             :     /*-----------------------------------------------------------------*
     332             :      * set input parameters
     333             :      *-----------------------------------------------------------------*/
     334             : 
     335         784 :     hMCParamUpmix->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f );
     336             : 
     337        3920 :     for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     338             :     {
     339        3136 :         ivas_td_decorr_dec_open( &( hMCParamUpmix->hTdDecorr[i] ), output_Fs, 2, 1 );
     340             :     }
     341             : 
     342        7056 :     for ( i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++ )
     343             :     {
     344        6272 :         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        6272 :         set_zero( hMCParamUpmix->pcm_delay[i], NS2SA( output_Fs, IVAS_FB_DEC_DELAY_NS ) );
     349             :     }
     350             : 
     351             :     /* Head or external rotation */
     352         784 :     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          86 :         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          86 :         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         784 :     hMCParamUpmix->free_param_interpolator = 0;
     363         784 :     hMCParamUpmix->param_interpolator = NULL;
     364             : 
     365         784 :     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         784 :     hMCParamUpmix->free_param_interpolator = 1;
     370             : 
     371         784 :     ivas_jbm_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, DEFAULT_JBM_CLDFB_TIMESLOTS, hMCParamUpmix->param_interpolator );
     372             : 
     373         784 :     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         114 :         buffer_mode = TC_BUFFER_MODE_RENDERER;
     381         114 :         nchan_tc = ivas_jbm_dec_get_num_tc_channels( st_ivas );
     382         114 :         nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS;
     383             : 
     384         114 :         if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO )
     385             :         {
     386          14 :             buffer_mode = TC_BUFFER_MODE_BUFFER;
     387          14 :             nchan_tc = st_ivas->hDecoderConfig->nchan_out;
     388          14 :             nchan_to_allocate = nchan_tc;
     389             :         }
     390         100 :         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          42 :             nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS;
     393             :         }
     394             : 
     395         114 :         granularity = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, output_Fs );
     396             : 
     397         114 :         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         784 :     st_ivas->hMCParamUpmix = hMCParamUpmix;
     404             : 
     405         784 :     return error;
     406             : }
     407             : 
     408             : 
     409             : /*-------------------------------------------------------------------------
     410             :  * ivas_mc_paramupmix_dec_close()
     411             :  *
     412             :  * Close ParamUpmix MC memories
     413             :  *------------------------------------------------------------------------*/
     414             : 
     415       92492 : 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       92492 :     if ( hMCParamUpmix == NULL || *hMCParamUpmix == NULL )
     422             :     {
     423       91708 :         return;
     424             :     }
     425        3920 :     for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     426             :     {
     427        3136 :         ivas_td_decorr_dec_close( &( ( *hMCParamUpmix )->hTdDecorr[i] ) );
     428             :     }
     429        7056 :     for ( i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++ )
     430             :     {
     431        6272 :         if ( ( *hMCParamUpmix )->pcm_delay[i] != NULL )
     432             :         {
     433        6272 :             free( ( *hMCParamUpmix )->pcm_delay[i] );
     434             :         }
     435             :     }
     436         784 :     if ( ( *hMCParamUpmix )->param_interpolator != NULL )
     437             :     {
     438         784 :         if ( ( *hMCParamUpmix )->free_param_interpolator == 1 )
     439             :         {
     440         784 :             free( ( *hMCParamUpmix )->param_interpolator );
     441             :         }
     442             :     }
     443         784 :     if ( ( *hMCParamUpmix )->hoa_encoder != NULL )
     444             :     {
     445          86 :         free( ( *hMCParamUpmix )->hoa_encoder );
     446          86 :         ( *hMCParamUpmix )->hoa_encoder = NULL;
     447             :     }
     448         784 :     free( *hMCParamUpmix );
     449             : 
     450         784 :     *hMCParamUpmix = NULL;
     451             : 
     452         784 :     return;
     453             : }
     454             : 
     455             : 
     456             : /*-------------------------------------------------------------------------
     457             :  * paramupmix_td_decorr_process_jbm()
     458             :  *
     459             :  *
     460             :  *------------------------------------------------------------------------*/
     461             : 
     462       42252 : 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       42252 :     offset = (int16_t) ( output_frame * FRAMES_PER_SEC * IVAS_DECORR_PARM_LOOKAHEAD_TAU );
     474             : 
     475             :     /* Look-ahead delay */
     476      211260 :     for ( k = 0; k < MC_PARAMUPMIX_COMBINATIONS; k++ )
     477             :     {
     478      169008 :         mvr2r( pcm_in[k], pp_out_pcm[k], output_frame );
     479      169008 :         delay_signal( pp_out_pcm[k], output_frame, hTdDecorr[k]->look_ahead_buf, offset );
     480             : 
     481             :         /* In ducking gains */
     482      169008 :         if ( hTdDecorr[k]->ducking_flag )
     483             :         {
     484      169008 :             ivas_td_decorr_get_ducking_gains( hTdDecorr[k]->pTrans_det, pcm_in[k], in_duck_gain, out_duck_gain, output_frame, 0 );
     485             : 
     486   135203888 :             for ( j = 0; j < output_frame; j++ )
     487             :             {
     488   135034880 :                 pp_out_pcm[k][j] = pp_out_pcm[k][j] * in_duck_gain[j];
     489             :             }
     490             :         }
     491             : 
     492             :         /* All pass delay section */
     493      169008 :         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      169008 :         if ( hTdDecorr[k]->ducking_flag )
     497             :         {
     498   135203888 :             for ( j = 0; j < output_frame; j++ )
     499             :             {
     500   135034880 :                 pp_out_pcm[k][j] = pp_out_pcm[k][j] * out_duck_gain[j];
     501             :             }
     502             :         }
     503             :     }
     504             : 
     505       42252 :     return;
     506             : }
     507             : 
     508             : 
     509             : /*-------------------------------------------------------------------------
     510             :  * ivas_param_upmix_dec_decorr_subframes()
     511             :  *
     512             :  *
     513             :  *------------------------------------------------------------------------*/
     514             : 
     515       42252 : 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       42252 :     hMCParamUpmix = st_ivas->hMCParamUpmix;
     526       42252 :     assert( hMCParamUpmix );
     527             : 
     528       42252 :     push_wmops( "ivas_param_upmix_dec_decorr_subframes" );
     529             : 
     530             :     /* TD decorrelator */
     531       42252 :     default_frame = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC );
     532       42252 :     nSamplesLeftForTD = nSamplesForRendering;
     533       42252 :     nchan_internal = MC_PARAMUPMIX_COMBINATIONS;
     534             : 
     535      211260 :     for ( ch = 0; ch < nchan_internal; ch++ )
     536             :     {
     537      169008 :         pPcm_tmp[ch] = st_ivas->hTcBuffer->tc[ch + 8];
     538      169008 :         p_tc[ch] = st_ivas->hTcBuffer->tc[ch + 4];
     539             :     }
     540             : 
     541       84504 :     while ( nSamplesLeftForTD )
     542             :     {
     543       42252 :         int16_t nSamplesToDecorr = min( nSamplesLeftForTD, default_frame );
     544             : 
     545       42252 :         paramupmix_td_decorr_process_jbm( hMCParamUpmix->hTdDecorr, p_tc, pPcm_tmp, nSamplesToDecorr );
     546             : 
     547      211260 :         for ( ch = 0; ch < nchan_internal; ch++ )
     548             :         {
     549      169008 :             p_tc[ch] += nSamplesToDecorr;
     550             :         }
     551             : 
     552       42252 :         nSamplesLeftForTD -= nSamplesToDecorr;
     553             :     }
     554             : 
     555       42252 :     pop_wmops();
     556       42252 :     return;
     557             : }
     558             : 
     559             : 
     560             : /*****************************************************************************************/
     561             : /* local functions                                                                       */
     562             : /*****************************************************************************************/
     563             : 
     564      679076 : 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      679076 :     float *alpha_prev = hMCParamUpmix->alpha_prev[ch];
     581      679076 :     float *beta_prev = hMCParamUpmix->beta_prev[ch];
     582      679076 :     float *alpha_sf = hMCParamUpmix->alpha_sf[ch];
     583      679076 :     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      679076 :     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      679076 :     mvr2r( alpha_sf, alpha_start, IVAS_MAX_NUM_BANDS );
     597      679076 :     mvr2r( beta_sf, beta_start, IVAS_MAX_NUM_BANDS );
     598    41423636 :     for ( iqmf = 0; iqmf < CLDFB_NO_CHANNELS_MAX; iqmf++ )
     599             :     {
     600    40744560 :         ipar = qmf_to_par_band[iqmf];
     601    40744560 :         alpha1 = alpha_prev;
     602    40744560 :         beta1 = beta_prev;
     603             : 
     604    40744560 :         ismp = 0;
     605    40744560 :         alpha2 = hMCParamUpmix->alphas[ch];
     606    40744560 :         beta2 = hMCParamUpmix->betas[ch];
     607    40744560 :         alpha_smp = alpha_start[ipar];
     608    40744560 :         beta_smp = beta_start[ipar];
     609             : 
     610   202992240 :         for ( iismp = 0; iismp < hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered]; iismp++ )
     611             :         {
     612   162247680 :             if ( ( slots_rendered == 0 ) && ( iismp == 0 ) )
     613             :             {
     614    10140480 :                 ifac = param_interpol[iismp];
     615             :             }
     616             :             else
     617             :             {
     618   152107200 :                 ifac = param_interpol[iismp] - param_interpol[iismp - 1];
     619             :             }
     620   162247680 :             dalpha = ( alpha2[ipar] - alpha1[ipar] ) * ifac;
     621   162247680 :             dbeta = ( beta2[ipar] - beta1[ipar] ) * ifac;
     622             : 
     623   162247680 :             alpha_smp += dalpha;
     624   162247680 :             beta_smp += dbeta;
     625             : 
     626   162247680 :             vmre = qmf_mod_re[ismp][iqmf];
     627   162247680 :             vmim = qmf_mod_im[ismp][iqmf];
     628   162247680 :             vsre = qmf_side_re[ismp][iqmf];
     629   162247680 :             vsim = qmf_side_im[ismp][iqmf];
     630             : 
     631   162247680 :             qmf_side_re[ismp][iqmf] = alpha_smp * vmre + beta_smp * vsre;
     632   162247680 :             qmf_side_im[ismp][iqmf] = alpha_smp * vmim + beta_smp * vsim;
     633             : 
     634   162247680 :             ismp++;
     635             :         }
     636    40744560 :         alpha_sf[ipar] = alpha_smp;
     637    40744560 :         beta_sf[ipar] = beta_smp;
     638             :     }
     639             : 
     640      679076 :     return;
     641             : }
     642             : 
     643      169769 : 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      169769 :     hMCParamUpmix = st_ivas->hMCParamUpmix;
     663      169769 :     assert( hMCParamUpmix );
     664      169769 :     push_wmops( "ivas_mc_paramupmix_dec_sf" );
     665             : 
     666      169769 :     slot_index_start = st_ivas->hTcBuffer->slots_rendered;
     667      848845 :     for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
     668             :     {
     669      679076 :         pPcm_temp[2 * i] = output_f[i + 4];     /* un-decorrelated */
     670      679076 :         pPcm_temp[2 * i + 1] = output_f[i + 8]; /* decorrelated */
     671             :     }
     672             : 
     673             :     /* CLDFB Analysis*/
     674     1527921 :     for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ )
     675             :     {
     676             :         /* slot loop for gathering the input data */
     677     6766408 :         for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     678             :         {
     679     5408256 :             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             : 
     683      848845 :     for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
     684             :     {
     685      679076 :         ps_pred_process_sf( hMCParamUpmix,
     686             :                             st_ivas->hTcBuffer,
     687      679076 :                             Cldfb_RealBuffer[2 * ch], /* in/out */
     688      679076 :                             Cldfb_ImagBuffer[2 * ch],
     689      679076 :                             Cldfb_RealBuffer[2 * ch + 1], /* in/out decorr */
     690      679076 :                             Cldfb_ImagBuffer[2 * ch + 1],
     691      679076 :                             &hMCParamUpmix->param_interpolator[st_ivas->hTcBuffer->slots_rendered],
     692             :                             ch,
     693      679076 :                             st_ivas->hTcBuffer->slots_rendered );
     694             : 
     695             :         /*-- m, s -> l, r ----------------------------*/
     696     3383204 :         for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     697             :         {
     698   164951808 :             for ( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ )
     699             :             {
     700   162247680 :                 float qlre = Cldfb_RealBuffer[2 * ch][slot_idx][k];
     701   162247680 :                 float qlim = Cldfb_ImagBuffer[2 * ch][slot_idx][k];
     702   162247680 :                 float qrre = Cldfb_RealBuffer[2 * ch + 1][slot_idx][k];
     703   162247680 :                 float qrim = Cldfb_ImagBuffer[2 * ch + 1][slot_idx][k];
     704             : 
     705   162247680 :                 Cldfb_RealBuffer[2 * ch][slot_idx][k] = qlre + qrre;
     706   162247680 :                 Cldfb_ImagBuffer[2 * ch][slot_idx][k] = qlim + qrim;
     707   162247680 :                 Cldfb_RealBuffer[2 * ch + 1][slot_idx][k] = qlre - qrre;
     708   162247680 :                 Cldfb_ImagBuffer[2 * ch + 1][slot_idx][k] = qlim - qrim;
     709             :             }
     710             :         }
     711             :     }
     712             : 
     713      169769 :     if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM )
     714             :     {
     715      117825 :         maxBand = (int16_t) ( ( CLDFB_NO_CHANNELS_MAX * st_ivas->hDecoderConfig->output_Fs ) / 48000 );
     716      117825 :         subframeIdx = st_ivas->hTcBuffer->subframes_rendered;
     717             :         /* fastconv binaural rendering and CLDFB synthesis */
     718             :         /* cldfb analysis of non-coupled, non-LFE channels */
     719      117825 :         idx_in = 0;
     720      589125 :         for ( ch = 0; ch < MC_PARAMUPMIX_MAX_INPUT_CHANS - 2 * MC_PARAMUPMIX_COMBINATIONS; ch++ )
     721             :         {
     722      471300 :             if ( st_ivas->hIntSetup.index_lfe[0] != ch )
     723             :             {
     724      428064 :                 pPcm_temp[ch] = output_f[ch];
     725             :                 /* slot loop for gathering the input data */
     726     2128144 :                 for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     727             :                 {
     728     1700080 :                     cldfbAnalysis_ts( &( pPcm_temp[ch][hMCParamUpmix->num_freq_bands * slot_idx] ),
     729     1700080 :                                       Cldfb_RealBuffer_subfr[idx_in][slot_idx],
     730     1700080 :                                       Cldfb_ImagBuffer_subfr[idx_in][slot_idx],
     731     1700080 :                                       maxBand, st_ivas->cldfbAnaDec[2 * MC_PARAMUPMIX_COMBINATIONS + idx_in] );
     732             :                 }
     733      428064 :                 idx_in++;
     734             :             }
     735             :         }
     736             : 
     737             :         /* copy and reorder cldfb analysis of coupled channels */
     738      589125 :         for ( ch = 0; ch < MAX_PARAM_SPATIAL_SUBFRAMES; ch++ )
     739             :         {
     740     2356500 :             for ( slot_idx = 0; slot_idx < MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ )
     741             :             {
     742     1885200 :                 mvr2r( Cldfb_RealBuffer[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_RealBuffer_subfr[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX );
     743     1885200 :                 mvr2r( Cldfb_ImagBuffer[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_ImagBuffer_subfr[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX );
     744     1885200 :                 mvr2r( Cldfb_RealBuffer[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_RealBuffer_subfr[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX );
     745     1885200 :                 mvr2r( Cldfb_ImagBuffer[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_ImagBuffer_subfr[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX );
     746             :             }
     747      471300 :             idx_in += 2;
     748             :         }
     749             : 
     750      117825 :         if ( st_ivas->hCombinedOrientationData && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
     751             :         {
     752      369901 :             for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     753             :             {
     754      295312 :                 ivas_param_mc_mc2sba_cldfb( st_ivas->hTransSetup, hMCParamUpmix->hoa_encoder, slot_idx, Cldfb_RealBuffer_subfr, Cldfb_ImagBuffer_subfr, maxBand, GAIN_LFE );
     755             :             }
     756             :         }
     757             : 
     758             :         /*LFE handling for split rendering cases*/
     759      117825 :         if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     760             :         {
     761           0 :             if ( st_ivas->hSplitBinRend->hCldfbDataOut != NULL )
     762             :             {
     763           0 :                 for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     764             :                 {
     765           0 :                     for ( ch = 0; ch < ( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ); ch++ )
     766             :                     {
     767           0 :                         mvr2r( Cldfb_RealBuffer_subfr[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_RealBuffer[ch][slot_index_start + slot_idx], maxBand );
     768           0 :                         mvr2r( Cldfb_ImagBuffer_subfr[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_ImagBuffer[ch][slot_index_start + slot_idx], maxBand );
     769             :                     }
     770             :                 }
     771             : 
     772           0 :                 st_ivas->hSplitBinRend->hCldfbDataOut->config = st_ivas->hIntSetup.output_config;
     773             :             }
     774             :         }
     775             : 
     776             :         /* Implement binaural rendering */
     777      117825 :         ivas_binRenderer( st_ivas->hBinRenderer,
     778           0 :                           ( st_ivas->hSplitBinRend == NULL ) ? NULL : &st_ivas->hSplitBinRend->splitrend.multiBinPoseData,
     779             :                           st_ivas->hCombinedOrientationData,
     780      117825 :                           st_ivas->hTcBuffer->subframe_nbslots[subframeIdx],
     781             :                           Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural,
     782             :                           Cldfb_RealBuffer_subfr,
     783             :                           Cldfb_ImagBuffer_subfr );
     784             : 
     785      117825 :         if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     786             :         {
     787             :             int16_t pos_idx;
     788           0 :             for ( pos_idx = 0; pos_idx < st_ivas->hBinRenderer->numPoses; pos_idx++ )
     789             :             {
     790           0 :                 for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[subframeIdx]; slot_idx++ )
     791             :                 {
     792           0 :                     for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
     793             :                     {
     794           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 );
     795           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 );
     796             :                     }
     797             :                 }
     798             :             }
     799             :         }
     800             : 
     801             :         /* Implement CLDFB synthesis */
     802      353475 :         for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
     803             :         {
     804             :             float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES];
     805             :             float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES];
     806             : 
     807     1172162 :             for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[subframeIdx]; slot_idx++ )
     808             :             {
     809      936512 :                 RealBuffer[slot_idx] = Cldfb_RealBuffer_Binaural[0][ch][slot_idx];
     810      936512 :                 ImagBuffer[slot_idx] = Cldfb_ImagBuffer_Binaural[0][ch][slot_idx];
     811             :             }
     812             : 
     813      235650 :             cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][0] ), maxBand * st_ivas->hTcBuffer->subframe_nbslots[subframeIdx], st_ivas->cldfbSynDec[ch] );
     814             :         }
     815             :     }
     816             :     else
     817             :     {
     818             :         /*  boxes = { 0 1 2 3 [4 6] [5 7] [8 10] [9 11] }; */
     819       51944 :         pPcm_temp[0] = output_f[4];
     820       51944 :         pPcm_temp[1] = output_f[6];
     821       51944 :         pPcm_temp[2] = output_f[5];
     822       51944 :         pPcm_temp[3] = output_f[7];
     823       51944 :         pPcm_temp[4] = output_f[8];
     824       51944 :         pPcm_temp[5] = output_f[10];
     825       51944 :         pPcm_temp[6] = output_f[9];
     826       51944 :         pPcm_temp[7] = output_f[11];
     827             : 
     828             :         /* CLDFB synthesis */
     829      467496 :         for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ )
     830             :         {
     831     2077760 :             for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
     832             :             {
     833             :                 float *ptr_im[1], *ptr_re[1];
     834     1662208 :                 ptr_re[0] = Cldfb_RealBuffer[ch][slot_idx];
     835     1662208 :                 ptr_im[0] = Cldfb_ImagBuffer[ch][slot_idx];
     836             : 
     837     1662208 :                 cldfbSynthesis( ptr_re, ptr_im, &( pPcm_temp[ch][hMCParamUpmix->num_freq_bands * slot_idx] ),
     838     1662208 :                                 hMCParamUpmix->num_freq_bands, st_ivas->cldfbSynDec[ch] );
     839             :             }
     840             :         }
     841             : 
     842             :         /* adjust delay of other channels */
     843       51944 :         noparamupmix_delay = NS2SA( st_ivas->hDecoderConfig->output_Fs, IVAS_FB_DEC_DELAY_NS );
     844       51944 :         n_samples_rendered = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered] * hMCParamUpmix->num_freq_bands;
     845       51944 :         if ( n_samples_rendered > noparamupmix_delay )
     846             :         {
     847           0 :             for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
     848             :             {
     849             :                 /*delay is handled within LFE decoder*/
     850           0 :                 if ( st_ivas->hIntSetup.index_lfe[0] != ch )
     851             :                 {
     852             :                     float tmp_buf[L_SUBFRAME5MS_48k];
     853           0 :                     mvr2r( &output_f[ch][n_samples_rendered - noparamupmix_delay], tmp_buf, noparamupmix_delay );
     854           0 :                     mvr2r( output_f[ch], &output_f[ch][noparamupmix_delay], n_samples_rendered - noparamupmix_delay );
     855           0 :                     mvr2r( hMCParamUpmix->pcm_delay[ch], output_f[ch], noparamupmix_delay );
     856           0 :                     mvr2r( tmp_buf, hMCParamUpmix->pcm_delay[ch], noparamupmix_delay );
     857             :                 }
     858             :             }
     859             :         }
     860             :         else
     861             :         {
     862      259720 :             for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
     863             :             {
     864      207776 :                 if ( st_ivas->hIntSetup.index_lfe[0] != ch )
     865             :                 {
     866             :                     float tmp_buf[L_SUBFRAME5MS_48k];
     867      155832 :                     mvr2r( &output_f[ch][0], tmp_buf, n_samples_rendered );
     868      155832 :                     mvr2r( hMCParamUpmix->pcm_delay[ch], output_f[ch], n_samples_rendered );
     869      155832 :                     mvr2r( &hMCParamUpmix->pcm_delay[ch][n_samples_rendered], &hMCParamUpmix->pcm_delay[ch][0], noparamupmix_delay - n_samples_rendered );
     870      155832 :                     mvr2r( tmp_buf, &hMCParamUpmix->pcm_delay[ch][noparamupmix_delay - n_samples_rendered], n_samples_rendered );
     871             :                 }
     872             :             }
     873             :         }
     874             :     }
     875             : 
     876      169769 :     st_ivas->hTcBuffer->slots_rendered += st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered];
     877      169769 :     st_ivas->hTcBuffer->subframes_rendered++;
     878             : 
     879      169769 :     pop_wmops();
     880      169769 :     return;
     881             : }
     882             : 
     883             : 
     884     4177344 : static int16_t huff_read(
     885             :     Decoder_State *st,
     886             :     const int16_t ( *ht )[2] )
     887             : {
     888     4177344 :     int16_t node = 0;
     889     4177344 :     uint16_t next_bit = 0;
     890             : 
     891             :     do
     892             :     {
     893     9481223 :         next_bit = st->bit_stream[st->next_bit_pos];
     894     9481223 :         st->next_bit_pos++;
     895     9481223 :         node = ht[node][next_bit];
     896     9481223 :     } while ( node > 0 );
     897             : 
     898     4177344 :     return -( node + 1 );
     899             : }
     900             : 
     901             : 
     902      348112 : static void huffman_decode(
     903             :     Decoder_State *st,
     904             :     const PAR_TYPE parType,
     905             :     int32_t *vq )
     906             : {
     907             :     const int16_t( *huff_node_table )[2];
     908             :     int16_t iv, nquant, offset;
     909             : 
     910      348112 :     nquant = 0;
     911      348112 :     switch ( parType )
     912             :     {
     913      174056 :         case ALPHA:
     914      174056 :             nquant = ivas_mc_paramupmix_alpha_quant_table.nquant;
     915      174056 :             break;
     916      174056 :         case BETA:
     917      174056 :             nquant = ivas_mc_paramupmix_beta_quant_table[0].nquant;
     918      174056 :             break;
     919           0 :         default:
     920           0 :             assert( 0 );
     921             :     }
     922             : 
     923      348112 :     offset = nquant - 1; /* range of df [-(nquant - 1), nquant - 1] */
     924             : 
     925      348112 :     st->next_bit_pos++;
     926      348112 :     switch ( parType )
     927             :     {
     928      174056 :         case ALPHA:
     929      174056 :             huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.alpha;
     930      174056 :             break;
     931      174056 :         case BETA:
     932      174056 :             huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.beta;
     933      174056 :             break;
     934           0 :         default:
     935           0 :             huff_node_table = NULL;
     936           0 :             assert( 0 );
     937             :     }
     938      348112 :     vq[0] = huff_read( st, huff_node_table );
     939             : 
     940      348112 :     switch ( parType )
     941             :     {
     942      174056 :         case ALPHA:
     943      174056 :             huff_node_table = ivas_mc_paramupmix_huff_nodes_df.alpha;
     944      174056 :             break;
     945      174056 :         case BETA:
     946      174056 :             huff_node_table = ivas_mc_paramupmix_huff_nodes_df.beta;
     947      174056 :             break;
     948           0 :         default:
     949           0 :             assert( 0 );
     950             :     }
     951             : 
     952     4177344 :     for ( iv = 1; iv < IVAS_MAX_NUM_BANDS; iv++ )
     953             :     {
     954     3829232 :         vq[iv] = huff_read( st, huff_node_table ) + vq[iv - 1] - offset;
     955             :     }
     956             : 
     957      348112 :     return;
     958             : }
     959             : 
     960             : 
     961      174056 : static void dequant_alpha(
     962             :     int32_t *vq,
     963             :     float *v )
     964             : {
     965             :     int16_t iv;
     966      174056 :     const ACPL_QUANT_TABLE *quant_table = &ivas_mc_paramupmix_alpha_quant_table;
     967             : 
     968     2262728 :     for ( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ )
     969             :     {
     970     2088672 :         v[iv] = quant_table->data[vq[iv]];
     971             :     }
     972             : 
     973      174056 :     return;
     974             : }
     975             : 
     976             : 
     977      174056 : static void dequant_beta(
     978             :     int32_t *aq,
     979             :     int32_t *bq,
     980             :     float *beta )
     981             : {
     982             :     int16_t iv;
     983             :     const ACPL_QUANT_TABLE *quant_table;
     984             : 
     985     2262728 :     for ( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ )
     986             :     {
     987     2088672 :         quant_table = &ivas_mc_paramupmix_beta_quant_table[ivas_param_upmx_mx_qmap[aq[iv]]];
     988     2088672 :         beta[iv] = quant_table->data[bq[iv]];
     989             :     }
     990             : 
     991      174056 :     return;
     992             : }
     993             : 
     994             : 
     995      348112 : static void get_ec_data(
     996             :     Decoder_State *st,
     997             :     const PAR_TYPE parType,
     998             :     int32_t *parQ,
     999             :     int32_t *alphaQEnv,
    1000             :     float ab[IVAS_MAX_NUM_BANDS] )
    1001             : {
    1002      348112 :     huffman_decode( st, parType, parQ );
    1003             : 
    1004      348112 :     if ( parType == ALPHA )
    1005             :     {
    1006      174056 :         dequant_alpha( parQ, ab );
    1007      174056 :         mvl2l( parQ, alphaQEnv, (int16_t) IVAS_MAX_NUM_BANDS );
    1008             :     }
    1009             :     else
    1010             :     {
    1011      174056 :         dequant_beta( alphaQEnv, parQ, ab );
    1012             :     }
    1013             : 
    1014      348112 :     return;
    1015             : }

Generated by: LCOV version 1.14