LCOV - code coverage report
Current view: top level - lib_rend - ivas_reverb_delay_line.c (source / functions) Hit Total Coverage
Test: Coverage on main @ fec202a8f89be4a2f278a9fc377bfb58b58fab11 Lines: 49 67 73.1 %
Date: 2025-09-11 08:49:05 Functions: 3 5 60.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             : #include "ivas_prot.h"
      36             : #include "ivas_prot_rend.h"
      37             : #include "prot.h"
      38             : #ifdef DEBUGGING
      39             : #include "debug.h"
      40             : #endif
      41             : #include "wmc_auto.h"
      42             : 
      43             : 
      44             : /*-----------------------------------------------------------------------------------------*
      45             :  * Function ivas_rev_delay_line_init()
      46             :  *
      47             :  * Initialize the delay line
      48             :  *-----------------------------------------------------------------------------------------*/
      49             : 
      50       52236 : void ivas_rev_delay_line_init(
      51             :     ivas_rev_delay_line_t *pDelay, /* o  : the delay line to initialize                 */
      52             :     float *memory_buffer,          /* i  : the memory buffer to use for the delay line  */
      53             :     const uint16_t delay,          /* i  : the delay                                    */
      54             :     const uint16_t maxdelay        /* i  : maximum delay to be supported                */
      55             : )
      56             : {
      57       52236 :     pDelay->MaxDelay = maxdelay;
      58             : 
      59       52236 :     if ( delay <= pDelay->MaxDelay )
      60             :     {
      61       52236 :         pDelay->Delay = delay;
      62             :     }
      63             :     else
      64             :     {
      65           0 :         pDelay->Delay = pDelay->MaxDelay;
      66             :     }
      67             : 
      68       52236 :     pDelay->pBuffer = memory_buffer;
      69       52236 :     set_f( pDelay->pBuffer, 0, pDelay->MaxDelay );
      70       52236 :     pDelay->BufferPos = 0;
      71       52236 :     pDelay->Gain = 1.0f;
      72             : 
      73       52236 :     return;
      74             : }
      75             : 
      76             : 
      77             : /*-----------------------------------------------------------------------------------------*
      78             :  * Function ivas_rev_delay_line_feed_sample()
      79             :  *
      80             :  * Feed sample into delay line; NOTE: get a sample out of the line before feeding the next
      81             :  *-----------------------------------------------------------------------------------------*/
      82             : 
      83           0 : void ivas_rev_delay_line_feed_sample(
      84             :     ivas_rev_delay_line_t *pDelay, /* i  : the delay line       */
      85             :     float input                    /* i  : the sample to feed   */
      86             : )
      87             : {
      88           0 :     pDelay->pBuffer[pDelay->BufferPos++] = input;
      89             : 
      90           0 :     if ( pDelay->BufferPos >= pDelay->Delay )
      91             :     {
      92           0 :         pDelay->BufferPos = 0;
      93             :     }
      94             : 
      95           0 :     return;
      96             : }
      97             : 
      98             : 
      99             : /*-----------------------------------------------------------------------------------------*
     100             :  * Function ivas_rev_delay_line_feed_sample_blk()
     101             :  *
     102             :  * Feed sample block into delay line; NOTE: get samples out of the line before feeding the next block
     103             :  *-----------------------------------------------------------------------------------------*/
     104             : 
     105   168563149 : void ivas_rev_delay_line_feed_sample_blk(
     106             :     ivas_rev_delay_line_t *pDelay, /* i/o: the delay line                            */
     107             :     const uint16_t blk_size,       /* i  : number of samples in the input data block */
     108             :     float *input                   /* i  : the samples to feed                       */
     109             : )
     110             : {
     111             :     float *pDst, *pSrc;
     112             :     uint16_t i, pos;
     113             : 
     114   168563149 :     pos = (uint16_t) pDelay->BufferPos;
     115             : 
     116   168563149 :     if ( pos + blk_size > (uint16_t) pDelay->Delay ) /* splitting block in 2 if it exceeds buffer end limit */
     117             :     {
     118             :         uint16_t blk_size_1; /* 1st block up to the end of the buffer */
     119             :         uint16_t blk_size_2; /* 2nd block at the beginning of the buffer */
     120             : 
     121    48436983 :         blk_size_1 = (uint16_t) pDelay->Delay - pos;
     122    48436983 :         blk_size_2 = blk_size - blk_size_1;
     123    48436983 :         pDst = &pDelay->pBuffer[pos];
     124  1151133754 :         for ( i = 0; i < blk_size_1; i++ )
     125             :         {
     126  1102696771 :             pDst[i] = input[i];
     127             :         }
     128    48436983 :         pDst = &pDelay->pBuffer[0];
     129    48436983 :         pSrc = &input[blk_size_1];
     130  1149223396 :         for ( i = 0; i < blk_size_2; i++ )
     131             :         {
     132  1100786413 :             pDst[i] = pSrc[i];
     133             :         }
     134    48436983 :         pos = blk_size_2;
     135             :     }
     136             :     else /* copy only 1 data block directly if it fits in the buffer */
     137             :     {
     138   120126166 :         pDst = &pDelay->pBuffer[pos];
     139  9582368102 :         for ( i = 0; i < blk_size; i++ )
     140             :         {
     141  9462241936 :             pDst[i] = input[i];
     142             :         }
     143   120126166 :         pos += blk_size;
     144             :     }
     145   168563149 :     pDelay->BufferPos = pos;
     146             : 
     147   168563149 :     if ( pDelay->BufferPos >= pDelay->Delay )
     148             :     {
     149     2377572 :         pDelay->BufferPos = 0;
     150             :     }
     151             : 
     152   168563149 :     return;
     153             : }
     154             : 
     155             : 
     156             : /*-----------------------------------------------------------------------------------------*
     157             :  * Function ivas_rev_delay_line_get_sample()
     158             :  *
     159             :  * Get sample out of delay line, amplified by set gain
     160             :  * NOTE: get a sample out of the line before feeding the next
     161             :  *-----------------------------------------------------------------------------------------*/
     162             : 
     163             : /*! r: sample gotten out of delay line, and amplified by set gain */
     164           0 : float ivas_rev_delay_line_get_sample(
     165             :     ivas_rev_delay_line_t *pDelay /* i/o: the delay line    */
     166             : )
     167             : {
     168           0 :     if ( pDelay->Gain == 1.0f )
     169             :     {
     170             : 
     171           0 :         return pDelay->pBuffer[pDelay->BufferPos];
     172             :     }
     173             :     else
     174             :     {
     175             : 
     176           0 :         return pDelay->Gain * pDelay->pBuffer[pDelay->BufferPos];
     177             :     }
     178             : }
     179             : 
     180             : 
     181             : /*-----------------------------------------------------------------------------------------*
     182             :  * Function ivas_rev_delay_line_get_sample_blk()
     183             :  *
     184             :  * Get a block samples out of delay line, amplified by set gain
     185             :  *-----------------------------------------------------------------------------------------*/
     186             : 
     187   168563149 : void ivas_rev_delay_line_get_sample_blk(
     188             :     ivas_rev_delay_line_t *pDelay, /* i  : the delay line                                               */
     189             :     const uint16_t blk_size,       /* i  : number of samples in the data block                          */
     190             :     float *output                  /* i/o: amples gotten out of delay line, and amplified by set gainin */
     191             : )
     192             : {
     193             :     float *pDst, *pSrc;
     194             :     uint16_t i, pos;
     195             :     float gain;
     196             : 
     197   168563149 :     pos = (uint16_t) pDelay->BufferPos;
     198   168563149 :     gain = pDelay->Gain;
     199             : 
     200   168563149 :     if ( pos + blk_size > (uint16_t) pDelay->Delay ) /* splitting block in 2 if it exceeds buffer end limit */
     201             :     {
     202             :         uint16_t blk_size_1; /* 1st block up to the end of the buffer */
     203             :         uint16_t blk_size_2; /* 2nd block at the beginning of the buffer */
     204             : 
     205    48436983 :         blk_size_1 = (uint16_t) pDelay->Delay - pos;
     206    48436983 :         blk_size_2 = blk_size - blk_size_1;
     207    48436983 :         pSrc = &pDelay->pBuffer[pos];
     208    48436983 :         if ( gain == 1.0f )
     209             :         {
     210  1151133754 :             for ( i = 0; i < blk_size_1; i++ )
     211             :             {
     212  1102696771 :                 output[i] = pSrc[i];
     213             :             }
     214    48436983 :             pSrc = &pDelay->pBuffer[0];
     215    48436983 :             pDst = &output[blk_size_1];
     216  1149223396 :             for ( i = 0; i < blk_size_2; i++ )
     217             :             {
     218  1100786413 :                 pDst[i] = pSrc[i];
     219             :             }
     220             :         }
     221             :         else
     222             :         {
     223           0 :             for ( i = 0; i < blk_size_1; i++ )
     224             :             {
     225           0 :                 output[i] = gain * pSrc[i];
     226             :             }
     227           0 :             pSrc = &pDelay->pBuffer[0];
     228           0 :             pDst = &output[blk_size_1];
     229           0 :             for ( i = 0; i < blk_size_2; i++ )
     230             :             {
     231           0 :                 pDst[i] = gain * pSrc[i];
     232             :             }
     233             :         }
     234             :     }
     235             :     else /* copy only 1 data block directly if it fits in the buffer */
     236             :     {
     237   120126166 :         pSrc = &pDelay->pBuffer[pos];
     238             : 
     239   120126166 :         if ( gain == 1.0f )
     240             :         {
     241  9582368102 :             for ( i = 0; i < blk_size; i++ )
     242             :             {
     243  9462241936 :                 output[i] = pSrc[i];
     244             :             }
     245             :         }
     246             :         else
     247             :         {
     248           0 :             for ( i = 0; i < blk_size; i++ )
     249             :             {
     250           0 :                 output[i] = gain * pSrc[i];
     251             :             }
     252             :         }
     253             :     }
     254             : 
     255   168563149 :     return;
     256             : }

Generated by: LCOV version 1.14