LCOV - code coverage report
Current view: top level - lib_enc - swb_bwe_enc_lr_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ b8e0d5b93229a45388410f93fd14fda7bdd8ab4a Lines: 202 517 39.1 %
Date: 2025-11-08 02:37:03 Functions: 4 9 44.4 %

          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 <stdint.h>
      34             : #include "options.h"
      35             : #include "prot_fx.h"     /* Function prototypes                    */
      36             : #include "prot_fx_enc.h" /* Function prototypes                    */
      37             : #include "rom_com.h"
      38             : #include "stl.h"
      39             : 
      40             : /*--------------------------------------------------------------------------*
      41             :  * GetSubbandCorrIndex2_har()
      42             :  *
      43             :  * Finds the index of best correlation between highband (*inBuf) and lowband (*predBuf) for current subband of length (fLen)
      44             :  *--------------------------------------------------------------------------*/
      45           0 : static Word16 GetSubbandCorrIndex2_har_fx(                               /* o  : best correlation index                            */
      46             :                                            const Word32 *L_inBuf,        /* i  : target buffer (i.e., highband signal) : spectra   */
      47             :                                            const Word16 fLen,            /* i  : window length                                     */
      48             :                                            const Word16 *predBuf_fx,     /* i  : prediction buffer (i.e., lowband) : sspectra      */
      49             :                                            const Word16 predBufLen,      /* i  : sspectra buffer size                              */
      50             :                                            const Word16 maxLag_fx,       /* i  : search length                                     */
      51             :                                            const GainItem_fx *G_item_fx, /* i  :                                                   */
      52             :                                            const Word16 nZero_fx,        /* i  : number of nonzero components used in              */
      53             :                                            Word16 *prev_frame_bstindx_fx /* i  : previous frame best Indices                       */
      54             : )
      55             : {
      56             :     Word16 i, j;
      57             :     Word16 bestIdx_fx;
      58             :     Word32 L_lagCorr_sq;
      59             :     Word32 L_lagEnergy;
      60             : 
      61             :     Word32 L_energy;
      62             :     Word32 L_corr;
      63             :     Word32 L_corr_sq;
      64             : 
      65             :     Word16 corr_sq_hi_fx;
      66             :     Word32 L_corr_sq_tmp;
      67             :     Word32 L_lagCorr_sq_tmp;
      68             :     Word16 corr_sq_fx;
      69             :     Word16 lagCorr_sq_fx;
      70             :     Word32 L_energy_tmp;
      71             :     Word32 L_lagEnergy_tmp;
      72             :     Word16 energy_fx;
      73             :     Word16 lagEnergy_fx;
      74             : 
      75             :     Word16 N1_fx, N2_fx;
      76             :     Word16 exp_safe_e;
      77             : 
      78             :     Word16 exp_corr;
      79             :     Word16 exp_energy;
      80             : 
      81             :     Word32 L_buf;
      82             : 
      83             :     Word16 ibuf_fx[L_FRAME32k];
      84             :     Word16 pbuf_fx[L_FRAME32k];
      85             :     Word16 *ptr_pbuf;
      86             :     Word16 exp_shift;
      87             : 
      88             :     Word16 exp_norm;
      89             : 
      90             :     Word32 L_tmp;
      91             : 
      92             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      93           0 :     Flag Overflow = 0;
      94           0 :     move16();
      95             : #endif
      96             : 
      97           0 :     exp_safe_e = 4;
      98           0 :     move16();
      99             : 
     100           0 :     L_tmp = L_deposit_l( 0 );
     101           0 :     FOR( i = 0; i < fLen; i++ )
     102             :     {
     103           0 :         L_tmp = L_or( L_tmp, L_abs( L_inBuf[i] ) );
     104             :     }
     105           0 :     exp_norm = norm_l( L_tmp );
     106           0 :     exp_shift = sub( exp_norm, exp_safe_e );
     107             : 
     108           0 :     FOR( i = 0; i < fLen; i++ )
     109             :     {
     110           0 :         ibuf_fx[i] = extract_h( L_shl( L_inBuf[i], exp_shift ) ); /* Qi+exp_shift-16 */
     111           0 :         move16();
     112             :     }
     113             : 
     114           0 :     FOR( i = 0; i < predBufLen; i++ )
     115             :     {
     116           0 :         pbuf_fx[i] = shr( predBuf_fx[i], exp_safe_e );
     117           0 :         move16(); /* Qss-exp_safe_e */
     118             :     }
     119             : 
     120           0 :     bestIdx_fx = 0;
     121           0 :     move16();
     122           0 :     L_lagCorr_sq = L_deposit_l( 0 );
     123           0 :     L_lagEnergy = 0x7FFFFFFF;
     124           0 :     move32();
     125             : 
     126           0 :     N1_fx = s_max( 0x0, sub( *prev_frame_bstindx_fx, shr( maxLag_fx, 1 ) ) );
     127           0 :     IF( *prev_frame_bstindx_fx < 0 )
     128             :     {
     129           0 :         N2_fx = sub( maxLag_fx, 1 );
     130             :     }
     131             :     ELSE
     132             :     {
     133           0 :         N2_fx = s_min( sub( maxLag_fx, 1 ), add( *prev_frame_bstindx_fx, shr( maxLag_fx, 1 ) ) );
     134             :     }
     135           0 :     predBuf_fx += N1_fx;
     136           0 :     ptr_pbuf = pbuf_fx + N1_fx;
     137             : 
     138             : 
     139           0 :     Overflow = 0;
     140           0 :     move16();
     141             : 
     142             :     /* find the best lag */
     143           0 :     FOR( i = N1_fx; i <= N2_fx; i++ )
     144             :     {
     145           0 :         L_corr = L_deposit_l( 0 );
     146             : 
     147             :         /* get the energy, remove the old and update with the new energy index */
     148             : 
     149           0 :         L_energy = L_deposit_l( 0 );
     150           0 :         FOR( j = 0; j < fLen; j++ )
     151             :         {
     152             :             /*energy += *predBuf * *predBuf; */
     153           0 :             L_energy = L_mac_o( L_energy, *ptr_pbuf, *ptr_pbuf, &Overflow ); /* Q*2-1; */
     154           0 :             ptr_pbuf++;
     155             :         }
     156             : 
     157           0 :         ptr_pbuf -= fLen;
     158             : 
     159             :         /* get cross-correlation */
     160           0 :         IF( L_energy != 0x0L )
     161             :         {
     162           0 :             L_corr = L_deposit_l( 0 );
     163           0 :             FOR( j = 0; j < nZero_fx; j++ )
     164             :             {
     165             :                 /*corr += inBuf[G_item[j].gainIndex]* predBuf[G_item[j].gainIndex]; */
     166           0 :                 L_corr = L_mac_o( L_corr, ibuf_fx[G_item_fx[j].gainIndex_fx], ptr_pbuf[G_item_fx[j].gainIndex_fx], &Overflow ); /* Q*2-1 */
     167             :             }
     168             : 
     169             :             /*corr_sq = corr*corr; */
     170           0 :             exp_norm = norm_l( L_corr );
     171           0 :             exp_norm = sub( exp_norm, 1 ); /* added for Overflow  0x8000 * 0x8000  -> Overflow */
     172           0 :             L_corr_sq = L_shl( L_corr, exp_norm );
     173           0 :             corr_sq_hi_fx = extract_h( L_corr_sq );
     174             : 
     175           0 :             L_corr_sq = L_mult_o( corr_sq_hi_fx, corr_sq_hi_fx, &Overflow );              /* (((Qhi:Qsh+exp_norm_hi-16)+Qss+1)+exp_norm-16)*2+1 */
     176           0 :             L_corr_sq = L_shr_o( L_corr_sq, s_min( shl( exp_norm, 1 ), 31 ), &Overflow ); /* (QCorr-16)*2+1 */
     177           0 :             if ( Overflow != 0 )
     178             :             {
     179           0 :                 L_corr_sq = 0x0L;
     180           0 :                 move32();
     181             :             }
     182             : 
     183           0 :             Overflow = 0;
     184           0 :             move16();
     185             : 
     186             :             /* normalize for L_lagCorr_sq and L_corr_sq */
     187           0 :             L_buf = L_or( L_lagCorr_sq, L_corr_sq );
     188           0 :             exp_corr = norm_l( L_buf );
     189           0 :             L_corr_sq_tmp = L_shl( L_corr_sq, exp_corr );
     190           0 :             L_lagCorr_sq_tmp = L_shl( L_lagCorr_sq, exp_corr );
     191           0 :             corr_sq_fx = extract_h( L_corr_sq_tmp );
     192           0 :             lagCorr_sq_fx = extract_h( L_lagCorr_sq_tmp );
     193             : 
     194             :             /* normalize for L_lagEnergy and L_energy */
     195           0 :             L_buf = L_or( L_lagEnergy, L_energy );
     196           0 :             exp_energy = norm_l( L_buf );
     197           0 :             L_energy_tmp = L_shl( L_energy, exp_energy );
     198           0 :             L_lagEnergy_tmp = L_shl( L_lagEnergy, exp_energy );
     199           0 :             energy_fx = extract_h( L_energy_tmp );
     200           0 :             lagEnergy_fx = extract_h( L_lagEnergy_tmp );
     201             : 
     202             :             /*if( (double)lagCorr_sq*(double)energy < (double)corr_sq*(double)lagEnergy ) */
     203           0 :             IF( L_msu( L_mult( lagCorr_sq_fx, energy_fx ), corr_sq_fx, lagEnergy_fx ) < 0 )
     204             :             {
     205           0 :                 bestIdx_fx = i;
     206           0 :                 move16();
     207           0 :                 L_lagCorr_sq = L_add( L_corr_sq, 0 );
     208           0 :                 L_lagEnergy = L_add( L_energy, 0 );
     209             :             }
     210             :         }
     211           0 :         predBuf_fx++;
     212           0 :         ptr_pbuf++;
     213             :     }
     214             : 
     215           0 :     test();
     216           0 :     IF( L_lagCorr_sq == 0x0 && *prev_frame_bstindx_fx < 0 )
     217             :     {
     218           0 :         bestIdx_fx = 0x0;
     219           0 :         move16();
     220             :     }
     221             :     ELSE
     222             :     {
     223           0 :         if ( L_lagCorr_sq == 0x0 )
     224             :         {
     225           0 :             bestIdx_fx = *prev_frame_bstindx_fx;
     226           0 :             move16();
     227             :         }
     228             :     }
     229             : 
     230           0 :     *prev_frame_bstindx_fx = bestIdx_fx;
     231           0 :     move16();
     232             : 
     233           0 :     return bestIdx_fx;
     234             : }
     235             : 
     236             : /*--------------------------------------------------------------------------*
     237             :  * getswbindices_har()
     238             :  *
     239             :  * Finds the pulse index of best correlation between highband (*yos) and lowband (*y2) for two groups of length sbLen
     240             :  *--------------------------------------------------------------------------*/
     241             : 
     242           0 : static void getswbindices_har_fx(
     243             :     const Word32 *L_yos,                   /* i  : original input spectrum   */
     244             :     Word16 exp_refBuf,                     /* i  :                           */
     245             :     Word16 *y2_fx,                         /* i  : decoded spectrum          */
     246             :     const Word16 nBands_search_fx,         /* i  : number of bands           */
     247             :     Word16 *lagIndices_fx,                 /* o  : pulse index               */
     248             :     Word16 *prev_frame_bstindx_fx,         /* i/o: prev frame index          */
     249             :     const Word16 swb_lowband_fx,           /* i  : length of the LF spectrum */
     250             :     const Word16 *subband_offsets_fx,      /* i  :                           */
     251             :     const Word16 *sbWidth_fx,              /* i  :                           */
     252             :     const Word16 *subband_search_offset_fx /* i  :                           */
     253             : )
     254             : {
     255             :     Word16 i, j, k, sb, tmp;
     256             :     Word16 *ptr_predBuf;
     257             :     GainItem_fx Nbiggest_fx[(NB_SWB_SUBBANDS_HAR_SEARCH_SB) *N_NBIGGEST_PULSEARCH];
     258             :     Word16 n_nbiggestsearch_fx[NB_SWB_SUBBANDS_HAR];
     259             : 
     260             :     Word16 search_offset_fx[NB_SWB_SUBBANDS_HAR_SEARCH_SB];
     261             :     Word16 nlags_fx[NB_SWB_SUBBANDS_HAR_SEARCH_SB];
     262             : 
     263             :     Word16 low_freqsgnl_fx[L_FRAME32k]; /* Qy2 (sspectra) */
     264             : 
     265           0 :     ptr_predBuf = y2_fx;
     266             : 
     267             :     /* Get the number of HF groups for performing Similarity search */
     268           0 :     FOR( sb = 0; sb < nBands_search_fx; sb++ )
     269             :     {
     270             :         /*nlags[sb] = (short)pow(2, bits_lagIndices_mode0_Har[sb]); */
     271           0 :         nlags_fx[sb] = shl( 1, bits_lagIndices_mode0_Har[sb] );
     272           0 :         move16();
     273             :     }
     274             : 
     275           0 :     j = 0;
     276           0 :     move16();
     277           0 :     FOR( sb = 0; sb < nBands_search_fx; sb++ )
     278             :     {
     279             :         /* Find NBiggest samples in HF Groups */
     280           0 :         FindNBiggest2_simple_fx_har( L_yos + add( swb_lowband_fx, subband_offsets_fx[sb] ), exp_refBuf, Nbiggest_fx + j,
     281           0 :                                      sbWidth_fx[sb], &n_nbiggestsearch_fx[sb], N_NBIGGEST_PULSEARCH );
     282             : 
     283           0 :         search_offset_fx[sb] = subband_search_offset_fx[sb];
     284           0 :         move16();
     285           0 :         j = add( j, N_NBIGGEST_PULSEARCH );
     286             :     }
     287             : 
     288             :     /* Similarity Search for the HF spectrum */
     289           0 :     FOR( sb = 0; sb < nBands_search_fx; sb++ )
     290             :     {
     291           0 :         IF( sb == 0 )
     292             :         {
     293             :             /* copy SSmoothed LF Spectrum */
     294           0 :             ptr_predBuf = y2_fx + sub( search_offset_fx[sb], shr( nlags_fx[sb], 1 ) );
     295           0 :             tmp = add( sbWidth_fx[sb], nlags_fx[sb] );
     296           0 :             FOR( i = 0; i < tmp; i++ )
     297             :             {
     298           0 :                 low_freqsgnl_fx[i] = *ptr_predBuf++;
     299           0 :                 move16();
     300             :             }
     301             :         }
     302             :         ELSE
     303             :         {
     304             :             /* copy SSmoothed LF Spectrum */
     305           0 :             k = 0;
     306           0 :             move16();
     307           0 :             tmp = sub( search_offset_fx[sb], add( sbWidth_fx[sb], shr( nlags_fx[sb], 1 ) ) );
     308           0 :             FOR( j = add( search_offset_fx[sb], shr( nlags_fx[sb], 1 ) ); j > tmp; j-- )
     309             :             {
     310           0 :                 low_freqsgnl_fx[k] = y2_fx[j];
     311           0 :                 move16();
     312           0 :                 k++;
     313             :             }
     314             :         }
     315             :         /* correlation b/w HF spectrum Group1 of length sbLen and decoded LF spectrum */
     316           0 :         lagIndices_fx[sb] = (Word16) GetSubbandCorrIndex2_har_fx( L_yos + add( swb_lowband_fx, subband_offsets_fx[sb] ),
     317           0 :                                                                   sbWidth_fx[sb],
     318             :                                                                   low_freqsgnl_fx,
     319           0 :                                                                   add( sbWidth_fx[sb], nlags_fx[sb] ),
     320           0 :                                                                   nlags_fx[sb], Nbiggest_fx + ( sb * N_NBIGGEST_PULSEARCH ),
     321           0 :                                                                   n_nbiggestsearch_fx[sb], &prev_frame_bstindx_fx[sb] );
     322           0 :         move16();
     323             :     }
     324             : 
     325           0 :     return;
     326             : }
     327             : /*--------------------------------------------------------------------------*
     328             :  * GetSubbandCorrIndex2_pulsestep_fx()
     329             :  *
     330             :  *--------------------------------------------------------------------------*/
     331             : 
     332         152 : static Word16 GetSubbandCorrIndex2_pulsestep_fx(
     333             :     const Word32 *L_inBuf,       /* i: original input vector (highband)                 */
     334             :     const Word16 *predBuf_fx,    /* i: spectrum smoothing vector                        */
     335             :     const Word16 *predBufMa_fx,  /* i: moving averaged spectrum smoothing vector  Q=Qss */
     336             :     const Word16 fLen,           /* i: subband length of highband                       */
     337             :     const Word16 maxLag,         /* i: number of search pulse number                    */
     338             :     const GainItem_fx *gi_fx,    /* i: lag gain structure                               */
     339             :     const Word16 nZero,          /* i:                                                  */
     340             :     const Word16 ssearch_buflim, /* i: length of search buffer                          */
     341             :     const Word16 *predBuf_ni_fx  /* i: spectrum including noise smoothing vector        */
     342             : )
     343             : {
     344             :     Word16 i, j;
     345             :     Word16 absPos_fx;
     346             :     Word16 bestIdx_fx;
     347             :     Word32 L_lagCorr_sq;
     348             :     Word32 L_lagEnergy;
     349             : 
     350             :     const Word16 *ptr_predBuf;
     351             : 
     352             :     Word32 L_energy;
     353             :     Word32 L_corr;
     354             :     Word16 corr_fx;
     355             : 
     356             :     Word32 L_corr_sq;
     357             : 
     358             : 
     359             :     Word16 hiBuf_fx[L_FRAME32k];
     360             :     Word16 exp_norm_hi;
     361             : 
     362             :     Word16 exp_norm;
     363             :     Word32 L_corr_sq_tmp;
     364             :     Word32 L_lagCorr_sq_tmp;
     365             :     Word16 corr_sq_fx;
     366             :     Word16 lagCorr_sq_fx;
     367             :     Word32 L_energy_tmp;
     368             :     Word32 L_lagEnergy_tmp;
     369             :     Word16 energy_fx;
     370             :     Word16 lagEnergy_fx;
     371             : 
     372             :     Word16 ib_flag_fx;
     373             : 
     374             :     Word32 L_buf;
     375             :     Word32 L_buf2;
     376             :     Word32 L_temp;
     377             : 
     378             :     Word16 ssBuf_fx[L_FRAME32k];
     379             :     Word16 ssBuf_ni_fx[L_FRAME32k];
     380             :     Word16 *ptr_ssBuf_ni_fx;
     381             :     Word16 exp_norm_ss;
     382             : 
     383         152 :     set16_fx( hiBuf_fx, 0x0, L_FRAME32k );
     384         152 :     set16_fx( ssBuf_fx, 0x0, L_FRAME32k );
     385             : 
     386         152 :     ib_flag_fx = 0;
     387         152 :     move16();
     388             : 
     389         152 :     absPos_fx = 0;
     390         152 :     move16();
     391         152 :     bestIdx_fx = -1;
     392         152 :     move16();
     393         152 :     L_lagCorr_sq = L_deposit_l( 0 );
     394         152 :     L_lagEnergy = 0x7FFFFFFFL;
     395         152 :     move32();
     396             : 
     397         152 :     ptr_predBuf = predBuf_fx;
     398             :     /* This part must be computed on parent function. */
     399         152 :     exp_norm_ss = 2;
     400         152 :     move16();
     401             : 
     402         152 :     j = add( ssearch_buflim, fLen );
     403       34200 :     FOR( i = 0; i < j; i++ )
     404             :     {
     405       34048 :         ssBuf_fx[i] = shr( predBuf_fx[i], exp_norm_ss );
     406       34048 :         move16(); /* Qss+exp_norm_ss */
     407       34048 :         ssBuf_ni_fx[i] = shr( predBuf_ni_fx[i], exp_norm_ss );
     408       34048 :         move16(); /* Qss+exp_norm_ss */
     409             :     }
     410             : 
     411         152 :     L_temp = L_deposit_l( 0 );
     412       12008 :     FOR( i = 0; i < fLen; i++ )
     413             :     {
     414       11856 :         L_temp = L_or( L_temp, L_abs( L_inBuf[i] ) );
     415             :     }
     416         152 :     exp_norm_hi = norm_l( L_temp );
     417         152 :     exp_norm_hi = sub( exp_norm_hi, 3 ); /* max 109 < 2^7 , sspectrum is sparse, it is't need 4 */
     418             : 
     419       12008 :     FOR( i = 0; i < fLen; i++ )
     420             :     {
     421       11856 :         hiBuf_fx[i] = extract_h( L_shl( L_inBuf[i], exp_norm_hi ) );
     422       11856 :         move16(); /* Qsh+exp_norm_hi-16 */
     423             :     }
     424             : 
     425             :     /* Get the initial energy for zero lag */
     426         152 :     test();
     427         780 :     WHILE( *ptr_predBuf == 0 && LT_16( absPos_fx, ssearch_buflim ) )
     428             :     {
     429         628 :         test();
     430         628 :         ptr_predBuf++;
     431         628 :         absPos_fx = add( absPos_fx, 1 );
     432             :     }
     433             : 
     434         152 :     IF( EQ_16( absPos_fx, ssearch_buflim ) )
     435             :     {
     436           0 :         ptr_predBuf--;
     437           0 :         absPos_fx = sub( absPos_fx, 1 );
     438             :     }
     439             : 
     440         152 :     ptr_ssBuf_ni_fx = ssBuf_ni_fx + absPos_fx;
     441         152 :     L_energy = L_deposit_l( 0 );
     442       12008 :     FOR( i = 0; i < fLen; i++ )
     443             :     {
     444       11856 :         L_energy = L_mac( L_energy, *ptr_ssBuf_ni_fx, *ptr_ssBuf_ni_fx ); /* (Qss-exp_norm_ss)*2+1 */
     445       11856 :         ptr_ssBuf_ni_fx++;
     446             :     }
     447             : 
     448         152 :     ptr_ssBuf_ni_fx -= fLen;
     449             : 
     450         152 :     L_lagEnergy = L_add( L_energy, 0 );
     451             : 
     452             :     /* Find the best lag */
     453         608 :     FOR( i = 0; i < maxLag; i++ )
     454             :     {
     455         456 :         L_corr = L_deposit_l( 0 );
     456             : 
     457             :         /* Get the energy, remove the old and update with the new energy index */
     458         456 :         L_energy = L_deposit_l( 0 );
     459       33516 :         FOR( j = 0; j < fLen; j++ )
     460             :         {
     461       33060 :             L_energy = L_mac( L_energy, *ptr_ssBuf_ni_fx, *ptr_ssBuf_ni_fx );
     462       33060 :             ptr_ssBuf_ni_fx++;
     463             :         }
     464         456 :         ptr_ssBuf_ni_fx -= fLen;
     465             : 
     466             :         /* Get cross-correlation */
     467         456 :         IF( L_energy != 0x0L )
     468             :         {
     469         456 :             L_corr = L_deposit_l( 0 );
     470        8624 :             FOR( j = 0; j < nZero; j++ )
     471             :             {
     472             :                 /*corr += inBuf[G_item[j].gainIndex]* predBufMa[G_item[j].gainIndex]; */
     473        8168 :                 L_corr = L_mac( L_corr, hiBuf_fx[gi_fx[j].gainIndex_fx], predBufMa_fx[gi_fx[j].gainIndex_fx] ); /* Qsh+Qss+1 */
     474             :             }
     475             : 
     476             :             /*corr_sq = corr*corr; */
     477         456 :             exp_norm = norm_l( L_corr );
     478         456 :             exp_norm = sub( exp_norm, 1 ); /* added for Overflow  0x8000 * 0x8000  -> Overflow */
     479         456 :             L_corr_sq = L_shl( L_corr, exp_norm );
     480         456 :             corr_fx = extract_h( L_corr_sq );
     481         456 :             L_corr_sq = L_mult( corr_fx, corr_fx );                          /* (((Qhi:Qsh+exp_norm_hi-16)+Qss+1)+exp_norm-16)*2+1 */
     482         456 :             L_corr_sq = L_shr( L_corr_sq, s_min( shl( exp_norm, 1 ), 31 ) ); /* (QCorr-16)*2+1 */
     483             : 
     484             :             /*if( (lagCorr_sq == 0.0f && corr_sq == 0.0f) || (double)lagCorr_sq*(double)energy < (double)corr_sq*(double)lagEnergy ) */
     485             :             /*{ */
     486             :             /*    bestIdx = i; */
     487             :             /*    bestAbsPos = absPos; */
     488             :             /*    lagCorr_sq = corr_sq; */
     489             :             /*    lagCorr = corr; */
     490             :             /*    lagEnergy = energy; */
     491             :             /*} */
     492             :             /* normalize for L_lagCorr_sq and L_corr_sq */
     493         456 :             L_buf = L_or( L_lagCorr_sq, L_corr_sq );
     494         456 :             exp_norm = norm_l( L_buf ); /* overflow allowed */
     495         456 :             L_corr_sq_tmp = L_shl( L_corr_sq, exp_norm );
     496         456 :             L_lagCorr_sq_tmp = L_shl( L_lagCorr_sq, exp_norm );
     497         456 :             corr_sq_fx = extract_h( L_corr_sq_tmp );
     498         456 :             lagCorr_sq_fx = extract_h( L_lagCorr_sq_tmp );
     499             : 
     500             :             /* normalize for L_lagEnergy and L_energy */
     501         456 :             L_buf = L_or( L_lagEnergy, L_energy );
     502         456 :             exp_norm = norm_l( L_buf ); /* overflow allowed */
     503         456 :             L_energy_tmp = L_shl( L_energy, exp_norm );
     504         456 :             L_lagEnergy_tmp = L_shl( L_lagEnergy, exp_norm );
     505         456 :             energy_fx = extract_h( L_energy_tmp );
     506         456 :             lagEnergy_fx = extract_h( L_lagEnergy_tmp );
     507             : 
     508         456 :             L_buf = L_or( L_lagCorr_sq, L_corr_sq );
     509         456 :             L_buf2 = L_msu( L_mult( lagCorr_sq_fx, energy_fx ), corr_sq_fx, lagEnergy_fx );
     510         456 :             test();
     511         456 :             IF( L_buf == 0 || L_buf2 < 0 )
     512             :             {
     513         348 :                 bestIdx_fx = i;
     514         348 :                 move16();
     515         348 :                 L_lagCorr_sq = L_add( L_corr_sq, 0 );
     516         348 :                 L_lagEnergy = L_add( L_energy, 0 );
     517             :             }
     518             :         }
     519         456 :         ptr_predBuf++;
     520         456 :         ptr_ssBuf_ni_fx++;
     521         456 :         absPos_fx++;
     522         456 :         test();
     523        1642 :         WHILE( *ptr_predBuf == 0 && LT_16( absPos_fx, ssearch_buflim ) )
     524             :         {
     525        1186 :             test();
     526        1186 :             ptr_predBuf++;
     527        1186 :             ptr_ssBuf_ni_fx++;
     528        1186 :             absPos_fx = add( absPos_fx, 1 );
     529             :         }
     530             : 
     531         456 :         IF( GE_16( absPos_fx, ssearch_buflim ) )
     532             :         {
     533           0 :             if ( EQ_16( bestIdx_fx, -1 ) )
     534             :             {
     535           0 :                 ib_flag_fx = 1;
     536           0 :                 move16();
     537             :             }
     538             : 
     539           0 :             BREAK;
     540             :         }
     541             :     }
     542             : 
     543         152 :     if ( EQ_16( ib_flag_fx, 1 ) )
     544             :     {
     545           0 :         bestIdx_fx = 0;
     546           0 :         move16();
     547             :     }
     548             : 
     549         152 :     return bestIdx_fx;
     550             : }
     551             : /*--------------------------------------------------------------------------*
     552             :  * GetSWBIndices_fx()
     553             :  *
     554             :  *--------------------------------------------------------------------------*/
     555          38 : static void GetSWBIndices_fx(
     556             :     const Word16 *predBuf_fx,      /* i  : low-frequency band                  */
     557             :     /*const Word16 Qss,*/          /* i  : Q value of predBuf_fx               */
     558             :     const Word32 *L_targetBuf,     /* i  : SWB MDCT coeff.                     */
     559             :     const Word16 Qsh,              /* i  : Q value of L_targetBuf              */
     560             :     const Word16 nBands_search,    /* i  : number of search subbands           */
     561             :     const Word16 *sbWidth,         /* i  : subband lengths                     */
     562             :     Word16 *lagIndices,            /* o  : selected lags for subband coding    */
     563             :     const Word16 predBufLen,       /* i  : low-frequency band length           */
     564             :     GainItem_fx *gi_fx,            /* o  : most representative region          */
     565             :     const Word16 *subband_offsets, /* o  : N biggest components                */
     566             :     Word16 *predBuf_ni_fx          /* i  : low-frequency band filled noise     */
     567             : )
     568             : {
     569             :     Word16 j;
     570             :     Word16 sb, tmp;
     571             :     Word16 sbLen;
     572             :     Word16 n_nbiggestsearch_fx[NB_SWB_SUBBANDS];
     573             :     Word16 ssearch_buflim_fx;
     574             :     Word16 search_offset_fx[NB_SWB_SUBBANDS];
     575             :     Word16 nlags_fx[NB_SWB_SUBBANDS];
     576             : 
     577             :     Word16 exp_refBuf;
     578             :     Word16 sspectra_ma_fx[L_FRAME32k];
     579             : 
     580             : 
     581             :     Word32 L_temp;
     582             : 
     583             : 
     584             :     /* Initializations */
     585          38 :     exp_refBuf = Qsh;
     586             : 
     587          38 :     j = 0;
     588          38 :     move16();
     589         190 :     FOR( sb = 0; sb < nBands_search; sb++ )
     590             :     {
     591         152 :         FindNBiggest2_simple_fx_har( L_targetBuf + subband_offsets[sb], exp_refBuf, gi_fx + j, sbWidth[sb], &n_nbiggestsearch_fx[sb], N_NBIGGEST_PULSEARCH );
     592             : 
     593         152 :         j = add( j, N_NBIGGEST_PULSEARCH );
     594         152 :         move16();
     595             :     }
     596             : 
     597             :     /* Selection of most representative subband (full search) */
     598         190 :     FOR( sb = 0; sb < nBands_search; sb++ )
     599             :     {
     600         152 :         nlags_fx[sb] = shl( 1, bits_lagIndices_modeNormal[sb] );
     601         152 :         move16();
     602             :     }
     603             : 
     604         190 :     FOR( sb = 0; sb < nBands_search; sb++ )
     605             :     {
     606         152 :         search_offset_fx[sb] = subband_search_offsets[sb];
     607         152 :         move16();
     608             :     }
     609             : 
     610          38 :     sspectra_ma_fx[0] = add( shr( predBuf_ni_fx[0], 1 ), shr( predBuf_ni_fx[1], 1 ) );
     611          38 :     move16();
     612          38 :     tmp = sub( predBufLen, 1 );
     613        9690 :     FOR( sb = 1; sb < tmp; sb++ )
     614             :     {
     615             :         /*sspectra_ma[sb] = (predBuf[sb-1] + predBuf[sb] + predBuf[sb+1])/3.0f; */
     616        9652 :         L_temp = L_mult( predBuf_ni_fx[sb], 10922 ); /* 10922 = 0.33333 (Q15) */
     617        9652 :         L_temp = L_add( L_temp, L_mult( predBuf_ni_fx[sb - 1], 10922 ) );
     618        9652 :         L_temp = L_add( L_temp, L_mult( predBuf_ni_fx[sb + 1], 10922 ) ); /* Qss+15+1 */
     619        9652 :         sspectra_ma_fx[sb] = round_fx( L_temp );
     620        9652 :         move16();
     621             :     }
     622          38 :     sspectra_ma_fx[sb] = add( shr( predBuf_ni_fx[sb - 1], 1 ), shr( predBuf_ni_fx[sb], 1 ) );
     623          38 :     move16();
     624             : 
     625             :     /* Partial search for rest of subbands except the last which is fixed */
     626         190 :     FOR( sb = 0; sb < nBands_search; sb++ )
     627             :     {
     628         152 :         sbLen = sbWidth[sb];
     629         152 :         ssearch_buflim_fx = sub( predBufLen, add( sbLen, search_offset_fx[sb] ) );
     630         304 :         lagIndices[sb] = GetSubbandCorrIndex2_pulsestep_fx(
     631         152 :             L_targetBuf + subband_offsets[sb],
     632         152 :             predBuf_fx + search_offset_fx[sb],
     633         152 :             sspectra_ma_fx + search_offset_fx[sb],
     634         152 :             sbLen, nlags_fx[sb], gi_fx + ( sb * N_NBIGGEST_PULSEARCH ),
     635         152 :             n_nbiggestsearch_fx[sb],
     636         152 :             ssearch_buflim_fx, predBuf_ni_fx + search_offset_fx[sb] );
     637         152 :         move16();
     638             :     }
     639          38 : }
     640             : /*--------------------------------------------------------------------------*
     641             :  * gethar_noisegn_fx()
     642             :  *
     643             :  *--------------------------------------------------------------------------*/
     644             : 
     645           0 : static void gethar_noisegn_fx(
     646             :     BSTR_ENC_HANDLE hBstr,                /* i/o: bitstream handle            */
     647             :     const Word32 L_spectra[],             /* i   : Qs   input MDCT                          */
     648             :     const Word16 QsL,                     /* i   : Q0   Q value for L_spectra, L_xSynth_har */
     649             :     const Word16 noise_flr_fx[],          /* i   : Qss  noise floor                         */
     650             :     const Word16 Qss,                     /* i   : Q0   Q value for noise_flr_fx, sspectra  */
     651             :     Word32 L_xSynth_har[],                /* o   : Qs   output SWB MDCT                     */
     652             :     const Word16 sbWidth[],               /* i   : Q0   band width for SWB                  */
     653             :     const Word16 lagIndices[],            /* i   : Q0   lag Indices                         */
     654             :     const Word16 bands,                   /* i   : Q0   all band number                     */
     655             :     const Word16 har_bands,               /* i   : Q0   harmonic band number                */
     656             :     const Word16 fLenLow,                 /* i   : Q0   low frequency band width            */
     657             :     const Word16 fLenHigh,                /* i   : Q0   SWB band width                      */
     658             :     const Word16 subband_offsets[],       /* i   : Q0   offset                              */
     659             :     const Word16 subband_search_offset[], /* i   : Q0   offset                              */
     660             :     const Word16 band_start[],            /* i   : Q0   band start array                    */
     661             :     const Word16 band_end[],              /* i   : Q0   band end array                      */
     662             :     const Word16 band_width[],            /* i   : Q0   band width                          */
     663             :     Word32 L_band_energy[],               /* i   : Qbe  band energy (Log scale)             */
     664             :     const Word16 Qbe,                     /* i   : Q0   Q value for L_band_energy           */
     665             :     Word32 L_be_tonal[],                  /* o   : QbeL tonal energy                        */
     666             :     Word16 *QbeL,                         /* o   : Q0   Q value for L_be_tonal              */
     667             :     const Word16 *sspectra_fx,            /* i   : Qss  smoothed spectrum                   */
     668             :     const Word16 har_freq_est2,           /* i   : Q0   for harmonic structure              */
     669             :     const Word16 pos_max_hfe2,            /* i/o : Q0   for harmonic structure              */
     670             :     Word16 *pul_res_fx,                   /* o   : Q0                                       */
     671             :     GainItem_fx pk_sf_fx[]                /* o   :                                          */
     672             : )
     673             : {
     674             :     Word16 i;
     675             : 
     676             :     Word32 L_xSynth_har_sft[L_FRAME32k];
     677             :     Word32 L_hfspec_sft[L_FRAME32k];
     678             : 
     679             :     Word32 L_hfspec[L_FRAME32k];
     680             : 
     681             :     GainItem_fx get_pk_fx[N_NBIGGEST_SEARCH_LRG_B];
     682             :     Word16 n_nbiggestsearch_fx, imin_fx, gqlevs_fx;
     683             : 
     684             :     Word32 L_g1, L_g2;
     685             :     Word16 exp_safe;
     686             :     Word32 L_temp;
     687             : 
     688             :     Word16 exp_normn, exp_normd;
     689             :     Word16 temp_fx;
     690             :     Word16 div_fx;
     691             : 
     692             :     Word16 exp_norm_g1, exp_norm_g2;
     693             :     Word16 sqrt_fx, Qsqrt;
     694             :     Word16 g_fx;
     695             :     Word16 exp, frac;
     696             : 
     697             :     Word16 dmin_fx, d_fx;
     698             : 
     699             :     Word16 temp_lo, temp_hi;
     700             :     Word16 Qg;
     701             : 
     702             :     /*Generate HF noise*/
     703           0 :     genhf_noise_fx( noise_flr_fx, Qss, L_xSynth_har, QsL, sspectra_fx, bands, har_bands, har_freq_est2, pos_max_hfe2, pul_res_fx, pk_sf_fx, fLenLow,
     704             :                     fLenHigh, sbWidth, lagIndices, subband_offsets, subband_search_offset );
     705             : 
     706           0 :     Copy32( &L_spectra[fLenLow], L_hfspec, fLenHigh );
     707           0 :     FindNBiggest2_simple_fx_har( L_hfspec, QsL, get_pk_fx, fLenHigh, &n_nbiggestsearch_fx, N_NBIGGEST_SEARCH_LRG_B );
     708           0 :     FOR( i = 0; i < n_nbiggestsearch_fx; i++ )
     709             :     {
     710           0 :         L_hfspec[get_pk_fx[i].gainIndex_fx] = 0x0;
     711           0 :         move16();
     712             :     }
     713             : 
     714           0 :     L_temp = 0x0;
     715           0 :     move32();
     716           0 :     FOR( i = 0; i < fLenHigh; i++ )
     717             :     {
     718           0 :         L_temp = L_or( L_temp, L_abs( L_hfspec[i] ) );
     719             :     }
     720           0 :     exp_norm_g1 = norm_l( L_temp );
     721           0 :     FOR( i = 0; i < fLenHigh; i++ )
     722             :     {
     723           0 :         L_hfspec_sft[i] = L_shl( L_hfspec[i], exp_norm_g1 );
     724           0 :         move32();
     725             :     }
     726             : 
     727           0 :     L_temp = 0x0;
     728           0 :     move32();
     729           0 :     FOR( i = 0; i < fLenHigh; i++ )
     730             :     {
     731           0 :         L_temp = L_or( L_temp, L_abs( L_xSynth_har[i] ) );
     732             :     }
     733           0 :     exp_norm_g2 = norm_l( L_temp );
     734           0 :     FOR( i = 0; i < fLenHigh; i++ )
     735             :     {
     736           0 :         L_xSynth_har_sft[i] = L_shl( L_xSynth_har[i], exp_norm_g2 );
     737           0 :         move32();
     738             :     }
     739             : 
     740           0 :     exp_safe = 4;
     741           0 :     move16();
     742           0 :     L_g1 = L_deposit_l( 0 );
     743           0 :     L_g2 = L_deposit_l( 0 );
     744           0 :     FOR( i = 0; i < fLenHigh; i++ )
     745             :     {
     746           0 :         temp_fx = round_fx( L_shr( L_hfspec_sft[i], exp_safe ) );
     747           0 :         L_g1 = L_mac( L_g1, temp_fx, temp_fx ); /* 4: safe shift */
     748           0 :         temp_fx = round_fx( L_shr( L_xSynth_har_sft[i], exp_safe ) );
     749           0 :         L_g2 = L_mac( L_g2, temp_fx, temp_fx ); /* 4: safe shift */
     750             :     }
     751             : 
     752             :     /*g = (float) log10(sqrt(g1/g2));*/
     753             :     /* Div Part */
     754           0 :     exp_normn = norm_l( L_g1 );
     755           0 :     exp_normn = sub( exp_normn, 1 );
     756           0 :     exp_normd = norm_l( L_g2 );
     757           0 :     temp_fx = extract_h( L_shl( L_g2, exp_normd ) );
     758           0 :     exp_normd = sub( exp_normd, 16 );
     759             : 
     760           0 :     imin_fx = 0;
     761           0 :     move16();
     762           0 :     test();
     763           0 :     IF( L_g1 != 0 && temp_fx != 0x0 )
     764             :     {
     765           0 :         div_fx = div_l( L_shl( L_g1, exp_normn ), temp_fx );
     766             :         /* SQRT Part */
     767           0 :         sqrt_32n_16_fx( L_deposit_h( div_fx ), add( add( sub( exp_normn, exp_normd ), shl( sub( exp_norm_g1, exp_norm_g2 ), 1 ) ), 15 ), &sqrt_fx, &Qsqrt ); /* (exp_normn-exp_normd+(exp_norm_g1-exp_norm_g2)*2 -1)+16 */
     768             : 
     769             :         /* Log10 Part */
     770           0 :         g_fx = 0x0;
     771           0 :         move16();
     772           0 :         IF( sqrt_fx > 0x0 )
     773             :         {
     774           0 :             L_temp = L_deposit_l( sqrt_fx );
     775             : 
     776           0 :             exp = norm_l( L_temp );
     777           0 :             frac = Log2_norm_lc( L_shl( L_temp, exp ) );
     778           0 :             exp = sub( 30, exp );
     779           0 :             exp = sub( exp, Qsqrt );
     780           0 :             L_temp = L_Comp( exp, frac );
     781             : 
     782           0 :             L_temp = Mpy_32_16_1( L_temp, 19728 ); /* log(2)/log(10)=.30102999566398119521 = 19728.3(Q16)    Q(0+16+1)=Q17 */
     783           0 :             L_temp = L_shl_sat( L_temp, 13 );      /* Q17+13=30    30-16=14 */
     784           0 :             g_fx = round_fx_sat( L_temp );
     785             :         }
     786             : 
     787           0 :         gqlevs_fx = 4;
     788           0 :         move16();
     789           0 :         dmin_fx = 32767;
     790           0 :         move16();
     791           0 :         imin_fx = 0;
     792           0 :         move16();
     793             : 
     794           0 :         FOR( i = 0; i < gqlevs_fx; i++ )
     795             :         {
     796           0 :             d_fx = abs_s( g_fx - gain_table_SWB_BWE_fx[i] );
     797           0 :             IF( LT_16( d_fx, dmin_fx ) )
     798             :             {
     799           0 :                 dmin_fx = d_fx;
     800           0 :                 move16();
     801           0 :                 imin_fx = i;
     802           0 :                 move16();
     803             :             }
     804             :         }
     805             :     }
     806             : 
     807           0 :     push_indice( hBstr, IND_NOISEG, imin_fx, 2 );
     808             : 
     809             :     /*g=(float) pow (10.0f,gain_table[imin]);*/
     810           0 :     L_temp = L_mult( gain_table_SWB_BWE_fx[imin_fx], 27213 ); /* Q14+Q13+1=Q28  log(10)/log(2)=3.3219 27213.23(Q13) */
     811           0 :     L_temp = L_shr( L_temp, 12 );                             /* Q28-Q12 -> Q16 */
     812           0 :     temp_lo = L_Extract_lc( L_temp, &temp_hi );
     813           0 :     Qg = sub( 14, temp_hi );
     814           0 :     g_fx = extract_l( Pow2( 14, temp_lo ) );
     815           0 :     g_fx = shl( g_fx, sub( 11, Qg ) );
     816             : 
     817           0 :     ton_ene_est_fx(
     818             :         L_xSynth_har, QsL, L_be_tonal, QbeL, L_band_energy, Qbe,
     819             :         band_start, band_end, band_width, fLenLow, fLenHigh, bands, har_bands, g_fx,
     820             :         pk_sf_fx, Qss, pul_res_fx );
     821             : 
     822           0 :     return;
     823             : }
     824             : /*--------------------------------------------------------------------------*
     825             :  * EncodeSWBSubbands()
     826             :  *
     827             :  * Main routine for generic SWB coding. High-frequency subband
     828             :  * replicated based on the lowband signal. A search is perform
     829             :  * find lowband indices denoting the selected lowband subband.
     830             :  *--------------------------------------------------------------------------*/
     831          38 : static void EncodeSWBSubbands_fx(
     832             :     Encoder_State *st_fx,                   /* i/o: encoder state structure                     */
     833             :     Word32 *L_spectra,                      /* i/o: MDCT domain spectrum                        */
     834             :     Word16 QsL,                             /* i  : Q value for L_spectra                       */
     835             :     const Word16 fLenLow_fx,                /* i  : lowband length                              */
     836             :     const Word16 fLenHigh_fx,               /* i  : highband length                             */
     837             :     const Word16 nBands_fx,                 /* i  : number of subbands                          */
     838             :     const Word16 nBands_search_fx,          /* i  : number of subbands to be searched for BWE   */
     839             :     const Word16 *sbWidth_fx,               /* i  : subband lengths                             */
     840             :     const Word16 *subband_offsets_fx,       /* i  : Subband offset for BWE                      */
     841             :     Word16 *lagIndices_fx,                  /* o  : lowband index for each subband              */
     842             :     const Word16 BANDS_fx,                  /* i  : noise estimate from WB part                 */
     843             :     const Word16 *band_start_fx,            /* i  : Number subbands/Frame                       */
     844             :     const Word16 *band_end_fx,              /* i  : Band Start of each SB                       */
     845             :     Word32 *L_band_energy,                  /* i  : Band end of each SB, :Qbe                   */
     846             :     Word16 Qbe,                             /* i  : Q value of band energy                      */
     847             :     const Word16 *p2a_flags_fx,             /* i  : BAnd energy of each SB                      */
     848             :     const Word16 hqswb_clas_fx,             /* i  : lowband synthesis                           */
     849             :     Word16 *prev_frm_index_fx,              /* i  : clas information                            */
     850             :     const Word16 har_bands_fx,              /* i/o: Index of the previous Frame                 */
     851             :     const Word16 *subband_search_offset_fx, /* i  : Number of harmonic LF bands                 */
     852             :     Word16 *prev_frm_hfe2,                  /* i/o:                                             */
     853             :     Word16 *prev_stab_hfe2,                 /* i/o:                                             */
     854             :     const Word16 band_width_fx[],           /* i  : band width                                  */
     855             :     const Word32 L_spectra_ni[],            /* i  : Qs noise injected spectra                   */
     856             :     Word16 *ni_seed_fx                      /* i/o: random seed                                 */
     857             : )
     858             : {
     859             :     Word16 i, k;
     860             :     Word16 sspectra_fx[L_FRAME32k];
     861             :     Word16 sspectra_ni_fx[L_FRAME32k];
     862             :     Word16 sspectra_diff_fx[L_FRAME32k];
     863             :     Word16 Qss;                      /* Q value of Smoothed Spectrum low-subband */
     864             :     Word32 L_be_tonal[SWB_HAR_RAN1]; /* Q */
     865             :     Word16 ss_min_fx;                /* Qss */
     866             :     Word32 L_th_g[NB_SWB_SUBBANDS];
     867             :     Word16 QbeL;
     868             :     GainItem_fx pk_sf_fx[(NB_SWB_SUBBANDS) *8];
     869             :     Word16 pul_res_fx[NB_SWB_SUBBANDS];
     870             : 
     871             :     GainItem_fx Nbiggest_fx[NB_SWB_SUBBANDS * N_NBIGGEST_PULSEARCH];
     872             : 
     873             :     Word32 L_xSynth_har[L_FRAME32k]; /* Qs */
     874             : 
     875             :     Word16 lagGains_fx[NB_SWB_SUBBANDS];
     876             :     Word16 QlagGains[NB_SWB_SUBBANDS];
     877             :     Word16 har_freq_est1, har_freq_est2;
     878             :     Word16 flag_dis;
     879             :     Word16 pos_max_hfe2;
     880          38 :     HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core;
     881             : 
     882          38 :     har_freq_est1 = 0;
     883          38 :     move16();
     884          38 :     har_freq_est2 = 0;
     885          38 :     move16();
     886          38 :     flag_dis = 1;
     887          38 :     move16();
     888          38 :     pos_max_hfe2 = 0;
     889          38 :     move16();
     890             : 
     891          38 :     set16_fx( sspectra_fx, 0, fLenLow_fx );
     892          38 :     set16_fx( sspectra_ni_fx, 0, fLenLow_fx );
     893          38 :     set32_fx( L_xSynth_har, 0, L_FRAME32k );
     894          38 :     set16_fx( pul_res_fx, 0, NB_SWB_SUBBANDS );
     895             : 
     896             : 
     897          38 :     IF( EQ_16( hqswb_clas_fx, HQ_HARMONIC ) )
     898             :     {
     899           0 :         pos_max_hfe2 = har_est_fx( L_spectra, fLenLow_fx, &har_freq_est1, &har_freq_est2, &flag_dis, prev_frm_hfe2, subband_search_offset_fx, sbWidth_fx, prev_stab_hfe2 );
     900           0 :         noise_extr_corcod_fx( L_spectra, L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, fLenLow_fx, hHQ_core->prev_hqswb_clas, &hHQ_core->prev_ni_ratio_fx, &Qss );
     901             :         /* Find best indices for each group */
     902           0 :         getswbindices_har_fx(
     903             :             L_spectra,
     904             :             QsL, sspectra_ni_fx,
     905             :             nBands_search_fx, lagIndices_fx, prev_frm_index_fx, fLenLow_fx, subband_offsets_fx, sbWidth_fx, subband_search_offset_fx );
     906             : 
     907             :         /* Write the indices into the bitstream */
     908           0 :         FOR( k = 0; k < nBands_search_fx; k++ )
     909             :         {
     910           0 :             push_indice( st_fx->hBstr, IND_LAGINDICES, lagIndices_fx[k], bits_lagIndices_mode0_Har[k] );
     911             :         }
     912             : 
     913           0 :         IF( flag_dis == 0 )
     914             :         {
     915           0 :             test();
     916           0 :             IF( NE_16( har_freq_est2, SWB_HAR_RAN1 ) || NE_16( har_freq_est2, *prev_frm_hfe2 ) )
     917             :             {
     918           0 :                 har_freq_est2 = add( har_freq_est2, lagIndices_fx[0] );
     919           0 :                 move16();
     920             :             }
     921             :         }
     922             : 
     923           0 :         gethar_noisegn_fx( st_fx->hBstr, L_spectra, QsL, sspectra_diff_fx, Qss, L_xSynth_har,
     924             :                            sbWidth_fx, lagIndices_fx, BANDS_fx, har_bands_fx, fLenLow_fx, fLenHigh_fx,
     925             :                            subband_offsets_fx, subband_search_offset_fx, band_start_fx, band_end_fx, band_width_fx,
     926             :                            L_band_energy, Qbe, L_be_tonal, &QbeL, sspectra_fx,
     927             :                            har_freq_est2, pos_max_hfe2, pul_res_fx, pk_sf_fx );
     928             : 
     929             : 
     930           0 :         Gettonl_scalfact_fx( L_xSynth_har, QsL, L_spectra_ni, fLenLow_fx, fLenHigh_fx, har_bands_fx, BANDS_fx, L_band_energy, Qbe, band_start_fx, band_end_fx,
     931             :                              p2a_flags_fx, L_be_tonal, QbeL, pk_sf_fx, Qss, pul_res_fx );
     932             : 
     933           0 :         IF( flag_dis == 0 )
     934             :         {
     935           0 :             *prev_frm_hfe2 = 0;
     936           0 :             move16();
     937             :         }
     938             :         ELSE
     939             :         {
     940           0 :             *prev_frm_hfe2 = har_freq_est2;
     941           0 :             move16();
     942             :         }
     943             : 
     944           0 :         FOR( k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++ )
     945             :         {
     946           0 :             FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ )
     947             :             {
     948           0 :                 L_spectra[i] = L_xSynth_har[i - fLenLow_fx];
     949           0 :                 move32(); /* QsL */
     950             :             }
     951             :         }
     952             :     }
     953             :     ELSE
     954             :     {
     955          38 :         ss_min_fx = spectrumsmooth_noiseton_fx( L_spectra, /*QsL,*/ L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, &Qss, fLenLow_fx, ni_seed_fx );
     956             : 
     957             :         /* Get lag indices */
     958          38 :         GetSWBIndices_fx( sspectra_fx, /*Qss,*/ L_spectra + fLenLow_fx, QsL, nBands_fx, sbWidth_fx, lagIndices_fx, fLenLow_fx,
     959             :                           Nbiggest_fx, subband_offsets_fx, sspectra_fx );
     960             : 
     961             :         /* Bitstream operations */
     962         190 :         FOR( k = 0; k < nBands_fx; k++ )
     963             :         {
     964         152 :             IF( EQ_16( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k], 1 ) )
     965             :             {
     966           5 :                 lagIndices_fx[k] = 0;
     967           5 :                 move16();
     968           5 :                 lagGains_fx[k] = 0;
     969           5 :                 move16();
     970           5 :                 QlagGains[k] = 15;
     971           5 :                 move16();
     972             :             }
     973             :             ELSE
     974             :             {
     975         147 :                 push_indice( st_fx->hBstr, IND_LAGINDICES, lagIndices_fx[k], bits_lagIndices_modeNormal[k] );
     976             :             }
     977             :         }
     978             : 
     979          38 :         convert_lagIndices_pls2smp_fx( lagIndices_fx, nBands_fx, lagIndices_fx, sspectra_fx, sbWidth_fx, fLenLow_fx );
     980             : 
     981          38 :         GetlagGains_fx( sspectra_ni_fx, Qss, &L_band_energy[BANDS_fx - NB_SWB_SUBBANDS], Qbe, nBands_fx, sbWidth_fx, lagIndices_fx, fLenLow_fx, lagGains_fx, QlagGains );
     982         190 :         FOR( k = 0; k < NB_SWB_SUBBANDS; k++ )
     983             :         {
     984         152 :             lagGains_fx[k] = mult_r( lagGains_fx[k], 29491 ); /* lagGains[k]*0.9f; */
     985         152 :             move16();
     986             :         }
     987             : 
     988         190 :         FOR( k = 0; k < NB_SWB_SUBBANDS; k++ )
     989             :         {
     990         152 :             L_th_g[k] = L_deposit_l( 0 );
     991         152 :             move32();
     992         152 :             IF( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k] == 0 )
     993             :             {
     994         147 :                 L_th_g[k] = L_shl( L_mult( lagGains_fx[k], ss_min_fx ), sub( QsL, add( add( QlagGains[k], Qss ), 1 ) ) ); /* QlagGain+Qss -> QsL */
     995         147 :                 move32();
     996             :             }
     997             :         }
     998             : 
     999          38 :         GetSynthesizedSpecThinOut_fx( sspectra_ni_fx, Qss, L_xSynth_har, QsL, nBands_fx, sbWidth_fx, lagIndices_fx, lagGains_fx, QlagGains, fLenLow_fx );
    1000             : 
    1001             :         /*Level adjustment for the missing bands*/
    1002          38 :         noiseinj_hf_fx( L_xSynth_har, QsL, L_th_g, L_band_energy, Qbe, hHQ_core->prev_En_sb_fx, p2a_flags_fx, BANDS_fx, band_start_fx, band_end_fx, fLenLow_fx, fLenHigh_fx );
    1003             : 
    1004             : 
    1005         190 :         FOR( k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++ )
    1006             :         {
    1007         152 :             IF( p2a_flags_fx[k] == 0 )
    1008             :             {
    1009       11520 :                 FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ )
    1010             :                 {
    1011       11373 :                     L_spectra[i] = L_xSynth_har[i - fLenLow_fx];
    1012       11373 :                     move32(); /* Qob */
    1013             :                 }
    1014             :             }
    1015             :             ELSE
    1016             :             {
    1017         488 :                 FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ )
    1018             :                 {
    1019         483 :                     L_spectra[i] = L_spectra_ni[i];
    1020         483 :                     move32();
    1021             :                 }
    1022             :             }
    1023             :         }
    1024             :     }
    1025             : 
    1026          38 :     return;
    1027             : }
    1028             : 
    1029           0 : static void EncodeSWBSubbands_ivas_fx(
    1030             :     Encoder_State *st_fx,                   /* i/o: encoder state structure                     */
    1031             :     Word32 *L_spectra,                      /* i/o: MDCT domain spectrum                        */
    1032             :     Word16 QsL,                             /* i  : Q value for L_spectra                       */
    1033             :     const Word16 fLenLow_fx,                /* i  : lowband length                              */
    1034             :     const Word16 fLenHigh_fx,               /* i  : highband length                             */
    1035             :     const Word16 nBands_fx,                 /* i  : number of subbands                          */
    1036             :     const Word16 nBands_search_fx,          /* i  : number of subbands to be searched for BWE   */
    1037             :     const Word16 *sbWidth_fx,               /* i  : subband lengths                             */
    1038             :     const Word16 *subband_offsets_fx,       /* i  : Subband offset for BWE                      */
    1039             :     Word16 *lagIndices_fx,                  /* o  : lowband index for each subband              */
    1040             :     const Word16 BANDS_fx,                  /* i  : noise estimate from WB part                 */
    1041             :     const Word16 *band_start_fx,            /* i  : Number subbands/Frame                       */
    1042             :     const Word16 *band_end_fx,              /* i  : Band Start of each SB                       */
    1043             :     Word32 *L_band_energy,                  /* i  : Band end of each SB, :Qbe                   */
    1044             :     Word16 Qbe,                             /* i  : Q value of band energy                      */
    1045             :     const Word16 *p2a_flags_fx,             /* i  : BAnd energy of each SB                      */
    1046             :     const Word16 hqswb_clas_fx,             /* i  : lowband synthesis                           */
    1047             :     Word16 *prev_frm_index_fx,              /* i  : clas information                            */
    1048             :     const Word16 har_bands_fx,              /* i/o: Index of the previous Frame                 */
    1049             :     const Word16 *subband_search_offset_fx, /* i  : Number of harmonic LF bands                 */
    1050             :     Word16 *prev_frm_hfe2,                  /* i/o:                                             */
    1051             :     Word16 *prev_stab_hfe2,                 /* i/o:                                             */
    1052             :     const Word16 band_width_fx[],           /* i  : band width                                  */
    1053             :     const Word32 L_spectra_ni[],            /* i  : Qs noise injected spectra                   */
    1054             :     Word16 *ni_seed_fx                      /* i/o: random seed                                 */
    1055             : )
    1056             : {
    1057             :     Word16 i, k;
    1058             :     Word16 sspectra_fx[L_FRAME32k];
    1059             :     Word16 sspectra_ni_fx[L_FRAME32k];
    1060             :     Word16 sspectra_diff_fx[L_FRAME32k];
    1061             :     Word16 Qss;                      /* Q value of Smoothed Spectrum low-subband */
    1062             :     Word32 L_be_tonal[SWB_HAR_RAN1]; /* Q */
    1063             :     Word16 ss_min_fx;                /* Qss */
    1064             :     Word32 L_th_g[NB_SWB_SUBBANDS];
    1065             :     Word16 QbeL;
    1066             :     GainItem_fx pk_sf_fx[(NB_SWB_SUBBANDS) *8];
    1067             :     Word16 pul_res_fx[NB_SWB_SUBBANDS];
    1068             : 
    1069             :     GainItem_fx Nbiggest_fx[NB_SWB_SUBBANDS * N_NBIGGEST_PULSEARCH];
    1070             : 
    1071             :     Word32 L_xSynth_har[L_FRAME32k]; /* Qs */
    1072             : 
    1073             :     Word16 lagGains_fx[NB_SWB_SUBBANDS];
    1074             :     Word16 QlagGains[NB_SWB_SUBBANDS];
    1075             :     Word16 har_freq_est1, har_freq_est2;
    1076             :     Word16 flag_dis;
    1077             :     Word16 pos_max_hfe2;
    1078           0 :     HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core;
    1079             : 
    1080           0 :     har_freq_est1 = 0;
    1081           0 :     move16();
    1082           0 :     har_freq_est2 = 0;
    1083           0 :     move16();
    1084           0 :     flag_dis = 1;
    1085           0 :     move16();
    1086           0 :     pos_max_hfe2 = 0;
    1087           0 :     move16();
    1088             : 
    1089           0 :     set16_fx( sspectra_fx, 0, fLenLow_fx );
    1090           0 :     set16_fx( sspectra_ni_fx, 0, fLenLow_fx );
    1091           0 :     set32_fx( L_xSynth_har, 0, L_FRAME32k );
    1092           0 :     set16_fx( pul_res_fx, 0, NB_SWB_SUBBANDS );
    1093             : 
    1094             : 
    1095           0 :     IF( EQ_16( hqswb_clas_fx, HQ_HARMONIC ) )
    1096             :     {
    1097           0 :         pos_max_hfe2 = har_est_fx( L_spectra, fLenLow_fx, &har_freq_est1, &har_freq_est2, &flag_dis, prev_frm_hfe2, subband_search_offset_fx, sbWidth_fx, prev_stab_hfe2 );
    1098           0 :         noise_extr_corcod_fx( L_spectra, L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, fLenLow_fx, hHQ_core->prev_hqswb_clas, &hHQ_core->prev_ni_ratio_fx, &Qss );
    1099             :         /* Find best indices for each group */
    1100           0 :         getswbindices_har_fx(
    1101             :             L_spectra,
    1102             :             QsL, sspectra_ni_fx,
    1103             :             nBands_search_fx, lagIndices_fx, prev_frm_index_fx, fLenLow_fx, subband_offsets_fx, sbWidth_fx, subband_search_offset_fx );
    1104             : 
    1105             :         /* Write the indices into the bitstream */
    1106           0 :         FOR( k = 0; k < nBands_search_fx; k++ )
    1107             :         {
    1108           0 :             push_indice( st_fx->hBstr, IND_LAGINDICES, lagIndices_fx[k], bits_lagIndices_mode0_Har[k] );
    1109             :         }
    1110             : 
    1111           0 :         IF( flag_dis == 0 )
    1112             :         {
    1113           0 :             test();
    1114           0 :             IF( NE_16( har_freq_est2, SWB_HAR_RAN1 ) || NE_16( har_freq_est2, *prev_frm_hfe2 ) )
    1115             :             {
    1116           0 :                 har_freq_est2 = add( har_freq_est2, lagIndices_fx[0] );
    1117           0 :                 move16();
    1118             :             }
    1119             :         }
    1120             : 
    1121           0 :         gethar_noisegn_fx( st_fx->hBstr, L_spectra, QsL, sspectra_diff_fx, Qss, L_xSynth_har,
    1122             :                            sbWidth_fx, lagIndices_fx, BANDS_fx, har_bands_fx, fLenLow_fx, fLenHigh_fx,
    1123             :                            subband_offsets_fx, subband_search_offset_fx, band_start_fx, band_end_fx, band_width_fx,
    1124             :                            L_band_energy, Qbe, L_be_tonal, &QbeL, sspectra_fx,
    1125             :                            har_freq_est2, pos_max_hfe2, pul_res_fx, pk_sf_fx );
    1126             : 
    1127             : 
    1128           0 :         Gettonl_scalfact_fx( L_xSynth_har, QsL, L_spectra_ni, fLenLow_fx, fLenHigh_fx, har_bands_fx, BANDS_fx, L_band_energy, Qbe, band_start_fx, band_end_fx,
    1129             :                              p2a_flags_fx, L_be_tonal, QbeL, pk_sf_fx, Qss, pul_res_fx );
    1130             : 
    1131           0 :         IF( flag_dis == 0 )
    1132             :         {
    1133           0 :             *prev_frm_hfe2 = 0;
    1134           0 :             move16();
    1135             :         }
    1136             :         ELSE
    1137             :         {
    1138           0 :             *prev_frm_hfe2 = har_freq_est2;
    1139           0 :             move16();
    1140             :         }
    1141             : 
    1142           0 :         FOR( k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++ )
    1143             :         {
    1144           0 :             FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ )
    1145             :             {
    1146           0 :                 L_spectra[i] = L_xSynth_har[i - fLenLow_fx];
    1147           0 :                 move32(); /* QsL */
    1148             :             }
    1149             :         }
    1150             :     }
    1151             :     ELSE
    1152             :     {
    1153           0 :         ss_min_fx = spectrumsmooth_noiseton_fx( L_spectra, /*QsL,*/ L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, &Qss, fLenLow_fx, ni_seed_fx );
    1154             : 
    1155             :         /* Get lag indices */
    1156           0 :         GetSWBIndices_fx( sspectra_fx, /*Qss,*/ L_spectra + fLenLow_fx, QsL, nBands_fx, sbWidth_fx, lagIndices_fx, fLenLow_fx,
    1157             :                           Nbiggest_fx, subband_offsets_fx, sspectra_fx );
    1158             : 
    1159             :         /* Bitstream operations */
    1160           0 :         FOR( k = 0; k < nBands_fx; k++ )
    1161             :         {
    1162           0 :             IF( EQ_16( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k], 1 ) )
    1163             :             {
    1164           0 :                 lagIndices_fx[k] = 0;
    1165           0 :                 move16();
    1166           0 :                 lagGains_fx[k] = 0;
    1167           0 :                 move16();
    1168           0 :                 QlagGains[k] = 15;
    1169           0 :                 move16();
    1170             :             }
    1171             :             ELSE
    1172             :             {
    1173           0 :                 push_indice( st_fx->hBstr, IND_LAGINDICES, lagIndices_fx[k], bits_lagIndices_modeNormal[k] );
    1174             :             }
    1175             :         }
    1176             : 
    1177           0 :         convert_lagIndices_pls2smp_fx( lagIndices_fx, nBands_fx, lagIndices_fx, sspectra_fx, sbWidth_fx, fLenLow_fx );
    1178             : 
    1179           0 :         GetlagGains_fx( sspectra_ni_fx, Qss, &L_band_energy[BANDS_fx - NB_SWB_SUBBANDS], Qbe, nBands_fx, sbWidth_fx, lagIndices_fx, fLenLow_fx, lagGains_fx, QlagGains );
    1180           0 :         FOR( k = 0; k < NB_SWB_SUBBANDS; k++ )
    1181             :         {
    1182           0 :             lagGains_fx[k] = mult_r( lagGains_fx[k], 29491 ); /* lagGains[k]*0.9f; */
    1183           0 :             move16();
    1184             :         }
    1185             : 
    1186           0 :         FOR( k = 0; k < NB_SWB_SUBBANDS; k++ )
    1187             :         {
    1188           0 :             L_th_g[k] = L_deposit_l( 0 );
    1189           0 :             move32();
    1190           0 :             IF( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k] == 0 )
    1191             :             {
    1192           0 :                 L_th_g[k] = L_shl( L_mult( lagGains_fx[k], ss_min_fx ), sub( QsL, add( add( QlagGains[k], Qss ), 1 ) ) ); /* QlagGain+Qss -> QsL */
    1193           0 :                 move32();
    1194             :             }
    1195             :         }
    1196             : 
    1197           0 :         GetSynthesizedSpecThinOut_fx( sspectra_ni_fx, Qss, L_xSynth_har, QsL, nBands_fx, sbWidth_fx, lagIndices_fx, lagGains_fx, QlagGains, fLenLow_fx );
    1198             : 
    1199             :         /*Level adjustment for the missing bands*/
    1200           0 :         noiseinj_hf_fx( L_xSynth_har, QsL, L_th_g, L_band_energy, Qbe, hHQ_core->prev_En_sb_fx, p2a_flags_fx, BANDS_fx, band_start_fx, band_end_fx, fLenLow_fx, fLenHigh_fx );
    1201             : 
    1202             : 
    1203           0 :         FOR( k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++ )
    1204             :         {
    1205           0 :             IF( p2a_flags_fx[k] == 0 )
    1206             :             {
    1207           0 :                 FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ )
    1208             :                 {
    1209           0 :                     L_spectra[i] = L_xSynth_har[i - fLenLow_fx];
    1210           0 :                     move32(); /* Qob */
    1211             :                 }
    1212             :             }
    1213             :             ELSE
    1214             :             {
    1215           0 :                 FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ )
    1216             :                 {
    1217           0 :                     L_spectra[i] = L_spectra_ni[i];
    1218           0 :                     move32();
    1219             :                 }
    1220             :             }
    1221             :         }
    1222             :     }
    1223             : 
    1224           0 :     return;
    1225             : }
    1226             : /*--------------------------------------------------------------------------*
    1227             :  * swb_bwe_enc_lr()
    1228             :  *
    1229             :  * Main encoding routine of  SWB BWE for the LR MDCT core
    1230             :  *--------------------------------------------------------------------------*/
    1231          38 : void swb_bwe_enc_lr_fx(
    1232             :     Encoder_State *st_fx,         /* i/o: encoder state structure                      */
    1233             :     const Word32 L_m_core[],      /* i  : lowband synthesis                            */
    1234             :     Word16 QsL,                   /* i  : Q value                                      */
    1235             :     const Word32 L_m_orig[],      /* i/o: scaled orig signal (MDCT)                    */
    1236             :     Word32 L_m[],                 /* o  : highband synthesis with lowband zeroed       */
    1237             :     const Word32 L_total_brate,   /* i  : total bitrate for selecting subband pattern  */
    1238             :     Word16 BANDS_fx,              /* i  : Total number of Subbands in a frame          */
    1239             :     Word16 *band_start_fx,        /* i  : band start of each SB                        */
    1240             :     Word16 *band_end_fx,          /* i  : band end of each SB                          */
    1241             :     Word32 *L_band_energy,        /* i  : band_energy of each SB                       */
    1242             :     Word16 Qbe,                   /* i  : Q value of band energy                       */
    1243             :     Word16 *p2a_flags_fx,         /* i  : HF tonal indicator                           */
    1244             :     const Word16 hqswb_clas_fx,   /* i  : HQ_NORMAL2 or HQ_HARMONIC mode               */
    1245             :     Word16 lowlength_fx,          /* i  : lowband length                               */
    1246             :     Word16 highlength_fx,         /* i  : highband length                              */
    1247             :     Word16 *prev_frm_index_fx,    /* i/o: previous frame lag index for harmonic mode   */
    1248             :     const Word16 har_bands_fx,    /* i  : Number of LF harmonic bands                  */
    1249             :     Word16 *prev_frm_hfe2,        /* i/o:                                              */
    1250             :     Word16 *prev_stab_hfe2,       /* i/o:                                              */
    1251             :     const Word16 band_width_fx[], /* i  : band_width information                       */
    1252             :     const Word32 L_y2_ni[],       /* i  : band_width information                       */
    1253             :     Word16 *ni_seed_fx            /* i/o: random seed for search buffer NI             */
    1254             : )
    1255             : {
    1256             :     Word16 k;
    1257             :     Word16 nBands_fx;
    1258             :     Word16 nBands_search_fx;
    1259             :     Word16 wBands_fx[NB_SWB_SUBBANDS];
    1260             :     Word16 lagIndices_fx[NB_SWB_SUBBANDS];
    1261             :     Word16 swb_lowband_fx, swb_highband_fx, allband_fx;
    1262             : 
    1263             :     const Word16 *subband_offsets_fx;
    1264             :     const Word16 *subband_search_offset_fx;
    1265             : 
    1266             :     Word32 *p_L_m;
    1267             : 
    1268          38 :     subband_search_offset_fx = subband_search_offsets_13p2kbps_Har;
    1269          38 :     subband_offsets_fx = subband_offsets_sub5_13p2kbps_Har;
    1270             : 
    1271          38 :     hf_parinitiz_fx( L_total_brate, hqswb_clas_fx, lowlength_fx, highlength_fx, wBands_fx, &subband_search_offset_fx, &subband_offsets_fx, &nBands_fx, &nBands_search_fx, &swb_lowband_fx, &swb_highband_fx );
    1272          38 :     allband_fx = add( swb_lowband_fx, swb_highband_fx );
    1273          38 :     move16();
    1274             : 
    1275             :     /* Prepare m[], low part from WB core, high part from 32k input */
    1276          38 :     Copy32( L_m_core, L_m, swb_lowband_fx );
    1277          38 :     Copy32( &L_m_orig[swb_lowband_fx], &L_m[swb_lowband_fx], swb_highband_fx );
    1278             : 
    1279          38 :     EncodeSWBSubbands_fx(
    1280             :         st_fx,
    1281             :         L_m, QsL,
    1282             :         swb_lowband_fx, swb_highband_fx, nBands_fx, nBands_search_fx, wBands_fx, subband_offsets_fx,
    1283             :         lagIndices_fx,
    1284             :         BANDS_fx, band_start_fx, band_end_fx,
    1285             :         L_band_energy, Qbe,
    1286             :         p2a_flags_fx,
    1287             :         hqswb_clas_fx, prev_frm_index_fx, har_bands_fx, subband_search_offset_fx,
    1288             :         prev_frm_hfe2, prev_stab_hfe2,
    1289             :         band_width_fx, L_y2_ni, ni_seed_fx );
    1290             : 
    1291          38 :     p_L_m = &L_m[sub( allband_fx, 1 )];
    1292          38 :     *p_L_m = Mult_32_16( *p_L_m, 2028 );
    1293          38 :     move32();
    1294          38 :     p_L_m--; /* 0.0625 =  2028 (Q15) */
    1295          38 :     *p_L_m = Mult_32_16( *p_L_m, 4096 );
    1296          38 :     move32();
    1297          38 :     p_L_m--; /* 0.125  =  4096 (Q15) */
    1298          38 :     *p_L_m = Mult_32_16( *p_L_m, 8192 );
    1299          38 :     move32();
    1300          38 :     p_L_m--; /* 0.25   =  8192 (Q15) */
    1301          38 :     *p_L_m = Mult_32_16( *p_L_m, 16384 );
    1302          38 :     move32();
    1303          38 :     p_L_m--; /* 0.5    = 16384 (Q15) */
    1304             : 
    1305             :     /* set low frequencies to zero */
    1306        9766 :     FOR( k = 0; k < swb_lowband_fx; k++ )
    1307             :     {
    1308        9728 :         L_m[k] = L_deposit_l( 0 );
    1309        9728 :         move32();
    1310             :     }
    1311             : 
    1312          38 :     return;
    1313             : }
    1314             : 
    1315           0 : void swb_bwe_enc_lr_ivas_fx(
    1316             :     Encoder_State *st_fx,         /* i/o: encoder state structure                      */
    1317             :     const Word32 L_m_core[],      /* i  : lowband synthesis                            */
    1318             :     Word16 QsL,                   /* i  : Q value                                      */
    1319             :     const Word32 L_m_orig[],      /* i/o: scaled orig signal (MDCT)                    */
    1320             :     Word32 L_m[],                 /* o  : highband synthesis with lowband zeroed       */
    1321             :     const Word32 L_total_brate,   /* i  : total bitrate for selecting subband pattern  */
    1322             :     Word16 BANDS_fx,              /* i  : Total number of Subbands in a frame          */
    1323             :     Word16 *band_start_fx,        /* i  : band start of each SB                        */
    1324             :     Word16 *band_end_fx,          /* i  : band end of each SB                          */
    1325             :     Word32 *L_band_energy,        /* i  : band_energy of each SB                       */
    1326             :     Word16 Qbe,                   /* i  : Q value of band energy                       */
    1327             :     Word16 *p2a_flags_fx,         /* i  : HF tonal indicator                           */
    1328             :     const Word16 hqswb_clas_fx,   /* i  : HQ_NORMAL2 or HQ_HARMONIC mode               */
    1329             :     Word16 lowlength_fx,          /* i  : lowband length                               */
    1330             :     Word16 highlength_fx,         /* i  : highband length                              */
    1331             :     Word16 *prev_frm_index_fx,    /* i/o: previous frame lag index for harmonic mode   */
    1332             :     const Word16 har_bands_fx,    /* i  : Number of LF harmonic bands                  */
    1333             :     Word16 *prev_frm_hfe2,        /* i/o:                                              */
    1334             :     Word16 *prev_stab_hfe2,       /* i/o:                                              */
    1335             :     const Word16 band_width_fx[], /* i  : band_width information                       */
    1336             :     const Word32 L_y2_ni[],       /* i  : band_width information                       */
    1337             :     Word16 *ni_seed_fx            /* i/o: random seed for search buffer NI             */
    1338             : )
    1339             : {
    1340             :     Word16 k;
    1341             :     Word16 nBands_fx;
    1342             :     Word16 nBands_search_fx;
    1343             :     Word16 wBands_fx[NB_SWB_SUBBANDS];
    1344             :     Word16 lagIndices_fx[NB_SWB_SUBBANDS];
    1345             :     Word16 swb_lowband_fx, swb_highband_fx, allband_fx;
    1346             : 
    1347             :     const Word16 *subband_offsets_fx;
    1348             :     const Word16 *subband_search_offset_fx;
    1349             : 
    1350             :     Word32 *p_L_m;
    1351             : 
    1352           0 :     subband_search_offset_fx = subband_search_offsets_13p2kbps_Har;
    1353           0 :     subband_offsets_fx = subband_offsets_sub5_13p2kbps_Har;
    1354             : 
    1355           0 :     hf_parinitiz_fx( L_total_brate, hqswb_clas_fx, lowlength_fx, highlength_fx, wBands_fx, &subband_search_offset_fx, &subband_offsets_fx, &nBands_fx, &nBands_search_fx, &swb_lowband_fx, &swb_highband_fx );
    1356           0 :     allband_fx = add( swb_lowband_fx, swb_highband_fx );
    1357           0 :     move16();
    1358             : 
    1359             :     /* Prepare m[], low part from WB core, high part from 32k input */
    1360           0 :     Copy32( L_m_core, L_m, swb_lowband_fx );
    1361           0 :     Copy32( &L_m_orig[swb_lowband_fx], &L_m[swb_lowband_fx], swb_highband_fx );
    1362             : 
    1363           0 :     EncodeSWBSubbands_ivas_fx(
    1364             :         st_fx,
    1365             :         L_m, QsL,
    1366             :         swb_lowband_fx, swb_highband_fx, nBands_fx, nBands_search_fx, wBands_fx, subband_offsets_fx,
    1367             :         lagIndices_fx,
    1368             :         BANDS_fx, band_start_fx, band_end_fx,
    1369             :         L_band_energy, Qbe,
    1370             :         p2a_flags_fx,
    1371             :         hqswb_clas_fx, prev_frm_index_fx, har_bands_fx, subband_search_offset_fx,
    1372             :         prev_frm_hfe2, prev_stab_hfe2,
    1373             :         band_width_fx, L_y2_ni, ni_seed_fx );
    1374             : 
    1375           0 :     p_L_m = &L_m[sub( allband_fx, 1 )];
    1376           0 :     *p_L_m = Mult_32_16( *p_L_m, 2028 );
    1377           0 :     move32();
    1378           0 :     p_L_m--; /* 0.0625 =  2028 (Q15) */
    1379           0 :     *p_L_m = Mult_32_16( *p_L_m, 4096 );
    1380           0 :     move32();
    1381           0 :     p_L_m--; /* 0.125  =  4096 (Q15) */
    1382           0 :     *p_L_m = Mult_32_16( *p_L_m, 8192 );
    1383           0 :     move32();
    1384           0 :     p_L_m--; /* 0.25   =  8192 (Q15) */
    1385           0 :     *p_L_m = Mult_32_16( *p_L_m, 16384 );
    1386           0 :     move32();
    1387           0 :     p_L_m--; /* 0.5    = 16384 (Q15) */
    1388             : 
    1389             :     /* set low frequencies to zero */
    1390           0 :     FOR( k = 0; k < swb_lowband_fx; k++ )
    1391             :     {
    1392           0 :         L_m[k] = L_deposit_l( 0 );
    1393           0 :         move32();
    1394             :     }
    1395             : 
    1396           0 :     return;
    1397             : }

Generated by: LCOV version 1.14