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 : /*====================================================================================
34 : EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
35 : ====================================================================================*/
36 :
37 : /*! @file jbm_pcmdsp_similarityestimation.c Algorithms for correlation and similarity estimation. */
38 :
39 : /* system headers */
40 : #include <stdlib.h>
41 : #include <math.h>
42 : #include <stdint.h>
43 : #include "options.h"
44 : #ifdef DEBUGGING
45 : #include "debug.h"
46 : #endif
47 : #include "wmc_auto.h"
48 :
49 : /* local headers */
50 : #include "jbm_pcmdsp_similarityestimation.h"
51 :
52 :
53 : /* Calculates cross correlation coefficient for template segment. */
54 0 : float cross_correlation_self(
55 : const float *signal,
56 : uint16_t x,
57 : uint16_t y,
58 : uint16_t corr_len )
59 : {
60 : float c_c;
61 : int16_t j;
62 :
63 0 : c_c = 0.0f;
64 0 : for ( j = 0; j < corr_len; j++ )
65 : {
66 0 : c_c += ( signal[j + x] * signal[j + y] );
67 : }
68 :
69 0 : return c_c;
70 : }
71 :
72 : /* Calculates cross correlation coefficient for template segment. */
73 309960 : float cross_correlation_subsampled_self(
74 : const float *signal,
75 : uint16_t x,
76 : uint16_t y,
77 : uint16_t corr_len,
78 : uint16_t subsampling )
79 : {
80 : float c_c;
81 : int16_t j;
82 :
83 309960 : c_c = 0.0f;
84 25106760 : for ( j = 0; j < corr_len; j += subsampling )
85 : {
86 24796800 : c_c += ( signal[j + x] * signal[j + y] );
87 : }
88 :
89 309960 : return c_c;
90 : }
91 :
92 :
93 : /* Calculates normalized cross correlation coefficient for template segment. */
94 13449 : float normalized_cross_correlation_self(
95 : const float *signal,
96 : uint16_t x,
97 : uint16_t y,
98 : uint16_t corr_len,
99 : uint16_t subsampling,
100 : float *energy )
101 : {
102 : float c_c;
103 : float energy_xy, energy_x, energy_y;
104 : uint16_t j;
105 : const float *signal_a, *signal_b;
106 :
107 13449 : c_c = 0.0f;
108 13449 : energy_x = 0.0f;
109 13449 : energy_y = 0.0f;
110 13449 : signal_a = &signal[x];
111 13449 : signal_b = &signal[y];
112 2909289 : for ( j = 0; j < corr_len; j += subsampling )
113 : {
114 2895840 : c_c += ( signal_a[j] * signal_b[j] );
115 2895840 : energy_x += ( signal_a[j] ) * ( signal_a[j] );
116 2895840 : energy_y += ( signal_b[j] ) * ( signal_b[j] );
117 : }
118 13449 : energy_xy = sqrtf( energy_x * energy_y );
119 13449 : if ( energy_xy < 1.0f )
120 : {
121 150 : energy_xy = 1.0f; /* conceal silent frames */
122 : }
123 :
124 13449 : c_c = c_c / energy_xy;
125 13449 : *energy = energy_xy;
126 :
127 13449 : return c_c;
128 : }
129 :
130 :
131 : /* Splits the signal into segments and checks if all of them have very low energy. */
132 1857 : bool isSilence(
133 : const float *signal,
134 : uint32_t len,
135 : uint32_t segments )
136 : {
137 : uint32_t i, samplesPerSegment;
138 : float energy;
139 :
140 1857 : energy = 0;
141 1857 : samplesPerSegment = len / segments;
142 209649 : for ( i = 0; i < len; i++ )
143 : {
144 209649 : energy += ( signal[i] / 32768.f ) * ( signal[i] / 32768.f );
145 209649 : if ( ( i != 0U && i % samplesPerSegment == 0U ) || i + 1 == len )
146 : {
147 : /* check energy of current segment */
148 1875 : energy = 10 * log10f( energy / (float) samplesPerSegment );
149 1875 : if ( energy > -65 )
150 : {
151 1857 : return false;
152 : }
153 18 : energy = 0;
154 : }
155 : }
156 :
157 0 : return true;
158 : }
|