LCOV - code coverage report
Current view: top level - lib_com - igf_base_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 657 954 68.9 %
Date: 2025-05-03 01:55:50 Functions: 11 11 100.0 %

          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     2971416 : 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     2971416 :     IF( EQ_16( transFac, 0x4000 /*ONE in Q14*/ ) )
      26             :     {
      27     1034710 :         return val;
      28             :     }
      29             : 
      30     1936706 :     ret = shl( val, 1 );
      31     1936706 :     ret = mac_r( 0x00000000, ret, transFac );
      32     1936706 :     ret = add( ret, s_and( ret, 1 ) ); /*Q0*/
      33             : 
      34             : 
      35     1936706 :     return ret; /*Q0*/
      36             : }
      37             : 
      38             : /**********************************************************************/ /*
      39             : maps a given bitrate to the IGF_BITRATE index
      40             : **************************************************************************/
      41      926386 : 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      926386 :     Word16 bitRateIndex = IGF_BITRATE_UNKNOWN;
      49      926386 :     move16();
      50             :     /* Stereo/CPE modes */
      51      926386 :     IF( GT_16( element_mode, IVAS_SCE ) )
      52             :     {
      53      871676 :         SWITCH( bwidth )
      54             :         {
      55         372 :             case IGF_MODE_WB:
      56         372 :                 test();
      57         372 :                 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         372 :                 ELSE IF( LE_32( brate, ACELP_9k60 ) )
      63             :                 {
      64         222 :                     bitRateIndex = IGF_BITRATE_WB_13200_CPE;
      65         222 :                     move16();
      66             :                 }
      67         150 :                 ELSE IF( LE_32( brate, IVAS_13k2 ) )
      68             :                 {
      69         150 :                     bitRateIndex = IGF_BITRATE_WB_16400_CPE;
      70         150 :                     move16();
      71             :                 }
      72         372 :                 BREAK;
      73      265106 :             case IGF_MODE_SWB:
      74             :                 /* DFT and TD Stereo bitrates */
      75      265106 :                 IF( LE_32( brate, ACELP_9k60 ) )
      76             :                 {
      77         666 :                     bitRateIndex = IGF_BITRATE_SWB_13200_CPE;
      78         666 :                     move16();
      79             :                 }
      80      264440 :                 ELSE IF( LE_32( brate, IVAS_13k2 ) )
      81             :                 {
      82         664 :                     IF( EQ_16( rf_mode, 1 ) )
      83             :                     {
      84           0 :                         bitRateIndex = IGF_BITRATE_RF_SWB_13200;
      85           0 :                         move16();
      86             :                     }
      87             :                     ELSE
      88             :                     {
      89         664 :                         bitRateIndex = IGF_BITRATE_SWB_16400_CPE;
      90         664 :                         move16();
      91             :                     }
      92             :                 }
      93      263776 :                 ELSE IF( LE_32( brate, IVAS_16k4 ) )
      94             :                 {
      95        1592 :                     bitRateIndex = IGF_BITRATE_SWB_24400_CPE;
      96        1592 :                     move16();
      97             :                 }
      98      262184 :                 ELSE IF( LE_32( brate, IVAS_24k4 ) )
      99             :                 {
     100        1488 :                     bitRateIndex = IGF_BITRATE_SWB_32000_CPE;
     101        1488 :                     move16();
     102             :                 }
     103      260696 :                 ELSE IF( LE_32( brate, IVAS_32k ) )
     104             :                 {
     105           0 :                     bitRateIndex = IGF_BITRATE_SWB_32000;
     106           0 :                     move16();
     107             :                 }
     108             :                 /* MDCT Stereo bitrates */
     109      260696 :                 ELSE IF( LE_32( brate, IVAS_48k ) )
     110             :                 {
     111      134587 :                     bitRateIndex = IGF_BITRATE_SWB_48000_CPE;
     112      134587 :                     move16();
     113             :                 }
     114      126109 :                 ELSE IF( LE_32( brate, IVAS_64k ) )
     115             :                 {
     116       43039 :                     bitRateIndex = IGF_BITRATE_SWB_64000_CPE;
     117       43039 :                     move16();
     118             :                 }
     119       83070 :                 ELSE IF( LE_32( brate, IVAS_80k ) )
     120             :                 {
     121       37514 :                     bitRateIndex = IGF_BITRATE_SWB_80000_CPE;
     122       37514 :                     move16();
     123             :                 }
     124       45556 :                 ELSE IF( LE_32( brate, IVAS_96k ) )
     125             :                 {
     126       45556 :                     bitRateIndex = IGF_BITRATE_SWB_96000_CPE;
     127       45556 :                     move16();
     128             :                 }
     129      265106 :                 BREAK;
     130      606198 :             case IGF_MODE_FB:
     131             :                 /* DFT and TD Stereo bitrates */
     132      606198 :                 IF( LE_32( brate, IVAS_16k4 ) )
     133             :                 {
     134         736 :                     bitRateIndex = IGF_BITRATE_FB_24400_CPE;
     135         736 :                     move16();
     136             :                 }
     137      605462 :                 ELSE IF( LE_32( brate, IVAS_24k4 ) )
     138             :                 {
     139        1180 :                     bitRateIndex = IGF_BITRATE_FB_32000_CPE;
     140        1180 :                     move16();
     141             :                 }
     142      604282 :                 ELSE IF( LE_32( brate, IVAS_32k ) )
     143             :                 {
     144           0 :                     bitRateIndex = IGF_BITRATE_FB_32000;
     145           0 :                     move16();
     146             :                 }
     147             :                 /* MDCT Stereo bitrates */
     148      604282 :                 ELSE IF( LE_32( brate, IVAS_48k ) )
     149             :                 {
     150       84876 :                     bitRateIndex = IGF_BITRATE_FB_48000_CPE;
     151       84876 :                     move16();
     152             :                 }
     153      519406 :                 ELSE IF( LE_32( brate, IVAS_64k ) )
     154             :                 {
     155      155886 :                     bitRateIndex = IGF_BITRATE_FB_64000_CPE;
     156      155886 :                     move16();
     157             :                 }
     158      363520 :                 ELSE IF( LE_32( brate, IVAS_80k ) )
     159             :                 {
     160       48740 :                     bitRateIndex = IGF_BITRATE_FB_80000_CPE;
     161       48740 :                     move16();
     162             :                 }
     163      314780 :                 ELSE IF( LE_32( brate, IVAS_96k ) )
     164             :                 {
     165       66238 :                     bitRateIndex = IGF_BITRATE_FB_96000_CPE;
     166       66238 :                     move16();
     167             :                 }
     168      248542 :                 ELSE IF( LE_32( brate, IVAS_128k ) )
     169             :                 {
     170      248542 :                     bitRateIndex = IGF_BITRATE_FB_128000_CPE;
     171      248542 :                     move16();
     172             :                 }
     173      606198 :                 BREAK;
     174             :         }
     175      871676 :     }
     176             :     /* SCE modes: use tunings done for DFT stereo bitrates also for according SCE bitrates, otherwise same config as mono modes */
     177       54710 :     ELSE IF( EQ_16( element_mode, IVAS_SCE ) )
     178             :     {
     179       54518 :         SWITCH( bwidth )
     180             :         {
     181          40 :             case IGF_MODE_WB:
     182          40 :                 test();
     183          40 :                 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          40 :                 ELSE IF( LE_32( brate, ACELP_9k60 ) ) /* bitrates 8000 and 9600 */
     189             :                 {
     190          40 :                     bitRateIndex = IGF_BITRATE_WB_9600;
     191          40 :                     move16();
     192             :                 }
     193          40 :                 BREAK;
     194       21254 :             case IGF_MODE_SWB:
     195       21254 :                 IF( LE_32( brate, ACELP_9k60 ) )
     196             :                 {
     197        6616 :                     bitRateIndex = IGF_BITRATE_SWB_13200_CPE;
     198        6616 :                     move16();
     199             :                 }
     200       14638 :                 ELSE IF( LE_32( brate, IVAS_13k2 ) )
     201             :                 {
     202        6982 :                     IF( EQ_16( rf_mode, 1 ) )
     203             :                     {
     204           0 :                         bitRateIndex = IGF_BITRATE_RF_SWB_13200;
     205           0 :                         move16();
     206             :                     }
     207             :                     ELSE
     208             :                     {
     209        6982 :                         bitRateIndex = IGF_BITRATE_SWB_16400_CPE;
     210        6982 :                         move16();
     211             :                     }
     212             :                 }
     213        7656 :                 ELSE IF( LE_32( brate, IVAS_16k4 ) )
     214             :                 {
     215        3772 :                     bitRateIndex = IGF_BITRATE_SWB_24400_CPE;
     216        3772 :                     move16();
     217             :                 }
     218        3884 :                 ELSE IF( LE_32( brate, IVAS_24k4 ) )
     219             :                 {
     220        1620 :                     move16();
     221        1620 :                     bitRateIndex = IGF_BITRATE_SWB_32000_CPE;
     222             :                 }
     223        2264 :                 ELSE IF( LE_32( brate, IVAS_32k ) )
     224             :                 {
     225        1538 :                     bitRateIndex = IGF_BITRATE_SWB_32000;
     226        1538 :                     move16();
     227             :                 }
     228         726 :                 ELSE IF( LE_32( brate, IVAS_48k ) )
     229             :                 {
     230         298 :                     bitRateIndex = IGF_BITRATE_SWB_48000;
     231         298 :                     move16();
     232             :                 }
     233         428 :                 ELSE IF( LE_32( brate, IVAS_64k ) )
     234             :                 {
     235         428 :                     bitRateIndex = IGF_BITRATE_SWB_64000;
     236         428 :                     move16();
     237             :                 }
     238       21254 :                 BREAK;
     239       33224 :             case IGF_MODE_FB:
     240       33224 :                 IF( LE_32( brate, IVAS_16k4 ) )
     241             :                 {
     242        5524 :                     bitRateIndex = IGF_BITRATE_FB_24400_CPE;
     243        5524 :                     move16();
     244             :                 }
     245       27700 :                 ELSE IF( LE_32( brate, IVAS_24k4 ) )
     246             :                 {
     247        9172 :                     bitRateIndex = IGF_BITRATE_FB_32000_CPE;
     248        9172 :                     move16();
     249             :                 }
     250       18528 :                 ELSE IF( LE_32( brate, IVAS_32k ) )
     251             :                 {
     252        7846 :                     bitRateIndex = IGF_BITRATE_FB_32000;
     253        7846 :                     move16();
     254             :                 }
     255       10682 :                 ELSE IF( LE_32( brate, IVAS_48k ) )
     256             :                 {
     257        7042 :                     bitRateIndex = IGF_BITRATE_FB_48000;
     258        7042 :                     move16();
     259             :                 }
     260        3640 :                 ELSE IF( LE_32( brate, IVAS_64k ) )
     261             :                 {
     262        2132 :                     bitRateIndex = IGF_BITRATE_FB_64000;
     263        2132 :                     move16();
     264             :                 }
     265        1508 :                 ELSE IF( LE_32( brate, IVAS_96k ) )
     266             :                 {
     267        1086 :                     bitRateIndex = IGF_BITRATE_FB_96000;
     268        1086 :                     move16();
     269             :                 }
     270         422 :                 ELSE IF( LE_32( brate, IVAS_128k ) )
     271             :                 {
     272         422 :                     bitRateIndex = IGF_BITRATE_FB_128000;
     273         422 :                     move16();
     274             :                 }
     275       33224 :                 BREAK;
     276             :         }
     277       54518 :     }
     278             :     /* EVS mono */
     279             :     ELSE
     280             :     {
     281         192 :         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         192 :             case IGF_MODE_SWB:
     297         192 :                 IF( LE_32( brate, ACELP_9k60 ) )
     298             :                 {
     299           0 :                     move16();
     300           0 :                     bitRateIndex = IGF_BITRATE_SWB_9600;
     301             :                 }
     302         192 :                 ELSE IF( LE_32( brate, ACELP_13k20 ) )
     303             :                 {
     304          80 :                     IF( EQ_16( rf_mode, 1 ) )
     305             :                     {
     306           0 :                         bitRateIndex = IGF_BITRATE_RF_SWB_13200;
     307           0 :                         move16();
     308             :                     }
     309             :                     ELSE
     310             :                     {
     311          80 :                         bitRateIndex = IGF_BITRATE_SWB_13200;
     312          80 :                         move16();
     313             :                     }
     314             :                 }
     315         112 :                 ELSE IF( LE_32( brate, ACELP_16k40 ) )
     316             :                 {
     317           0 :                     bitRateIndex = IGF_BITRATE_SWB_16400;
     318           0 :                     move16();
     319             :                 }
     320         112 :                 ELSE IF( LE_32( brate, ACELP_24k40 ) )
     321             :                 {
     322         112 :                     bitRateIndex = IGF_BITRATE_SWB_24400;
     323         112 :                     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         192 :                 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      926386 :     }
     380             : 
     381      926386 :     return bitRateIndex; /*Q0*/
     382             : }
     383             : 
     384             : /**********************************************************************/ /*
     385             : IGF grid setup
     386             : **************************************************************************/
     387         288 : 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         288 :     swb_offset = NULL;
     407         288 :     swb_offset_len = 0;
     408         288 :     move16();
     409             : 
     410         288 :     SWITCH( bitRateIndex )
     411             :     {
     412         288 :         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         288 :             swb_offset = &swb_offset_LB_new[bitRateIndex][1];
     422         288 :             swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; /*Q0*/
     423         288 :             move16();
     424         288 :             Copy( &igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2 );
     425         288 :             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        2640 :     FOR( sfb = 0; sfb < swb_offset_len; sfb++ )
     448             :     {
     449        2352 :         hGrid->swb_offset[sfb] = IGF_ApplyTransFac( swb_offset[sfb], transFac ); /*Q0*/
     450        2352 :         move16();
     451             :     }
     452             : 
     453         288 :     hGrid->infoIsRefined = 0;
     454         288 :     move16();
     455         288 :     frameLength = IGF_ApplyTransFac( frameLength, transFac ); /*Q0*/
     456         288 :     tmp2 = norm_s( frameLength );
     457         288 :     bandwidth = shl( frameLength, tmp2 );                        /*tmp2*/
     458         288 :     hGrid->swb_offset_len = extract_l( L_shr( sampleRate, 2 ) ); /*-1*/
     459         288 :     move16();
     460         288 :     tmp1 = sub( norm_s( hGrid->swb_offset_len ), 1 );
     461         288 :     hGrid->swb_offset_len = shl( hGrid->swb_offset_len, tmp1 ); /*tmp1-1*/
     462         288 :     move16();
     463         288 :     bandwidth = div_s( hGrid->swb_offset_len, bandwidth ); /*15 + tmp1-1-tmp2*/
     464         288 :     tmp2 = sub( add( tmp2, 1 ), tmp1 );
     465         288 :     bandwidth = shr( bandwidth, sub( 15, tmp2 ) ); /*Q0*/
     466             : 
     467             : 
     468         288 :     hGrid->swb_offset_len = swb_offset_len; /*Q0*/
     469         288 :     move16();
     470         288 :     hGrid->startSfb = 0;
     471         288 :     move16();
     472         288 :     hGrid->stopSfb = sub( hGrid->swb_offset_len, 1 ); /*Q0*/
     473         288 :     move16();
     474         288 :     hGrid->startLine = hGrid->swb_offset[hGrid->startSfb]; /*Q0*/
     475         288 :     move16();
     476         288 :     hGrid->stopLine = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/
     477         288 :     move16();
     478         288 :     hGrid->startFrequency = imult1616( bandwidth, hGrid->startLine ); /*Q0*/
     479         288 :     move16();
     480         288 :     hGrid->stopFrequency = imult1616( bandwidth, hGrid->stopLine ); /*Q0*/
     481         288 :     move16();
     482             : 
     483         288 :     L_tmp1 = L_mult0( igfMinFq, frameLength ); /*Q0*/
     484         288 :     tmp1 = sub( norm_l( L_tmp1 ), 1 );
     485         288 :     L_tmp1 = L_shl( L_tmp1, tmp1 ); /*tmp1*/
     486             : 
     487         288 :     tmp2 = norm_l( sampleRate );
     488         288 :     L_tmp2 = L_shl( sampleRate, tmp2 );                         /*tmp2*/
     489         288 :     tmp1 = add( WORD16_BITS - 1, sub( tmp1, add( tmp2, 1 ) ) ); /* takes into account sampleRate >> 1 */
     490             : 
     491         288 :     hGrid->minSrcSubband = div_s( extract_h( L_tmp1 ), extract_h( L_tmp2 ) ); /*tmp1*/
     492         288 :     hGrid->minSrcSubband = shr( hGrid->minSrcSubband, tmp1 );                 /*Q0*/
     493         288 :     move16();
     494         288 :     move16();
     495             : 
     496             : 
     497         288 :     hGrid->minSrcSubband = add( hGrid->minSrcSubband, s_and( hGrid->minSrcSubband, 1 ) );
     498         288 :     move16();
     499         288 :     hGrid->minSrcFrequency = imult1616( bandwidth, hGrid->minSrcSubband );
     500         288 :     move16();
     501         288 :     hGrid->infoGranuleLen = frameLength; /*Q0*/
     502         288 :     move16();
     503         288 :     hGrid->infoTransFac = transFac; /*Q14*/
     504         288 :     move16();
     505             : 
     506         288 :     hGrid->sfbWrap[0] = 0;
     507         288 :     move16();
     508         288 :     hGrid->tile[0] = hGrid->startLine; /*Q0*/
     509         288 :     move16();
     510             : 
     511             : 
     512             :     /*************************************************************************/
     513         288 :     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         120 :         case IGF_BITRATE_SWB_13200:
     630         120 :             hGrid->nTiles = 2;
     631         120 :             move16();
     632         120 :             wrp_sfb = 4;
     633         120 :             move16();
     634             : 
     635             :             /*1st*/
     636         120 :             hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/
     637         120 :             move16();
     638         120 :             hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/
     639         120 :             move16();
     640         120 :             hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/
     641         120 :             move16();
     642             : 
     643             :             /*2nd*/
     644         120 :             hGrid->sfbWrap[1 + 1] = hGrid->stopSfb; /*Q0*/
     645         120 :             move16();
     646         120 :             hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 32, transFac ) ); /*Q0*/
     647         120 :             move16();
     648         120 :             hGrid->tile[1 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/
     649         120 :             move16();
     650         120 :             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         168 :         case IGF_BITRATE_SWB_24400:
     684             :         case IGF_BITRATE_SWB_32000:
     685         168 :             hGrid->nTiles = 3;
     686         168 :             move16();
     687         168 :             wrp_sfb = 4;
     688         168 :             move16();
     689             : 
     690             :             /*1st*/
     691         168 :             hGrid->sfbWrap[0 + 1] = wrp_sfb; /*Q0*/
     692         168 :             move16();
     693         168 :             hGrid->sbWrap[0] = hGrid->minSrcSubband; /*Q0*/
     694         168 :             move16();
     695         168 :             hGrid->tile[0 + 1] = hGrid->swb_offset[wrp_sfb]; /*Q0*/
     696         168 :             move16();
     697             : 
     698             :             /*2nd*/
     699         168 :             hGrid->sfbWrap[1 + 1] = 7;
     700         168 :             move16();
     701         168 :             hGrid->sbWrap[1] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 32, transFac ) ); /*Q0*/
     702         168 :             move16();
     703         168 :             hGrid->tile[1 + 1] = hGrid->swb_offset[7]; /*Q0*/
     704         168 :             move16();
     705             : 
     706             :             /*3nd*/
     707         168 :             hGrid->sfbWrap[2 + 1] = hGrid->stopSfb; /*Q0*/
     708         168 :             move16();
     709         168 :             hGrid->sbWrap[2] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( 64, transFac ) ); /*Q0*/
     710         168 :             move16();
     711         168 :             hGrid->tile[2 + 1] = hGrid->swb_offset[hGrid->stopSfb]; /*Q0*/
     712         168 :             move16();
     713         168 :             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         288 :     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         120 :         case IGF_BITRATE_SWB_13200:
     842             :         case IGF_BITRATE_FB_16400:
     843             :         case IGF_BITRATE_SWB_16400:
     844         120 :             hGrid->gFactor = 15237 /*0.93f Q14*/;
     845         120 :             move16();
     846         120 :             hGrid->fFactor = 3277 /*0.20f Q14*/;
     847         120 :             move16();
     848         120 :             hGrid->lFactor = 13926 /*0.85f Q14*/;
     849         120 :             move16();
     850         120 :             BREAK;
     851         168 :         case IGF_BITRATE_FB_24400:
     852             :         case IGF_BITRATE_SWB_24400:
     853             :         case IGF_BITRATE_FB_32000:
     854             :         case IGF_BITRATE_SWB_32000:
     855         168 :             hGrid->gFactor = 15811 /*0.965f Q14*/;
     856         168 :             move16();
     857         168 :             hGrid->fFactor = 3277 /*0.20f Q14*/;
     858         168 :             move16();
     859         168 :             hGrid->lFactor = 13926 /*0.85f Q14*/;
     860         168 :             move16();
     861         168 :             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        2136 :     FOR( t = add( hGrid->nTiles, 1 ); t < IGF_MAX_TILES; t++ )
     883             :     {
     884        1848 :         hGrid->tile[t] = 0;
     885        1848 :         move16();
     886        1848 :         hGrid->sbWrap[t - 1] = 0;
     887        1848 :         move16();
     888        1848 :         hGrid->sfbWrap[t] = 0;
     889        1848 :         move16();
     890             :     }
     891         288 : }
     892      161595 : 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      161595 :     swb_offset = NULL;
     912      161595 :     swb_offset_len = 0;
     913      161595 :     move16();
     914             : 
     915      161595 :     test();
     916      161595 :     test();
     917      161595 :     IF( EQ_16( transFac, 8192 /*0.5 in Q14*/ ) && EQ_16( bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) )
     918             :     {
     919        1468 :         bitRateIndex = IGF_BITRATE_SWB_48000_CPE_TCX10;
     920        1468 :         move16();
     921             :     }
     922      160127 :     ELSE IF( EQ_16( transFac, 8192 /*0.5 in Q14*/ ) && EQ_16( bitRateIndex, IGF_BITRATE_FB_48000_CPE ) )
     923             :     {
     924        4294 :         bitRateIndex = IGF_BITRATE_FB_48000_CPE_TCX10;
     925        4294 :         move16();
     926             :     }
     927             : 
     928      161595 :     IF( NE_16( bitRateIndex, IGF_BITRATE_UNKNOWN ) )
     929             :     {
     930      161595 :         swb_offset = &swb_offset_LB_new[bitRateIndex][1];
     931      161595 :         swb_offset_len = swb_offset_LB_new[bitRateIndex][0];
     932      161595 :         move16();
     933      161595 :         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     1375670 :     FOR( sfb = 0; sfb < swb_offset_len; sfb++ )
     941             :     {
     942     1214075 :         hGrid->swb_offset[sfb] = IGF_ApplyTransFac( swb_offset[sfb], transFac );
     943     1214075 :         move16();
     944             :     }
     945     2664205 :     FOR( sfb = swb_offset_len; sfb < IGF_MAX_SFB; sfb++ )
     946             :     {
     947     2502610 :         hGrid->swb_offset[sfb] = 0;
     948     2502610 :         move16();
     949             :     }
     950             : 
     951      161595 :     hGrid->infoIsRefined = 0;
     952      161595 :     move16();
     953      161595 :     frameLength = IGF_ApplyTransFac( frameLength, transFac ); /*Q0*/
     954      161595 :     tmp2 = norm_s( frameLength );
     955      161595 :     bandwidth_fx = shl( frameLength, tmp2 );                     /*tmp2*/
     956      161595 :     hGrid->swb_offset_len = extract_l( L_shr( sampleRate, 2 ) ); /*-1*/
     957      161595 :     move16();
     958      161595 :     tmp1 = sub( norm_s( hGrid->swb_offset_len ), 1 );
     959      161595 :     hGrid->swb_offset_len = shl( hGrid->swb_offset_len, tmp1 ); /*tmp1-1*/
     960      161595 :     move16();
     961      161595 :     bandwidth_fx = div_s( hGrid->swb_offset_len, bandwidth_fx ); /*15 + tmp1-1-tmp2*/
     962      161595 :     tmp2 = sub( add( tmp2, 1 ), tmp1 );
     963      161595 :     bandwidth_fx = shr( bandwidth_fx, sub( 15, tmp2 ) );
     964      161595 :     hGrid->swb_offset_len = swb_offset_len; /*Q0*/
     965      161595 :     move16();
     966      161595 :     hGrid->startSfb = 0;
     967      161595 :     move16();
     968      161595 :     hGrid->stopSfb = sub( hGrid->swb_offset_len, 1 );
     969      161595 :     move16();
     970      161595 :     hGrid->startLine = hGrid->swb_offset[hGrid->startSfb];
     971      161595 :     move16();
     972      161595 :     hGrid->stopLine = hGrid->swb_offset[hGrid->stopSfb];
     973      161595 :     move16();
     974      161595 :     hGrid->startFrequency = imult1616( bandwidth_fx, hGrid->startLine );
     975      161595 :     move16();
     976      161595 :     hGrid->stopFrequency = imult1616( bandwidth_fx, hGrid->stopLine );
     977      161595 :     move16();
     978      161595 :     L_tmp1 = L_mult0( igfMinFq, frameLength );
     979      161595 :     tmp1 = sub( norm_l( L_tmp1 ), 1 );
     980      161595 :     L_tmp1 = L_shl( L_tmp1, tmp1 );
     981      161595 :     tmp2 = norm_l( sampleRate );
     982      161595 :     L_tmp2 = L_shl( sampleRate, tmp2 );
     983      161595 :     tmp1 = add( WORD16_BITS - 1, sub( tmp1, add( tmp2, 1 ) ) ); /* takes into account sampleRate >> 1 */
     984      161595 :     hGrid->minSrcSubband = div_s( extract_h( L_tmp1 ), extract_h( L_tmp2 ) );
     985      161595 :     move16();
     986      161595 :     hGrid->minSrcSubband = shr( hGrid->minSrcSubband, tmp1 ); /*Q0*/
     987      161595 :     move16();
     988      161595 :     hGrid->minSrcSubband = add( hGrid->minSrcSubband, s_and( hGrid->minSrcSubband, 1 ) );
     989      161595 :     move16();
     990      161595 :     hGrid->minSrcFrequency = imult1616( bandwidth_fx, hGrid->minSrcSubband ); /*Q0*/
     991      161595 :     move16();
     992      161595 :     hGrid->infoGranuleLen = frameLength; /*Q0*/
     993      161595 :     move16();
     994      161595 :     hGrid->sfbWrap[0] = 0;
     995      161595 :     move16();
     996      161595 :     hGrid->tile[0] = hGrid->startLine; /*Q0*/
     997      161595 :     move16();
     998             : 
     999      161595 :     igf_tile_offset = &igf_tile_offset_table[bitRateIndex][1];
    1000      161595 :     hGrid->nTiles = igf_tile_offset_table[bitRateIndex][0];
    1001      161595 :     move16();
    1002      161595 :     hGrid->tile[0] = hGrid->startLine;
    1003      161595 :     move16();
    1004      161595 :     hGrid->sfbWrap[0] = 0;
    1005      161595 :     move16();
    1006      935781 :     FOR( k = 0; k < hGrid->nTiles; k++ )
    1007             :     {
    1008      774186 :         hGrid->sfbWrap[k + 1] = igf_tile_offset[2 * k];
    1009      774186 :         move16();
    1010      774186 :         hGrid->sbWrap[k] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( igf_tile_offset[2 * k + 1], transFac ) );
    1011      774186 :         move16();
    1012      774186 :         hGrid->tile[k + 1] = hGrid->swb_offset[igf_tile_offset[2 * k]]; /*Q0*/
    1013      774186 :         move16();
    1014             :     }
    1015      857292 :     FOR( t = hGrid->nTiles + 1; t < IGF_MAX_TILES; t++ )
    1016             :     {
    1017      695697 :         hGrid->tile[t] = 0;
    1018      695697 :         move16();
    1019      695697 :         hGrid->sbWrap[t - 1] = 0;
    1020      695697 :         move16();
    1021      695697 :         hGrid->sfbWrap[t] = 0;
    1022      695697 :         move16();
    1023             :     }
    1024             : 
    1025             :     /* adapt level envelope: */
    1026      161595 :     SWITCH( bitRateIndex )
    1027             :     {
    1028         618 :         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         618 :             hGrid->gFactor = 13107 /*0.80f Q14*/;
    1033         618 :             move16();
    1034         618 :             hGrid->fFactor = 11469 /*0.70f Q14*/;
    1035         618 :             move16();
    1036         618 :             hGrid->lFactor = 9830 /*0.60f Q14*/;
    1037         618 :             move16();
    1038         618 :             BREAK;
    1039       28905 :         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       28905 :             hGrid->gFactor = 15237 /*0.93f Q14*/;
    1046       28905 :             move16();
    1047       28905 :             hGrid->fFactor = 3277 /*0.20f Q14*/;
    1048       28905 :             move16();
    1049       28905 :             hGrid->lFactor = 13926 /*0.85f Q14*/;
    1050       28905 :             move16();
    1051       28905 :             BREAK;
    1052       43337 :         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       43337 :             hGrid->gFactor = 15811 /*0.965f Q14*/;
    1061       43337 :             move16();
    1062       43337 :             hGrid->fFactor = 3277 /*0.20f Q14*/;
    1063       43337 :             move16();
    1064       43337 :             hGrid->lFactor = 13926 /*0.85f Q14*/;
    1065       43337 :             move16();
    1066       43337 :             BREAK;
    1067       18591 :         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       18591 :             hGrid->gFactor = 16384 /*1.00f Q14*/;
    1074       18591 :             move16();
    1075       18591 :             hGrid->fFactor = 3277 /*0.20f Q14*/;
    1076       18591 :             move16();
    1077       18591 :             hGrid->lFactor = 16384 /*1.00f Q14*/;
    1078       18591 :             move16();
    1079       18591 :             BREAK;
    1080       70144 :         case IGF_BITRATE_SWB_9600:
    1081             :         case IGF_BITRATE_SWB_13200_CPE:
    1082             :         case IGF_BITRATE_RF_SWB_13200:
    1083             :         default:
    1084       70144 :             hGrid->gFactor = 16384 /*1.00f Q14*/;
    1085       70144 :             move16();
    1086       70144 :             hGrid->fFactor = 0; /*0.00f Q30*/
    1087       70144 :             move16();
    1088       70144 :             hGrid->lFactor = 16384 /*1.00f Q14*/;
    1089       70144 :             move16();
    1090             :     }
    1091             : 
    1092      857292 :     FOR( t = add( hGrid->nTiles, 1 ); t < IGF_MAX_TILES; t++ )
    1093             :     {
    1094      695697 :         hGrid->tile[t] = 0;
    1095      695697 :         move16();
    1096      695697 :         hGrid->sbWrap[t - 1] = 0;
    1097      695697 :         move16();
    1098      695697 :         hGrid->sfbWrap[t] = 0;
    1099      695697 :         move16();
    1100             :     }
    1101      161595 :     return;
    1102             : }
    1103             : 
    1104             : 
    1105             : /**********************************************************************/ /*
    1106             : calculates energy per sfb via power spectrum
    1107             : **************************************************************************/
    1108     2379441 : 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     2379441 :     Flag Overflow = 0;
    1123     2379441 :     Flag Carry = 0;
    1124     2379441 :     move16();
    1125     2379441 :     move16();
    1126             : #endif
    1127             : 
    1128    12909817 :     FOR( sfb = startSfb; sfb < stopSfb; sfb++ )
    1129             :     {
    1130    10530376 :         sfbEnergy[sfb] = L_deposit_l( 0 );
    1131    10530376 :         move32();
    1132             :     }
    1133     2379441 :     IF( NULL == pPowerSpectrum )
    1134             :     {
    1135           0 :         return;
    1136             :     }
    1137             : 
    1138    12909817 :     FOR( sfb = startSfb; sfb < stopSfb; sfb++ )
    1139             :     {
    1140    10530376 :         L_c = L_deposit_l( 0 );
    1141   323952118 :         FOR( line = swb_offset[sfb]; line < swb_offset[sfb + 1]; line++ )
    1142             :         {
    1143   313421742 :             Carry = 0;
    1144   313421742 :             move16();
    1145   313421742 :             sfbEnergy[sfb] = L_add_co( sfbEnergy[sfb], pPowerSpectrum[line], &Carry, &Overflow );
    1146   313421742 :             move32();
    1147   313421742 :             Overflow = 0;
    1148   313421742 :             move16();
    1149   313421742 :             L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow );
    1150             :         }
    1151    10530376 :         sfbEnergy[sfb] = norm_llQ31( L_c, sfbEnergy[sfb], &( sfbEnergy_exp[sfb] ) );
    1152    10530376 :         move32();
    1153    10530376 :         sfbEnergy_exp[sfb] = add( sfbEnergy_exp[sfb], *pPowerSpectrum_exp );
    1154    10530376 :         move16();
    1155             :     }
    1156             : }
    1157             : 
    1158             : /**********************************************************************/ /*
    1159             : calculate the MDCT square spectrum in the IGF range
    1160             : **************************************************************************/
    1161        3588 : 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        3588 :     s1 = getScaleFactor32( mdctSpec + sqrtBgn, sub( sqrtEnd, sqrtBgn ) );
    1178             : 
    1179             :     /* set new exponent */
    1180        3588 :     *mdctSquareSpec_e = add( shl( sub( mdctSpec_e, s1 ), 1 ), 1 );
    1181        3588 :     move16();
    1182             : 
    1183             :     /* MDCT square spectrum: MDCT^2 */
    1184        3588 :     j = add( sqrtBgn, indexOffset ); /* handle indexOffset with care, otherwise memory overruns may occur! */
    1185             : 
    1186             : 
    1187      714734 :     FOR( i = sqrtBgn; i < sqrtEnd; i++ )
    1188             :     {
    1189      711146 :         tmp = round_fx_sat( L_shl_sat( mdctSpec[i], s1 ) ); /*(15 - mdctSpec_e)+ S1*/
    1190      711146 :         mdctSquareSpec[j++] = L_mult0( tmp, tmp );          /*31 - mdctSquareSpec_e*/
    1191      711146 :         move32();
    1192             :     }
    1193        3588 : }
    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        7466 : 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        7466 :     IF( hBstr )
    1244             :     {
    1245        3733 :         push_next_indice( hBstr, bit, 1 );
    1246             :     }
    1247        7466 :     *pBitOffset = add( *pBitOffset, 1 );
    1248        7466 :     move16();
    1249             : 
    1250        7466 :     return;
    1251             : }
    1252             : 
    1253             : /**********************************************************************/ /*
    1254             : changes the IGF configuration
    1255             : **************************************************************************/
    1256          96 : 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          96 :     retValue = 0; /* bitrate index is unknown -> error! */
    1272          96 :     move16();
    1273             : 
    1274             :     /* interface call for reading in settings */
    1275          96 :     hIGFInfo->bitRateIndex = IGF_MapBitRateToIndex( total_brate, bwidth, element_mode, rf_mode ); /*Q0*/
    1276          96 :     move16();
    1277             : 
    1278          96 :     IF( NE_16( hIGFInfo->bitRateIndex, IGF_BITRATE_UNKNOWN ) )
    1279             :     {
    1280          96 :         retValue = 1; /* no error */
    1281          96 :         move16();
    1282             : 
    1283             :         /* mapping to local values */
    1284          96 :         sampleRate = igfMode[hIGFInfo->bitRateIndex].sampleRate; /*Q0*/
    1285          96 :         move32();
    1286          96 :         frameLength = igfMode[hIGFInfo->bitRateIndex].frameLength; /*Q0*/
    1287          96 :         move16();
    1288          96 :         igfMinFq = igfMode[hIGFInfo->bitRateIndex].igfMinFq; /*Q0*/
    1289          96 :         move16();
    1290          96 :         maxHopsize = igfMode[hIGFInfo->bitRateIndex].maxHopsize; /*Q0*/
    1291          96 :         move16();
    1292             : 
    1293             :         /* basic information */
    1294          96 :         hIGFInfo->sampleRate = sampleRate; /*Q0*/
    1295          96 :         move32();
    1296          96 :         hIGFInfo->frameLength = frameLength; /*Q0*/
    1297          96 :         move16();
    1298          96 :         hIGFInfo->maxHopsize = maxHopsize; /*Q0*/
    1299          96 :         move16();
    1300             : 
    1301          96 :         hIGFInfo->nfSeedBuf[0] = 0;
    1302          96 :         move16();
    1303          96 :         hIGFInfo->nfSeedBuf[1] = 0;
    1304          96 :         move16();
    1305          96 :         hIGFInfo->nfSeed = &hIGFInfo->nfSeedBuf[0];
    1306          96 :         move16();
    1307             : 
    1308             :         /* set up regular IGF grid for TCX 20  (transfac = 1.f) */
    1309          96 :         hGrid = &hIGFInfo->grid[IGF_GRID_LB_NORM];
    1310          96 :         IGF_gridSetUp( hGrid,
    1311          96 :                        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          96 :         hGrid = &hIGFInfo->grid[IGF_GRID_LB_TRAN];
    1319          96 :         IGF_gridSetUp( hGrid,
    1320          96 :                        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          96 :         hGrid = &hIGFInfo->grid[IGF_GRID_LB_SHORT];
    1327          96 :         IGF_gridSetUp( hGrid,
    1328          96 :                        hIGFInfo->bitRateIndex,
    1329             :                        sampleRate,
    1330             :                        frameLength,
    1331             :                        8192 /*0.50f Q14*/,
    1332             :                        igfMinFq );
    1333             :     }
    1334             : 
    1335          96 :     return retValue;
    1336             : }
    1337       53865 : 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       53865 :     retValue = 0; /* bitrate index is unknown -> error! */
    1353       53865 :     move16();
    1354             : 
    1355             :     /* interface call for reading in settings */
    1356       53865 :     hIGFInfo->bitRateIndex = IGF_MapBitRateToIndex( total_brate, bwidth, element_mode, rf_mode ); /*Q0*/
    1357             : 
    1358       53865 :     IF( NE_16( hIGFInfo->bitRateIndex, IGF_BITRATE_UNKNOWN ) )
    1359             :     {
    1360       53865 :         retValue = 1; /* no error */
    1361       53865 :         move16();
    1362             : 
    1363             :         /* mapping to local values */
    1364       53865 :         sampleRate = igfMode[hIGFInfo->bitRateIndex].sampleRate; /*Q0*/
    1365       53865 :         move32();
    1366       53865 :         frameLength = igfMode[hIGFInfo->bitRateIndex].frameLength; /*Q0*/
    1367       53865 :         move16();
    1368       53865 :         igfMinFq = igfMode[hIGFInfo->bitRateIndex].igfMinFq; /*Q0*/
    1369       53865 :         move16();
    1370       53865 :         maxHopsize = igfMode[hIGFInfo->bitRateIndex].maxHopsize; /*Q0*/
    1371       53865 :         move16();
    1372             : 
    1373             :         /* basic information */
    1374       53865 :         hIGFInfo->sampleRate = sampleRate; /*Q0*/
    1375       53865 :         move32();
    1376       53865 :         hIGFInfo->frameLength = frameLength; /*Q0*/
    1377       53865 :         move16();
    1378       53865 :         hIGFInfo->maxHopsize = maxHopsize; /*Q0*/
    1379       53865 :         move16();
    1380       53865 :         hIGFInfo->nfSeedBuf[0] = 0;
    1381       53865 :         move16();
    1382       53865 :         hIGFInfo->nfSeedBuf[1] = 0;
    1383       53865 :         move16();
    1384       53865 :         hIGFInfo->nfSeed = &hIGFInfo->nfSeedBuf[0];
    1385       53865 :         move16();
    1386             : 
    1387             :         /* set up regular IGF grid for TCX 20  (transfac = 1.f) */
    1388       53865 :         hGrid = &hIGFInfo->grid[IGF_GRID_LB_NORM];
    1389       53865 :         IGF_gridSetUp_ivas_fx( hGrid,
    1390       53865 :                                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       53865 :         hGrid = &hIGFInfo->grid[IGF_GRID_LB_TRAN];
    1397       53865 :         IGF_gridSetUp_ivas_fx( hGrid,
    1398       53865 :                                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       53865 :         hGrid = &hIGFInfo->grid[IGF_GRID_LB_SHORT];
    1405       53865 :         IGF_gridSetUp_ivas_fx( hGrid,
    1406       53865 :                                hIGFInfo->bitRateIndex,
    1407             :                                sampleRate,
    1408             :                                frameLength,
    1409             :                                8192 /*0.50f Q14*/,
    1410             :                                igfMinFq );
    1411             :     }
    1412             : 
    1413       53865 :     return retValue; /*Q0*/
    1414             : }
    1415             : 
    1416             : /**********************************************************************/ /*
    1417             : selects cumulative frequency tables and offsets for the IGF SCF arithmetic coder
    1418             : **************************************************************************/
    1419       53961 : 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       53961 :     retValue = 0; /* bitrate index is unknown -> error! */
    1439       53961 :     move16();
    1440             : 
    1441       53961 :     bitRateIndex = IGF_MapBitRateToIndex( total_brate, bwidth, element_mode, rf_mode );
    1442             : 
    1443       53961 :     IF( NE_32( bitRateIndex, IGF_BITRATE_UNKNOWN ) )
    1444             :     {
    1445       53961 :         retValue = 1; /* no error */
    1446       53961 :         move16();
    1447             : 
    1448       53961 :         SWITCH( bitRateIndex )
    1449             :         {
    1450         111 :             case IGF_BITRATE_WB_13200_CPE:
    1451         111 :                 bitRateIndex = IGF_BITRATE_WB_9600;
    1452         111 :                 move16();
    1453         111 :                 BREAK;
    1454          75 :             case IGF_BITRATE_WB_16400_CPE:
    1455          75 :                 bitRateIndex = IGF_BITRATE_WB_9600;
    1456          75 :                 move16();
    1457          75 :                 BREAK;
    1458        3641 :             case IGF_BITRATE_SWB_13200_CPE:
    1459        3641 :                 bitRateIndex = IGF_BITRATE_SWB_9600;
    1460        3641 :                 move16();
    1461        3641 :                 BREAK;
    1462        3823 :             case IGF_BITRATE_SWB_16400_CPE:
    1463        3823 :                 bitRateIndex = IGF_BITRATE_SWB_13200;
    1464        3823 :                 move16();
    1465        3823 :                 BREAK;
    1466        2682 :             case IGF_BITRATE_SWB_24400_CPE:
    1467        2682 :                 bitRateIndex = IGF_BITRATE_SWB_16400;
    1468        2682 :                 move16();
    1469        2682 :                 BREAK;
    1470        3130 :             case IGF_BITRATE_FB_24400_CPE:
    1471        3130 :                 bitRateIndex = IGF_BITRATE_FB_16400;
    1472        3130 :                 move16();
    1473        3130 :                 BREAK;
    1474        1554 :             case IGF_BITRATE_SWB_32000_CPE:
    1475        1554 :                 bitRateIndex = IGF_BITRATE_SWB_24400;
    1476        1554 :                 move16();
    1477        1554 :                 BREAK;
    1478        5176 :             case IGF_BITRATE_FB_32000_CPE:
    1479        5176 :                 bitRateIndex = IGF_BITRATE_FB_24400;
    1480        5176 :                 move16();
    1481        5176 :                 BREAK;
    1482        9774 :             case IGF_BITRATE_FB_48000_CPE:
    1483             :             case IGF_BITRATE_FB_64000_CPE:
    1484        9774 :                 bitRateIndex = IGF_BITRATE_FB_32000;
    1485        9774 :                 move16();
    1486        9774 :                 BREAK;
    1487             :         }
    1488             : 
    1489       53961 :         switch ( bitRateIndex )
    1490             :         {
    1491       13134 :             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       13134 :                 *cf_se00 = cf_se00_tab;
    1502       13134 :                 *cf_se01 = cf_se01_tab[bitRateIndex];
    1503       13134 :                 *cf_off_se01 = cf_off_se01_tab[bitRateIndex];
    1504       13134 :                 *cf_se02 = &cf_se02_tab[bitRateIndex][0][0];
    1505       13134 :                 *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0];
    1506       13134 :                 *cf_se10 = &cf_se10_tab[0];
    1507       13134 :                 *cf_off_se10 = cf_off_se10_tab;
    1508       13134 :                 *cf_se11 = &cf_se11_tab[0][0][0];
    1509       13134 :                 *cf_off_se11 = &cf_off_se11_tab[0][0];
    1510             : 
    1511       13134 :                 BREAK;
    1512       22003 :             case IGF_BITRATE_FB_16400:
    1513             :             case IGF_BITRATE_FB_24400:
    1514             :             case IGF_BITRATE_FB_32000:
    1515       22003 :                 bitRateIndex = add( sub( bitRateIndex, IGF_BITRATE_FB_16400 ), IGF_BITRATE_SWB_16400 );
    1516       22003 :                 *cf_se00 = cf_se00_tab;
    1517       22003 :                 *cf_se01 = cf_se01_tab[bitRateIndex];
    1518       22003 :                 *cf_off_se01 = cf_off_se01_tab[bitRateIndex];
    1519       22003 :                 *cf_se02 = &cf_se02_tab[bitRateIndex][0][0];
    1520       22003 :                 *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0];
    1521       22003 :                 *cf_se10 = &cf_se10_tab[0];
    1522       22003 :                 *cf_off_se10 = cf_off_se10_tab;
    1523       22003 :                 *cf_se11 = &cf_se11_tab[0][0][0];
    1524       22003 :                 *cf_off_se11 = &cf_off_se11_tab[0][0];
    1525       22003 :                 BREAK;
    1526        4587 :             case IGF_BITRATE_FB_48000:
    1527             :             case IGF_BITRATE_FB_64000:
    1528        4587 :                 bitRateIndex = add( sub( bitRateIndex, IGF_BITRATE_FB_48000 ), IGF_BITRATE_SWB_48000 );
    1529        4587 :                 *cf_se00 = cf_se00_tab;
    1530        4587 :                 *cf_se01 = cf_se01_tab[bitRateIndex];
    1531        4587 :                 *cf_off_se01 = cf_off_se01_tab[bitRateIndex];
    1532        4587 :                 *cf_se02 = &cf_se02_tab[bitRateIndex][0][0];
    1533        4587 :                 *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0];
    1534        4587 :                 *cf_se10 = &cf_se10_tab[0];
    1535        4587 :                 *cf_off_se10 = cf_off_se10_tab;
    1536        4587 :                 *cf_se11 = &cf_se11_tab[0][0][0];
    1537        4587 :                 *cf_off_se11 = &cf_off_se11_tab[0][0];
    1538        4587 :                 BREAK;
    1539        9477 :             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        9477 :                 bitRateIndex = IGF_BITRATE_SWB_48000;
    1545        9477 :                 *cf_se00 = cf_se00_tab;
    1546        9477 :                 *cf_se01 = cf_se01_tab[bitRateIndex];
    1547        9477 :                 *cf_off_se01 = cf_off_se01_tab[bitRateIndex];
    1548        9477 :                 *cf_se02 = &cf_se02_tab[bitRateIndex][0][0];
    1549        9477 :                 *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0];
    1550        9477 :                 *cf_se10 = &cf_se10_tab[0];
    1551        9477 :                 *cf_off_se10 = cf_off_se10_tab;
    1552        9477 :                 *cf_se11 = &cf_se11_tab[0][0][0];
    1553        9477 :                 *cf_off_se11 = &cf_off_se11_tab[0][0];
    1554        9477 :                 BREAK;
    1555        1468 :             case IGF_BITRATE_SWB_48000_CPE:
    1556        1468 :                 bitRateIndex = IGF_BITRATE_SWB_16400;
    1557        1468 :                 *cf_se00 = cf_se00_tab;
    1558        1468 :                 *cf_se01 = cf_se01_tab[bitRateIndex];
    1559        1468 :                 *cf_off_se01 = cf_off_se01_tab[bitRateIndex];
    1560        1468 :                 *cf_se02 = &cf_se02_tab[bitRateIndex][0][0];
    1561        1468 :                 *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0];
    1562        1468 :                 *cf_se10 = &cf_se10_tab[0];
    1563        1468 :                 *cf_off_se10 = cf_off_se10_tab;
    1564        1468 :                 *cf_se11 = &cf_se11_tab[0][0][0];
    1565        1468 :                 *cf_off_se11 = &cf_off_se11_tab[0][0];
    1566        1468 :                 BREAK;
    1567        3292 :             case IGF_BITRATE_SWB_64000_CPE:
    1568             :             case IGF_BITRATE_SWB_80000_CPE:
    1569             :             case IGF_BITRATE_SWB_96000_CPE:
    1570        3292 :                 bitRateIndex = IGF_BITRATE_SWB_48000; /*bitRateIndex-IGF_BITRATE_SWB_56000+IGF_BITRATE_SWB_48000;*/
    1571        3292 :                 *cf_se00 = cf_se00_tab;
    1572        3292 :                 *cf_se01 = cf_se01_tab[bitRateIndex];
    1573        3292 :                 *cf_off_se01 = cf_off_se01_tab[bitRateIndex];
    1574        3292 :                 *cf_se02 = &cf_se02_tab[bitRateIndex][0][0];
    1575        3292 :                 *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0];
    1576        3292 :                 *cf_se10 = &cf_se10_tab[0];
    1577        3292 :                 *cf_off_se10 = cf_off_se10_tab;
    1578        3292 :                 *cf_se11 = &cf_se11_tab[0][0][0];
    1579        3292 :                 *cf_off_se11 = &cf_off_se11_tab[0][0];
    1580        3292 :                 BREAK;
    1581           0 :             case IGF_BITRATE_UNKNOWN:
    1582             :             default:
    1583           0 :                 assert( 0 );
    1584             :         }
    1585           0 :     }
    1586             : 
    1587       53961 :     return retValue;
    1588             : }

Generated by: LCOV version 1.14