LCOV - code coverage report
Current view: top level - lib_com - ivas_stereo_dft_com.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 74 76 97.4 %
Date: 2025-05-23 08:37:30 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : #include <assert.h>
      34             : #include <stdint.h>
      35             : #include "options.h"
      36             : #include "ivas_cnst.h"
      37             : #include "ivas_rom_com.h"
      38             : #include "ivas_prot.h"
      39             : #include "prot.h"
      40             : #include "cnst.h"
      41             : #include "wmc_auto.h"
      42             : 
      43             : /*-------------------------------------------------------------------------
      44             :  * stereo_dft_config()
      45             :  *
      46             :  * DFT Stereo Configuration function
      47             :  *------------------------------------------------------------------------*/
      48             : 
      49       39635 : void stereo_dft_config(
      50             :     STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o  : DFT stereo configuration                */
      51             :     const int32_t brate,                   /* i  : IVAS/CPE/nominal total bitrate          */
      52             :     int16_t *bits_frame_nominal,           /* o  : primary channel nominal bits per frame  */
      53             :     int16_t *bits_frame_nominal_2          /* o  : secondary channel nominal bits per frame*/
      54             : )
      55             : {
      56       39635 :     if ( hConfig != NULL )
      57             :     {
      58       38882 :         hConfig->band_res = STEREO_DFT_BAND_RES_HIGH;
      59       38882 :         hConfig->prm_res = 2;
      60             : #ifndef DEBUG_STEREO_DFT_NOSTEREO
      61       38882 :         hConfig->dmx_active = STEREO_DFT_DMX_ACTIVE;
      62             : #else
      63             :         hConfig->dmx_active = 0;
      64             : #endif
      65       38882 :         hConfig->ada_wb_res_cod_mode = 0;
      66             :     }
      67             : 
      68       39635 :     *bits_frame_nominal_2 = 5000 / FRAMES_PER_SEC;
      69             : 
      70             :     /* ITD, IPD and residual coding is not used in SID/No data  */
      71       39635 :     if ( brate == FRAME_NO_DATA )
      72             :     {
      73       12708 :         *bits_frame_nominal = FRAME_NO_DATA;
      74       12708 :         if ( hConfig != NULL )
      75             :         {
      76             : #ifdef DEBUG_MODE_DFT
      77             :             hConfig->itd_mode = 1;
      78             :             hConfig->gipd_mode = 1;
      79             : #endif
      80       12708 :             hConfig->res_pred_mode = STEREO_DFT_RESPRED_OFF;
      81       12708 :             hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
      82       12708 :             hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
      83             :         }
      84             :     }
      85       26927 :     else if ( brate == IVAS_SID_5k2 )
      86             :     {
      87        5899 :         *bits_frame_nominal = SID_2k40 / FRAMES_PER_SEC;
      88        5899 :         if ( hConfig != NULL )
      89             :         {
      90             : #ifdef DEBUG_MODE_DFT
      91             :             hConfig->itd_mode = 1;
      92             :             hConfig->gipd_mode = 1;
      93             : #endif
      94        5899 :             hConfig->res_pred_mode = STEREO_DFT_RESPRED_OFF;
      95        5899 :             hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
      96        5899 :             hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
      97             :         }
      98             :     }
      99       21028 :     else if ( brate <= IVAS_13k2 )
     100             :     {
     101        5534 :         *bits_frame_nominal = ACELP_9k60 / FRAMES_PER_SEC;
     102        5534 :         if ( hConfig != NULL )
     103             :         {
     104             : #ifdef DEBUG_MODE_DFT
     105             :             hConfig->itd_mode = 1;
     106             :             hConfig->gipd_mode = 1;
     107             : #endif
     108        5534 :             hConfig->res_pred_mode = STEREO_DFT_RESPRED_ESF;
     109        5534 :             hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
     110        5534 :             hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
     111             :         }
     112             :     }
     113       15494 :     else if ( brate <= IVAS_16k4 )
     114             :     {
     115        3728 :         *bits_frame_nominal = ACELP_13k20 / FRAMES_PER_SEC;
     116        3728 :         if ( hConfig != NULL )
     117             :         {
     118             : #ifdef DEBUG_MODE_DFT
     119             :             hConfig->itd_mode = 1;
     120             :             hConfig->gipd_mode = 1;
     121             : #endif
     122        3636 :             hConfig->res_pred_mode = STEREO_DFT_RESPRED_ESF;
     123        3636 :             hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
     124        3636 :             hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
     125             :         }
     126             :     }
     127       11766 :     else if ( brate <= IVAS_24k4 )
     128             :     {
     129        6984 :         *bits_frame_nominal = ACELP_16k40 / FRAMES_PER_SEC;
     130        6984 :         if ( hConfig != NULL )
     131             :         {
     132             : #ifdef DEBUG_MODE_DFT
     133             :             hConfig->itd_mode = 1;
     134             :             hConfig->gipd_mode = 1;
     135             : #endif
     136        6796 :             hConfig->res_pred_mode = STEREO_DFT_RESPRED_ESF;
     137        6796 :             hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
     138             :         }
     139             :     }
     140        4782 :     else if ( brate <= IVAS_32k )
     141             :     {
     142        4743 :         *bits_frame_nominal = ACELP_24k40 / FRAMES_PER_SEC;
     143        4743 :         if ( hConfig != NULL )
     144             :         {
     145        4270 :             hConfig->ada_wb_res_cod_mode = 1;
     146             : #ifdef DEBUG_MODE_DFT
     147             :             hConfig->itd_mode = 1;
     148             :             hConfig->gipd_mode = 1;
     149             : #endif
     150        4270 :             hConfig->res_pred_mode = STEREO_DFT_RESPRED_STEFI;
     151        4270 :             hConfig->res_cod_mode = STEREO_DFT_RES_COD_1kHz;
     152             :         }
     153             :     }
     154          39 :     else if ( brate <= IVAS_48k )
     155             :     {
     156          39 :         *bits_frame_nominal = ACELP_32k / FRAMES_PER_SEC;
     157          39 :         if ( hConfig != NULL )
     158             :         {
     159             : #ifdef DEBUG_MODE_DFT
     160             :             hConfig->itd_mode = 1;
     161             :             hConfig->gipd_mode = 1;
     162             : #endif
     163          39 :             hConfig->res_pred_mode = STEREO_DFT_RESPRED_STEFI;
     164          39 :             hConfig->res_cod_mode = STEREO_DFT_RES_COD_1_6kHz;
     165             :         }
     166             :     }
     167             :     else
     168             :     {
     169           0 :         assert( 0 && "Bit-rate not supported by DFT stereo." );
     170             :     }
     171             : 
     172       39635 :     if ( hConfig != NULL && hConfig->force_mono_transmission )
     173             :     {
     174        1735 :         hConfig->res_pred_mode = STEREO_DFT_RESPRED_OFF;
     175        1735 :         hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
     176        1735 :         hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
     177        1735 :         hConfig->ada_wb_res_cod_mode = 0;
     178             :     }
     179             : 
     180             :     /*sanity check*/
     181       39635 :     if ( hConfig != NULL )
     182             :     {
     183       38882 :         assert( hConfig->prm_res <= STEREO_DFT_NBDIV );
     184             :         /* make sure residual switching and ESF are not active at the same time */
     185       38882 :         assert( !( hConfig->ada_wb_res_cod_mode == 1 && hConfig->res_pred_mode == STEREO_DFT_RESPRED_ESF ) );
     186             :     }
     187             : 
     188       39635 :     return;
     189             : }
     190             : 
     191             : /*-------------------------------------------------------------------------
     192             :  * stereo_dft_band_config()
     193             :  *
     194             :  * Stereo DFT bands condfiguration
     195             :  *------------------------------------------------------------------------*/
     196             : 
     197      367187 : int16_t stereo_dft_band_config(
     198             :     int16_t *band_limits,   /* o  : DFT band limits                     */
     199             :     const int16_t band_res, /* i  : DFT band resolution                 */
     200             :     const int16_t NFFT,     /* i  : analysis/synthesis window length    */
     201             :     const int16_t enc_dec   /* i  : flag to indicate enc vs dec         */
     202             : )
     203             : {
     204             :     int16_t nbands;
     205             : 
     206             :     /*sanity check*/
     207      367187 :     assert( ( band_res == 1 || band_res == 0 || band_res == 2 ) && "stereo DFT: Parameter band resolution not supported!\n" );
     208             : 
     209      367187 :     band_limits[0] = 1;
     210      367187 :     nbands = 0;
     211     3763940 :     while ( band_limits[nbands++] < NFFT / 2 )
     212             :     {
     213     3396753 :         if ( band_res == 0 )
     214             :         {
     215           0 :             assert( 0 && "stereo DFT: band config failed!\n" );
     216             :         }
     217     3396753 :         else if ( band_res == 1 )
     218             :         {
     219     2511636 :             if ( enc_dec == ENC )
     220             :             {
     221     1439448 :                 band_limits[nbands] = (int16_t) round_f( dft_band_limits_erb4[nbands] * ( (float) ( STEREO_DFT_N_NS_ENC ) / STEREO_DFT_N_NS ) );
     222             :             }
     223             :             else
     224             :             {
     225     1072188 :                 band_limits[nbands] = (int16_t) round_f( dft_band_limits_erb4[nbands] * ( (float) ( STEREO_DFT32MS_N_NS ) / STEREO_DFT_N_NS ) );
     226             :             }
     227             : 
     228     2511636 :             assert( ( nbands < STEREO_DFT_ERB4_BANDS ) && "stereo DFT: band config failed!\n" );
     229             :         }
     230             :         else
     231             :         {
     232      885117 :             if ( enc_dec == ENC )
     233             :             {
     234      314589 :                 band_limits[nbands] = (int16_t) round_f( dft_band_limits_erb8[nbands] * ( (float) ( STEREO_DFT_N_NS_ENC ) / STEREO_DFT_N_NS ) );
     235             :             }
     236             :             else
     237             :             {
     238      570528 :                 band_limits[nbands] = (int16_t) round_f( dft_band_limits_erb8[nbands] * ( (float) ( STEREO_DFT32MS_N_NS ) / STEREO_DFT_N_NS ) );
     239             :             }
     240             : 
     241      885117 :             assert( ( nbands < STEREO_DFT_ERB8_BANDS ) && "stereo DFT: band config failed!\n" );
     242             :         }
     243             :     }
     244      367187 :     nbands--;
     245      367187 :     band_limits[nbands] = NFFT / 2; /*Nyquist Freq*/
     246             : 
     247      367187 :     return ( nbands );
     248             : }

Generated by: LCOV version 1.14