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 #define WEBRTC_SPL_MUL(a, b) \
40 ((int32_t) ((int32_t)(a) * (int32_t)(b)))
41 #define WEBRTC_SPL_UMUL(a, b) \
42 ((uint32_t) ((uint32_t)(a) * (uint32_t)(b)))
43 #define WEBRTC_SPL_UMUL_16_16(a, b) \
44 ((uint32_t) (uint16_t)(a) * (uint16_t)(b))
45 #define WEBRTC_SPL_UMUL_32_16(a, b) \
46 ((uint32_t) ((uint32_t)(a) * (uint16_t)(b)))
47 #define WEBRTC_SPL_MUL_16_U16(a, b) \
48 ((int32_t)(int16_t)(a) * (uint16_t)(b))
50 #ifndef WEBRTC_ARCH_ARM_V7
51 // For ARMv7 platforms, these are inline functions in spl_inl_armv7.h
53 // For MIPS platforms, these are inline functions in spl_inl_mips.h
54 #define WEBRTC_SPL_MUL_16_16(a, b) \
55 ((int32_t) (((int16_t)(a)) * ((int16_t)(b))))
56 #define WEBRTC_SPL_MUL_16_32_RSFT16(a, b) \
57 (WEBRTC_SPL_MUL_16_16(a, b >> 16) \
58 + ((WEBRTC_SPL_MUL_16_16(a, (b & 0xffff) >> 1) + 0x4000) >> 15))
62 #define WEBRTC_SPL_MUL_16_32_RSFT11(a, b) \
63 ((WEBRTC_SPL_MUL_16_16(a, (b) >> 16) << 5) \
64 + (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x0200) >> 10))
65 #define WEBRTC_SPL_MUL_16_32_RSFT14(a, b) \
66 ((WEBRTC_SPL_MUL_16_16(a, (b) >> 16) << 2) \
67 + (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x1000) >> 13))
68 #define WEBRTC_SPL_MUL_16_32_RSFT15(a, b) \
69 ((WEBRTC_SPL_MUL_16_16(a, (b) >> 16) << 1) \
70 + (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x2000) >> 14))
72 #define WEBRTC_SPL_MUL_16_16_RSFT(a, b, c) \
73 (WEBRTC_SPL_MUL_16_16(a, b) >> (c))
75 #define WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(a, b, c) \
76 ((WEBRTC_SPL_MUL_16_16(a, b) + ((int32_t) \
77 (((int32_t)1) << ((c) - 1)))) >> (c))
79 // C + the 32 most significant bits of A * B
80 #define WEBRTC_SPL_SCALEDIFF32(A, B, C) \
81 (C + (B >> 16) * A + (((uint32_t)(0x0000FFFF & B) * A) >> 16))
83 #define WEBRTC_SPL_SAT(a, b, c) (b > a ? a : b < c ? c : b)
85 // Shifting with negative numbers allowed
86 // Positive means left shift
87 #define WEBRTC_SPL_SHIFT_W32(x, c) \
88 (((c) >= 0) ? ((x) << (c)) : ((x) >> (-(c))))
90 // Shifting with negative numbers not allowed
91 // We cannot do casting here due to signed/unsigned problem
92 #define WEBRTC_SPL_RSHIFT_W16(x, c) ((x) >> (c))
93 #define WEBRTC_SPL_LSHIFT_W16(x, c) ((x) << (c))
94 #define WEBRTC_SPL_RSHIFT_W32(x, c) ((x) >> (c))
95 #define WEBRTC_SPL_LSHIFT_W32(x, c) ((x) << (c))
97 #define WEBRTC_SPL_RSHIFT_U32(x, c) ((uint32_t)(x) >> (c))
98 #define WEBRTC_SPL_LSHIFT_U32(x, c) ((uint32_t)(x) << (c))
100 #define WEBRTC_SPL_RAND(a) \
101 ((int16_t)(WEBRTC_SPL_MUL_16_16_RSFT((a), 18816, 7) & 0x00007fff))
107 #define WEBRTC_SPL_MEMCPY_W16(v1, v2, length) \
108 memcpy(v1, v2, (length) * sizeof(int16_t))
111 #include "webrtc/common_audio/signal_processing/include/spl_inl.h"
113 // Initialize SPL. Currently it contains only function pointer initialization.
114 // If the underlying platform is known to be ARM-Neon (WEBRTC_ARCH_ARM_NEON
115 // defined), the pointers will be assigned to code optimized for Neon; otherwise
116 // if run-time Neon detection (WEBRTC_DETECT_ARM_NEON) is enabled, the pointers
117 // will be assigned to either Neon code or generic C code; otherwise, generic C
118 // code will be assigned.
119 // Note that this function MUST be called in any application that uses SPL
121 void WebRtcSpl_Init();
124 int16_t WebRtcSpl_get_version(char* version, int16_t length_in_bytes);
126 int16_t WebRtcSpl_GetScalingSquare(int16_t* in_vector,
127 int in_vector_length,
130 // Copy and set operations. Implementation in copy_set_operations.c.
131 // Descriptions at bottom of file.
132 void WebRtcSpl_MemSetW16(int16_t* vector,
135 void WebRtcSpl_MemSetW32(int32_t* vector,
138 void WebRtcSpl_MemCpyReversedOrder(int16_t* out_vector,
141 void WebRtcSpl_CopyFromEndW16(const int16_t* in_vector,
142 int in_vector_length,
144 int16_t* out_vector);
145 void WebRtcSpl_ZerosArrayW16(int16_t* vector,
147 void WebRtcSpl_ZerosArrayW32(int32_t* vector,
149 // End: Copy and set operations.
152 // Minimum and maximum operation functions and their pointers.
153 // Implementation in min_max_operations.c.
155 // Returns the largest absolute value in a signed 16-bit vector.
158 // - vector : 16-bit input vector.
159 // - length : Number of samples in vector.
161 // Return value : Maximum absolute value in vector;
162 // or -1, if (vector == NULL || length <= 0).
163 typedef int16_t (*MaxAbsValueW16)(const int16_t* vector, int length);
164 extern MaxAbsValueW16 WebRtcSpl_MaxAbsValueW16;
165 int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, int length);
166 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
167 int16_t WebRtcSpl_MaxAbsValueW16Neon(const int16_t* vector, int length);
169 #if defined(MIPS32_LE)
170 int16_t WebRtcSpl_MaxAbsValueW16_mips(const int16_t* vector, int length);
173 // Returns the largest absolute value in a signed 32-bit vector.
176 // - vector : 32-bit input vector.
177 // - length : Number of samples in vector.
179 // Return value : Maximum absolute value in vector;
180 // or -1, if (vector == NULL || length <= 0).
181 typedef int32_t (*MaxAbsValueW32)(const int32_t* vector, int length);
182 extern MaxAbsValueW32 WebRtcSpl_MaxAbsValueW32;
183 int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, int length);
184 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
185 int32_t WebRtcSpl_MaxAbsValueW32Neon(const int32_t* vector, int length);
187 #if defined(MIPS_DSP_R1_LE)
188 int32_t WebRtcSpl_MaxAbsValueW32_mips(const int32_t* vector, int length);
191 // Returns the maximum value of a 16-bit vector.
194 // - vector : 16-bit input vector.
195 // - length : Number of samples in vector.
197 // Return value : Maximum sample value in |vector|.
198 // If (vector == NULL || length <= 0) WEBRTC_SPL_WORD16_MIN
199 // is returned. Note that WEBRTC_SPL_WORD16_MIN is a feasible
200 // value and we can't catch errors purely based on it.
201 typedef int16_t (*MaxValueW16)(const int16_t* vector, int length);
202 extern MaxValueW16 WebRtcSpl_MaxValueW16;
203 int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, int length);
204 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
205 int16_t WebRtcSpl_MaxValueW16Neon(const int16_t* vector, int length);
207 #if defined(MIPS32_LE)
208 int16_t WebRtcSpl_MaxValueW16_mips(const int16_t* vector, int length);
211 // Returns the maximum value of a 32-bit vector.
214 // - vector : 32-bit input vector.
215 // - length : Number of samples in vector.
217 // Return value : Maximum sample value in |vector|.
218 // If (vector == NULL || length <= 0) WEBRTC_SPL_WORD32_MIN
219 // is returned. Note that WEBRTC_SPL_WORD32_MIN is a feasible
220 // value and we can't catch errors purely based on it.
221 typedef int32_t (*MaxValueW32)(const int32_t* vector, int length);
222 extern MaxValueW32 WebRtcSpl_MaxValueW32;
223 int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, int length);
224 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
225 int32_t WebRtcSpl_MaxValueW32Neon(const int32_t* vector, int length);
227 #if defined(MIPS32_LE)
228 int32_t WebRtcSpl_MaxValueW32_mips(const int32_t* vector, int length);
231 // Returns the minimum value of a 16-bit vector.
234 // - vector : 16-bit input vector.
235 // - length : Number of samples in vector.
237 // Return value : Minimum sample value in |vector|.
238 // If (vector == NULL || length <= 0) WEBRTC_SPL_WORD16_MAX
239 // is returned. Note that WEBRTC_SPL_WORD16_MAX is a feasible
240 // value and we can't catch errors purely based on it.
241 typedef int16_t (*MinValueW16)(const int16_t* vector, int length);
242 extern MinValueW16 WebRtcSpl_MinValueW16;
243 int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, int length);
244 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
245 int16_t WebRtcSpl_MinValueW16Neon(const int16_t* vector, int length);
247 #if defined(MIPS32_LE)
248 int16_t WebRtcSpl_MinValueW16_mips(const int16_t* vector, int length);
251 // Returns the minimum value of a 32-bit vector.
254 // - vector : 32-bit input vector.
255 // - length : Number of samples in vector.
257 // Return value : Minimum sample value in |vector|.
258 // If (vector == NULL || length <= 0) WEBRTC_SPL_WORD32_MAX
259 // is returned. Note that WEBRTC_SPL_WORD32_MAX is a feasible
260 // value and we can't catch errors purely based on it.
261 typedef int32_t (*MinValueW32)(const int32_t* vector, int length);
262 extern MinValueW32 WebRtcSpl_MinValueW32;
263 int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, int length);
264 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
265 int32_t WebRtcSpl_MinValueW32Neon(const int32_t* vector, int length);
267 #if defined(MIPS32_LE)
268 int32_t WebRtcSpl_MinValueW32_mips(const int32_t* vector, int length);
271 // Returns the vector index to the largest absolute value of a 16-bit vector.
274 // - vector : 16-bit input vector.
275 // - length : Number of samples in vector.
277 // Return value : Index to the maximum absolute value in vector, or -1,
278 // if (vector == NULL || length <= 0).
279 // If there are multiple equal maxima, return the index of the
280 // first. -32768 will always have precedence over 32767 (despite
281 // -32768 presenting an int16 absolute value of 32767);
282 int WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, int length);
284 // Returns the vector index to the maximum sample value of a 16-bit vector.
287 // - vector : 16-bit input vector.
288 // - length : Number of samples in vector.
290 // Return value : Index to the maximum value in vector (if multiple
291 // indexes have the maximum, return the first);
292 // or -1, if (vector == NULL || length <= 0).
293 int WebRtcSpl_MaxIndexW16(const int16_t* vector, int length);
295 // Returns the vector index to the maximum sample value of a 32-bit vector.
298 // - vector : 32-bit input vector.
299 // - length : Number of samples in vector.
301 // Return value : Index to the maximum value in vector (if multiple
302 // indexes have the maximum, return the first);
303 // or -1, if (vector == NULL || length <= 0).
304 int WebRtcSpl_MaxIndexW32(const int32_t* vector, int length);
306 // Returns the vector index to the minimum sample value of a 16-bit vector.
309 // - vector : 16-bit input vector.
310 // - length : Number of samples in vector.
312 // Return value : Index to the mimimum value in vector (if multiple
313 // indexes have the minimum, return the first);
314 // or -1, if (vector == NULL || length <= 0).
315 int WebRtcSpl_MinIndexW16(const int16_t* vector, int length);
317 // Returns the vector index to the minimum sample value of a 32-bit vector.
320 // - vector : 32-bit input vector.
321 // - length : Number of samples in vector.
323 // Return value : Index to the mimimum value in vector (if multiple
324 // indexes have the minimum, return the first);
325 // or -1, if (vector == NULL || length <= 0).
326 int WebRtcSpl_MinIndexW32(const int32_t* vector, int length);
328 // End: Minimum and maximum operations.
331 // Vector scaling operations. Implementation in vector_scaling_operations.c.
332 // Description at bottom of file.
333 void WebRtcSpl_VectorBitShiftW16(int16_t* out_vector,
334 int16_t vector_length,
335 const int16_t* in_vector,
336 int16_t right_shifts);
337 void WebRtcSpl_VectorBitShiftW32(int32_t* out_vector,
338 int16_t vector_length,
339 const int32_t* in_vector,
340 int16_t right_shifts);
341 void WebRtcSpl_VectorBitShiftW32ToW16(int16_t* out_vector,
343 const int32_t* in_vector,
345 void WebRtcSpl_ScaleVector(const int16_t* in_vector,
348 int16_t vector_length,
349 int16_t right_shifts);
350 void WebRtcSpl_ScaleVectorWithSat(const int16_t* in_vector,
353 int16_t vector_length,
354 int16_t right_shifts);
355 void WebRtcSpl_ScaleAndAddVectors(const int16_t* in_vector1,
356 int16_t gain1, int right_shifts1,
357 const int16_t* in_vector2,
358 int16_t gain2, int right_shifts2,
362 // The functions (with related pointer) perform the vector operation:
363 // out_vector[k] = ((scale1 * in_vector1[k]) + (scale2 * in_vector2[k])
364 // + round_value) >> right_shifts,
365 // where round_value = (1 << right_shifts) >> 1.
368 // - in_vector1 : Input vector 1
369 // - in_vector1_scale : Gain to be used for vector 1
370 // - in_vector2 : Input vector 2
371 // - in_vector2_scale : Gain to be used for vector 2
372 // - right_shifts : Number of right bit shifts to be applied
373 // - length : Number of elements in the input vectors
376 // - out_vector : Output vector
377 // Return value : 0 if OK, -1 if (in_vector1 == NULL
378 // || in_vector2 == NULL || out_vector == NULL
379 // || length <= 0 || right_shift < 0).
380 typedef int (*ScaleAndAddVectorsWithRound)(const int16_t* in_vector1,
381 int16_t in_vector1_scale,
382 const int16_t* in_vector2,
383 int16_t in_vector2_scale,
387 extern ScaleAndAddVectorsWithRound WebRtcSpl_ScaleAndAddVectorsWithRound;
388 int WebRtcSpl_ScaleAndAddVectorsWithRoundC(const int16_t* in_vector1,
389 int16_t in_vector1_scale,
390 const int16_t* in_vector2,
391 int16_t in_vector2_scale,
395 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
396 int WebRtcSpl_ScaleAndAddVectorsWithRoundNeon(const int16_t* in_vector1,
397 int16_t in_vector1_scale,
398 const int16_t* in_vector2,
399 int16_t in_vector2_scale,
404 #if defined(MIPS_DSP_R1_LE)
405 int WebRtcSpl_ScaleAndAddVectorsWithRound_mips(const int16_t* in_vector1,
406 int16_t in_vector1_scale,
407 const int16_t* in_vector2,
408 int16_t in_vector2_scale,
413 // End: Vector scaling operations.
415 // iLBC specific functions. Implementations in ilbc_specific_functions.c.
416 // Description at bottom of file.
417 void WebRtcSpl_ReverseOrderMultArrayElements(int16_t* out_vector,
418 const int16_t* in_vector,
419 const int16_t* window,
420 int16_t vector_length,
421 int16_t right_shifts);
422 void WebRtcSpl_ElementwiseVectorMult(int16_t* out_vector,
423 const int16_t* in_vector,
424 const int16_t* window,
425 int16_t vector_length,
426 int16_t right_shifts);
427 void WebRtcSpl_AddVectorsAndShift(int16_t* out_vector,
428 const int16_t* in_vector1,
429 const int16_t* in_vector2,
430 int16_t vector_length,
431 int16_t right_shifts);
432 void WebRtcSpl_AddAffineVectorToVector(int16_t* out_vector,
435 int32_t add_constant,
436 int16_t right_shifts,
438 void WebRtcSpl_AffineTransformVector(int16_t* out_vector,
441 int32_t add_constant,
442 int16_t right_shifts,
444 // End: iLBC specific functions.
446 // Signal processing operations.
448 // A 32-bit fix-point implementation of auto-correlation computation
451 // - in_vector : Vector to calculate autocorrelation upon
452 // - in_vector_length : Length (in samples) of |vector|
453 // - order : The order up to which the autocorrelation should be
457 // - result : auto-correlation values (values should be seen
458 // relative to each other since the absolute values
459 // might have been down shifted to avoid overflow)
461 // - scale : The number of left shifts required to obtain the
462 // auto-correlation in Q0
465 // - -1, if |order| > |in_vector_length|;
466 // - Number of samples in |result|, i.e. (order+1), otherwise.
467 int WebRtcSpl_AutoCorrelation(const int16_t* in_vector,
468 int in_vector_length,
473 // A 32-bit fix-point implementation of the Levinson-Durbin algorithm that
474 // does NOT use the 64 bit class
477 // - auto_corr : Vector with autocorrelation values of length >=
479 // - use_order : The LPC filter order (support up to order 20)
482 // - lpc_coef : lpc_coef[0..use_order] LPC coefficients in Q12
483 // - refl_coef : refl_coef[0...use_order-1]| Reflection coefficients in
486 // Return value : 1 for stable 0 for unstable
487 int16_t WebRtcSpl_LevinsonDurbin(int32_t* auto_corr,
492 // Converts reflection coefficients |refl_coef| to LPC coefficients |lpc_coef|.
493 // This version is a 16 bit operation.
495 // NOTE: The 16 bit refl_coef -> lpc_coef conversion might result in a
496 // "slightly unstable" filter (i.e., a pole just outside the unit circle) in
497 // "rare" cases even if the reflection coefficients are stable.
500 // - refl_coef : Reflection coefficients in Q15 that should be converted
501 // to LPC coefficients
502 // - use_order : Number of coefficients in |refl_coef|
505 // - lpc_coef : LPC coefficients in Q12
506 void WebRtcSpl_ReflCoefToLpc(const int16_t* refl_coef,
510 // Converts LPC coefficients |lpc_coef| to reflection coefficients |refl_coef|.
511 // This version is a 16 bit operation.
512 // The conversion is implemented by the step-down algorithm.
515 // - lpc_coef : LPC coefficients in Q12, that should be converted to
516 // reflection coefficients
517 // - use_order : Number of coefficients in |lpc_coef|
520 // - refl_coef : Reflection coefficients in Q15.
521 void WebRtcSpl_LpcToReflCoef(int16_t* lpc_coef,
525 // Calculates reflection coefficients (16 bit) from auto-correlation values
528 // - auto_corr : Auto-correlation values
529 // - use_order : Number of coefficients wanted be calculated
532 // - refl_coef : Reflection coefficients in Q15.
533 void WebRtcSpl_AutoCorrToReflCoef(const int32_t* auto_corr,
537 // The functions (with related pointer) calculate the cross-correlation between
538 // two sequences |seq1| and |seq2|.
539 // |seq1| is fixed and |seq2| slides as the pointer is increased with the
540 // amount |step_seq2|. Note the arguments should obey the relationship:
541 // |dim_seq| - 1 + |step_seq2| * (|dim_cross_correlation| - 1) <
542 // buffer size of |seq2|
545 // - seq1 : First sequence (fixed throughout the correlation)
546 // - seq2 : Second sequence (slides |step_vector2| for each
548 // - dim_seq : Number of samples to use in the cross-correlation
549 // - dim_cross_correlation : Number of cross-correlations to calculate (the
550 // start position for |vector2| is updated for each
552 // - right_shifts : Number of right bit shifts to use. This will
553 // become the output Q-domain.
554 // - step_seq2 : How many (positive or negative) steps the
555 // |vector2| pointer should be updated for each new
556 // cross-correlation value.
559 // - cross_correlation : The cross-correlation in Q(-right_shifts)
560 typedef void (*CrossCorrelation)(int32_t* cross_correlation,
564 int16_t dim_cross_correlation,
565 int16_t right_shifts,
567 extern CrossCorrelation WebRtcSpl_CrossCorrelation;
568 void WebRtcSpl_CrossCorrelationC(int32_t* cross_correlation,
572 int16_t dim_cross_correlation,
573 int16_t right_shifts,
575 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
576 void WebRtcSpl_CrossCorrelationNeon(int32_t* cross_correlation,
580 int16_t dim_cross_correlation,
581 int16_t right_shifts,
584 #if defined(MIPS32_LE)
585 void WebRtcSpl_CrossCorrelation_mips(int32_t* cross_correlation,
589 int16_t dim_cross_correlation,
590 int16_t right_shifts,
594 // Creates (the first half of) a Hanning window. Size must be at least 1 and
598 // - size : Length of the requested Hanning window (1 to 512)
601 // - window : Hanning vector in Q14.
602 void WebRtcSpl_GetHanningWindow(int16_t* window, int16_t size);
604 // Calculates y[k] = sqrt(1 - x[k]^2) for each element of the input vector
605 // |in_vector|. Input and output values are in Q15.
608 // - in_vector : Values to calculate sqrt(1 - x^2) of
609 // - vector_length : Length of vector |in_vector|
612 // - out_vector : Output values in Q15
613 void WebRtcSpl_SqrtOfOneMinusXSquared(int16_t* in_vector,
615 int16_t* out_vector);
616 // End: Signal processing operations.
618 // Randomization functions. Implementations collected in
619 // randomization_functions.c and descriptions at bottom of this file.
620 int16_t WebRtcSpl_RandU(uint32_t* seed);
621 int16_t WebRtcSpl_RandN(uint32_t* seed);
622 int16_t WebRtcSpl_RandUArray(int16_t* vector,
623 int16_t vector_length,
625 // End: Randomization functions.
628 int32_t WebRtcSpl_Sqrt(int32_t value);
629 int32_t WebRtcSpl_SqrtFloor(int32_t value);
631 // Divisions. Implementations collected in division_operations.c and
632 // descriptions at bottom of this file.
633 uint32_t WebRtcSpl_DivU32U16(uint32_t num, uint16_t den);
634 int32_t WebRtcSpl_DivW32W16(int32_t num, int16_t den);
635 int16_t WebRtcSpl_DivW32W16ResW16(int32_t num, int16_t den);
636 int32_t WebRtcSpl_DivResultInQ31(int32_t num, int32_t den);
637 int32_t WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low);
640 int32_t WebRtcSpl_Energy(int16_t* vector, int vector_length, int* scale_factor);
642 // Calculates the dot product between two (int16_t) vectors.
645 // - vector1 : Vector 1
646 // - vector2 : Vector 2
647 // - vector_length : Number of samples used in the dot product
648 // - scaling : The number of right bit shifts to apply on each term
649 // during calculation to avoid overflow, i.e., the
650 // output will be in Q(-|scaling|)
652 // Return value : The dot product in Q(-scaling)
653 int32_t WebRtcSpl_DotProductWithScale(const int16_t* vector1,
654 const int16_t* vector2,
658 // Filter operations.
659 int WebRtcSpl_FilterAR(const int16_t* ar_coef,
661 const int16_t* in_vector,
662 int in_vector_length,
663 int16_t* filter_state,
664 int filter_state_length,
665 int16_t* filter_state_low,
666 int filter_state_low_length,
668 int16_t* out_vector_low,
669 int out_vector_low_length);
671 void WebRtcSpl_FilterMAFastQ12(int16_t* in_vector,
674 int16_t ma_coef_length,
675 int16_t vector_length);
677 // Performs a AR filtering on a vector in Q12
679 // - data_in : Input samples
680 // - data_out : State information in positions
681 // data_out[-order] .. data_out[-1]
682 // - coefficients : Filter coefficients (in Q12)
683 // - coefficients_length: Number of coefficients (order+1)
684 // - data_length : Number of samples to be filtered
686 // - data_out : Filtered samples
687 void WebRtcSpl_FilterARFastQ12(const int16_t* data_in,
689 const int16_t* __restrict coefficients,
690 int coefficients_length,
693 // The functions (with related pointer) perform a MA down sampling filter
696 // - data_in : Input samples (state in positions
697 // data_in[-order] .. data_in[-1])
698 // - data_in_length : Number of samples in |data_in| to be filtered.
699 // This must be at least
700 // |delay| + |factor|*(|out_vector_length|-1) + 1)
701 // - data_out_length : Number of down sampled samples desired
702 // - coefficients : Filter coefficients (in Q12)
703 // - coefficients_length: Number of coefficients (order+1)
704 // - factor : Decimation factor
705 // - delay : Delay of filter (compensated for in out_vector)
707 // - data_out : Filtered samples
708 // Return value : 0 if OK, -1 if |in_vector| is too short
709 typedef int (*DownsampleFast)(const int16_t* data_in,
713 const int16_t* __restrict coefficients,
714 int coefficients_length,
717 extern DownsampleFast WebRtcSpl_DownsampleFast;
718 int WebRtcSpl_DownsampleFastC(const int16_t* data_in,
722 const int16_t* __restrict coefficients,
723 int coefficients_length,
726 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
727 int WebRtcSpl_DownsampleFastNeon(const int16_t* data_in,
731 const int16_t* __restrict coefficients,
732 int coefficients_length,
736 #if defined(MIPS32_LE)
737 int WebRtcSpl_DownsampleFast_mips(const int16_t* data_in,
741 const int16_t* __restrict coefficients,
742 int coefficients_length,
747 // End: Filter operations.
751 int WebRtcSpl_ComplexFFT(int16_t vector[], int stages, int mode);
752 int WebRtcSpl_ComplexIFFT(int16_t vector[], int stages, int mode);
754 // Treat a 16-bit complex data buffer |complex_data| as an array of 32-bit
755 // values, and swap elements whose indexes are bit-reverses of each other.
758 // - complex_data : Complex data buffer containing 2^|stages| real
759 // elements interleaved with 2^|stages| imaginary
760 // elements: [Re Im Re Im Re Im....]
761 // - stages : Number of FFT stages. Must be at least 3 and at most
762 // 10, since the table WebRtcSpl_kSinTable1024[] is 1024
766 // - complex_data : The complex data buffer.
768 void WebRtcSpl_ComplexBitReverse(int16_t* __restrict complex_data, int stages);
770 // End: FFT operations
772 /************************************************************
774 * RESAMPLING FUNCTIONS AND THEIR STRUCTS ARE DEFINED BELOW
776 ************************************************************/
778 /*******************************************************************
781 * Includes the following resampling combinations
787 ******************************************************************/
789 // state structure for 22 -> 16 resampler
794 } WebRtcSpl_State22khzTo16khz;
796 void WebRtcSpl_Resample22khzTo16khz(const int16_t* in,
798 WebRtcSpl_State22khzTo16khz* state,
801 void WebRtcSpl_ResetResample22khzTo16khz(WebRtcSpl_State22khzTo16khz* state);
803 // state structure for 16 -> 22 resampler
807 } WebRtcSpl_State16khzTo22khz;
809 void WebRtcSpl_Resample16khzTo22khz(const int16_t* in,
811 WebRtcSpl_State16khzTo22khz* state,
814 void WebRtcSpl_ResetResample16khzTo22khz(WebRtcSpl_State16khzTo22khz* state);
816 // state structure for 22 -> 8 resampler
821 } WebRtcSpl_State22khzTo8khz;
823 void WebRtcSpl_Resample22khzTo8khz(const int16_t* in, int16_t* out,
824 WebRtcSpl_State22khzTo8khz* state,
827 void WebRtcSpl_ResetResample22khzTo8khz(WebRtcSpl_State22khzTo8khz* state);
829 // state structure for 8 -> 22 resampler
834 } WebRtcSpl_State8khzTo22khz;
836 void WebRtcSpl_Resample8khzTo22khz(const int16_t* in, int16_t* out,
837 WebRtcSpl_State8khzTo22khz* state,
840 void WebRtcSpl_ResetResample8khzTo22khz(WebRtcSpl_State8khzTo22khz* state);
842 /*******************************************************************
843 * resample_fractional.c
844 * Functions for internal use in the other resample functions
846 * Includes the following resampling combinations
851 ******************************************************************/
853 void WebRtcSpl_Resample48khzTo32khz(const int32_t* In, int32_t* Out,
856 void WebRtcSpl_Resample32khzTo24khz(const int32_t* In, int32_t* Out,
859 void WebRtcSpl_Resample44khzTo32khz(const int32_t* In, int32_t* Out,
862 /*******************************************************************
865 * Includes the following resampling combinations
871 ******************************************************************/
877 } WebRtcSpl_State48khzTo16khz;
879 void WebRtcSpl_Resample48khzTo16khz(const int16_t* in, int16_t* out,
880 WebRtcSpl_State48khzTo16khz* state,
883 void WebRtcSpl_ResetResample48khzTo16khz(WebRtcSpl_State48khzTo16khz* state);
889 } WebRtcSpl_State16khzTo48khz;
891 void WebRtcSpl_Resample16khzTo48khz(const int16_t* in, int16_t* out,
892 WebRtcSpl_State16khzTo48khz* state,
895 void WebRtcSpl_ResetResample16khzTo48khz(WebRtcSpl_State16khzTo48khz* state);
902 } WebRtcSpl_State48khzTo8khz;
904 void WebRtcSpl_Resample48khzTo8khz(const int16_t* in, int16_t* out,
905 WebRtcSpl_State48khzTo8khz* state,
908 void WebRtcSpl_ResetResample48khzTo8khz(WebRtcSpl_State48khzTo8khz* state);
915 } WebRtcSpl_State8khzTo48khz;
917 void WebRtcSpl_Resample8khzTo48khz(const int16_t* in, int16_t* out,
918 WebRtcSpl_State8khzTo48khz* state,
921 void WebRtcSpl_ResetResample8khzTo48khz(WebRtcSpl_State8khzTo48khz* state);
923 /*******************************************************************
926 * Includes down and up sampling by a factor of two.
928 ******************************************************************/
930 void WebRtcSpl_DownsampleBy2(const int16_t* in, int len,
931 int16_t* out, int32_t* filtState);
933 void WebRtcSpl_UpsampleBy2(const int16_t* in, int len,
934 int16_t* out, int32_t* filtState);
936 /************************************************************
937 * END OF RESAMPLING FUNCTIONS
938 ************************************************************/
939 void WebRtcSpl_AnalysisQMF(const int16_t* in_data,
943 int32_t* filter_state1,
944 int32_t* filter_state2);
945 void WebRtcSpl_SynthesisQMF(const int16_t* low_band,
946 const int16_t* high_band,
949 int32_t* filter_state1,
950 int32_t* filter_state2);
954 #endif // __cplusplus
955 #endif // WEBRTC_SPL_SIGNAL_PROCESSING_LIBRARY_H_
958 // WebRtcSpl_AddSatW16(...)
959 // WebRtcSpl_AddSatW32(...)
961 // Returns the result of a saturated 16-bit, respectively 32-bit, addition of
962 // the numbers specified by the |var1| and |var2| parameters.
965 // - var1 : Input variable 1
966 // - var2 : Input variable 2
968 // Return value : Added and saturated value
972 // WebRtcSpl_SubSatW16(...)
973 // WebRtcSpl_SubSatW32(...)
975 // Returns the result of a saturated 16-bit, respectively 32-bit, subtraction
976 // of the numbers specified by the |var1| and |var2| parameters.
979 // - var1 : Input variable 1
980 // - var2 : Input variable 2
982 // Returned value : Subtracted and saturated value
986 // WebRtcSpl_GetSizeInBits(...)
988 // Returns the # of bits that are needed at the most to represent the number
989 // specified by the |value| parameter.
992 // - value : Input value
994 // Return value : Number of bits needed to represent |value|
998 // WebRtcSpl_NormW32(...)
1000 // Norm returns the # of left shifts required to 32-bit normalize the 32-bit
1001 // signed number specified by the |value| parameter.
1004 // - value : Input value
1006 // Return value : Number of bit shifts needed to 32-bit normalize |value|
1010 // WebRtcSpl_NormW16(...)
1012 // Norm returns the # of left shifts required to 16-bit normalize the 16-bit
1013 // signed number specified by the |value| parameter.
1016 // - value : Input value
1018 // Return value : Number of bit shifts needed to 32-bit normalize |value|
1022 // WebRtcSpl_NormU32(...)
1024 // Norm returns the # of left shifts required to 32-bit normalize the unsigned
1025 // 32-bit number specified by the |value| parameter.
1028 // - value : Input value
1030 // Return value : Number of bit shifts needed to 32-bit normalize |value|
1034 // WebRtcSpl_GetScalingSquare(...)
1036 // Returns the # of bits required to scale the samples specified in the
1037 // |in_vector| parameter so that, if the squares of the samples are added the
1038 // # of times specified by the |times| parameter, the 32-bit addition will not
1039 // overflow (result in int32_t).
1042 // - in_vector : Input vector to check scaling on
1043 // - in_vector_length : Samples in |in_vector|
1044 // - times : Number of additions to be performed
1046 // Return value : Number of right bit shifts needed to avoid
1047 // overflow in the addition calculation
1051 // WebRtcSpl_MemSetW16(...)
1053 // Sets all the values in the int16_t vector |vector| of length
1054 // |vector_length| to the specified value |set_value|
1057 // - vector : Pointer to the int16_t vector
1058 // - set_value : Value specified
1059 // - vector_length : Length of vector
1063 // WebRtcSpl_MemSetW32(...)
1065 // Sets all the values in the int32_t vector |vector| of length
1066 // |vector_length| to the specified value |set_value|
1069 // - vector : Pointer to the int16_t vector
1070 // - set_value : Value specified
1071 // - vector_length : Length of vector
1075 // WebRtcSpl_MemCpyReversedOrder(...)
1077 // Copies all the values from the source int16_t vector |in_vector| to a
1078 // destination int16_t vector |out_vector|. It is done in reversed order,
1079 // meaning that the first sample of |in_vector| is copied to the last sample of
1080 // the |out_vector|. The procedure continues until the last sample of
1081 // |in_vector| has been copied to the first sample of |out_vector|. This
1082 // creates a reversed vector. Used in e.g. prediction in iLBC.
1085 // - in_vector : Pointer to the first sample in a int16_t vector
1086 // of length |length|
1087 // - vector_length : Number of elements to copy
1090 // - out_vector : Pointer to the last sample in a int16_t vector
1091 // of length |length|
1095 // WebRtcSpl_CopyFromEndW16(...)
1097 // Copies the rightmost |samples| of |in_vector| (of length |in_vector_length|)
1098 // to the vector |out_vector|.
1101 // - in_vector : Input vector
1102 // - in_vector_length : Number of samples in |in_vector|
1103 // - samples : Number of samples to extract (from right side)
1107 // - out_vector : Vector with the requested samples
1111 // WebRtcSpl_ZerosArrayW16(...)
1112 // WebRtcSpl_ZerosArrayW32(...)
1114 // Inserts the value "zero" in all positions of a w16 and a w32 vector
1118 // - vector_length : Number of samples in vector
1121 // - vector : Vector containing all zeros
1125 // WebRtcSpl_VectorBitShiftW16(...)
1126 // WebRtcSpl_VectorBitShiftW32(...)
1128 // Bit shifts all the values in a vector up or downwards. Different calls for
1129 // int16_t and int32_t vectors respectively.
1132 // - vector_length : Length of vector
1133 // - in_vector : Pointer to the vector that should be bit shifted
1134 // - right_shifts : Number of right bit shifts (negative value gives left
1138 // - out_vector : Pointer to the result vector (can be the same as
1143 // WebRtcSpl_VectorBitShiftW32ToW16(...)
1145 // Bit shifts all the values in a int32_t vector up or downwards and
1146 // stores the result as an int16_t vector. The function will saturate the
1147 // signal if needed, before storing in the output vector.
1150 // - vector_length : Length of vector
1151 // - in_vector : Pointer to the vector that should be bit shifted
1152 // - right_shifts : Number of right bit shifts (negative value gives left
1156 // - out_vector : Pointer to the result vector (can be the same as
1161 // WebRtcSpl_ScaleVector(...)
1163 // Performs the vector operation:
1164 // out_vector[k] = (gain*in_vector[k])>>right_shifts
1167 // - in_vector : Input vector
1168 // - gain : Scaling gain
1169 // - vector_length : Elements in the |in_vector|
1170 // - right_shifts : Number of right bit shifts applied
1173 // - out_vector : Output vector (can be the same as |in_vector|)
1177 // WebRtcSpl_ScaleVectorWithSat(...)
1179 // Performs the vector operation:
1180 // out_vector[k] = SATURATE( (gain*in_vector[k])>>right_shifts )
1183 // - in_vector : Input vector
1184 // - gain : Scaling gain
1185 // - vector_length : Elements in the |in_vector|
1186 // - right_shifts : Number of right bit shifts applied
1189 // - out_vector : Output vector (can be the same as |in_vector|)
1193 // WebRtcSpl_ScaleAndAddVectors(...)
1195 // Performs the vector operation:
1196 // out_vector[k] = (gain1*in_vector1[k])>>right_shifts1
1197 // + (gain2*in_vector2[k])>>right_shifts2
1200 // - in_vector1 : Input vector 1
1201 // - gain1 : Gain to be used for vector 1
1202 // - right_shifts1 : Right bit shift to be used for vector 1
1203 // - in_vector2 : Input vector 2
1204 // - gain2 : Gain to be used for vector 2
1205 // - right_shifts2 : Right bit shift to be used for vector 2
1206 // - vector_length : Elements in the input vectors
1209 // - out_vector : Output vector
1213 // WebRtcSpl_ReverseOrderMultArrayElements(...)
1215 // Performs the vector operation:
1216 // out_vector[n] = (in_vector[n]*window[-n])>>right_shifts
1219 // - in_vector : Input vector
1220 // - window : Window vector (should be reversed). The pointer
1221 // should be set to the last value in the vector
1222 // - right_shifts : Number of right bit shift to be applied after the
1224 // - vector_length : Number of elements in |in_vector|
1227 // - out_vector : Output vector (can be same as |in_vector|)
1231 // WebRtcSpl_ElementwiseVectorMult(...)
1233 // Performs the vector operation:
1234 // out_vector[n] = (in_vector[n]*window[n])>>right_shifts
1237 // - in_vector : Input vector
1238 // - window : Window vector.
1239 // - right_shifts : Number of right bit shift to be applied after the
1241 // - vector_length : Number of elements in |in_vector|
1244 // - out_vector : Output vector (can be same as |in_vector|)
1248 // WebRtcSpl_AddVectorsAndShift(...)
1250 // Performs the vector operation:
1251 // out_vector[k] = (in_vector1[k] + in_vector2[k])>>right_shifts
1254 // - in_vector1 : Input vector 1
1255 // - in_vector2 : Input vector 2
1256 // - right_shifts : Number of right bit shift to be applied after the
1258 // - vector_length : Number of elements in |in_vector1| and |in_vector2|
1261 // - out_vector : Output vector (can be same as |in_vector1|)
1265 // WebRtcSpl_AddAffineVectorToVector(...)
1267 // Adds an affine transformed vector to another vector |out_vector|, i.e,
1269 // out_vector[k] += (in_vector[k]*gain+add_constant)>>right_shifts
1272 // - in_vector : Input vector
1273 // - gain : Gain value, used to multiply the in vector with
1274 // - add_constant : Constant value to add (usually 1<<(right_shifts-1),
1275 // but others can be used as well
1276 // - right_shifts : Number of right bit shifts (0-16)
1277 // - vector_length : Number of samples in |in_vector| and |out_vector|
1280 // - out_vector : Vector with the output
1284 // WebRtcSpl_AffineTransformVector(...)
1286 // Affine transforms a vector, i.e, performs
1287 // out_vector[k] = (in_vector[k]*gain+add_constant)>>right_shifts
1290 // - in_vector : Input vector
1291 // - gain : Gain value, used to multiply the in vector with
1292 // - add_constant : Constant value to add (usually 1<<(right_shifts-1),
1293 // but others can be used as well
1294 // - right_shifts : Number of right bit shifts (0-16)
1295 // - vector_length : Number of samples in |in_vector| and |out_vector|
1298 // - out_vector : Vector with the output
1302 // WebRtcSpl_IncreaseSeed(...)
1304 // Increases the seed (and returns the new value)
1307 // - seed : Seed for random calculation
1310 // - seed : Updated seed value
1312 // Return value : The new seed value
1316 // WebRtcSpl_RandU(...)
1318 // Produces a uniformly distributed value in the int16_t range
1321 // - seed : Seed for random calculation
1324 // - seed : Updated seed value
1326 // Return value : Uniformly distributed value in the range
1327 // [Word16_MIN...Word16_MAX]
1331 // WebRtcSpl_RandN(...)
1333 // Produces a normal distributed value in the int16_t range
1336 // - seed : Seed for random calculation
1339 // - seed : Updated seed value
1341 // Return value : N(0,1) value in the Q13 domain
1345 // WebRtcSpl_RandUArray(...)
1347 // Produces a uniformly distributed vector with elements in the int16_t
1351 // - vector_length : Samples wanted in the vector
1352 // - seed : Seed for random calculation
1355 // - vector : Vector with the uniform values
1356 // - seed : Updated seed value
1358 // Return value : Number of samples in vector, i.e., |vector_length|
1362 // WebRtcSpl_Sqrt(...)
1364 // Returns the square root of the input value |value|. The precision of this
1365 // function is integer precision, i.e., sqrt(8) gives 2 as answer.
1366 // If |value| is a negative number then 0 is returned.
1370 // A sixth order Taylor Series expansion is used here to compute the square
1371 // root of a number y^0.5 = (1+x)^0.5
1374 // = 1+(x/2)-0.5*((x/2)^2+0.5*((x/2)^3-0.625*((x/2)^4+0.875*((x/2)^5)
1378 // - value : Value to calculate sqrt of
1380 // Return value : Result of the sqrt calculation
1384 // WebRtcSpl_SqrtFloor(...)
1386 // Returns the square root of the input value |value|. The precision of this
1387 // function is rounding down integer precision, i.e., sqrt(8) gives 2 as answer.
1388 // If |value| is a negative number then 0 is returned.
1392 // An iterative 4 cylce/bit routine
1395 // - value : Value to calculate sqrt of
1397 // Return value : Result of the sqrt calculation
1401 // WebRtcSpl_DivU32U16(...)
1403 // Divides a uint32_t |num| by a uint16_t |den|.
1405 // If |den|==0, (uint32_t)0xFFFFFFFF is returned.
1408 // - num : Numerator
1409 // - den : Denominator
1411 // Return value : Result of the division (as a uint32_t), i.e., the
1412 // integer part of num/den.
1416 // WebRtcSpl_DivW32W16(...)
1418 // Divides a int32_t |num| by a int16_t |den|.
1420 // If |den|==0, (int32_t)0x7FFFFFFF is returned.
1423 // - num : Numerator
1424 // - den : Denominator
1426 // Return value : Result of the division (as a int32_t), i.e., the
1427 // integer part of num/den.
1431 // WebRtcSpl_DivW32W16ResW16(...)
1433 // Divides a int32_t |num| by a int16_t |den|, assuming that the
1434 // result is less than 32768, otherwise an unpredictable result will occur.
1436 // If |den|==0, (int16_t)0x7FFF is returned.
1439 // - num : Numerator
1440 // - den : Denominator
1442 // Return value : Result of the division (as a int16_t), i.e., the
1443 // integer part of num/den.
1447 // WebRtcSpl_DivResultInQ31(...)
1449 // Divides a int32_t |num| by a int16_t |den|, assuming that the
1450 // absolute value of the denominator is larger than the numerator, otherwise
1451 // an unpredictable result will occur.
1454 // - num : Numerator
1455 // - den : Denominator
1457 // Return value : Result of the division in Q31.
1461 // WebRtcSpl_DivW32HiLow(...)
1463 // Divides a int32_t |num| by a denominator in hi, low format. The
1464 // absolute value of the denominator has to be larger (or equal to) the
1468 // - num : Numerator
1469 // - den_hi : High part of denominator
1470 // - den_low : Low part of denominator
1472 // Return value : Divided value in Q31
1476 // WebRtcSpl_Energy(...)
1478 // Calculates the energy of a vector
1481 // - vector : Vector which the energy should be calculated on
1482 // - vector_length : Number of samples in vector
1485 // - scale_factor : Number of left bit shifts needed to get the physical
1486 // energy value, i.e, to get the Q0 value
1488 // Return value : Energy value in Q(-|scale_factor|)
1492 // WebRtcSpl_FilterAR(...)
1494 // Performs a 32-bit AR filtering on a vector in Q12
1497 // - ar_coef : AR-coefficient vector (values in Q12),
1498 // ar_coef[0] must be 4096.
1499 // - ar_coef_length : Number of coefficients in |ar_coef|.
1500 // - in_vector : Vector to be filtered.
1501 // - in_vector_length : Number of samples in |in_vector|.
1502 // - filter_state : Current state (higher part) of the filter.
1503 // - filter_state_length : Length (in samples) of |filter_state|.
1504 // - filter_state_low : Current state (lower part) of the filter.
1505 // - filter_state_low_length : Length (in samples) of |filter_state_low|.
1506 // - out_vector_low_length : Maximum length (in samples) of
1507 // |out_vector_low|.
1510 // - filter_state : Updated state (upper part) vector.
1511 // - filter_state_low : Updated state (lower part) vector.
1512 // - out_vector : Vector containing the upper part of the
1514 // - out_vector_low : Vector containing the lower part of the
1517 // Return value : Number of samples in the |out_vector|.
1521 // WebRtcSpl_FilterMAFastQ12(...)
1523 // Performs a MA filtering on a vector in Q12
1526 // - in_vector : Input samples (state in positions
1527 // in_vector[-order] .. in_vector[-1])
1528 // - ma_coef : Filter coefficients (in Q12)
1529 // - ma_coef_length : Number of B coefficients (order+1)
1530 // - vector_length : Number of samples to be filtered
1533 // - out_vector : Filtered samples
1537 // WebRtcSpl_ComplexIFFT(...)
1539 // Complex Inverse FFT
1541 // Computes an inverse complex 2^|stages|-point FFT on the input vector, which
1542 // is in bit-reversed order. The original content of the vector is destroyed in
1543 // the process, since the input is overwritten by the output, normal-ordered,
1544 // FFT vector. With X as the input complex vector, y as the output complex
1545 // vector and with M = 2^|stages|, the following is computed:
1548 // y(k) = sum[X(i)*[cos(2*pi*i*k/M) + j*sin(2*pi*i*k/M)]]
1551 // The implementations are optimized for speed, not for code size. It uses the
1552 // decimation-in-time algorithm with radix-2 butterfly technique.
1555 // - vector : In pointer to complex vector containing 2^|stages|
1556 // real elements interleaved with 2^|stages| imaginary
1558 // [ReImReImReIm....]
1559 // The elements are in Q(-scale) domain, see more on Return
1562 // - stages : Number of FFT stages. Must be at least 3 and at most 10,
1563 // since the table WebRtcSpl_kSinTable1024[] is 1024
1566 // - mode : This parameter gives the user to choose how the FFT
1568 // mode==0: Low-complexity and Low-accuracy mode
1569 // mode==1: High-complexity and High-accuracy mode
1572 // - vector : Out pointer to the FFT vector (the same as input).
1574 // Return Value : The scale value that tells the number of left bit shifts
1575 // that the elements in the |vector| should be shifted with
1576 // in order to get Q0 values, i.e. the physically correct
1577 // values. The scale parameter is always 0 or positive,
1578 // except if N>1024 (|stages|>10), which returns a scale
1579 // value of -1, indicating error.
1583 // WebRtcSpl_ComplexFFT(...)
1587 // Computes a complex 2^|stages|-point FFT on the input vector, which is in
1588 // bit-reversed order. The original content of the vector is destroyed in
1589 // the process, since the input is overwritten by the output, normal-ordered,
1590 // FFT vector. With x as the input complex vector, Y as the output complex
1591 // vector and with M = 2^|stages|, the following is computed:
1594 // Y(k) = 1/M * sum[x(i)*[cos(2*pi*i*k/M) + j*sin(2*pi*i*k/M)]]
1597 // The implementations are optimized for speed, not for code size. It uses the
1598 // decimation-in-time algorithm with radix-2 butterfly technique.
1600 // This routine prevents overflow by scaling by 2 before each FFT stage. This is
1601 // a fixed scaling, for proper normalization - there will be log2(n) passes, so
1602 // this results in an overall factor of 1/n, distributed to maximize arithmetic
1606 // - vector : In pointer to complex vector containing 2^|stages| real
1607 // elements interleaved with 2^|stages| imaginary elements.
1608 // [ReImReImReIm....]
1609 // The output is in the Q0 domain.
1611 // - stages : Number of FFT stages. Must be at least 3 and at most 10,
1612 // since the table WebRtcSpl_kSinTable1024[] is 1024
1615 // - mode : This parameter gives the user to choose how the FFT
1617 // mode==0: Low-complexity and Low-accuracy mode
1618 // mode==1: High-complexity and High-accuracy mode
1621 // - vector : The output FFT vector is in the Q0 domain.
1623 // Return value : The scale parameter is always 0, except if N>1024,
1624 // which returns a scale value of -1, indicating error.
1628 // WebRtcSpl_AnalysisQMF(...)
1630 // Splits a 0-2*F Hz signal into two sub bands: 0-F Hz and F-2*F Hz. The
1631 // current version has F = 8000, therefore, a super-wideband audio signal is
1632 // split to lower-band 0-8 kHz and upper-band 8-16 kHz.
1635 // - in_data : Wide band speech signal, 320 samples (10 ms)
1638 // - filter_state1 : Filter state for first All-pass filter
1639 // - filter_state2 : Filter state for second All-pass filter
1642 // - low_band : Lower-band signal 0-8 kHz band, 160 samples (10 ms)
1643 // - high_band : Upper-band signal 8-16 kHz band (flipped in frequency
1644 // domain), 160 samples (10 ms)
1648 // WebRtcSpl_SynthesisQMF(...)
1650 // Combines the two sub bands (0-F and F-2*F Hz) into a signal of 0-2*F
1651 // Hz, (current version has F = 8000 Hz). So the filter combines lower-band
1652 // (0-8 kHz) and upper-band (8-16 kHz) channels to obtain super-wideband 0-16
1656 // - low_band : The signal with the 0-8 kHz band, 160 samples (10 ms)
1657 // - high_band : The signal with the 8-16 kHz band, 160 samples (10 ms)
1660 // - filter_state1 : Filter state for first All-pass filter
1661 // - filter_state2 : Filter state for second All-pass filter
1664 // - out_data : Super-wideband speech signal, 0-16 kHz
1667 // int16_t WebRtcSpl_SatW32ToW16(...)
1669 // This function saturates a 32-bit word into a 16-bit word.
1672 // - value32 : The value of a 32-bit word.
1675 // - out16 : the saturated 16-bit word.
1678 // int32_t WebRtc_MulAccumW16(...)
1680 // This function multiply a 16-bit word by a 16-bit word, and accumulate this
1681 // value to a 32-bit integer.
1684 // - a : The value of the first 16-bit word.
1685 // - b : The value of the second 16-bit word.
1686 // - c : The value of an 32-bit integer.
1688 // Return Value: The value of a * b + c.
1691 // int16_t WebRtcSpl_get_version(...)
1693 // This function gives the version string of the Signal Processing Library.
1696 // - length_in_bytes : The size of Allocated space (in Bytes) where
1697 // the version number is written to (in string format).
1700 // - version : Pointer to a buffer where the version number is