LCOV - code coverage report
Current view: top level - lib_enc - decision_matrix_enc.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 151 225 67.1 %
Date: 2025-05-23 08:37:30 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : /*====================================================================================
      34             :     EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
      35             :   ====================================================================================*/
      36             : 
      37             : #include <assert.h>
      38             : #include <stdint.h>
      39             : #include "options.h"
      40             : #ifdef DEBUGGING
      41             : #include "debug.h"
      42             : #endif
      43             : #include "prot.h"
      44             : #include "stat_enc.h"
      45             : #include "stat_dec.h"
      46             : #include "rom_com.h"
      47             : #include "wmc_auto.h"
      48             : 
      49             : 
      50             : /*-----------------------------------------------------------------*
      51             :  * decision_matrix_enc()
      52             :  *
      53             :  * Select operating point (combination of technologies) based on input signal properties and command-line parameters:
      54             :  *
      55             :  *             7.20        8.00        9.60        13.20        16.40         24.40            32               48               64               96      128
      56             :  *  Mode       1           1           2           1            2             2                1                2                1                2       2
      57             :  * ----------------------------------------------------------------------------------------------------------------------------------------------------------------
      58             :  *  NB
      59             :  *  speech     ACELP@12k8  ACELP@12k8  ACELP@12k8  ACELP@12k8
      60             :  *  audio      LR MDCT     LR MDCT     TCX         LR MDCT
      61             :  *  inactive   GSC@12k8    GSC@12k8    TCX         GSC@12k8
      62             :  * ----------------------------------------------------------------------------------------------------------------------------------------------------------------
      63             :  *  WB
      64             :  *  speech     ACELP@12k8  ACELP@12k8  ACELP@12k8  ACELP@12k8   ACELP@16k     ACELP@16k        ACELP@16k        TCX              ACELP@16k        TCX     TCX
      65             :  *             +0b WB BWE  +0b WB BWE  +TD WB BWE  +TD WB BWE
      66             :  *  audio      GSC@12k8    GSC@12k8    TCX         LR MDCT      TCX           TCX              HQ               TCX              HQ               TCX     TCX
      67             :  *             +0b WB BWE  +0b WB BWE  +IGF
      68             :  *  inactive   GSC@12k8    GSC@12k8    TCX         GSC@12k8     TCX           TCX              AVQ@16k          TCX              AVQ@16k          TCX     TCX
      69             :  *             +0b WB BWE  +0b WB BWE  +IGF        +FD WB BWE
      70             :  * ----------------------------------------------------------------------------------------------------------------------------------------------------------------
      71             :  *  SWB
      72             :  *  speech                                         ACELP@12k8   ACELP@16k     ACELP@16k        ACELP@16k        TCX              ACELP@16k        TCX     TCX
      73             :  *                                                 +TD SWB BWE  +TD SWB BWE   +TD SWB BWE      +TD SWB BWE      +IGF             +HR SWB BWE
      74             :  *  audio                                          LR MDCT/GSC  TCX           TCX              HQ               TCX              HQ               TCX     TCX
      75             :  *                                                 +FD SWB BWE  +IGF          +IGF             +FD SWB BWE      +IGF
      76             :  *  inactive                                       GSC@12k8     TCX           TCX              AVQ@16k          TCX              AVQ@16k          TCX     TCX
      77             :  *                                                 +FD SWB BWE  +IGF          +IGF             +FD SWB BWE      +IGF             +HR SWB BWE
      78             :  * ----------------------------------------------------------------------------------------------------------------------------------------------------------------
      79             :  *  FB
      80             :  *  speech                                                      ACELP@16k     ACELP@16k        ACELP@16k        TCX              ACELP@16k        TCX     TCX
      81             :  *                                                              +TD FB BWE    +TD FB BWE       +TD FB BWE       +IGF             +HR FB BWE
      82             :  *  audio                                                       TCX           TCX              HQ               TCX              HQ               TCX     TCX
      83             :  *                                                              +IGF          +IGF             +FD FB BWE       +IGF
      84             :  *  inactive                                                    TCX           TCX              AVQ@16k          TCX              AVQ@16k          TCX     TCX
      85             :  *                                                              +IGF          +IGF             +FD FB BWE       +IGF             +HR FB BWE
      86             :  * -----------------------------------------------------------------------------------------------------------------------------------------------------------------
      87             :  *
      88             :  * Note: the GSC technology is part of the ACELP core as AUDIO coder_type (it is used also at 13.2 for SWB unvoiced noisy speech)
      89             :  * Note2: FB processing is optional and is activated via "-band FB" option on the encoder command line
      90             :  * Note3: NB (0-4kHz), WB (0-8kHz), SWB (0-16kHz), FB (0-20kHz)
      91             :  *
      92             :  * Signalling of modes (x marks a mode that must be signalled in the bitstream)
      93             :  *
      94             :  *                     7.20           8.00           9.6            13.2           16.4           24.4           32             48             64
      95             :  *                     NB WB SWB FB   NB WB SWB FB   NB WB SWB FB   NB WB SWB FB   NB WB SWB FB   NB WB SWB FB   NB WB SWB FB   NB WB SWB FB   NB WB SWB FB
      96             :  * GC, 12k8            x  x           x  x           x  x           x  x   x       x  x   x       x
      97             :  * UC, 12k8            x  x           x  x           x  x
      98             :  * VC, 12k8            x  x           x  x           x  x           x  x   x       x  x   x       x
      99             :  * TC, 12k8            x  x           x  x           x  x           x  x   x       x  x   x       x
     100             :  * GC, 16k                                                                                           x   x   x      x   x   x      x   x   x      x   x   x
     101             :  * TC, 16k                                                                                           x   x   x      x   x   x      x   x   x      x   x   x
     102             :  * AC(GSC)             x  x           x  x           x  x           x  x   x       x  x   x       x
     103             :  * IC                  x  x           x  x           x  x           x  x   x       x  x   x       x  x   x   x      x   x   x      x   x   x      x   x   x
     104             :  *
     105             :  * GC, 12k8, FS        x  x           x  x           x  x           x  x   x       x  x   x       x
     106             :  * GC, 16k, FS                                                                                       x   x   x      x   x   x      x   x   x          x   x
     107             :  * VC, 12k8, FS                                                     x  x   x       x  x   x       x
     108             :  * TC, 12k8, FS                                                                                   x
     109             :  * TC, 16k, FS                                                                                       x   x   x      x   x   x      x   x   x          x   x
     110             :  *
     111             :  * LR MDCT             x              x              x              x  x   x   x   x  x   x   x
     112             :  *
     113             :  *-----------------------------------------------------------------*/
     114             : 
     115        2050 : void decision_matrix_enc(
     116             :     Encoder_State *st,    /* i  : encoder state structure                 */
     117             :     int16_t *hq_core_type /* o  : HQ core type                            */
     118             : )
     119             : {
     120             :     /* initialization */
     121        2050 :     st->core = -1;
     122        2050 :     st->extl = -1;
     123        2050 :     st->extl_brate = 0;
     124        2050 :     *hq_core_type = -1;
     125        2050 :     st->igf = 0;
     126             : 
     127             :     /* SID and FRAME_NO_DATA frames */
     128        2050 :     if ( st->Opt_DTX_ON && ( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA ) )
     129             :     {
     130           0 :         st->core = ACELP_CORE;
     131             : 
     132           0 :         if ( st->input_Fs >= 32000 && st->bwidth >= SWB )
     133             :         {
     134           0 :             st->extl = SWB_CNG;
     135             :         }
     136             : 
     137           0 :         st->rf_mode = 0;
     138             : 
     139           0 :         return;
     140             :     }
     141             : 
     142        2050 :     st->core_brate = 0;
     143             : 
     144             :     /* SC-VBR */
     145        2050 :     if ( st->Opt_SC_VBR )
     146             :     {
     147             :         /* SC-VBR */
     148           0 :         st->core = ACELP_CORE;
     149           0 :         st->core_brate = ACELP_7k20;
     150           0 :         st->total_brate = ACELP_7k20;
     151             : 
     152           0 :         if ( st->hSC_VBR->ppp_mode == 1 )
     153             :         {
     154             :             /* PPP mode */
     155           0 :             st->core_brate = PPP_NELP_2k80;
     156             :         }
     157           0 :         else if ( ( ( st->coder_type == UNVOICED || st->coder_type == TRANSITION ) && !st->sp_aud_decision1 ) || st->bwidth != NB )
     158             :         {
     159           0 :             if ( st->coder_type == UNVOICED && st->vad_flag == 1 && ( ( st->last_bwidth >= SWB && st->last_Opt_SC_VBR ) || st->last_bwidth < SWB ) && ( st->last_core != HQ_CORE || st->bwidth != NB ) )
     160             :             {
     161             :                 /* NELP mode */
     162           0 :                 st->hSC_VBR->nelp_mode = 1;
     163           0 :                 st->core_brate = PPP_NELP_2k80;
     164             :             }
     165           0 :             else if ( st->coder_type == TRANSITION || ( st->coder_type == UNVOICED && st->hSC_VBR->nelp_mode != 1 ) || ( ( st->coder_type == AUDIO || st->coder_type == INACTIVE ) && st->bwidth != NB ) )
     166             :             {
     167             :                 /* silence portions */
     168           0 :                 st->core_brate = ACELP_8k00;
     169           0 :                 st->total_brate = ACELP_8k00;
     170             :             }
     171             :         }
     172             : 
     173             :         /* set inactive coder_type flag in ACELP core to GSC */
     174           0 :         st->inactive_coder_type_flag = 1;
     175             : 
     176           0 :         return;
     177             :     }
     178             : 
     179             :     /*---------------------------------------------------------------------*
     180             :      * NB
     181             :      *---------------------------------------------------------------------*/
     182             : 
     183        2050 :     else if ( st->bwidth == NB )
     184             :     {
     185           0 :         st->core = ACELP_CORE;
     186             : 
     187             : #ifdef DEBUGGING
     188             :         if ( st->total_brate >= HQCORE_NB_MIN_RATE && ( st->force == FORCE_MUSIC || ( st->force == -1 && st->sp_aud_decision1 == 1 ) ) )
     189             :         {
     190             :             st->core = HQ_CORE;
     191             :         }
     192             : #else
     193           0 :         if ( st->total_brate >= HQCORE_NB_MIN_RATE && st->sp_aud_decision1 == 1 )
     194             :         {
     195           0 :             st->core = HQ_CORE;
     196             :         }
     197             : #endif
     198             :     }
     199             : 
     200             :     /*---------------------------------------------------------------------*
     201             :      * WB
     202             :      *---------------------------------------------------------------------*/
     203             : 
     204        2050 :     else if ( st->bwidth == WB )
     205             :     {
     206           0 :         st->core = ACELP_CORE;
     207             : 
     208             : #ifdef DEBUGGING
     209             :         if ( ( st->total_brate >= HQCORE_WB_MIN_RATE && ( st->force == FORCE_MUSIC || ( st->force == -1 && st->sp_aud_decision1 == 1 ) ) ) || st->total_brate >= HQ_96k )
     210             : #else
     211           0 :         if ( ( st->total_brate >= HQCORE_WB_MIN_RATE && st->sp_aud_decision1 == 1 ) || st->total_brate >= HQ_96k )
     212             : #endif
     213             :         {
     214           0 :             st->core = HQ_CORE;
     215             :         }
     216             :         else
     217             :         {
     218           0 :             if ( st->bwidth == WB && st->total_brate < ACELP_9k60 )
     219             :             {
     220           0 :                 st->extl = WB_BWE;
     221             :             }
     222           0 :             else if ( st->bwidth == WB && st->total_brate >= ACELP_9k60 && st->total_brate <= ACELP_16k40 )
     223             :             {
     224             :                 /* Note: WB BWE is used exceptionally at 13.2 kbps if GSC is selected instead of LR-MDCT */
     225           0 :                 if ( st->sp_aud_decision1 == 1 || st->coder_type == INACTIVE || ( st->sp_aud_decision1 == 0 && st->sp_aud_decision2 == 1 ) )
     226             :                 {
     227           0 :                     st->extl = WB_BWE;
     228           0 :                     st->extl_brate = WB_BWE_0k35;
     229             :                 }
     230             :                 else
     231             :                 {
     232           0 :                     st->extl = WB_TBE;
     233           0 :                     st->extl_brate = WB_TBE_1k05;
     234             :                 }
     235             :             }
     236             :         }
     237             :     }
     238             : 
     239             :     /*---------------------------------------------------------------------*
     240             :      * SWB and FB
     241             :      *---------------------------------------------------------------------*/
     242             : 
     243        2050 :     else if ( st->bwidth == SWB || st->bwidth == FB )
     244             :     {
     245             : #ifdef DEBUGGING
     246             :         if ( ( st->total_brate >= HQCORE_WB_MIN_RATE && ( st->force == FORCE_MUSIC || ( st->force == -1 && st->sp_aud_decision1 == 1 ) ) ) || st->total_brate >= HQ_96k )
     247             : #else
     248        2050 :         if ( ( st->total_brate >= HQCORE_SWB_MIN_RATE && st->sp_aud_decision1 == 1 ) || st->total_brate >= HQ_96k )
     249             : #endif
     250             :         {
     251         640 :             st->core = HQ_CORE;
     252             :         }
     253             :         else
     254             :         {
     255        1410 :             st->core = ACELP_CORE;
     256             : 
     257        1410 :             if ( st->total_brate >= ACELP_13k20 && st->total_brate < ACELP_48k )
     258             :             {
     259             :                 /* Note: SWB BWE is not used in case of GSC noisy speech */
     260             :                 /* Note: SWB BWE is used exceptionally at 13.2 kbps if GSC is selected instead of LR-MDCT */
     261         741 :                 if ( ( st->sp_aud_decision1 == 1 || st->coder_type == INACTIVE || ( st->sp_aud_decision1 == 0 && st->sp_aud_decision2 == 1 ) ) && !st->GSC_noisy_speech )
     262             :                 {
     263           6 :                     st->extl = SWB_BWE;
     264           6 :                     st->extl_brate = SWB_BWE_1k6;
     265             : 
     266           6 :                     if ( st->bwidth == FB && st->total_brate >= ACELP_24k40 )
     267             :                     {
     268           0 :                         st->extl = FB_BWE;
     269           0 :                         st->extl_brate = FB_BWE_1k8;
     270             :                     }
     271             :                 }
     272             :                 else
     273             :                 {
     274         735 :                     st->extl = SWB_TBE;
     275         735 :                     st->extl_brate = SWB_TBE_1k6;
     276             : 
     277         735 :                     if ( st->total_brate >= ACELP_24k40 )
     278             :                     {
     279           0 :                         st->extl_brate = SWB_TBE_2k8;
     280             :                     }
     281             : 
     282         735 :                     if ( st->bwidth == FB && st->total_brate >= ACELP_24k40 )
     283             :                     {
     284           0 :                         st->extl = FB_TBE;
     285           0 :                         st->extl_brate = FB_TBE_3k0;
     286             :                     }
     287             :                 }
     288             :             }
     289         669 :             else if ( st->total_brate >= ACELP_48k )
     290             :             {
     291         669 :                 st->extl = SWB_BWE_HIGHRATE;
     292         669 :                 st->extl_brate = SWB_BWE_16k;
     293             : 
     294         669 :                 if ( st->bwidth == FB )
     295             :                 {
     296           0 :                     st->extl = FB_BWE_HIGHRATE;
     297             :                 }
     298             :             }
     299             :         }
     300             :     }
     301             : 
     302             :     /*-----------------------------------------------------------------*
     303             :      * Set HQ core type
     304             :      *-----------------------------------------------------------------*/
     305             : 
     306        2050 :     if ( st->core == HQ_CORE )
     307             :     {
     308         640 :         *hq_core_type = NORMAL_HQ_CORE;
     309             : 
     310         640 :         if ( ( st->bwidth == SWB || st->bwidth == WB ) && st->total_brate <= LRMDCT_CROSSOVER_POINT )
     311             :         {
     312             :             /* note that FB (bitrate >= 24400 bps) is always coded with NORMAL_HQ_CORE */
     313         309 :             *hq_core_type = LOW_RATE_HQ_CORE;
     314             :         }
     315         331 :         else if ( st->bwidth == NB )
     316             :         {
     317           0 :             *hq_core_type = LOW_RATE_HQ_CORE;
     318             :         }
     319             :     }
     320             : 
     321             :     /* set core bitrate */
     322        2050 :     st->core_brate = st->total_brate - st->extl_brate;
     323             : 
     324        2050 :     if ( st->ini_frame == 0 )
     325             :     {
     326             :         /* avoid switching in the very first frame */
     327           2 :         st->last_core = st->core;
     328           2 :         st->last_core_brate = st->core_brate;
     329           2 :         st->last_extl = st->extl;
     330             :     }
     331             : 
     332             :     /*-----------------------------------------------------------------*
     333             :      * set inactive coder_type flag in ACELP core
     334             :      *-----------------------------------------------------------------*/
     335             : 
     336        2050 :     st->inactive_coder_type_flag = 0; /* AVQ by default */
     337        2050 :     if ( st->total_brate <= MAX_GSC_INACTIVE_BRATE )
     338             :     {
     339        1050 :         st->inactive_coder_type_flag = 1; /* GSC */
     340             :     }
     341             : 
     342        2050 :     return;
     343             : }
     344             : 
     345             : 
     346             : /*---------------------------------------------------------------------*
     347             :  * signaling_mode1_tcx20_enc()
     348             :  *
     349             :  * write MODE1 TCX20 signaling information into the bitstream
     350             :  *---------------------------------------------------------------------*/
     351             : 
     352         550 : int16_t signaling_mode1_tcx20_enc(
     353             :     Encoder_State *st, /* i/o: encoder state structure   */
     354             :     const int16_t push /* i  : flag to push indice       */
     355             : )
     356             : {
     357             :     int16_t num_bits;
     358             :     int16_t nBits, idx, start_idx;
     359         550 :     BSTR_ENC_HANDLE hBstr = st->hBstr;
     360             : 
     361         550 :     assert( st->core == TCX_20_CORE );
     362             : 
     363         550 :     num_bits = 0;
     364             : 
     365             :     /* Use ACELP signaling for LR MDCT */
     366         550 :     if ( st->total_brate <= ACELP_16k40 )
     367             :     {
     368             :         /* find the section in the ACELP signaling table corresponding to bitrate */
     369         550 :         idx = 0;
     370       19250 :         while ( acelp_sig_tbl[idx] != st->total_brate )
     371             :         {
     372       18700 :             idx++;
     373             :         }
     374             : 
     375             :         /* retrieve the number of bits for signaling */
     376         550 :         nBits = (int16_t) acelp_sig_tbl[++idx];
     377             : 
     378             :         /* retrieve the signaling index */
     379         550 :         start_idx = ++idx;
     380       17600 :         while ( acelp_sig_tbl[idx] != SIG2IND( LR_MDCT, st->bwidth, 0, 0 ) )
     381             :         {
     382       17050 :             idx++;
     383             :         }
     384             : 
     385         550 :         num_bits += nBits;
     386         550 :         if ( push )
     387             :         {
     388         275 :             push_indice( hBstr, IND_ACELP_SIGNALLING, idx - start_idx, nBits );
     389             :         }
     390             : 
     391             :         /* HQ/TCX core switching flag */
     392         550 :         ++num_bits;
     393         550 :         if ( push )
     394             :         {
     395         275 :             push_indice( hBstr, IND_MDCT_CORE, 1, 1 );
     396             :         }
     397             :     }
     398             :     else
     399             :     {
     400           0 :         if ( st->core_brate <= ACELP_64k )
     401             :         {
     402             :             /* write ACELP/HQ core indication flag */
     403           0 :             ++num_bits;
     404           0 :             if ( push )
     405             :             {
     406           0 :                 push_indice( hBstr, IND_CORE, 1, 1 );
     407             :             }
     408             :         }
     409             : 
     410             :         /* HQ/TCX core switching flag */
     411           0 :         ++num_bits;
     412           0 :         if ( push )
     413             :         {
     414           0 :             push_indice( hBstr, IND_MDCT_CORE, 1, 1 );
     415             :         }
     416             : 
     417           0 :         num_bits += 2;
     418           0 :         if ( push )
     419             :         {
     420             :             /* write band-width (needed for different I/O sampling rate support) */
     421           0 :             if ( st->bwidth == NB )
     422             :             {
     423           0 :                 push_indice( hBstr, IND_HQ_BWIDTH, 0, 2 );
     424             :             }
     425           0 :             else if ( st->bwidth == WB )
     426             :             {
     427           0 :                 push_indice( hBstr, IND_HQ_BWIDTH, 1, 2 );
     428             :             }
     429           0 :             else if ( st->bwidth == SWB )
     430             :             {
     431           0 :                 push_indice( hBstr, IND_HQ_BWIDTH, 2, 2 );
     432             :             }
     433             :             else /* st->bwidth == FB */
     434             :             {
     435           0 :                 push_indice( hBstr, IND_HQ_BWIDTH, 3, 2 );
     436             :             }
     437             :         }
     438             :     }
     439             : 
     440         550 :     return num_bits;
     441             : }
     442             : 
     443             : 
     444             : /*---------------------------------------------------------------------*
     445             :  * signaling_enc()
     446             :  *
     447             :  * write signaling information into the bitstream
     448             :  *---------------------------------------------------------------------*/
     449             : 
     450        1850 : void signaling_enc(
     451             :     Encoder_State *st /* i  : encoder state structure   */
     452             : )
     453             : {
     454             :     int16_t nBits, idx, start_idx;
     455             :     int32_t total_brate_temp;
     456             :     int16_t sig;
     457        1850 :     BSTR_ENC_HANDLE hBstr = st->hBstr;
     458             : 
     459        1850 :     if ( st->mdct_sw == MODE2 )
     460             :     {
     461             : 
     462          75 :         assert( !st->tcxonly );
     463          75 :         assert( st->core == HQ_CORE );
     464             : 
     465          75 :         push_next_indice( hBstr, 1, 1 ); /* TCX */
     466          75 :         push_next_indice( hBstr, 1, 1 ); /* HQ_CORE */
     467             : 
     468             :         /* write ACELP->HQ core switching flag */
     469          75 :         if ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE )
     470             :         {
     471           8 :             push_indice( hBstr, IND_HQ_SWITCHING_FLG, 1, 1 );
     472             : 
     473             :             /* write ACELP L_frame info */
     474           8 :             if ( st->last_L_frame == L_FRAME )
     475             :             {
     476           0 :                 push_indice( hBstr, IND_LAST_L_FRAME, 0, 1 );
     477             :             }
     478             :             else
     479             :             {
     480           8 :                 push_indice( hBstr, IND_LAST_L_FRAME, 1, 1 );
     481             :             }
     482             :         }
     483             :         else
     484             :         {
     485          67 :             push_indice( hBstr, IND_HQ_SWITCHING_FLG, 0, 1 );
     486             :         }
     487             : 
     488          75 :         return;
     489             :     }
     490             : 
     491        1775 :     if ( st->core == ACELP_CORE )
     492             :     {
     493             :         int16_t ppp_mode, nelp_mode;
     494             : 
     495        1410 :         if ( st->Opt_SC_VBR )
     496             :         {
     497           0 :             ppp_mode = st->hSC_VBR->ppp_mode;
     498           0 :             nelp_mode = st->hSC_VBR->nelp_mode;
     499             :         }
     500             :         else
     501             :         {
     502        1410 :             ppp_mode = 0;
     503        1410 :             nelp_mode = 0;
     504             :         }
     505             : 
     506        1410 :         if ( ppp_mode == 1 || nelp_mode == 1 )
     507             :         {
     508             :             /* 1 bit to distinguish between 2.8kbps PPP/NELP frame and SID frame */
     509           0 :             push_indice( hBstr, IND_CORE, 0, 1 );
     510             : 
     511             :             /* SC-VBR: 0 - PPP_NB, 1 - PPP_WB, 2 - NELP_NB, 3 - NELP_WB */
     512           0 :             if ( st->coder_type == VOICED && st->bwidth == NB && ppp_mode == 1 )
     513             :             {
     514           0 :                 push_indice( hBstr, IND_PPP_NELP_MODE, 0, 2 );
     515             :             }
     516           0 :             else if ( st->coder_type == VOICED && st->bwidth != NB && ppp_mode == 1 )
     517             :             {
     518           0 :                 push_indice( hBstr, IND_PPP_NELP_MODE, 1, 2 );
     519             :             }
     520           0 :             else if ( st->coder_type == UNVOICED && st->bwidth == NB && nelp_mode == 1 )
     521             :             {
     522           0 :                 push_indice( hBstr, IND_PPP_NELP_MODE, 2, 2 );
     523             :             }
     524           0 :             else if ( st->coder_type == UNVOICED && st->bwidth != NB && nelp_mode == 1 )
     525             :             {
     526           0 :                 push_indice( hBstr, IND_PPP_NELP_MODE, 3, 2 );
     527             :             }
     528             :         }
     529        1410 :         else if ( st->core_brate != SID_2k40 && st->core_brate != FRAME_NO_DATA )
     530             :         {
     531             :             /* write the ACELP/HQ core selection bit */
     532        1410 :             if ( st->total_brate >= ACELP_24k40 )
     533             :             {
     534         669 :                 push_indice( hBstr, IND_CORE, 0, 1 );
     535             :             }
     536             : 
     537             :             /* find the section in the ACELP signaling table corresponding to bitrate */
     538        1410 :             idx = 0;
     539        8985 :             while ( idx < MAX_ACELP_SIG )
     540             :             {
     541        8985 :                 if ( st->total_brate <= brate_tbl[idx] )
     542             :                 {
     543        1410 :                     break;
     544             :                 }
     545        7575 :                 idx++;
     546             :             }
     547        1410 :             total_brate_temp = brate_tbl[idx];
     548             : 
     549        1410 :             idx = 0;
     550       83469 :             while ( acelp_sig_tbl[idx] != total_brate_temp )
     551             :             {
     552       82059 :                 idx++;
     553             :             }
     554             : 
     555             :             /* retrieve the number of bits for signaling */
     556        1410 :             nBits = (int16_t) acelp_sig_tbl[++idx];
     557             : 
     558             :             /* retrieve the signaling index */
     559        1410 :             start_idx = ++idx;
     560        1410 :             if ( st->element_mode == IVAS_CPE_TD && st->bwidth == SWB && st->total_brate <= ACELP_9k60 )
     561             :             {
     562             :                 /* patch to signal SWB as NB in Stereo */
     563           0 :                 sig = SIG2IND( st->coder_type, NB, st->sharpFlag, st->rf_mode );
     564             :             }
     565             :             else
     566             :             {
     567        1410 :                 sig = SIG2IND( st->coder_type, st->bwidth, st->sharpFlag, st->rf_mode );
     568             :             }
     569             : 
     570       11396 :             while ( acelp_sig_tbl[idx] != sig )
     571             :             {
     572        9986 :                 idx++;
     573             :             }
     574             : 
     575        1410 :             push_indice( hBstr, IND_ACELP_SIGNALLING, idx - start_idx, nBits );
     576             :         }
     577             : 
     578             :         /* write extension layer flag to distinguish between TBE (0) and BWE (1) */
     579        1410 :         if ( st->extl_brate > 0 )
     580             :         {
     581        1410 :             if ( st->extl == WB_TBE || st->extl == SWB_TBE || st->extl == FB_TBE )
     582             :             {
     583         735 :                 push_indice( hBstr, IND_BWE_FLAG, 0, 1 );
     584             :             }
     585         675 :             else if ( st->extl == WB_BWE || st->extl == SWB_BWE || st->extl == FB_BWE )
     586             :             {
     587           6 :                 push_indice( hBstr, IND_BWE_FLAG, 1, 1 );
     588             :             }
     589             :         }
     590             :     }
     591             :     else /* HQ core */
     592             :     {
     593             :         /* write ACELP->HQ core switching flag */
     594         365 :         if ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE )
     595             :         {
     596          17 :             push_indice( hBstr, IND_HQ_SWITCHING_FLG, 1, 1 );
     597             : 
     598             :             /* write ACELP L_frame info */
     599          17 :             if ( st->last_L_frame == L_FRAME )
     600             :             {
     601           5 :                 push_indice( hBstr, IND_LAST_L_FRAME, 0, 1 );
     602             :             }
     603             :             else
     604             :             {
     605          12 :                 push_indice( hBstr, IND_LAST_L_FRAME, 1, 1 );
     606             :             }
     607             :         }
     608             :         else
     609             :         {
     610         348 :             push_indice( hBstr, IND_HQ_SWITCHING_FLG, 0, 1 );
     611             :         }
     612             : 
     613             :         /* HQ/TCX core switching flag */
     614         365 :         push_indice( hBstr, IND_MDCT_CORE, 0, 1 );
     615             : 
     616             :         /* Use ACELP signaling for LR MDCT */
     617         365 :         if ( st->total_brate <= ACELP_16k40 )
     618             :         {
     619             :             /* find the section in the ACELP signaling table corresponding to bitrate */
     620          34 :             idx = 0;
     621        1190 :             while ( acelp_sig_tbl[idx] != st->total_brate )
     622             :             {
     623        1156 :                 idx++;
     624             :             }
     625             : 
     626             :             /* retrieve the number of bits for signaling */
     627          34 :             nBits = (int16_t) acelp_sig_tbl[++idx];
     628             : 
     629             :             /* retrieve the signaling index */
     630          34 :             start_idx = ++idx;
     631        1088 :             while ( acelp_sig_tbl[idx] != SIG2IND( LR_MDCT, st->bwidth, 0, 0 ) )
     632             :             {
     633        1054 :                 idx++;
     634             :             }
     635             : 
     636          34 :             push_indice( hBstr, IND_ACELP_SIGNALLING, idx - start_idx, nBits );
     637             :         }
     638             :         else
     639             :         {
     640         331 :             if ( st->core_brate <= ACELP_64k )
     641             :             {
     642             :                 /* write ACELP/HQ core indication flag */
     643         331 :                 push_indice( hBstr, IND_CORE, 1, 1 );
     644             :             }
     645             : 
     646             :             /* write band-width (needed for different I/O sampling rate support) */
     647         331 :             if ( st->bwidth == NB )
     648             :             {
     649           0 :                 push_indice( hBstr, IND_HQ_BWIDTH, 0, 2 );
     650             :             }
     651         331 :             else if ( st->bwidth == WB )
     652             :             {
     653           0 :                 push_indice( hBstr, IND_HQ_BWIDTH, 1, 2 );
     654             :             }
     655         331 :             else if ( st->bwidth == SWB )
     656             :             {
     657         331 :                 push_indice( hBstr, IND_HQ_BWIDTH, 2, 2 );
     658             :             }
     659             :             else /* st->bwidth == FB */
     660             :             {
     661           0 :                 push_indice( hBstr, IND_HQ_BWIDTH, 3, 2 );
     662             :             }
     663             :         }
     664             :     }
     665             : 
     666        1775 :     return;
     667             : }
     668             : 
     669             : /*---------------------------------------------------------------------*
     670             :  * signaling_enc_rf()
     671             :  *
     672             :  * write channel-aware signaling information into the bitstream
     673             :  *---------------------------------------------------------------------*/
     674             : 
     675     1132914 : void signaling_enc_rf(
     676             :     Encoder_State *st /* i/o: encoder state structure */
     677             : )
     678             : {
     679             :     int16_t i, sfr;
     680     1132914 :     RF_ENC_HANDLE hRF = st->hRF;
     681             : 
     682             :     /* write partial copy into bitstream */
     683     1132914 :     if ( st->rf_mode == 1 )
     684             :     {
     685           0 :         enc_prm_rf( st, hRF->rf_indx_frametype[st->rf_fec_offset], st->rf_fec_offset );
     686           0 :         hRF->rf_indx_tbeGainFr[0] = hRF->RF_bwe_gainFr_ind;
     687             :     }
     688             : 
     689     1132914 :     if ( hRF != NULL )
     690             :     {
     691             :         /* Shift the RF indices such that the partial copy associated with
     692             :            (n-fec_offset)th frame is included in the bitstream in nth frame. */
     693        6200 :         for ( i = st->rf_fec_offset; i >= 0; i-- )
     694             :         {
     695             :             /* RF frame type */
     696        3100 :             hRF->rf_indx_frametype[i + 1] = hRF->rf_indx_frametype[i];
     697             : 
     698             :             /* RF target bits buffer */
     699        3100 :             hRF->rf_targetbits_buff[i + 1] = hRF->rf_targetbits_buff[i];
     700             : 
     701             :             /* lsf indx */
     702        3100 :             hRF->rf_indx_lsf[i + 1][0] = hRF->rf_indx_lsf[i][0];
     703        3100 :             hRF->rf_indx_lsf[i + 1][1] = hRF->rf_indx_lsf[i][1];
     704        3100 :             hRF->rf_indx_lsf[i + 1][2] = hRF->rf_indx_lsf[i][2];
     705             : 
     706             :             /* ES pred energy */
     707        3100 :             hRF->rf_indx_EsPred[i + 1] = hRF->rf_indx_EsPred[i];
     708             : 
     709             :             /* LTF mode, sfr params: pitch, fcb and gain */
     710       16550 :             for ( sfr = 0; sfr < st->nb_subfr; sfr++ )
     711             :             {
     712       13450 :                 hRF->rf_indx_ltfMode[i + 1][sfr] = hRF->rf_indx_ltfMode[i][sfr];
     713       13450 :                 hRF->rf_indx_pitch[i + 1][sfr] = hRF->rf_indx_pitch[i][sfr];
     714       13450 :                 hRF->rf_indx_fcb[i + 1][sfr] = hRF->rf_indx_fcb[i][sfr];
     715       13450 :                 hRF->rf_indx_gain[i + 1][sfr] = hRF->rf_indx_gain[i][sfr];
     716             :             }
     717             : 
     718             :             /* shift the nelp indices */
     719        3100 :             hRF->rf_indx_nelp_iG1[i + 1] = hRF->rf_indx_nelp_iG1[i];
     720        3100 :             hRF->rf_indx_nelp_iG2[i + 1][0] = hRF->rf_indx_nelp_iG2[i][0];
     721        3100 :             hRF->rf_indx_nelp_iG2[i + 1][1] = hRF->rf_indx_nelp_iG2[i][1];
     722        3100 :             hRF->rf_indx_nelp_fid[i + 1] = hRF->rf_indx_nelp_fid[i];
     723             : 
     724             :             /* tbe gain Fr shift */
     725        3100 :             hRF->rf_indx_tbeGainFr[i + 1] = hRF->rf_indx_tbeGainFr[i];
     726        3100 :             hRF->rf_clas[i + 1] = hRF->rf_clas[i];
     727        3100 :             hRF->rf_gain_tcx[i + 1] = hRF->rf_gain_tcx[i];
     728        3100 :             hRF->rf_tcxltp_param[i + 1] = hRF->rf_tcxltp_param[i];
     729             :         }
     730             :     }
     731             : 
     732     1132914 :     return;
     733             : }

Generated by: LCOV version 1.14