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_32_16(a, b) \
44 ((uint32_t) ((uint32_t)(a) * (uint16_t)(b)))
45 #define WEBRTC_SPL_MUL_16_U16(a, b) \
46 ((int32_t)(int16_t)(a) * (uint16_t)(b))
48 #ifndef WEBRTC_ARCH_ARM_V7
49 // For ARMv7 platforms, these are inline functions in spl_inl_armv7.h
51 // For MIPS platforms, these are inline functions in spl_inl_mips.h
52 #define WEBRTC_SPL_MUL_16_16(a, b) \
53 ((int32_t) (((int16_t)(a)) * ((int16_t)(b))))
54 #define WEBRTC_SPL_MUL_16_32_RSFT16(a, b) \
55 (WEBRTC_SPL_MUL_16_16(a, b >> 16) \
56 + ((WEBRTC_SPL_MUL_16_16(a, (b & 0xffff) >> 1) + 0x4000) >> 15))
60 #define WEBRTC_SPL_MUL_16_32_RSFT11(a, b) \
61 ((WEBRTC_SPL_MUL_16_16(a, (b) >> 16) << 5) \
62 + (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x0200) >> 10))
63 #define WEBRTC_SPL_MUL_16_32_RSFT14(a, b) \
64 ((WEBRTC_SPL_MUL_16_16(a, (b) >> 16) << 2) \
65 + (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x1000) >> 13))
66 #define WEBRTC_SPL_MUL_16_32_RSFT15(a, b) \
67 ((WEBRTC_SPL_MUL_16_16(a, (b) >> 16) << 1) \
68 + (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x2000) >> 14))
70 #define WEBRTC_SPL_MUL_16_16_RSFT(a, b, c) \
71 (WEBRTC_SPL_MUL_16_16(a, b) >> (c))
73 #define WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(a, b, c) \
74 ((WEBRTC_SPL_MUL_16_16(a, b) + ((int32_t) \
75 (((int32_t)1) << ((c) - 1)))) >> (c))
77 // C + the 32 most significant bits of A * B
78 #define WEBRTC_SPL_SCALEDIFF32(A, B, C) \
79 (C + (B >> 16) * A + (((uint32_t)(0x0000FFFF & B) * A) >> 16))
81 #define WEBRTC_SPL_SAT(a, b, c) (b > a ? a : b < c ? c : b)
83 // Shifting with negative numbers allowed
84 // Positive means left shift
85 #define WEBRTC_SPL_SHIFT_W32(x, c) \
86 (((c) >= 0) ? ((x) << (c)) : ((x) >> (-(c))))
88 // Shifting with negative numbers not allowed
89 // We cannot do casting here due to signed/unsigned problem
90 #define WEBRTC_SPL_LSHIFT_W32(x, c) ((x) << (c))
92 #define WEBRTC_SPL_RSHIFT_U32(x, c) ((uint32_t)(x) >> (c))
94 #define WEBRTC_SPL_RAND(a) \
95 ((int16_t)(WEBRTC_SPL_MUL_16_16_RSFT((a), 18816, 7) & 0x00007fff))
101 #define WEBRTC_SPL_MEMCPY_W16(v1, v2, length) \
102 memcpy(v1, v2, (length) * sizeof(int16_t))
105 #include "webrtc/common_audio/signal_processing/include/spl_inl.h"
107 // Initialize SPL. Currently it contains only function pointer initialization.
108 // If the underlying platform is known to be ARM-Neon (WEBRTC_ARCH_ARM_NEON
109 // defined), the pointers will be assigned to code optimized for Neon; otherwise
110 // if run-time Neon detection (WEBRTC_DETECT_ARM_NEON) is enabled, the pointers
111 // will be assigned to either Neon code or generic C code; otherwise, generic C
112 // code will be assigned.
113 // Note that this function MUST be called in any application that uses SPL
115 void WebRtcSpl_Init();
117 int16_t WebRtcSpl_GetScalingSquare(int16_t* in_vector,
118 int in_vector_length,
121 // Copy and set operations. Implementation in copy_set_operations.c.
122 // Descriptions at bottom of file.
123 void WebRtcSpl_MemSetW16(int16_t* vector,
126 void WebRtcSpl_MemSetW32(int32_t* vector,
129 void WebRtcSpl_MemCpyReversedOrder(int16_t* out_vector,
132 void WebRtcSpl_CopyFromEndW16(const int16_t* in_vector,
133 int in_vector_length,
135 int16_t* out_vector);
136 void WebRtcSpl_ZerosArrayW16(int16_t* vector,
138 void WebRtcSpl_ZerosArrayW32(int32_t* vector,
140 // End: Copy and set operations.
143 // Minimum and maximum operation functions and their pointers.
144 // Implementation in min_max_operations.c.
146 // Returns the largest absolute value in a signed 16-bit vector.
149 // - vector : 16-bit input vector.
150 // - length : Number of samples in vector.
152 // Return value : Maximum absolute value in vector;
153 // or -1, if (vector == NULL || length <= 0).
154 typedef int16_t (*MaxAbsValueW16)(const int16_t* vector, int length);
155 extern MaxAbsValueW16 WebRtcSpl_MaxAbsValueW16;
156 int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, int length);
157 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
158 int16_t WebRtcSpl_MaxAbsValueW16Neon(const int16_t* vector, int length);
160 #if defined(MIPS32_LE)
161 int16_t WebRtcSpl_MaxAbsValueW16_mips(const int16_t* vector, int length);
164 // Returns the largest absolute value in a signed 32-bit vector.
167 // - vector : 32-bit input vector.
168 // - length : Number of samples in vector.
170 // Return value : Maximum absolute value in vector;
171 // or -1, if (vector == NULL || length <= 0).
172 typedef int32_t (*MaxAbsValueW32)(const int32_t* vector, int length);
173 extern MaxAbsValueW32 WebRtcSpl_MaxAbsValueW32;
174 int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, int length);
175 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
176 int32_t WebRtcSpl_MaxAbsValueW32Neon(const int32_t* vector, int length);
178 #if defined(MIPS_DSP_R1_LE)
179 int32_t WebRtcSpl_MaxAbsValueW32_mips(const int32_t* vector, int length);
182 // Returns the maximum value of a 16-bit vector.
185 // - vector : 16-bit input vector.
186 // - length : Number of samples in vector.
188 // Return value : Maximum sample value in |vector|.
189 // If (vector == NULL || length <= 0) WEBRTC_SPL_WORD16_MIN
190 // is returned. Note that WEBRTC_SPL_WORD16_MIN is a feasible
191 // value and we can't catch errors purely based on it.
192 typedef int16_t (*MaxValueW16)(const int16_t* vector, int length);
193 extern MaxValueW16 WebRtcSpl_MaxValueW16;
194 int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, int length);
195 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
196 int16_t WebRtcSpl_MaxValueW16Neon(const int16_t* vector, int length);
198 #if defined(MIPS32_LE)
199 int16_t WebRtcSpl_MaxValueW16_mips(const int16_t* vector, int length);
202 // Returns the maximum value of a 32-bit vector.
205 // - vector : 32-bit input vector.
206 // - length : Number of samples in vector.
208 // Return value : Maximum sample value in |vector|.
209 // If (vector == NULL || length <= 0) WEBRTC_SPL_WORD32_MIN
210 // is returned. Note that WEBRTC_SPL_WORD32_MIN is a feasible
211 // value and we can't catch errors purely based on it.
212 typedef int32_t (*MaxValueW32)(const int32_t* vector, int length);
213 extern MaxValueW32 WebRtcSpl_MaxValueW32;
214 int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, int length);
215 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
216 int32_t WebRtcSpl_MaxValueW32Neon(const int32_t* vector, int length);
218 #if defined(MIPS32_LE)
219 int32_t WebRtcSpl_MaxValueW32_mips(const int32_t* vector, int length);
222 // Returns the minimum value of a 16-bit vector.
225 // - vector : 16-bit input vector.
226 // - length : Number of samples in vector.
228 // Return value : Minimum sample value in |vector|.
229 // If (vector == NULL || length <= 0) WEBRTC_SPL_WORD16_MAX
230 // is returned. Note that WEBRTC_SPL_WORD16_MAX is a feasible
231 // value and we can't catch errors purely based on it.
232 typedef int16_t (*MinValueW16)(const int16_t* vector, int length);
233 extern MinValueW16 WebRtcSpl_MinValueW16;
234 int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, int length);
235 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
236 int16_t WebRtcSpl_MinValueW16Neon(const int16_t* vector, int length);
238 #if defined(MIPS32_LE)
239 int16_t WebRtcSpl_MinValueW16_mips(const int16_t* vector, int length);
242 // Returns the minimum value of a 32-bit vector.
245 // - vector : 32-bit input vector.
246 // - length : Number of samples in vector.
248 // Return value : Minimum sample value in |vector|.
249 // If (vector == NULL || length <= 0) WEBRTC_SPL_WORD32_MAX
250 // is returned. Note that WEBRTC_SPL_WORD32_MAX is a feasible
251 // value and we can't catch errors purely based on it.
252 typedef int32_t (*MinValueW32)(const int32_t* vector, int length);
253 extern MinValueW32 WebRtcSpl_MinValueW32;
254 int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, int length);
255 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
256 int32_t WebRtcSpl_MinValueW32Neon(const int32_t* vector, int length);
258 #if defined(MIPS32_LE)
259 int32_t WebRtcSpl_MinValueW32_mips(const int32_t* vector, int length);
262 // Returns the vector index to the largest absolute value of a 16-bit vector.
265 // - vector : 16-bit input vector.
266 // - length : Number of samples in vector.
268 // Return value : Index to the maximum absolute value in vector, or -1,
269 // if (vector == NULL || length <= 0).
270 // If there are multiple equal maxima, return the index of the
271 // first. -32768 will always have precedence over 32767 (despite
272 // -32768 presenting an int16 absolute value of 32767);
273 int WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, int length);
275 // Returns the vector index to the maximum sample value of a 16-bit vector.
278 // - vector : 16-bit input vector.
279 // - length : Number of samples in vector.
281 // Return value : Index to the maximum value in vector (if multiple
282 // indexes have the maximum, return the first);
283 // or -1, if (vector == NULL || length <= 0).
284 int WebRtcSpl_MaxIndexW16(const int16_t* vector, int length);
286 // Returns the vector index to the maximum sample value of a 32-bit vector.
289 // - vector : 32-bit input vector.
290 // - length : Number of samples in vector.
292 // Return value : Index to the maximum value in vector (if multiple
293 // indexes have the maximum, return the first);
294 // or -1, if (vector == NULL || length <= 0).
295 int WebRtcSpl_MaxIndexW32(const int32_t* vector, int length);
297 // Returns the vector index to the minimum sample value of a 16-bit vector.
300 // - vector : 16-bit input vector.
301 // - length : Number of samples in vector.
303 // Return value : Index to the mimimum value in vector (if multiple
304 // indexes have the minimum, return the first);
305 // or -1, if (vector == NULL || length <= 0).
306 int WebRtcSpl_MinIndexW16(const int16_t* vector, int length);
308 // Returns the vector index to the minimum sample value of a 32-bit vector.
311 // - vector : 32-bit input vector.
312 // - length : Number of samples in vector.
314 // Return value : Index to the mimimum value in vector (if multiple
315 // indexes have the minimum, return the first);
316 // or -1, if (vector == NULL || length <= 0).
317 int WebRtcSpl_MinIndexW32(const int32_t* vector, int length);
319 // End: Minimum and maximum operations.
322 // Vector scaling operations. Implementation in vector_scaling_operations.c.
323 // Description at bottom of file.
324 void WebRtcSpl_VectorBitShiftW16(int16_t* out_vector,
325 int16_t vector_length,
326 const int16_t* in_vector,
327 int16_t right_shifts);
328 void WebRtcSpl_VectorBitShiftW32(int32_t* out_vector,
329 int16_t vector_length,
330 const int32_t* in_vector,
331 int16_t right_shifts);
332 void WebRtcSpl_VectorBitShiftW32ToW16(int16_t* out_vector,
334 const int32_t* in_vector,
336 void WebRtcSpl_ScaleVector(const int16_t* in_vector,
339 int16_t vector_length,
340 int16_t right_shifts);
341 void WebRtcSpl_ScaleVectorWithSat(const int16_t* in_vector,
344 int16_t vector_length,
345 int16_t right_shifts);
346 void WebRtcSpl_ScaleAndAddVectors(const int16_t* in_vector1,
347 int16_t gain1, int right_shifts1,
348 const int16_t* in_vector2,
349 int16_t gain2, int right_shifts2,
353 // The functions (with related pointer) perform the vector operation:
354 // out_vector[k] = ((scale1 * in_vector1[k]) + (scale2 * in_vector2[k])
355 // + round_value) >> right_shifts,
356 // where round_value = (1 << right_shifts) >> 1.
359 // - in_vector1 : Input vector 1
360 // - in_vector1_scale : Gain to be used for vector 1
361 // - in_vector2 : Input vector 2
362 // - in_vector2_scale : Gain to be used for vector 2
363 // - right_shifts : Number of right bit shifts to be applied
364 // - length : Number of elements in the input vectors
367 // - out_vector : Output vector
368 // Return value : 0 if OK, -1 if (in_vector1 == NULL
369 // || in_vector2 == NULL || out_vector == NULL
370 // || length <= 0 || right_shift < 0).
371 typedef int (*ScaleAndAddVectorsWithRound)(const int16_t* in_vector1,
372 int16_t in_vector1_scale,
373 const int16_t* in_vector2,
374 int16_t in_vector2_scale,
378 extern ScaleAndAddVectorsWithRound WebRtcSpl_ScaleAndAddVectorsWithRound;
379 int WebRtcSpl_ScaleAndAddVectorsWithRoundC(const int16_t* in_vector1,
380 int16_t in_vector1_scale,
381 const int16_t* in_vector2,
382 int16_t in_vector2_scale,
386 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
387 int WebRtcSpl_ScaleAndAddVectorsWithRoundNeon(const int16_t* in_vector1,
388 int16_t in_vector1_scale,
389 const int16_t* in_vector2,
390 int16_t in_vector2_scale,
395 #if defined(MIPS_DSP_R1_LE)
396 int WebRtcSpl_ScaleAndAddVectorsWithRound_mips(const int16_t* in_vector1,
397 int16_t in_vector1_scale,
398 const int16_t* in_vector2,
399 int16_t in_vector2_scale,
404 // End: Vector scaling operations.
406 // iLBC specific functions. Implementations in ilbc_specific_functions.c.
407 // Description at bottom of file.
408 void WebRtcSpl_ReverseOrderMultArrayElements(int16_t* out_vector,
409 const int16_t* in_vector,
410 const int16_t* window,
411 int16_t vector_length,
412 int16_t right_shifts);
413 void WebRtcSpl_ElementwiseVectorMult(int16_t* out_vector,
414 const int16_t* in_vector,
415 const int16_t* window,
416 int16_t vector_length,
417 int16_t right_shifts);
418 void WebRtcSpl_AddVectorsAndShift(int16_t* out_vector,
419 const int16_t* in_vector1,
420 const int16_t* in_vector2,
421 int16_t vector_length,
422 int16_t right_shifts);
423 void WebRtcSpl_AddAffineVectorToVector(int16_t* out_vector,
426 int32_t add_constant,
427 int16_t right_shifts,
429 void WebRtcSpl_AffineTransformVector(int16_t* out_vector,
432 int32_t add_constant,
433 int16_t right_shifts,
435 // End: iLBC specific functions.
437 // Signal processing operations.
439 // A 32-bit fix-point implementation of auto-correlation computation
442 // - in_vector : Vector to calculate autocorrelation upon
443 // - in_vector_length : Length (in samples) of |vector|
444 // - order : The order up to which the autocorrelation should be
448 // - result : auto-correlation values (values should be seen
449 // relative to each other since the absolute values
450 // might have been down shifted to avoid overflow)
452 // - scale : The number of left shifts required to obtain the
453 // auto-correlation in Q0
456 // - -1, if |order| > |in_vector_length|;
457 // - Number of samples in |result|, i.e. (order+1), otherwise.
458 int WebRtcSpl_AutoCorrelation(const int16_t* in_vector,
459 int in_vector_length,
464 // A 32-bit fix-point implementation of the Levinson-Durbin algorithm that
465 // does NOT use the 64 bit class
468 // - auto_corr : Vector with autocorrelation values of length >=
470 // - use_order : The LPC filter order (support up to order 20)
473 // - lpc_coef : lpc_coef[0..use_order] LPC coefficients in Q12
474 // - refl_coef : refl_coef[0...use_order-1]| Reflection coefficients in
477 // Return value : 1 for stable 0 for unstable
478 int16_t WebRtcSpl_LevinsonDurbin(int32_t* auto_corr,
483 // Converts reflection coefficients |refl_coef| to LPC coefficients |lpc_coef|.
484 // This version is a 16 bit operation.
486 // NOTE: The 16 bit refl_coef -> lpc_coef conversion might result in a
487 // "slightly unstable" filter (i.e., a pole just outside the unit circle) in
488 // "rare" cases even if the reflection coefficients are stable.
491 // - refl_coef : Reflection coefficients in Q15 that should be converted
492 // to LPC coefficients
493 // - use_order : Number of coefficients in |refl_coef|
496 // - lpc_coef : LPC coefficients in Q12
497 void WebRtcSpl_ReflCoefToLpc(const int16_t* refl_coef,
501 // Converts LPC coefficients |lpc_coef| to reflection coefficients |refl_coef|.
502 // This version is a 16 bit operation.
503 // The conversion is implemented by the step-down algorithm.
506 // - lpc_coef : LPC coefficients in Q12, that should be converted to
507 // reflection coefficients
508 // - use_order : Number of coefficients in |lpc_coef|
511 // - refl_coef : Reflection coefficients in Q15.
512 void WebRtcSpl_LpcToReflCoef(int16_t* lpc_coef,
516 // Calculates reflection coefficients (16 bit) from auto-correlation values
519 // - auto_corr : Auto-correlation values
520 // - use_order : Number of coefficients wanted be calculated
523 // - refl_coef : Reflection coefficients in Q15.
524 void WebRtcSpl_AutoCorrToReflCoef(const int32_t* auto_corr,
528 // The functions (with related pointer) calculate the cross-correlation between
529 // two sequences |seq1| and |seq2|.
530 // |seq1| is fixed and |seq2| slides as the pointer is increased with the
531 // amount |step_seq2|. Note the arguments should obey the relationship:
532 // |dim_seq| - 1 + |step_seq2| * (|dim_cross_correlation| - 1) <
533 // buffer size of |seq2|
536 // - seq1 : First sequence (fixed throughout the correlation)
537 // - seq2 : Second sequence (slides |step_vector2| for each
539 // - dim_seq : Number of samples to use in the cross-correlation
540 // - dim_cross_correlation : Number of cross-correlations to calculate (the
541 // start position for |vector2| is updated for each
543 // - right_shifts : Number of right bit shifts to use. This will
544 // become the output Q-domain.
545 // - step_seq2 : How many (positive or negative) steps the
546 // |vector2| pointer should be updated for each new
547 // cross-correlation value.
550 // - cross_correlation : The cross-correlation in Q(-right_shifts)
551 typedef void (*CrossCorrelation)(int32_t* cross_correlation,
555 int16_t dim_cross_correlation,
556 int16_t right_shifts,
558 extern CrossCorrelation WebRtcSpl_CrossCorrelation;
559 void WebRtcSpl_CrossCorrelationC(int32_t* cross_correlation,
563 int16_t dim_cross_correlation,
564 int16_t right_shifts,
566 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
567 void WebRtcSpl_CrossCorrelationNeon(int32_t* cross_correlation,
571 int16_t dim_cross_correlation,
572 int16_t right_shifts,
575 #if defined(MIPS32_LE)
576 void WebRtcSpl_CrossCorrelation_mips(int32_t* cross_correlation,
580 int16_t dim_cross_correlation,
581 int16_t right_shifts,
585 // Creates (the first half of) a Hanning window. Size must be at least 1 and
589 // - size : Length of the requested Hanning window (1 to 512)
592 // - window : Hanning vector in Q14.
593 void WebRtcSpl_GetHanningWindow(int16_t* window, int16_t size);
595 // Calculates y[k] = sqrt(1 - x[k]^2) for each element of the input vector
596 // |in_vector|. Input and output values are in Q15.
599 // - in_vector : Values to calculate sqrt(1 - x^2) of
600 // - vector_length : Length of vector |in_vector|
603 // - out_vector : Output values in Q15
604 void WebRtcSpl_SqrtOfOneMinusXSquared(int16_t* in_vector,
606 int16_t* out_vector);
607 // End: Signal processing operations.
609 // Randomization functions. Implementations collected in
610 // randomization_functions.c and descriptions at bottom of this file.
611 int16_t WebRtcSpl_RandU(uint32_t* seed);
612 int16_t WebRtcSpl_RandN(uint32_t* seed);
613 int16_t WebRtcSpl_RandUArray(int16_t* vector,
614 int16_t vector_length,
616 // End: Randomization functions.
619 int32_t WebRtcSpl_Sqrt(int32_t value);
620 int32_t WebRtcSpl_SqrtFloor(int32_t value);
622 // Divisions. Implementations collected in division_operations.c and
623 // descriptions at bottom of this file.
624 uint32_t WebRtcSpl_DivU32U16(uint32_t num, uint16_t den);
625 int32_t WebRtcSpl_DivW32W16(int32_t num, int16_t den);
626 int16_t WebRtcSpl_DivW32W16ResW16(int32_t num, int16_t den);
627 int32_t WebRtcSpl_DivResultInQ31(int32_t num, int32_t den);
628 int32_t WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low);
631 int32_t WebRtcSpl_Energy(int16_t* vector, int vector_length, int* scale_factor);
633 // Calculates the dot product between two (int16_t) vectors.
636 // - vector1 : Vector 1
637 // - vector2 : Vector 2
638 // - vector_length : Number of samples used in the dot product
639 // - scaling : The number of right bit shifts to apply on each term
640 // during calculation to avoid overflow, i.e., the
641 // output will be in Q(-|scaling|)
643 // Return value : The dot product in Q(-scaling)
644 int32_t WebRtcSpl_DotProductWithScale(const int16_t* vector1,
645 const int16_t* vector2,
649 // Filter operations.
650 int WebRtcSpl_FilterAR(const int16_t* ar_coef,
652 const int16_t* in_vector,
653 int in_vector_length,
654 int16_t* filter_state,
655 int filter_state_length,
656 int16_t* filter_state_low,
657 int filter_state_low_length,
659 int16_t* out_vector_low,
660 int out_vector_low_length);
662 void WebRtcSpl_FilterMAFastQ12(int16_t* in_vector,
665 int16_t ma_coef_length,
666 int16_t vector_length);
668 // Performs a AR filtering on a vector in Q12
670 // - data_in : Input samples
671 // - data_out : State information in positions
672 // data_out[-order] .. data_out[-1]
673 // - coefficients : Filter coefficients (in Q12)
674 // - coefficients_length: Number of coefficients (order+1)
675 // - data_length : Number of samples to be filtered
677 // - data_out : Filtered samples
678 void WebRtcSpl_FilterARFastQ12(const int16_t* data_in,
680 const int16_t* __restrict coefficients,
681 int coefficients_length,
684 // The functions (with related pointer) perform a MA down sampling filter
687 // - data_in : Input samples (state in positions
688 // data_in[-order] .. data_in[-1])
689 // - data_in_length : Number of samples in |data_in| to be filtered.
690 // This must be at least
691 // |delay| + |factor|*(|out_vector_length|-1) + 1)
692 // - data_out_length : Number of down sampled samples desired
693 // - coefficients : Filter coefficients (in Q12)
694 // - coefficients_length: Number of coefficients (order+1)
695 // - factor : Decimation factor
696 // - delay : Delay of filter (compensated for in out_vector)
698 // - data_out : Filtered samples
699 // Return value : 0 if OK, -1 if |in_vector| is too short
700 typedef int (*DownsampleFast)(const int16_t* data_in,
704 const int16_t* __restrict coefficients,
705 int coefficients_length,
708 extern DownsampleFast WebRtcSpl_DownsampleFast;
709 int WebRtcSpl_DownsampleFastC(const int16_t* data_in,
713 const int16_t* __restrict coefficients,
714 int coefficients_length,
717 #if (defined WEBRTC_DETECT_ARM_NEON) || (defined WEBRTC_ARCH_ARM_NEON)
718 int WebRtcSpl_DownsampleFastNeon(const int16_t* data_in,
722 const int16_t* __restrict coefficients,
723 int coefficients_length,
727 #if defined(MIPS32_LE)
728 int WebRtcSpl_DownsampleFast_mips(const int16_t* data_in,
732 const int16_t* __restrict coefficients,
733 int coefficients_length,
738 // End: Filter operations.
742 int WebRtcSpl_ComplexFFT(int16_t vector[], int stages, int mode);
743 int WebRtcSpl_ComplexIFFT(int16_t vector[], int stages, int mode);
745 // Treat a 16-bit complex data buffer |complex_data| as an array of 32-bit
746 // values, and swap elements whose indexes are bit-reverses of each other.
749 // - complex_data : Complex data buffer containing 2^|stages| real
750 // elements interleaved with 2^|stages| imaginary
751 // elements: [Re Im Re Im Re Im....]
752 // - stages : Number of FFT stages. Must be at least 3 and at most
753 // 10, since the table WebRtcSpl_kSinTable1024[] is 1024
757 // - complex_data : The complex data buffer.
759 void WebRtcSpl_ComplexBitReverse(int16_t* __restrict complex_data, int stages);
761 // End: FFT operations
763 /************************************************************
765 * RESAMPLING FUNCTIONS AND THEIR STRUCTS ARE DEFINED BELOW
767 ************************************************************/
769 /*******************************************************************
772 * Includes the following resampling combinations
778 ******************************************************************/
780 // state structure for 22 -> 16 resampler
785 } WebRtcSpl_State22khzTo16khz;
787 void WebRtcSpl_Resample22khzTo16khz(const int16_t* in,
789 WebRtcSpl_State22khzTo16khz* state,
792 void WebRtcSpl_ResetResample22khzTo16khz(WebRtcSpl_State22khzTo16khz* state);
794 // state structure for 16 -> 22 resampler
798 } WebRtcSpl_State16khzTo22khz;
800 void WebRtcSpl_Resample16khzTo22khz(const int16_t* in,
802 WebRtcSpl_State16khzTo22khz* state,
805 void WebRtcSpl_ResetResample16khzTo22khz(WebRtcSpl_State16khzTo22khz* state);
807 // state structure for 22 -> 8 resampler
812 } WebRtcSpl_State22khzTo8khz;
814 void WebRtcSpl_Resample22khzTo8khz(const int16_t* in, int16_t* out,
815 WebRtcSpl_State22khzTo8khz* state,
818 void WebRtcSpl_ResetResample22khzTo8khz(WebRtcSpl_State22khzTo8khz* state);
820 // state structure for 8 -> 22 resampler
825 } WebRtcSpl_State8khzTo22khz;
827 void WebRtcSpl_Resample8khzTo22khz(const int16_t* in, int16_t* out,
828 WebRtcSpl_State8khzTo22khz* state,
831 void WebRtcSpl_ResetResample8khzTo22khz(WebRtcSpl_State8khzTo22khz* state);
833 /*******************************************************************
834 * resample_fractional.c
835 * Functions for internal use in the other resample functions
837 * Includes the following resampling combinations
842 ******************************************************************/
844 void WebRtcSpl_Resample48khzTo32khz(const int32_t* In, int32_t* Out,
847 void WebRtcSpl_Resample32khzTo24khz(const int32_t* In, int32_t* Out,
850 void WebRtcSpl_Resample44khzTo32khz(const int32_t* In, int32_t* Out,
853 /*******************************************************************
856 * Includes the following resampling combinations
862 ******************************************************************/
868 } WebRtcSpl_State48khzTo16khz;
870 void WebRtcSpl_Resample48khzTo16khz(const int16_t* in, int16_t* out,
871 WebRtcSpl_State48khzTo16khz* state,
874 void WebRtcSpl_ResetResample48khzTo16khz(WebRtcSpl_State48khzTo16khz* state);
880 } WebRtcSpl_State16khzTo48khz;
882 void WebRtcSpl_Resample16khzTo48khz(const int16_t* in, int16_t* out,
883 WebRtcSpl_State16khzTo48khz* state,
886 void WebRtcSpl_ResetResample16khzTo48khz(WebRtcSpl_State16khzTo48khz* state);
893 } WebRtcSpl_State48khzTo8khz;
895 void WebRtcSpl_Resample48khzTo8khz(const int16_t* in, int16_t* out,
896 WebRtcSpl_State48khzTo8khz* state,
899 void WebRtcSpl_ResetResample48khzTo8khz(WebRtcSpl_State48khzTo8khz* state);
906 } WebRtcSpl_State8khzTo48khz;
908 void WebRtcSpl_Resample8khzTo48khz(const int16_t* in, int16_t* out,
909 WebRtcSpl_State8khzTo48khz* state,
912 void WebRtcSpl_ResetResample8khzTo48khz(WebRtcSpl_State8khzTo48khz* state);
914 /*******************************************************************
917 * Includes down and up sampling by a factor of two.
919 ******************************************************************/
921 void WebRtcSpl_DownsampleBy2(const int16_t* in, int len,
922 int16_t* out, int32_t* filtState);
924 void WebRtcSpl_UpsampleBy2(const int16_t* in, int len,
925 int16_t* out, int32_t* filtState);
927 /************************************************************
928 * END OF RESAMPLING FUNCTIONS
929 ************************************************************/
930 void WebRtcSpl_AnalysisQMF(const int16_t* in_data,
934 int32_t* filter_state1,
935 int32_t* filter_state2);
936 void WebRtcSpl_SynthesisQMF(const int16_t* low_band,
937 const int16_t* high_band,
940 int32_t* filter_state1,
941 int32_t* filter_state2);
945 #endif // __cplusplus
946 #endif // WEBRTC_SPL_SIGNAL_PROCESSING_LIBRARY_H_
949 // WebRtcSpl_AddSatW16(...)
950 // WebRtcSpl_AddSatW32(...)
952 // Returns the result of a saturated 16-bit, respectively 32-bit, addition of
953 // the numbers specified by the |var1| and |var2| parameters.
956 // - var1 : Input variable 1
957 // - var2 : Input variable 2
959 // Return value : Added and saturated value
963 // WebRtcSpl_SubSatW16(...)
964 // WebRtcSpl_SubSatW32(...)
966 // Returns the result of a saturated 16-bit, respectively 32-bit, subtraction
967 // of the numbers specified by the |var1| and |var2| parameters.
970 // - var1 : Input variable 1
971 // - var2 : Input variable 2
973 // Returned value : Subtracted and saturated value
977 // WebRtcSpl_GetSizeInBits(...)
979 // Returns the # of bits that are needed at the most to represent the number
980 // specified by the |value| parameter.
983 // - value : Input value
985 // Return value : Number of bits needed to represent |value|
989 // WebRtcSpl_NormW32(...)
991 // Norm returns the # of left shifts required to 32-bit normalize the 32-bit
992 // signed number specified by the |value| parameter.
995 // - value : Input value
997 // Return value : Number of bit shifts needed to 32-bit normalize |value|
1001 // WebRtcSpl_NormW16(...)
1003 // Norm returns the # of left shifts required to 16-bit normalize the 16-bit
1004 // signed number specified by the |value| parameter.
1007 // - value : Input value
1009 // Return value : Number of bit shifts needed to 32-bit normalize |value|
1013 // WebRtcSpl_NormU32(...)
1015 // Norm returns the # of left shifts required to 32-bit normalize the unsigned
1016 // 32-bit number specified by the |value| parameter.
1019 // - value : Input value
1021 // Return value : Number of bit shifts needed to 32-bit normalize |value|
1025 // WebRtcSpl_GetScalingSquare(...)
1027 // Returns the # of bits required to scale the samples specified in the
1028 // |in_vector| parameter so that, if the squares of the samples are added the
1029 // # of times specified by the |times| parameter, the 32-bit addition will not
1030 // overflow (result in int32_t).
1033 // - in_vector : Input vector to check scaling on
1034 // - in_vector_length : Samples in |in_vector|
1035 // - times : Number of additions to be performed
1037 // Return value : Number of right bit shifts needed to avoid
1038 // overflow in the addition calculation
1042 // WebRtcSpl_MemSetW16(...)
1044 // Sets all the values in the int16_t vector |vector| of length
1045 // |vector_length| to the specified value |set_value|
1048 // - vector : Pointer to the int16_t vector
1049 // - set_value : Value specified
1050 // - vector_length : Length of vector
1054 // WebRtcSpl_MemSetW32(...)
1056 // Sets all the values in the int32_t vector |vector| of length
1057 // |vector_length| to the specified value |set_value|
1060 // - vector : Pointer to the int16_t vector
1061 // - set_value : Value specified
1062 // - vector_length : Length of vector
1066 // WebRtcSpl_MemCpyReversedOrder(...)
1068 // Copies all the values from the source int16_t vector |in_vector| to a
1069 // destination int16_t vector |out_vector|. It is done in reversed order,
1070 // meaning that the first sample of |in_vector| is copied to the last sample of
1071 // the |out_vector|. The procedure continues until the last sample of
1072 // |in_vector| has been copied to the first sample of |out_vector|. This
1073 // creates a reversed vector. Used in e.g. prediction in iLBC.
1076 // - in_vector : Pointer to the first sample in a int16_t vector
1077 // of length |length|
1078 // - vector_length : Number of elements to copy
1081 // - out_vector : Pointer to the last sample in a int16_t vector
1082 // of length |length|
1086 // WebRtcSpl_CopyFromEndW16(...)
1088 // Copies the rightmost |samples| of |in_vector| (of length |in_vector_length|)
1089 // to the vector |out_vector|.
1092 // - in_vector : Input vector
1093 // - in_vector_length : Number of samples in |in_vector|
1094 // - samples : Number of samples to extract (from right side)
1098 // - out_vector : Vector with the requested samples
1102 // WebRtcSpl_ZerosArrayW16(...)
1103 // WebRtcSpl_ZerosArrayW32(...)
1105 // Inserts the value "zero" in all positions of a w16 and a w32 vector
1109 // - vector_length : Number of samples in vector
1112 // - vector : Vector containing all zeros
1116 // WebRtcSpl_VectorBitShiftW16(...)
1117 // WebRtcSpl_VectorBitShiftW32(...)
1119 // Bit shifts all the values in a vector up or downwards. Different calls for
1120 // int16_t and int32_t vectors respectively.
1123 // - vector_length : Length of vector
1124 // - in_vector : Pointer to the vector that should be bit shifted
1125 // - right_shifts : Number of right bit shifts (negative value gives left
1129 // - out_vector : Pointer to the result vector (can be the same as
1134 // WebRtcSpl_VectorBitShiftW32ToW16(...)
1136 // Bit shifts all the values in a int32_t vector up or downwards and
1137 // stores the result as an int16_t vector. The function will saturate the
1138 // signal if needed, before storing in the output vector.
1141 // - vector_length : Length of vector
1142 // - in_vector : Pointer to the vector that should be bit shifted
1143 // - right_shifts : Number of right bit shifts (negative value gives left
1147 // - out_vector : Pointer to the result vector (can be the same as
1152 // WebRtcSpl_ScaleVector(...)
1154 // Performs the vector operation:
1155 // out_vector[k] = (gain*in_vector[k])>>right_shifts
1158 // - in_vector : Input vector
1159 // - gain : Scaling gain
1160 // - vector_length : Elements in the |in_vector|
1161 // - right_shifts : Number of right bit shifts applied
1164 // - out_vector : Output vector (can be the same as |in_vector|)
1168 // WebRtcSpl_ScaleVectorWithSat(...)
1170 // Performs the vector operation:
1171 // out_vector[k] = SATURATE( (gain*in_vector[k])>>right_shifts )
1174 // - in_vector : Input vector
1175 // - gain : Scaling gain
1176 // - vector_length : Elements in the |in_vector|
1177 // - right_shifts : Number of right bit shifts applied
1180 // - out_vector : Output vector (can be the same as |in_vector|)
1184 // WebRtcSpl_ScaleAndAddVectors(...)
1186 // Performs the vector operation:
1187 // out_vector[k] = (gain1*in_vector1[k])>>right_shifts1
1188 // + (gain2*in_vector2[k])>>right_shifts2
1191 // - in_vector1 : Input vector 1
1192 // - gain1 : Gain to be used for vector 1
1193 // - right_shifts1 : Right bit shift to be used for vector 1
1194 // - in_vector2 : Input vector 2
1195 // - gain2 : Gain to be used for vector 2
1196 // - right_shifts2 : Right bit shift to be used for vector 2
1197 // - vector_length : Elements in the input vectors
1200 // - out_vector : Output vector
1204 // WebRtcSpl_ReverseOrderMultArrayElements(...)
1206 // Performs the vector operation:
1207 // out_vector[n] = (in_vector[n]*window[-n])>>right_shifts
1210 // - in_vector : Input vector
1211 // - window : Window vector (should be reversed). The pointer
1212 // should be set to the last value in the vector
1213 // - right_shifts : Number of right bit shift to be applied after the
1215 // - vector_length : Number of elements in |in_vector|
1218 // - out_vector : Output vector (can be same as |in_vector|)
1222 // WebRtcSpl_ElementwiseVectorMult(...)
1224 // Performs the vector operation:
1225 // out_vector[n] = (in_vector[n]*window[n])>>right_shifts
1228 // - in_vector : Input vector
1229 // - window : Window vector.
1230 // - right_shifts : Number of right bit shift to be applied after the
1232 // - vector_length : Number of elements in |in_vector|
1235 // - out_vector : Output vector (can be same as |in_vector|)
1239 // WebRtcSpl_AddVectorsAndShift(...)
1241 // Performs the vector operation:
1242 // out_vector[k] = (in_vector1[k] + in_vector2[k])>>right_shifts
1245 // - in_vector1 : Input vector 1
1246 // - in_vector2 : Input vector 2
1247 // - right_shifts : Number of right bit shift to be applied after the
1249 // - vector_length : Number of elements in |in_vector1| and |in_vector2|
1252 // - out_vector : Output vector (can be same as |in_vector1|)
1256 // WebRtcSpl_AddAffineVectorToVector(...)
1258 // Adds an affine transformed vector to another vector |out_vector|, i.e,
1260 // out_vector[k] += (in_vector[k]*gain+add_constant)>>right_shifts
1263 // - in_vector : Input vector
1264 // - gain : Gain value, used to multiply the in vector with
1265 // - add_constant : Constant value to add (usually 1<<(right_shifts-1),
1266 // but others can be used as well
1267 // - right_shifts : Number of right bit shifts (0-16)
1268 // - vector_length : Number of samples in |in_vector| and |out_vector|
1271 // - out_vector : Vector with the output
1275 // WebRtcSpl_AffineTransformVector(...)
1277 // Affine transforms a vector, i.e, performs
1278 // out_vector[k] = (in_vector[k]*gain+add_constant)>>right_shifts
1281 // - in_vector : Input vector
1282 // - gain : Gain value, used to multiply the in vector with
1283 // - add_constant : Constant value to add (usually 1<<(right_shifts-1),
1284 // but others can be used as well
1285 // - right_shifts : Number of right bit shifts (0-16)
1286 // - vector_length : Number of samples in |in_vector| and |out_vector|
1289 // - out_vector : Vector with the output
1293 // WebRtcSpl_IncreaseSeed(...)
1295 // Increases the seed (and returns the new value)
1298 // - seed : Seed for random calculation
1301 // - seed : Updated seed value
1303 // Return value : The new seed value
1307 // WebRtcSpl_RandU(...)
1309 // Produces a uniformly distributed value in the int16_t range
1312 // - seed : Seed for random calculation
1315 // - seed : Updated seed value
1317 // Return value : Uniformly distributed value in the range
1318 // [Word16_MIN...Word16_MAX]
1322 // WebRtcSpl_RandN(...)
1324 // Produces a normal distributed value in the int16_t range
1327 // - seed : Seed for random calculation
1330 // - seed : Updated seed value
1332 // Return value : N(0,1) value in the Q13 domain
1336 // WebRtcSpl_RandUArray(...)
1338 // Produces a uniformly distributed vector with elements in the int16_t
1342 // - vector_length : Samples wanted in the vector
1343 // - seed : Seed for random calculation
1346 // - vector : Vector with the uniform values
1347 // - seed : Updated seed value
1349 // Return value : Number of samples in vector, i.e., |vector_length|
1353 // WebRtcSpl_Sqrt(...)
1355 // Returns the square root of the input value |value|. The precision of this
1356 // function is integer precision, i.e., sqrt(8) gives 2 as answer.
1357 // If |value| is a negative number then 0 is returned.
1361 // A sixth order Taylor Series expansion is used here to compute the square
1362 // root of a number y^0.5 = (1+x)^0.5
1365 // = 1+(x/2)-0.5*((x/2)^2+0.5*((x/2)^3-0.625*((x/2)^4+0.875*((x/2)^5)
1369 // - value : Value to calculate sqrt of
1371 // Return value : Result of the sqrt calculation
1375 // WebRtcSpl_SqrtFloor(...)
1377 // Returns the square root of the input value |value|. The precision of this
1378 // function is rounding down integer precision, i.e., sqrt(8) gives 2 as answer.
1379 // If |value| is a negative number then 0 is returned.
1383 // An iterative 4 cylce/bit routine
1386 // - value : Value to calculate sqrt of
1388 // Return value : Result of the sqrt calculation
1392 // WebRtcSpl_DivU32U16(...)
1394 // Divides a uint32_t |num| by a uint16_t |den|.
1396 // If |den|==0, (uint32_t)0xFFFFFFFF is returned.
1399 // - num : Numerator
1400 // - den : Denominator
1402 // Return value : Result of the division (as a uint32_t), i.e., the
1403 // integer part of num/den.
1407 // WebRtcSpl_DivW32W16(...)
1409 // Divides a int32_t |num| by a int16_t |den|.
1411 // If |den|==0, (int32_t)0x7FFFFFFF is returned.
1414 // - num : Numerator
1415 // - den : Denominator
1417 // Return value : Result of the division (as a int32_t), i.e., the
1418 // integer part of num/den.
1422 // WebRtcSpl_DivW32W16ResW16(...)
1424 // Divides a int32_t |num| by a int16_t |den|, assuming that the
1425 // result is less than 32768, otherwise an unpredictable result will occur.
1427 // If |den|==0, (int16_t)0x7FFF is returned.
1430 // - num : Numerator
1431 // - den : Denominator
1433 // Return value : Result of the division (as a int16_t), i.e., the
1434 // integer part of num/den.
1438 // WebRtcSpl_DivResultInQ31(...)
1440 // Divides a int32_t |num| by a int16_t |den|, assuming that the
1441 // absolute value of the denominator is larger than the numerator, otherwise
1442 // an unpredictable result will occur.
1445 // - num : Numerator
1446 // - den : Denominator
1448 // Return value : Result of the division in Q31.
1452 // WebRtcSpl_DivW32HiLow(...)
1454 // Divides a int32_t |num| by a denominator in hi, low format. The
1455 // absolute value of the denominator has to be larger (or equal to) the
1459 // - num : Numerator
1460 // - den_hi : High part of denominator
1461 // - den_low : Low part of denominator
1463 // Return value : Divided value in Q31
1467 // WebRtcSpl_Energy(...)
1469 // Calculates the energy of a vector
1472 // - vector : Vector which the energy should be calculated on
1473 // - vector_length : Number of samples in vector
1476 // - scale_factor : Number of left bit shifts needed to get the physical
1477 // energy value, i.e, to get the Q0 value
1479 // Return value : Energy value in Q(-|scale_factor|)
1483 // WebRtcSpl_FilterAR(...)
1485 // Performs a 32-bit AR filtering on a vector in Q12
1488 // - ar_coef : AR-coefficient vector (values in Q12),
1489 // ar_coef[0] must be 4096.
1490 // - ar_coef_length : Number of coefficients in |ar_coef|.
1491 // - in_vector : Vector to be filtered.
1492 // - in_vector_length : Number of samples in |in_vector|.
1493 // - filter_state : Current state (higher part) of the filter.
1494 // - filter_state_length : Length (in samples) of |filter_state|.
1495 // - filter_state_low : Current state (lower part) of the filter.
1496 // - filter_state_low_length : Length (in samples) of |filter_state_low|.
1497 // - out_vector_low_length : Maximum length (in samples) of
1498 // |out_vector_low|.
1501 // - filter_state : Updated state (upper part) vector.
1502 // - filter_state_low : Updated state (lower part) vector.
1503 // - out_vector : Vector containing the upper part of the
1505 // - out_vector_low : Vector containing the lower part of the
1508 // Return value : Number of samples in the |out_vector|.
1512 // WebRtcSpl_FilterMAFastQ12(...)
1514 // Performs a MA filtering on a vector in Q12
1517 // - in_vector : Input samples (state in positions
1518 // in_vector[-order] .. in_vector[-1])
1519 // - ma_coef : Filter coefficients (in Q12)
1520 // - ma_coef_length : Number of B coefficients (order+1)
1521 // - vector_length : Number of samples to be filtered
1524 // - out_vector : Filtered samples
1528 // WebRtcSpl_ComplexIFFT(...)
1530 // Complex Inverse FFT
1532 // Computes an inverse complex 2^|stages|-point FFT on the input vector, which
1533 // is in bit-reversed order. The original content of the vector is destroyed in
1534 // the process, since the input is overwritten by the output, normal-ordered,
1535 // FFT vector. With X as the input complex vector, y as the output complex
1536 // vector and with M = 2^|stages|, the following is computed:
1539 // y(k) = sum[X(i)*[cos(2*pi*i*k/M) + j*sin(2*pi*i*k/M)]]
1542 // The implementations are optimized for speed, not for code size. It uses the
1543 // decimation-in-time algorithm with radix-2 butterfly technique.
1546 // - vector : In pointer to complex vector containing 2^|stages|
1547 // real elements interleaved with 2^|stages| imaginary
1549 // [ReImReImReIm....]
1550 // The elements are in Q(-scale) domain, see more on Return
1553 // - stages : Number of FFT stages. Must be at least 3 and at most 10,
1554 // since the table WebRtcSpl_kSinTable1024[] is 1024
1557 // - mode : This parameter gives the user to choose how the FFT
1559 // mode==0: Low-complexity and Low-accuracy mode
1560 // mode==1: High-complexity and High-accuracy mode
1563 // - vector : Out pointer to the FFT vector (the same as input).
1565 // Return Value : The scale value that tells the number of left bit shifts
1566 // that the elements in the |vector| should be shifted with
1567 // in order to get Q0 values, i.e. the physically correct
1568 // values. The scale parameter is always 0 or positive,
1569 // except if N>1024 (|stages|>10), which returns a scale
1570 // value of -1, indicating error.
1574 // WebRtcSpl_ComplexFFT(...)
1578 // Computes a complex 2^|stages|-point FFT on the input vector, which is in
1579 // bit-reversed order. The original content of the vector is destroyed in
1580 // the process, since the input is overwritten by the output, normal-ordered,
1581 // FFT vector. With x as the input complex vector, Y as the output complex
1582 // vector and with M = 2^|stages|, the following is computed:
1585 // Y(k) = 1/M * sum[x(i)*[cos(2*pi*i*k/M) + j*sin(2*pi*i*k/M)]]
1588 // The implementations are optimized for speed, not for code size. It uses the
1589 // decimation-in-time algorithm with radix-2 butterfly technique.
1591 // This routine prevents overflow by scaling by 2 before each FFT stage. This is
1592 // a fixed scaling, for proper normalization - there will be log2(n) passes, so
1593 // this results in an overall factor of 1/n, distributed to maximize arithmetic
1597 // - vector : In pointer to complex vector containing 2^|stages| real
1598 // elements interleaved with 2^|stages| imaginary elements.
1599 // [ReImReImReIm....]
1600 // The output is in the Q0 domain.
1602 // - stages : Number of FFT stages. Must be at least 3 and at most 10,
1603 // since the table WebRtcSpl_kSinTable1024[] is 1024
1606 // - mode : This parameter gives the user to choose how the FFT
1608 // mode==0: Low-complexity and Low-accuracy mode
1609 // mode==1: High-complexity and High-accuracy mode
1612 // - vector : The output FFT vector is in the Q0 domain.
1614 // Return value : The scale parameter is always 0, except if N>1024,
1615 // which returns a scale value of -1, indicating error.
1619 // WebRtcSpl_AnalysisQMF(...)
1621 // Splits a 0-2*F Hz signal into two sub bands: 0-F Hz and F-2*F Hz. The
1622 // current version has F = 8000, therefore, a super-wideband audio signal is
1623 // split to lower-band 0-8 kHz and upper-band 8-16 kHz.
1626 // - in_data : Wide band speech signal, 320 samples (10 ms)
1629 // - filter_state1 : Filter state for first All-pass filter
1630 // - filter_state2 : Filter state for second All-pass filter
1633 // - low_band : Lower-band signal 0-8 kHz band, 160 samples (10 ms)
1634 // - high_band : Upper-band signal 8-16 kHz band (flipped in frequency
1635 // domain), 160 samples (10 ms)
1639 // WebRtcSpl_SynthesisQMF(...)
1641 // Combines the two sub bands (0-F and F-2*F Hz) into a signal of 0-2*F
1642 // Hz, (current version has F = 8000 Hz). So the filter combines lower-band
1643 // (0-8 kHz) and upper-band (8-16 kHz) channels to obtain super-wideband 0-16
1647 // - low_band : The signal with the 0-8 kHz band, 160 samples (10 ms)
1648 // - high_band : The signal with the 8-16 kHz band, 160 samples (10 ms)
1651 // - filter_state1 : Filter state for first All-pass filter
1652 // - filter_state2 : Filter state for second All-pass filter
1655 // - out_data : Super-wideband speech signal, 0-16 kHz
1658 // int16_t WebRtcSpl_SatW32ToW16(...)
1660 // This function saturates a 32-bit word into a 16-bit word.
1663 // - value32 : The value of a 32-bit word.
1666 // - out16 : the saturated 16-bit word.
1669 // int32_t WebRtc_MulAccumW16(...)
1671 // This function multiply a 16-bit word by a 16-bit word, and accumulate this
1672 // value to a 32-bit integer.
1675 // - a : The value of the first 16-bit word.
1676 // - b : The value of the second 16-bit word.
1677 // - c : The value of an 32-bit integer.
1679 // Return Value: The value of a * b + c.