LCOV - code coverage report
Current view: top level - lib_com - ivas_filters.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 43 45 95.6 %
Date: 2025-05-23 08:37:30 Functions: 3 3 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 <stdint.h>
      34             : #include "options.h"
      35             : #ifdef DEBUGGING
      36             : #include "debug.h"
      37             : #endif
      38             : #include "ivas_prot.h"
      39             : #include "ivas_cnst.h"
      40             : #include "ivas_stat_com.h"
      41             : #include "wmc_auto.h"
      42             : 
      43             : 
      44             : /*------------------------------------------------------------------------------------------*
      45             :  * Local functions declaration
      46             :  *------------------------------------------------------------------------------------------*/
      47             : 
      48             : static void ivas_iir_2_filter( ivas_filters_process_state_t *filter_state, float *pIn_Out, const int16_t length, const int16_t stage );
      49             : 
      50             : 
      51             : /*-----------------------------------------------------------------------------------------*
      52             :  * Function ivas_filters_init()
      53             :  *
      54             :  * Initialisation call for filtering a signal
      55             :  *-----------------------------------------------------------------------------------------*/
      56             : 
      57       16261 : void ivas_filters_init(
      58             :     ivas_filters_process_state_t *filter_state, /* i/o: filter state handle     */
      59             :     const float *filt_coeff,                    /* i  : filter coefficients     */
      60             :     const int16_t order )                       /* i  : filter order            */
      61             : {
      62             :     int16_t i;
      63       16261 :     filter_state->order = order;
      64             : 
      65       16261 :     if ( order == IVAS_FILTER_ORDER_1 )
      66             :     {
      67       15891 :         filter_state->filt_len = order + 1;
      68             : 
      69       63564 :         for ( i = 0; i < IVAS_BIQUAD_FILT_LEN; i++ )
      70             :         {
      71       47673 :             filter_state->num[IVAS_FILTER_STAGE_0][i] = filt_coeff[i];
      72       47673 :             filter_state->den[IVAS_FILTER_STAGE_0][i] = filt_coeff[i + IVAS_BIQUAD_FILT_LEN];
      73             :         }
      74             : 
      75       15891 :         filter_state->state[0][0] = 0.0f;
      76       15891 :         filter_state->state[0][1] = 0.0f;
      77       15891 :         filter_state->state[0][2] = 0.0f;
      78             :     }
      79             :     else
      80             :     {
      81         370 :         filter_state->filt_len = IVAS_BIQUAD_FILT_LEN;
      82             : 
      83        1480 :         for ( i = 0; i < IVAS_BIQUAD_FILT_LEN; i++ )
      84             :         {
      85        1110 :             filter_state->num[IVAS_FILTER_STAGE_0][i] = filt_coeff[i];
      86        1110 :             filter_state->den[IVAS_FILTER_STAGE_0][i] = filt_coeff[i + IVAS_BIQUAD_FILT_LEN];
      87        1110 :             filter_state->num[IVAS_FILTER_STAGE_1][i] = filt_coeff[i + IVAS_BIQUAD_FILT_LEN * 2];
      88        1110 :             filter_state->den[IVAS_FILTER_STAGE_1][i] = filt_coeff[i + IVAS_BIQUAD_FILT_LEN * 3];
      89             :         }
      90             : 
      91         370 :         filter_state->state[0][0] = 0.0f;
      92         370 :         filter_state->state[0][1] = 0.0f;
      93         370 :         filter_state->state[0][2] = 0.0f;
      94         370 :         filter_state->state[1][0] = 0.0f;
      95         370 :         filter_state->state[1][1] = 0.0f;
      96         370 :         filter_state->state[1][2] = 0.0f;
      97             :     }
      98             : 
      99       16261 :     return;
     100             : }
     101             : 
     102             : 
     103             : /*-----------------------------------------------------------------------------------------*
     104             :  * Function ivas_filter_process()
     105             :  *
     106             :  * Process call for selecting the type filter
     107             :  *-----------------------------------------------------------------------------------------*/
     108             : 
     109     1394158 : void ivas_filter_process(
     110             :     ivas_filters_process_state_t *filter_state, /* i/o: filter state handle             */
     111             :     float *pIn_Out,                             /* i/o: signal subject to filtering     */
     112             :     const int16_t length                        /* i  : filter order                    */
     113             : )
     114             : {
     115             : 
     116     1394158 :     switch ( filter_state->order )
     117             :     {
     118     1341804 :         case IVAS_FILTER_ORDER_1:
     119     1341804 :             ivas_iir_2_filter( filter_state, pIn_Out, length, IVAS_FILTER_STAGE_0 );
     120     1341804 :             break;
     121       52354 :         case IVAS_FILTER_ORDER_4:
     122             :             /* biquad-1 */
     123       52354 :             ivas_iir_2_filter( filter_state, pIn_Out, length, IVAS_FILTER_STAGE_0 );
     124             :             /* biquad-2 */
     125       52354 :             ivas_iir_2_filter( filter_state, pIn_Out, length, IVAS_FILTER_STAGE_1 );
     126       52354 :             break;
     127           0 :         default:
     128           0 :             break;
     129             :     }
     130             : 
     131     1394158 :     return;
     132             : }
     133             : 
     134             : 
     135             : /*-----------------------------------------------------------------------------------------*
     136             :  * Function ivas_iir_2_filter()
     137             :  *
     138             :  * Process call for filtering a signal
     139             :  *-----------------------------------------------------------------------------------------*/
     140             : 
     141     1446512 : static void ivas_iir_2_filter(
     142             :     ivas_filters_process_state_t *filter_state,
     143             :     float *pIn_Out,
     144             :     const int16_t length,
     145             :     const int16_t stage )
     146             : {
     147             :     int16_t i, j;
     148     1446512 :     float *pIn = pIn_Out;
     149     1446512 :     float *pOut = pIn_Out;
     150             :     float tmp_pIn_buf_i;
     151             : 
     152  1169430052 :     for ( i = 0; i < length; i++ )
     153             :     {
     154  1167983540 :         tmp_pIn_buf_i = pIn[i];
     155  1167983540 :         pOut[i] = filter_state->state[stage][0] + pIn[i] * filter_state->num[stage][0];
     156             : 
     157  2434733160 :         for ( j = 1; j < filter_state->filt_len; j++ )
     158             :         {
     159  1266749620 :             filter_state->state[stage][j - 1] = filter_state->state[stage][j] + filter_state->num[stage][j] * tmp_pIn_buf_i -
     160  1266749620 :                                                 filter_state->den[stage][j] * pOut[i];
     161             :         }
     162             :     }
     163             : 
     164     1446512 :     return;
     165             : }

Generated by: LCOV version 1.14