2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
13 * This header file includes all of the fix point signal processing library (SPL) function
14 * descriptions and declarations.
15 * For specific function calls, see bottom of file.
18 #ifndef WEBRTC_SPL_SIGNAL_PROCESSING_LIBRARY_H_
19 #define WEBRTC_SPL_SIGNAL_PROCESSING_LIBRARY_H_
22 #include "webrtc/typedefs.h"
24 // Macros specific for the fixed point implementation
25 #define WEBRTC_SPL_WORD16_MAX 32767
26 #define WEBRTC_SPL_WORD16_MIN -32768
27 #define WEBRTC_SPL_WORD32_MAX (int32_t)0x7fffffff
28 #define WEBRTC_SPL_WORD32_MIN (int32_t)0x80000000
29 #define WEBRTC_SPL_MAX_LPC_ORDER 14
30 #define WEBRTC_SPL_MAX_SEED_USED 0x80000000L
31 #define WEBRTC_SPL_MIN(A, B) (A < B ? A : B) // Get min value
32 #define WEBRTC_SPL_MAX(A, B) (A > B ? A : B) // Get max value
33 // TODO(kma/bjorn): For the next two macros, investigate how to correct the code
34 // for inputs of a = WEBRTC_SPL_WORD16_MIN or WEBRTC_SPL_WORD32_MIN.
35 #define WEBRTC_SPL_ABS_W16(a) \
36 (((int16_t)a >= 0) ? ((int16_t)a) : -((int16_t)a))
37 #define WEBRTC_SPL_ABS_W32(a) \
38 (((int32_t)a >= 0) ? ((int32_t)a) : -((int32_t)a))
40 #ifdef WEBRTC_ARCH_LITTLE_ENDIAN
41 #define WEBRTC_SPL_GET_BYTE(a, nr) (((int8_t *)a)[nr])
42 #define WEBRTC_SPL_SET_BYTE(d_ptr, val, index) \
43 (((int8_t *)d_ptr)[index] = (val))
45 #define WEBRTC_SPL_GET_BYTE(a, nr) \
46 ((((int16_t *)a)[nr >> 1]) >> (((nr + 1) & 0x1) * 8) & 0x00ff)
47 #define WEBRTC_SPL_SET_BYTE(d_ptr, val, index) \
48 ((int16_t *)d_ptr)[index >> 1] = \
49 ((((int16_t *)d_ptr)[index >> 1]) \
50 & (0x00ff << (8 * ((index) & 0x1)))) | (val << (8 * ((index + 1) & 0x1)))
53 #define WEBRTC_SPL_MUL(a, b) \
54 ((int32_t) ((int32_t)(a) * (int32_t)(b)))
55 #define WEBRTC_SPL_UMUL(a, b) \
56 ((uint32_t) ((uint32_t)(a) * (uint32_t)(b)))
57 #define WEBRTC_SPL_UMUL_RSFT16(a, b) \
58 ((uint32_t) ((uint32_t)(a) * (uint32_t)(b)) >> 16)
59 #define WEBRTC_SPL_UMUL_16_16(a, b) \
60 ((uint32_t) (uint16_t)(a) * (uint16_t)(b))
61 #define WEBRTC_SPL_UMUL_16_16_RSFT16(a, b) \
62 (((uint32_t) (uint16_t)(a) * (uint16_t)(b)) >> 16)
63 #define WEBRTC_SPL_UMUL_32_16(a, b) \
64 ((uint32_t) ((uint32_t)(a) * (uint16_t)(b)))
65 #define WEBRTC_SPL_UMUL_32_16_RSFT16(a, b) \
66 ((uint32_t) ((uint32_t)(a) * (uint16_t)(b)) >> 16)
67 #define WEBRTC_SPL_MUL_16_U16(a, b) \
68 ((int32_t)(int16_t)(a) * (uint16_t)(b))
69 #define WEBRTC_SPL_DIV(a, b) \
70 ((int32_t) ((int32_t)(a) / (int32_t)(b)))
71 #define WEBRTC_SPL_UDIV(a, b) \
72 ((uint32_t) ((uint32_t)(a) / (uint32_t)(b)))
74 #ifndef WEBRTC_ARCH_ARM_V7
75 // For ARMv7 platforms, these are inline functions in spl_inl_armv7.h
77 // For MIPS platforms, these are inline functions in spl_inl_mips.h
78 #define WEBRTC_SPL_MUL_16_16(a, b) \
79 ((int32_t) (((int16_t)(a)) * ((int16_t)(b))))
80 #define WEBRTC_SPL_MUL_16_32_RSFT16(a, b) \
81 (WEBRTC_SPL_MUL_16_16(a, b >> 16) \
82 + ((WEBRTC_SPL_MUL_16_16(a, (b & 0xffff) >> 1) + 0x4000) >> 15))
83 #define WEBRTC_SPL_MUL_32_32_RSFT32(a32a, a32b, b32) \
84 ((int32_t)(WEBRTC_SPL_MUL_16_32_RSFT16(a32a, b32) \
85 + (WEBRTC_SPL_MUL_16_32_RSFT16(a32b, b32) >> 16)))
86 #define WEBRTC_SPL_MUL_32_32_RSFT32BI(a32, b32) \
87 ((int32_t)(WEBRTC_SPL_MUL_16_32_RSFT16(( \
88 (int16_t)(a32 >> 16)), b32) + \
89 (WEBRTC_SPL_MUL_16_32_RSFT16(( \
90 (int16_t)((a32 & 0x0000FFFF) >> 1)), b32) >> 15)))
94 #define WEBRTC_SPL_MUL_16_32_RSFT11(a, b) \
95 ((WEBRTC_SPL_MUL_16_16(a, (b) >> 16) << 5) \
96 + (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x0200) >> 10))
97 #define WEBRTC_SPL_MUL_16_32_RSFT14(a, b) \
98 ((WEBRTC_SPL_MUL_16_16(a, (b) >> 16) << 2) \
99 + (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x1000) >> 13))
100 #define WEBRTC_SPL_MUL_16_32_RSFT15(a, b) \
101 ((WEBRTC_SPL_MUL_16_16(a, (b) >> 16) << 1) \
102 + (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x2000) >> 14))
104 #define WEBRTC_SPL_MUL_16_16_RSFT(a, b, c) \
105 (WEBRTC_SPL_MUL_16_16(a, b) >> (c))
107 #define WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(a, b, c) \
108 ((WEBRTC_SPL_MUL_16_16(a, b) + ((int32_t) \
109 (((int32_t)1) << ((c) - 1)))) >> (c))
110 #define WEBRTC_SPL_MUL_16_16_RSFT_WITH_FIXROUND(a, b) \
111 ((WEBRTC_SPL_MUL_16_16(a, b) + ((int32_t) (1 << 14))) >> 15)
113 // C + the 32 most significant bits of A * B
114 #define WEBRTC_SPL_SCALEDIFF32(A, B, C) \
115 (C + (B >> 16) * A + (((uint32_t)(0x0000FFFF & B) * A) >> 16))
117 #define WEBRTC_SPL_ADD_SAT_W32(a, b) WebRtcSpl_AddSatW32(a, b)
118 #define WEBRTC_SPL_SAT(a, b, c) (b > a ? a : b < c ? c : b)
119 #define WEBRTC_SPL_MUL_32_16(a, b) ((a) * (b))
121 #define WEBRTC_SPL_SUB_SAT_W32(a, b) WebRtcSpl_SubSatW32(a, b)
122 #define WEBRTC_SPL_ADD_SAT_W16(a, b) WebRtcSpl_AddSatW16(a, b)
123 #define WEBRTC_SPL_SUB_SAT_W16(a, b) WebRtcSpl_SubSatW16(a, b)
125 // We cannot do casting here due to signed/unsigned problem
126 #define WEBRTC_SPL_IS_NEG(a) ((a) & 0x80000000)
127 // Shifting with negative numbers allowed
128 // Positive means left shift
129 #define WEBRTC_SPL_SHIFT_W16(x, c) \
130 (((c) >= 0) ? ((x) << (c)) : ((x) >> (-(c))))
131 #define WEBRTC_SPL_SHIFT_W32(x, c) \
132 (((c) >= 0) ? ((x) << (c)) : ((x) >> (-(c))))
134 // Shifting with negative numbers not allowed
135 // We cannot do casting here due to signed/unsigned problem
136 #define WEBRTC_SPL_RSHIFT_W16(x, c) ((x) >> (c))
137 #define WEBRTC_SPL_LSHIFT_W16(x, c) ((x) << (c))
138 #define WEBRTC_SPL_RSHIFT_W32(x, c) ((x) >> (c))
139 #define WEBRTC_SPL_LSHIFT_W32(x, c) ((x) << (c))
141 #define WEBRTC_SPL_RSHIFT_U16(x, c) ((uint16_t)(x) >> (c))
142 #define WEBRTC_SPL_LSHIFT_U16(x, c) ((uint16_t)(x) << (c))
143 #define WEBRTC_SPL_RSHIFT_U32(x, c) ((uint32_t)(x) >> (c))
144 #define WEBRTC_SPL_LSHIFT_U32(x, c) ((uint32_t)(x) << (c))
146 #define WEBRTC_SPL_VNEW(t, n) (t *) malloc (sizeof (t) * (n))
147 #define WEBRTC_SPL_FREE free
149 #define WEBRTC_SPL_RAND(a) \
150 ((int16_t)(WEBRTC_SPL_MUL_16_16_RSFT((a), 18816, 7) & 0x00007fff))
156 #define WEBRTC_SPL_MEMCPY_W8(v1, v2, length) \
157 memcpy(v1, v2, (length) * sizeof(char))
158 #define WEBRTC_SPL_MEMCPY_W16(v1, v2, length) \
159 memcpy(v1, v2, (length) * sizeof(int16_t))
161 #define WEBRTC_SPL_MEMMOVE_W16(v1, v2, length) \
162 memmove(v1, v2, (length) * sizeof(int16_t))
165 #include "webrtc/common_audio/signal_processing/include/spl_inl.h"
167 // Initialize SPL. Currently it contains only function pointer initialization.
168 // If the underlying platform is known to be ARM-Neon (WEBRTC_ARCH_ARM_NEON
169 // defined), the pointers will be assigned to code optimized for Neon; otherwise
170 // if run-time Neon detection (WEBRTC_DETECT_ARM_NEON) is enabled, the pointers
171 // will be assigned to either Neon code or generic C code; otherwise, generic C
172 // code will be assigned.
173 // Note that this function MUST be called in any application that uses SPL
175 void WebRtcSpl_Init();
178 int16_t WebRtcSpl_get_version(char* version, int16_t length_in_bytes);
180 int WebRtcSpl_GetScalingSquare(int16_t* in_vector,
181 int in_vector_length,
184 // Copy and set operations. Implementation in copy_set_operations.c.
185 // Descriptions at bottom of file.
186 void WebRtcSpl_MemSetW16(int16_t* vector,
189 void WebRtcSpl_MemSetW32(int32_t* vector,
192 void WebRtcSpl_MemCpyReversedOrder(int16_t* out_vector,
195 int16_t WebRtcSpl_CopyFromEndW16(const int16_t* in_vector,
196 int16_t in_vector_length,
198 int16_t* out_vector);
199 int16_t WebRtcSpl_ZerosArrayW16(int16_t* vector,
200 int16_t vector_length);
201 int16_t WebRtcSpl_ZerosArrayW32(int32_t* vector,
202 int16_t vector_length);
203 int16_t WebRtcSpl_OnesArrayW16(int16_t* vector,
204 int16_t vector_length);
205 int16_t WebRtcSpl_OnesArrayW32(int32_t* vector,
206 int16_t vector_length);
207 // End: Copy and set operations.
210 // Minimum and maximum operation functions and their pointers.
211 // Implementation in min_max_operations.c.
213 // Returns the largest absolute value in a signed 16-bit vector.
216 // - vector : 16-bit input vector.
217 // - length : Number of samples in vector.
219 // Return value : Maximum absolute value in vector;
220 // or -1, if (vector == NULL || length <= 0).
221 typedef int16_t (*MaxAbsValueW16)(const int16_t* vector, int length);
222 extern MaxAbsValueW16 WebRtcSpl_MaxAbsValueW16;
223 int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, int length);
224 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
225 int16_t WebRtcSpl_MaxAbsValueW16Neon(const int16_t* vector, int length);
227 #if defined(MIPS32_LE)
228 int16_t WebRtcSpl_MaxAbsValueW16_mips(const int16_t* vector, int length);
231 // Returns the largest absolute value in a signed 32-bit vector.
234 // - vector : 32-bit input vector.
235 // - length : Number of samples in vector.
237 // Return value : Maximum absolute value in vector;
238 // or -1, if (vector == NULL || length <= 0).
239 typedef int32_t (*MaxAbsValueW32)(const int32_t* vector, int length);
240 extern MaxAbsValueW32 WebRtcSpl_MaxAbsValueW32;
241 int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, int length);
242 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
243 int32_t WebRtcSpl_MaxAbsValueW32Neon(const int32_t* vector, int length);
245 #if defined(MIPS_DSP_R1_LE)
246 int32_t WebRtcSpl_MaxAbsValueW32_mips(const int32_t* vector, int length);
249 // Returns the maximum value of a 16-bit vector.
252 // - vector : 16-bit input vector.
253 // - length : Number of samples in vector.
255 // Return value : Maximum sample value in |vector|.
256 // If (vector == NULL || length <= 0) WEBRTC_SPL_WORD16_MIN
257 // is returned. Note that WEBRTC_SPL_WORD16_MIN is a feasible
258 // value and we can't catch errors purely based on it.
259 typedef int16_t (*MaxValueW16)(const int16_t* vector, int length);
260 extern MaxValueW16 WebRtcSpl_MaxValueW16;
261 int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, int length);
262 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
263 int16_t WebRtcSpl_MaxValueW16Neon(const int16_t* vector, int length);
265 #if defined(MIPS32_LE)
266 int16_t WebRtcSpl_MaxValueW16_mips(const int16_t* vector, int length);
269 // Returns the maximum value of a 32-bit vector.
272 // - vector : 32-bit input vector.
273 // - length : Number of samples in vector.
275 // Return value : Maximum sample value in |vector|.
276 // If (vector == NULL || length <= 0) WEBRTC_SPL_WORD32_MIN
277 // is returned. Note that WEBRTC_SPL_WORD32_MIN is a feasible
278 // value and we can't catch errors purely based on it.
279 typedef int32_t (*MaxValueW32)(const int32_t* vector, int length);
280 extern MaxValueW32 WebRtcSpl_MaxValueW32;
281 int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, int length);
282 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
283 int32_t WebRtcSpl_MaxValueW32Neon(const int32_t* vector, int length);
285 #if defined(MIPS32_LE)
286 int32_t WebRtcSpl_MaxValueW32_mips(const int32_t* vector, int length);
289 // Returns the minimum value of a 16-bit vector.
292 // - vector : 16-bit input vector.
293 // - length : Number of samples in vector.
295 // Return value : Minimum sample value in |vector|.
296 // If (vector == NULL || length <= 0) WEBRTC_SPL_WORD16_MAX
297 // is returned. Note that WEBRTC_SPL_WORD16_MAX is a feasible
298 // value and we can't catch errors purely based on it.
299 typedef int16_t (*MinValueW16)(const int16_t* vector, int length);
300 extern MinValueW16 WebRtcSpl_MinValueW16;
301 int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, int length);
302 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
303 int16_t WebRtcSpl_MinValueW16Neon(const int16_t* vector, int length);
305 #if defined(MIPS32_LE)
306 int16_t WebRtcSpl_MinValueW16_mips(const int16_t* vector, int length);
309 // Returns the minimum value of a 32-bit vector.
312 // - vector : 32-bit input vector.
313 // - length : Number of samples in vector.
315 // Return value : Minimum sample value in |vector|.
316 // If (vector == NULL || length <= 0) WEBRTC_SPL_WORD32_MAX
317 // is returned. Note that WEBRTC_SPL_WORD32_MAX is a feasible
318 // value and we can't catch errors purely based on it.
319 typedef int32_t (*MinValueW32)(const int32_t* vector, int length);
320 extern MinValueW32 WebRtcSpl_MinValueW32;
321 int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, int length);
322 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
323 int32_t WebRtcSpl_MinValueW32Neon(const int32_t* vector, int length);
325 #if defined(MIPS32_LE)
326 int32_t WebRtcSpl_MinValueW32_mips(const int32_t* vector, int length);
329 // Returns the vector index to the largest absolute value of a 16-bit vector.
332 // - vector : 16-bit input vector.
333 // - length : Number of samples in vector.
335 // Return value : Index to the maximum absolute value in vector, or -1,
336 // if (vector == NULL || length <= 0).
337 // If there are multiple equal maxima, return the index of the
338 // first. -32768 will always have precedence over 32767 (despite
339 // -32768 presenting an int16 absolute value of 32767);
340 int WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, int length);
342 // Returns the vector index to the maximum sample value of a 16-bit vector.
345 // - vector : 16-bit input vector.
346 // - length : Number of samples in vector.
348 // Return value : Index to the maximum value in vector (if multiple
349 // indexes have the maximum, return the first);
350 // or -1, if (vector == NULL || length <= 0).
351 int WebRtcSpl_MaxIndexW16(const int16_t* vector, int length);
353 // Returns the vector index to the maximum sample value of a 32-bit vector.
356 // - vector : 32-bit input vector.
357 // - length : Number of samples in vector.
359 // Return value : Index to the maximum value in vector (if multiple
360 // indexes have the maximum, return the first);
361 // or -1, if (vector == NULL || length <= 0).
362 int WebRtcSpl_MaxIndexW32(const int32_t* vector, int length);
364 // Returns the vector index to the minimum sample value of a 16-bit vector.
367 // - vector : 16-bit input vector.
368 // - length : Number of samples in vector.
370 // Return value : Index to the mimimum value in vector (if multiple
371 // indexes have the minimum, return the first);
372 // or -1, if (vector == NULL || length <= 0).
373 int WebRtcSpl_MinIndexW16(const int16_t* vector, int length);
375 // Returns the vector index to the minimum sample value of a 32-bit vector.
378 // - vector : 32-bit input vector.
379 // - length : Number of samples in vector.
381 // Return value : Index to the mimimum value in vector (if multiple
382 // indexes have the minimum, return the first);
383 // or -1, if (vector == NULL || length <= 0).
384 int WebRtcSpl_MinIndexW32(const int32_t* vector, int length);
386 // End: Minimum and maximum operations.
389 // Vector scaling operations. Implementation in vector_scaling_operations.c.
390 // Description at bottom of file.
391 void WebRtcSpl_VectorBitShiftW16(int16_t* out_vector,
392 int16_t vector_length,
393 const int16_t* in_vector,
394 int16_t right_shifts);
395 void WebRtcSpl_VectorBitShiftW32(int32_t* out_vector,
396 int16_t vector_length,
397 const int32_t* in_vector,
398 int16_t right_shifts);
399 void WebRtcSpl_VectorBitShiftW32ToW16(int16_t* out_vector,
401 const int32_t* in_vector,
403 void WebRtcSpl_ScaleVector(const int16_t* in_vector,
406 int16_t vector_length,
407 int16_t right_shifts);
408 void WebRtcSpl_ScaleVectorWithSat(const int16_t* in_vector,
411 int16_t vector_length,
412 int16_t right_shifts);
413 void WebRtcSpl_ScaleAndAddVectors(const int16_t* in_vector1,
414 int16_t gain1, int right_shifts1,
415 const int16_t* in_vector2,
416 int16_t gain2, int right_shifts2,
420 // The functions (with related pointer) perform the vector operation:
421 // out_vector[k] = ((scale1 * in_vector1[k]) + (scale2 * in_vector2[k])
422 // + round_value) >> right_shifts,
423 // where round_value = (1 << right_shifts) >> 1.
426 // - in_vector1 : Input vector 1
427 // - in_vector1_scale : Gain to be used for vector 1
428 // - in_vector2 : Input vector 2
429 // - in_vector2_scale : Gain to be used for vector 2
430 // - right_shifts : Number of right bit shifts to be applied
431 // - length : Number of elements in the input vectors
434 // - out_vector : Output vector
435 // Return value : 0 if OK, -1 if (in_vector1 == NULL
436 // || in_vector2 == NULL || out_vector == NULL
437 // || length <= 0 || right_shift < 0).
438 typedef int (*ScaleAndAddVectorsWithRound)(const int16_t* in_vector1,
439 int16_t in_vector1_scale,
440 const int16_t* in_vector2,
441 int16_t in_vector2_scale,
445 extern ScaleAndAddVectorsWithRound WebRtcSpl_ScaleAndAddVectorsWithRound;
446 int WebRtcSpl_ScaleAndAddVectorsWithRoundC(const int16_t* in_vector1,
447 int16_t in_vector1_scale,
448 const int16_t* in_vector2,
449 int16_t in_vector2_scale,
453 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
454 int WebRtcSpl_ScaleAndAddVectorsWithRoundNeon(const int16_t* in_vector1,
455 int16_t in_vector1_scale,
456 const int16_t* in_vector2,
457 int16_t in_vector2_scale,
462 #if defined(MIPS_DSP_R1_LE)
463 int WebRtcSpl_ScaleAndAddVectorsWithRound_mips(const int16_t* in_vector1,
464 int16_t in_vector1_scale,
465 const int16_t* in_vector2,
466 int16_t in_vector2_scale,
471 // End: Vector scaling operations.
473 // iLBC specific functions. Implementations in ilbc_specific_functions.c.
474 // Description at bottom of file.
475 void WebRtcSpl_ReverseOrderMultArrayElements(int16_t* out_vector,
476 const int16_t* in_vector,
477 const int16_t* window,
478 int16_t vector_length,
479 int16_t right_shifts);
480 void WebRtcSpl_ElementwiseVectorMult(int16_t* out_vector,
481 const int16_t* in_vector,
482 const int16_t* window,
483 int16_t vector_length,
484 int16_t right_shifts);
485 void WebRtcSpl_AddVectorsAndShift(int16_t* out_vector,
486 const int16_t* in_vector1,
487 const int16_t* in_vector2,
488 int16_t vector_length,
489 int16_t right_shifts);
490 void WebRtcSpl_AddAffineVectorToVector(int16_t* out_vector,
493 int32_t add_constant,
494 int16_t right_shifts,
496 void WebRtcSpl_AffineTransformVector(int16_t* out_vector,
499 int32_t add_constant,
500 int16_t right_shifts,
502 // End: iLBC specific functions.
504 // Signal processing operations.
506 // A 32-bit fix-point implementation of auto-correlation computation
509 // - in_vector : Vector to calculate autocorrelation upon
510 // - in_vector_length : Length (in samples) of |vector|
511 // - order : The order up to which the autocorrelation should be
515 // - result : auto-correlation values (values should be seen
516 // relative to each other since the absolute values
517 // might have been down shifted to avoid overflow)
519 // - scale : The number of left shifts required to obtain the
520 // auto-correlation in Q0
523 // - -1, if |order| > |in_vector_length|;
524 // - Number of samples in |result|, i.e. (order+1), otherwise.
525 int WebRtcSpl_AutoCorrelation(const int16_t* in_vector,
526 int in_vector_length,
531 // A 32-bit fix-point implementation of the Levinson-Durbin algorithm that
532 // does NOT use the 64 bit class
535 // - auto_corr : Vector with autocorrelation values of length >=
537 // - use_order : The LPC filter order (support up to order 20)
540 // - lpc_coef : lpc_coef[0..use_order] LPC coefficients in Q12
541 // - refl_coef : refl_coef[0...use_order-1]| Reflection coefficients in
544 // Return value : 1 for stable 0 for unstable
545 int16_t WebRtcSpl_LevinsonDurbin(int32_t* auto_corr,
550 // Converts reflection coefficients |refl_coef| to LPC coefficients |lpc_coef|.
551 // This version is a 16 bit operation.
553 // NOTE: The 16 bit refl_coef -> lpc_coef conversion might result in a
554 // "slightly unstable" filter (i.e., a pole just outside the unit circle) in
555 // "rare" cases even if the reflection coefficients are stable.
558 // - refl_coef : Reflection coefficients in Q15 that should be converted
559 // to LPC coefficients
560 // - use_order : Number of coefficients in |refl_coef|
563 // - lpc_coef : LPC coefficients in Q12
564 void WebRtcSpl_ReflCoefToLpc(const int16_t* refl_coef,
568 // Converts LPC coefficients |lpc_coef| to reflection coefficients |refl_coef|.
569 // This version is a 16 bit operation.
570 // The conversion is implemented by the step-down algorithm.
573 // - lpc_coef : LPC coefficients in Q12, that should be converted to
574 // reflection coefficients
575 // - use_order : Number of coefficients in |lpc_coef|
578 // - refl_coef : Reflection coefficients in Q15.
579 void WebRtcSpl_LpcToReflCoef(int16_t* lpc_coef,
583 // Calculates reflection coefficients (16 bit) from auto-correlation values
586 // - auto_corr : Auto-correlation values
587 // - use_order : Number of coefficients wanted be calculated
590 // - refl_coef : Reflection coefficients in Q15.
591 void WebRtcSpl_AutoCorrToReflCoef(const int32_t* auto_corr,
595 // The functions (with related pointer) calculate the cross-correlation between
596 // two sequences |seq1| and |seq2|.
597 // |seq1| is fixed and |seq2| slides as the pointer is increased with the
598 // amount |step_seq2|. Note the arguments should obey the relationship:
599 // |dim_seq| - 1 + |step_seq2| * (|dim_cross_correlation| - 1) <
600 // buffer size of |seq2|
603 // - seq1 : First sequence (fixed throughout the correlation)
604 // - seq2 : Second sequence (slides |step_vector2| for each
606 // - dim_seq : Number of samples to use in the cross-correlation
607 // - dim_cross_correlation : Number of cross-correlations to calculate (the
608 // start position for |vector2| is updated for each
610 // - right_shifts : Number of right bit shifts to use. This will
611 // become the output Q-domain.
612 // - step_seq2 : How many (positive or negative) steps the
613 // |vector2| pointer should be updated for each new
614 // cross-correlation value.
617 // - cross_correlation : The cross-correlation in Q(-right_shifts)
618 typedef void (*CrossCorrelation)(int32_t* cross_correlation,
622 int16_t dim_cross_correlation,
623 int16_t right_shifts,
625 extern CrossCorrelation WebRtcSpl_CrossCorrelation;
626 void WebRtcSpl_CrossCorrelationC(int32_t* cross_correlation,
630 int16_t dim_cross_correlation,
631 int16_t right_shifts,
633 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
634 void WebRtcSpl_CrossCorrelationNeon(int32_t* cross_correlation,
638 int16_t dim_cross_correlation,
639 int16_t right_shifts,
642 #if defined(MIPS32_LE)
643 void WebRtcSpl_CrossCorrelation_mips(int32_t* cross_correlation,
647 int16_t dim_cross_correlation,
648 int16_t right_shifts,
652 // Creates (the first half of) a Hanning window. Size must be at least 1 and
656 // - size : Length of the requested Hanning window (1 to 512)
659 // - window : Hanning vector in Q14.
660 void WebRtcSpl_GetHanningWindow(int16_t* window, int16_t size);
662 // Calculates y[k] = sqrt(1 - x[k]^2) for each element of the input vector
663 // |in_vector|. Input and output values are in Q15.
666 // - in_vector : Values to calculate sqrt(1 - x^2) of
667 // - vector_length : Length of vector |in_vector|
670 // - out_vector : Output values in Q15
671 void WebRtcSpl_SqrtOfOneMinusXSquared(int16_t* in_vector,
673 int16_t* out_vector);
674 // End: Signal processing operations.
676 // Randomization functions. Implementations collected in
677 // randomization_functions.c and descriptions at bottom of this file.
678 uint32_t WebRtcSpl_IncreaseSeed(uint32_t* seed);
679 int16_t WebRtcSpl_RandU(uint32_t* seed);
680 int16_t WebRtcSpl_RandN(uint32_t* seed);
681 int16_t WebRtcSpl_RandUArray(int16_t* vector,
682 int16_t vector_length,
684 // End: Randomization functions.
687 int32_t WebRtcSpl_Sqrt(int32_t value);
688 int32_t WebRtcSpl_SqrtFloor(int32_t value);
690 // Divisions. Implementations collected in division_operations.c and
691 // descriptions at bottom of this file.
692 uint32_t WebRtcSpl_DivU32U16(uint32_t num, uint16_t den);
693 int32_t WebRtcSpl_DivW32W16(int32_t num, int16_t den);
694 int16_t WebRtcSpl_DivW32W16ResW16(int32_t num, int16_t den);
695 int32_t WebRtcSpl_DivResultInQ31(int32_t num, int32_t den);
696 int32_t WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low);
699 int32_t WebRtcSpl_Energy(int16_t* vector, int vector_length, int* scale_factor);
701 // Calculates the dot product between two (int16_t) vectors.
704 // - vector1 : Vector 1
705 // - vector2 : Vector 2
706 // - vector_length : Number of samples used in the dot product
707 // - scaling : The number of right bit shifts to apply on each term
708 // during calculation to avoid overflow, i.e., the
709 // output will be in Q(-|scaling|)
711 // Return value : The dot product in Q(-scaling)
712 int32_t WebRtcSpl_DotProductWithScale(const int16_t* vector1,
713 const int16_t* vector2,
717 // Filter operations.
718 int WebRtcSpl_FilterAR(const int16_t* ar_coef,
720 const int16_t* in_vector,
721 int in_vector_length,
722 int16_t* filter_state,
723 int filter_state_length,
724 int16_t* filter_state_low,
725 int filter_state_low_length,
727 int16_t* out_vector_low,
728 int out_vector_low_length);
730 void WebRtcSpl_FilterMAFastQ12(int16_t* in_vector,
733 int16_t ma_coef_length,
734 int16_t vector_length);
736 // Performs a AR filtering on a vector in Q12
738 // - data_in : Input samples
739 // - data_out : State information in positions
740 // data_out[-order] .. data_out[-1]
741 // - coefficients : Filter coefficients (in Q12)
742 // - coefficients_length: Number of coefficients (order+1)
743 // - data_length : Number of samples to be filtered
745 // - data_out : Filtered samples
746 void WebRtcSpl_FilterARFastQ12(const int16_t* data_in,
748 const int16_t* __restrict coefficients,
749 int coefficients_length,
752 // The functions (with related pointer) perform a MA down sampling filter
755 // - data_in : Input samples (state in positions
756 // data_in[-order] .. data_in[-1])
757 // - data_in_length : Number of samples in |data_in| to be filtered.
758 // This must be at least
759 // |delay| + |factor|*(|out_vector_length|-1) + 1)
760 // - data_out_length : Number of down sampled samples desired
761 // - coefficients : Filter coefficients (in Q12)
762 // - coefficients_length: Number of coefficients (order+1)
763 // - factor : Decimation factor
764 // - delay : Delay of filter (compensated for in out_vector)
766 // - data_out : Filtered samples
767 // Return value : 0 if OK, -1 if |in_vector| is too short
768 typedef int (*DownsampleFast)(const int16_t* data_in,
772 const int16_t* __restrict coefficients,
773 int coefficients_length,
776 extern DownsampleFast WebRtcSpl_DownsampleFast;
777 int WebRtcSpl_DownsampleFastC(const int16_t* data_in,
781 const int16_t* __restrict coefficients,
782 int coefficients_length,
785 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
786 int WebRtcSpl_DownsampleFastNeon(const int16_t* data_in,
790 const int16_t* __restrict coefficients,
791 int coefficients_length,
795 #if defined(MIPS32_LE)
796 int WebRtcSpl_DownsampleFast_mips(const int16_t* data_in,
800 const int16_t* __restrict coefficients,
801 int coefficients_length,
806 // End: Filter operations.
810 int WebRtcSpl_ComplexFFT(int16_t vector[], int stages, int mode);
811 int WebRtcSpl_ComplexIFFT(int16_t vector[], int stages, int mode);
813 // Treat a 16-bit complex data buffer |complex_data| as an array of 32-bit
814 // values, and swap elements whose indexes are bit-reverses of each other.
817 // - complex_data : Complex data buffer containing 2^|stages| real
818 // elements interleaved with 2^|stages| imaginary
819 // elements: [Re Im Re Im Re Im....]
820 // - stages : Number of FFT stages. Must be at least 3 and at most
821 // 10, since the table WebRtcSpl_kSinTable1024[] is 1024
825 // - complex_data : The complex data buffer.
827 void WebRtcSpl_ComplexBitReverse(int16_t* __restrict complex_data, int stages);
829 // End: FFT operations
831 /************************************************************
833 * RESAMPLING FUNCTIONS AND THEIR STRUCTS ARE DEFINED BELOW
835 ************************************************************/
837 /*******************************************************************
840 * Includes the following resampling combinations
846 ******************************************************************/
848 // state structure for 22 -> 16 resampler
853 } WebRtcSpl_State22khzTo16khz;
855 void WebRtcSpl_Resample22khzTo16khz(const int16_t* in,
857 WebRtcSpl_State22khzTo16khz* state,
860 void WebRtcSpl_ResetResample22khzTo16khz(WebRtcSpl_State22khzTo16khz* state);
862 // state structure for 16 -> 22 resampler
866 } WebRtcSpl_State16khzTo22khz;
868 void WebRtcSpl_Resample16khzTo22khz(const int16_t* in,
870 WebRtcSpl_State16khzTo22khz* state,
873 void WebRtcSpl_ResetResample16khzTo22khz(WebRtcSpl_State16khzTo22khz* state);
875 // state structure for 22 -> 8 resampler
880 } WebRtcSpl_State22khzTo8khz;
882 void WebRtcSpl_Resample22khzTo8khz(const int16_t* in, int16_t* out,
883 WebRtcSpl_State22khzTo8khz* state,
886 void WebRtcSpl_ResetResample22khzTo8khz(WebRtcSpl_State22khzTo8khz* state);
888 // state structure for 8 -> 22 resampler
893 } WebRtcSpl_State8khzTo22khz;
895 void WebRtcSpl_Resample8khzTo22khz(const int16_t* in, int16_t* out,
896 WebRtcSpl_State8khzTo22khz* state,
899 void WebRtcSpl_ResetResample8khzTo22khz(WebRtcSpl_State8khzTo22khz* state);
901 /*******************************************************************
902 * resample_fractional.c
903 * Functions for internal use in the other resample functions
905 * Includes the following resampling combinations
910 ******************************************************************/
912 void WebRtcSpl_Resample48khzTo32khz(const int32_t* In, int32_t* Out,
915 void WebRtcSpl_Resample32khzTo24khz(const int32_t* In, int32_t* Out,
918 void WebRtcSpl_Resample44khzTo32khz(const int32_t* In, int32_t* Out,
921 /*******************************************************************
924 * Includes the following resampling combinations
930 ******************************************************************/
936 } WebRtcSpl_State48khzTo16khz;
938 void WebRtcSpl_Resample48khzTo16khz(const int16_t* in, int16_t* out,
939 WebRtcSpl_State48khzTo16khz* state,
942 void WebRtcSpl_ResetResample48khzTo16khz(WebRtcSpl_State48khzTo16khz* state);
948 } WebRtcSpl_State16khzTo48khz;
950 void WebRtcSpl_Resample16khzTo48khz(const int16_t* in, int16_t* out,
951 WebRtcSpl_State16khzTo48khz* state,
954 void WebRtcSpl_ResetResample16khzTo48khz(WebRtcSpl_State16khzTo48khz* state);
961 } WebRtcSpl_State48khzTo8khz;
963 void WebRtcSpl_Resample48khzTo8khz(const int16_t* in, int16_t* out,
964 WebRtcSpl_State48khzTo8khz* state,
967 void WebRtcSpl_ResetResample48khzTo8khz(WebRtcSpl_State48khzTo8khz* state);
974 } WebRtcSpl_State8khzTo48khz;
976 void WebRtcSpl_Resample8khzTo48khz(const int16_t* in, int16_t* out,
977 WebRtcSpl_State8khzTo48khz* state,
980 void WebRtcSpl_ResetResample8khzTo48khz(WebRtcSpl_State8khzTo48khz* state);
982 /*******************************************************************
985 * Includes down and up sampling by a factor of two.
987 ******************************************************************/
989 void WebRtcSpl_DownsampleBy2(const int16_t* in, int16_t len,
990 int16_t* out, int32_t* filtState);
992 void WebRtcSpl_UpsampleBy2(const int16_t* in, int16_t len,
993 int16_t* out, int32_t* filtState);
995 /************************************************************
996 * END OF RESAMPLING FUNCTIONS
997 ************************************************************/
998 void WebRtcSpl_AnalysisQMF(const int16_t* in_data,
1002 int32_t* filter_state1,
1003 int32_t* filter_state2);
1004 void WebRtcSpl_SynthesisQMF(const int16_t* low_band,
1005 const int16_t* high_band,
1008 int32_t* filter_state1,
1009 int32_t* filter_state2);
1013 #endif // __cplusplus
1014 #endif // WEBRTC_SPL_SIGNAL_PROCESSING_LIBRARY_H_
1017 // WebRtcSpl_AddSatW16(...)
1018 // WebRtcSpl_AddSatW32(...)
1020 // Returns the result of a saturated 16-bit, respectively 32-bit, addition of
1021 // the numbers specified by the |var1| and |var2| parameters.
1024 // - var1 : Input variable 1
1025 // - var2 : Input variable 2
1027 // Return value : Added and saturated value
1031 // WebRtcSpl_SubSatW16(...)
1032 // WebRtcSpl_SubSatW32(...)
1034 // Returns the result of a saturated 16-bit, respectively 32-bit, subtraction
1035 // of the numbers specified by the |var1| and |var2| parameters.
1038 // - var1 : Input variable 1
1039 // - var2 : Input variable 2
1041 // Returned value : Subtracted and saturated value
1045 // WebRtcSpl_GetSizeInBits(...)
1047 // Returns the # of bits that are needed at the most to represent the number
1048 // specified by the |value| parameter.
1051 // - value : Input value
1053 // Return value : Number of bits needed to represent |value|
1057 // WebRtcSpl_NormW32(...)
1059 // Norm returns the # of left shifts required to 32-bit normalize the 32-bit
1060 // signed number specified by the |value| parameter.
1063 // - value : Input value
1065 // Return value : Number of bit shifts needed to 32-bit normalize |value|
1069 // WebRtcSpl_NormW16(...)
1071 // Norm returns the # of left shifts required to 16-bit normalize the 16-bit
1072 // signed number specified by the |value| parameter.
1075 // - value : Input value
1077 // Return value : Number of bit shifts needed to 32-bit normalize |value|
1081 // WebRtcSpl_NormU32(...)
1083 // Norm returns the # of left shifts required to 32-bit normalize the unsigned
1084 // 32-bit number specified by the |value| parameter.
1087 // - value : Input value
1089 // Return value : Number of bit shifts needed to 32-bit normalize |value|
1093 // WebRtcSpl_GetScalingSquare(...)
1095 // Returns the # of bits required to scale the samples specified in the
1096 // |in_vector| parameter so that, if the squares of the samples are added the
1097 // # of times specified by the |times| parameter, the 32-bit addition will not
1098 // overflow (result in int32_t).
1101 // - in_vector : Input vector to check scaling on
1102 // - in_vector_length : Samples in |in_vector|
1103 // - times : Number of additions to be performed
1105 // Return value : Number of right bit shifts needed to avoid
1106 // overflow in the addition calculation
1110 // WebRtcSpl_MemSetW16(...)
1112 // Sets all the values in the int16_t vector |vector| of length
1113 // |vector_length| to the specified value |set_value|
1116 // - vector : Pointer to the int16_t vector
1117 // - set_value : Value specified
1118 // - vector_length : Length of vector
1122 // WebRtcSpl_MemSetW32(...)
1124 // Sets all the values in the int32_t vector |vector| of length
1125 // |vector_length| to the specified value |set_value|
1128 // - vector : Pointer to the int16_t vector
1129 // - set_value : Value specified
1130 // - vector_length : Length of vector
1134 // WebRtcSpl_MemCpyReversedOrder(...)
1136 // Copies all the values from the source int16_t vector |in_vector| to a
1137 // destination int16_t vector |out_vector|. It is done in reversed order,
1138 // meaning that the first sample of |in_vector| is copied to the last sample of
1139 // the |out_vector|. The procedure continues until the last sample of
1140 // |in_vector| has been copied to the first sample of |out_vector|. This
1141 // creates a reversed vector. Used in e.g. prediction in iLBC.
1144 // - in_vector : Pointer to the first sample in a int16_t vector
1145 // of length |length|
1146 // - vector_length : Number of elements to copy
1149 // - out_vector : Pointer to the last sample in a int16_t vector
1150 // of length |length|
1154 // WebRtcSpl_CopyFromEndW16(...)
1156 // Copies the rightmost |samples| of |in_vector| (of length |in_vector_length|)
1157 // to the vector |out_vector|.
1160 // - in_vector : Input vector
1161 // - in_vector_length : Number of samples in |in_vector|
1162 // - samples : Number of samples to extract (from right side)
1166 // - out_vector : Vector with the requested samples
1168 // Return value : Number of copied samples in |out_vector|
1172 // WebRtcSpl_ZerosArrayW16(...)
1173 // WebRtcSpl_ZerosArrayW32(...)
1175 // Inserts the value "zero" in all positions of a w16 and a w32 vector
1179 // - vector_length : Number of samples in vector
1182 // - vector : Vector containing all zeros
1184 // Return value : Number of samples in vector
1188 // WebRtcSpl_OnesArrayW16(...)
1189 // WebRtcSpl_OnesArrayW32(...)
1191 // Inserts the value "one" in all positions of a w16 and a w32 vector
1195 // - vector_length : Number of samples in vector
1198 // - vector : Vector containing all ones
1200 // Return value : Number of samples in vector
1204 // WebRtcSpl_VectorBitShiftW16(...)
1205 // WebRtcSpl_VectorBitShiftW32(...)
1207 // Bit shifts all the values in a vector up or downwards. Different calls for
1208 // int16_t and int32_t vectors respectively.
1211 // - vector_length : Length of vector
1212 // - in_vector : Pointer to the vector that should be bit shifted
1213 // - right_shifts : Number of right bit shifts (negative value gives left
1217 // - out_vector : Pointer to the result vector (can be the same as
1222 // WebRtcSpl_VectorBitShiftW32ToW16(...)
1224 // Bit shifts all the values in a int32_t vector up or downwards and
1225 // stores the result as an int16_t vector. The function will saturate the
1226 // signal if needed, before storing in the output vector.
1229 // - vector_length : Length of vector
1230 // - in_vector : Pointer to the vector that should be bit shifted
1231 // - right_shifts : Number of right bit shifts (negative value gives left
1235 // - out_vector : Pointer to the result vector (can be the same as
1240 // WebRtcSpl_ScaleVector(...)
1242 // Performs the vector operation:
1243 // out_vector[k] = (gain*in_vector[k])>>right_shifts
1246 // - in_vector : Input vector
1247 // - gain : Scaling gain
1248 // - vector_length : Elements in the |in_vector|
1249 // - right_shifts : Number of right bit shifts applied
1252 // - out_vector : Output vector (can be the same as |in_vector|)
1256 // WebRtcSpl_ScaleVectorWithSat(...)
1258 // Performs the vector operation:
1259 // out_vector[k] = SATURATE( (gain*in_vector[k])>>right_shifts )
1262 // - in_vector : Input vector
1263 // - gain : Scaling gain
1264 // - vector_length : Elements in the |in_vector|
1265 // - right_shifts : Number of right bit shifts applied
1268 // - out_vector : Output vector (can be the same as |in_vector|)
1272 // WebRtcSpl_ScaleAndAddVectors(...)
1274 // Performs the vector operation:
1275 // out_vector[k] = (gain1*in_vector1[k])>>right_shifts1
1276 // + (gain2*in_vector2[k])>>right_shifts2
1279 // - in_vector1 : Input vector 1
1280 // - gain1 : Gain to be used for vector 1
1281 // - right_shifts1 : Right bit shift to be used for vector 1
1282 // - in_vector2 : Input vector 2
1283 // - gain2 : Gain to be used for vector 2
1284 // - right_shifts2 : Right bit shift to be used for vector 2
1285 // - vector_length : Elements in the input vectors
1288 // - out_vector : Output vector
1292 // WebRtcSpl_ReverseOrderMultArrayElements(...)
1294 // Performs the vector operation:
1295 // out_vector[n] = (in_vector[n]*window[-n])>>right_shifts
1298 // - in_vector : Input vector
1299 // - window : Window vector (should be reversed). The pointer
1300 // should be set to the last value in the vector
1301 // - right_shifts : Number of right bit shift to be applied after the
1303 // - vector_length : Number of elements in |in_vector|
1306 // - out_vector : Output vector (can be same as |in_vector|)
1310 // WebRtcSpl_ElementwiseVectorMult(...)
1312 // Performs the vector operation:
1313 // out_vector[n] = (in_vector[n]*window[n])>>right_shifts
1316 // - in_vector : Input vector
1317 // - window : Window vector.
1318 // - right_shifts : Number of right bit shift to be applied after the
1320 // - vector_length : Number of elements in |in_vector|
1323 // - out_vector : Output vector (can be same as |in_vector|)
1327 // WebRtcSpl_AddVectorsAndShift(...)
1329 // Performs the vector operation:
1330 // out_vector[k] = (in_vector1[k] + in_vector2[k])>>right_shifts
1333 // - in_vector1 : Input vector 1
1334 // - in_vector2 : Input vector 2
1335 // - right_shifts : Number of right bit shift to be applied after the
1337 // - vector_length : Number of elements in |in_vector1| and |in_vector2|
1340 // - out_vector : Output vector (can be same as |in_vector1|)
1344 // WebRtcSpl_AddAffineVectorToVector(...)
1346 // Adds an affine transformed vector to another vector |out_vector|, i.e,
1348 // out_vector[k] += (in_vector[k]*gain+add_constant)>>right_shifts
1351 // - in_vector : Input vector
1352 // - gain : Gain value, used to multiply the in vector with
1353 // - add_constant : Constant value to add (usually 1<<(right_shifts-1),
1354 // but others can be used as well
1355 // - right_shifts : Number of right bit shifts (0-16)
1356 // - vector_length : Number of samples in |in_vector| and |out_vector|
1359 // - out_vector : Vector with the output
1363 // WebRtcSpl_AffineTransformVector(...)
1365 // Affine transforms a vector, i.e, performs
1366 // out_vector[k] = (in_vector[k]*gain+add_constant)>>right_shifts
1369 // - in_vector : Input vector
1370 // - gain : Gain value, used to multiply the in vector with
1371 // - add_constant : Constant value to add (usually 1<<(right_shifts-1),
1372 // but others can be used as well
1373 // - right_shifts : Number of right bit shifts (0-16)
1374 // - vector_length : Number of samples in |in_vector| and |out_vector|
1377 // - out_vector : Vector with the output
1381 // WebRtcSpl_IncreaseSeed(...)
1383 // Increases the seed (and returns the new value)
1386 // - seed : Seed for random calculation
1389 // - seed : Updated seed value
1391 // Return value : The new seed value
1395 // WebRtcSpl_RandU(...)
1397 // Produces a uniformly distributed value in the int16_t range
1400 // - seed : Seed for random calculation
1403 // - seed : Updated seed value
1405 // Return value : Uniformly distributed value in the range
1406 // [Word16_MIN...Word16_MAX]
1410 // WebRtcSpl_RandN(...)
1412 // Produces a normal distributed value in the int16_t range
1415 // - seed : Seed for random calculation
1418 // - seed : Updated seed value
1420 // Return value : N(0,1) value in the Q13 domain
1424 // WebRtcSpl_RandUArray(...)
1426 // Produces a uniformly distributed vector with elements in the int16_t
1430 // - vector_length : Samples wanted in the vector
1431 // - seed : Seed for random calculation
1434 // - vector : Vector with the uniform values
1435 // - seed : Updated seed value
1437 // Return value : Number of samples in vector, i.e., |vector_length|
1441 // WebRtcSpl_Sqrt(...)
1443 // Returns the square root of the input value |value|. The precision of this
1444 // function is integer precision, i.e., sqrt(8) gives 2 as answer.
1445 // If |value| is a negative number then 0 is returned.
1449 // A sixth order Taylor Series expansion is used here to compute the square
1450 // root of a number y^0.5 = (1+x)^0.5
1453 // = 1+(x/2)-0.5*((x/2)^2+0.5*((x/2)^3-0.625*((x/2)^4+0.875*((x/2)^5)
1457 // - value : Value to calculate sqrt of
1459 // Return value : Result of the sqrt calculation
1463 // WebRtcSpl_SqrtFloor(...)
1465 // Returns the square root of the input value |value|. The precision of this
1466 // function is rounding down integer precision, i.e., sqrt(8) gives 2 as answer.
1467 // If |value| is a negative number then 0 is returned.
1471 // An iterative 4 cylce/bit routine
1474 // - value : Value to calculate sqrt of
1476 // Return value : Result of the sqrt calculation
1480 // WebRtcSpl_DivU32U16(...)
1482 // Divides a uint32_t |num| by a uint16_t |den|.
1484 // If |den|==0, (uint32_t)0xFFFFFFFF is returned.
1487 // - num : Numerator
1488 // - den : Denominator
1490 // Return value : Result of the division (as a uint32_t), i.e., the
1491 // integer part of num/den.
1495 // WebRtcSpl_DivW32W16(...)
1497 // Divides a int32_t |num| by a int16_t |den|.
1499 // If |den|==0, (int32_t)0x7FFFFFFF is returned.
1502 // - num : Numerator
1503 // - den : Denominator
1505 // Return value : Result of the division (as a int32_t), i.e., the
1506 // integer part of num/den.
1510 // WebRtcSpl_DivW32W16ResW16(...)
1512 // Divides a int32_t |num| by a int16_t |den|, assuming that the
1513 // result is less than 32768, otherwise an unpredictable result will occur.
1515 // If |den|==0, (int16_t)0x7FFF is returned.
1518 // - num : Numerator
1519 // - den : Denominator
1521 // Return value : Result of the division (as a int16_t), i.e., the
1522 // integer part of num/den.
1526 // WebRtcSpl_DivResultInQ31(...)
1528 // Divides a int32_t |num| by a int16_t |den|, assuming that the
1529 // absolute value of the denominator is larger than the numerator, otherwise
1530 // an unpredictable result will occur.
1533 // - num : Numerator
1534 // - den : Denominator
1536 // Return value : Result of the division in Q31.
1540 // WebRtcSpl_DivW32HiLow(...)
1542 // Divides a int32_t |num| by a denominator in hi, low format. The
1543 // absolute value of the denominator has to be larger (or equal to) the
1547 // - num : Numerator
1548 // - den_hi : High part of denominator
1549 // - den_low : Low part of denominator
1551 // Return value : Divided value in Q31
1555 // WebRtcSpl_Energy(...)
1557 // Calculates the energy of a vector
1560 // - vector : Vector which the energy should be calculated on
1561 // - vector_length : Number of samples in vector
1564 // - scale_factor : Number of left bit shifts needed to get the physical
1565 // energy value, i.e, to get the Q0 value
1567 // Return value : Energy value in Q(-|scale_factor|)
1571 // WebRtcSpl_FilterAR(...)
1573 // Performs a 32-bit AR filtering on a vector in Q12
1576 // - ar_coef : AR-coefficient vector (values in Q12),
1577 // ar_coef[0] must be 4096.
1578 // - ar_coef_length : Number of coefficients in |ar_coef|.
1579 // - in_vector : Vector to be filtered.
1580 // - in_vector_length : Number of samples in |in_vector|.
1581 // - filter_state : Current state (higher part) of the filter.
1582 // - filter_state_length : Length (in samples) of |filter_state|.
1583 // - filter_state_low : Current state (lower part) of the filter.
1584 // - filter_state_low_length : Length (in samples) of |filter_state_low|.
1585 // - out_vector_low_length : Maximum length (in samples) of
1586 // |out_vector_low|.
1589 // - filter_state : Updated state (upper part) vector.
1590 // - filter_state_low : Updated state (lower part) vector.
1591 // - out_vector : Vector containing the upper part of the
1593 // - out_vector_low : Vector containing the lower part of the
1596 // Return value : Number of samples in the |out_vector|.
1600 // WebRtcSpl_FilterMAFastQ12(...)
1602 // Performs a MA filtering on a vector in Q12
1605 // - in_vector : Input samples (state in positions
1606 // in_vector[-order] .. in_vector[-1])
1607 // - ma_coef : Filter coefficients (in Q12)
1608 // - ma_coef_length : Number of B coefficients (order+1)
1609 // - vector_length : Number of samples to be filtered
1612 // - out_vector : Filtered samples
1616 // WebRtcSpl_ComplexIFFT(...)
1618 // Complex Inverse FFT
1620 // Computes an inverse complex 2^|stages|-point FFT on the input vector, which
1621 // is in bit-reversed order. The original content of the vector is destroyed in
1622 // the process, since the input is overwritten by the output, normal-ordered,
1623 // FFT vector. With X as the input complex vector, y as the output complex
1624 // vector and with M = 2^|stages|, the following is computed:
1627 // y(k) = sum[X(i)*[cos(2*pi*i*k/M) + j*sin(2*pi*i*k/M)]]
1630 // The implementations are optimized for speed, not for code size. It uses the
1631 // decimation-in-time algorithm with radix-2 butterfly technique.
1634 // - vector : In pointer to complex vector containing 2^|stages|
1635 // real elements interleaved with 2^|stages| imaginary
1637 // [ReImReImReIm....]
1638 // The elements are in Q(-scale) domain, see more on Return
1641 // - stages : Number of FFT stages. Must be at least 3 and at most 10,
1642 // since the table WebRtcSpl_kSinTable1024[] is 1024
1645 // - mode : This parameter gives the user to choose how the FFT
1647 // mode==0: Low-complexity and Low-accuracy mode
1648 // mode==1: High-complexity and High-accuracy mode
1651 // - vector : Out pointer to the FFT vector (the same as input).
1653 // Return Value : The scale value that tells the number of left bit shifts
1654 // that the elements in the |vector| should be shifted with
1655 // in order to get Q0 values, i.e. the physically correct
1656 // values. The scale parameter is always 0 or positive,
1657 // except if N>1024 (|stages|>10), which returns a scale
1658 // value of -1, indicating error.
1662 // WebRtcSpl_ComplexFFT(...)
1666 // Computes a complex 2^|stages|-point FFT on the input vector, which is in
1667 // bit-reversed order. The original content of the vector is destroyed in
1668 // the process, since the input is overwritten by the output, normal-ordered,
1669 // FFT vector. With x as the input complex vector, Y as the output complex
1670 // vector and with M = 2^|stages|, the following is computed:
1673 // Y(k) = 1/M * sum[x(i)*[cos(2*pi*i*k/M) + j*sin(2*pi*i*k/M)]]
1676 // The implementations are optimized for speed, not for code size. It uses the
1677 // decimation-in-time algorithm with radix-2 butterfly technique.
1679 // This routine prevents overflow by scaling by 2 before each FFT stage. This is
1680 // a fixed scaling, for proper normalization - there will be log2(n) passes, so
1681 // this results in an overall factor of 1/n, distributed to maximize arithmetic
1685 // - vector : In pointer to complex vector containing 2^|stages| real
1686 // elements interleaved with 2^|stages| imaginary elements.
1687 // [ReImReImReIm....]
1688 // The output is in the Q0 domain.
1690 // - stages : Number of FFT stages. Must be at least 3 and at most 10,
1691 // since the table WebRtcSpl_kSinTable1024[] is 1024
1694 // - mode : This parameter gives the user to choose how the FFT
1696 // mode==0: Low-complexity and Low-accuracy mode
1697 // mode==1: High-complexity and High-accuracy mode
1700 // - vector : The output FFT vector is in the Q0 domain.
1702 // Return value : The scale parameter is always 0, except if N>1024,
1703 // which returns a scale value of -1, indicating error.
1707 // WebRtcSpl_AnalysisQMF(...)
1709 // Splits a 0-2*F Hz signal into two sub bands: 0-F Hz and F-2*F Hz. The
1710 // current version has F = 8000, therefore, a super-wideband audio signal is
1711 // split to lower-band 0-8 kHz and upper-band 8-16 kHz.
1714 // - in_data : Wide band speech signal, 320 samples (10 ms)
1717 // - filter_state1 : Filter state for first All-pass filter
1718 // - filter_state2 : Filter state for second All-pass filter
1721 // - low_band : Lower-band signal 0-8 kHz band, 160 samples (10 ms)
1722 // - high_band : Upper-band signal 8-16 kHz band (flipped in frequency
1723 // domain), 160 samples (10 ms)
1727 // WebRtcSpl_SynthesisQMF(...)
1729 // Combines the two sub bands (0-F and F-2*F Hz) into a signal of 0-2*F
1730 // Hz, (current version has F = 8000 Hz). So the filter combines lower-band
1731 // (0-8 kHz) and upper-band (8-16 kHz) channels to obtain super-wideband 0-16
1735 // - low_band : The signal with the 0-8 kHz band, 160 samples (10 ms)
1736 // - high_band : The signal with the 8-16 kHz band, 160 samples (10 ms)
1739 // - filter_state1 : Filter state for first All-pass filter
1740 // - filter_state2 : Filter state for second All-pass filter
1743 // - out_data : Super-wideband speech signal, 0-16 kHz
1746 // int16_t WebRtcSpl_SatW32ToW16(...)
1748 // This function saturates a 32-bit word into a 16-bit word.
1751 // - value32 : The value of a 32-bit word.
1754 // - out16 : the saturated 16-bit word.
1757 // int32_t WebRtc_MulAccumW16(...)
1759 // This function multiply a 16-bit word by a 16-bit word, and accumulate this
1760 // value to a 32-bit integer.
1763 // - a : The value of the first 16-bit word.
1764 // - b : The value of the second 16-bit word.
1765 // - c : The value of an 32-bit integer.
1767 // Return Value: The value of a * b + c.
1770 // int16_t WebRtcSpl_get_version(...)
1772 // This function gives the version string of the Signal Processing Library.
1775 // - length_in_bytes : The size of Allocated space (in Bytes) where
1776 // the version number is written to (in string format).
1779 // - version : Pointer to a buffer where the version number is