LCOV - code coverage report
Current view: top level - lib_rend - ivas_reverb_delay_line_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 4c82f1d24d39d0296b18d775f18a006f4c7d024b Lines: 71 95 74.7 %
Date: 2025-05-17 01:59:02 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_rend_fx.h"
      36             : #include "prot_fx.h"
      37             : #include "wmc_auto.h"
      38             : #include "debug.h"
      39             : /*-----------------------------------------------------------------------------------------*
      40             :  * Function ivas_rev_delay_line_init()
      41             :  *
      42             :  * Initialize the delay line
      43             :  *-----------------------------------------------------------------------------------------*/
      44             : 
      45        1431 : void ivas_rev_delay_line_init(
      46             :     ivas_rev_delay_line_t *pDelay, /* o  : the delay line to initialize                     */
      47             :     Word32 *memory_buffer,         /* i  : the memory buffer to use for the delay line  Q11 */
      48             :     const UWord16 delay,           /* i  : the delay                                        */
      49             :     const UWord16 maxdelay         /* i  : maximum delay to be supported                    */
      50             : )
      51             : {
      52        1431 :     pDelay->MaxDelay = maxdelay;
      53        1431 :     move16();
      54             : 
      55        1431 :     IF( LE_32( delay, pDelay->MaxDelay ) )
      56             :     {
      57        1431 :         pDelay->Delay = delay;
      58             :     }
      59             :     ELSE
      60             :     {
      61           0 :         pDelay->Delay = pDelay->MaxDelay;
      62             :     }
      63        1431 :     move16();
      64             : 
      65        1431 :     pDelay->pBuffer_fx = memory_buffer;
      66        1431 :     move32();
      67        1431 :     set32_fx( pDelay->pBuffer_fx, 0, pDelay->MaxDelay );
      68        1431 :     pDelay->BufferPos = 0;
      69        1431 :     move16();
      70        1431 :     pDelay->Gain_fx = ONE_IN_Q14;
      71        1431 :     move16();
      72             : 
      73        1431 :     return;
      74             : }
      75             : 
      76             : /*-----------------------------------------------------------------------------------------*
      77             :  * Function ivas_rev_delay_line_feed_sample()
      78             :  *
      79             :  * Feed sample into delay line; NOTE: get a sample out of the line before feeding the next
      80             :  *-----------------------------------------------------------------------------------------*/
      81             : 
      82           0 : void ivas_rev_delay_line_feed_sample_fx(
      83             :     ivas_rev_delay_line_t *pDelay, /* i  : the delay line          */
      84             :     Word32 input                   /* i  : the sample to feed  Q11 */
      85             : )
      86             : {
      87           0 :     pDelay->pBuffer_fx[pDelay->BufferPos] = input; // Q11
      88           0 :     pDelay->BufferPos = u_extract_l( UL_addNsD( pDelay->BufferPos, 1 ) );
      89           0 :     move16();
      90             : 
      91           0 :     IF( GE_32( pDelay->BufferPos, pDelay->Delay ) )
      92             :     {
      93           0 :         pDelay->BufferPos = 0;
      94           0 :         move16();
      95             :     }
      96             : 
      97           0 :     return;
      98             : }
      99             : 
     100             : 
     101             : /*-----------------------------------------------------------------------------------------*
     102             :  * Function ivas_rev_delay_line_feed_sample_blk()
     103             :  *
     104             :  * Feed sample block into delay line; NOTE: get samples out of the line before feeding the next block
     105             :  *-----------------------------------------------------------------------------------------*/
     106             : 
     107    10145880 : void ivas_rev_delay_line_feed_sample_blk_fx(
     108             :     ivas_rev_delay_line_t *pDelay, /* i/o: the delay line                                */
     109             :     const UWord16 blk_size,        /* i  : number of samples in the input data block     */
     110             :     Word32 *input                  /* i  : the samples to feed                       Q11 */
     111             : )
     112             : {
     113             :     Word32 *pDst, *pSrc;
     114             :     UWord16 i, pos;
     115             : 
     116    10145880 :     pos = pDelay->BufferPos;
     117    10145880 :     move16();
     118             : 
     119    10145880 :     IF( GT_32( L_add( pos, blk_size ), pDelay->Delay ) ) /* splitting block in 2 if it exceeds buffer end limit */
     120             :     {
     121             :         UWord16 blk_size_1; /* 1st block up to the end of the buffer */
     122             :         UWord16 blk_size_2; /* 2nd block at the beginning of the buffer */
     123             : 
     124     2254220 :         blk_size_1 = (UWord16) L_sub( pDelay->Delay, pos );
     125     2254220 :         move16();
     126     2254220 :         blk_size_2 = (UWord16) L_sub( blk_size, blk_size_1 );
     127     2254220 :         move16();
     128     2254220 :         pDst = &pDelay->pBuffer_fx[pos];
     129    65019168 :         FOR( i = 0; i < blk_size_1; i++ )
     130             :         {
     131    62764948 :             pDst[i] = input[i]; // Q11
     132    62764948 :             move32();
     133             :         }
     134     2254220 :         pDst = &pDelay->pBuffer_fx[0]; // Q11
     135     2254220 :         pSrc = &input[blk_size_1];     // Q11
     136    65054344 :         FOR( i = 0; i < blk_size_2; i++ )
     137             :         {
     138    62800124 :             pDst[i] = pSrc[i]; // Q11
     139    62800124 :             move32();
     140             :         }
     141     2254220 :         pos = blk_size_2;
     142     2254220 :         move16();
     143             :     }
     144             :     ELSE /* copy only 1 data block directly if it fits in the buffer */
     145             :     {
     146     7891660 :         pDst = &pDelay->pBuffer_fx[pos]; // Q11
     147   636569788 :         FOR( i = 0; i < blk_size; i++ )
     148             :         {
     149   628678128 :             pDst[i] = input[i]; // Q11
     150   628678128 :             move32();
     151             :         }
     152     7891660 :         pos = (UWord16) L_add( pos, blk_size );
     153     7891660 :         move16();
     154             :     }
     155    10145880 :     pDelay->BufferPos = pos;
     156    10145880 :     move16();
     157             : 
     158    10145880 :     IF( GE_32( pDelay->BufferPos, pDelay->Delay ) )
     159             :     {
     160       73245 :         pDelay->BufferPos = 0;
     161       73245 :         move16();
     162             :     }
     163             : 
     164    10145880 :     return;
     165             : }
     166             : /*-----------------------------------------------------------------------------------------*
     167             :  * Function ivas_rev_delay_line_get_sample()
     168             :  *
     169             :  * Get sample out of delay line, amplified by set gain
     170             :  * NOTE: get a sample out of the line before feeding the next
     171             :  *-----------------------------------------------------------------------------------------*/
     172             : 
     173             : /*! r: sample gotten out of delay line, and amplified by set gain */
     174           0 : Word32 ivas_rev_delay_line_get_sample_fx(                               /* Q11 */
     175             :                                           ivas_rev_delay_line_t *pDelay /* i/o: the delay line    */
     176             : )
     177             : {
     178           0 :     IF( EQ_16( pDelay->Gain_fx, ONE_IN_Q14 ) )
     179             :     {
     180             : 
     181           0 :         return pDelay->pBuffer_fx[pDelay->BufferPos];
     182             :     }
     183             :     ELSE
     184             :     {
     185             : 
     186           0 :         return ( L_shl( Mpy_32_16_r( pDelay->pBuffer_fx[pDelay->BufferPos], pDelay->Gain_fx ), 1 ) ); // Q11 + Q14 - 15 + 1 = Q11
     187             :     }
     188             : }
     189             : /*-----------------------------------------------------------------------------------------*
     190             :  * Function ivas_rev_delay_line_get_sample_blk()
     191             :  *
     192             :  * Get a block samples out of delay line, amplified by set gain
     193             :  *-----------------------------------------------------------------------------------------*/
     194             : 
     195    10145880 : void ivas_rev_delay_line_get_sample_blk_fx(
     196             :     ivas_rev_delay_line_t *pDelay, /* i  : the delay line                                                     */
     197             :     const UWord16 blk_size,        /* i  : number of samples in the data block                                */
     198             :     Word32 *output                 /* i/o: amples gotten out of delay line, and amplified by set gainin   Q11 */
     199             : )
     200             : {
     201             :     Word32 *pDst, *pSrc;
     202             :     UWord16 i, pos;
     203             :     Word16 gain;
     204             : 
     205    10145880 :     pos = (UWord16) pDelay->BufferPos;
     206    10145880 :     gain = pDelay->Gain_fx;
     207    10145880 :     move16();
     208    10145880 :     move16();
     209             : 
     210    10145880 :     IF( GT_32( L_add( pos, blk_size ), pDelay->Delay ) ) /* splitting block in 2 if it exceeds buffer end limit */
     211             :     {
     212             :         UWord16 blk_size_1; /* 1st block up to the end of the buffer */
     213             :         UWord16 blk_size_2; /* 2nd block at the beginning of the buffer */
     214             : 
     215     2254220 :         blk_size_1 = (UWord16) L_sub( pDelay->Delay, pos );
     216     2254220 :         move16();
     217     2254220 :         blk_size_2 = (UWord16) L_sub( blk_size, blk_size_1 );
     218     2254220 :         move16();
     219     2254220 :         pSrc = &pDelay->pBuffer_fx[pos]; // Q11
     220     2254220 :         IF( EQ_16( gain, ONE_IN_Q14 ) )
     221             :         {
     222    65019168 :             FOR( i = 0; i < blk_size_1; i++ )
     223             :             {
     224    62764948 :                 output[i] = pSrc[i]; // Q11
     225    62764948 :                 move32();
     226             :             }
     227     2254220 :             pSrc = &pDelay->pBuffer_fx[0]; // Q11
     228     2254220 :             pDst = &output[blk_size_1];    // Q11
     229    65054344 :             FOR( i = 0; i < blk_size_2; i++ )
     230             :             {
     231    62800124 :                 pDst[i] = pSrc[i];
     232    62800124 :                 move32();
     233             :             }
     234             :         }
     235             :         ELSE
     236             :         {
     237           0 :             FOR( i = 0; i < blk_size_1; i++ )
     238             :             {
     239           0 :                 output[i] = L_shl( Mpy_32_16_r( pSrc[i], gain ), 1 ); // Q11 + Q14 - 15 + 1 = Q11
     240           0 :                 move32();
     241             :             }
     242           0 :             pSrc = &pDelay->pBuffer_fx[0];
     243           0 :             pDst = &output[blk_size_1];
     244           0 :             FOR( i = 0; i < blk_size_2; i++ )
     245             :             {
     246           0 :                 pDst[i] = L_shl( Mpy_32_16_r( pSrc[i], gain ), 1 ); // Q11 + Q14 - 15 + 1 = Q11
     247           0 :                 move32();
     248             :             }
     249             :         }
     250             :     }
     251             :     ELSE /* copy only 1 data block directly if it fits in the buffer */
     252             :     {
     253     7891660 :         pSrc = &pDelay->pBuffer_fx[pos];
     254             : 
     255     7891660 :         IF( EQ_16( gain, ONE_IN_Q14 ) )
     256             :         {
     257   636569788 :             FOR( i = 0; i < blk_size; i++ )
     258             :             {
     259   628678128 :                 output[i] = pSrc[i]; // Q11
     260   628678128 :                 move32();
     261             :             }
     262             :         }
     263             :         ELSE
     264             :         {
     265           0 :             FOR( i = 0; i < blk_size; i++ )
     266             :             {
     267           0 :                 output[i] = L_shl( Mpy_32_16_r( pSrc[i], gain ), 1 ); // Q11 + Q14 - 15 + 1 = Q11
     268           0 :                 move32();
     269             :             }
     270             :         }
     271             :     }
     272             : 
     273    10145880 :     return;
     274             : }

Generated by: LCOV version 1.14