LCOV - code coverage report
Current view: top level - lib_com - ivas_stereo_dft_com_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 4c82f1d24d39d0296b18d775f18a006f4c7d024b Lines: 113 119 95.0 %
Date: 2025-05-17 01:59:02 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 "prot_fx.h"
      39             : #include "cnst.h"
      40             : #include "wmc_auto.h"
      41             : #include "ivas_prot_fx.h"
      42             : 
      43             : /*-------------------------------------------------------------------------
      44             :  * stereo_dft_config()
      45             :  *
      46             :  * DFT Stereo Configuration function
      47             :  *------------------------------------------------------------------------*/
      48             : 
      49        5430 : void stereo_dft_config_fx(
      50             :     STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o  : DFT stereo configuration                */
      51             :     const Word32 brate,                    /* i  : IVAS/CPE/nominal total bitrate          */
      52             :     Word16 *bits_frame_nominal,            /* o  : primary channel nominal bits per frame  */
      53             :     Word16 *bits_frame_nominal_2           /* o  : secondary channel nominal bits per frame*/
      54             : )
      55             : {
      56        5430 :     IF( hConfig != NULL )
      57             :     {
      58        5243 :         hConfig->band_res = STEREO_DFT_BAND_RES_HIGH;
      59        5243 :         move16();
      60        5243 :         hConfig->prm_res = 2;
      61        5243 :         move16();
      62        5243 :         hConfig->dmx_active = STEREO_DFT_DMX_ACTIVE;
      63        5243 :         move16();
      64        5243 :         hConfig->ada_wb_res_cod_mode = 0;
      65        5243 :         move16();
      66             :     }
      67             : 
      68        5430 :     *bits_frame_nominal_2 = 5000 / FRAMES_PER_SEC;
      69        5430 :     move16();
      70             : 
      71             :     /* ITD, IPD and residual coding is not used in SID/No data  */
      72        5430 :     IF( brate == FRAME_NO_DATA )
      73             :     {
      74        1367 :         *bits_frame_nominal = FRAME_NO_DATA;
      75        1367 :         move16();
      76        1367 :         IF( hConfig != NULL )
      77             :         {
      78        1367 :             hConfig->res_pred_mode = STEREO_DFT_RESPRED_OFF;
      79        1367 :             move16();
      80        1367 :             hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
      81        1367 :             move16();
      82        1367 :             hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
      83        1367 :             move16();
      84             :         }
      85             :     }
      86        4063 :     ELSE IF( EQ_32( brate, IVAS_SID_5k2 ) )
      87             :     {
      88        1523 :         *bits_frame_nominal = SID_2k40 / FRAMES_PER_SEC;
      89        1523 :         move16();
      90        1523 :         IF( hConfig != NULL )
      91             :         {
      92        1523 :             hConfig->res_pred_mode = STEREO_DFT_RESPRED_OFF;
      93        1523 :             move16();
      94        1523 :             hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
      95        1523 :             move16();
      96        1523 :             hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
      97        1523 :             move16();
      98             :         }
      99             :     }
     100        2540 :     ELSE IF( LE_32( brate, IVAS_13k2 ) )
     101             :     {
     102         721 :         *bits_frame_nominal = ACELP_9k60 / FRAMES_PER_SEC;
     103         721 :         move16();
     104         721 :         IF( hConfig != NULL )
     105             :         {
     106         721 :             hConfig->res_pred_mode = STEREO_DFT_RESPRED_ESF;
     107         721 :             move16();
     108         721 :             hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
     109         721 :             move16();
     110         721 :             hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
     111         721 :             move16();
     112             :         }
     113             :     }
     114        1819 :     ELSE IF( LE_32( brate, IVAS_16k4 ) )
     115             :     {
     116         505 :         *bits_frame_nominal = ACELP_13k20 / FRAMES_PER_SEC;
     117         505 :         move16();
     118         505 :         IF( hConfig != NULL )
     119             :         {
     120         483 :             hConfig->res_pred_mode = STEREO_DFT_RESPRED_ESF;
     121         483 :             move16();
     122         483 :             hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
     123         483 :             move16();
     124         483 :             hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
     125         483 :             move16();
     126             :         }
     127             :     }
     128        1314 :     ELSE IF( LE_32( brate, IVAS_24k4 ) )
     129             :     {
     130         782 :         *bits_frame_nominal = ACELP_16k40 / FRAMES_PER_SEC;
     131         782 :         move16();
     132         782 :         IF( hConfig != NULL )
     133             :         {
     134         735 :             hConfig->res_pred_mode = STEREO_DFT_RESPRED_ESF;
     135         735 :             move16();
     136         735 :             hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
     137         735 :             move16();
     138             :         }
     139             :     }
     140         532 :     ELSE IF( LE_32( brate, IVAS_32k ) )
     141             :     {
     142         519 :         *bits_frame_nominal = ACELP_24k40 / FRAMES_PER_SEC;
     143         519 :         move16();
     144         519 :         IF( hConfig != NULL )
     145             :         {
     146         401 :             hConfig->ada_wb_res_cod_mode = 1;
     147         401 :             move16();
     148         401 :             hConfig->res_pred_mode = STEREO_DFT_RESPRED_STEFI;
     149         401 :             move16();
     150         401 :             hConfig->res_cod_mode = STEREO_DFT_RES_COD_1kHz;
     151         401 :             move16();
     152             :         }
     153             :     }
     154          13 :     ELSE IF( LE_32( brate, IVAS_48k ) )
     155             :     {
     156          13 :         *bits_frame_nominal = ACELP_32k / FRAMES_PER_SEC;
     157          13 :         move16();
     158          13 :         IF( hConfig != NULL )
     159             :         {
     160          13 :             hConfig->res_pred_mode = STEREO_DFT_RESPRED_STEFI;
     161          13 :             move16();
     162          13 :             hConfig->res_cod_mode = STEREO_DFT_RES_COD_1_6kHz;
     163          13 :             move16();
     164             :         }
     165             :     }
     166             :     ELSE
     167             :     {
     168           0 :         assert( 0 && "Bit-rate not supported by DFT stereo." );
     169             :     }
     170             : 
     171        5430 :     test();
     172        5430 :     IF( hConfig != NULL && hConfig->force_mono_transmission )
     173             :     {
     174         266 :         hConfig->res_pred_mode = STEREO_DFT_RESPRED_OFF;
     175         266 :         move16();
     176         266 :         hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
     177         266 :         move16();
     178         266 :         hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
     179         266 :         move16();
     180         266 :         hConfig->ada_wb_res_cod_mode = 0;
     181         266 :         move16();
     182             :     }
     183             : 
     184             :     /*sanity check*/
     185        5430 :     IF( hConfig != NULL )
     186             :     {
     187        5243 :         assert( LE_16( hConfig->prm_res, STEREO_DFT_NBDIV ) );
     188             :         /* make sure residual switching and ESF are not active at the same time */
     189        5243 :         assert( !( EQ_16( hConfig->ada_wb_res_cod_mode, 1 ) && EQ_16( hConfig->res_pred_mode, STEREO_DFT_RESPRED_ESF ) ) );
     190             :     }
     191             : 
     192        5430 :     return;
     193             : }
     194             : 
     195             : /*-------------------------------------------------------------------------
     196             :  * stereo_dft_band_config()
     197             :  *
     198             :  * Stereo DFT bands condfiguration
     199             :  *------------------------------------------------------------------------*/
     200             : 
     201       63738 : Word16 stereo_dft_band_config_fx(
     202             :     Word16 *band_limits,   /* o  : DFT band limits                     */
     203             :     const Word16 band_res, /* i  : DFT band resolution                 */
     204             :     const Word16 NFFT,     /* i  : analysis/synthesis window length    */
     205             :     const Word16 enc_dec   /* i  : flag to indicate enc vs dec         */
     206             : )
     207             : {
     208             :     Word16 nbands;
     209             : 
     210             :     /*sanity check*/
     211       63738 :     assert( ( EQ_16( band_res, 1 ) || ( band_res == 0 ) || EQ_16( band_res, 2 ) ) && "stereo DFT: Parameter band resolution not supported!\n" );
     212             : 
     213       63738 :     band_limits[0] = 1;
     214       63738 :     move16();
     215       63738 :     nbands = 0;
     216       63738 :     move16();
     217      611212 :     WHILE( LT_16( band_limits[nbands], NFFT / 2 ) )
     218             :     {
     219      547474 :         nbands++;
     220      547474 :         IF( band_res == 0 )
     221             :         {
     222           0 :             assert( 0 && "stereo DFT: band config failed!\n" );
     223             :         }
     224      547474 :         ELSE IF( EQ_16( band_res, 1 ) )
     225             :         {
     226      356880 :             IF( enc_dec == ENC /*0*/ )
     227             :             {
     228           0 :                 band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); // Q0
     229           0 :                 move16();
     230             :             }
     231             :             ELSE
     232             :             {
     233      356880 :                 band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); // Q0
     234      356880 :                 move16();
     235             :             }
     236             : 
     237      356880 :             assert( ( LT_16( nbands, STEREO_DFT_ERB4_BANDS ) ) && "stereo DFT: band config failed!\n" );
     238             :         }
     239             :         ELSE
     240             :         {
     241      190594 :             IF( enc_dec == ENC )
     242             :             {
     243           0 :                 band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); // Q0
     244           0 :                 move16();
     245             :             }
     246             :             ELSE
     247             :             {
     248      190594 :                 band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); // Q0
     249      190594 :                 move16();
     250             :             }
     251             : 
     252      190594 :             assert( ( LT_16( nbands, STEREO_DFT_ERB8_BANDS ) ) && "stereo DFT: band config failed!\n" );
     253             :         }
     254             :     }
     255             : 
     256       63738 :     band_limits[nbands] = NFFT / 2; /*Nyquist Freq*/
     257       63738 :     move16();
     258             : 
     259       63738 :     return ( nbands );
     260             : }

Generated by: LCOV version 1.14