LCOV - code coverage report
Current view: top level - lib_com - fill_spectrum.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 177 184 96.2 %
Date: 2025-05-03 01:55:50 Functions: 2 2 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             : /*====================================================================================
      34             :     EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
      35             :   ====================================================================================*/
      36             : 
      37             : #include <stdint.h>
      38             : #include "options.h"
      39             : #include "cnst.h"
      40             : #include "rom_com.h"
      41             : #include "prot_fx.h"
      42             : #include "wmc_auto.h"
      43             : #include "ivas_prot_fx.h"
      44             : 
      45             : 
      46        7331 : void ivas_fill_spectrum_fx(
      47             :     Word16 *coeff,                    /* i/o: normalized MLT spectrum / nf spectrum                Q12 */
      48             :     Word32 *L_coeff_out,              /* i/o: Noisefilled MLT spectrum                             Q12 */
      49             :     const Word16 *R,                  /* i  : number of pulses per band                            Q0  */
      50             :     const Word16 is_transient,        /* i  : transient flag                                       Q0  */
      51             :     Word16 norm[],                    /* i  : quantization indices for norms                       Q0  */
      52             :     const Word16 *hq_generic_fenv,    /* i  : HQ GENERIC envelope                                  Q1  */
      53             :     const Word16 hq_generic_offset,   /* i  : HQ GENERIC offset                                    Q0  */
      54             :     const Word16 nf_idx,              /* i  : noise fill index                                     Q0  */
      55             :     const Word16 length,              /* i  : Length of spectrum (32 or 48 kHz)                    Q0  */
      56             :     const Word16 env_stab,            /* i  : Envelope stability measure [0..1]                    Q15 */
      57             :     Word16 *no_att_hangover,          /* i/o: Frame counter for attenuation hangover               Q0  */
      58             :     Word32 *L_energy_lt,              /* i/o: Long-term energy measure for transient detection     Q13 */
      59             :     Word16 *bwe_seed,                 /* i/o: random seed for generating BWE input                 Q0  */
      60             :     const Word16 hq_generic_exc_clas, /* i  : BWE excitation class                                 Q0  */
      61             :     const Word16 core_sfm,            /* i  : index of the end band for core                       Q0  */
      62             :     const Word16 HQ_mode,             /* i  : HQ mode                                              Q0  */
      63             :     Word16 noise_level[],             /* i  : noise levels for harmonic modes                      Q15 */
      64             :     const Word32 L_core_brate,        /* i  : target bit-rate                                      Q0  */
      65             :     Word16 prev_noise_level[],        /* i/o: noise factor in previous frame                       Q15 */
      66             :     Word16 *prev_R,                   /* i/o: bit allocation info. in previous frame               Q0  */
      67             :     Word32 *prev_coeff_out,           /* i/o: decoded spectrum in previous frame                   Q12 */
      68             :     const Word16 *peak_idx,           /* i  : peak indices for hvq                                 Q0  */
      69             :     const Word16 Npeaks,              /* i  : number of peaks in hvq                               Q0  */
      70             :     const Word16 *npulses,            /* i  : number of pulses per band                            Q0  */
      71             :     const Word16 prev_is_transient,   /* i  : previous transient flag                              Q0  */
      72             :     Word32 *prev_normq,               /* i/o: previous norms                                       Q14 */
      73             :     Word32 *prev_env,                 /* i/o: previous noise envelopes                             Q(prev_env_Q) */
      74             :     const Word16 prev_bfi,            /* i  : previous bad frame indicator                         Q0  */
      75             :     const Word16 *sfmsize,            /* i  : Length of bands                                      Q0  */
      76             :     const Word16 *sfm_start,          /* i  : Start of bands                                       Q0  */
      77             :     const Word16 *sfm_end,            /* i  : End of bands                                         Q0  */
      78             :     Word16 *prev_L_swb_norm,          /* i/o: HVQ/Harmonic mode normalization length               Q0  */
      79             :     const Word16 prev_hq_mode,        /* i  : Previous HQ mode                                     Q0  */
      80             :     const Word16 num_sfm,             /* i  : Total number of bands                                Q0  */
      81             :     Word16 *prev_env_Q,
      82             :     const Word16 num_env_bands, /* i  : Number sub bands to be encoded for HQ_GEN            Q0  */
      83             :     const Word16 element_mode   /* i  : IVAS element mode */
      84             : )
      85             : {
      86             :     Word16 CodeBook[L_SPEC48k_EXT]; /* Q12 */
      87             :     Word16 cb_size;
      88             :     Word16 last_sfm;
      89             :     Word16 CodeBook_mod[L_SPEC48k_EXT]; /*Q12 */
      90             :     Word16 norm_adj[NB_SFM];            /*Q15 */
      91             :     Word16 high_sfm;
      92             :     Word16 flag_32K_env_hangover;
      93             :     Word16 bin_th;
      94             :     Word16 peak_pos[L_HARMONIC_EXC];
      95             :     Word16 bwe_peaks[L_FRAME48k];
      96             :     Word32 L_normq_v[NB_SFM];           /*Q14 */
      97             :     Word16 coeff_fine[L_SPEC48k_EXT];   /*Q15 */
      98             :     Word32 L_coeff_out1[L_SPEC48k_EXT]; /*Q12 */
      99        7331 :     set16_fx( peak_pos, 0, L_HARMONIC_EXC );
     100        7331 :     set16_fx( bwe_peaks, 0, L_FRAME48k );
     101        7331 :     set16_fx( norm_adj, 32767, num_sfm ); /* 1.0, Q15 */
     102        7331 :     cb_size = 0;
     103        7331 :     move16();
     104        7331 :     bin_th = 0;
     105        7331 :     move16();
     106        7331 :     high_sfm = 23;
     107        7331 :     move16();
     108             : 
     109        7331 :     test();
     110        7331 :     IF( EQ_16( HQ_mode, HQ_TRANSIENT ) )
     111             :     {
     112         477 :         last_sfm = sub( num_sfm, 1 );
     113             :     }
     114        6854 :     ELSE IF( EQ_16( HQ_mode, HQ_GEN_SWB ) || EQ_16( HQ_mode, HQ_GEN_FB ) )
     115             :     {
     116        2743 :         last_sfm = s_max( core_sfm, sub( num_env_bands, 1 ) );
     117             :     }
     118             :     ELSE
     119             :     {
     120        4111 :         last_sfm = core_sfm;
     121        4111 :         move16();
     122             :     }
     123             : 
     124        7331 :     IF( EQ_16( HQ_mode, HQ_HARMONIC ) )
     125             :     {
     126             :         /*high_sfm = (core_brate == HQ_BWE_CROSSOVER_BRATE) ? HVQ_THRES_SFM_24k-1 : HVQ_THRES_SFM_32k-3; */
     127         708 :         high_sfm = HVQ_THRES_SFM_32k - 1;
     128         708 :         move16();
     129         708 :         if ( LT_32( L_core_brate, HQ_BWE_CROSSOVER_BRATE ) )
     130             :         {
     131         360 :             high_sfm = HVQ_THRES_SFM_24k - 1;
     132         360 :             move16();
     133             :         }
     134             : 
     135         708 :         if ( LT_16( last_sfm, high_sfm ) )
     136             :         {
     137          71 :             last_sfm = high_sfm;
     138          71 :             move16();
     139             :         }
     140             :     }
     141        6623 :     ELSE IF( EQ_16( HQ_mode, HQ_HVQ ) )
     142             :     {
     143        1229 :         bin_th = sfm_end[last_sfm];
     144        1229 :         move16();
     145             :     }
     146             : 
     147             :     /* Transient analysis for envelope stability measure */
     148        7331 :     IF( EQ_16( length, L_FRAME32k ) )
     149             :     {
     150        1085 :         env_stab_transient_detect_fx( is_transient, length, norm, no_att_hangover, L_energy_lt, HQ_mode, bin_th, L_coeff_out, 12 );
     151             :     }
     152             : 
     153        7331 :     test();
     154        7331 :     test();
     155        7331 :     test();
     156        7331 :     test();
     157        7331 :     IF( EQ_16( length, L_FRAME16k ) ||
     158             :         ( ( EQ_16( length, L_FRAME32k ) && NE_16( HQ_mode, HQ_HARMONIC ) && NE_16( HQ_mode, HQ_HVQ ) ) && ( *no_att_hangover == 0 ) ) )
     159             :     {
     160             :         /* Norm adjustment function */
     161        1430 :         env_adj_fx( npulses, length, last_sfm, norm_adj, env_stab, sfmsize );
     162             :     }
     163             : 
     164             :     /*flag_32K_env_hangover = ( length == L_FRAME32k && ( (env_stab < 0.5f && *no_att_hangover == 0) || HQ_mode == HQ_HVQ ) );   */
     165        7331 :     flag_32K_env_hangover = 0;
     166        7331 :     move16();
     167        7331 :     test();
     168        7331 :     test();
     169        7331 :     test();
     170        7331 :     if ( EQ_16( length, L_FRAME32k ) && ( ( LT_16( env_stab, 16384 /*0.5.Q15*/ ) && *no_att_hangover == 0 ) || EQ_16( HQ_mode, HQ_HVQ ) ) )
     171             :     {
     172         541 :         flag_32K_env_hangover = 1;
     173         541 :         move16();
     174             :     }
     175             : 
     176             : 
     177             :     /*----------------------------------------------------------------*
     178             :      * Build noise-fill codebook
     179             :      *----------------------------------------------------------------*/
     180             : 
     181        7331 :     IF( NE_16( HQ_mode, HQ_HVQ ) )
     182             :     {
     183        6102 :         cb_size = build_nf_codebook_fx( flag_32K_env_hangover, coeff, sfm_start, sfmsize, sfm_end, last_sfm, R, CodeBook, CodeBook_mod );
     184             :     }
     185             :     /*----------------------------------------------------------------*
     186             :      * Prepare fine structure for Harmonic and HVQ
     187             :      *----------------------------------------------------------------*/
     188             : 
     189        7331 :     IF( EQ_16( HQ_mode, HQ_HARMONIC ) )
     190             :     {
     191         708 :         harm_bwe_fine_fx( R, last_sfm, high_sfm, num_sfm, norm, sfm_start, sfm_end, prev_L_swb_norm, coeff, L_coeff_out, coeff_fine );
     192             :     }
     193        6623 :     ELSE IF( EQ_16( HQ_mode, HQ_HVQ ) )
     194             :     {
     195        1229 :         hvq_bwe_fine_fx( last_sfm, num_sfm, sfm_end, peak_idx, Npeaks, peak_pos, prev_L_swb_norm, L_coeff_out, bwe_peaks, coeff_fine );
     196             :     }
     197             : 
     198             :     /*----------------------------------------------------------------*
     199             :      * Apply noise-fill
     200             :      *----------------------------------------------------------------*/
     201             : 
     202        7331 :     test();
     203        7331 :     IF( NE_16( HQ_mode, HQ_HVQ ) && ( cb_size > 0 ) )
     204             :     {
     205        6102 :         apply_noisefill_HQ_fx( R, length, flag_32K_env_hangover, L_core_brate, last_sfm, CodeBook,
     206             :                                CodeBook_mod, cb_size, sfm_start, sfm_end, sfmsize, coeff );
     207             :     }
     208             : 
     209             :     /*----------------------------------------------------------------*
     210             :      * Normal mode BWE
     211             :      *----------------------------------------------------------------*/
     212             : 
     213        7331 :     IF( HQ_mode == HQ_NORMAL )
     214             :     {
     215        2174 :         hq_fold_bwe_fx( last_sfm, sfm_end, num_sfm, coeff );
     216             :     }
     217             : 
     218             :     /*----------------------------------------------------------------*
     219             :      * Apply noise-fill adjustment
     220             :      *----------------------------------------------------------------*/
     221             : 
     222        7331 :     test();
     223        7331 :     test();
     224        7331 :     test();
     225        7331 :     IF( ( GE_16( length, L_FRAME32k ) || GT_32( L_core_brate, HQ_32k ) || LT_32( L_core_brate, HQ_24k40 ) ) && NE_16( HQ_mode, HQ_HVQ ) )
     226             :     {
     227        6020 :         apply_nf_gain_fx( nf_idx, last_sfm, R, sfm_start, sfm_end, coeff );
     228             :     }
     229             : 
     230             :     /*----------------------------------------------------------------*
     231             :      * Prepare fine strucutre for HQ GENERIC
     232             :      *----------------------------------------------------------------*/
     233        7331 :     test();
     234        7331 :     IF( EQ_16( HQ_mode, HQ_GEN_SWB ) || EQ_16( HQ_mode, HQ_GEN_FB ) )
     235             :     {
     236        2743 :         hq_generic_fine_fx( coeff, last_sfm, sfm_start, sfm_end, bwe_seed, coeff_fine );
     237             :     }
     238             : 
     239             :     /*----------------------------------------------------------------*
     240             :      * Apply envelope
     241             :      *----------------------------------------------------------------*/
     242             : 
     243        7331 :     test();
     244        7331 :     IF( NE_16( HQ_mode, HQ_HARMONIC ) && NE_16( HQ_mode, HQ_HVQ ) )
     245             :     {
     246        5394 :         apply_envelope_fx( coeff, norm, norm_adj, num_sfm, last_sfm, HQ_mode, length, sfm_start, sfm_end,
     247             :                            L_normq_v, L_coeff_out, coeff_fine, L_coeff_out1 );
     248             :     }
     249             : 
     250             :     /*----------------------------------------------------------------*
     251             :      * Harmonic BWE, HVQ BWE and HQ SWB BWE
     252             :      *----------------------------------------------------------------*/
     253        7331 :     test();
     254        7331 :     IF( EQ_16( HQ_mode, HQ_HARMONIC ) )
     255             :     {
     256         708 :         ivas_harm_bwe_fx( coeff_fine, coeff, num_sfm, sfm_start, sfm_end, last_sfm, R, prev_hq_mode, norm, noise_level, prev_noise_level, bwe_seed, L_coeff_out, element_mode );
     257             :     }
     258        6623 :     ELSE IF( EQ_16( HQ_mode, HQ_HVQ ) )
     259             :     {
     260        1229 :         hvq_bwe_fx( L_coeff_out, coeff_fine, sfm_start, sfm_end, sfmsize, last_sfm, prev_hq_mode, bwe_peaks, bin_th, num_sfm, L_core_brate, R, norm,
     261             :                     noise_level, prev_noise_level, bwe_seed, L_coeff_out, 15, 12 );
     262             :     }
     263        5394 :     ELSE IF( EQ_16( HQ_mode, HQ_GEN_SWB ) || EQ_16( HQ_mode, HQ_GEN_FB ) )
     264             :     {
     265        2743 :         hq_bwe_ivas_fx( HQ_mode, L_coeff_out1, hq_generic_fenv, L_coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, sfm_end, num_sfm, num_env_bands, R );
     266             :     }
     267             : 
     268             :     /*----------------------------------------------------------------*
     269             :      * HQ WB BWE refinements
     270             :      *----------------------------------------------------------------*/
     271        7331 :     test();
     272        7331 :     IF( EQ_16( length, L_FRAME16k ) && LE_32( L_core_brate, HQ_32k ) )
     273             :     {
     274         476 :         hq_wb_nf_bwe_fx( coeff, is_transient, prev_bfi, L_normq_v, num_sfm, sfm_start, sfm_end, sfmsize, last_sfm, R,
     275             :                          prev_is_transient, prev_normq, prev_env, bwe_seed, prev_coeff_out, prev_R, L_coeff_out, prev_env_Q );
     276             :     }
     277             : 
     278             :     /*----------------------------------------------------------------*
     279             :      * Update memories
     280             :      *----------------------------------------------------------------*/
     281             : 
     282        7331 :     test();
     283        7331 :     IF( NE_16( HQ_mode, HQ_HARMONIC ) && NE_16( HQ_mode, HQ_HVQ ) )
     284             :     {
     285        5394 :         prev_noise_level[0] = 3277;
     286        5394 :         move16(); /* 0.1 in Q15 */
     287        5394 :         prev_noise_level[1] = 3277;
     288        5394 :         move16(); /* 0.1 in Q15 */
     289             :     }
     290        7331 :     test();
     291        7331 :     IF( !( EQ_16( length, L_FRAME16k ) && LE_32( L_core_brate, HQ_32k ) ) )
     292             :     {
     293        6855 :         set32_fx( prev_env, 0, SFM_N_WB );
     294        6855 :         set32_fx( prev_normq, 0, SFM_N_WB );
     295             :     }
     296             : 
     297        7331 :     test();
     298        7331 :     IF( EQ_16( length, L_FRAME32k ) && LE_32( L_core_brate, HQ_32k ) )
     299             :     {
     300        1007 :         *prev_R = R[SFM_N_WB - 1];
     301        1007 :         move16();
     302        1007 :         Copy32( L_coeff_out + L_FRAME16k - L_HQ_WB_BWE, prev_coeff_out, L_HQ_WB_BWE );
     303             :     }
     304             : 
     305        7331 :     return;
     306             : }
     307             : 
     308         397 : void fill_spectrum_fx(
     309             :     Word16 *coeff,                    /* i/o: normalized MLT spectrum / nf spectrum                Q12 */
     310             :     Word32 *L_coeff_out,              /* i/o: Noisefilled MLT spectrum                             Q12 */
     311             :     const Word16 *R,                  /* i  : number of pulses per band                            Q0  */
     312             :     const Word16 is_transient,        /* i  : transient flag                                       Q0  */
     313             :     Word16 norm[],                    /* i  : quantization indices for norms                       Q0  */
     314             :     const Word16 *hq_generic_fenv,    /* i  : HQ GENERIC envelope                                  Q1  */
     315             :     const Word16 hq_generic_offset,   /* i  : HQ GENERIC offset                                    Q0  */
     316             :     const Word16 nf_idx,              /* i  : noise fill index                                     Q0  */
     317             :     const Word16 length,              /* i  : Length of spectrum (32 or 48 kHz)                    Q0  */
     318             :     const Word16 env_stab,            /* i  : Envelope stability measure [0..1]                    Q15 */
     319             :     Word16 *no_att_hangover,          /* i/o: Frame counter for attenuation hangover               Q0  */
     320             :     Word32 *L_energy_lt,              /* i/o: Long-term energy measure for transient detection     Q13 */
     321             :     Word16 *bwe_seed,                 /* i/o: random seed for generating BWE input                 Q0  */
     322             :     const Word16 hq_generic_exc_clas, /* i  : BWE excitation class                                 Q0  */
     323             :     const Word16 core_sfm,            /* i  : index of the end band for core                       Q0  */
     324             :     const Word16 HQ_mode,             /* i  : HQ mode                                              Q0  */
     325             :     Word16 noise_level[],             /* i  : noise levels for harmonic modes                      Q15 */
     326             :     const Word32 L_core_brate,        /* i  : target bit-rate                                      Q0  */
     327             :     Word16 prev_noise_level[],        /* i/o: noise factor in previous frame                       Q15 */
     328             :     Word16 *prev_R,                   /* i/o: bit allocation info. in previous frame               Q0  */
     329             :     Word32 *prev_coeff_out,           /* i/o: decoded spectrum in previous frame                   Q12 */
     330             :     const Word16 *peak_idx,           /* i  : peak indices for hvq                                 Q0  */
     331             :     const Word16 Npeaks,              /* i  : number of peaks in hvq                               Q0  */
     332             :     const Word16 *npulses,            /* i  : number of pulses per band                            Q0  */
     333             :     const Word16 prev_is_transient,   /* i  : previous transient flag                              Q0  */
     334             :     Word32 *prev_normq,               /* i/o: previous norms                                       Q14 */
     335             :     Word32 *prev_env,                 /* i/o: previous noise envelopes                             Q(prev_env_Q) */
     336             :     const Word16 prev_bfi,            /* i  : previous bad frame indicator                         Q0  */
     337             :     const Word16 *sfmsize,            /* i  : Length of bands                                      Q0  */
     338             :     const Word16 *sfm_start,          /* i  : Start of bands                                       Q0  */
     339             :     const Word16 *sfm_end,            /* i  : End of bands                                         Q0  */
     340             :     Word16 *prev_L_swb_norm,          /* i/o: HVQ/Harmonic mode normalization length               Q0  */
     341             :     const Word16 prev_hq_mode,        /* i  : Previous HQ mode                                     Q0  */
     342             :     const Word16 num_sfm,             /* i  : Total number of bands                                Q0  */
     343             :     Word16 *prev_env_Q,
     344             :     const Word16 num_env_bands, /* i  : Number sub bands to be encoded for HQ_GEN            Q0  */
     345             :     const Word16 element_mode   /* i  : IVAS element mode */
     346             : )
     347             : {
     348             :     Word16 CodeBook[FREQ_LENGTH]; /* Q12 */
     349             :     Word16 cb_size;
     350             :     Word16 last_sfm;
     351             :     Word16 CodeBook_mod[FREQ_LENGTH]; /*Q12 */
     352             :     Word16 norm_adj[NB_SFM];          /*Q15 */
     353             :     Word16 high_sfm;
     354             :     Word16 flag_32K_env_hangover;
     355             :     Word16 bin_th;
     356             :     Word16 peak_pos[L_HARMONIC_EXC];
     357             :     Word16 bwe_peaks[L_FRAME48k];
     358             :     Word32 L_normq_v[NB_SFM];           /*Q14 */
     359             :     Word16 coeff_fine[L_SPEC48k_EXT];   /*Q15 */
     360             :     Word32 L_coeff_out1[L_SPEC48k_EXT]; /*Q12 */
     361         397 :     set16_fx( peak_pos, 0, L_HARMONIC_EXC );
     362         397 :     set16_fx( bwe_peaks, 0, L_FRAME48k );
     363         397 :     set16_fx( norm_adj, 32767, num_sfm ); /* 1.0, Q15 */
     364         397 :     cb_size = 0;
     365         397 :     move16();
     366         397 :     bin_th = 0;
     367         397 :     move16();
     368         397 :     high_sfm = 23;
     369         397 :     move16();
     370             : 
     371         397 :     test();
     372         397 :     IF( EQ_16( HQ_mode, HQ_TRANSIENT ) )
     373             :     {
     374          35 :         last_sfm = sub( num_sfm, 1 );
     375             :     }
     376         362 :     ELSE IF( EQ_16( HQ_mode, HQ_GEN_SWB ) || EQ_16( HQ_mode, HQ_GEN_FB ) )
     377             :     {
     378          46 :         last_sfm = s_max( core_sfm, sub( num_env_bands, 1 ) );
     379             :     }
     380             :     ELSE
     381             :     {
     382         316 :         last_sfm = core_sfm;
     383         316 :         move16();
     384             :     }
     385             : 
     386         397 :     IF( EQ_16( HQ_mode, HQ_HARMONIC ) )
     387             :     {
     388             :         /*high_sfm = (core_brate == HQ_BWE_CROSSOVER_BRATE) ? HVQ_THRES_SFM_24k-1 : HVQ_THRES_SFM_32k-3; */
     389          20 :         high_sfm = sub( HVQ_THRES_SFM_32k, 1 );
     390          20 :         if ( LT_32( L_core_brate, HQ_BWE_CROSSOVER_BRATE ) )
     391             :         {
     392          20 :             high_sfm = sub( HVQ_THRES_SFM_24k, 1 );
     393             :         }
     394             : 
     395          20 :         if ( LT_16( last_sfm, high_sfm ) )
     396             :         {
     397           0 :             last_sfm = high_sfm;
     398           0 :             move16();
     399             :         }
     400             :     }
     401         377 :     ELSE IF( EQ_16( HQ_mode, HQ_HVQ ) )
     402             :     {
     403           0 :         bin_th = sfm_end[last_sfm];
     404           0 :         move16();
     405             :     }
     406             : 
     407             :     /* Transient analysis for envelope stability measure */
     408         397 :     IF( EQ_16( length, L_FRAME32k ) )
     409             :     {
     410         397 :         env_stab_transient_detect_fx( is_transient, length, norm, no_att_hangover, L_energy_lt, HQ_mode, bin_th, L_coeff_out, 12 );
     411             :     }
     412             : 
     413         397 :     test();
     414         397 :     test();
     415         397 :     test();
     416         397 :     test();
     417         397 :     IF( EQ_16( length, L_FRAME16k ) ||
     418             :         ( ( EQ_16( length, L_FRAME32k ) && NE_16( HQ_mode, HQ_HARMONIC ) && NE_16( HQ_mode, HQ_HVQ ) ) && *no_att_hangover == 0 ) )
     419             :     {
     420             :         /* Norm adjustment function */
     421         377 :         env_adj_fx( npulses, length, last_sfm, norm_adj, env_stab, sfmsize );
     422             :     }
     423             : 
     424             :     /*flag_32K_env_hangover = ( length == L_FRAME32k && ( (env_stab < 0.5f && *no_att_hangover == 0) || HQ_mode == HQ_HVQ ) );   */
     425         397 :     flag_32K_env_hangover = 0;
     426         397 :     move16();
     427         397 :     test();
     428         397 :     test();
     429         397 :     test();
     430         397 :     if ( EQ_16( length, L_FRAME32k ) && ( ( LT_16( env_stab, 16384 /*0.5.Q15*/ ) && *no_att_hangover == 0 ) || EQ_16( HQ_mode, HQ_HVQ ) ) )
     431             :     {
     432          43 :         flag_32K_env_hangover = 1;
     433          43 :         move16();
     434             :     }
     435             : 
     436             : 
     437             :     /*----------------------------------------------------------------*
     438             :      * Build noise-fill codebook
     439             :      *----------------------------------------------------------------*/
     440             : 
     441         397 :     IF( NE_16( HQ_mode, HQ_HVQ ) )
     442             :     {
     443         397 :         cb_size = build_nf_codebook_fx( flag_32K_env_hangover, coeff, sfm_start, sfmsize, sfm_end, last_sfm, R, CodeBook, CodeBook_mod );
     444             :     }
     445             :     /*----------------------------------------------------------------*
     446             :      * Prepare fine structure for Harmonic and HVQ
     447             :      *----------------------------------------------------------------*/
     448             : 
     449         397 :     IF( EQ_16( HQ_mode, HQ_HARMONIC ) )
     450             :     {
     451          20 :         harm_bwe_fine_fx( R, last_sfm, high_sfm, num_sfm, norm, sfm_start, sfm_end, prev_L_swb_norm, coeff, L_coeff_out, coeff_fine );
     452             :     }
     453         377 :     ELSE IF( EQ_16( HQ_mode, HQ_HVQ ) )
     454             :     {
     455           0 :         hvq_bwe_fine_fx( last_sfm, num_sfm, sfm_end, peak_idx, Npeaks, peak_pos, prev_L_swb_norm, L_coeff_out, bwe_peaks, coeff_fine );
     456             :     }
     457             : 
     458             :     /*----------------------------------------------------------------*
     459             :      * Apply noise-fill
     460             :      *----------------------------------------------------------------*/
     461             : 
     462         397 :     test();
     463         397 :     IF( NE_16( HQ_mode, HQ_HVQ ) && cb_size > 0 )
     464             :     {
     465         397 :         apply_noisefill_HQ_fx( R, length, flag_32K_env_hangover, L_core_brate, last_sfm, CodeBook,
     466             :                                CodeBook_mod, cb_size, sfm_start, sfm_end, sfmsize, coeff );
     467             :     }
     468             : 
     469             :     /*----------------------------------------------------------------*
     470             :      * Normal mode BWE
     471             :      *----------------------------------------------------------------*/
     472             : 
     473         397 :     IF( HQ_mode == HQ_NORMAL )
     474             :     {
     475         296 :         hq_fold_bwe_fx( last_sfm, sfm_end, num_sfm, coeff );
     476             :     }
     477             : 
     478             :     /*----------------------------------------------------------------*
     479             :      * Apply noise-fill adjustment
     480             :      *----------------------------------------------------------------*/
     481             : 
     482         397 :     test();
     483         397 :     test();
     484         397 :     test();
     485         397 :     IF( ( GE_16( length, L_FRAME32k ) || GT_32( L_core_brate, HQ_32k ) || LT_32( L_core_brate, HQ_24k40 ) ) && NE_16( HQ_mode, HQ_HVQ ) )
     486             :     {
     487         397 :         apply_nf_gain_fx( nf_idx, last_sfm, R, sfm_start, sfm_end, coeff );
     488             :     }
     489             : 
     490             :     /*----------------------------------------------------------------*
     491             :      * Prepare fine strucutre for HQ GENERIC
     492             :      *----------------------------------------------------------------*/
     493         397 :     test();
     494         397 :     IF( EQ_16( HQ_mode, HQ_GEN_SWB ) || EQ_16( HQ_mode, HQ_GEN_FB ) )
     495             :     {
     496          46 :         hq_generic_fine_fx( coeff, last_sfm, sfm_start, sfm_end, bwe_seed, coeff_fine );
     497             :     }
     498             : 
     499             :     /*----------------------------------------------------------------*
     500             :      * Apply envelope
     501             :      *----------------------------------------------------------------*/
     502             : 
     503         397 :     test();
     504         397 :     IF( NE_16( HQ_mode, HQ_HARMONIC ) && NE_16( HQ_mode, HQ_HVQ ) )
     505             :     {
     506         377 :         apply_envelope_fx( coeff, norm, norm_adj, num_sfm, last_sfm, HQ_mode, length, sfm_start, sfm_end,
     507             :                            L_normq_v, L_coeff_out, coeff_fine, L_coeff_out1 );
     508             :     }
     509             : 
     510             :     /*----------------------------------------------------------------*
     511             :      * Harmonic BWE, HVQ BWE and HQ SWB BWE
     512             :      *----------------------------------------------------------------*/
     513         397 :     test();
     514         397 :     IF( EQ_16( HQ_mode, HQ_HARMONIC ) )
     515             :     {
     516          20 :         harm_bwe_fx( coeff_fine, coeff, num_sfm, sfm_start, sfm_end, last_sfm, R, prev_hq_mode, norm, noise_level, prev_noise_level, bwe_seed, L_coeff_out, element_mode );
     517             :     }
     518         377 :     ELSE IF( EQ_16( HQ_mode, HQ_HVQ ) )
     519             :     {
     520           0 :         hvq_bwe_fx( L_coeff_out, coeff_fine, sfm_start, sfm_end, sfmsize, last_sfm, prev_hq_mode, bwe_peaks, bin_th, num_sfm, L_core_brate, R, norm,
     521             :                     noise_level, prev_noise_level, bwe_seed, L_coeff_out, 15, 12 );
     522             :     }
     523         377 :     ELSE IF( EQ_16( HQ_mode, HQ_GEN_SWB ) || EQ_16( HQ_mode, HQ_GEN_FB ) )
     524             :     {
     525          46 :         hq_bwe_fx( HQ_mode, L_coeff_out1, hq_generic_fenv, L_coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, sfm_end, num_sfm, num_env_bands, R );
     526             :     }
     527             : 
     528             :     /*----------------------------------------------------------------*
     529             :      * HQ WB BWE refinements
     530             :      *----------------------------------------------------------------*/
     531         397 :     test();
     532         397 :     IF( EQ_16( length, L_FRAME16k ) && LE_32( L_core_brate, HQ_32k ) )
     533             :     {
     534           0 :         hq_wb_nf_bwe_fx( coeff, is_transient, prev_bfi, L_normq_v, num_sfm, sfm_start, sfm_end, sfmsize, last_sfm, R,
     535             :                          prev_is_transient, prev_normq, prev_env, bwe_seed, prev_coeff_out, prev_R, L_coeff_out, prev_env_Q );
     536             :     }
     537             : 
     538             :     /*----------------------------------------------------------------*
     539             :      * Update memories
     540             :      *----------------------------------------------------------------*/
     541             : 
     542         397 :     test();
     543         397 :     IF( NE_16( HQ_mode, HQ_HARMONIC ) && NE_16( HQ_mode, HQ_HVQ ) )
     544             :     {
     545         377 :         prev_noise_level[0] = 3277;
     546         377 :         move16(); /* 0.1 in Q15 */
     547         377 :         prev_noise_level[1] = 3277;
     548         377 :         move16(); /* 0.1 in Q15 */
     549             :     }
     550         397 :     test();
     551         397 :     IF( !( EQ_16( length, L_FRAME16k ) && LE_32( L_core_brate, HQ_32k ) ) )
     552             :     {
     553         397 :         set32_fx( prev_env, 0, SFM_N_WB );
     554         397 :         set32_fx( prev_normq, 0, SFM_N_WB );
     555             :     }
     556             : 
     557         397 :     test();
     558         397 :     IF( EQ_16( length, L_FRAME32k ) && LE_32( L_core_brate, HQ_32k ) )
     559             :     {
     560          66 :         *prev_R = R[SFM_N_WB - 1];
     561          66 :         move16();
     562          66 :         Copy32( L_coeff_out + L_FRAME16k - L_HQ_WB_BWE, prev_coeff_out, L_HQ_WB_BWE );
     563             :     }
     564             : 
     565         397 :     return;
     566             : }

Generated by: LCOV version 1.14