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_MIN(A, B) (A < B ? A : B) // Get min value
31 #define WEBRTC_SPL_MAX(A, B) (A > B ? A : B) // Get max value
32 // TODO(kma/bjorn): For the next two macros, investigate how to correct the code
33 // for inputs of a = WEBRTC_SPL_WORD16_MIN or WEBRTC_SPL_WORD32_MIN.
34 #define WEBRTC_SPL_ABS_W16(a) \
35 (((int16_t)a >= 0) ? ((int16_t)a) : -((int16_t)a))
36 #define WEBRTC_SPL_ABS_W32(a) \
37 (((int32_t)a >= 0) ? ((int32_t)a) : -((int32_t)a))
39 #ifdef WEBRTC_ARCH_LITTLE_ENDIAN
40 #define WEBRTC_SPL_GET_BYTE(a, nr) (((int8_t *)a)[nr])
41 #define WEBRTC_SPL_SET_BYTE(d_ptr, val, index) \
42 (((int8_t *)d_ptr)[index] = (val))
44 #define WEBRTC_SPL_GET_BYTE(a, nr) \
45 ((((int16_t *)a)[nr >> 1]) >> (((nr + 1) & 0x1) * 8) & 0x00ff)
46 #define WEBRTC_SPL_SET_BYTE(d_ptr, val, index) \
47 ((int16_t *)d_ptr)[index >> 1] = \
48 ((((int16_t *)d_ptr)[index >> 1]) \
49 & (0x00ff << (8 * ((index) & 0x1)))) | (val << (8 * ((index + 1) & 0x1)))
52 #define WEBRTC_SPL_MUL(a, b) \
53 ((int32_t) ((int32_t)(a) * (int32_t)(b)))
54 #define WEBRTC_SPL_UMUL(a, b) \
55 ((uint32_t) ((uint32_t)(a) * (uint32_t)(b)))
56 #define WEBRTC_SPL_UMUL_16_16(a, b) \
57 ((uint32_t) (uint16_t)(a) * (uint16_t)(b))
58 #define WEBRTC_SPL_UMUL_32_16(a, b) \
59 ((uint32_t) ((uint32_t)(a) * (uint16_t)(b)))
60 #define WEBRTC_SPL_MUL_16_U16(a, b) \
61 ((int32_t)(int16_t)(a) * (uint16_t)(b))
62 #define WEBRTC_SPL_DIV(a, b) \
63 ((int32_t) ((int32_t)(a) / (int32_t)(b)))
64 #define WEBRTC_SPL_UDIV(a, b) \
65 ((uint32_t) ((uint32_t)(a) / (uint32_t)(b)))
67 #ifndef WEBRTC_ARCH_ARM_V7
68 // For ARMv7 platforms, these are inline functions in spl_inl_armv7.h
70 // For MIPS platforms, these are inline functions in spl_inl_mips.h
71 #define WEBRTC_SPL_MUL_16_16(a, b) \
72 ((int32_t) (((int16_t)(a)) * ((int16_t)(b))))
73 #define WEBRTC_SPL_MUL_16_32_RSFT16(a, b) \
74 (WEBRTC_SPL_MUL_16_16(a, b >> 16) \
75 + ((WEBRTC_SPL_MUL_16_16(a, (b & 0xffff) >> 1) + 0x4000) >> 15))
79 #define WEBRTC_SPL_MUL_16_32_RSFT11(a, b) \
80 ((WEBRTC_SPL_MUL_16_16(a, (b) >> 16) << 5) \
81 + (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x0200) >> 10))
82 #define WEBRTC_SPL_MUL_16_32_RSFT14(a, b) \
83 ((WEBRTC_SPL_MUL_16_16(a, (b) >> 16) << 2) \
84 + (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x1000) >> 13))
85 #define WEBRTC_SPL_MUL_16_32_RSFT15(a, b) \
86 ((WEBRTC_SPL_MUL_16_16(a, (b) >> 16) << 1) \
87 + (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x2000) >> 14))
89 #define WEBRTC_SPL_MUL_16_16_RSFT(a, b, c) \
90 (WEBRTC_SPL_MUL_16_16(a, b) >> (c))
92 #define WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(a, b, c) \
93 ((WEBRTC_SPL_MUL_16_16(a, b) + ((int32_t) \
94 (((int32_t)1) << ((c) - 1)))) >> (c))
96 // C + the 32 most significant bits of A * B
97 #define WEBRTC_SPL_SCALEDIFF32(A, B, C) \
98 (C + (B >> 16) * A + (((uint32_t)(0x0000FFFF & B) * A) >> 16))
100 #define WEBRTC_SPL_ADD_SAT_W32(a, b) WebRtcSpl_AddSatW32(a, b)
101 #define WEBRTC_SPL_SAT(a, b, c) (b > a ? a : b < c ? c : b)
102 #define WEBRTC_SPL_MUL_32_16(a, b) ((a) * (b))
104 #define WEBRTC_SPL_ADD_SAT_W16(a, b) WebRtcSpl_AddSatW16(a, b)
106 // Shifting with negative numbers allowed
107 // Positive means left shift
108 #define WEBRTC_SPL_SHIFT_W32(x, c) \
109 (((c) >= 0) ? ((x) << (c)) : ((x) >> (-(c))))
111 // Shifting with negative numbers not allowed
112 // We cannot do casting here due to signed/unsigned problem
113 #define WEBRTC_SPL_RSHIFT_W16(x, c) ((x) >> (c))
114 #define WEBRTC_SPL_LSHIFT_W16(x, c) ((x) << (c))
115 #define WEBRTC_SPL_RSHIFT_W32(x, c) ((x) >> (c))
116 #define WEBRTC_SPL_LSHIFT_W32(x, c) ((x) << (c))
118 #define WEBRTC_SPL_RSHIFT_U32(x, c) ((uint32_t)(x) >> (c))
119 #define WEBRTC_SPL_LSHIFT_U32(x, c) ((uint32_t)(x) << (c))
121 #define WEBRTC_SPL_RAND(a) \
122 ((int16_t)(WEBRTC_SPL_MUL_16_16_RSFT((a), 18816, 7) & 0x00007fff))
128 #define WEBRTC_SPL_MEMCPY_W8(v1, v2, length) \
129 memcpy(v1, v2, (length) * sizeof(char))
130 #define WEBRTC_SPL_MEMCPY_W16(v1, v2, length) \
131 memcpy(v1, v2, (length) * sizeof(int16_t))
133 #define WEBRTC_SPL_MEMMOVE_W16(v1, v2, length) \
134 memmove(v1, v2, (length) * sizeof(int16_t))
137 #include "webrtc/common_audio/signal_processing/include/spl_inl.h"
139 // Initialize SPL. Currently it contains only function pointer initialization.
140 // If the underlying platform is known to be ARM-Neon (WEBRTC_ARCH_ARM_NEON
141 // defined), the pointers will be assigned to code optimized for Neon; otherwise
142 // if run-time Neon detection (WEBRTC_DETECT_ARM_NEON) is enabled, the pointers
143 // will be assigned to either Neon code or generic C code; otherwise, generic C
144 // code will be assigned.
145 // Note that this function MUST be called in any application that uses SPL
147 void WebRtcSpl_Init();
150 int16_t WebRtcSpl_get_version(char* version, int16_t length_in_bytes);
152 int WebRtcSpl_GetScalingSquare(int16_t* in_vector,
153 int in_vector_length,
156 // Copy and set operations. Implementation in copy_set_operations.c.
157 // Descriptions at bottom of file.
158 void WebRtcSpl_MemSetW16(int16_t* vector,
161 void WebRtcSpl_MemSetW32(int32_t* vector,
164 void WebRtcSpl_MemCpyReversedOrder(int16_t* out_vector,
167 int16_t WebRtcSpl_CopyFromEndW16(const int16_t* in_vector,
168 int16_t in_vector_length,
170 int16_t* out_vector);
171 int16_t WebRtcSpl_ZerosArrayW16(int16_t* vector,
172 int16_t vector_length);
173 int16_t WebRtcSpl_ZerosArrayW32(int32_t* vector,
174 int16_t vector_length);
175 int16_t WebRtcSpl_OnesArrayW16(int16_t* vector,
176 int16_t vector_length);
177 int16_t WebRtcSpl_OnesArrayW32(int32_t* vector,
178 int16_t vector_length);
179 // End: Copy and set operations.
182 // Minimum and maximum operation functions and their pointers.
183 // Implementation in min_max_operations.c.
185 // Returns the largest absolute value in a signed 16-bit vector.
188 // - vector : 16-bit input vector.
189 // - length : Number of samples in vector.
191 // Return value : Maximum absolute value in vector;
192 // or -1, if (vector == NULL || length <= 0).
193 typedef int16_t (*MaxAbsValueW16)(const int16_t* vector, int length);
194 extern MaxAbsValueW16 WebRtcSpl_MaxAbsValueW16;
195 int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, int length);
196 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
197 int16_t WebRtcSpl_MaxAbsValueW16Neon(const int16_t* vector, int length);
199 #if defined(MIPS32_LE)
200 int16_t WebRtcSpl_MaxAbsValueW16_mips(const int16_t* vector, int length);
203 // Returns the largest absolute value in a signed 32-bit vector.
206 // - vector : 32-bit input vector.
207 // - length : Number of samples in vector.
209 // Return value : Maximum absolute value in vector;
210 // or -1, if (vector == NULL || length <= 0).
211 typedef int32_t (*MaxAbsValueW32)(const int32_t* vector, int length);
212 extern MaxAbsValueW32 WebRtcSpl_MaxAbsValueW32;
213 int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, int length);
214 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
215 int32_t WebRtcSpl_MaxAbsValueW32Neon(const int32_t* vector, int length);
217 #if defined(MIPS_DSP_R1_LE)
218 int32_t WebRtcSpl_MaxAbsValueW32_mips(const int32_t* vector, int length);
221 // Returns the maximum value of a 16-bit vector.
224 // - vector : 16-bit input vector.
225 // - length : Number of samples in vector.
227 // Return value : Maximum sample value in |vector|.
228 // If (vector == NULL || length <= 0) WEBRTC_SPL_WORD16_MIN
229 // is returned. Note that WEBRTC_SPL_WORD16_MIN is a feasible
230 // value and we can't catch errors purely based on it.
231 typedef int16_t (*MaxValueW16)(const int16_t* vector, int length);
232 extern MaxValueW16 WebRtcSpl_MaxValueW16;
233 int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, int length);
234 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
235 int16_t WebRtcSpl_MaxValueW16Neon(const int16_t* vector, int length);
237 #if defined(MIPS32_LE)
238 int16_t WebRtcSpl_MaxValueW16_mips(const int16_t* vector, int length);
241 // Returns the maximum value of a 32-bit vector.
244 // - vector : 32-bit input vector.
245 // - length : Number of samples in vector.
247 // Return value : Maximum sample value in |vector|.
248 // If (vector == NULL || length <= 0) WEBRTC_SPL_WORD32_MIN
249 // is returned. Note that WEBRTC_SPL_WORD32_MIN is a feasible
250 // value and we can't catch errors purely based on it.
251 typedef int32_t (*MaxValueW32)(const int32_t* vector, int length);
252 extern MaxValueW32 WebRtcSpl_MaxValueW32;
253 int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, int length);
254 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
255 int32_t WebRtcSpl_MaxValueW32Neon(const int32_t* vector, int length);
257 #if defined(MIPS32_LE)
258 int32_t WebRtcSpl_MaxValueW32_mips(const int32_t* vector, int length);
261 // Returns the minimum value of a 16-bit vector.
264 // - vector : 16-bit input vector.
265 // - length : Number of samples in vector.
267 // Return value : Minimum sample value in |vector|.
268 // If (vector == NULL || length <= 0) WEBRTC_SPL_WORD16_MAX
269 // is returned. Note that WEBRTC_SPL_WORD16_MAX is a feasible
270 // value and we can't catch errors purely based on it.
271 typedef int16_t (*MinValueW16)(const int16_t* vector, int length);
272 extern MinValueW16 WebRtcSpl_MinValueW16;
273 int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, int length);
274 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
275 int16_t WebRtcSpl_MinValueW16Neon(const int16_t* vector, int length);
277 #if defined(MIPS32_LE)
278 int16_t WebRtcSpl_MinValueW16_mips(const int16_t* vector, int length);
281 // Returns the minimum value of a 32-bit vector.
284 // - vector : 32-bit input vector.
285 // - length : Number of samples in vector.
287 // Return value : Minimum sample value in |vector|.
288 // If (vector == NULL || length <= 0) WEBRTC_SPL_WORD32_MAX
289 // is returned. Note that WEBRTC_SPL_WORD32_MAX is a feasible
290 // value and we can't catch errors purely based on it.
291 typedef int32_t (*MinValueW32)(const int32_t* vector, int length);
292 extern MinValueW32 WebRtcSpl_MinValueW32;
293 int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, int length);
294 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
295 int32_t WebRtcSpl_MinValueW32Neon(const int32_t* vector, int length);
297 #if defined(MIPS32_LE)
298 int32_t WebRtcSpl_MinValueW32_mips(const int32_t* vector, int length);
301 // Returns the vector index to the largest absolute value of a 16-bit vector.
304 // - vector : 16-bit input vector.
305 // - length : Number of samples in vector.
307 // Return value : Index to the maximum absolute value in vector, or -1,
308 // if (vector == NULL || length <= 0).
309 // If there are multiple equal maxima, return the index of the
310 // first. -32768 will always have precedence over 32767 (despite
311 // -32768 presenting an int16 absolute value of 32767);
312 int WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, int length);
314 // Returns the vector index to the maximum sample value of a 16-bit vector.
317 // - vector : 16-bit input vector.
318 // - length : Number of samples in vector.
320 // Return value : Index to the maximum value in vector (if multiple
321 // indexes have the maximum, return the first);
322 // or -1, if (vector == NULL || length <= 0).
323 int WebRtcSpl_MaxIndexW16(const int16_t* vector, int length);
325 // Returns the vector index to the maximum sample value of a 32-bit vector.
328 // - vector : 32-bit input vector.
329 // - length : Number of samples in vector.
331 // Return value : Index to the maximum value in vector (if multiple
332 // indexes have the maximum, return the first);
333 // or -1, if (vector == NULL || length <= 0).
334 int WebRtcSpl_MaxIndexW32(const int32_t* vector, int length);
336 // Returns the vector index to the minimum sample value of a 16-bit vector.
339 // - vector : 16-bit input vector.
340 // - length : Number of samples in vector.
342 // Return value : Index to the mimimum value in vector (if multiple
343 // indexes have the minimum, return the first);
344 // or -1, if (vector == NULL || length <= 0).
345 int WebRtcSpl_MinIndexW16(const int16_t* vector, int length);
347 // Returns the vector index to the minimum sample value of a 32-bit vector.
350 // - vector : 32-bit input vector.
351 // - length : Number of samples in vector.
353 // Return value : Index to the mimimum value in vector (if multiple
354 // indexes have the minimum, return the first);
355 // or -1, if (vector == NULL || length <= 0).
356 int WebRtcSpl_MinIndexW32(const int32_t* vector, int length);
358 // End: Minimum and maximum operations.
361 // Vector scaling operations. Implementation in vector_scaling_operations.c.
362 // Description at bottom of file.
363 void WebRtcSpl_VectorBitShiftW16(int16_t* out_vector,
364 int16_t vector_length,
365 const int16_t* in_vector,
366 int16_t right_shifts);
367 void WebRtcSpl_VectorBitShiftW32(int32_t* out_vector,
368 int16_t vector_length,
369 const int32_t* in_vector,
370 int16_t right_shifts);
371 void WebRtcSpl_VectorBitShiftW32ToW16(int16_t* out_vector,
373 const int32_t* in_vector,
375 void WebRtcSpl_ScaleVector(const int16_t* in_vector,
378 int16_t vector_length,
379 int16_t right_shifts);
380 void WebRtcSpl_ScaleVectorWithSat(const int16_t* in_vector,
383 int16_t vector_length,
384 int16_t right_shifts);
385 void WebRtcSpl_ScaleAndAddVectors(const int16_t* in_vector1,
386 int16_t gain1, int right_shifts1,
387 const int16_t* in_vector2,
388 int16_t gain2, int right_shifts2,
392 // The functions (with related pointer) perform the vector operation:
393 // out_vector[k] = ((scale1 * in_vector1[k]) + (scale2 * in_vector2[k])
394 // + round_value) >> right_shifts,
395 // where round_value = (1 << right_shifts) >> 1.
398 // - in_vector1 : Input vector 1
399 // - in_vector1_scale : Gain to be used for vector 1
400 // - in_vector2 : Input vector 2
401 // - in_vector2_scale : Gain to be used for vector 2
402 // - right_shifts : Number of right bit shifts to be applied
403 // - length : Number of elements in the input vectors
406 // - out_vector : Output vector
407 // Return value : 0 if OK, -1 if (in_vector1 == NULL
408 // || in_vector2 == NULL || out_vector == NULL
409 // || length <= 0 || right_shift < 0).
410 typedef int (*ScaleAndAddVectorsWithRound)(const int16_t* in_vector1,
411 int16_t in_vector1_scale,
412 const int16_t* in_vector2,
413 int16_t in_vector2_scale,
417 extern ScaleAndAddVectorsWithRound WebRtcSpl_ScaleAndAddVectorsWithRound;
418 int WebRtcSpl_ScaleAndAddVectorsWithRoundC(const int16_t* in_vector1,
419 int16_t in_vector1_scale,
420 const int16_t* in_vector2,
421 int16_t in_vector2_scale,
425 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
426 int WebRtcSpl_ScaleAndAddVectorsWithRoundNeon(const int16_t* in_vector1,
427 int16_t in_vector1_scale,
428 const int16_t* in_vector2,
429 int16_t in_vector2_scale,
434 #if defined(MIPS_DSP_R1_LE)
435 int WebRtcSpl_ScaleAndAddVectorsWithRound_mips(const int16_t* in_vector1,
436 int16_t in_vector1_scale,
437 const int16_t* in_vector2,
438 int16_t in_vector2_scale,
443 // End: Vector scaling operations.
445 // iLBC specific functions. Implementations in ilbc_specific_functions.c.
446 // Description at bottom of file.
447 void WebRtcSpl_ReverseOrderMultArrayElements(int16_t* out_vector,
448 const int16_t* in_vector,
449 const int16_t* window,
450 int16_t vector_length,
451 int16_t right_shifts);
452 void WebRtcSpl_ElementwiseVectorMult(int16_t* out_vector,
453 const int16_t* in_vector,
454 const int16_t* window,
455 int16_t vector_length,
456 int16_t right_shifts);
457 void WebRtcSpl_AddVectorsAndShift(int16_t* out_vector,
458 const int16_t* in_vector1,
459 const int16_t* in_vector2,
460 int16_t vector_length,
461 int16_t right_shifts);
462 void WebRtcSpl_AddAffineVectorToVector(int16_t* out_vector,
465 int32_t add_constant,
466 int16_t right_shifts,
468 void WebRtcSpl_AffineTransformVector(int16_t* out_vector,
471 int32_t add_constant,
472 int16_t right_shifts,
474 // End: iLBC specific functions.
476 // Signal processing operations.
478 // A 32-bit fix-point implementation of auto-correlation computation
481 // - in_vector : Vector to calculate autocorrelation upon
482 // - in_vector_length : Length (in samples) of |vector|
483 // - order : The order up to which the autocorrelation should be
487 // - result : auto-correlation values (values should be seen
488 // relative to each other since the absolute values
489 // might have been down shifted to avoid overflow)
491 // - scale : The number of left shifts required to obtain the
492 // auto-correlation in Q0
495 // - -1, if |order| > |in_vector_length|;
496 // - Number of samples in |result|, i.e. (order+1), otherwise.
497 int WebRtcSpl_AutoCorrelation(const int16_t* in_vector,
498 int in_vector_length,
503 // A 32-bit fix-point implementation of the Levinson-Durbin algorithm that
504 // does NOT use the 64 bit class
507 // - auto_corr : Vector with autocorrelation values of length >=
509 // - use_order : The LPC filter order (support up to order 20)
512 // - lpc_coef : lpc_coef[0..use_order] LPC coefficients in Q12
513 // - refl_coef : refl_coef[0...use_order-1]| Reflection coefficients in
516 // Return value : 1 for stable 0 for unstable
517 int16_t WebRtcSpl_LevinsonDurbin(int32_t* auto_corr,
522 // Converts reflection coefficients |refl_coef| to LPC coefficients |lpc_coef|.
523 // This version is a 16 bit operation.
525 // NOTE: The 16 bit refl_coef -> lpc_coef conversion might result in a
526 // "slightly unstable" filter (i.e., a pole just outside the unit circle) in
527 // "rare" cases even if the reflection coefficients are stable.
530 // - refl_coef : Reflection coefficients in Q15 that should be converted
531 // to LPC coefficients
532 // - use_order : Number of coefficients in |refl_coef|
535 // - lpc_coef : LPC coefficients in Q12
536 void WebRtcSpl_ReflCoefToLpc(const int16_t* refl_coef,
540 // Converts LPC coefficients |lpc_coef| to reflection coefficients |refl_coef|.
541 // This version is a 16 bit operation.
542 // The conversion is implemented by the step-down algorithm.
545 // - lpc_coef : LPC coefficients in Q12, that should be converted to
546 // reflection coefficients
547 // - use_order : Number of coefficients in |lpc_coef|
550 // - refl_coef : Reflection coefficients in Q15.
551 void WebRtcSpl_LpcToReflCoef(int16_t* lpc_coef,
555 // Calculates reflection coefficients (16 bit) from auto-correlation values
558 // - auto_corr : Auto-correlation values
559 // - use_order : Number of coefficients wanted be calculated
562 // - refl_coef : Reflection coefficients in Q15.
563 void WebRtcSpl_AutoCorrToReflCoef(const int32_t* auto_corr,
567 // The functions (with related pointer) calculate the cross-correlation between
568 // two sequences |seq1| and |seq2|.
569 // |seq1| is fixed and |seq2| slides as the pointer is increased with the
570 // amount |step_seq2|. Note the arguments should obey the relationship:
571 // |dim_seq| - 1 + |step_seq2| * (|dim_cross_correlation| - 1) <
572 // buffer size of |seq2|
575 // - seq1 : First sequence (fixed throughout the correlation)
576 // - seq2 : Second sequence (slides |step_vector2| for each
578 // - dim_seq : Number of samples to use in the cross-correlation
579 // - dim_cross_correlation : Number of cross-correlations to calculate (the
580 // start position for |vector2| is updated for each
582 // - right_shifts : Number of right bit shifts to use. This will
583 // become the output Q-domain.
584 // - step_seq2 : How many (positive or negative) steps the
585 // |vector2| pointer should be updated for each new
586 // cross-correlation value.
589 // - cross_correlation : The cross-correlation in Q(-right_shifts)
590 typedef void (*CrossCorrelation)(int32_t* cross_correlation,
594 int16_t dim_cross_correlation,
595 int16_t right_shifts,
597 extern CrossCorrelation WebRtcSpl_CrossCorrelation;
598 void WebRtcSpl_CrossCorrelationC(int32_t* cross_correlation,
602 int16_t dim_cross_correlation,
603 int16_t right_shifts,
605 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
606 void WebRtcSpl_CrossCorrelationNeon(int32_t* cross_correlation,
610 int16_t dim_cross_correlation,
611 int16_t right_shifts,
614 #if defined(MIPS32_LE)
615 void WebRtcSpl_CrossCorrelation_mips(int32_t* cross_correlation,
619 int16_t dim_cross_correlation,
620 int16_t right_shifts,
624 // Creates (the first half of) a Hanning window. Size must be at least 1 and
628 // - size : Length of the requested Hanning window (1 to 512)
631 // - window : Hanning vector in Q14.
632 void WebRtcSpl_GetHanningWindow(int16_t* window, int16_t size);
634 // Calculates y[k] = sqrt(1 - x[k]^2) for each element of the input vector
635 // |in_vector|. Input and output values are in Q15.
638 // - in_vector : Values to calculate sqrt(1 - x^2) of
639 // - vector_length : Length of vector |in_vector|
642 // - out_vector : Output values in Q15
643 void WebRtcSpl_SqrtOfOneMinusXSquared(int16_t* in_vector,
645 int16_t* out_vector);
646 // End: Signal processing operations.
648 // Randomization functions. Implementations collected in
649 // randomization_functions.c and descriptions at bottom of this file.
650 int16_t WebRtcSpl_RandU(uint32_t* seed);
651 int16_t WebRtcSpl_RandN(uint32_t* seed);
652 int16_t WebRtcSpl_RandUArray(int16_t* vector,
653 int16_t vector_length,
655 // End: Randomization functions.
658 int32_t WebRtcSpl_Sqrt(int32_t value);
659 int32_t WebRtcSpl_SqrtFloor(int32_t value);
661 // Divisions. Implementations collected in division_operations.c and
662 // descriptions at bottom of this file.
663 uint32_t WebRtcSpl_DivU32U16(uint32_t num, uint16_t den);
664 int32_t WebRtcSpl_DivW32W16(int32_t num, int16_t den);
665 int16_t WebRtcSpl_DivW32W16ResW16(int32_t num, int16_t den);
666 int32_t WebRtcSpl_DivResultInQ31(int32_t num, int32_t den);
667 int32_t WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low);
670 int32_t WebRtcSpl_Energy(int16_t* vector, int vector_length, int* scale_factor);
672 // Calculates the dot product between two (int16_t) vectors.
675 // - vector1 : Vector 1
676 // - vector2 : Vector 2
677 // - vector_length : Number of samples used in the dot product
678 // - scaling : The number of right bit shifts to apply on each term
679 // during calculation to avoid overflow, i.e., the
680 // output will be in Q(-|scaling|)
682 // Return value : The dot product in Q(-scaling)
683 int32_t WebRtcSpl_DotProductWithScale(const int16_t* vector1,
684 const int16_t* vector2,
688 // Filter operations.
689 int WebRtcSpl_FilterAR(const int16_t* ar_coef,
691 const int16_t* in_vector,
692 int in_vector_length,
693 int16_t* filter_state,
694 int filter_state_length,
695 int16_t* filter_state_low,
696 int filter_state_low_length,
698 int16_t* out_vector_low,
699 int out_vector_low_length);
701 void WebRtcSpl_FilterMAFastQ12(int16_t* in_vector,
704 int16_t ma_coef_length,
705 int16_t vector_length);
707 // Performs a AR filtering on a vector in Q12
709 // - data_in : Input samples
710 // - data_out : State information in positions
711 // data_out[-order] .. data_out[-1]
712 // - coefficients : Filter coefficients (in Q12)
713 // - coefficients_length: Number of coefficients (order+1)
714 // - data_length : Number of samples to be filtered
716 // - data_out : Filtered samples
717 void WebRtcSpl_FilterARFastQ12(const int16_t* data_in,
719 const int16_t* __restrict coefficients,
720 int coefficients_length,
723 // The functions (with related pointer) perform a MA down sampling filter
726 // - data_in : Input samples (state in positions
727 // data_in[-order] .. data_in[-1])
728 // - data_in_length : Number of samples in |data_in| to be filtered.
729 // This must be at least
730 // |delay| + |factor|*(|out_vector_length|-1) + 1)
731 // - data_out_length : Number of down sampled samples desired
732 // - coefficients : Filter coefficients (in Q12)
733 // - coefficients_length: Number of coefficients (order+1)
734 // - factor : Decimation factor
735 // - delay : Delay of filter (compensated for in out_vector)
737 // - data_out : Filtered samples
738 // Return value : 0 if OK, -1 if |in_vector| is too short
739 typedef int (*DownsampleFast)(const int16_t* data_in,
743 const int16_t* __restrict coefficients,
744 int coefficients_length,
747 extern DownsampleFast WebRtcSpl_DownsampleFast;
748 int WebRtcSpl_DownsampleFastC(const int16_t* data_in,
752 const int16_t* __restrict coefficients,
753 int coefficients_length,
756 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
757 int WebRtcSpl_DownsampleFastNeon(const int16_t* data_in,
761 const int16_t* __restrict coefficients,
762 int coefficients_length,
766 #if defined(MIPS32_LE)
767 int WebRtcSpl_DownsampleFast_mips(const int16_t* data_in,
771 const int16_t* __restrict coefficients,
772 int coefficients_length,
777 // End: Filter operations.
781 int WebRtcSpl_ComplexFFT(int16_t vector[], int stages, int mode);
782 int WebRtcSpl_ComplexIFFT(int16_t vector[], int stages, int mode);
784 // Treat a 16-bit complex data buffer |complex_data| as an array of 32-bit
785 // values, and swap elements whose indexes are bit-reverses of each other.
788 // - complex_data : Complex data buffer containing 2^|stages| real
789 // elements interleaved with 2^|stages| imaginary
790 // elements: [Re Im Re Im Re Im....]
791 // - stages : Number of FFT stages. Must be at least 3 and at most
792 // 10, since the table WebRtcSpl_kSinTable1024[] is 1024
796 // - complex_data : The complex data buffer.
798 void WebRtcSpl_ComplexBitReverse(int16_t* __restrict complex_data, int stages);
800 // End: FFT operations
802 /************************************************************
804 * RESAMPLING FUNCTIONS AND THEIR STRUCTS ARE DEFINED BELOW
806 ************************************************************/
808 /*******************************************************************
811 * Includes the following resampling combinations
817 ******************************************************************/
819 // state structure for 22 -> 16 resampler
824 } WebRtcSpl_State22khzTo16khz;
826 void WebRtcSpl_Resample22khzTo16khz(const int16_t* in,
828 WebRtcSpl_State22khzTo16khz* state,
831 void WebRtcSpl_ResetResample22khzTo16khz(WebRtcSpl_State22khzTo16khz* state);
833 // state structure for 16 -> 22 resampler
837 } WebRtcSpl_State16khzTo22khz;
839 void WebRtcSpl_Resample16khzTo22khz(const int16_t* in,
841 WebRtcSpl_State16khzTo22khz* state,
844 void WebRtcSpl_ResetResample16khzTo22khz(WebRtcSpl_State16khzTo22khz* state);
846 // state structure for 22 -> 8 resampler
851 } WebRtcSpl_State22khzTo8khz;
853 void WebRtcSpl_Resample22khzTo8khz(const int16_t* in, int16_t* out,
854 WebRtcSpl_State22khzTo8khz* state,
857 void WebRtcSpl_ResetResample22khzTo8khz(WebRtcSpl_State22khzTo8khz* state);
859 // state structure for 8 -> 22 resampler
864 } WebRtcSpl_State8khzTo22khz;
866 void WebRtcSpl_Resample8khzTo22khz(const int16_t* in, int16_t* out,
867 WebRtcSpl_State8khzTo22khz* state,
870 void WebRtcSpl_ResetResample8khzTo22khz(WebRtcSpl_State8khzTo22khz* state);
872 /*******************************************************************
873 * resample_fractional.c
874 * Functions for internal use in the other resample functions
876 * Includes the following resampling combinations
881 ******************************************************************/
883 void WebRtcSpl_Resample48khzTo32khz(const int32_t* In, int32_t* Out,
886 void WebRtcSpl_Resample32khzTo24khz(const int32_t* In, int32_t* Out,
889 void WebRtcSpl_Resample44khzTo32khz(const int32_t* In, int32_t* Out,
892 /*******************************************************************
895 * Includes the following resampling combinations
901 ******************************************************************/
907 } WebRtcSpl_State48khzTo16khz;
909 void WebRtcSpl_Resample48khzTo16khz(const int16_t* in, int16_t* out,
910 WebRtcSpl_State48khzTo16khz* state,
913 void WebRtcSpl_ResetResample48khzTo16khz(WebRtcSpl_State48khzTo16khz* state);
919 } WebRtcSpl_State16khzTo48khz;
921 void WebRtcSpl_Resample16khzTo48khz(const int16_t* in, int16_t* out,
922 WebRtcSpl_State16khzTo48khz* state,
925 void WebRtcSpl_ResetResample16khzTo48khz(WebRtcSpl_State16khzTo48khz* state);
932 } WebRtcSpl_State48khzTo8khz;
934 void WebRtcSpl_Resample48khzTo8khz(const int16_t* in, int16_t* out,
935 WebRtcSpl_State48khzTo8khz* state,
938 void WebRtcSpl_ResetResample48khzTo8khz(WebRtcSpl_State48khzTo8khz* state);
945 } WebRtcSpl_State8khzTo48khz;
947 void WebRtcSpl_Resample8khzTo48khz(const int16_t* in, int16_t* out,
948 WebRtcSpl_State8khzTo48khz* state,
951 void WebRtcSpl_ResetResample8khzTo48khz(WebRtcSpl_State8khzTo48khz* state);
953 /*******************************************************************
956 * Includes down and up sampling by a factor of two.
958 ******************************************************************/
960 void WebRtcSpl_DownsampleBy2(const int16_t* in, int16_t len,
961 int16_t* out, int32_t* filtState);
963 void WebRtcSpl_UpsampleBy2(const int16_t* in, int16_t len,
964 int16_t* out, int32_t* filtState);
966 /************************************************************
967 * END OF RESAMPLING FUNCTIONS
968 ************************************************************/
969 void WebRtcSpl_AnalysisQMF(const int16_t* in_data,
973 int32_t* filter_state1,
974 int32_t* filter_state2);
975 void WebRtcSpl_SynthesisQMF(const int16_t* low_band,
976 const int16_t* high_band,
979 int32_t* filter_state1,
980 int32_t* filter_state2);
984 #endif // __cplusplus
985 #endif // WEBRTC_SPL_SIGNAL_PROCESSING_LIBRARY_H_
988 // WebRtcSpl_AddSatW16(...)
989 // WebRtcSpl_AddSatW32(...)
991 // Returns the result of a saturated 16-bit, respectively 32-bit, addition of
992 // the numbers specified by the |var1| and |var2| parameters.
995 // - var1 : Input variable 1
996 // - var2 : Input variable 2
998 // Return value : Added and saturated value
1002 // WebRtcSpl_SubSatW16(...)
1003 // WebRtcSpl_SubSatW32(...)
1005 // Returns the result of a saturated 16-bit, respectively 32-bit, subtraction
1006 // of the numbers specified by the |var1| and |var2| parameters.
1009 // - var1 : Input variable 1
1010 // - var2 : Input variable 2
1012 // Returned value : Subtracted and saturated value
1016 // WebRtcSpl_GetSizeInBits(...)
1018 // Returns the # of bits that are needed at the most to represent the number
1019 // specified by the |value| parameter.
1022 // - value : Input value
1024 // Return value : Number of bits needed to represent |value|
1028 // WebRtcSpl_NormW32(...)
1030 // Norm returns the # of left shifts required to 32-bit normalize the 32-bit
1031 // signed number specified by the |value| parameter.
1034 // - value : Input value
1036 // Return value : Number of bit shifts needed to 32-bit normalize |value|
1040 // WebRtcSpl_NormW16(...)
1042 // Norm returns the # of left shifts required to 16-bit normalize the 16-bit
1043 // signed number specified by the |value| parameter.
1046 // - value : Input value
1048 // Return value : Number of bit shifts needed to 32-bit normalize |value|
1052 // WebRtcSpl_NormU32(...)
1054 // Norm returns the # of left shifts required to 32-bit normalize the unsigned
1055 // 32-bit number specified by the |value| parameter.
1058 // - value : Input value
1060 // Return value : Number of bit shifts needed to 32-bit normalize |value|
1064 // WebRtcSpl_GetScalingSquare(...)
1066 // Returns the # of bits required to scale the samples specified in the
1067 // |in_vector| parameter so that, if the squares of the samples are added the
1068 // # of times specified by the |times| parameter, the 32-bit addition will not
1069 // overflow (result in int32_t).
1072 // - in_vector : Input vector to check scaling on
1073 // - in_vector_length : Samples in |in_vector|
1074 // - times : Number of additions to be performed
1076 // Return value : Number of right bit shifts needed to avoid
1077 // overflow in the addition calculation
1081 // WebRtcSpl_MemSetW16(...)
1083 // Sets all the values in the int16_t vector |vector| of length
1084 // |vector_length| to the specified value |set_value|
1087 // - vector : Pointer to the int16_t vector
1088 // - set_value : Value specified
1089 // - vector_length : Length of vector
1093 // WebRtcSpl_MemSetW32(...)
1095 // Sets all the values in the int32_t vector |vector| of length
1096 // |vector_length| to the specified value |set_value|
1099 // - vector : Pointer to the int16_t vector
1100 // - set_value : Value specified
1101 // - vector_length : Length of vector
1105 // WebRtcSpl_MemCpyReversedOrder(...)
1107 // Copies all the values from the source int16_t vector |in_vector| to a
1108 // destination int16_t vector |out_vector|. It is done in reversed order,
1109 // meaning that the first sample of |in_vector| is copied to the last sample of
1110 // the |out_vector|. The procedure continues until the last sample of
1111 // |in_vector| has been copied to the first sample of |out_vector|. This
1112 // creates a reversed vector. Used in e.g. prediction in iLBC.
1115 // - in_vector : Pointer to the first sample in a int16_t vector
1116 // of length |length|
1117 // - vector_length : Number of elements to copy
1120 // - out_vector : Pointer to the last sample in a int16_t vector
1121 // of length |length|
1125 // WebRtcSpl_CopyFromEndW16(...)
1127 // Copies the rightmost |samples| of |in_vector| (of length |in_vector_length|)
1128 // to the vector |out_vector|.
1131 // - in_vector : Input vector
1132 // - in_vector_length : Number of samples in |in_vector|
1133 // - samples : Number of samples to extract (from right side)
1137 // - out_vector : Vector with the requested samples
1139 // Return value : Number of copied samples in |out_vector|
1143 // WebRtcSpl_ZerosArrayW16(...)
1144 // WebRtcSpl_ZerosArrayW32(...)
1146 // Inserts the value "zero" in all positions of a w16 and a w32 vector
1150 // - vector_length : Number of samples in vector
1153 // - vector : Vector containing all zeros
1155 // Return value : Number of samples in vector
1159 // WebRtcSpl_OnesArrayW16(...)
1160 // WebRtcSpl_OnesArrayW32(...)
1162 // Inserts the value "one" in all positions of a w16 and a w32 vector
1166 // - vector_length : Number of samples in vector
1169 // - vector : Vector containing all ones
1171 // Return value : Number of samples in vector
1175 // WebRtcSpl_VectorBitShiftW16(...)
1176 // WebRtcSpl_VectorBitShiftW32(...)
1178 // Bit shifts all the values in a vector up or downwards. Different calls for
1179 // int16_t and int32_t vectors respectively.
1182 // - vector_length : Length of vector
1183 // - in_vector : Pointer to the vector that should be bit shifted
1184 // - right_shifts : Number of right bit shifts (negative value gives left
1188 // - out_vector : Pointer to the result vector (can be the same as
1193 // WebRtcSpl_VectorBitShiftW32ToW16(...)
1195 // Bit shifts all the values in a int32_t vector up or downwards and
1196 // stores the result as an int16_t vector. The function will saturate the
1197 // signal if needed, before storing in the output vector.
1200 // - vector_length : Length of vector
1201 // - in_vector : Pointer to the vector that should be bit shifted
1202 // - right_shifts : Number of right bit shifts (negative value gives left
1206 // - out_vector : Pointer to the result vector (can be the same as
1211 // WebRtcSpl_ScaleVector(...)
1213 // Performs the vector operation:
1214 // out_vector[k] = (gain*in_vector[k])>>right_shifts
1217 // - in_vector : Input vector
1218 // - gain : Scaling gain
1219 // - vector_length : Elements in the |in_vector|
1220 // - right_shifts : Number of right bit shifts applied
1223 // - out_vector : Output vector (can be the same as |in_vector|)
1227 // WebRtcSpl_ScaleVectorWithSat(...)
1229 // Performs the vector operation:
1230 // out_vector[k] = SATURATE( (gain*in_vector[k])>>right_shifts )
1233 // - in_vector : Input vector
1234 // - gain : Scaling gain
1235 // - vector_length : Elements in the |in_vector|
1236 // - right_shifts : Number of right bit shifts applied
1239 // - out_vector : Output vector (can be the same as |in_vector|)
1243 // WebRtcSpl_ScaleAndAddVectors(...)
1245 // Performs the vector operation:
1246 // out_vector[k] = (gain1*in_vector1[k])>>right_shifts1
1247 // + (gain2*in_vector2[k])>>right_shifts2
1250 // - in_vector1 : Input vector 1
1251 // - gain1 : Gain to be used for vector 1
1252 // - right_shifts1 : Right bit shift to be used for vector 1
1253 // - in_vector2 : Input vector 2
1254 // - gain2 : Gain to be used for vector 2
1255 // - right_shifts2 : Right bit shift to be used for vector 2
1256 // - vector_length : Elements in the input vectors
1259 // - out_vector : Output vector
1263 // WebRtcSpl_ReverseOrderMultArrayElements(...)
1265 // Performs the vector operation:
1266 // out_vector[n] = (in_vector[n]*window[-n])>>right_shifts
1269 // - in_vector : Input vector
1270 // - window : Window vector (should be reversed). The pointer
1271 // should be set to the last value in the vector
1272 // - right_shifts : Number of right bit shift to be applied after the
1274 // - vector_length : Number of elements in |in_vector|
1277 // - out_vector : Output vector (can be same as |in_vector|)
1281 // WebRtcSpl_ElementwiseVectorMult(...)
1283 // Performs the vector operation:
1284 // out_vector[n] = (in_vector[n]*window[n])>>right_shifts
1287 // - in_vector : Input vector
1288 // - window : Window vector.
1289 // - right_shifts : Number of right bit shift to be applied after the
1291 // - vector_length : Number of elements in |in_vector|
1294 // - out_vector : Output vector (can be same as |in_vector|)
1298 // WebRtcSpl_AddVectorsAndShift(...)
1300 // Performs the vector operation:
1301 // out_vector[k] = (in_vector1[k] + in_vector2[k])>>right_shifts
1304 // - in_vector1 : Input vector 1
1305 // - in_vector2 : Input vector 2
1306 // - right_shifts : Number of right bit shift to be applied after the
1308 // - vector_length : Number of elements in |in_vector1| and |in_vector2|
1311 // - out_vector : Output vector (can be same as |in_vector1|)
1315 // WebRtcSpl_AddAffineVectorToVector(...)
1317 // Adds an affine transformed vector to another vector |out_vector|, i.e,
1319 // out_vector[k] += (in_vector[k]*gain+add_constant)>>right_shifts
1322 // - in_vector : Input vector
1323 // - gain : Gain value, used to multiply the in vector with
1324 // - add_constant : Constant value to add (usually 1<<(right_shifts-1),
1325 // but others can be used as well
1326 // - right_shifts : Number of right bit shifts (0-16)
1327 // - vector_length : Number of samples in |in_vector| and |out_vector|
1330 // - out_vector : Vector with the output
1334 // WebRtcSpl_AffineTransformVector(...)
1336 // Affine transforms a vector, i.e, performs
1337 // out_vector[k] = (in_vector[k]*gain+add_constant)>>right_shifts
1340 // - in_vector : Input vector
1341 // - gain : Gain value, used to multiply the in vector with
1342 // - add_constant : Constant value to add (usually 1<<(right_shifts-1),
1343 // but others can be used as well
1344 // - right_shifts : Number of right bit shifts (0-16)
1345 // - vector_length : Number of samples in |in_vector| and |out_vector|
1348 // - out_vector : Vector with the output
1352 // WebRtcSpl_IncreaseSeed(...)
1354 // Increases the seed (and returns the new value)
1357 // - seed : Seed for random calculation
1360 // - seed : Updated seed value
1362 // Return value : The new seed value
1366 // WebRtcSpl_RandU(...)
1368 // Produces a uniformly distributed value in the int16_t range
1371 // - seed : Seed for random calculation
1374 // - seed : Updated seed value
1376 // Return value : Uniformly distributed value in the range
1377 // [Word16_MIN...Word16_MAX]
1381 // WebRtcSpl_RandN(...)
1383 // Produces a normal distributed value in the int16_t range
1386 // - seed : Seed for random calculation
1389 // - seed : Updated seed value
1391 // Return value : N(0,1) value in the Q13 domain
1395 // WebRtcSpl_RandUArray(...)
1397 // Produces a uniformly distributed vector with elements in the int16_t
1401 // - vector_length : Samples wanted in the vector
1402 // - seed : Seed for random calculation
1405 // - vector : Vector with the uniform values
1406 // - seed : Updated seed value
1408 // Return value : Number of samples in vector, i.e., |vector_length|
1412 // WebRtcSpl_Sqrt(...)
1414 // Returns the square root of the input value |value|. The precision of this
1415 // function is integer precision, i.e., sqrt(8) gives 2 as answer.
1416 // If |value| is a negative number then 0 is returned.
1420 // A sixth order Taylor Series expansion is used here to compute the square
1421 // root of a number y^0.5 = (1+x)^0.5
1424 // = 1+(x/2)-0.5*((x/2)^2+0.5*((x/2)^3-0.625*((x/2)^4+0.875*((x/2)^5)
1428 // - value : Value to calculate sqrt of
1430 // Return value : Result of the sqrt calculation
1434 // WebRtcSpl_SqrtFloor(...)
1436 // Returns the square root of the input value |value|. The precision of this
1437 // function is rounding down integer precision, i.e., sqrt(8) gives 2 as answer.
1438 // If |value| is a negative number then 0 is returned.
1442 // An iterative 4 cylce/bit routine
1445 // - value : Value to calculate sqrt of
1447 // Return value : Result of the sqrt calculation
1451 // WebRtcSpl_DivU32U16(...)
1453 // Divides a uint32_t |num| by a uint16_t |den|.
1455 // If |den|==0, (uint32_t)0xFFFFFFFF is returned.
1458 // - num : Numerator
1459 // - den : Denominator
1461 // Return value : Result of the division (as a uint32_t), i.e., the
1462 // integer part of num/den.
1466 // WebRtcSpl_DivW32W16(...)
1468 // Divides a int32_t |num| by a int16_t |den|.
1470 // If |den|==0, (int32_t)0x7FFFFFFF is returned.
1473 // - num : Numerator
1474 // - den : Denominator
1476 // Return value : Result of the division (as a int32_t), i.e., the
1477 // integer part of num/den.
1481 // WebRtcSpl_DivW32W16ResW16(...)
1483 // Divides a int32_t |num| by a int16_t |den|, assuming that the
1484 // result is less than 32768, otherwise an unpredictable result will occur.
1486 // If |den|==0, (int16_t)0x7FFF is returned.
1489 // - num : Numerator
1490 // - den : Denominator
1492 // Return value : Result of the division (as a int16_t), i.e., the
1493 // integer part of num/den.
1497 // WebRtcSpl_DivResultInQ31(...)
1499 // Divides a int32_t |num| by a int16_t |den|, assuming that the
1500 // absolute value of the denominator is larger than the numerator, otherwise
1501 // an unpredictable result will occur.
1504 // - num : Numerator
1505 // - den : Denominator
1507 // Return value : Result of the division in Q31.
1511 // WebRtcSpl_DivW32HiLow(...)
1513 // Divides a int32_t |num| by a denominator in hi, low format. The
1514 // absolute value of the denominator has to be larger (or equal to) the
1518 // - num : Numerator
1519 // - den_hi : High part of denominator
1520 // - den_low : Low part of denominator
1522 // Return value : Divided value in Q31
1526 // WebRtcSpl_Energy(...)
1528 // Calculates the energy of a vector
1531 // - vector : Vector which the energy should be calculated on
1532 // - vector_length : Number of samples in vector
1535 // - scale_factor : Number of left bit shifts needed to get the physical
1536 // energy value, i.e, to get the Q0 value
1538 // Return value : Energy value in Q(-|scale_factor|)
1542 // WebRtcSpl_FilterAR(...)
1544 // Performs a 32-bit AR filtering on a vector in Q12
1547 // - ar_coef : AR-coefficient vector (values in Q12),
1548 // ar_coef[0] must be 4096.
1549 // - ar_coef_length : Number of coefficients in |ar_coef|.
1550 // - in_vector : Vector to be filtered.
1551 // - in_vector_length : Number of samples in |in_vector|.
1552 // - filter_state : Current state (higher part) of the filter.
1553 // - filter_state_length : Length (in samples) of |filter_state|.
1554 // - filter_state_low : Current state (lower part) of the filter.
1555 // - filter_state_low_length : Length (in samples) of |filter_state_low|.
1556 // - out_vector_low_length : Maximum length (in samples) of
1557 // |out_vector_low|.
1560 // - filter_state : Updated state (upper part) vector.
1561 // - filter_state_low : Updated state (lower part) vector.
1562 // - out_vector : Vector containing the upper part of the
1564 // - out_vector_low : Vector containing the lower part of the
1567 // Return value : Number of samples in the |out_vector|.
1571 // WebRtcSpl_FilterMAFastQ12(...)
1573 // Performs a MA filtering on a vector in Q12
1576 // - in_vector : Input samples (state in positions
1577 // in_vector[-order] .. in_vector[-1])
1578 // - ma_coef : Filter coefficients (in Q12)
1579 // - ma_coef_length : Number of B coefficients (order+1)
1580 // - vector_length : Number of samples to be filtered
1583 // - out_vector : Filtered samples
1587 // WebRtcSpl_ComplexIFFT(...)
1589 // Complex Inverse FFT
1591 // Computes an inverse complex 2^|stages|-point FFT on the input vector, which
1592 // is in bit-reversed order. The original content of the vector is destroyed in
1593 // the process, since the input is overwritten by the output, normal-ordered,
1594 // FFT vector. With X as the input complex vector, y as the output complex
1595 // vector and with M = 2^|stages|, the following is computed:
1598 // y(k) = sum[X(i)*[cos(2*pi*i*k/M) + j*sin(2*pi*i*k/M)]]
1601 // The implementations are optimized for speed, not for code size. It uses the
1602 // decimation-in-time algorithm with radix-2 butterfly technique.
1605 // - vector : In pointer to complex vector containing 2^|stages|
1606 // real elements interleaved with 2^|stages| imaginary
1608 // [ReImReImReIm....]
1609 // The elements are in Q(-scale) domain, see more on Return
1612 // - stages : Number of FFT stages. Must be at least 3 and at most 10,
1613 // since the table WebRtcSpl_kSinTable1024[] is 1024
1616 // - mode : This parameter gives the user to choose how the FFT
1618 // mode==0: Low-complexity and Low-accuracy mode
1619 // mode==1: High-complexity and High-accuracy mode
1622 // - vector : Out pointer to the FFT vector (the same as input).
1624 // Return Value : The scale value that tells the number of left bit shifts
1625 // that the elements in the |vector| should be shifted with
1626 // in order to get Q0 values, i.e. the physically correct
1627 // values. The scale parameter is always 0 or positive,
1628 // except if N>1024 (|stages|>10), which returns a scale
1629 // value of -1, indicating error.
1633 // WebRtcSpl_ComplexFFT(...)
1637 // Computes a complex 2^|stages|-point FFT on the input vector, which is in
1638 // bit-reversed order. The original content of the vector is destroyed in
1639 // the process, since the input is overwritten by the output, normal-ordered,
1640 // FFT vector. With x as the input complex vector, Y as the output complex
1641 // vector and with M = 2^|stages|, the following is computed:
1644 // Y(k) = 1/M * sum[x(i)*[cos(2*pi*i*k/M) + j*sin(2*pi*i*k/M)]]
1647 // The implementations are optimized for speed, not for code size. It uses the
1648 // decimation-in-time algorithm with radix-2 butterfly technique.
1650 // This routine prevents overflow by scaling by 2 before each FFT stage. This is
1651 // a fixed scaling, for proper normalization - there will be log2(n) passes, so
1652 // this results in an overall factor of 1/n, distributed to maximize arithmetic
1656 // - vector : In pointer to complex vector containing 2^|stages| real
1657 // elements interleaved with 2^|stages| imaginary elements.
1658 // [ReImReImReIm....]
1659 // The output is in the Q0 domain.
1661 // - stages : Number of FFT stages. Must be at least 3 and at most 10,
1662 // since the table WebRtcSpl_kSinTable1024[] is 1024
1665 // - mode : This parameter gives the user to choose how the FFT
1667 // mode==0: Low-complexity and Low-accuracy mode
1668 // mode==1: High-complexity and High-accuracy mode
1671 // - vector : The output FFT vector is in the Q0 domain.
1673 // Return value : The scale parameter is always 0, except if N>1024,
1674 // which returns a scale value of -1, indicating error.
1678 // WebRtcSpl_AnalysisQMF(...)
1680 // Splits a 0-2*F Hz signal into two sub bands: 0-F Hz and F-2*F Hz. The
1681 // current version has F = 8000, therefore, a super-wideband audio signal is
1682 // split to lower-band 0-8 kHz and upper-band 8-16 kHz.
1685 // - in_data : Wide band speech signal, 320 samples (10 ms)
1688 // - filter_state1 : Filter state for first All-pass filter
1689 // - filter_state2 : Filter state for second All-pass filter
1692 // - low_band : Lower-band signal 0-8 kHz band, 160 samples (10 ms)
1693 // - high_band : Upper-band signal 8-16 kHz band (flipped in frequency
1694 // domain), 160 samples (10 ms)
1698 // WebRtcSpl_SynthesisQMF(...)
1700 // Combines the two sub bands (0-F and F-2*F Hz) into a signal of 0-2*F
1701 // Hz, (current version has F = 8000 Hz). So the filter combines lower-band
1702 // (0-8 kHz) and upper-band (8-16 kHz) channels to obtain super-wideband 0-16
1706 // - low_band : The signal with the 0-8 kHz band, 160 samples (10 ms)
1707 // - high_band : The signal with the 8-16 kHz band, 160 samples (10 ms)
1710 // - filter_state1 : Filter state for first All-pass filter
1711 // - filter_state2 : Filter state for second All-pass filter
1714 // - out_data : Super-wideband speech signal, 0-16 kHz
1717 // int16_t WebRtcSpl_SatW32ToW16(...)
1719 // This function saturates a 32-bit word into a 16-bit word.
1722 // - value32 : The value of a 32-bit word.
1725 // - out16 : the saturated 16-bit word.
1728 // int32_t WebRtc_MulAccumW16(...)
1730 // This function multiply a 16-bit word by a 16-bit word, and accumulate this
1731 // value to a 32-bit integer.
1734 // - a : The value of the first 16-bit word.
1735 // - b : The value of the second 16-bit word.
1736 // - c : The value of an 32-bit integer.
1738 // Return Value: The value of a * b + c.
1741 // int16_t WebRtcSpl_get_version(...)
1743 // This function gives the version string of the Signal Processing Library.
1746 // - length_in_bytes : The size of Allocated space (in Bytes) where
1747 // the version number is written to (in string format).
1750 // - version : Pointer to a buffer where the version number is