LCOV - code coverage report
Current view: top level - lib_rend - ivas_dirac_onsets_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 29 31 93.5 %
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 "cnst.h"
      37             : #include "prot.h"
      38             : #include "ivas_prot.h"
      39             : #include "ivas_prot_rend.h"
      40             : #include "ivas_cnst.h"
      41             : #include "ivas_rom_com.h"
      42             : #include "ivas_rom_dec.h"
      43             : #ifdef DEBUGGING
      44             : #include "debug.h"
      45             : #endif
      46             : #include "wmc_auto.h"
      47             : 
      48             : 
      49             : /*-------------------------------------------------------------------------
      50             :  * ivas_dirac_dec_onset_detection_open()
      51             :  *
      52             :  * onset detection
      53             :  *------------------------------------------------------------------------*/
      54             : 
      55       10291 : ivas_error ivas_dirac_dec_onset_detection_open(
      56             :     const int16_t num_protos_diff,
      57             :     const int16_t num_freq_bands,
      58             :     const int16_t max_band_decorr,
      59             :     DIRAC_ONSET_DETECTION_PARAMS *ph_dirac_onset_detection_params,
      60             :     DIRAC_ONSET_DETECTION_STATE *ph_dirac_onset_detection_state )
      61             : {
      62             :     /* pointers to structs for allocation */
      63       10291 :     DIRAC_ONSET_DETECTION_PARAMS *dirac_onset_detection_params = ph_dirac_onset_detection_params;
      64       10291 :     DIRAC_ONSET_DETECTION_STATE *dirac_onset_detection_state = ph_dirac_onset_detection_state;
      65             : 
      66             :     /* check / set input parameters */
      67       10291 :     dirac_onset_detection_params->num_freq_bands = num_freq_bands;
      68       10291 :     assert( dirac_onset_detection_params->num_freq_bands > 0 && "Error: Number of frequency bands <= 0!" );
      69             : 
      70       10291 :     dirac_onset_detection_params->max_band_decorr = max_band_decorr;
      71             : 
      72             :     /* memory allocation */
      73       10291 :     if ( ( dirac_onset_detection_state->onset_detector_1 = (float *) malloc( sizeof( float ) * num_protos_diff * dirac_onset_detection_params->max_band_decorr ) ) == NULL )
      74             :     {
      75           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for onset detection\n" ) );
      76             :     }
      77       10291 :     if ( ( dirac_onset_detection_state->onset_detector_2 = (float *) malloc( sizeof( float ) * num_protos_diff * dirac_onset_detection_params->max_band_decorr ) ) == NULL )
      78             :     {
      79           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for onset detection\n" ) );
      80             :     }
      81             : 
      82             :     /* init to zero */
      83       10291 :     set_zero( dirac_onset_detection_state->onset_detector_1, num_protos_diff * dirac_onset_detection_params->max_band_decorr );
      84       10291 :     set_zero( dirac_onset_detection_state->onset_detector_2, num_protos_diff * dirac_onset_detection_params->max_band_decorr );
      85             : 
      86       10291 :     return IVAS_ERR_OK;
      87             : }
      88             : 
      89             : 
      90             : /*-------------------------------------------------------------------------
      91             :  * ivas_dirac_dec_onset_detection_process()
      92             :  *
      93             :  *
      94             :  *------------------------------------------------------------------------*/
      95             : 
      96     5827593 : void ivas_dirac_dec_onset_detection_process(
      97             :     const float *input_power_f,
      98             :     float *onset_filter,
      99             :     const int16_t num_protos_diff,
     100             :     DIRAC_ONSET_DETECTION_PARAMS h_dirac_onset_detection_params,
     101             :     DIRAC_ONSET_DETECTION_STATE h_dirac_onset_detection_state )
     102             : {
     103             :     int16_t b, ch_idx;
     104             :     float tmp_f;
     105             :     float *p_onset_detector_1, *p_onset_detector_2;
     106             : 
     107     5827593 :     p_onset_detector_1 = h_dirac_onset_detection_state.onset_detector_1;
     108     5827593 :     p_onset_detector_2 = h_dirac_onset_detection_state.onset_detector_2;
     109             : 
     110    15133308 :     for ( ch_idx = 0; ch_idx < num_protos_diff; ch_idx++ )
     111             :     {
     112   266094180 :         for ( b = 0; b < h_dirac_onset_detection_params.max_band_decorr; b++ )
     113             :         {
     114             :             /*detector 1: envelope max*/
     115   256788465 :             *p_onset_detector_1 *= DIRAC_ONSET_ALPHA;
     116   256788465 :             *p_onset_detector_1 = ( *p_onset_detector_1 > *input_power_f ) ? *p_onset_detector_1 : *input_power_f;
     117             : 
     118             :             /*detector 2: envelope min*/
     119   256788465 :             *p_onset_detector_2 = DIRAC_ONSET_BETA * *p_onset_detector_2 + ( 1.f - DIRAC_ONSET_BETA ) * *p_onset_detector_1;
     120   256788465 :             *p_onset_detector_2 = ( *p_onset_detector_2 < *p_onset_detector_1 ) ? *p_onset_detector_2 : *p_onset_detector_1;
     121             : 
     122             :             /*onset filter limited between 0 and 1*/
     123   256788465 :             tmp_f = ( DIRAC_ONSET_GAIN * *p_onset_detector_2 ) / ( *p_onset_detector_1 + EPSILON );
     124   256788465 :             tmp_f = ( tmp_f < 0.f ) ? 0.f : tmp_f;
     125   256788465 :             tmp_f = ( tmp_f > 1.f ) ? 1.f : tmp_f;
     126   256788465 :             onset_filter[b] = tmp_f;
     127             : 
     128   256788465 :             input_power_f++;
     129   256788465 :             p_onset_detector_1++;
     130   256788465 :             p_onset_detector_2++;
     131             :         }
     132             : 
     133     9305715 :         onset_filter += h_dirac_onset_detection_params.num_freq_bands;
     134             :     }
     135             : 
     136     5827593 :     return;
     137             : }

Generated by: LCOV version 1.14