LCOV - code coverage report
Current view: top level - lib_dec - ivas_corecoder_dec_reconfig.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 174 193 90.2 %
Date: 2025-05-23 08:37:30 Functions: 3 3 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 "options.h"
      34             : #include "ivas_cnst.h"
      35             : #include "ivas_prot.h"
      36             : #include "prot.h"
      37             : #include <stdint.h>
      38             : #ifdef DEBUGGING
      39             : #include "debug.h"
      40             : #endif
      41             : #include "wmc_auto.h"
      42             : 
      43             : 
      44             : /*-------------------------------------------------------------------*
      45             :  * ivas_corecoder_dec_reconfig()
      46             :  *
      47             :  * Allocate, initialize, and configure SCE/CPE/MCT handles in case of bitrate switching
      48             :  *-------------------------------------------------------------------*/
      49             : 
      50       17004 : ivas_error ivas_corecoder_dec_reconfig(
      51             :     Decoder_Struct *st_ivas,                 /* i/o: IVAS decoder structure                                    */
      52             :     const int16_t nSCE_old,                  /* i  : number of SCEs in previous frame                          */
      53             :     int16_t nCPE_old,                        /* i  : number of CPEs in previous frame                          */
      54             :     const int16_t nchan_transport_old,       /* i  : number of TCs in previous frame                           */
      55             :     const int16_t sba_dirac_stereo_flag_old, /* i  : signal stereo rendering using DFT upmix in previous frame */
      56             :     const int32_t brate_SCE,                 /* i  : bitrate to be set for the SCEs                            */
      57             :     const int32_t brate_CPE                  /* i  : bitrate to be set for the CPEs                            */
      58             : )
      59             : {
      60             :     int16_t n, sce_id, cpe_id, output_frame;
      61             :     int16_t nSCE_existing, nCPE_existing;
      62             :     int32_t ivas_total_brate;
      63             :     int16_t nchan_transport_real;
      64             :     MC_MODE last_mc_mode;
      65             :     DECODER_CONFIG_HANDLE hDecoderConfig;
      66             :     ivas_error error;
      67             :     int16_t prev_bfi;
      68             :     Decoder_State *st0;
      69             : 
      70             :     /*-----------------------------------------------------------------*
      71             :      * Initialization
      72             :      *-----------------------------------------------------------------*/
      73             : 
      74       17004 :     hDecoderConfig = st_ivas->hDecoderConfig;
      75       17004 :     ivas_total_brate = hDecoderConfig->ivas_total_brate;
      76       17004 :     output_frame = (int16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC );
      77       17004 :     error = IVAS_ERR_OK;
      78             : 
      79       17004 :     if ( st_ivas->ivas_format == MC_FORMAT )
      80             :     {
      81        3234 :         last_mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */
      82             :     }
      83             :     else
      84             :     {
      85       13770 :         last_mc_mode = MC_MODE_NONE;
      86             :     }
      87             : 
      88       17004 :     nchan_transport_real = st_ivas->nchan_transport;
      89             : 
      90       17004 :     if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
      91             :     {
      92         765 :         nchan_transport_real += st_ivas->nchan_ism;
      93             :     }
      94             :     /*-----------------------------------------------------------------*
      95             :      * Allocate, initialize, and configure SCE/CPE/MCT handles
      96             :      *-----------------------------------------------------------------*/
      97             : 
      98             :     /* remove dummy CPE element for DFT stereo-like upmix */
      99       17004 :     if ( ( st_ivas->ivas_format == SBA_FORMAT && sba_dirac_stereo_flag_old && nchan_transport_old == 1 && ( !st_ivas->sba_dirac_stereo_flag || st_ivas->nchan_transport > 1 ) ) ||
     100       16842 :          ( st_ivas->ivas_format == MC_FORMAT && last_mc_mode == MC_MODE_MCMASA && sba_dirac_stereo_flag_old && nchan_transport_old == 1 && ( !st_ivas->sba_dirac_stereo_flag || st_ivas->nchan_transport > 1 ) ) )
     101             :     {
     102         171 :         st_ivas->hCPE[0]->hCoreCoder[0] = NULL;
     103         171 :         st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
     104         171 :         destroy_cpe_dec( st_ivas->hCPE[0] );
     105         171 :         st_ivas->hCPE[0] = NULL;
     106             : 
     107         171 :         if ( st_ivas->hSCE[0] != NULL )
     108             :         {
     109         171 :             free( st_ivas->hSCE[0]->save_synth );
     110         171 :             st_ivas->hSCE[0]->save_synth = NULL;
     111             : 
     112         171 :             free( st_ivas->hSCE[0]->save_hb_synth );
     113         171 :             st_ivas->hSCE[0]->save_hb_synth = NULL;
     114             :         }
     115             :     }
     116             : 
     117       17004 :     if ( nchan_transport_real == nchan_transport_old && st_ivas->nSCE == nSCE_old && st_ivas->nCPE == nCPE_old )
     118             :     {
     119       12291 :         for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
     120             :         {
     121        7827 :             st_ivas->hSCE[sce_id]->element_brate = brate_SCE;
     122        7827 :             st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
     123             :         }
     124             : 
     125        7944 :         for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
     126             :         {
     127        3480 :             st_ivas->hCPE[cpe_id]->element_brate = brate_CPE;
     128             : 
     129             :             /* prepare bitstream buffers */
     130       10440 :             for ( n = 0; n < CPE_CHANNELS; n++ )
     131             :             {
     132        6960 :                 st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
     133             :             }
     134             :         }
     135             : 
     136        4464 :         if ( st_ivas->nCPE > 1 )
     137             :         {
     138         867 :             if ( ( error = mct_dec_reconfigure( st_ivas, 0 ) ) != IVAS_ERR_OK )
     139             :             {
     140           0 :                 return error;
     141             :             }
     142             :         }
     143             :     }
     144             :     else
     145             :     {
     146       12540 :         st0 = ( nSCE_old > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0];
     147       12540 :         prev_bfi = st0->prev_bfi;
     148       12540 :         nSCE_existing = min( nSCE_old, st_ivas->nSCE );
     149       12540 :         nCPE_existing = min( nCPE_old, st_ivas->nCPE );
     150             : 
     151             :         /* destroy superfluous core coder elements */
     152       20265 :         for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ )
     153             :         {
     154        7725 :             destroy_sce_dec( st_ivas->hSCE[sce_id] );
     155        7725 :             st_ivas->hSCE[sce_id] = NULL;
     156             :         }
     157             : 
     158       12540 :         if ( sba_dirac_stereo_flag_old && nCPE_old == 0 && st_ivas->hCPE[0] )
     159             :         {
     160          81 :             st_ivas->hCPE[0]->hCoreCoder[0] = 0; /* this has been deallocated as part of the SCE it actually belongs to */
     161          81 :             destroy_cpe_dec( st_ivas->hCPE[0] );
     162          81 :             st_ivas->hCPE[0] = NULL;
     163             :         }
     164             : 
     165       18936 :         for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ )
     166             :         {
     167             :             /* don't deallocate first CPE in case of mono/stereo output of 1 TC SBA, only deallocate core coder */
     168        6396 :             if ( cpe_id == 0 && st_ivas->sba_dirac_stereo_flag && sba_dirac_stereo_flag_old )
     169             :             {
     170         468 :                 for ( n = 0; n < CPE_CHANNELS; n++ )
     171             :                 {
     172         312 :                     if ( st_ivas->hCPE[cpe_id]->hCoreCoder[n] != NULL )
     173             :                     {
     174         312 :                         destroy_core_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
     175             : 
     176         312 :                         free( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
     177         312 :                         st_ivas->hCPE[cpe_id]->hCoreCoder[n] = NULL;
     178             :                     }
     179             :                 }
     180         156 :                 continue;
     181             :             }
     182        6240 :             destroy_cpe_dec( st_ivas->hCPE[cpe_id] );
     183        6240 :             st_ivas->hCPE[cpe_id] = NULL;
     184             :         }
     185             : 
     186             :         /* the CPE-internal settings depend from ivas_format and mc_mode, so clean-up when switching between mc_modes */
     187       12540 :         if ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode != last_mc_mode && ( st_ivas->mc_mode == MC_MODE_MCMASA || last_mc_mode == MC_MODE_MCMASA ) )
     188             :         {
     189        1488 :             for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ )
     190             :             {
     191         132 :                 destroy_cpe_dec( st_ivas->hCPE[cpe_id] );
     192         132 :                 st_ivas->hCPE[cpe_id] = NULL;
     193             :             }
     194        1356 :             nCPE_old = 0;
     195        1356 :             nCPE_existing = min( nCPE_old, st_ivas->nCPE );
     196             :         }
     197       12540 :         if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL )
     198             :         {
     199        1431 :             ivas_mct_dec_close( &st_ivas->hMCT );
     200             :         }
     201             : 
     202             :         /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles from the first CPE*/
     203       12540 :         if ( st_ivas->nCPE > 1 && nCPE_old == 1 )
     204             :         {
     205         906 :             free( st_ivas->hCPE[0]->hStereoMdct );
     206         906 :             st_ivas->hCPE[0]->hStereoMdct = NULL;
     207             :         }
     208             : 
     209       17739 :         for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ )
     210             :         {
     211        5199 :             st_ivas->hSCE[sce_id]->element_brate = brate_SCE;
     212        5199 :             st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
     213             :         }
     214       20208 :         for ( ; sce_id < st_ivas->nSCE; sce_id++ )
     215             :         {
     216        7668 :             if ( ( error = create_sce_dec( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK )
     217             :             {
     218           0 :                 return error;
     219             :             }
     220        7668 :             st_ivas->hSCE[sce_id]->hCoreCoder[0]->prev_bfi = prev_bfi;
     221             :         }
     222       12540 :         if ( st_ivas->sba_dirac_stereo_flag && sba_dirac_stereo_flag_old && st_ivas->nchan_transport == 1 && nSCE_old == 0 )
     223             :         {
     224         156 :             st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */
     225         156 :             st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
     226             :         }
     227             : 
     228       19644 :         for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ )
     229             :         {
     230        7104 :             st_ivas->hCPE[cpe_id]->element_brate = brate_CPE;
     231             : 
     232             :             /* prepare bitstream buffers */
     233       21312 :             for ( n = 0; n < CPE_CHANNELS; n++ )
     234             :             {
     235       14208 :                 st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
     236             :             }
     237             :         }
     238       19398 :         for ( ; cpe_id < st_ivas->nCPE; cpe_id++ )
     239             :         {
     240        6858 :             if ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->hOutSetup.separateChannelEnabled )
     241             :             {
     242          63 :                 st_ivas->element_mode_init = IVAS_CPE_MDCT;
     243             :             }
     244             : 
     245        6858 :             if ( ( error = create_cpe_dec( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK )
     246             :             {
     247           0 :                 return error;
     248             :             }
     249        6858 :             st_ivas->hCPE[cpe_id]->hCoreCoder[0]->prev_bfi = prev_bfi;
     250        6858 :             st_ivas->hCPE[cpe_id]->hCoreCoder[1]->prev_bfi = prev_bfi;
     251             :         }
     252             : 
     253       12540 :         if ( st_ivas->nCPE > 1 && nCPE_old <= 1 )
     254             :         {
     255        2412 :             if ( nCPE_old == 1 )
     256             :             {
     257             :                 /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */
     258        2718 :                 for ( n = 0; n < CPE_CHANNELS; n++ )
     259             :                 {
     260        1812 :                     st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate;
     261        1812 :                     st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC );
     262        1812 :                     st_ivas->hCPE[0]->hCoreCoder[n]->igf = 0;
     263             :                 }
     264             :             }
     265             : 
     266        2412 :             if ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK )
     267             :             {
     268           0 :                 return error;
     269             :             }
     270             :         }
     271       10128 :         else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 )
     272             :         {
     273         471 :             if ( ( error = mct_dec_reconfigure( st_ivas, nchan_transport_real != nchan_transport_old ) ) != IVAS_ERR_OK )
     274             :             {
     275           0 :                 return error;
     276             :             }
     277             :         }
     278             : 
     279             :         /* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */
     280       12540 :         if ( st_ivas->nCPE == 1 && nCPE_old > 1 )
     281             :         {
     282         945 :             if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL )
     283             :             {
     284           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) );
     285             :             }
     286             : 
     287         945 :             st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->use_itd = 0;
     288         945 :             st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->reverse_dmx = 0;
     289         945 :             st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->smooth_ratio = 1.f;
     290         945 :             set_s( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->prev_ms_mask[0], 0, MAX_SFB );
     291         945 :             set_s( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->prev_ms_mask[1], 0, MAX_SFB );
     292         945 :             st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->lastCoh = 1.f;
     293         945 :             st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->mdct_stereo_mode[0] = SMDCT_DUAL_MONO;
     294         945 :             st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO;
     295         945 :             st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->IGFStereoMode[0] = -1;
     296         945 :             st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->IGFStereoMode[1] = -1;
     297        2835 :             for ( n = 0; n < CPE_CHANNELS; n++ )
     298             :             {
     299             :                 /* reset mct_chan_mode */
     300        1890 :                 st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR;
     301             :             }
     302             :         }
     303             :     }
     304             : 
     305             :     /* create dummy CPE element for DFT stereo-like upmix */
     306       17004 :     if ( ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) ||
     307       16926 :          ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) )
     308             :     {
     309             :         /* if at least one CPE is already available, only allocate DFT Stereo struct */
     310          84 :         if ( st_ivas->nCPE > 0 )
     311             :         {
     312           0 :             if ( ( error = stereo_dft_dec_create( &( st_ivas->hCPE[0]->hStereoDft ), st_ivas->hCPE[0]->element_brate, st_ivas->hDecoderConfig->output_Fs, st_ivas->sba_dirac_stereo_flag, st_ivas->nchan_transport ) ) != IVAS_ERR_OK )
     313             :             {
     314           0 :                 return error;
     315             :             }
     316             :         }
     317             :         /* otherwise create extra dummy CPE */
     318             :         else
     319             :         {
     320          84 :             if ( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK )
     321             :             {
     322           0 :                 return error;
     323             :             }
     324             :         }
     325             : 
     326          84 :         set_f( st_ivas->hCPE[0]->hStereoDft->buff_LBTCX_mem, 0, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ) );
     327             : 
     328          84 :         st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */
     329          84 :         st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
     330             : 
     331          84 :         if ( st_ivas->hSCE[0]->save_synth == NULL )
     332             :         {
     333           6 :             if ( ( st_ivas->hSCE[0]->save_synth = (float *) malloc( sizeof( float ) * output_frame ) ) == NULL )
     334             :             {
     335           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo output\n" ) );
     336             :             }
     337           6 :             set_zero( st_ivas->hSCE[0]->save_synth, output_frame );
     338             :         }
     339             : 
     340          84 :         if ( st_ivas->hSCE[0]->save_hb_synth == NULL )
     341             :         {
     342           6 :             if ( ( st_ivas->hSCE[0]->save_hb_synth = (float *) malloc( sizeof( float ) * output_frame ) ) == NULL )
     343             :             {
     344           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate HB memory for stereo output\n" ) );
     345             :             }
     346           6 :             set_zero( st_ivas->hSCE[0]->save_hb_synth, output_frame );
     347             :         }
     348             :     }
     349             : 
     350             :     /*-----------------------------------------------------------------*
     351             :      * Set CNA/CNG flags
     352             :      *-----------------------------------------------------------------*/
     353             : 
     354       17004 :     if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT )
     355             :     {
     356        6333 :         ivas_sba_set_cna_cng_flag( st_ivas );
     357             :     }
     358             : 
     359             :     /* special case, if the decoder goes from 1TC DTX to 2TC active frame (in case the bitstream started with an SBA SID frame), allocate DTX memories */
     360       17004 :     if ( hDecoderConfig->last_ivas_total_brate <= IVAS_SID_5k2 && st_ivas->nCPE >= 1 )
     361             :     {
     362          18 :         if ( ( error = initMdctStereoDtxData( st_ivas->hCPE[0] ) ) != IVAS_ERR_OK )
     363             :         {
     364           0 :             return error;
     365             :         }
     366             :     }
     367             : 
     368       17004 :     return error;
     369             : }
     370             : 
     371             : 
     372             : /*-------------------------------------------------------------------*
     373             :  * ivas_hp20_dec_reconfig()
     374             :  *
     375             :  * Allocate, initialize, and configure HP20 memory handles in case of bitrate switching
     376             :  *-------------------------------------------------------------------*/
     377             : 
     378       17004 : ivas_error ivas_hp20_dec_reconfig(
     379             :     Decoder_Struct *st_ivas,     /* i/o: IVAS decoder structure                     */
     380             :     const int16_t nchan_hp20_old /* i  : number of HP20 filters in previous frame   */
     381             : )
     382             : {
     383             :     int16_t i, nchan_hp20;
     384             :     float **old_mem_hp20_out;
     385             :     ivas_error error;
     386             : 
     387       17004 :     error = IVAS_ERR_OK;
     388             : 
     389             :     /*-----------------------------------------------------------------*
     390             :      * HP20 memories
     391             :      *-----------------------------------------------------------------*/
     392             : 
     393       17004 :     nchan_hp20 = getNumChanSynthesis( st_ivas );
     394             : 
     395       17004 :     if ( nchan_hp20 > nchan_hp20_old )
     396             :     {
     397             :         /* save old mem_hp_20 pointer */
     398        6075 :         old_mem_hp20_out = st_ivas->mem_hp20_out;
     399        6075 :         st_ivas->mem_hp20_out = NULL;
     400             : 
     401        6075 :         if ( ( st_ivas->mem_hp20_out = (float **) malloc( nchan_hp20 * sizeof( float * ) ) ) == NULL )
     402             :         {
     403           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
     404             :         }
     405             : 
     406       17586 :         for ( i = 0; i < nchan_hp20_old; i++ )
     407             :         {
     408       11511 :             st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i];
     409       11511 :             old_mem_hp20_out[i] = NULL;
     410             :         }
     411             :         /* create additional hp20 memories */
     412       21594 :         for ( ; i < nchan_hp20; i++ )
     413             :         {
     414       15519 :             if ( ( st_ivas->mem_hp20_out[i] = (float *) malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL )
     415             :             {
     416           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
     417             :             }
     418             : 
     419       15519 :             set_f( st_ivas->mem_hp20_out[i], 0.0f, L_HP20_MEM );
     420             :         }
     421             : 
     422        6075 :         free( old_mem_hp20_out );
     423        6075 :         old_mem_hp20_out = NULL;
     424             :     }
     425       10929 :     else if ( nchan_hp20 < nchan_hp20_old )
     426             :     {
     427             :         /* save old mem_hp_20 pointer */
     428        5949 :         old_mem_hp20_out = st_ivas->mem_hp20_out;
     429        5949 :         st_ivas->mem_hp20_out = NULL;
     430             : 
     431        5949 :         if ( ( st_ivas->mem_hp20_out = (float **) malloc( nchan_hp20 * sizeof( float * ) ) ) == NULL )
     432             :         {
     433           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
     434             :         }
     435             : 
     436       17160 :         for ( i = 0; i < nchan_hp20; i++ )
     437             :         {
     438       11211 :             st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i];
     439       11211 :             old_mem_hp20_out[i] = NULL;
     440             :         }
     441             :         /* remove superfluous hp20 memories */
     442       20916 :         for ( ; i < nchan_hp20_old; i++ )
     443             :         {
     444       14967 :             free( old_mem_hp20_out[i] );
     445       14967 :             old_mem_hp20_out[i] = NULL;
     446             :         }
     447             : 
     448        5949 :         free( old_mem_hp20_out );
     449        5949 :         old_mem_hp20_out = NULL;
     450             :     }
     451             : 
     452       17004 :     return error;
     453             : }
     454             : 
     455             : 
     456             : /*-------------------------------------------------------------------*
     457             :  * ivas_cldfb_dec_reconfig()
     458             :  *
     459             :  * Allocate, initialize, and configure CLDFB handles in case of bitrate switching
     460             :  *-------------------------------------------------------------------*/
     461             : 
     462       20955 : ivas_error ivas_cldfb_dec_reconfig(
     463             :     Decoder_Struct *st_ivas,            /* i/o: IVAS decoder structure                                */
     464             :     const int16_t nchan_transport_old,  /* i  : number of TCs in previous frame                       */
     465             :     int16_t numCldfbAnalyses_old,       /* i  : number of CLDFB analysis instances in previous frame  */
     466             :     const int16_t numCldfbSyntheses_old /* i  : number of CLDFB synthesis instances in previous frame */
     467             : )
     468             : {
     469             :     int16_t i, numCldfbAnalyses, numCldfbSyntheses;
     470             :     DECODER_CONFIG_HANDLE hDecoderConfig;
     471             :     ivas_error error;
     472             : 
     473       20955 :     hDecoderConfig = st_ivas->hDecoderConfig;
     474             : 
     475       20955 :     ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses );
     476             : 
     477             :     /* special case, if there was one transport channel in the previous frame and more than one in the current frame,
     478             :        remove the second CLDFB here, it was for CNA/CNG */
     479       20955 :     if ( st_ivas->ivas_format == SBA_FORMAT && nchan_transport_old == 1 && numCldfbAnalyses_old == 2 && st_ivas->nchan_transport > 1 )
     480             :     {
     481           0 :         deleteCldfb( &( st_ivas->cldfbAnaDec[1] ) );
     482           0 :         numCldfbAnalyses_old--;
     483             :     }
     484             : 
     485             :     /* resample CLDFB analysis instances */
     486       56556 :     for ( i = 0; i < min( numCldfbAnalyses, numCldfbAnalyses_old ); i++ )
     487             :     {
     488       35601 :         if ( ( st_ivas->cldfbAnaDec[i]->no_channels * st_ivas->cldfbAnaDec[i]->no_col ) != ( hDecoderConfig->output_Fs / FRAMES_PER_SEC ) )
     489             :         {
     490        1932 :             resampleCldfb( st_ivas->cldfbAnaDec[i], hDecoderConfig->output_Fs );
     491             :         }
     492             :     }
     493             : 
     494             :     /* Analysis*/
     495       20955 :     if ( numCldfbAnalyses_old > numCldfbAnalyses )
     496             :     {
     497             :         /* delete superfluous CLDFB synthesis instances */
     498       16083 :         for ( i = numCldfbAnalyses; i < numCldfbAnalyses_old; i++ )
     499             :         {
     500       11613 :             deleteCldfb( &( st_ivas->cldfbAnaDec[i] ) );
     501             :         }
     502             :     }
     503       16485 :     else if ( numCldfbAnalyses_old < numCldfbAnalyses )
     504             :     {
     505             :         /* create additional CLDFB synthesis instances */
     506       14550 :         for ( i = numCldfbAnalyses_old; i < numCldfbAnalyses; i++ )
     507             :         {
     508       10104 :             if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK )
     509             :             {
     510           0 :                 return error;
     511             :             }
     512             :         }
     513             :     }
     514             : 
     515             :     /* Synthesis */
     516       20955 :     if ( numCldfbSyntheses_old > numCldfbSyntheses )
     517             :     {
     518             :         /* delete superfluous CLDFB synthesis instances */
     519       17940 :         for ( i = numCldfbSyntheses; i < numCldfbSyntheses_old; i++ )
     520             :         {
     521       15321 :             deleteCldfb( &( st_ivas->cldfbSynDec[i] ) );
     522             :         }
     523             :     }
     524       18336 :     else if ( numCldfbSyntheses_old < numCldfbSyntheses )
     525             :     {
     526             :         /* create additional CLDFB synthesis instances */
     527       17919 :         for ( i = numCldfbSyntheses_old; i < numCldfbSyntheses; i++ )
     528             :         {
     529       15324 :             if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK )
     530             :             {
     531           0 :                 return error;
     532             :             }
     533             :         }
     534             :     }
     535             : 
     536             :     /* CLDFB Interpolation weights */
     537       20955 :     if ( st_ivas->ivas_format == SBA_FORMAT && ( numCldfbAnalyses_old != numCldfbAnalyses || numCldfbSyntheses_old != numCldfbSyntheses || nchan_transport_old != st_ivas->nchan_transport ) && numCldfbAnalyses != 0 && numCldfbSyntheses != 0 )
     538             :     {
     539        1977 :         ivas_spar_get_cldfb_gains( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig );
     540             :     }
     541             : 
     542       20955 :     return IVAS_ERR_OK;
     543             : }

Generated by: LCOV version 1.14