LCOV - code coverage report
Current view: top level - lib_com - igf_base_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 4c82f1d24d39d0296b18d775f18a006f4c7d024b Lines: 651 954 68.2 %
Date: 2025-05-17 01:59:02 Functions: 10 11 90.9 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : 
       5             : #include <stdio.h>
       6             : #include <stdlib.h>
       7             : #include <memory.h>
       8             : #include <assert.h>
       9             : #include "options.h"
      10             : #include "stl.h"
      11             : #include "prot_fx.h"
      12             : #include "rom_com.h"
      13             : #include "basop_util.h"
      14             : 
      15             : /**********************************************************************/ /*
      16             : returns an int val, multiplied with transFac
      17             : **************************************************************************/
      18     1147242 : Word16 IGF_ApplyTransFac(                                                /**< out: Q0 | multiplication factor                                                        */
      19             :                           const Word16 val,                              /**< in: Q15 | input value for multiplication, Q15                                          */
      20             :                           const Word16 transFac                          /**< in: Q14 | multiplicator for variable val, Q14: 1.25f=0x5000, 1.0f=0x4000, 0.5f=0x2000  */
      21             : )
      22             : {
      23             :     Word16 ret;
      24             : 
      25     1147242 :     IF( EQ_16( transFac, 0x4000 /*ONE in Q14*/ ) )
      26             :     {
      27      387141 :         return val;
      28             :     }
      29             : 
      30      760101 :     ret = shl( val, 1 );
      31      760101 :     ret = mac_r( 0x00000000, ret, transFac );
      32      760101 :     ret = add( ret, s_and( ret, 1 ) ); /*Q0*/
      33             : 
      34             : 
      35      760101 :     return ret; /*Q0*/
      36             : }
      37             : 
      38             : /**********************************************************************/ /*
      39             : maps a given bitrate to the IGF_BITRATE index
      40             : **************************************************************************/
      41      471444 : Word16 IGF_MapBitRateToIndex(
      42             :     const Word32 brate,        /* i  :  bitrate                    */
      43             :     const Word16 bwidth,       /* i  :  audio bandwidth            */
      44             :     const Word16 element_mode, /* i  :  element mode               */
      45             :     const Word16 rf_mode       /* i  :  flag to signal the RF mode */
      46             : )
      47             : {
      48      471444 :     Word16 bitRateIndex = IGF_BITRATE_UNKNOWN;
      49      471444 :     move16();
      50             :     /* Stereo/CPE modes */
      51      471444 :     IF( GT_16( element_mode, IVAS_SCE ) )
      52             :     {
      53      454956 :         SWITCH( bwidth )
      54             :         {
      55         186 :             case IGF_MODE_WB:
      56         186 :                 test();
      57         186 :                 IF( LE_32( brate, IVAS_13k2 ) && EQ_16( rf_mode, 1 ) )
      58             :                 {
      59           0 :                     bitRateIndex = IGF_BITRATE_RF_WB_13200;
      60           0 :                     move16();
      61             :                 }
      62         186 :                 ELSE IF( LE_32( brate, ACELP_9k60 ) )
      63             :                 {
      64         116 :                     bitRateIndex = IGF_BITRATE_WB_13200_CPE;
      65         116 :                     move16();
      66             :                 }
      67          70 :                 ELSE IF( LE_32( brate, IVAS_13k2 ) )
      68             :                 {
      69          70 :                     bitRateIndex = IGF_BITRATE_WB_16400_CPE;
      70          70 :                     move16();
      71             :                 }
      72         186 :                 BREAK;
      73      136708 :             case IGF_MODE_SWB:
      74             :                 /* DFT and TD Stereo bitrates */
      75      136708 :                 IF( LE_32( brate, ACELP_9k60 ) )
      76             :                 {
      77         278 :                     bitRateIndex = IGF_BITRATE_SWB_13200_CPE;
      78         278 :                     move16();
      79             :                 }
      80      136430 :                 ELSE IF( LE_32( brate, IVAS_13k2 ) )
      81             :                 {
      82         266 :                     IF( EQ_16( rf_mode, 1 ) )
      83             :                     {
      84           0 :                         bitRateIndex = IGF_BITRATE_RF_SWB_13200;
      85           0 :                         move16();
      86             :                     }
      87             :                     ELSE
      88             :                     {
      89         266 :                         bitRateIndex = IGF_BITRATE_SWB_16400_CPE;
      90         266 :                         move16();
      91             :                     }
      92             :                 }
      93      136164 :                 ELSE IF( LE_32( brate, IVAS_16k4 ) )
      94             :                 {
      95         670 :                     bitRateIndex = IGF_BITRATE_SWB_24400_CPE;
      96         670 :                     move16();
      97             :                 }
      98      135494 :                 ELSE IF( LE_32( brate, IVAS_24k4 ) )
      99             :                 {
     100         400 :                     bitRateIndex = IGF_BITRATE_SWB_32000_CPE;
     101         400 :                     move16();
     102             :                 }
     103      135094 :                 ELSE IF( LE_32( brate, IVAS_32k ) )
     104             :                 {
     105           0 :                     bitRateIndex = IGF_BITRATE_SWB_32000;
     106           0 :                     move16();
     107             :                 }
     108             :                 /* MDCT Stereo bitrates */
     109      135094 :                 ELSE IF( LE_32( brate, IVAS_48k ) )
     110             :                 {
     111       67367 :                     bitRateIndex = IGF_BITRATE_SWB_48000_CPE;
     112       67367 :                     move16();
     113             :                 }
     114       67727 :                 ELSE IF( LE_32( brate, IVAS_64k ) )
     115             :                 {
     116       22759 :                     bitRateIndex = IGF_BITRATE_SWB_64000_CPE;
     117       22759 :                     move16();
     118             :                 }
     119       44968 :                 ELSE IF( LE_32( brate, IVAS_80k ) )
     120             :                 {
     121       18682 :                     bitRateIndex = IGF_BITRATE_SWB_80000_CPE;
     122       18682 :                     move16();
     123             :                 }
     124       26286 :                 ELSE IF( LE_32( brate, IVAS_96k ) )
     125             :                 {
     126       26286 :                     bitRateIndex = IGF_BITRATE_SWB_96000_CPE;
     127       26286 :                     move16();
     128             :                 }
     129      136708 :                 BREAK;
     130      318062 :             case IGF_MODE_FB:
     131             :                 /* DFT and TD Stereo bitrates */
     132      318062 :                 IF( LE_32( brate, IVAS_16k4 ) )
     133             :                 {
     134         300 :                     bitRateIndex = IGF_BITRATE_FB_24400_CPE;
     135         300 :                     move16();
     136             :                 }
     137      317762 :                 ELSE IF( LE_32( brate, IVAS_24k4 ) )
     138             :                 {
     139         386 :                     bitRateIndex = IGF_BITRATE_FB_32000_CPE;
     140         386 :                     move16();
     141             :                 }
     142      317376 :                 ELSE IF( LE_32( brate, IVAS_32k ) )
     143             :                 {
     144           0 :                     bitRateIndex = IGF_BITRATE_FB_32000;
     145           0 :                     move16();
     146             :                 }
     147             :                 /* MDCT Stereo bitrates */
     148      317376 :                 ELSE IF( LE_32( brate, IVAS_48k ) )
     149             :                 {
     150       42423 :                     bitRateIndex = IGF_BITRATE_FB_48000_CPE;
     151       42423 :                     move16();
     152             :                 }
     153      274953 :                 ELSE IF( LE_32( brate, IVAS_64k ) )
     154             :                 {
     155       78469 :                     bitRateIndex = IGF_BITRATE_FB_64000_CPE;
     156       78469 :                     move16();
     157             :                 }
     158      196484 :                 ELSE IF( LE_32( brate, IVAS_80k ) )
     159             :                 {
     160       25291 :                     bitRateIndex = IGF_BITRATE_FB_80000_CPE;
     161       25291 :                     move16();
     162             :                 }
     163      171193 :                 ELSE IF( LE_32( brate, IVAS_96k ) )
     164             :                 {
     165       35055 :                     bitRateIndex = IGF_BITRATE_FB_96000_CPE;
     166       35055 :                     move16();
     167             :                 }
     168      136138 :                 ELSE IF( LE_32( brate, IVAS_128k ) )
     169             :                 {
     170      136138 :                     bitRateIndex = IGF_BITRATE_FB_128000_CPE;
     171      136138 :                     move16();
     172             :                 }
     173      318062 :                 BREAK;
     174             :         }
     175      454956 :     }
     176             :     /* SCE modes: use tunings done for DFT stereo bitrates also for according SCE bitrates, otherwise same config as mono modes */
     177       16488 :     ELSE IF( EQ_16( element_mode, IVAS_SCE ) )
     178             :     {
     179       16424 :         SWITCH( bwidth )
     180             :         {
     181          20 :             case IGF_MODE_WB:
     182          20 :                 test();
     183          20 :                 IF( LE_32( brate, IVAS_13k2 ) && EQ_16( rf_mode, 1 ) )
     184             :                 {
     185           0 :                     bitRateIndex = IGF_BITRATE_RF_WB_13200;
     186           0 :                     move16();
     187             :                 }
     188          20 :                 ELSE IF( LE_32( brate, ACELP_9k60 ) ) /* bitrates 8000 and 9600 */
     189             :                 {
     190          20 :                     bitRateIndex = IGF_BITRATE_WB_9600;
     191          20 :                     move16();
     192             :                 }
     193          20 :                 BREAK;
     194        7616 :             case IGF_MODE_SWB:
     195        7616 :                 IF( LE_32( brate, ACELP_9k60 ) )
     196             :                 {
     197        2208 :                     bitRateIndex = IGF_BITRATE_SWB_13200_CPE;
     198        2208 :                     move16();
     199             :                 }
     200        5408 :                 ELSE IF( LE_32( brate, IVAS_13k2 ) )
     201             :                 {
     202        2758 :                     IF( EQ_16( rf_mode, 1 ) )
     203             :                     {
     204           0 :                         bitRateIndex = IGF_BITRATE_RF_SWB_13200;
     205           0 :                         move16();
     206             :                     }
     207             :                     ELSE
     208             :                     {
     209        2758 :                         bitRateIndex = IGF_BITRATE_SWB_16400_CPE;
     210        2758 :                         move16();
     211             :                     }
     212             :                 }
     213        2650 :                 ELSE IF( LE_32( brate, IVAS_16k4 ) )
     214             :                 {
     215        1294 :                     bitRateIndex = IGF_BITRATE_SWB_24400_CPE;
     216        1294 :                     move16();
     217             :                 }
     218        1356 :                 ELSE IF( LE_32( brate, IVAS_24k4 ) )
     219             :                 {
     220         628 :                     move16();
     221         628 :                     bitRateIndex = IGF_BITRATE_SWB_32000_CPE;
     222             :                 }
     223         728 :                 ELSE IF( LE_32( brate, IVAS_32k ) )
     224             :                 {
     225         430 :                     bitRateIndex = IGF_BITRATE_SWB_32000;
     226         430 :                     move16();
     227             :                 }
     228         298 :                 ELSE IF( LE_32( brate, IVAS_48k ) )
     229             :                 {
     230         114 :                     bitRateIndex = IGF_BITRATE_SWB_48000;
     231         114 :                     move16();
     232             :                 }
     233         184 :                 ELSE IF( LE_32( brate, IVAS_64k ) )
     234             :                 {
     235         184 :                     bitRateIndex = IGF_BITRATE_SWB_64000;
     236         184 :                     move16();
     237             :                 }
     238        7616 :                 BREAK;
     239        8788 :             case IGF_MODE_FB:
     240        8788 :                 IF( LE_32( brate, IVAS_16k4 ) )
     241             :                 {
     242        2252 :                     bitRateIndex = IGF_BITRATE_FB_24400_CPE;
     243        2252 :                     move16();
     244             :                 }
     245        6536 :                 ELSE IF( LE_32( brate, IVAS_24k4 ) )
     246             :                 {
     247        2194 :                     bitRateIndex = IGF_BITRATE_FB_32000_CPE;
     248        2194 :                     move16();
     249             :                 }
     250        4342 :                 ELSE IF( LE_32( brate, IVAS_32k ) )
     251             :                 {
     252        1308 :                     bitRateIndex = IGF_BITRATE_FB_32000;
     253        1308 :                     move16();
     254             :                 }
     255        3034 :                 ELSE IF( LE_32( brate, IVAS_48k ) )
     256             :                 {
     257        1550 :                     bitRateIndex = IGF_BITRATE_FB_48000;
     258        1550 :                     move16();
     259             :                 }
     260        1484 :                 ELSE IF( LE_32( brate, IVAS_64k ) )
     261             :                 {
     262         832 :                     bitRateIndex = IGF_BITRATE_FB_64000;
     263         832 :                     move16();
     264             :                 }
     265         652 :                 ELSE IF( LE_32( brate, IVAS_96k ) )
     266             :                 {
     267         464 :                     bitRateIndex = IGF_BITRATE_FB_96000;
     268         464 :                     move16();
     269             :                 }
     270         188 :                 ELSE IF( LE_32( brate, IVAS_128k ) )
     271             :                 {
     272         188 :                     bitRateIndex = IGF_BITRATE_FB_128000;
     273         188 :                     move16();
     274             :                 }
     275        8788 :                 BREAK;
     276             :         }
     277       16424 :     }
     278             :     /* EVS mono */
     279             :     ELSE
     280             :     {
     281          64 :         SWITCH( bwidth )
     282             :         {
     283           0 :             case IGF_MODE_WB:
     284           0 :                 test();
     285           0 :                 IF( LE_32( brate, ACELP_13k20 ) && EQ_16( rf_mode, 1 ) )
     286             :                 {
     287           0 :                     bitRateIndex = IGF_BITRATE_RF_WB_13200;
     288           0 :                     move16();
     289             :                 }
     290           0 :                 ELSE IF( LE_32( brate, ACELP_9k60 ) ) /* bitrates 8000 and 9600 */
     291             :                 {
     292           0 :                     bitRateIndex = IGF_BITRATE_WB_9600;
     293           0 :                     move16();
     294             :                 }
     295           0 :                 BREAK;
     296          64 :             case IGF_MODE_SWB:
     297          64 :                 IF( LE_32( brate, ACELP_9k60 ) )
     298             :                 {
     299           0 :                     move16();
     300           0 :                     bitRateIndex = IGF_BITRATE_SWB_9600;
     301             :                 }
     302          64 :                 ELSE IF( LE_32( brate, ACELP_13k20 ) )
     303             :                 {
     304          40 :                     IF( EQ_16( rf_mode, 1 ) )
     305             :                     {
     306           0 :                         bitRateIndex = IGF_BITRATE_RF_SWB_13200;
     307           0 :                         move16();
     308             :                     }
     309             :                     ELSE
     310             :                     {
     311          40 :                         bitRateIndex = IGF_BITRATE_SWB_13200;
     312          40 :                         move16();
     313             :                     }
     314             :                 }
     315          24 :                 ELSE IF( LE_32( brate, ACELP_16k40 ) )
     316             :                 {
     317           0 :                     bitRateIndex = IGF_BITRATE_SWB_16400;
     318           0 :                     move16();
     319             :                 }
     320          24 :                 ELSE IF( LE_32( brate, ACELP_24k40 ) )
     321             :                 {
     322          24 :                     bitRateIndex = IGF_BITRATE_SWB_24400;
     323          24 :                     move16();
     324             :                 }
     325           0 :                 ELSE IF( LE_32( brate, ACELP_32k ) )
     326             :                 {
     327           0 :                     bitRateIndex = IGF_BITRATE_SWB_32000;
     328           0 :                     move16();
     329             :                 }
     330           0 :                 ELSE IF( LE_32( brate, ACELP_48k ) )
     331             :                 {
     332           0 :                     bitRateIndex = IGF_BITRATE_SWB_48000;
     333           0 :                     move16();
     334             :                 }
     335           0 :                 ELSE IF( LE_32( brate, ACELP_64k ) )
     336             :                 {
     337           0 :                     bitRateIndex = IGF_BITRATE_SWB_64000;
     338           0 :                     move16();
     339             :                 }
     340          64 :                 BREAK;
     341           0 :             case IGF_MODE_FB:
     342           0 :                 IF( LE_32( brate, ACELP_16k40 ) )
     343             :                 {
     344           0 :                     bitRateIndex = IGF_BITRATE_FB_16400;
     345           0 :                     move16();
     346             :                 }
     347           0 :                 ELSE IF( LE_32( brate, ACELP_24k40 ) )
     348             :                 {
     349           0 :                     bitRateIndex = IGF_BITRATE_FB_24400;
     350           0 :                     move16();
     351             :                 }
     352           0 :                 ELSE IF( LE_32( brate, ACELP_32k ) )
     353             :                 {
     354           0 :                     bitRateIndex = IGF_BITRATE_FB_32000;
     355           0 :                     move16();
     356             :                 }
     357           0 :                 ELSE IF( LE_32( brate, ACELP_48k ) )
     358             :                 {
     359           0 :                     bitRateIndex = IGF_BITRATE_FB_48000;
     360           0 :                     move16();
     361             :                 }
     362           0 :                 ELSE IF( LE_32( brate, ACELP_64k ) )
     363             :                 {
     364           0 :                     bitRateIndex = IGF_BITRATE_FB_64000;
     365           0 :                     move16();
     366             :                 }
     367           0 :                 ELSE IF( LE_32( brate, HQ_96k ) )
     368             :                 {
     369           0 :                     bitRateIndex = IGF_BITRATE_FB_96000;
     370           0 :                     move16();
     371             :                 }
     372           0 :                 ELSE IF( LE_32( brate, HQ_128k ) )
     373             :                 {
     374           0 :                     bitRateIndex = IGF_BITRATE_FB_128000;
     375           0 :                     move16();
     376             :                 }
     377           0 :                 BREAK;
     378             :         }
     379      471444 :     }
     380             : 
     381      471444 :     return bitRateIndex; /*Q0*/
     382             : }
     383             : 
     384             : /**********************************************************************/ /*
     385             : IGF grid setup
     386             : **************************************************************************/
     387          96 : static void IGF_gridSetUp( H_IGF_GRID hGrid,                             /**< out:    | IGF grid handle                                                    */
     388             :                            Word16 bitRateIndex,                          /**< in: Q0  | IGF bitrate index                                                  */
     389             :                            Word32 sampleRate,                            /**< in:     | sample rate                                                        */
     390             :                            Word16 frameLength,                           /**< in:     | frame length                                                       */
     391             :                            Word16 transFac,                              /**< in: Q14 |transFac                                                           */
     392             :                            Word16 igfMinFq                               /**< in:     | IGF minimum frequency indicating lower start frequency for copy up */
     393             : )
     394             : {
     395             :     Word16 t;
     396             :     Word16 sfb;
     397             :     const Word16 *swb_offset;
     398             :     Word16 swb_offset_len;
     399             :     Word16 bandwidth;
     400             :     Word16 wrp_sfb;
     401             :     Word16 tmp1;
     402             :     Word16 tmp2;
     403             :     Word32 L_tmp1;
     404             :     Word32 L_tmp2;
     405             : 
     406          96 :     swb_offset = NULL;
     407          96 :     swb_offset_len = 0;
     408          96 :     move16();
     409             : 
     410          96 :     SWITCH( bitRateIndex )
     411             :     {
     412          96 :         case IGF_BITRATE_WB_9600:
     413             :         case IGF_BITRATE_SWB_9600:
     414             :         case IGF_BITRATE_RF_WB_13200:
     415             :         case IGF_BITRATE_RF_SWB_13200:
     416             :         case IGF_BITRATE_SWB_13200:
     417             :         case IGF_BITRATE_SWB_16400:
     418             :         case IGF_BITRATE_SWB_24400:
     419             :         case IGF_BITRATE_SWB_32000:
     420             :         case IGF_BITRATE_SWB_48000:
     421          96 :             swb_offset = &swb_offset_LB_new[bitRateIndex][1];
     422          96 :             swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; /*Q0*/
     423          96 :             move16();
     424          96 :             Copy( &igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2 );
     425          96 :             BREAK;
     426           0 :         case IGF_BITRATE_FB_16400:
     427             :         case IGF_BITRATE_FB_24400:
     428             :         case IGF_BITRATE_FB_32000:
     429           0 :             swb_offset = &swb_offset_LB_new[bitRateIndex][1];
     430           0 :             swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; /*Q0*/
     431           0 :             move16();
     432           0 :             Copy( &igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2 );
     433           0 :             BREAK;
     434           0 :         case IGF_BITRATE_FB_48000:
     435             :         case IGF_BITRATE_FB_96000:
     436             :         case IGF_BITRATE_FB_128000:
     437           0 :             swb_offset = &swb_offset_LB_new[bitRateIndex][1];
     438           0 :             swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; /*Q0*/
     439           0 :             move16();
     440           0 :             Copy( &igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2 );
     441           0 :             BREAK;
     442           0 :         case IGF_BITRATE_UNKNOWN:
     443             :         default:
     444           0 :             assert( 0 );
     445             :     }
     446             : 
     447         840 :     FOR( sfb = 0; sfb < swb_offset_len; sfb++ )
     448             :     {
     449         744 :         hGrid->swb_offset[sfb] = IGF_ApplyTransFac( swb_offset[sfb], transFac ); /*Q0*/
     450         744 :         move16();
     451             :     }
     452             : 
     453          96 :     hGrid->infoIsRefined = 0;
     454          96 :     move16();
     455          96 :     frameLength = IGF_ApplyTransFac( frameLength, transFac ); /*Q0*/
     456          96 :     tmp2 = norm_s( frameLength );
     457          96 :     bandwidth = shl( frameLength, tmp2 );                        /*tmp2*/
     458          96 :     hGrid->swb_offset_len = extract_l( L_shr( sampleRate, 2 ) ); /*-1*/
     459          96 :     move16();
     460          96 :     tmp1 = sub( norm_s( hGrid->swb_offset_len ), 1 );
     461          96 :     hGrid->swb_offset_len = shl( hGrid->swb_offset_len, tmp1 ); /*tmp1-1*/
     462          96 :     move16();
     463          96 :     bandwidth = div_s( hGrid->swb_offset_len, bandwidth ); /*15 + tmp1-1-tmp2*/
     464          96 :     tmp2 = sub( add( tmp2, 1 ), tmp1 );
     465          96 :     bandwidth = shr( bandwidth, sub( 15, tmp2 ) ); /*Q0*/
     466             : 
     467             : 
     468          96 :     hGrid->swb_offset_len = swb_offset_len; /*Q0*/
     469          96 :     move16();
     470          96 :     hGrid->startSfb = 0;
     471          96 :     move16();
     472          96 :     hGrid->stopSfb = sub( hGrid->swb_offset_len, 1 ); /*Q0*/
     473          96 :     move16();
     474          96 :     hGrid->startLine = hGrid->swb_offset[hGrid->startSfb]; /*Q0*/
     475          96 :     move16();
     476          96 :     hGrid->stopLine = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/
     477          96 :     move16();
     478          96 :     hGrid->startFrequency = imult1616( bandwidth, hGrid->startLine ); /*Q0*/
     479          96 :     move16();
     480          96 :     hGrid->stopFrequency = imult1616( bandwidth, hGrid->stopLine ); /*Q0*/
     481          96 :     move16();
     482             : 
     483          96 :     L_tmp1 = L_mult0( igfMinFq, frameLength ); /*Q0*/
     484          96 :     tmp1 = sub( norm_l( L_tmp1 ), 1 );
     485          96 :     L_tmp1 = L_shl( L_tmp1, tmp1 ); /*tmp1*/
     486             : 
     487          96 :     tmp2 = norm_l( sampleRate );
     488          96 :     L_tmp2 = L_shl( sampleRate, tmp2 );                         /*tmp2*/
     489          96 :     tmp1 = add( WORD16_BITS - 1, sub( tmp1, add( tmp2, 1 ) ) ); /* takes into account sampleRate >> 1 */
     490             : 
     491          96 :     hGrid->minSrcSubband = div_s( extract_h( L_tmp1 ), extract_h( L_tmp2 ) ); /*tmp1*/
     492          96 :     hGrid->minSrcSubband = shr( hGrid->minSrcSubband, tmp1 );                 /*Q0*/
     493          96 :     move16();
     494          96 :     move16();
     495             : 
     496             : 
     497          96 :     hGrid->minSrcSubband = add( hGrid->minSrcSubband, s_and( hGrid->minSrcSubband, 1 ) );
     498          96 :     move16();
     499          96 :     hGrid->minSrcFrequency = imult1616( bandwidth, hGrid->minSrcSubband );
     500          96 :     move16();
     501          96 :     hGrid->infoGranuleLen = frameLength; /*Q0*/
     502          96 :     move16();
     503          96 :     hGrid->infoTransFac = transFac; /*Q14*/
     504          96 :     move16();
     505             : 
     506          96 :     hGrid->sfbWrap[0] = 0;
     507          96 :     move16();
     508          96 :     hGrid->tile[0] = hGrid->startLine; /*Q0*/
     509          96 :     move16();
     510             : 
     511             : 
     512             :     /*************************************************************************/
     513          96 :     SWITCH( bitRateIndex )
     514             :     {
     515             :             /* SWB 13200 */
     516           0 :         case IGF_BITRATE_WB_9600:
     517           0 :             hGrid->nTiles = 2;
     518           0 :             move16();
     519           0 :             wrp_sfb = 2;
     520           0 :             move16();
     521             : 
     522             :             /*1st*/
     523           0 :             hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/
     524           0 :             move16();
     525           0 :             hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/
     526           0 :             move16();
     527           0 :             hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/
     528           0 :             move16();
     529             : 
     530             :             /*2nd*/
     531           0 :             hGrid->sfbWrap[1 + 1] = hGrid->stopSfb; /*Q0*/
     532           0 :             move16();
     533           0 :             hGrid->sbWrap[1] = hGrid->minSrcSubband; /*Q0*/
     534           0 :             move16();
     535           0 :             hGrid->tile[1 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/
     536           0 :             move16();
     537           0 :             BREAK;
     538             : 
     539           0 :         case IGF_BITRATE_RF_WB_13200:
     540           0 :             hGrid->nTiles = 2;
     541           0 :             move16();
     542           0 :             wrp_sfb = 2;
     543           0 :             move16();
     544             : 
     545             :             /*1st*/
     546           0 :             hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/
     547           0 :             move16();
     548           0 :             hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/
     549           0 :             move16();
     550           0 :             hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/
     551           0 :             move16();
     552             : 
     553             :             /*2nd*/
     554           0 :             hGrid->sfbWrap[1 + 1] = hGrid->stopSfb; /*Q0*/
     555           0 :             move16();
     556           0 :             hGrid->sbWrap[1] = hGrid->minSrcSubband; /*Q0*/
     557           0 :             move16();
     558           0 :             hGrid->tile[1 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/
     559           0 :             move16();
     560             : 
     561           0 :             BREAK;
     562           0 :         case IGF_BITRATE_SWB_9600:
     563           0 :             hGrid->nTiles = 3;
     564           0 :             move16();
     565           0 :             wrp_sfb = 1;
     566           0 :             move16();
     567             : 
     568             :             /*1st*/
     569           0 :             hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/
     570           0 :             move16();
     571           0 :             hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/
     572           0 :             move16();
     573           0 :             hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/
     574           0 :             move16();
     575             : 
     576             :             /*2nd*/
     577           0 :             wrp_sfb = 2;
     578           0 :             move16();
     579           0 :             hGrid->sfbWrap[1 + 1] = wrp_sfb; /*Q0*/
     580           0 :             move16();
     581           0 :             hGrid->sbWrap[1] = hGrid->minSrcSubband + IGF_ApplyTransFac( 32, transFac ); /*Q0*/
     582           0 :             move16();
     583           0 :             hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/
     584           0 :             move16();
     585             : 
     586             :             /*3rd*/
     587           0 :             hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; /*Q0*/
     588           0 :             move16();
     589           0 :             hGrid->sbWrap[2] = hGrid->minSrcSubband + IGF_ApplyTransFac( 46, transFac ); /*Q0*/
     590           0 :             move16();
     591           0 :             hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/
     592           0 :             move16();
     593             : 
     594           0 :             BREAK;
     595           0 :         case IGF_BITRATE_RF_SWB_13200:
     596           0 :             hGrid->nTiles = 3;
     597           0 :             move16();
     598           0 :             wrp_sfb = 1;
     599           0 :             move16();
     600             : 
     601             :             /*1st*/
     602           0 :             hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/
     603           0 :             move16();
     604           0 :             hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/
     605           0 :             move16();
     606           0 :             hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/
     607           0 :             move16();
     608             : 
     609             :             /*2nd*/
     610           0 :             wrp_sfb = 2;
     611           0 :             move16();
     612           0 :             hGrid->sfbWrap[1 + 1] = wrp_sfb; /*Q0*/
     613           0 :             move16();
     614           0 :             hGrid->sbWrap[1] = hGrid->minSrcSubband + IGF_ApplyTransFac( 32, transFac ); /*Q0*/
     615           0 :             move16();
     616           0 :             hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/
     617           0 :             move16();
     618             : 
     619             :             /*3rd*/
     620           0 :             hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; /*Q0*/
     621           0 :             move16();
     622           0 :             hGrid->sbWrap[2] = hGrid->minSrcSubband + IGF_ApplyTransFac( 46, transFac ); /*Q0*/
     623           0 :             move16();
     624           0 :             hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/
     625           0 :             move16();
     626             : 
     627           0 :             BREAK;
     628             : 
     629          60 :         case IGF_BITRATE_SWB_13200:
     630          60 :             hGrid->nTiles = 2;
     631          60 :             move16();
     632          60 :             wrp_sfb = 4;
     633          60 :             move16();
     634             : 
     635             :             /*1st*/
     636          60 :             hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/
     637          60 :             move16();
     638          60 :             hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/
     639          60 :             move16();
     640          60 :             hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/
     641          60 :             move16();
     642             : 
     643             :             /*2nd*/
     644          60 :             hGrid->sfbWrap[1 + 1] = hGrid->stopSfb; /*Q0*/
     645          60 :             move16();
     646          60 :             hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 32, transFac ) ); /*Q0*/
     647          60 :             move16();
     648          60 :             hGrid->tile[1 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/
     649          60 :             move16();
     650          60 :             BREAK;
     651             : 
     652           0 :         case IGF_BITRATE_SWB_16400:
     653           0 :             hGrid->nTiles = 3;
     654           0 :             move16();
     655           0 :             wrp_sfb = 4;
     656           0 :             move16();
     657             : 
     658             :             /*1st*/
     659           0 :             hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/
     660           0 :             move16();
     661           0 :             hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/
     662           0 :             move16();
     663           0 :             hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/
     664           0 :             move16();
     665             : 
     666             :             /*2nd*/
     667           0 :             hGrid->sfbWrap[1 + 1] = 6;
     668           0 :             move16();
     669           0 :             hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 48, transFac ) ); /*Q0*/
     670           0 :             move16();
     671           0 :             hGrid->tile[1 + 1] = hGrid->swb_offset[6]; /*Q0*/
     672           0 :             move16();
     673             : 
     674             :             /*3nd*/
     675           0 :             hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; /*Q0*/
     676           0 :             move16();
     677           0 :             hGrid->sbWrap[2] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 64, transFac ) ); /*Q0*/
     678           0 :             move16();
     679           0 :             hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/
     680           0 :             move16();
     681           0 :             BREAK;
     682             : 
     683          36 :         case IGF_BITRATE_SWB_24400:
     684             :         case IGF_BITRATE_SWB_32000:
     685          36 :             hGrid->nTiles = 3;
     686          36 :             move16();
     687          36 :             wrp_sfb = 4;
     688          36 :             move16();
     689             : 
     690             :             /*1st*/
     691          36 :             hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/
     692          36 :             move16();
     693          36 :             hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/
     694          36 :             move16();
     695          36 :             hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/
     696          36 :             move16();
     697             : 
     698             :             /*2nd*/
     699          36 :             hGrid->sfbWrap[1 + 1] = 7;
     700          36 :             move16();
     701          36 :             hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 32, transFac ) ); /*Q0*/
     702          36 :             move16();
     703          36 :             hGrid->tile[1 + 1] = hGrid->swb_offset[7]; /*Q0*/
     704          36 :             move16();
     705             : 
     706             :             /*3nd*/
     707          36 :             hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; /*Q0*/
     708          36 :             move16();
     709          36 :             hGrid->sbWrap[2] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 64, transFac ) ); /*Q0*/
     710          36 :             move16();
     711          36 :             hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/
     712          36 :             move16();
     713          36 :             BREAK;
     714           0 :         case IGF_BITRATE_SWB_48000:
     715           0 :             hGrid->nTiles = 1;
     716           0 :             move16();
     717           0 :             wrp_sfb = hGrid->stopSfb;
     718           0 :             move16();
     719             : 
     720             :             /*1st*/
     721           0 :             hGrid->sfbWrap[0 + 1] = hGrid->stopSfb; /*Q0*/
     722           0 :             move16();
     723           0 :             hGrid->sbWrap[0] = sub( shl( hGrid->startLine, 1 ), hGrid->stopLine ); /*Q0*/
     724           0 :             move16();
     725           0 :             hGrid->tile[0 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/
     726           0 :             move16();
     727             : 
     728           0 :             BREAK;
     729           0 :         case IGF_BITRATE_FB_16400:
     730           0 :             hGrid->nTiles = 3;
     731           0 :             move16();
     732           0 :             wrp_sfb = 4;
     733           0 :             move16();
     734             : 
     735             :             /*1st*/
     736           0 :             hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/
     737           0 :             move16();
     738           0 :             hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/
     739           0 :             move16();
     740           0 :             hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/
     741           0 :             move16();
     742           0 :             wrp_sfb = 7;
     743           0 :             move16();
     744             : 
     745             :             /*2nd*/
     746           0 :             hGrid->sfbWrap[1 + 1] = wrp_sfb; /*Q0*/
     747           0 :             move16();
     748           0 :             hGrid->sbWrap[1] = hGrid->minSrcSubband; /*Q0*/
     749           0 :             move16();
     750           0 :             hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/
     751           0 :             move16();
     752             : 
     753             :             /*3nd*/
     754           0 :             hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; /*Q0*/
     755           0 :             move16();
     756           0 :             hGrid->sbWrap[2] = hGrid->minSrcSubband; /*Q0*/
     757           0 :             move16();
     758           0 :             hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/
     759           0 :             move16();
     760             : 
     761           0 :             BREAK;
     762             : 
     763           0 :         case IGF_BITRATE_FB_24400:
     764             :         case IGF_BITRATE_FB_32000:
     765           0 :             hGrid->nTiles = 4;
     766           0 :             move16();
     767           0 :             wrp_sfb = 4;
     768           0 :             move16();
     769             : 
     770             :             /*1st*/
     771           0 :             hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/
     772           0 :             move16();
     773           0 :             hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/
     774           0 :             move16();
     775           0 :             hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/
     776           0 :             move16();
     777           0 :             wrp_sfb = 6;
     778           0 :             move16();
     779             : 
     780             :             /*2nd*/
     781           0 :             hGrid->sfbWrap[1 + 1] = wrp_sfb; /*Q0*/
     782           0 :             move16();
     783           0 :             hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 32, transFac ) ); /*Q0*/
     784           0 :             move16();
     785           0 :             hGrid->tile[1 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/
     786           0 :             move16();
     787           0 :             wrp_sfb = 9;
     788           0 :             move16();
     789             : 
     790             :             /*3nd*/
     791           0 :             hGrid->sfbWrap[2 + 1] = wrp_sfb; /*Q0*/
     792           0 :             move16();
     793           0 :             hGrid->sbWrap[2] = hGrid->minSrcSubband; /*Q0*/
     794           0 :             move16();
     795           0 :             hGrid->tile[2 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/
     796           0 :             move16();
     797             : 
     798             :             /*4nd*/
     799           0 :             hGrid->sfbWrap[3 + 1] = hGrid->stopSfb; /*Q0*/
     800           0 :             move16();
     801           0 :             hGrid->sbWrap[3] = add( hGrid->minSrcSubband, sub( hGrid->swb_offset[9], hGrid->swb_offset[8] ) ); /*Q0*/
     802           0 :             move16();
     803           0 :             hGrid->tile[3 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/
     804           0 :             move16();
     805           0 :             BREAK;
     806           0 :         case IGF_BITRATE_FB_48000:
     807             :         case IGF_BITRATE_FB_96000:
     808             :         case IGF_BITRATE_FB_128000:
     809           0 :             hGrid->nTiles = 1;
     810           0 :             move16();
     811             : 
     812             :             /*1st*/
     813           0 :             hGrid->sfbWrap[0 + 1] = hGrid->stopSfb; /*Q0*/
     814           0 :             move16();
     815           0 :             hGrid->sbWrap[0] = sub( shl( hGrid->startLine, 1 ), hGrid->stopLine ); /*Q0*/
     816           0 :             move16();
     817           0 :             hGrid->tile[0 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/
     818           0 :             move16();
     819             : 
     820           0 :             BREAK;
     821           0 :         default:
     822           0 :             assert( 0 );
     823             :     } /*switch*/
     824             : 
     825             :     /*************************************************************************/
     826             :     /*************************************************************************/
     827             : 
     828             : 
     829             :     /* adapt level envelope: */
     830          96 :     SWITCH( bitRateIndex )
     831             :     {
     832           0 :         case IGF_BITRATE_RF_WB_13200:
     833             :         case IGF_BITRATE_WB_9600:
     834           0 :             hGrid->gFactor = 13107 /*0.80f Q14*/;
     835           0 :             move16();
     836           0 :             hGrid->fFactor = 11469 /*0.70f Q14*/;
     837           0 :             move16();
     838           0 :             hGrid->lFactor = 9830 /*0.60f Q14*/;
     839           0 :             move16();
     840           0 :             BREAK;
     841          60 :         case IGF_BITRATE_SWB_13200:
     842             :         case IGF_BITRATE_FB_16400:
     843             :         case IGF_BITRATE_SWB_16400:
     844          60 :             hGrid->gFactor = 15237 /*0.93f Q14*/;
     845          60 :             move16();
     846          60 :             hGrid->fFactor = 3277 /*0.20f Q14*/;
     847          60 :             move16();
     848          60 :             hGrid->lFactor = 13926 /*0.85f Q14*/;
     849          60 :             move16();
     850          60 :             BREAK;
     851          36 :         case IGF_BITRATE_FB_24400:
     852             :         case IGF_BITRATE_SWB_24400:
     853             :         case IGF_BITRATE_FB_32000:
     854             :         case IGF_BITRATE_SWB_32000:
     855          36 :             hGrid->gFactor = 15811 /*0.965f Q14*/;
     856          36 :             move16();
     857          36 :             hGrid->fFactor = 3277 /*0.20f Q14*/;
     858          36 :             move16();
     859          36 :             hGrid->lFactor = 13926 /*0.85f Q14*/;
     860          36 :             move16();
     861          36 :             BREAK;
     862           0 :         case IGF_BITRATE_FB_48000:
     863             :         case IGF_BITRATE_SWB_48000:
     864           0 :             hGrid->gFactor = 16384 /*1.00f Q14*/;
     865           0 :             move16();
     866           0 :             hGrid->fFactor = 3277 /*0.20f Q14*/;
     867           0 :             move16();
     868           0 :             hGrid->lFactor = 16384 /*1.00f Q14*/;
     869           0 :             move16();
     870           0 :             BREAK;
     871           0 :         case IGF_BITRATE_SWB_9600:
     872             :         case IGF_BITRATE_RF_SWB_13200:
     873             :         default:
     874           0 :             hGrid->gFactor = 16384 /*1.00f Q14*/;
     875           0 :             move16();
     876           0 :             hGrid->fFactor = 0 /*0.00f Q14*/;
     877           0 :             move16();
     878           0 :             hGrid->lFactor = 16384 /*1.00f Q14*/;
     879           0 :             move16();
     880             :     }
     881             : 
     882         732 :     FOR( t = add( hGrid->nTiles, 1 ); t < IGF_MAX_TILES; t++ )
     883             :     {
     884         636 :         hGrid->tile[t] = 0;
     885         636 :         move16();
     886         636 :         hGrid->sbWrap[t - 1] = 0;
     887         636 :         move16();
     888         636 :         hGrid->sfbWrap[t] = 0;
     889         636 :         move16();
     890             :     }
     891          96 : }
     892       54327 : static void IGF_gridSetUp_ivas_fx(
     893             :     H_IGF_GRID hGrid,        /* o  : IGF grid handle                                                    */
     894             :     Word16 bitRateIndex,     /* i  : IGF bitrate index                                                  */
     895             :     const Word32 sampleRate, /* i  : sample rate                                                        */
     896             :     Word16 frameLength,      /* i  : frame length                                                       */
     897             :     const Word16 transFac,   /* i  : transFac, Q14                                                      */
     898             :     const Word16 igfMinFq    /* i  : IGF minimum frequency indicating lower start frequency for copy up */
     899             : )
     900             : {
     901             :     Word16 t, k;
     902             :     Word16 sfb;
     903             :     Word16 swb_offset_len;
     904             :     const Word16 *swb_offset;
     905             :     Word16 bandwidth_fx;
     906             :     const Word16 *igf_tile_offset;
     907             :     Word16 tmp2, tmp1;
     908             :     Word32 L_tmp1, L_tmp2;
     909             : 
     910             :     /* inits */
     911       54327 :     swb_offset = NULL;
     912       54327 :     swb_offset_len = 0;
     913       54327 :     move16();
     914             : 
     915       54327 :     test();
     916       54327 :     test();
     917       54327 :     IF( EQ_16( transFac, 8192 /*0.5 in Q14*/ ) && EQ_16( bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) )
     918             :     {
     919         610 :         bitRateIndex = IGF_BITRATE_SWB_48000_CPE_TCX10;
     920         610 :         move16();
     921             :     }
     922       53717 :     ELSE IF( EQ_16( transFac, 8192 /*0.5 in Q14*/ ) && EQ_16( bitRateIndex, IGF_BITRATE_FB_48000_CPE ) )
     923             :     {
     924        1503 :         bitRateIndex = IGF_BITRATE_FB_48000_CPE_TCX10;
     925        1503 :         move16();
     926             :     }
     927             : 
     928       54327 :     IF( NE_16( bitRateIndex, IGF_BITRATE_UNKNOWN ) )
     929             :     {
     930       54327 :         swb_offset = &swb_offset_LB_new[bitRateIndex][1];
     931       54327 :         swb_offset_len = swb_offset_LB_new[bitRateIndex][0];
     932       54327 :         move16();
     933       54327 :         Copy( &igf_whitening_TH_ivas_fx[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2 );
     934             :     }
     935             :     ELSE
     936             :     {
     937           0 :         assert( 0 );
     938             :     }
     939             : 
     940      451863 :     FOR( sfb = 0; sfb < swb_offset_len; sfb++ )
     941             :     {
     942      397536 :         hGrid->swb_offset[sfb] = IGF_ApplyTransFac( swb_offset[sfb], transFac );
     943      397536 :         move16();
     944             :     }
     945      906312 :     FOR( sfb = swb_offset_len; sfb < IGF_MAX_SFB; sfb++ )
     946             :     {
     947      851985 :         hGrid->swb_offset[sfb] = 0;
     948      851985 :         move16();
     949             :     }
     950             : 
     951       54327 :     hGrid->infoIsRefined = 0;
     952       54327 :     move16();
     953       54327 :     frameLength = IGF_ApplyTransFac( frameLength, transFac ); /*Q0*/
     954       54327 :     tmp2 = norm_s( frameLength );
     955       54327 :     bandwidth_fx = shl( frameLength, tmp2 );                     /*tmp2*/
     956       54327 :     hGrid->swb_offset_len = extract_l( L_shr( sampleRate, 2 ) ); /*-1*/
     957       54327 :     move16();
     958       54327 :     tmp1 = sub( norm_s( hGrid->swb_offset_len ), 1 );
     959       54327 :     hGrid->swb_offset_len = shl( hGrid->swb_offset_len, tmp1 ); /*tmp1-1*/
     960       54327 :     move16();
     961       54327 :     bandwidth_fx = div_s( hGrid->swb_offset_len, bandwidth_fx ); /*15 + tmp1-1-tmp2*/
     962       54327 :     tmp2 = sub( add( tmp2, 1 ), tmp1 );
     963       54327 :     bandwidth_fx = shr( bandwidth_fx, sub( 15, tmp2 ) );
     964       54327 :     hGrid->swb_offset_len = swb_offset_len; /*Q0*/
     965       54327 :     move16();
     966       54327 :     hGrid->startSfb = 0;
     967       54327 :     move16();
     968       54327 :     hGrid->stopSfb = sub( hGrid->swb_offset_len, 1 );
     969       54327 :     move16();
     970       54327 :     hGrid->startLine = hGrid->swb_offset[hGrid->startSfb];
     971       54327 :     move16();
     972       54327 :     hGrid->stopLine = hGrid->swb_offset[hGrid->stopSfb];
     973       54327 :     move16();
     974       54327 :     hGrid->startFrequency = imult1616( bandwidth_fx, hGrid->startLine );
     975       54327 :     move16();
     976       54327 :     hGrid->stopFrequency = imult1616( bandwidth_fx, hGrid->stopLine );
     977       54327 :     move16();
     978       54327 :     L_tmp1 = L_mult0( igfMinFq, frameLength );
     979       54327 :     tmp1 = sub( norm_l( L_tmp1 ), 1 );
     980       54327 :     L_tmp1 = L_shl( L_tmp1, tmp1 );
     981       54327 :     tmp2 = norm_l( sampleRate );
     982       54327 :     L_tmp2 = L_shl( sampleRate, tmp2 );
     983       54327 :     tmp1 = add( WORD16_BITS - 1, sub( tmp1, add( tmp2, 1 ) ) ); /* takes into account sampleRate >> 1 */
     984       54327 :     hGrid->minSrcSubband = div_s( extract_h( L_tmp1 ), extract_h( L_tmp2 ) );
     985       54327 :     move16();
     986       54327 :     hGrid->minSrcSubband = shr( hGrid->minSrcSubband, tmp1 ); /*Q0*/
     987       54327 :     move16();
     988       54327 :     hGrid->minSrcSubband = add( hGrid->minSrcSubband, s_and( hGrid->minSrcSubband, 1 ) );
     989       54327 :     move16();
     990       54327 :     hGrid->minSrcFrequency = imult1616( bandwidth_fx, hGrid->minSrcSubband ); /*Q0*/
     991       54327 :     move16();
     992       54327 :     hGrid->infoGranuleLen = frameLength; /*Q0*/
     993       54327 :     move16();
     994       54327 :     hGrid->sfbWrap[0] = 0;
     995       54327 :     move16();
     996       54327 :     hGrid->tile[0] = hGrid->startLine; /*Q0*/
     997       54327 :     move16();
     998             : 
     999       54327 :     igf_tile_offset = &igf_tile_offset_table[bitRateIndex][1];
    1000       54327 :     hGrid->nTiles = igf_tile_offset_table[bitRateIndex][0];
    1001       54327 :     move16();
    1002       54327 :     hGrid->tile[0] = hGrid->startLine;
    1003       54327 :     move16();
    1004       54327 :     hGrid->sfbWrap[0] = 0;
    1005       54327 :     move16();
    1006      313572 :     FOR( k = 0; k < hGrid->nTiles; k++ )
    1007             :     {
    1008      259245 :         hGrid->sfbWrap[k + 1] = igf_tile_offset[2 * k];
    1009      259245 :         move16();
    1010      259245 :         hGrid->sbWrap[k] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( igf_tile_offset[2 * k + 1], transFac ) );
    1011      259245 :         move16();
    1012      259245 :         hGrid->tile[k + 1] = hGrid->swb_offset[igf_tile_offset[2 * k]]; /*Q0*/
    1013      259245 :         move16();
    1014             :     }
    1015      287895 :     FOR( t = hGrid->nTiles + 1; t < IGF_MAX_TILES; t++ )
    1016             :     {
    1017      233568 :         hGrid->tile[t] = 0;
    1018      233568 :         move16();
    1019      233568 :         hGrid->sbWrap[t - 1] = 0;
    1020      233568 :         move16();
    1021      233568 :         hGrid->sfbWrap[t] = 0;
    1022      233568 :         move16();
    1023             :     }
    1024             : 
    1025             :     /* adapt level envelope: */
    1026       54327 :     SWITCH( bitRateIndex )
    1027             :     {
    1028         309 :         case IGF_BITRATE_RF_WB_13200:
    1029             :         case IGF_BITRATE_WB_9600:
    1030             :         case IGF_BITRATE_WB_13200_CPE:
    1031             :         case IGF_BITRATE_WB_16400_CPE:
    1032         309 :             hGrid->gFactor = 13107 /*0.80f Q14*/;
    1033         309 :             move16();
    1034         309 :             hGrid->fFactor = 11469 /*0.70f Q14*/;
    1035         309 :             move16();
    1036         309 :             hGrid->lFactor = 9830 /*0.60f Q14*/;
    1037         309 :             move16();
    1038         309 :             BREAK;
    1039       11310 :         case IGF_BITRATE_SWB_13200:
    1040             :         case IGF_BITRATE_SWB_16400_CPE:
    1041             :         case IGF_BITRATE_FB_16400:
    1042             :         case IGF_BITRATE_SWB_16400:
    1043             :         case IGF_BITRATE_FB_24400_CPE:
    1044             :         case IGF_BITRATE_SWB_24400_CPE:
    1045       11310 :             hGrid->gFactor = 15237 /*0.93f Q14*/;
    1046       11310 :             move16();
    1047       11310 :             hGrid->fFactor = 3277 /*0.20f Q14*/;
    1048       11310 :             move16();
    1049       11310 :             hGrid->lFactor = 13926 /*0.85f Q14*/;
    1050       11310 :             move16();
    1051       11310 :             BREAK;
    1052       11774 :         case IGF_BITRATE_FB_24400:
    1053             :         case IGF_BITRATE_SWB_24400:
    1054             :         case IGF_BITRATE_FB_32000_CPE:
    1055             :         case IGF_BITRATE_SWB_32000_CPE:
    1056             :         case IGF_BITRATE_FB_32000:
    1057             :         case IGF_BITRATE_SWB_32000:
    1058             :         case IGF_BITRATE_SWB_48000_CPE:
    1059             :         case IGF_BITRATE_SWB_64000_CPE:
    1060       11774 :             hGrid->gFactor = 15811 /*0.965f Q14*/;
    1061       11774 :             move16();
    1062       11774 :             hGrid->fFactor = 3277 /*0.20f Q14*/;
    1063       11774 :             move16();
    1064       11774 :             hGrid->lFactor = 13926 /*0.85f Q14*/;
    1065       11774 :             move16();
    1066       11774 :             BREAK;
    1067        5448 :         case IGF_BITRATE_FB_48000:
    1068             :         case IGF_BITRATE_SWB_48000:
    1069             :         case IGF_BITRATE_FB_64000:
    1070             :         case IGF_BITRATE_SWB_64000:
    1071             :         case IGF_BITRATE_SWB_80000_CPE:
    1072             :         case IGF_BITRATE_SWB_96000_CPE:
    1073        5448 :             hGrid->gFactor = 16384 /*1.00f Q14*/;
    1074        5448 :             move16();
    1075        5448 :             hGrid->fFactor = 3277 /*0.20f Q14*/;
    1076        5448 :             move16();
    1077        5448 :             hGrid->lFactor = 16384 /*1.00f Q14*/;
    1078        5448 :             move16();
    1079        5448 :             BREAK;
    1080       25486 :         case IGF_BITRATE_SWB_9600:
    1081             :         case IGF_BITRATE_SWB_13200_CPE:
    1082             :         case IGF_BITRATE_RF_SWB_13200:
    1083             :         default:
    1084       25486 :             hGrid->gFactor = 16384 /*1.00f Q14*/;
    1085       25486 :             move16();
    1086       25486 :             hGrid->fFactor = 0; /*0.00f Q30*/
    1087       25486 :             move16();
    1088       25486 :             hGrid->lFactor = 16384 /*1.00f Q14*/;
    1089       25486 :             move16();
    1090             :     }
    1091             : 
    1092      287895 :     FOR( t = add( hGrid->nTiles, 1 ); t < IGF_MAX_TILES; t++ )
    1093             :     {
    1094      233568 :         hGrid->tile[t] = 0;
    1095      233568 :         move16();
    1096      233568 :         hGrid->sbWrap[t - 1] = 0;
    1097      233568 :         move16();
    1098      233568 :         hGrid->sfbWrap[t] = 0;
    1099      233568 :         move16();
    1100             :     }
    1101       54327 :     return;
    1102             : }
    1103             : 
    1104             : 
    1105             : /**********************************************************************/ /*
    1106             : calculates energy per sfb via power spectrum
    1107             : **************************************************************************/
    1108     2377463 : void IGFCommonFuncsCalcSfbEnergyPowerSpec( const Word16 startSfb,        /**< in: Q0  | start sfb index                                          */
    1109             :                                            const Word16 stopSfb,         /**< in: Q0  | stop  sfb index                                          */
    1110             :                                            const Word16 *swb_offset,     /**< in: Q0  | IGF swb offset table                                     */
    1111             :                                            Word32 *pPowerSpectrum,       /**< in: Q31 | power spectrum                                           */
    1112             :                                            Word16 *pPowerSpectrum_exp,   /**< in:     | Exponent of PowerSpectrum                                */
    1113             :                                            Word32 *sfbEnergy,            /**< out:Q31 | SFB energies , will be initialized inside this function  */
    1114             :                                            Word16 *sfbEnergy_exp         /**< out:    | Exponent of PowerSpectrum                                */
    1115             : )
    1116             : {
    1117             :     Word16 /*Q0*/ sfb;
    1118             :     Word16 /*Q0*/ line;
    1119             :     Word32 L_c;
    1120             : 
    1121             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
    1122     2377463 :     Flag Overflow = 0;
    1123     2377463 :     Flag Carry = 0;
    1124     2377463 :     move16();
    1125     2377463 :     move16();
    1126             : #endif
    1127             : 
    1128    12893575 :     FOR( sfb = startSfb; sfb < stopSfb; sfb++ )
    1129             :     {
    1130    10516112 :         sfbEnergy[sfb] = L_deposit_l( 0 );
    1131    10516112 :         move32();
    1132             :     }
    1133     2377463 :     IF( NULL == pPowerSpectrum )
    1134             :     {
    1135           0 :         return;
    1136             :     }
    1137             : 
    1138    12893575 :     FOR( sfb = startSfb; sfb < stopSfb; sfb++ )
    1139             :     {
    1140    10516112 :         L_c = L_deposit_l( 0 );
    1141   323225492 :         FOR( line = swb_offset[sfb]; line < swb_offset[sfb + 1]; line++ )
    1142             :         {
    1143   312709380 :             Carry = 0;
    1144   312709380 :             move16();
    1145   312709380 :             sfbEnergy[sfb] = L_add_co( sfbEnergy[sfb], pPowerSpectrum[line], &Carry, &Overflow );
    1146   312709380 :             move32();
    1147   312709380 :             Overflow = 0;
    1148   312709380 :             move16();
    1149   312709380 :             L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow );
    1150             :         }
    1151    10516112 :         sfbEnergy[sfb] = norm_llQ31( L_c, sfbEnergy[sfb], &( sfbEnergy_exp[sfb] ) );
    1152    10516112 :         move32();
    1153    10516112 :         sfbEnergy_exp[sfb] = add( sfbEnergy_exp[sfb], *pPowerSpectrum_exp );
    1154    10516112 :         move16();
    1155             :     }
    1156             : }
    1157             : 
    1158             : /**********************************************************************/ /*
    1159             : calculate the MDCT square spectrum in the IGF range
    1160             : **************************************************************************/
    1161        2926 : void IGFCommonFuncsMDCTSquareSpec( const Word16 sqrtBgn,                 /**< in: Q0  | start MDCT subband index       */
    1162             :                                    const Word16 sqrtEnd,                 /**< in: Q0  | stop  MDCT subband index       */
    1163             :                                    const Word32 *mdctSpec,               /**< in:     | MDCT spectrum to square        */
    1164             :                                    const Word16 mdctSpec_e,              /**< in:     | exponent of mdctSpectrum       */
    1165             :                                    Word32 *mdctSquareSpec,               /**< out:    | MDCT square spectrum           */
    1166             :                                    Word16 *mdctSquareSpec_e,             /**< out:    | exponent of mdctSquareSpec     */
    1167             :                                    Word16 indexOffset                    /**< in: Q0  | index offset                   */
    1168             : )
    1169             : {
    1170             :     Word16 i;
    1171             :     Word16 j;
    1172             :     Word16 s1;
    1173             :     Word16 tmp;
    1174             : 
    1175             : 
    1176             :     /* get headroom, only in IGF range */
    1177        2926 :     s1 = getScaleFactor32( mdctSpec + sqrtBgn, sub( sqrtEnd, sqrtBgn ) );
    1178             : 
    1179             :     /* set new exponent */
    1180        2926 :     *mdctSquareSpec_e = add( shl( sub( mdctSpec_e, s1 ), 1 ), 1 );
    1181        2926 :     move16();
    1182             : 
    1183             :     /* MDCT square spectrum: MDCT^2 */
    1184        2926 :     j = add( sqrtBgn, indexOffset ); /* handle indexOffset with care, otherwise memory overruns may occur! */
    1185             : 
    1186             : 
    1187      475594 :     FOR( i = sqrtBgn; i < sqrtEnd; i++ )
    1188             :     {
    1189      472668 :         tmp = round_fx_sat( L_shl_sat( mdctSpec[i], s1 ) ); /*(15 - mdctSpec_e)+ S1*/
    1190      472668 :         mdctSquareSpec[j++] = L_mult0( tmp, tmp );          /*31 - mdctSquareSpec_e*/
    1191      472668 :         move32();
    1192             :     }
    1193        2926 : }
    1194             : 
    1195             : /**********************************************************************/ /*
    1196             : calculate the MDCT square spectrum in the IGF range (for IVAS)
    1197             : **************************************************************************/
    1198     2913964 : void IGFCommonFuncsMDCTSquareSpec_ivas( const Word16 sqrtBgn,            /**< in: Q0  | start MDCT subband index       */
    1199             :                                         const Word16 sqrtEnd,            /**< in: Q0  | stop  MDCT subband index       */
    1200             :                                         const Word32 *mdctSpec,          /**< in:     | MDCT spectrum to square        */
    1201             :                                         const Word16 mdctSpec_e,         /**< in:     | exponent of mdctSpectrum       */
    1202             :                                         Word32 *mdctSquareSpec,          /**< out:    | MDCT square spectrum           */
    1203             :                                         Word16 *mdctSquareSpec_e,        /**< out:    | exponent of mdctSquareSpec     */
    1204             :                                         Word16 indexOffset               /**< in: Q0  | index offset                   */
    1205             : )
    1206             : {
    1207             :     Word16 i;
    1208             :     Word16 j;
    1209             :     Word16 s1;
    1210             :     Word16 tmp;
    1211             : 
    1212             : 
    1213             :     /* get headroom, only in IGF range */
    1214     2913964 :     s1 = getScaleFactor32( mdctSpec + sqrtBgn, sub( sqrtEnd, sqrtBgn ) );
    1215             : 
    1216             :     /* set new exponent */
    1217     2913964 :     *mdctSquareSpec_e = add( shl( sub( mdctSpec_e, s1 ), 1 ), 1 );
    1218     2913964 :     move16();
    1219             : 
    1220             :     /* MDCT square spectrum: MDCT^2 */
    1221     2913964 :     j = add( sqrtBgn, indexOffset ); /* handle indexOffset with care, otherwise memory overruns may occur! */
    1222             : 
    1223             : 
    1224   328096924 :     FOR( i = sqrtBgn; i < sqrtEnd; i++ )
    1225             :     {
    1226   325182960 :         tmp = extract_h( L_shl( mdctSpec[i], s1 ) ); /*(15 - mdctSpec_e)+ S1*/
    1227   325182960 :         mdctSquareSpec[j++] = L_mult0( tmp, tmp );   /*31 - mdctSquareSpec_e*/
    1228   325182960 :         move32();
    1229             :     }
    1230     2913964 : }
    1231             : 
    1232             : 
    1233             : /**********************************************************************/ /*
    1234             : write bits to stream
    1235             : **************************************************************************/
    1236           0 : void IGFCommonFuncsWriteSerialBit(
    1237             :     BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle       */
    1238             :     Word16 *pBitOffset,    /**< out: Q0 | bit offset                       */
    1239             :     Word16 bit             /**< in: Q0  | value of bit                     */
    1240             : )
    1241             : {
    1242             : 
    1243           0 :     IF( hBstr )
    1244             :     {
    1245           0 :         push_next_indice( hBstr, bit, 1 );
    1246             :     }
    1247           0 :     *pBitOffset = add( *pBitOffset, 1 );
    1248           0 :     move16();
    1249             : 
    1250           0 :     return;
    1251             : }
    1252             : 
    1253             : /**********************************************************************/ /*
    1254             : changes the IGF configuration
    1255             : **************************************************************************/
    1256          32 : Word16 IGFCommonFuncsIGFConfiguration(
    1257             :     const Word32 total_brate,  /* i  : bitrate in bs e.g. 9600 for 9.6kbs  */
    1258             :     const Word16 bwidth,       /* i  : audio bandwidth                     */
    1259             :     const Word16 element_mode, /* i  : element mode                        */
    1260             :     H_IGF_INFO hIGFInfo,       /* o  : IGF info handle                     */
    1261             :     const Word16 rf_mode       /* i  : flag to signal the RF mode          */
    1262             : )
    1263             : {
    1264             :     H_IGF_GRID hGrid;
    1265             :     Word16 retValue;
    1266             :     Word32 sampleRate;
    1267             :     Word16 frameLength;
    1268             :     Word16 igfMinFq;
    1269             :     Word16 maxHopsize;
    1270             : 
    1271          32 :     retValue = 0; /* bitrate index is unknown -> error! */
    1272          32 :     move16();
    1273             : 
    1274             :     /* interface call for reading in settings */
    1275          32 :     hIGFInfo->bitRateIndex = IGF_MapBitRateToIndex( total_brate, bwidth, element_mode, rf_mode ); /*Q0*/
    1276          32 :     move16();
    1277             : 
    1278          32 :     IF( NE_16( hIGFInfo->bitRateIndex, IGF_BITRATE_UNKNOWN ) )
    1279             :     {
    1280          32 :         retValue = 1; /* no error */
    1281          32 :         move16();
    1282             : 
    1283             :         /* mapping to local values */
    1284          32 :         sampleRate = igfMode[hIGFInfo->bitRateIndex].sampleRate; /*Q0*/
    1285          32 :         move32();
    1286          32 :         frameLength = igfMode[hIGFInfo->bitRateIndex].frameLength; /*Q0*/
    1287          32 :         move16();
    1288          32 :         igfMinFq = igfMode[hIGFInfo->bitRateIndex].igfMinFq; /*Q0*/
    1289          32 :         move16();
    1290          32 :         maxHopsize = igfMode[hIGFInfo->bitRateIndex].maxHopsize; /*Q0*/
    1291          32 :         move16();
    1292             : 
    1293             :         /* basic information */
    1294          32 :         hIGFInfo->sampleRate = sampleRate; /*Q0*/
    1295          32 :         move32();
    1296          32 :         hIGFInfo->frameLength = frameLength; /*Q0*/
    1297          32 :         move16();
    1298          32 :         hIGFInfo->maxHopsize = maxHopsize; /*Q0*/
    1299          32 :         move16();
    1300             : 
    1301          32 :         hIGFInfo->nfSeedBuf[0] = 0;
    1302          32 :         move16();
    1303          32 :         hIGFInfo->nfSeedBuf[1] = 0;
    1304          32 :         move16();
    1305          32 :         hIGFInfo->nfSeed = &hIGFInfo->nfSeedBuf[0];
    1306          32 :         move16();
    1307             : 
    1308             :         /* set up regular IGF grid for TCX 20  (transfac = 1.f) */
    1309          32 :         hGrid = &hIGFInfo->grid[IGF_GRID_LB_NORM];
    1310          32 :         IGF_gridSetUp( hGrid,
    1311          32 :                        hIGFInfo->bitRateIndex,
    1312             :                        sampleRate,
    1313             :                        frameLength,
    1314             :                        16384 /*1 Q14*/,
    1315             :                        igfMinFq );
    1316             : 
    1317             :         /* set up IGF grid for CELP->TCX 20 transitions (transfac = 1.25) */
    1318          32 :         hGrid = &hIGFInfo->grid[IGF_GRID_LB_TRAN];
    1319          32 :         IGF_gridSetUp( hGrid,
    1320          32 :                        hIGFInfo->bitRateIndex,
    1321             :                        sampleRate,
    1322             :                        frameLength,
    1323             :                        20480 /*1.25 Q14*/,
    1324             :                        igfMinFq );
    1325             :         /* set up IGF grid for TCX 10 (transfac = 0.5) */
    1326          32 :         hGrid = &hIGFInfo->grid[IGF_GRID_LB_SHORT];
    1327          32 :         IGF_gridSetUp( hGrid,
    1328          32 :                        hIGFInfo->bitRateIndex,
    1329             :                        sampleRate,
    1330             :                        frameLength,
    1331             :                        8192 /*0.50f Q14*/,
    1332             :                        igfMinFq );
    1333             :     }
    1334             : 
    1335          32 :     return retValue;
    1336             : }
    1337       18109 : Word16 IGFCommonFuncsIGFConfiguration_ivas_fx(
    1338             :     const Word32 total_brate,  /* i  : bitrate in bs e.g. 9600 for 9.6kbs  */
    1339             :     const Word16 bwidth,       /* i  : audio bandwidth                     */
    1340             :     const Word16 element_mode, /* i  : element mode                        */
    1341             :     H_IGF_INFO hIGFInfo,       /* o  : IGF info handle                     */
    1342             :     const Word16 rf_mode       /* i  : flag to signal the RF mode          */
    1343             : )
    1344             : {
    1345             :     H_IGF_GRID hGrid;
    1346             :     Word16 retValue;
    1347             :     Word32 sampleRate;
    1348             :     Word16 frameLength;
    1349             :     Word16 igfMinFq;
    1350             :     Word16 maxHopsize;
    1351             : 
    1352       18109 :     retValue = 0; /* bitrate index is unknown -> error! */
    1353       18109 :     move16();
    1354             : 
    1355             :     /* interface call for reading in settings */
    1356       18109 :     hIGFInfo->bitRateIndex = IGF_MapBitRateToIndex( total_brate, bwidth, element_mode, rf_mode ); /*Q0*/
    1357             : 
    1358       18109 :     IF( NE_16( hIGFInfo->bitRateIndex, IGF_BITRATE_UNKNOWN ) )
    1359             :     {
    1360       18109 :         retValue = 1; /* no error */
    1361       18109 :         move16();
    1362             : 
    1363             :         /* mapping to local values */
    1364       18109 :         sampleRate = igfMode[hIGFInfo->bitRateIndex].sampleRate; /*Q0*/
    1365       18109 :         move32();
    1366       18109 :         frameLength = igfMode[hIGFInfo->bitRateIndex].frameLength; /*Q0*/
    1367       18109 :         move16();
    1368       18109 :         igfMinFq = igfMode[hIGFInfo->bitRateIndex].igfMinFq; /*Q0*/
    1369       18109 :         move16();
    1370       18109 :         maxHopsize = igfMode[hIGFInfo->bitRateIndex].maxHopsize; /*Q0*/
    1371       18109 :         move16();
    1372             : 
    1373             :         /* basic information */
    1374       18109 :         hIGFInfo->sampleRate = sampleRate; /*Q0*/
    1375       18109 :         move32();
    1376       18109 :         hIGFInfo->frameLength = frameLength; /*Q0*/
    1377       18109 :         move16();
    1378       18109 :         hIGFInfo->maxHopsize = maxHopsize; /*Q0*/
    1379       18109 :         move16();
    1380       18109 :         hIGFInfo->nfSeedBuf[0] = 0;
    1381       18109 :         move16();
    1382       18109 :         hIGFInfo->nfSeedBuf[1] = 0;
    1383       18109 :         move16();
    1384       18109 :         hIGFInfo->nfSeed = &hIGFInfo->nfSeedBuf[0];
    1385       18109 :         move16();
    1386             : 
    1387             :         /* set up regular IGF grid for TCX 20  (transfac = 1.f) */
    1388       18109 :         hGrid = &hIGFInfo->grid[IGF_GRID_LB_NORM];
    1389       18109 :         IGF_gridSetUp_ivas_fx( hGrid,
    1390       18109 :                                hIGFInfo->bitRateIndex,
    1391             :                                sampleRate,
    1392             :                                frameLength,
    1393             :                                16384 /*1 Q14*/,
    1394             :                                igfMinFq );
    1395             :         /* set up IGF grid for CELP->TCX 20 transitions (transfac = 1.25) */
    1396       18109 :         hGrid = &hIGFInfo->grid[IGF_GRID_LB_TRAN];
    1397       18109 :         IGF_gridSetUp_ivas_fx( hGrid,
    1398       18109 :                                hIGFInfo->bitRateIndex,
    1399             :                                sampleRate,
    1400             :                                frameLength,
    1401             :                                20480 /*1.25 Q14*/,
    1402             :                                igfMinFq );
    1403             :         /* set up IGF grid for TCX 10 (transfac = 0.5) */
    1404       18109 :         hGrid = &hIGFInfo->grid[IGF_GRID_LB_SHORT];
    1405       18109 :         IGF_gridSetUp_ivas_fx( hGrid,
    1406       18109 :                                hIGFInfo->bitRateIndex,
    1407             :                                sampleRate,
    1408             :                                frameLength,
    1409             :                                8192 /*0.50f Q14*/,
    1410             :                                igfMinFq );
    1411             :     }
    1412             : 
    1413       18109 :     return retValue; /*Q0*/
    1414             : }
    1415             : 
    1416             : /**********************************************************************/ /*
    1417             : selects cumulative frequency tables and offsets for the IGF SCF arithmetic coder
    1418             : **************************************************************************/
    1419       18141 : Word16 IGFCommonFuncsIGFGetCFTables_fx(
    1420             :     const Word32 total_brate,   /* i  : bitrate in bs e.g. 9600 for 9.6kbs  */
    1421             :     const Word16 bwidth,        /* i  : audio bandwidth                     */
    1422             :     const Word16 element_mode,  /* i  : element mode                        */
    1423             :     const Word16 rf_mode,       /* i  : flag to signal the RF mode          */
    1424             :     const UWord16 **cf_se00,    /* o  : CF table for t == 0 and f == 0      */
    1425             :     const UWord16 **cf_se01,    /* o  : CF table for t == 0 and f == 1      */
    1426             :     Word16 *cf_off_se01,        /* o  : offset for CF table above           */
    1427             :     const UWord16 **cf_se02,    /* o  : CF tables for t == 0 and f >= 2     */
    1428             :     const Word16 **cf_off_se02, /* o  : offsets for CF tables above         */
    1429             :     const UWord16 **cf_se10,    /* o  : CF table for t == 1 and f == 0      */
    1430             :     Word16 *cf_off_se10,        /* o  : offset for CF table above           */
    1431             :     const UWord16 **cf_se11,    /* o  : CF tables for t == 1 and f >= 1     */
    1432             :     const Word16 **cf_off_se11  /* o  : offsets for CF tables above         */
    1433             : )
    1434             : {
    1435             :     Word16 retValue;
    1436             :     Word16 bitRateIndex;
    1437             : 
    1438       18141 :     retValue = 0; /* bitrate index is unknown -> error! */
    1439       18141 :     move16();
    1440             : 
    1441       18141 :     bitRateIndex = IGF_MapBitRateToIndex( total_brate, bwidth, element_mode, rf_mode );
    1442             : 
    1443       18141 :     IF( NE_32( bitRateIndex, IGF_BITRATE_UNKNOWN ) )
    1444             :     {
    1445       18141 :         retValue = 1; /* no error */
    1446       18141 :         move16();
    1447             : 
    1448       18141 :         SWITCH( bitRateIndex )
    1449             :         {
    1450          58 :             case IGF_BITRATE_WB_13200_CPE:
    1451          58 :                 bitRateIndex = IGF_BITRATE_WB_9600;
    1452          58 :                 move16();
    1453          58 :                 BREAK;
    1454          35 :             case IGF_BITRATE_WB_16400_CPE:
    1455          35 :                 bitRateIndex = IGF_BITRATE_WB_9600;
    1456          35 :                 move16();
    1457          35 :                 BREAK;
    1458        1243 :             case IGF_BITRATE_SWB_13200_CPE:
    1459        1243 :                 bitRateIndex = IGF_BITRATE_SWB_9600;
    1460        1243 :                 move16();
    1461        1243 :                 BREAK;
    1462        1512 :             case IGF_BITRATE_SWB_16400_CPE:
    1463        1512 :                 bitRateIndex = IGF_BITRATE_SWB_13200;
    1464        1512 :                 move16();
    1465        1512 :                 BREAK;
    1466         982 :             case IGF_BITRATE_SWB_24400_CPE:
    1467         982 :                 bitRateIndex = IGF_BITRATE_SWB_16400;
    1468         982 :                 move16();
    1469         982 :                 BREAK;
    1470        1276 :             case IGF_BITRATE_FB_24400_CPE:
    1471        1276 :                 bitRateIndex = IGF_BITRATE_FB_16400;
    1472        1276 :                 move16();
    1473        1276 :                 BREAK;
    1474         514 :             case IGF_BITRATE_SWB_32000_CPE:
    1475         514 :                 bitRateIndex = IGF_BITRATE_SWB_24400;
    1476         514 :                 move16();
    1477         514 :                 BREAK;
    1478        1290 :             case IGF_BITRATE_FB_32000_CPE:
    1479        1290 :                 bitRateIndex = IGF_BITRATE_FB_24400;
    1480        1290 :                 move16();
    1481        1290 :                 BREAK;
    1482        3602 :             case IGF_BITRATE_FB_48000_CPE:
    1483             :             case IGF_BITRATE_FB_64000_CPE:
    1484        3602 :                 bitRateIndex = IGF_BITRATE_FB_32000;
    1485        3602 :                 move16();
    1486        3602 :                 BREAK;
    1487             :         }
    1488             : 
    1489       18141 :         switch ( bitRateIndex )
    1490             :         {
    1491        4750 :             case IGF_BITRATE_WB_9600:
    1492             :             case IGF_BITRATE_RF_WB_13200:
    1493             :             case IGF_BITRATE_SWB_9600:
    1494             :             case IGF_BITRATE_SWB_13200:
    1495             :             case IGF_BITRATE_RF_SWB_13200:
    1496             :             case IGF_BITRATE_SWB_16400:
    1497             :             case IGF_BITRATE_SWB_24400:
    1498             :             case IGF_BITRATE_SWB_32000:
    1499             :             case IGF_BITRATE_SWB_48000:
    1500             :             case IGF_BITRATE_SWB_64000:
    1501        4750 :                 *cf_se00 = cf_se00_tab;
    1502        4750 :                 *cf_se01 = cf_se01_tab[bitRateIndex];
    1503        4750 :                 *cf_off_se01 = cf_off_se01_tab[bitRateIndex];
    1504        4750 :                 *cf_se02 = &cf_se02_tab[bitRateIndex][0][0];
    1505        4750 :                 *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0];
    1506        4750 :                 *cf_se10 = &cf_se10_tab[0];
    1507        4750 :                 *cf_off_se10 = cf_off_se10_tab;
    1508        4750 :                 *cf_se11 = &cf_se11_tab[0][0][0];
    1509        4750 :                 *cf_off_se11 = &cf_off_se11_tab[0][0];
    1510             : 
    1511        4750 :                 BREAK;
    1512        6822 :             case IGF_BITRATE_FB_16400:
    1513             :             case IGF_BITRATE_FB_24400:
    1514             :             case IGF_BITRATE_FB_32000:
    1515        6822 :                 bitRateIndex = add( sub( bitRateIndex, IGF_BITRATE_FB_16400 ), IGF_BITRATE_SWB_16400 );
    1516        6822 :                 *cf_se00 = cf_se00_tab;
    1517        6822 :                 *cf_se01 = cf_se01_tab[bitRateIndex];
    1518        6822 :                 *cf_off_se01 = cf_off_se01_tab[bitRateIndex];
    1519        6822 :                 *cf_se02 = &cf_se02_tab[bitRateIndex][0][0];
    1520        6822 :                 *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0];
    1521        6822 :                 *cf_se10 = &cf_se10_tab[0];
    1522        6822 :                 *cf_off_se10 = cf_off_se10_tab;
    1523        6822 :                 *cf_se11 = &cf_se11_tab[0][0][0];
    1524        6822 :                 *cf_off_se11 = &cf_off_se11_tab[0][0];
    1525        6822 :                 BREAK;
    1526        1191 :             case IGF_BITRATE_FB_48000:
    1527             :             case IGF_BITRATE_FB_64000:
    1528        1191 :                 bitRateIndex = add( sub( bitRateIndex, IGF_BITRATE_FB_48000 ), IGF_BITRATE_SWB_48000 );
    1529        1191 :                 *cf_se00 = cf_se00_tab;
    1530        1191 :                 *cf_se01 = cf_se01_tab[bitRateIndex];
    1531        1191 :                 *cf_off_se01 = cf_off_se01_tab[bitRateIndex];
    1532        1191 :                 *cf_se02 = &cf_se02_tab[bitRateIndex][0][0];
    1533        1191 :                 *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0];
    1534        1191 :                 *cf_se10 = &cf_se10_tab[0];
    1535        1191 :                 *cf_off_se10 = cf_off_se10_tab;
    1536        1191 :                 *cf_se11 = &cf_se11_tab[0][0][0];
    1537        1191 :                 *cf_off_se11 = &cf_off_se11_tab[0][0];
    1538        1191 :                 BREAK;
    1539        3447 :             case IGF_BITRATE_FB_96000:
    1540             :             case IGF_BITRATE_FB_128000:
    1541             :             case IGF_BITRATE_FB_80000_CPE:
    1542             :             case IGF_BITRATE_FB_96000_CPE:
    1543             :             case IGF_BITRATE_FB_128000_CPE:
    1544        3447 :                 bitRateIndex = IGF_BITRATE_SWB_48000;
    1545        3447 :                 *cf_se00 = cf_se00_tab;
    1546        3447 :                 *cf_se01 = cf_se01_tab[bitRateIndex];
    1547        3447 :                 *cf_off_se01 = cf_off_se01_tab[bitRateIndex];
    1548        3447 :                 *cf_se02 = &cf_se02_tab[bitRateIndex][0][0];
    1549        3447 :                 *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0];
    1550        3447 :                 *cf_se10 = &cf_se10_tab[0];
    1551        3447 :                 *cf_off_se10 = cf_off_se10_tab;
    1552        3447 :                 *cf_se11 = &cf_se11_tab[0][0][0];
    1553        3447 :                 *cf_off_se11 = &cf_off_se11_tab[0][0];
    1554        3447 :                 BREAK;
    1555         610 :             case IGF_BITRATE_SWB_48000_CPE:
    1556         610 :                 bitRateIndex = IGF_BITRATE_SWB_16400;
    1557         610 :                 *cf_se00 = cf_se00_tab;
    1558         610 :                 *cf_se01 = cf_se01_tab[bitRateIndex];
    1559         610 :                 *cf_off_se01 = cf_off_se01_tab[bitRateIndex];
    1560         610 :                 *cf_se02 = &cf_se02_tab[bitRateIndex][0][0];
    1561         610 :                 *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0];
    1562         610 :                 *cf_se10 = &cf_se10_tab[0];
    1563         610 :                 *cf_off_se10 = cf_off_se10_tab;
    1564         610 :                 *cf_se11 = &cf_se11_tab[0][0][0];
    1565         610 :                 *cf_off_se11 = &cf_off_se11_tab[0][0];
    1566         610 :                 BREAK;
    1567        1321 :             case IGF_BITRATE_SWB_64000_CPE:
    1568             :             case IGF_BITRATE_SWB_80000_CPE:
    1569             :             case IGF_BITRATE_SWB_96000_CPE:
    1570        1321 :                 bitRateIndex = IGF_BITRATE_SWB_48000; /*bitRateIndex-IGF_BITRATE_SWB_56000+IGF_BITRATE_SWB_48000;*/
    1571        1321 :                 *cf_se00 = cf_se00_tab;
    1572        1321 :                 *cf_se01 = cf_se01_tab[bitRateIndex];
    1573        1321 :                 *cf_off_se01 = cf_off_se01_tab[bitRateIndex];
    1574        1321 :                 *cf_se02 = &cf_se02_tab[bitRateIndex][0][0];
    1575        1321 :                 *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0];
    1576        1321 :                 *cf_se10 = &cf_se10_tab[0];
    1577        1321 :                 *cf_off_se10 = cf_off_se10_tab;
    1578        1321 :                 *cf_se11 = &cf_se11_tab[0][0][0];
    1579        1321 :                 *cf_off_se11 = &cf_off_se11_tab[0][0];
    1580        1321 :                 BREAK;
    1581           0 :             case IGF_BITRATE_UNKNOWN:
    1582             :             default:
    1583           0 :                 assert( 0 );
    1584             :         }
    1585           0 :     }
    1586             : 
    1587       18141 :     return retValue;
    1588             : }

Generated by: LCOV version 1.14