1 /* 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 * 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. 9 */ 10 11 /* 12 * This header file includes all of the fix point signal processing library 13 * (SPL) function descriptions and declarations. For specific function calls, 14 * see bottom of file. 15 */ 16 17 #ifndef COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SIGNAL_PROCESSING_LIBRARY_H_ 18 #define COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SIGNAL_PROCESSING_LIBRARY_H_ 19 20 #include <string.h> 21 22 #include "common_audio/signal_processing/dot_product_with_scale.h" 23 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) (((int16_t)a >= 0) ? ((int16_t)a) : -((int16_t)a)) 35 #define WEBRTC_SPL_ABS_W32(a) (((int32_t)a >= 0) ? ((int32_t)a) : -((int32_t)a)) 36 37 #define WEBRTC_SPL_MUL(a, b) ((int32_t)((int32_t)(a) * (int32_t)(b))) 38 #define WEBRTC_SPL_UMUL(a, b) ((uint32_t)((uint32_t)(a) * (uint32_t)(b))) 39 #define WEBRTC_SPL_UMUL_32_16(a, b) ((uint32_t)((uint32_t)(a) * (uint16_t)(b))) 40 #define WEBRTC_SPL_MUL_16_U16(a, b) ((int32_t)(int16_t)(a) * (uint16_t)(b)) 41 42 // clang-format off 43 // clang-format would choose some identation 44 // leading to presubmit error (cpplint.py) 45 #ifndef WEBRTC_ARCH_ARM_V7 46 // For ARMv7 platforms, these are inline functions in spl_inl_armv7.h 47 #ifndef MIPS32_LE 48 // For MIPS platforms, these are inline functions in spl_inl_mips.h 49 #define WEBRTC_SPL_MUL_16_16(a, b) ((int32_t)(((int16_t)(a)) * ((int16_t)(b)))) 50 #define WEBRTC_SPL_MUL_16_32_RSFT16(a, b) \ 51 (WEBRTC_SPL_MUL_16_16(a, b >> 16) + \ 52 ((WEBRTC_SPL_MUL_16_16(a, (b & 0xffff) >> 1) + 0x4000) >> 15)) 53 #endif 54 #endif 55 56 #define WEBRTC_SPL_MUL_16_32_RSFT11(a, b) \ 57 (WEBRTC_SPL_MUL_16_16(a, (b) >> 16) * (1 << 5) + \ 58 (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x0200) >> 10)) 59 #define WEBRTC_SPL_MUL_16_32_RSFT14(a, b) \ 60 (WEBRTC_SPL_MUL_16_16(a, (b) >> 16) * (1 << 2) + \ 61 (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x1000) >> 13)) 62 #define WEBRTC_SPL_MUL_16_32_RSFT15(a, b) \ 63 ((WEBRTC_SPL_MUL_16_16(a, (b) >> 16) * (1 << 1)) + \ 64 (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x2000) >> 14)) 65 // clang-format on 66 67 #define WEBRTC_SPL_MUL_16_16_RSFT(a, b, c) (WEBRTC_SPL_MUL_16_16(a, b) >> (c)) 68 69 #define WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(a, b, c) \ 70 ((WEBRTC_SPL_MUL_16_16(a, b) + ((int32_t)(((int32_t)1) << ((c)-1)))) >> (c)) 71 72 // C + the 32 most significant bits of A * B 73 #define WEBRTC_SPL_SCALEDIFF32(A, B, C) \ 74 (C + (B >> 16) * A + (((uint32_t)(B & 0x0000FFFF) * A) >> 16)) 75 76 #define WEBRTC_SPL_SAT(a, b, c) (b > a ? a : b < c ? c : b) 77 78 // Shifting with negative numbers allowed 79 // Positive means left shift 80 #define WEBRTC_SPL_SHIFT_W32(x, c) ((c) >= 0 ? (x) * (1 << (c)) : (x) >> -(c)) 81 82 // Shifting with negative numbers not allowed 83 // We cannot do casting here due to signed/unsigned problem 84 #define WEBRTC_SPL_LSHIFT_W32(x, c) ((x) << (c)) 85 86 #define WEBRTC_SPL_RSHIFT_U32(x, c) ((uint32_t)(x) >> (c)) 87 88 #define WEBRTC_SPL_RAND(a) ((int16_t)((((int16_t)a * 18816) >> 7) & 0x00007fff)) 89 90 #ifdef __cplusplus 91 extern "C" { 92 #endif 93 94 #define WEBRTC_SPL_MEMCPY_W16(v1, v2, length) \ 95 memcpy(v1, v2, (length) * sizeof(int16_t)) 96 97 // inline functions: 98 #include "common_audio/signal_processing/include/spl_inl.h" 99 100 // third party math functions 101 #include "common_audio/third_party/spl_sqrt_floor/spl_sqrt_floor.h" 102 103 int16_t WebRtcSpl_GetScalingSquare(int16_t* in_vector, 104 size_t in_vector_length, 105 size_t times); 106 107 // Copy and set operations. Implementation in copy_set_operations.c. 108 // Descriptions at bottom of file. 109 void WebRtcSpl_MemSetW16(int16_t* vector, 110 int16_t set_value, 111 size_t vector_length); 112 void WebRtcSpl_MemSetW32(int32_t* vector, 113 int32_t set_value, 114 size_t vector_length); 115 void WebRtcSpl_MemCpyReversedOrder(int16_t* out_vector, 116 int16_t* in_vector, 117 size_t vector_length); 118 void WebRtcSpl_CopyFromEndW16(const int16_t* in_vector, 119 size_t in_vector_length, 120 size_t samples, 121 int16_t* out_vector); 122 void WebRtcSpl_ZerosArrayW16(int16_t* vector, size_t vector_length); 123 void WebRtcSpl_ZerosArrayW32(int32_t* vector, size_t vector_length); 124 // End: Copy and set operations. 125 126 // Minimum and maximum operation functions and their pointers. 127 // Implementation in min_max_operations.c. 128 129 // Returns the largest absolute value in a signed 16-bit vector. 130 // 131 // Input: 132 // - vector : 16-bit input vector. 133 // - length : Number of samples in vector. 134 // 135 // Return value : Maximum absolute value in vector. 136 typedef int16_t (*MaxAbsValueW16)(const int16_t* vector, size_t length); 137 extern const MaxAbsValueW16 WebRtcSpl_MaxAbsValueW16; 138 int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, size_t length); 139 #if defined(WEBRTC_HAS_NEON) 140 int16_t WebRtcSpl_MaxAbsValueW16Neon(const int16_t* vector, size_t length); 141 #endif 142 #if defined(MIPS32_LE) 143 int16_t WebRtcSpl_MaxAbsValueW16_mips(const int16_t* vector, size_t length); 144 #endif 145 146 // Returns the largest absolute value in a signed 32-bit vector. 147 // 148 // Input: 149 // - vector : 32-bit input vector. 150 // - length : Number of samples in vector. 151 // 152 // Return value : Maximum absolute value in vector. 153 typedef int32_t (*MaxAbsValueW32)(const int32_t* vector, size_t length); 154 extern const MaxAbsValueW32 WebRtcSpl_MaxAbsValueW32; 155 int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, size_t length); 156 #if defined(WEBRTC_HAS_NEON) 157 int32_t WebRtcSpl_MaxAbsValueW32Neon(const int32_t* vector, size_t length); 158 #endif 159 #if defined(MIPS_DSP_R1_LE) 160 int32_t WebRtcSpl_MaxAbsValueW32_mips(const int32_t* vector, size_t length); 161 #endif 162 163 // Returns the maximum value of a 16-bit vector. 164 // 165 // Input: 166 // - vector : 16-bit input vector. 167 // - length : Number of samples in vector. 168 // 169 // Return value : Maximum sample value in |vector|. 170 typedef int16_t (*MaxValueW16)(const int16_t* vector, size_t length); 171 extern const MaxValueW16 WebRtcSpl_MaxValueW16; 172 int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, size_t length); 173 #if defined(WEBRTC_HAS_NEON) 174 int16_t WebRtcSpl_MaxValueW16Neon(const int16_t* vector, size_t length); 175 #endif 176 #if defined(MIPS32_LE) 177 int16_t WebRtcSpl_MaxValueW16_mips(const int16_t* vector, size_t length); 178 #endif 179 180 // Returns the maximum value of a 32-bit vector. 181 // 182 // Input: 183 // - vector : 32-bit input vector. 184 // - length : Number of samples in vector. 185 // 186 // Return value : Maximum sample value in |vector|. 187 typedef int32_t (*MaxValueW32)(const int32_t* vector, size_t length); 188 extern const MaxValueW32 WebRtcSpl_MaxValueW32; 189 int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, size_t length); 190 #if defined(WEBRTC_HAS_NEON) 191 int32_t WebRtcSpl_MaxValueW32Neon(const int32_t* vector, size_t length); 192 #endif 193 #if defined(MIPS32_LE) 194 int32_t WebRtcSpl_MaxValueW32_mips(const int32_t* vector, size_t length); 195 #endif 196 197 // Returns the minimum value of a 16-bit vector. 198 // 199 // Input: 200 // - vector : 16-bit input vector. 201 // - length : Number of samples in vector. 202 // 203 // Return value : Minimum sample value in |vector|. 204 typedef int16_t (*MinValueW16)(const int16_t* vector, size_t length); 205 extern const MinValueW16 WebRtcSpl_MinValueW16; 206 int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, size_t length); 207 #if defined(WEBRTC_HAS_NEON) 208 int16_t WebRtcSpl_MinValueW16Neon(const int16_t* vector, size_t length); 209 #endif 210 #if defined(MIPS32_LE) 211 int16_t WebRtcSpl_MinValueW16_mips(const int16_t* vector, size_t length); 212 #endif 213 214 // Returns the minimum value of a 32-bit vector. 215 // 216 // Input: 217 // - vector : 32-bit input vector. 218 // - length : Number of samples in vector. 219 // 220 // Return value : Minimum sample value in |vector|. 221 typedef int32_t (*MinValueW32)(const int32_t* vector, size_t length); 222 extern const MinValueW32 WebRtcSpl_MinValueW32; 223 int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, size_t length); 224 #if defined(WEBRTC_HAS_NEON) 225 int32_t WebRtcSpl_MinValueW32Neon(const int32_t* vector, size_t length); 226 #endif 227 #if defined(MIPS32_LE) 228 int32_t WebRtcSpl_MinValueW32_mips(const int32_t* vector, size_t length); 229 #endif 230 231 // Returns the vector index to the largest absolute value of a 16-bit vector. 232 // 233 // Input: 234 // - vector : 16-bit input vector. 235 // - length : Number of samples in vector. 236 // 237 // Return value : Index to the maximum absolute value in vector. 238 // If there are multiple equal maxima, return the index of the 239 // first. -32768 will always have precedence over 32767 (despite 240 // -32768 presenting an int16 absolute value of 32767). 241 size_t WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length); 242 243 // Returns the vector index to the maximum sample value of a 16-bit vector. 244 // 245 // Input: 246 // - vector : 16-bit input vector. 247 // - length : Number of samples in vector. 248 // 249 // Return value : Index to the maximum value in vector (if multiple 250 // indexes have the maximum, return the first). 251 size_t WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length); 252 253 // Returns the vector index to the maximum sample value of a 32-bit vector. 254 // 255 // Input: 256 // - vector : 32-bit input vector. 257 // - length : Number of samples in vector. 258 // 259 // Return value : Index to the maximum value in vector (if multiple 260 // indexes have the maximum, return the first). 261 size_t WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length); 262 263 // Returns the vector index to the minimum sample value of a 16-bit vector. 264 // 265 // Input: 266 // - vector : 16-bit input vector. 267 // - length : Number of samples in vector. 268 // 269 // Return value : Index to the mimimum value in vector (if multiple 270 // indexes have the minimum, return the first). 271 size_t WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length); 272 273 // Returns the vector index to the minimum sample value of a 32-bit vector. 274 // 275 // Input: 276 // - vector : 32-bit input vector. 277 // - length : Number of samples in vector. 278 // 279 // Return value : Index to the mimimum value in vector (if multiple 280 // indexes have the minimum, return the first). 281 size_t WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length); 282 283 // End: Minimum and maximum operations. 284 285 // Vector scaling operations. Implementation in vector_scaling_operations.c. 286 // Description at bottom of file. 287 void WebRtcSpl_VectorBitShiftW16(int16_t* out_vector, 288 size_t vector_length, 289 const int16_t* in_vector, 290 int16_t right_shifts); 291 void WebRtcSpl_VectorBitShiftW32(int32_t* out_vector, 292 size_t vector_length, 293 const int32_t* in_vector, 294 int16_t right_shifts); 295 void WebRtcSpl_VectorBitShiftW32ToW16(int16_t* out_vector, 296 size_t vector_length, 297 const int32_t* in_vector, 298 int right_shifts); 299 void WebRtcSpl_ScaleVector(const int16_t* in_vector, 300 int16_t* out_vector, 301 int16_t gain, 302 size_t vector_length, 303 int16_t right_shifts); 304 void WebRtcSpl_ScaleVectorWithSat(const int16_t* in_vector, 305 int16_t* out_vector, 306 int16_t gain, 307 size_t vector_length, 308 int16_t right_shifts); 309 void WebRtcSpl_ScaleAndAddVectors(const int16_t* in_vector1, 310 int16_t gain1, 311 int right_shifts1, 312 const int16_t* in_vector2, 313 int16_t gain2, 314 int right_shifts2, 315 int16_t* out_vector, 316 size_t vector_length); 317 318 // The functions (with related pointer) perform the vector operation: 319 // out_vector[k] = ((scale1 * in_vector1[k]) + (scale2 * in_vector2[k]) 320 // + round_value) >> right_shifts, 321 // where round_value = (1 << right_shifts) >> 1. 322 // 323 // Input: 324 // - in_vector1 : Input vector 1 325 // - in_vector1_scale : Gain to be used for vector 1 326 // - in_vector2 : Input vector 2 327 // - in_vector2_scale : Gain to be used for vector 2 328 // - right_shifts : Number of right bit shifts to be applied 329 // - length : Number of elements in the input vectors 330 // 331 // Output: 332 // - out_vector : Output vector 333 // Return value : 0 if OK, -1 if (in_vector1 == null 334 // || in_vector2 == null || out_vector == null 335 // || length <= 0 || right_shift < 0). 336 typedef int (*ScaleAndAddVectorsWithRound)(const int16_t* in_vector1, 337 int16_t in_vector1_scale, 338 const int16_t* in_vector2, 339 int16_t in_vector2_scale, 340 int right_shifts, 341 int16_t* out_vector, 342 size_t length); 343 extern const ScaleAndAddVectorsWithRound WebRtcSpl_ScaleAndAddVectorsWithRound; 344 int WebRtcSpl_ScaleAndAddVectorsWithRoundC(const int16_t* in_vector1, 345 int16_t in_vector1_scale, 346 const int16_t* in_vector2, 347 int16_t in_vector2_scale, 348 int right_shifts, 349 int16_t* out_vector, 350 size_t length); 351 #if defined(MIPS_DSP_R1_LE) 352 int WebRtcSpl_ScaleAndAddVectorsWithRound_mips(const int16_t* in_vector1, 353 int16_t in_vector1_scale, 354 const int16_t* in_vector2, 355 int16_t in_vector2_scale, 356 int right_shifts, 357 int16_t* out_vector, 358 size_t length); 359 #endif 360 // End: Vector scaling operations. 361 362 // iLBC specific functions. Implementations in ilbc_specific_functions.c. 363 // Description at bottom of file. 364 void WebRtcSpl_ReverseOrderMultArrayElements(int16_t* out_vector, 365 const int16_t* in_vector, 366 const int16_t* window, 367 size_t vector_length, 368 int16_t right_shifts); 369 void WebRtcSpl_ElementwiseVectorMult(int16_t* out_vector, 370 const int16_t* in_vector, 371 const int16_t* window, 372 size_t vector_length, 373 int16_t right_shifts); 374 void WebRtcSpl_AddVectorsAndShift(int16_t* out_vector, 375 const int16_t* in_vector1, 376 const int16_t* in_vector2, 377 size_t vector_length, 378 int16_t right_shifts); 379 void WebRtcSpl_AddAffineVectorToVector(int16_t* out_vector, 380 const int16_t* in_vector, 381 int16_t gain, 382 int32_t add_constant, 383 int16_t right_shifts, 384 size_t vector_length); 385 void WebRtcSpl_AffineTransformVector(int16_t* out_vector, 386 const int16_t* in_vector, 387 int16_t gain, 388 int32_t add_constant, 389 int16_t right_shifts, 390 size_t vector_length); 391 // End: iLBC specific functions. 392 393 // Signal processing operations. 394 395 // A 32-bit fix-point implementation of auto-correlation computation 396 // 397 // Input: 398 // - in_vector : Vector to calculate autocorrelation upon 399 // - in_vector_length : Length (in samples) of |vector| 400 // - order : The order up to which the autocorrelation should be 401 // calculated 402 // 403 // Output: 404 // - result : auto-correlation values (values should be seen 405 // relative to each other since the absolute values 406 // might have been down shifted to avoid overflow) 407 // 408 // - scale : The number of left shifts required to obtain the 409 // auto-correlation in Q0 410 // 411 // Return value : Number of samples in |result|, i.e. (order+1) 412 size_t WebRtcSpl_AutoCorrelation(const int16_t* in_vector, 413 size_t in_vector_length, 414 size_t order, 415 int32_t* result, 416 int* scale); 417 418 // A 32-bit fix-point implementation of the Levinson-Durbin algorithm that 419 // does NOT use the 64 bit class 420 // 421 // Input: 422 // - auto_corr : Vector with autocorrelation values of length >= |order|+1 423 // - order : The LPC filter order (support up to order 20) 424 // 425 // Output: 426 // - lpc_coef : lpc_coef[0..order] LPC coefficients in Q12 427 // - refl_coef : refl_coef[0...order-1]| Reflection coefficients in Q15 428 // 429 // Return value : 1 for stable 0 for unstable 430 int16_t WebRtcSpl_LevinsonDurbin(const int32_t* auto_corr, 431 int16_t* lpc_coef, 432 int16_t* refl_coef, 433 size_t order); 434 435 // Converts reflection coefficients |refl_coef| to LPC coefficients |lpc_coef|. 436 // This version is a 16 bit operation. 437 // 438 // NOTE: The 16 bit refl_coef -> lpc_coef conversion might result in a 439 // "slightly unstable" filter (i.e., a pole just outside the unit circle) in 440 // "rare" cases even if the reflection coefficients are stable. 441 // 442 // Input: 443 // - refl_coef : Reflection coefficients in Q15 that should be converted 444 // to LPC coefficients 445 // - use_order : Number of coefficients in |refl_coef| 446 // 447 // Output: 448 // - lpc_coef : LPC coefficients in Q12 449 void WebRtcSpl_ReflCoefToLpc(const int16_t* refl_coef, 450 int use_order, 451 int16_t* lpc_coef); 452 453 // Converts LPC coefficients |lpc_coef| to reflection coefficients |refl_coef|. 454 // This version is a 16 bit operation. 455 // The conversion is implemented by the step-down algorithm. 456 // 457 // Input: 458 // - lpc_coef : LPC coefficients in Q12, that should be converted to 459 // reflection coefficients 460 // - use_order : Number of coefficients in |lpc_coef| 461 // 462 // Output: 463 // - refl_coef : Reflection coefficients in Q15. 464 void WebRtcSpl_LpcToReflCoef(int16_t* lpc_coef, 465 int use_order, 466 int16_t* refl_coef); 467 468 // Calculates reflection coefficients (16 bit) from auto-correlation values 469 // 470 // Input: 471 // - auto_corr : Auto-correlation values 472 // - use_order : Number of coefficients wanted be calculated 473 // 474 // Output: 475 // - refl_coef : Reflection coefficients in Q15. 476 void WebRtcSpl_AutoCorrToReflCoef(const int32_t* auto_corr, 477 int use_order, 478 int16_t* refl_coef); 479 480 // The functions (with related pointer) calculate the cross-correlation between 481 // two sequences |seq1| and |seq2|. 482 // |seq1| is fixed and |seq2| slides as the pointer is increased with the 483 // amount |step_seq2|. Note the arguments should obey the relationship: 484 // |dim_seq| - 1 + |step_seq2| * (|dim_cross_correlation| - 1) < 485 // buffer size of |seq2| 486 // 487 // Input: 488 // - seq1 : First sequence (fixed throughout the correlation) 489 // - seq2 : Second sequence (slides |step_vector2| for each 490 // new correlation) 491 // - dim_seq : Number of samples to use in the cross-correlation 492 // - dim_cross_correlation : Number of cross-correlations to calculate (the 493 // start position for |vector2| is updated for each 494 // new one) 495 // - right_shifts : Number of right bit shifts to use. This will 496 // become the output Q-domain. 497 // - step_seq2 : How many (positive or negative) steps the 498 // |vector2| pointer should be updated for each new 499 // cross-correlation value. 500 // 501 // Output: 502 // - cross_correlation : The cross-correlation in Q(-right_shifts) 503 typedef void (*CrossCorrelation)(int32_t* cross_correlation, 504 const int16_t* seq1, 505 const int16_t* seq2, 506 size_t dim_seq, 507 size_t dim_cross_correlation, 508 int right_shifts, 509 int step_seq2); 510 extern const CrossCorrelation WebRtcSpl_CrossCorrelation; 511 void WebRtcSpl_CrossCorrelationC(int32_t* cross_correlation, 512 const int16_t* seq1, 513 const int16_t* seq2, 514 size_t dim_seq, 515 size_t dim_cross_correlation, 516 int right_shifts, 517 int step_seq2); 518 #if defined(WEBRTC_HAS_NEON) 519 void WebRtcSpl_CrossCorrelationNeon(int32_t* cross_correlation, 520 const int16_t* seq1, 521 const int16_t* seq2, 522 size_t dim_seq, 523 size_t dim_cross_correlation, 524 int right_shifts, 525 int step_seq2); 526 #endif 527 #if defined(MIPS32_LE) 528 void WebRtcSpl_CrossCorrelation_mips(int32_t* cross_correlation, 529 const int16_t* seq1, 530 const int16_t* seq2, 531 size_t dim_seq, 532 size_t dim_cross_correlation, 533 int right_shifts, 534 int step_seq2); 535 #endif 536 537 // Creates (the first half of) a Hanning window. Size must be at least 1 and 538 // at most 512. 539 // 540 // Input: 541 // - size : Length of the requested Hanning window (1 to 512) 542 // 543 // Output: 544 // - window : Hanning vector in Q14. 545 void WebRtcSpl_GetHanningWindow(int16_t* window, size_t size); 546 547 // Calculates y[k] = sqrt(1 - x[k]^2) for each element of the input vector 548 // |in_vector|. Input and output values are in Q15. 549 // 550 // Inputs: 551 // - in_vector : Values to calculate sqrt(1 - x^2) of 552 // - vector_length : Length of vector |in_vector| 553 // 554 // Output: 555 // - out_vector : Output values in Q15 556 void WebRtcSpl_SqrtOfOneMinusXSquared(int16_t* in_vector, 557 size_t vector_length, 558 int16_t* out_vector); 559 // End: Signal processing operations. 560 561 // Randomization functions. Implementations collected in 562 // randomization_functions.c and descriptions at bottom of this file. 563 int16_t WebRtcSpl_RandU(uint32_t* seed); 564 int16_t WebRtcSpl_RandN(uint32_t* seed); 565 int16_t WebRtcSpl_RandUArray(int16_t* vector, 566 int16_t vector_length, 567 uint32_t* seed); 568 // End: Randomization functions. 569 570 // Math functions 571 int32_t WebRtcSpl_Sqrt(int32_t value); 572 573 // Divisions. Implementations collected in division_operations.c and 574 // descriptions at bottom of this file. 575 uint32_t WebRtcSpl_DivU32U16(uint32_t num, uint16_t den); 576 int32_t WebRtcSpl_DivW32W16(int32_t num, int16_t den); 577 int16_t WebRtcSpl_DivW32W16ResW16(int32_t num, int16_t den); 578 int32_t WebRtcSpl_DivResultInQ31(int32_t num, int32_t den); 579 int32_t WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low); 580 // End: Divisions. 581 582 int32_t WebRtcSpl_Energy(int16_t* vector, 583 size_t vector_length, 584 int* scale_factor); 585 586 // Filter operations. 587 size_t WebRtcSpl_FilterAR(const int16_t* ar_coef, 588 size_t ar_coef_length, 589 const int16_t* in_vector, 590 size_t in_vector_length, 591 int16_t* filter_state, 592 size_t filter_state_length, 593 int16_t* filter_state_low, 594 size_t filter_state_low_length, 595 int16_t* out_vector, 596 int16_t* out_vector_low, 597 size_t out_vector_low_length); 598 599 // WebRtcSpl_FilterMAFastQ12(...) 600 // 601 // Performs a MA filtering on a vector in Q12 602 // 603 // Input: 604 // - in_vector : Input samples (state in positions 605 // in_vector[-order] .. in_vector[-1]) 606 // - ma_coef : Filter coefficients (in Q12) 607 // - ma_coef_length : Number of B coefficients (order+1) 608 // - vector_length : Number of samples to be filtered 609 // 610 // Output: 611 // - out_vector : Filtered samples 612 // 613 void WebRtcSpl_FilterMAFastQ12(const int16_t* in_vector, 614 int16_t* out_vector, 615 const int16_t* ma_coef, 616 size_t ma_coef_length, 617 size_t vector_length); 618 619 // Performs a AR filtering on a vector in Q12 620 // Input: 621 // - data_in : Input samples 622 // - data_out : State information in positions 623 // data_out[-order] .. data_out[-1] 624 // - coefficients : Filter coefficients (in Q12) 625 // - coefficients_length: Number of coefficients (order+1) 626 // - data_length : Number of samples to be filtered 627 // Output: 628 // - data_out : Filtered samples 629 void WebRtcSpl_FilterARFastQ12(const int16_t* data_in, 630 int16_t* data_out, 631 const int16_t* __restrict coefficients, 632 size_t coefficients_length, 633 size_t data_length); 634 635 // The functions (with related pointer) perform a MA down sampling filter 636 // on a vector. 637 // Input: 638 // - data_in : Input samples (state in positions 639 // data_in[-order] .. data_in[-1]) 640 // - data_in_length : Number of samples in |data_in| to be filtered. 641 // This must be at least 642 // |delay| + |factor|*(|out_vector_length|-1) + 1) 643 // - data_out_length : Number of down sampled samples desired 644 // - coefficients : Filter coefficients (in Q12) 645 // - coefficients_length: Number of coefficients (order+1) 646 // - factor : Decimation factor 647 // - delay : Delay of filter (compensated for in out_vector) 648 // Output: 649 // - data_out : Filtered samples 650 // Return value : 0 if OK, -1 if |in_vector| is too short 651 typedef int (*DownsampleFast)(const int16_t* data_in, 652 size_t data_in_length, 653 int16_t* data_out, 654 size_t data_out_length, 655 const int16_t* __restrict coefficients, 656 size_t coefficients_length, 657 int factor, 658 size_t delay); 659 extern const DownsampleFast WebRtcSpl_DownsampleFast; 660 int WebRtcSpl_DownsampleFastC(const int16_t* data_in, 661 size_t data_in_length, 662 int16_t* data_out, 663 size_t data_out_length, 664 const int16_t* __restrict coefficients, 665 size_t coefficients_length, 666 int factor, 667 size_t delay); 668 #if defined(WEBRTC_HAS_NEON) 669 int WebRtcSpl_DownsampleFastNeon(const int16_t* data_in, 670 size_t data_in_length, 671 int16_t* data_out, 672 size_t data_out_length, 673 const int16_t* __restrict coefficients, 674 size_t coefficients_length, 675 int factor, 676 size_t delay); 677 #endif 678 #if defined(MIPS32_LE) 679 int WebRtcSpl_DownsampleFast_mips(const int16_t* data_in, 680 size_t data_in_length, 681 int16_t* data_out, 682 size_t data_out_length, 683 const int16_t* __restrict coefficients, 684 size_t coefficients_length, 685 int factor, 686 size_t delay); 687 #endif 688 689 // End: Filter operations. 690 691 // FFT operations 692 693 int WebRtcSpl_ComplexFFT(int16_t vector[], int stages, int mode); 694 int WebRtcSpl_ComplexIFFT(int16_t vector[], int stages, int mode); 695 696 // Treat a 16-bit complex data buffer |complex_data| as an array of 32-bit 697 // values, and swap elements whose indexes are bit-reverses of each other. 698 // 699 // Input: 700 // - complex_data : Complex data buffer containing 2^|stages| real 701 // elements interleaved with 2^|stages| imaginary 702 // elements: [Re Im Re Im Re Im....] 703 // - stages : Number of FFT stages. Must be at least 3 and at most 704 // 10, since the table WebRtcSpl_kSinTable1024[] is 1024 705 // elements long. 706 // 707 // Output: 708 // - complex_data : The complex data buffer. 709 710 void WebRtcSpl_ComplexBitReverse(int16_t* __restrict complex_data, int stages); 711 712 // End: FFT operations 713 714 /************************************************************ 715 * 716 * RESAMPLING FUNCTIONS AND THEIR STRUCTS ARE DEFINED BELOW 717 * 718 ************************************************************/ 719 720 /******************************************************************* 721 * resample.c 722 * 723 * Includes the following resampling combinations 724 * 22 kHz -> 16 kHz 725 * 16 kHz -> 22 kHz 726 * 22 kHz -> 8 kHz 727 * 8 kHz -> 22 kHz 728 * 729 ******************************************************************/ 730 731 // state structure for 22 -> 16 resampler 732 typedef struct { 733 int32_t S_22_44[8]; 734 int32_t S_44_32[8]; 735 int32_t S_32_16[8]; 736 } WebRtcSpl_State22khzTo16khz; 737 738 void WebRtcSpl_Resample22khzTo16khz(const int16_t* in, 739 int16_t* out, 740 WebRtcSpl_State22khzTo16khz* state, 741 int32_t* tmpmem); 742 743 void WebRtcSpl_ResetResample22khzTo16khz(WebRtcSpl_State22khzTo16khz* state); 744 745 // state structure for 16 -> 22 resampler 746 typedef struct { 747 int32_t S_16_32[8]; 748 int32_t S_32_22[8]; 749 } WebRtcSpl_State16khzTo22khz; 750 751 void WebRtcSpl_Resample16khzTo22khz(const int16_t* in, 752 int16_t* out, 753 WebRtcSpl_State16khzTo22khz* state, 754 int32_t* tmpmem); 755 756 void WebRtcSpl_ResetResample16khzTo22khz(WebRtcSpl_State16khzTo22khz* state); 757 758 // state structure for 22 -> 8 resampler 759 typedef struct { 760 int32_t S_22_22[16]; 761 int32_t S_22_16[8]; 762 int32_t S_16_8[8]; 763 } WebRtcSpl_State22khzTo8khz; 764 765 void WebRtcSpl_Resample22khzTo8khz(const int16_t* in, 766 int16_t* out, 767 WebRtcSpl_State22khzTo8khz* state, 768 int32_t* tmpmem); 769 770 void WebRtcSpl_ResetResample22khzTo8khz(WebRtcSpl_State22khzTo8khz* state); 771 772 // state structure for 8 -> 22 resampler 773 typedef struct { 774 int32_t S_8_16[8]; 775 int32_t S_16_11[8]; 776 int32_t S_11_22[8]; 777 } WebRtcSpl_State8khzTo22khz; 778 779 void WebRtcSpl_Resample8khzTo22khz(const int16_t* in, 780 int16_t* out, 781 WebRtcSpl_State8khzTo22khz* state, 782 int32_t* tmpmem); 783 784 void WebRtcSpl_ResetResample8khzTo22khz(WebRtcSpl_State8khzTo22khz* state); 785 786 /******************************************************************* 787 * resample_fractional.c 788 * Functions for internal use in the other resample functions 789 * 790 * Includes the following resampling combinations 791 * 48 kHz -> 32 kHz 792 * 32 kHz -> 24 kHz 793 * 44 kHz -> 32 kHz 794 * 795 ******************************************************************/ 796 797 void WebRtcSpl_Resample48khzTo32khz(const int32_t* In, int32_t* Out, size_t K); 798 799 void WebRtcSpl_Resample32khzTo24khz(const int32_t* In, int32_t* Out, size_t K); 800 801 void WebRtcSpl_Resample44khzTo32khz(const int32_t* In, int32_t* Out, size_t K); 802 803 /******************************************************************* 804 * resample_48khz.c 805 * 806 * Includes the following resampling combinations 807 * 48 kHz -> 16 kHz 808 * 16 kHz -> 48 kHz 809 * 48 kHz -> 8 kHz 810 * 8 kHz -> 48 kHz 811 * 812 ******************************************************************/ 813 814 typedef struct { 815 int32_t S_48_48[16]; 816 int32_t S_48_32[8]; 817 int32_t S_32_16[8]; 818 } WebRtcSpl_State48khzTo16khz; 819 820 void WebRtcSpl_Resample48khzTo16khz(const int16_t* in, 821 int16_t* out, 822 WebRtcSpl_State48khzTo16khz* state, 823 int32_t* tmpmem); 824 825 void WebRtcSpl_ResetResample48khzTo16khz(WebRtcSpl_State48khzTo16khz* state); 826 827 typedef struct { 828 int32_t S_16_32[8]; 829 int32_t S_32_24[8]; 830 int32_t S_24_48[8]; 831 } WebRtcSpl_State16khzTo48khz; 832 833 void WebRtcSpl_Resample16khzTo48khz(const int16_t* in, 834 int16_t* out, 835 WebRtcSpl_State16khzTo48khz* state, 836 int32_t* tmpmem); 837 838 void WebRtcSpl_ResetResample16khzTo48khz(WebRtcSpl_State16khzTo48khz* state); 839 840 typedef struct { 841 int32_t S_48_24[8]; 842 int32_t S_24_24[16]; 843 int32_t S_24_16[8]; 844 int32_t S_16_8[8]; 845 } WebRtcSpl_State48khzTo8khz; 846 847 void WebRtcSpl_Resample48khzTo8khz(const int16_t* in, 848 int16_t* out, 849 WebRtcSpl_State48khzTo8khz* state, 850 int32_t* tmpmem); 851 852 void WebRtcSpl_ResetResample48khzTo8khz(WebRtcSpl_State48khzTo8khz* state); 853 854 typedef struct { 855 int32_t S_8_16[8]; 856 int32_t S_16_12[8]; 857 int32_t S_12_24[8]; 858 int32_t S_24_48[8]; 859 } WebRtcSpl_State8khzTo48khz; 860 861 void WebRtcSpl_Resample8khzTo48khz(const int16_t* in, 862 int16_t* out, 863 WebRtcSpl_State8khzTo48khz* state, 864 int32_t* tmpmem); 865 866 void WebRtcSpl_ResetResample8khzTo48khz(WebRtcSpl_State8khzTo48khz* state); 867 868 /******************************************************************* 869 * resample_by_2.c 870 * 871 * Includes down and up sampling by a factor of two. 872 * 873 ******************************************************************/ 874 875 void WebRtcSpl_DownsampleBy2(const int16_t* in, 876 size_t len, 877 int16_t* out, 878 int32_t* filtState); 879 880 void WebRtcSpl_UpsampleBy2(const int16_t* in, 881 size_t len, 882 int16_t* out, 883 int32_t* filtState); 884 885 /************************************************************ 886 * END OF RESAMPLING FUNCTIONS 887 ************************************************************/ 888 void WebRtcSpl_AnalysisQMF(const int16_t* in_data, 889 size_t in_data_length, 890 int16_t* low_band, 891 int16_t* high_band, 892 int32_t* filter_state1, 893 int32_t* filter_state2); 894 void WebRtcSpl_SynthesisQMF(const int16_t* low_band, 895 const int16_t* high_band, 896 size_t band_length, 897 int16_t* out_data, 898 int32_t* filter_state1, 899 int32_t* filter_state2); 900 901 #ifdef __cplusplus 902 } 903 #endif // __cplusplus 904 #endif // COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SIGNAL_PROCESSING_LIBRARY_H_ 905 906 // 907 // WebRtcSpl_AddSatW16(...) 908 // WebRtcSpl_AddSatW32(...) 909 // 910 // Returns the result of a saturated 16-bit, respectively 32-bit, addition of 911 // the numbers specified by the |var1| and |var2| parameters. 912 // 913 // Input: 914 // - var1 : Input variable 1 915 // - var2 : Input variable 2 916 // 917 // Return value : Added and saturated value 918 // 919 920 // 921 // WebRtcSpl_SubSatW16(...) 922 // WebRtcSpl_SubSatW32(...) 923 // 924 // Returns the result of a saturated 16-bit, respectively 32-bit, subtraction 925 // of the numbers specified by the |var1| and |var2| parameters. 926 // 927 // Input: 928 // - var1 : Input variable 1 929 // - var2 : Input variable 2 930 // 931 // Returned value : Subtracted and saturated value 932 // 933 934 // 935 // WebRtcSpl_GetSizeInBits(...) 936 // 937 // Returns the # of bits that are needed at the most to represent the number 938 // specified by the |value| parameter. 939 // 940 // Input: 941 // - value : Input value 942 // 943 // Return value : Number of bits needed to represent |value| 944 // 945 946 // 947 // WebRtcSpl_NormW32(...) 948 // 949 // Norm returns the # of left shifts required to 32-bit normalize the 32-bit 950 // signed number specified by the |value| parameter. 951 // 952 // Input: 953 // - value : Input value 954 // 955 // Return value : Number of bit shifts needed to 32-bit normalize |value| 956 // 957 958 // 959 // WebRtcSpl_NormW16(...) 960 // 961 // Norm returns the # of left shifts required to 16-bit normalize the 16-bit 962 // signed number specified by the |value| parameter. 963 // 964 // Input: 965 // - value : Input value 966 // 967 // Return value : Number of bit shifts needed to 32-bit normalize |value| 968 // 969 970 // 971 // WebRtcSpl_NormU32(...) 972 // 973 // Norm returns the # of left shifts required to 32-bit normalize the unsigned 974 // 32-bit number specified by the |value| parameter. 975 // 976 // Input: 977 // - value : Input value 978 // 979 // Return value : Number of bit shifts needed to 32-bit normalize |value| 980 // 981 982 // 983 // WebRtcSpl_GetScalingSquare(...) 984 // 985 // Returns the # of bits required to scale the samples specified in the 986 // |in_vector| parameter so that, if the squares of the samples are added the 987 // # of times specified by the |times| parameter, the 32-bit addition will not 988 // overflow (result in int32_t). 989 // 990 // Input: 991 // - in_vector : Input vector to check scaling on 992 // - in_vector_length : Samples in |in_vector| 993 // - times : Number of additions to be performed 994 // 995 // Return value : Number of right bit shifts needed to avoid 996 // overflow in the addition calculation 997 // 998 999 // 1000 // WebRtcSpl_MemSetW16(...) 1001 // 1002 // Sets all the values in the int16_t vector |vector| of length 1003 // |vector_length| to the specified value |set_value| 1004 // 1005 // Input: 1006 // - vector : Pointer to the int16_t vector 1007 // - set_value : Value specified 1008 // - vector_length : Length of vector 1009 // 1010 1011 // 1012 // WebRtcSpl_MemSetW32(...) 1013 // 1014 // Sets all the values in the int32_t vector |vector| of length 1015 // |vector_length| to the specified value |set_value| 1016 // 1017 // Input: 1018 // - vector : Pointer to the int16_t vector 1019 // - set_value : Value specified 1020 // - vector_length : Length of vector 1021 // 1022 1023 // 1024 // WebRtcSpl_MemCpyReversedOrder(...) 1025 // 1026 // Copies all the values from the source int16_t vector |in_vector| to a 1027 // destination int16_t vector |out_vector|. It is done in reversed order, 1028 // meaning that the first sample of |in_vector| is copied to the last sample of 1029 // the |out_vector|. The procedure continues until the last sample of 1030 // |in_vector| has been copied to the first sample of |out_vector|. This 1031 // creates a reversed vector. Used in e.g. prediction in iLBC. 1032 // 1033 // Input: 1034 // - in_vector : Pointer to the first sample in a int16_t vector 1035 // of length |length| 1036 // - vector_length : Number of elements to copy 1037 // 1038 // Output: 1039 // - out_vector : Pointer to the last sample in a int16_t vector 1040 // of length |length| 1041 // 1042 1043 // 1044 // WebRtcSpl_CopyFromEndW16(...) 1045 // 1046 // Copies the rightmost |samples| of |in_vector| (of length |in_vector_length|) 1047 // to the vector |out_vector|. 1048 // 1049 // Input: 1050 // - in_vector : Input vector 1051 // - in_vector_length : Number of samples in |in_vector| 1052 // - samples : Number of samples to extract (from right side) 1053 // from |in_vector| 1054 // 1055 // Output: 1056 // - out_vector : Vector with the requested samples 1057 // 1058 1059 // 1060 // WebRtcSpl_ZerosArrayW16(...) 1061 // WebRtcSpl_ZerosArrayW32(...) 1062 // 1063 // Inserts the value "zero" in all positions of a w16 and a w32 vector 1064 // respectively. 1065 // 1066 // Input: 1067 // - vector_length : Number of samples in vector 1068 // 1069 // Output: 1070 // - vector : Vector containing all zeros 1071 // 1072 1073 // 1074 // WebRtcSpl_VectorBitShiftW16(...) 1075 // WebRtcSpl_VectorBitShiftW32(...) 1076 // 1077 // Bit shifts all the values in a vector up or downwards. Different calls for 1078 // int16_t and int32_t vectors respectively. 1079 // 1080 // Input: 1081 // - vector_length : Length of vector 1082 // - in_vector : Pointer to the vector that should be bit shifted 1083 // - right_shifts : Number of right bit shifts (negative value gives left 1084 // shifts) 1085 // 1086 // Output: 1087 // - out_vector : Pointer to the result vector (can be the same as 1088 // |in_vector|) 1089 // 1090 1091 // 1092 // WebRtcSpl_VectorBitShiftW32ToW16(...) 1093 // 1094 // Bit shifts all the values in a int32_t vector up or downwards and 1095 // stores the result as an int16_t vector. The function will saturate the 1096 // signal if needed, before storing in the output vector. 1097 // 1098 // Input: 1099 // - vector_length : Length of vector 1100 // - in_vector : Pointer to the vector that should be bit shifted 1101 // - right_shifts : Number of right bit shifts (negative value gives left 1102 // shifts) 1103 // 1104 // Output: 1105 // - out_vector : Pointer to the result vector (can be the same as 1106 // |in_vector|) 1107 // 1108 1109 // 1110 // WebRtcSpl_ScaleVector(...) 1111 // 1112 // Performs the vector operation: 1113 // out_vector[k] = (gain*in_vector[k])>>right_shifts 1114 // 1115 // Input: 1116 // - in_vector : Input vector 1117 // - gain : Scaling gain 1118 // - vector_length : Elements in the |in_vector| 1119 // - right_shifts : Number of right bit shifts applied 1120 // 1121 // Output: 1122 // - out_vector : Output vector (can be the same as |in_vector|) 1123 // 1124 1125 // 1126 // WebRtcSpl_ScaleVectorWithSat(...) 1127 // 1128 // Performs the vector operation: 1129 // out_vector[k] = SATURATE( (gain*in_vector[k])>>right_shifts ) 1130 // 1131 // Input: 1132 // - in_vector : Input vector 1133 // - gain : Scaling gain 1134 // - vector_length : Elements in the |in_vector| 1135 // - right_shifts : Number of right bit shifts applied 1136 // 1137 // Output: 1138 // - out_vector : Output vector (can be the same as |in_vector|) 1139 // 1140 1141 // 1142 // WebRtcSpl_ScaleAndAddVectors(...) 1143 // 1144 // Performs the vector operation: 1145 // out_vector[k] = (gain1*in_vector1[k])>>right_shifts1 1146 // + (gain2*in_vector2[k])>>right_shifts2 1147 // 1148 // Input: 1149 // - in_vector1 : Input vector 1 1150 // - gain1 : Gain to be used for vector 1 1151 // - right_shifts1 : Right bit shift to be used for vector 1 1152 // - in_vector2 : Input vector 2 1153 // - gain2 : Gain to be used for vector 2 1154 // - right_shifts2 : Right bit shift to be used for vector 2 1155 // - vector_length : Elements in the input vectors 1156 // 1157 // Output: 1158 // - out_vector : Output vector 1159 // 1160 1161 // 1162 // WebRtcSpl_ReverseOrderMultArrayElements(...) 1163 // 1164 // Performs the vector operation: 1165 // out_vector[n] = (in_vector[n]*window[-n])>>right_shifts 1166 // 1167 // Input: 1168 // - in_vector : Input vector 1169 // - window : Window vector (should be reversed). The pointer 1170 // should be set to the last value in the vector 1171 // - right_shifts : Number of right bit shift to be applied after the 1172 // multiplication 1173 // - vector_length : Number of elements in |in_vector| 1174 // 1175 // Output: 1176 // - out_vector : Output vector (can be same as |in_vector|) 1177 // 1178 1179 // 1180 // WebRtcSpl_ElementwiseVectorMult(...) 1181 // 1182 // Performs the vector operation: 1183 // out_vector[n] = (in_vector[n]*window[n])>>right_shifts 1184 // 1185 // Input: 1186 // - in_vector : Input vector 1187 // - window : Window vector. 1188 // - right_shifts : Number of right bit shift to be applied after the 1189 // multiplication 1190 // - vector_length : Number of elements in |in_vector| 1191 // 1192 // Output: 1193 // - out_vector : Output vector (can be same as |in_vector|) 1194 // 1195 1196 // 1197 // WebRtcSpl_AddVectorsAndShift(...) 1198 // 1199 // Performs the vector operation: 1200 // out_vector[k] = (in_vector1[k] + in_vector2[k])>>right_shifts 1201 // 1202 // Input: 1203 // - in_vector1 : Input vector 1 1204 // - in_vector2 : Input vector 2 1205 // - right_shifts : Number of right bit shift to be applied after the 1206 // multiplication 1207 // - vector_length : Number of elements in |in_vector1| and |in_vector2| 1208 // 1209 // Output: 1210 // - out_vector : Output vector (can be same as |in_vector1|) 1211 // 1212 1213 // 1214 // WebRtcSpl_AddAffineVectorToVector(...) 1215 // 1216 // Adds an affine transformed vector to another vector |out_vector|, i.e, 1217 // performs 1218 // out_vector[k] += (in_vector[k]*gain+add_constant)>>right_shifts 1219 // 1220 // Input: 1221 // - in_vector : Input vector 1222 // - gain : Gain value, used to multiply the in vector with 1223 // - add_constant : Constant value to add (usually 1<<(right_shifts-1), 1224 // but others can be used as well 1225 // - right_shifts : Number of right bit shifts (0-16) 1226 // - vector_length : Number of samples in |in_vector| and |out_vector| 1227 // 1228 // Output: 1229 // - out_vector : Vector with the output 1230 // 1231 1232 // 1233 // WebRtcSpl_AffineTransformVector(...) 1234 // 1235 // Affine transforms a vector, i.e, performs 1236 // out_vector[k] = (in_vector[k]*gain+add_constant)>>right_shifts 1237 // 1238 // Input: 1239 // - in_vector : Input vector 1240 // - gain : Gain value, used to multiply the in vector with 1241 // - add_constant : Constant value to add (usually 1<<(right_shifts-1), 1242 // but others can be used as well 1243 // - right_shifts : Number of right bit shifts (0-16) 1244 // - vector_length : Number of samples in |in_vector| and |out_vector| 1245 // 1246 // Output: 1247 // - out_vector : Vector with the output 1248 // 1249 1250 // 1251 // WebRtcSpl_IncreaseSeed(...) 1252 // 1253 // Increases the seed (and returns the new value) 1254 // 1255 // Input: 1256 // - seed : Seed for random calculation 1257 // 1258 // Output: 1259 // - seed : Updated seed value 1260 // 1261 // Return value : The new seed value 1262 // 1263 1264 // 1265 // WebRtcSpl_RandU(...) 1266 // 1267 // Produces a uniformly distributed value in the int16_t range 1268 // 1269 // Input: 1270 // - seed : Seed for random calculation 1271 // 1272 // Output: 1273 // - seed : Updated seed value 1274 // 1275 // Return value : Uniformly distributed value in the range 1276 // [Word16_MIN...Word16_MAX] 1277 // 1278 1279 // 1280 // WebRtcSpl_RandN(...) 1281 // 1282 // Produces a normal distributed value in the int16_t range 1283 // 1284 // Input: 1285 // - seed : Seed for random calculation 1286 // 1287 // Output: 1288 // - seed : Updated seed value 1289 // 1290 // Return value : N(0,1) value in the Q13 domain 1291 // 1292 1293 // 1294 // WebRtcSpl_RandUArray(...) 1295 // 1296 // Produces a uniformly distributed vector with elements in the int16_t 1297 // range 1298 // 1299 // Input: 1300 // - vector_length : Samples wanted in the vector 1301 // - seed : Seed for random calculation 1302 // 1303 // Output: 1304 // - vector : Vector with the uniform values 1305 // - seed : Updated seed value 1306 // 1307 // Return value : Number of samples in vector, i.e., |vector_length| 1308 // 1309 1310 // 1311 // WebRtcSpl_Sqrt(...) 1312 // 1313 // Returns the square root of the input value |value|. The precision of this 1314 // function is integer precision, i.e., sqrt(8) gives 2 as answer. 1315 // If |value| is a negative number then 0 is returned. 1316 // 1317 // Algorithm: 1318 // 1319 // A sixth order Taylor Series expansion is used here to compute the square 1320 // root of a number y^0.5 = (1+x)^0.5 1321 // where 1322 // x = y-1 1323 // = 1+(x/2)-0.5*((x/2)^2+0.5*((x/2)^3-0.625*((x/2)^4+0.875*((x/2)^5) 1324 // 0.5 <= x < 1 1325 // 1326 // Input: 1327 // - value : Value to calculate sqrt of 1328 // 1329 // Return value : Result of the sqrt calculation 1330 // 1331 1332 // 1333 // WebRtcSpl_DivU32U16(...) 1334 // 1335 // Divides a uint32_t |num| by a uint16_t |den|. 1336 // 1337 // If |den|==0, (uint32_t)0xFFFFFFFF is returned. 1338 // 1339 // Input: 1340 // - num : Numerator 1341 // - den : Denominator 1342 // 1343 // Return value : Result of the division (as a uint32_t), i.e., the 1344 // integer part of num/den. 1345 // 1346 1347 // 1348 // WebRtcSpl_DivW32W16(...) 1349 // 1350 // Divides a int32_t |num| by a int16_t |den|. 1351 // 1352 // If |den|==0, (int32_t)0x7FFFFFFF is returned. 1353 // 1354 // Input: 1355 // - num : Numerator 1356 // - den : Denominator 1357 // 1358 // Return value : Result of the division (as a int32_t), i.e., the 1359 // integer part of num/den. 1360 // 1361 1362 // 1363 // WebRtcSpl_DivW32W16ResW16(...) 1364 // 1365 // Divides a int32_t |num| by a int16_t |den|, assuming that the 1366 // result is less than 32768, otherwise an unpredictable result will occur. 1367 // 1368 // If |den|==0, (int16_t)0x7FFF is returned. 1369 // 1370 // Input: 1371 // - num : Numerator 1372 // - den : Denominator 1373 // 1374 // Return value : Result of the division (as a int16_t), i.e., the 1375 // integer part of num/den. 1376 // 1377 1378 // 1379 // WebRtcSpl_DivResultInQ31(...) 1380 // 1381 // Divides a int32_t |num| by a int16_t |den|, assuming that the 1382 // absolute value of the denominator is larger than the numerator, otherwise 1383 // an unpredictable result will occur. 1384 // 1385 // Input: 1386 // - num : Numerator 1387 // - den : Denominator 1388 // 1389 // Return value : Result of the division in Q31. 1390 // 1391 1392 // 1393 // WebRtcSpl_DivW32HiLow(...) 1394 // 1395 // Divides a int32_t |num| by a denominator in hi, low format. The 1396 // absolute value of the denominator has to be larger (or equal to) the 1397 // numerator. 1398 // 1399 // Input: 1400 // - num : Numerator 1401 // - den_hi : High part of denominator 1402 // - den_low : Low part of denominator 1403 // 1404 // Return value : Divided value in Q31 1405 // 1406 1407 // 1408 // WebRtcSpl_Energy(...) 1409 // 1410 // Calculates the energy of a vector 1411 // 1412 // Input: 1413 // - vector : Vector which the energy should be calculated on 1414 // - vector_length : Number of samples in vector 1415 // 1416 // Output: 1417 // - scale_factor : Number of left bit shifts needed to get the physical 1418 // energy value, i.e, to get the Q0 value 1419 // 1420 // Return value : Energy value in Q(-|scale_factor|) 1421 // 1422 1423 // 1424 // WebRtcSpl_FilterAR(...) 1425 // 1426 // Performs a 32-bit AR filtering on a vector in Q12 1427 // 1428 // Input: 1429 // - ar_coef : AR-coefficient vector (values in Q12), 1430 // ar_coef[0] must be 4096. 1431 // - ar_coef_length : Number of coefficients in |ar_coef|. 1432 // - in_vector : Vector to be filtered. 1433 // - in_vector_length : Number of samples in |in_vector|. 1434 // - filter_state : Current state (higher part) of the filter. 1435 // - filter_state_length : Length (in samples) of |filter_state|. 1436 // - filter_state_low : Current state (lower part) of the filter. 1437 // - filter_state_low_length : Length (in samples) of |filter_state_low|. 1438 // - out_vector_low_length : Maximum length (in samples) of 1439 // |out_vector_low|. 1440 // 1441 // Output: 1442 // - filter_state : Updated state (upper part) vector. 1443 // - filter_state_low : Updated state (lower part) vector. 1444 // - out_vector : Vector containing the upper part of the 1445 // filtered values. 1446 // - out_vector_low : Vector containing the lower part of the 1447 // filtered values. 1448 // 1449 // Return value : Number of samples in the |out_vector|. 1450 // 1451 1452 // 1453 // WebRtcSpl_ComplexIFFT(...) 1454 // 1455 // Complex Inverse FFT 1456 // 1457 // Computes an inverse complex 2^|stages|-point FFT on the input vector, which 1458 // is in bit-reversed order. The original content of the vector is destroyed in 1459 // the process, since the input is overwritten by the output, normal-ordered, 1460 // FFT vector. With X as the input complex vector, y as the output complex 1461 // vector and with M = 2^|stages|, the following is computed: 1462 // 1463 // M-1 1464 // y(k) = sum[X(i)*[cos(2*pi*i*k/M) + j*sin(2*pi*i*k/M)]] 1465 // i=0 1466 // 1467 // The implementations are optimized for speed, not for code size. It uses the 1468 // decimation-in-time algorithm with radix-2 butterfly technique. 1469 // 1470 // Input: 1471 // - vector : In pointer to complex vector containing 2^|stages| 1472 // real elements interleaved with 2^|stages| imaginary 1473 // elements. 1474 // [ReImReImReIm....] 1475 // The elements are in Q(-scale) domain, see more on Return 1476 // Value below. 1477 // 1478 // - stages : Number of FFT stages. Must be at least 3 and at most 10, 1479 // since the table WebRtcSpl_kSinTable1024[] is 1024 1480 // elements long. 1481 // 1482 // - mode : This parameter gives the user to choose how the FFT 1483 // should work. 1484 // mode==0: Low-complexity and Low-accuracy mode 1485 // mode==1: High-complexity and High-accuracy mode 1486 // 1487 // Output: 1488 // - vector : Out pointer to the FFT vector (the same as input). 1489 // 1490 // Return Value : The scale value that tells the number of left bit shifts 1491 // that the elements in the |vector| should be shifted with 1492 // in order to get Q0 values, i.e. the physically correct 1493 // values. The scale parameter is always 0 or positive, 1494 // except if N>1024 (|stages|>10), which returns a scale 1495 // value of -1, indicating error. 1496 // 1497 1498 // 1499 // WebRtcSpl_ComplexFFT(...) 1500 // 1501 // Complex FFT 1502 // 1503 // Computes a complex 2^|stages|-point FFT on the input vector, which is in 1504 // bit-reversed order. The original content of the vector is destroyed in 1505 // the process, since the input is overwritten by the output, normal-ordered, 1506 // FFT vector. With x as the input complex vector, Y as the output complex 1507 // vector and with M = 2^|stages|, the following is computed: 1508 // 1509 // M-1 1510 // Y(k) = 1/M * sum[x(i)*[cos(2*pi*i*k/M) + j*sin(2*pi*i*k/M)]] 1511 // i=0 1512 // 1513 // The implementations are optimized for speed, not for code size. It uses the 1514 // decimation-in-time algorithm with radix-2 butterfly technique. 1515 // 1516 // This routine prevents overflow by scaling by 2 before each FFT stage. This is 1517 // a fixed scaling, for proper normalization - there will be log2(n) passes, so 1518 // this results in an overall factor of 1/n, distributed to maximize arithmetic 1519 // accuracy. 1520 // 1521 // Input: 1522 // - vector : In pointer to complex vector containing 2^|stages| real 1523 // elements interleaved with 2^|stages| imaginary elements. 1524 // [ReImReImReIm....] 1525 // The output is in the Q0 domain. 1526 // 1527 // - stages : Number of FFT stages. Must be at least 3 and at most 10, 1528 // since the table WebRtcSpl_kSinTable1024[] is 1024 1529 // elements long. 1530 // 1531 // - mode : This parameter gives the user to choose how the FFT 1532 // should work. 1533 // mode==0: Low-complexity and Low-accuracy mode 1534 // mode==1: High-complexity and High-accuracy mode 1535 // 1536 // Output: 1537 // - vector : The output FFT vector is in the Q0 domain. 1538 // 1539 // Return value : The scale parameter is always 0, except if N>1024, 1540 // which returns a scale value of -1, indicating error. 1541 // 1542 1543 // 1544 // WebRtcSpl_AnalysisQMF(...) 1545 // 1546 // Splits a 0-2*F Hz signal into two sub bands: 0-F Hz and F-2*F Hz. The 1547 // current version has F = 8000, therefore, a super-wideband audio signal is 1548 // split to lower-band 0-8 kHz and upper-band 8-16 kHz. 1549 // 1550 // Input: 1551 // - in_data : Wide band speech signal, 320 samples (10 ms) 1552 // 1553 // Input & Output: 1554 // - filter_state1 : Filter state for first All-pass filter 1555 // - filter_state2 : Filter state for second All-pass filter 1556 // 1557 // Output: 1558 // - low_band : Lower-band signal 0-8 kHz band, 160 samples (10 ms) 1559 // - high_band : Upper-band signal 8-16 kHz band (flipped in frequency 1560 // domain), 160 samples (10 ms) 1561 // 1562 1563 // 1564 // WebRtcSpl_SynthesisQMF(...) 1565 // 1566 // Combines the two sub bands (0-F and F-2*F Hz) into a signal of 0-2*F 1567 // Hz, (current version has F = 8000 Hz). So the filter combines lower-band 1568 // (0-8 kHz) and upper-band (8-16 kHz) channels to obtain super-wideband 0-16 1569 // kHz audio. 1570 // 1571 // Input: 1572 // - low_band : The signal with the 0-8 kHz band, 160 samples (10 ms) 1573 // - high_band : The signal with the 8-16 kHz band, 160 samples (10 ms) 1574 // 1575 // Input & Output: 1576 // - filter_state1 : Filter state for first All-pass filter 1577 // - filter_state2 : Filter state for second All-pass filter 1578 // 1579 // Output: 1580 // - out_data : Super-wideband speech signal, 0-16 kHz 1581 // 1582 1583 // int16_t WebRtcSpl_SatW32ToW16(...) 1584 // 1585 // This function saturates a 32-bit word into a 16-bit word. 1586 // 1587 // Input: 1588 // - value32 : The value of a 32-bit word. 1589 // 1590 // Output: 1591 // - out16 : the saturated 16-bit word. 1592 // 1593 1594 // int32_t WebRtc_MulAccumW16(...) 1595 // 1596 // This function multiply a 16-bit word by a 16-bit word, and accumulate this 1597 // value to a 32-bit integer. 1598 // 1599 // Input: 1600 // - a : The value of the first 16-bit word. 1601 // - b : The value of the second 16-bit word. 1602 // - c : The value of an 32-bit integer. 1603 // 1604 // Return Value: The value of a * b + c. 1605 // 1606