LCOV - code coverage report
Current view: top level - lib_rend - ivas_dirac_onsets_dec_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 48 52 92.3 %
Date: 2025-05-03 01:55:50 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 "cnst.h"
      37             : #include "prot_fx.h"
      38             : #include "ivas_prot_rend_fx.h"
      39             : #include "ivas_cnst.h"
      40             : #include "ivas_rom_com.h"
      41             : #include "ivas_rom_dec.h"
      42             : #include "wmc_auto.h"
      43             : 
      44             : /*-------------------------------------------------------------------------
      45             :  * ivas_dirac_dec_onset_detection_open()
      46             :  *
      47             :  * onset detection
      48             :  *------------------------------------------------------------------------*/
      49             : 
      50        3158 : ivas_error ivas_dirac_dec_onset_detection_open_fx(
      51             :     const Word16 num_protos_diff, // Q0
      52             :     const Word16 num_freq_bands,  // Q0
      53             :     const Word16 max_band_decorr, // Q0
      54             :     DIRAC_ONSET_DETECTION_PARAMS *ph_dirac_onset_detection_params,
      55             :     DIRAC_ONSET_DETECTION_STATE *ph_dirac_onset_detection_state )
      56             : {
      57             :     /* pointers to structs for allocation */
      58        3158 :     DIRAC_ONSET_DETECTION_PARAMS *dirac_onset_detection_params = ph_dirac_onset_detection_params;
      59        3158 :     DIRAC_ONSET_DETECTION_STATE *dirac_onset_detection_state = ph_dirac_onset_detection_state;
      60             : 
      61             :     /* check / set input parameters */
      62        3158 :     dirac_onset_detection_params->num_freq_bands = num_freq_bands;
      63        3158 :     move16();
      64        3158 :     assert( dirac_onset_detection_params->num_freq_bands > 0 && "Error: Number of frequency bands <= 0!" );
      65             : 
      66        3158 :     dirac_onset_detection_params->max_band_decorr = max_band_decorr;
      67        3158 :     move16();
      68             : 
      69             :     /* memory allocation */
      70             : 
      71        3158 :     IF( ( dirac_onset_detection_state->onset_detector_1_fx = (Word32 *) malloc( sizeof( Word32 ) * imult1616( num_protos_diff, dirac_onset_detection_params->max_band_decorr ) ) ) == NULL )
      72             :     {
      73           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for onset detection\n" ) );
      74             :     }
      75        3158 :     IF( ( dirac_onset_detection_state->onset_detector_2_fx = (Word32 *) malloc( sizeof( Word32 ) * imult1616( num_protos_diff, dirac_onset_detection_params->max_band_decorr ) ) ) == NULL )
      76             :     {
      77           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for onset detection\n" ) );
      78             :     }
      79             :     /* init to zero */
      80        3158 :     set32_fx( dirac_onset_detection_state->onset_detector_1_fx, 0, imult1616( num_protos_diff, dirac_onset_detection_params->max_band_decorr ) );
      81        3158 :     set32_fx( dirac_onset_detection_state->onset_detector_2_fx, 0, imult1616( num_protos_diff, dirac_onset_detection_params->max_band_decorr ) );
      82        3158 :     dirac_onset_detection_state->q_onset_detector = Q31; // Q31
      83        3158 :     move16();
      84             : 
      85        3158 :     return IVAS_ERR_OK;
      86             : }
      87             : 
      88             : 
      89             : /*-------------------------------------------------------------------------
      90             :  * ivas_dirac_dec_onset_detection_process()
      91             :  *
      92             :  *
      93             :  *------------------------------------------------------------------------*/
      94             : 
      95     1855338 : void ivas_dirac_dec_onset_detection_process_fx(
      96             :     const Word32 *input_power_f, // Qx
      97             :     Word32 *onset_filter,        // Qx
      98             :     const Word16 num_protos_diff,
      99             :     DIRAC_ONSET_DETECTION_PARAMS h_dirac_onset_detection_params,
     100             :     DIRAC_ONSET_DETECTION_STATE h_dirac_onset_detection_state )
     101             : {
     102             : 
     103             :     Word16 b, ch_idx;
     104             :     Word16 tmp_fx;
     105             :     Word32 tmp32_fx;
     106             :     Word32 *p_onset_detector_1_fx, *p_onset_detector_2_fx;
     107             :     Word16 e_scale;
     108             : 
     109     1855338 :     p_onset_detector_1_fx = h_dirac_onset_detection_state.onset_detector_1_fx; /* Q(q_onset_detector) */
     110     1855338 :     p_onset_detector_2_fx = h_dirac_onset_detection_state.onset_detector_2_fx; /* Q(q_onset_detector) */
     111             : 
     112     4833002 :     FOR( ch_idx = 0; ch_idx < num_protos_diff; ch_idx++ )
     113             :     {
     114    83096964 :         FOR( b = 0; b < h_dirac_onset_detection_params.max_band_decorr; b++ )
     115             :         {
     116             :             /*detector 1: envelope max*/
     117    80119300 :             *p_onset_detector_1_fx = Mpy_32_16_1( *p_onset_detector_1_fx, DIRAC_ONSET_ALPHA_FX ); /* Q(q_onset_detector) */
     118    80119300 :             move32();
     119    80119300 :             IF( GT_32( *p_onset_detector_1_fx, *input_power_f ) )
     120             :             {
     121    44009481 :                 *p_onset_detector_1_fx = *p_onset_detector_1_fx;
     122    44009481 :                 move32();
     123             :             }
     124             :             ELSE
     125             :             {
     126    36109819 :                 *p_onset_detector_1_fx = *input_power_f;
     127    36109819 :                 move32();
     128             :             }
     129             : 
     130             :             /*detector 2: envelope min*/
     131    80119300 :             *p_onset_detector_2_fx = L_add( Mpy_32_16_1( *p_onset_detector_2_fx, DIRAC_ONSET_BETA_FX ), Mpy_32_16_1( *p_onset_detector_1_fx, ONE_DIRAC_ONSET_BETA_FX ) ); /* Q(q_onset_detector) */
     132    80119300 :             move32();
     133    80119300 :             IF( LT_32( *p_onset_detector_2_fx, *p_onset_detector_1_fx ) )
     134             :             {
     135    45869464 :                 *p_onset_detector_2_fx = *p_onset_detector_2_fx; /* Q(q_onset_detector) */
     136    45869464 :                 move32();
     137             :             }
     138             :             ELSE
     139             :             {
     140    34249836 :                 *p_onset_detector_2_fx = *p_onset_detector_1_fx; /* Q(q_onset_detector) */
     141    34249836 :                 move32();
     142             :             }
     143             : 
     144    80119300 :             if ( *p_onset_detector_1_fx == 0 )
     145             :             {
     146             : 
     147    26197399 :                 *p_onset_detector_1_fx = EPSILON_FX; /* Q(q_onset_detector) */
     148    26197399 :                 move32();
     149             :             }
     150             :             /*onset filter limited between 0 and 1*/
     151    80119300 :             tmp_fx = BASOP_Util_Divide3232_Scale( *p_onset_detector_2_fx, *p_onset_detector_1_fx, &e_scale );
     152    80119300 :             tmp32_fx = L_mult0( tmp_fx, DIRAC_ONSET_GAIN_FX ); // Q= Q12 + (15-e_scale)
     153    80119300 :             if ( tmp32_fx < 0 )
     154             :             {
     155           0 :                 tmp32_fx = 0;
     156           0 :                 move32();
     157             :             }
     158    80119300 :             tmp32_fx = L_shl_sat( tmp32_fx, add( e_scale, 4 ) );
     159             : 
     160    80119300 :             onset_filter[b] = tmp32_fx;
     161    80119300 :             move32();
     162             : 
     163    80119300 :             input_power_f++;
     164    80119300 :             p_onset_detector_1_fx++;
     165    80119300 :             p_onset_detector_2_fx++;
     166             :         }
     167             : 
     168     2977664 :         onset_filter += h_dirac_onset_detection_params.num_freq_bands;
     169             :     }
     170             : 
     171     1855338 :     return;
     172             : }

Generated by: LCOV version 1.14