├── so ├── mips │ └── libwebrtc.so ├── x86 │ └── libwebrtc.so ├── armeabi │ └── libwebrtc.so ├── arm64-v8a │ └── libwebrtc.so └── armeabi-v7a │ └── libwebrtc.so ├── webrtc-android-jni └── jni │ ├── .DS_Store │ ├── src │ ├── webrtc │ │ ├── .gitignore │ │ ├── .DS_Store │ │ ├── modules │ │ │ ├── .DS_Store │ │ │ └── audio_processing │ │ │ │ ├── .DS_Store │ │ │ │ ├── aec │ │ │ │ ├── .DS_Store │ │ │ │ ├── aec_common.h │ │ │ │ ├── aec_resampler.h │ │ │ │ ├── echo_cancellation_unittest.cc │ │ │ │ ├── echo_cancellation_internal.h │ │ │ │ ├── aec_rdft.h │ │ │ │ ├── aec_core.h │ │ │ │ └── aec_resampler.c │ │ │ │ ├── aecm │ │ │ │ ├── .DS_Store │ │ │ │ └── aecm_defines.h │ │ │ │ ├── logging │ │ │ │ ├── aec_logging_file_handling.h │ │ │ │ ├── aec_logging_file_handling.cc │ │ │ │ └── aec_logging.h │ │ │ │ ├── utility │ │ │ │ └── delay_estimator_internal.h │ │ │ │ └── ns │ │ │ │ ├── noise_suppression_x.c │ │ │ │ ├── noise_suppression.c │ │ │ │ ├── defines.h │ │ │ │ ├── include │ │ │ │ ├── noise_suppression_x.h │ │ │ │ └── noise_suppression.h │ │ │ │ ├── nsx_defines.h │ │ │ │ └── ns_core.h │ │ ├── common_audio │ │ │ ├── .DS_Store │ │ │ ├── signal_processing │ │ │ │ ├── .DS_Store │ │ │ │ ├── sqrt_of_one_minus_x_squared.c │ │ │ │ ├── energy.c │ │ │ │ ├── cross_correlation.c │ │ │ │ ├── dot_product_with_scale.c │ │ │ │ ├── filter_ar_fast_q12.c │ │ │ │ ├── get_scaling_square.c │ │ │ │ ├── filter_ma_fast_q12.c │ │ │ │ ├── refl_coef_to_lpc.c │ │ │ │ ├── downsample_fast.c │ │ │ │ ├── resample_by_2_internal.h │ │ │ │ ├── lpc_to_refl_coef.c │ │ │ │ ├── auto_correlation.c │ │ │ │ ├── copy_set_operations.c │ │ │ │ ├── vector_scaling_operations_mips.c │ │ │ │ ├── spl_sqrt_floor.c │ │ │ │ ├── filter_ar.c │ │ │ │ ├── ilbc_specific_functions.c │ │ │ │ ├── auto_corr_to_refl_coef.c │ │ │ │ ├── spl_sqrt_floor_arm.S │ │ │ │ ├── get_hanning_window.c │ │ │ │ ├── cross_correlation_neon.c │ │ │ │ ├── real_fft.c │ │ │ │ ├── include │ │ │ │ │ ├── spl_inl_armv7.h │ │ │ │ │ ├── real_fft.h │ │ │ │ │ └── spl_inl.h │ │ │ │ ├── division_operations.c │ │ │ │ ├── real_fft_unittest.cc │ │ │ │ ├── complex_bit_reverse.c │ │ │ │ ├── complex_bit_reverse_arm.S │ │ │ │ ├── spl_init.c │ │ │ │ ├── spl_sqrt.c │ │ │ │ ├── vector_scaling_operations.c │ │ │ │ ├── min_max_operations.c │ │ │ │ ├── cross_correlation_mips.c │ │ │ │ ├── resample_48khz.c │ │ │ │ ├── resample_by_2.c │ │ │ │ └── randomization_functions.c │ │ │ ├── fft4g.h │ │ │ ├── ring_buffer.h │ │ │ └── wav_file.h │ │ ├── system_wrappers │ │ │ ├── .DS_Store │ │ │ ├── source │ │ │ │ ├── .DS_Store │ │ │ │ ├── cpu_features_android.c │ │ │ │ └── cpu_features.cc │ │ │ └── interface │ │ │ │ ├── .DS_Store │ │ │ │ ├── compile_assert_c.h │ │ │ │ └── cpu_features_wrapper.h │ │ └── typedefs.h │ └── .DS_Store │ ├── Application.mk │ └── Android.mk └── README.md /so/mips/libwebrtc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tata88k/webrtc-android-jni/HEAD/so/mips/libwebrtc.so -------------------------------------------------------------------------------- /so/x86/libwebrtc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tata88k/webrtc-android-jni/HEAD/so/x86/libwebrtc.so -------------------------------------------------------------------------------- /so/armeabi/libwebrtc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tata88k/webrtc-android-jni/HEAD/so/armeabi/libwebrtc.so -------------------------------------------------------------------------------- /so/arm64-v8a/libwebrtc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tata88k/webrtc-android-jni/HEAD/so/arm64-v8a/libwebrtc.so -------------------------------------------------------------------------------- /so/armeabi-v7a/libwebrtc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tata88k/webrtc-android-jni/HEAD/so/armeabi-v7a/libwebrtc.so -------------------------------------------------------------------------------- /webrtc-android-jni/jni/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tata88k/webrtc-android-jni/HEAD/webrtc-android-jni/jni/.DS_Store -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/.gitignore: -------------------------------------------------------------------------------- 1 | # This file is for projects that checkout webrtc/ directly (e.g. Chromium). 2 | *.mk 3 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tata88k/webrtc-android-jni/HEAD/webrtc-android-jni/jni/src/.DS_Store -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tata88k/webrtc-android-jni/HEAD/webrtc-android-jni/jni/src/webrtc/.DS_Store -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tata88k/webrtc-android-jni/HEAD/webrtc-android-jni/jni/src/webrtc/modules/.DS_Store -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tata88k/webrtc-android-jni/HEAD/webrtc-android-jni/jni/src/webrtc/common_audio/.DS_Store -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/system_wrappers/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tata88k/webrtc-android-jni/HEAD/webrtc-android-jni/jni/src/webrtc/system_wrappers/.DS_Store -------------------------------------------------------------------------------- /webrtc-android-jni/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_ABI := armeabi armeabi-v7a arm64-v8a mips x86 2 | 3 | ifeq ($(findstring x86,$(TARGET_ARCH_ABI)),) 4 | APP_STL := stlport_static 5 | endif 6 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tata88k/webrtc-android-jni/HEAD/webrtc-android-jni/jni/src/webrtc/modules/audio_processing/.DS_Store -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/system_wrappers/source/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tata88k/webrtc-android-jni/HEAD/webrtc-android-jni/jni/src/webrtc/system_wrappers/source/.DS_Store -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/system_wrappers/interface/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tata88k/webrtc-android-jni/HEAD/webrtc-android-jni/jni/src/webrtc/system_wrappers/interface/.DS_Store -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/aec/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tata88k/webrtc-android-jni/HEAD/webrtc-android-jni/jni/src/webrtc/modules/audio_processing/aec/.DS_Store -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/aecm/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tata88k/webrtc-android-jni/HEAD/webrtc-android-jni/jni/src/webrtc/modules/audio_processing/aecm/.DS_Store -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tata88k/webrtc-android-jni/HEAD/webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/.DS_Store -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/system_wrappers/source/cpu_features_android.c: -------------------------------------------------------------------------------- 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 | #include 12 | 13 | uint64_t WebRtc_GetCPUFeaturesARM(void) { 14 | return android_getCpuFeatures(); 15 | } 16 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/fft4g.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | #ifndef WEBRTC_COMMON_AUDIO_FFT4G_H_ 12 | #define WEBRTC_COMMON_AUDIO_FFT4G_H_ 13 | 14 | #if defined(__cplusplus) 15 | extern "C" { 16 | #endif 17 | 18 | // Refer to fft4g.c for documentation. 19 | void WebRtc_rdft(size_t n, int isgn, float *a, size_t *ip, float *w); 20 | 21 | #if defined(__cplusplus) 22 | } 23 | #endif 24 | 25 | #endif // WEBRTC_COMMON_AUDIO_FFT4G_H_ 26 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/system_wrappers/interface/compile_assert_c.h: -------------------------------------------------------------------------------- 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 | #ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_COMPILE_ASSERT_H_ 12 | #define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_COMPILE_ASSERT_H_ 13 | 14 | #ifdef __cplusplus 15 | #error "Only use this for C files. For C++, use static_assert." 16 | #endif 17 | 18 | // Use this macro to verify at compile time that certain restrictions are met. 19 | // The argument is the boolean expression to evaluate. 20 | // Example: 21 | // COMPILE_ASSERT(sizeof(foo) < 128); 22 | #define COMPILE_ASSERT(expression) switch (0) {case 0: case expression:;} 23 | 24 | #endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_COMPILE_ASSERT_H_ 25 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/sqrt_of_one_minus_x_squared.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | /* 13 | * This file contains the function WebRtcSpl_SqrtOfOneMinusXSquared(). 14 | * The description header can be found in signal_processing_library.h 15 | * 16 | */ 17 | 18 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 19 | 20 | void WebRtcSpl_SqrtOfOneMinusXSquared(int16_t *xQ15, size_t vector_length, 21 | int16_t *yQ15) 22 | { 23 | int32_t sq; 24 | size_t m; 25 | int16_t tmp; 26 | 27 | for (m = 0; m < vector_length; m++) 28 | { 29 | tmp = xQ15[m]; 30 | sq = tmp * tmp; // x^2 in Q30 31 | sq = 1073741823 - sq; // 1-x^2, where 1 ~= 0.99999999906 is 1073741823 in Q30 32 | sq = WebRtcSpl_Sqrt(sq); // sqrt(1-x^2) in Q15 33 | yQ15[m] = (int16_t)sq; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/energy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | /* 13 | * This file contains the function WebRtcSpl_Energy(). 14 | * The description header can be found in signal_processing_library.h 15 | * 16 | */ 17 | 18 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 19 | 20 | int32_t WebRtcSpl_Energy(int16_t* vector, 21 | size_t vector_length, 22 | int* scale_factor) 23 | { 24 | int32_t en = 0; 25 | size_t i; 26 | int scaling = 27 | WebRtcSpl_GetScalingSquare(vector, vector_length, vector_length); 28 | size_t looptimes = vector_length; 29 | int16_t *vectorptr = vector; 30 | 31 | for (i = 0; i < looptimes; i++) 32 | { 33 | en += (*vectorptr * *vectorptr) >> scaling; 34 | vectorptr++; 35 | } 36 | *scale_factor = scaling; 37 | 38 | return en; 39 | } 40 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/cross_correlation.c: -------------------------------------------------------------------------------- 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 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 12 | 13 | /* C version of WebRtcSpl_CrossCorrelation() for generic platforms. */ 14 | void WebRtcSpl_CrossCorrelationC(int32_t* cross_correlation, 15 | const int16_t* seq1, 16 | const int16_t* seq2, 17 | size_t dim_seq, 18 | size_t dim_cross_correlation, 19 | int right_shifts, 20 | int step_seq2) { 21 | size_t i = 0, j = 0; 22 | 23 | for (i = 0; i < dim_cross_correlation; i++) { 24 | int32_t corr = 0; 25 | for (j = 0; j < dim_seq; j++) 26 | corr += (seq1[j] * seq2[j]) >> right_shifts; 27 | seq2 += step_seq2; 28 | *cross_correlation++ = corr; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/dot_product_with_scale.c: -------------------------------------------------------------------------------- 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 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 12 | 13 | int32_t WebRtcSpl_DotProductWithScale(const int16_t* vector1, 14 | const int16_t* vector2, 15 | size_t length, 16 | int scaling) { 17 | int32_t sum = 0; 18 | size_t i = 0; 19 | 20 | /* Unroll the loop to improve performance. */ 21 | for (i = 0; i + 3 < length; i += 4) { 22 | sum += (vector1[i + 0] * vector2[i + 0]) >> scaling; 23 | sum += (vector1[i + 1] * vector2[i + 1]) >> scaling; 24 | sum += (vector1[i + 2] * vector2[i + 2]) >> scaling; 25 | sum += (vector1[i + 3] * vector2[i + 3]) >> scaling; 26 | } 27 | for (; i < length; i++) { 28 | sum += (vector1[i] * vector2[i]) >> scaling; 29 | } 30 | 31 | return sum; 32 | } 33 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/aec/aec_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 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 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_COMMON_H_ 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_COMMON_H_ 13 | 14 | #include "webrtc/typedefs.h" 15 | 16 | #ifdef _MSC_VER /* visual c++ */ 17 | #define ALIGN16_BEG __declspec(align(16)) 18 | #define ALIGN16_END 19 | #else /* gcc or icc */ 20 | #define ALIGN16_BEG 21 | #define ALIGN16_END __attribute__((aligned(16))) 22 | #endif 23 | 24 | extern ALIGN16_BEG const float ALIGN16_END WebRtcAec_sqrtHanning[65]; 25 | extern ALIGN16_BEG const float ALIGN16_END WebRtcAec_weightCurve[65]; 26 | extern ALIGN16_BEG const float ALIGN16_END WebRtcAec_overDriveCurve[65]; 27 | extern const float WebRtcAec_kExtendedSmoothingCoefficients[2][2]; 28 | extern const float WebRtcAec_kNormalSmoothingCoefficients[2][2]; 29 | extern const float WebRtcAec_kMinFarendPSD; 30 | 31 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_COMMON_H_ 32 | 33 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/logging/aec_logging_file_handling.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 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 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_LOGGING_FILE_HANDLING_ 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_LOGGING_FILE_HANDLING_ 13 | 14 | #include 15 | 16 | #include "webrtc/common_audio/wav_file.h" 17 | #include "webrtc/typedefs.h" 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #ifdef WEBRTC_AEC_DEBUG_DUMP 24 | // Opens a new Wav file for writing. If it was already open with a different 25 | // sample frequency, it closes it first. 26 | void WebRtcAec_ReopenWav(const char* name, 27 | int instance_index, 28 | int process_rate, 29 | int sample_rate, 30 | rtc_WavWriter** wav_file); 31 | 32 | // Opens dumpfile with instance-specific filename. 33 | void WebRtcAec_RawFileOpen(const char* name, int instance_index, FILE** file); 34 | 35 | #endif // WEBRTC_AEC_DEBUG_DUMP 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_LOGGING_FILE_HANDLING_ 42 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/filter_ar_fast_q12.c: -------------------------------------------------------------------------------- 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 | #include 11 | 12 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 13 | 14 | // TODO(bjornv): Change the return type to report errors. 15 | 16 | void WebRtcSpl_FilterARFastQ12(const int16_t* data_in, 17 | int16_t* data_out, 18 | const int16_t* __restrict coefficients, 19 | size_t coefficients_length, 20 | size_t data_length) { 21 | size_t i = 0; 22 | size_t j = 0; 23 | 24 | assert(data_length > 0); 25 | assert(coefficients_length > 1); 26 | 27 | for (i = 0; i < data_length; i++) { 28 | int32_t output = 0; 29 | int32_t sum = 0; 30 | 31 | for (j = coefficients_length - 1; j > 0; j--) { 32 | sum += coefficients[j] * data_out[i - j]; 33 | } 34 | 35 | output = coefficients[0] * data_in[i]; 36 | output -= sum; 37 | 38 | // Saturate and store the output. 39 | output = WEBRTC_SPL_SAT(134215679, output, -134217728); 40 | data_out[i] = (int16_t)((output + 2048) >> 12); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/get_scaling_square.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | /* 13 | * This file contains the function WebRtcSpl_GetScalingSquare(). 14 | * The description header can be found in signal_processing_library.h 15 | * 16 | */ 17 | 18 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 19 | 20 | int16_t WebRtcSpl_GetScalingSquare(int16_t* in_vector, 21 | size_t in_vector_length, 22 | size_t times) 23 | { 24 | int16_t nbits = WebRtcSpl_GetSizeInBits((uint32_t)times); 25 | size_t i; 26 | int16_t smax = -1; 27 | int16_t sabs; 28 | int16_t *sptr = in_vector; 29 | int16_t t; 30 | size_t looptimes = in_vector_length; 31 | 32 | for (i = looptimes; i > 0; i--) 33 | { 34 | sabs = (*sptr > 0 ? *sptr++ : -*sptr++); 35 | smax = (sabs > smax ? sabs : smax); 36 | } 37 | t = WebRtcSpl_NormW32(WEBRTC_SPL_MUL(smax, smax)); 38 | 39 | if (smax == 0) 40 | { 41 | return 0; // Since norm(0) returns 0 42 | } else 43 | { 44 | return (t > nbits) ? 0 : nbits - t; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/filter_ma_fast_q12.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | /* 13 | * This file contains the function WebRtcSpl_FilterMAFastQ12(). 14 | * The description header can be found in signal_processing_library.h 15 | * 16 | */ 17 | 18 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 19 | 20 | void WebRtcSpl_FilterMAFastQ12(const int16_t* in_ptr, 21 | int16_t* out_ptr, 22 | const int16_t* B, 23 | size_t B_length, 24 | size_t length) 25 | { 26 | size_t i, j; 27 | for (i = 0; i < length; i++) 28 | { 29 | int32_t o = 0; 30 | 31 | for (j = 0; j < B_length; j++) 32 | { 33 | o += B[j] * in_ptr[i - j]; 34 | } 35 | 36 | // If output is higher than 32768, saturate it. Same with negative side 37 | // 2^27 = 134217728, which corresponds to 32768 in Q12 38 | 39 | // Saturate the output 40 | o = WEBRTC_SPL_SAT((int32_t)134215679, o, (int32_t)-134217728); 41 | 42 | *out_ptr++ = (int16_t)((o + (int32_t)2048) >> 12); 43 | } 44 | return; 45 | } 46 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/aec/aec_resampler.h: -------------------------------------------------------------------------------- 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 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_RESAMPLER_H_ 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_RESAMPLER_H_ 13 | 14 | #include "webrtc/modules/audio_processing/aec/aec_core.h" 15 | 16 | enum { 17 | kResamplingDelay = 1 18 | }; 19 | enum { 20 | kResamplerBufferSize = FRAME_LEN * 4 21 | }; 22 | 23 | // Unless otherwise specified, functions return 0 on success and -1 on error. 24 | void* WebRtcAec_CreateResampler(); // Returns NULL on error. 25 | int WebRtcAec_InitResampler(void* resampInst, int deviceSampleRateHz); 26 | void WebRtcAec_FreeResampler(void* resampInst); 27 | 28 | // Estimates skew from raw measurement. 29 | int WebRtcAec_GetSkew(void* resampInst, int rawSkew, float* skewEst); 30 | 31 | // Resamples input using linear interpolation. 32 | void WebRtcAec_ResampleLinear(void* resampInst, 33 | const float* inspeech, 34 | size_t size, 35 | float skew, 36 | float* outspeech, 37 | size_t* size_out); 38 | 39 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_RESAMPLER_H_ 40 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/aec/echo_cancellation_unittest.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 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 | // TODO(bjornv): Make this a comprehensive test. 12 | 13 | #include "webrtc/modules/audio_processing/aec/include/echo_cancellation.h" 14 | 15 | #include 16 | #include 17 | 18 | extern "C" { 19 | #include "webrtc/modules/audio_processing/aec/aec_core.h" 20 | } 21 | 22 | #include "testing/gtest/include/gtest/gtest.h" 23 | #include "webrtc/base/checks.h" 24 | 25 | namespace webrtc { 26 | 27 | TEST(EchoCancellationTest, CreateAndFreeHasExpectedBehavior) { 28 | void* handle = WebRtcAec_Create(); 29 | ASSERT_TRUE(handle); 30 | WebRtcAec_Free(nullptr); 31 | WebRtcAec_Free(handle); 32 | } 33 | 34 | TEST(EchoCancellationTest, ApplyAecCoreHandle) { 35 | void* handle = WebRtcAec_Create(); 36 | ASSERT_TRUE(handle); 37 | EXPECT_TRUE(WebRtcAec_aec_core(NULL) == NULL); 38 | AecCore* aec_core = WebRtcAec_aec_core(handle); 39 | EXPECT_TRUE(aec_core != NULL); 40 | // A simple test to verify that we can set and get a value from the lower 41 | // level |aec_core| handle. 42 | int delay = 111; 43 | WebRtcAec_SetSystemDelay(aec_core, delay); 44 | EXPECT_EQ(delay, WebRtcAec_system_delay(aec_core)); 45 | WebRtcAec_Free(handle); 46 | } 47 | 48 | } // namespace webrtc 49 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/system_wrappers/interface/cpu_features_wrapper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | #ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CPU_FEATURES_WRAPPER_H_ 12 | #define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CPU_FEATURES_WRAPPER_H_ 13 | 14 | #if defined(__cplusplus) || defined(c_plusplus) 15 | extern "C" { 16 | #endif 17 | 18 | #include "webrtc/typedefs.h" 19 | 20 | // List of features in x86. 21 | typedef enum { 22 | kSSE2, 23 | kSSE3 24 | } CPUFeature; 25 | 26 | // List of features in ARM. 27 | enum { 28 | kCPUFeatureARMv7 = (1 << 0), 29 | kCPUFeatureVFPv3 = (1 << 1), 30 | kCPUFeatureNEON = (1 << 2), 31 | kCPUFeatureLDREXSTREX = (1 << 3) 32 | }; 33 | 34 | typedef int (*WebRtc_CPUInfo)(CPUFeature feature); 35 | 36 | // Returns true if the CPU supports the feature. 37 | extern WebRtc_CPUInfo WebRtc_GetCPUInfo; 38 | 39 | // No CPU feature is available => straight C path. 40 | extern WebRtc_CPUInfo WebRtc_GetCPUInfoNoASM; 41 | 42 | // Return the features in an ARM device. 43 | // It detects the features in the hardware platform, and returns supported 44 | // values in the above enum definition as a bitmask. 45 | extern uint64_t WebRtc_GetCPUFeaturesARM(void); 46 | 47 | #if defined(__cplusplus) || defined(c_plusplus) 48 | } // extern "C" 49 | #endif 50 | 51 | #endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CPU_FEATURES_WRAPPER_H_ 52 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/utility/delay_estimator_internal.h: -------------------------------------------------------------------------------- 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 | // Header file including the delay estimator handle used for testing. 12 | 13 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_DELAY_ESTIMATOR_INTERNAL_H_ 14 | #define WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_DELAY_ESTIMATOR_INTERNAL_H_ 15 | 16 | #include "webrtc/modules/audio_processing/utility/delay_estimator.h" 17 | #include "webrtc/typedefs.h" 18 | 19 | typedef union { 20 | float float_; 21 | int32_t int32_; 22 | } SpectrumType; 23 | 24 | typedef struct { 25 | // Pointers to mean values of spectrum. 26 | SpectrumType* mean_far_spectrum; 27 | // |mean_far_spectrum| initialization indicator. 28 | int far_spectrum_initialized; 29 | 30 | int spectrum_size; 31 | 32 | // Far-end part of binary spectrum based delay estimation. 33 | BinaryDelayEstimatorFarend* binary_farend; 34 | } DelayEstimatorFarend; 35 | 36 | typedef struct { 37 | // Pointers to mean values of spectrum. 38 | SpectrumType* mean_near_spectrum; 39 | // |mean_near_spectrum| initialization indicator. 40 | int near_spectrum_initialized; 41 | 42 | int spectrum_size; 43 | 44 | // Binary spectrum based delay estimator 45 | BinaryDelayEstimator* binary_handle; 46 | } DelayEstimator; 47 | 48 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_DELAY_ESTIMATOR_INTERNAL_H_ 49 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/refl_coef_to_lpc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | /* 13 | * This file contains the function WebRtcSpl_ReflCoefToLpc(). 14 | * The description header can be found in signal_processing_library.h 15 | * 16 | */ 17 | 18 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 19 | 20 | void WebRtcSpl_ReflCoefToLpc(const int16_t *k, int use_order, int16_t *a) 21 | { 22 | int16_t any[WEBRTC_SPL_MAX_LPC_ORDER + 1]; 23 | int16_t *aptr, *aptr2, *anyptr; 24 | const int16_t *kptr; 25 | int m, i; 26 | 27 | kptr = k; 28 | *a = 4096; // i.e., (Word16_MAX >> 3)+1. 29 | *any = *a; 30 | a[1] = *k >> 3; 31 | 32 | for (m = 1; m < use_order; m++) 33 | { 34 | kptr++; 35 | aptr = a; 36 | aptr++; 37 | aptr2 = &a[m]; 38 | anyptr = any; 39 | anyptr++; 40 | 41 | any[m + 1] = *kptr >> 3; 42 | for (i = 0; i < m; i++) 43 | { 44 | *anyptr = *aptr + (int16_t)((*aptr2 * *kptr) >> 15); 45 | anyptr++; 46 | aptr++; 47 | aptr2--; 48 | } 49 | 50 | aptr = a; 51 | anyptr = any; 52 | for (i = 0; i < (m + 2); i++) 53 | { 54 | *aptr = *anyptr; 55 | aptr++; 56 | anyptr++; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## webrtc-android-jni 2 | webrtc AEC module and its required dependencies module for android. 3 | 4 | ##How to build WebRTC 5 | * Go to jni folder and run ndk-build 6 | * Copy the resulting .so files from ../libs/[target_architecture] into your Android application project directory 7 | 8 | ##AEC 9 | ```c++ 10 | AudioProcessing* apm = AudioProcessing::Create(0); 11 | apm->set_sample_rate_hz(32000); 12 | Super-wideband processing. 13 | 14 | // Mono capture and stereo render. 15 | apm->set_num_channels(1, 1); 16 | apm->set_num_reverse_channels(2); 17 | apm->high_pass_filter()->Enable(true); 18 | apm->echo_cancellation()->enable_drift_compensation(false); 19 | apm->echo_cancellation()->Enable(true); 20 | apm->noise_reduction()->set_level(kHighSuppression); 21 | apm->noise_reduction()->Enable(true); 22 | apm->gain_control()->set_analog_level_limits(0, 255); 23 | apm->gain_control()->set_mode(kAdaptiveAnalog); 24 | apm->gain_control()->Enable(true); 25 | apm->voice_detection()->Enable(true); 26 | 27 | // Start a voice call... 28 | // ... Render frame arrives bound for the audio HAL ... 29 | apm->AnalyzeReverseStream(render_frame); 30 | 31 | // ... Capture frame arrives from the audio HAL ... 32 | // Call required set_stream_ functions. 33 | apm->set_stream_delay_ms(delay_ms); 34 | apm->gain_control()->set_stream_analog_level(analog_level); 35 | apm->ProcessStream(capture_frame); 36 | // Call required stream_ functions. 37 | analog_level = apm->gain_control()->stream_analog_level(); 38 | has_voice = apm->stream_has_voice(); 39 | 40 | // Repeate render and capture processing for the duration of the call... 41 | // Start a new call... 42 | apm->Initialize(); 43 | 44 | // Close the application... 45 | AudioProcessing::Destroy(apm); 46 | apm = NULL; 47 | ``` 48 | 49 | [Link !](https://trac.pjsip.org/repos/ticket/1888) 50 | 51 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/ns/noise_suppression_x.c: -------------------------------------------------------------------------------- 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 | #include "webrtc/modules/audio_processing/ns/include/noise_suppression_x.h" 12 | 13 | #include 14 | 15 | #include "webrtc/common_audio/signal_processing/include/real_fft.h" 16 | #include "webrtc/modules/audio_processing/ns/nsx_core.h" 17 | #include "webrtc/modules/audio_processing/ns/nsx_defines.h" 18 | 19 | NsxHandle* WebRtcNsx_Create() { 20 | NoiseSuppressionFixedC* self = malloc(sizeof(NoiseSuppressionFixedC)); 21 | WebRtcSpl_Init(); 22 | self->real_fft = NULL; 23 | self->initFlag = 0; 24 | return (NsxHandle*)self; 25 | } 26 | 27 | void WebRtcNsx_Free(NsxHandle* nsxInst) { 28 | WebRtcSpl_FreeRealFFT(((NoiseSuppressionFixedC*)nsxInst)->real_fft); 29 | free(nsxInst); 30 | } 31 | 32 | int WebRtcNsx_Init(NsxHandle* nsxInst, uint32_t fs) { 33 | return WebRtcNsx_InitCore((NoiseSuppressionFixedC*)nsxInst, fs); 34 | } 35 | 36 | int WebRtcNsx_set_policy(NsxHandle* nsxInst, int mode) { 37 | return WebRtcNsx_set_policy_core((NoiseSuppressionFixedC*)nsxInst, mode); 38 | } 39 | 40 | void WebRtcNsx_Process(NsxHandle* nsxInst, 41 | const short* const* speechFrame, 42 | int num_bands, 43 | short* const* outFrame) { 44 | WebRtcNsx_ProcessCore((NoiseSuppressionFixedC*)nsxInst, speechFrame, 45 | num_bands, outFrame); 46 | } 47 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/downsample_fast.c: -------------------------------------------------------------------------------- 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 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 12 | 13 | // TODO(Bjornv): Change the function parameter order to WebRTC code style. 14 | // C version of WebRtcSpl_DownsampleFast() for generic platforms. 15 | int WebRtcSpl_DownsampleFastC(const int16_t* data_in, 16 | size_t data_in_length, 17 | int16_t* data_out, 18 | size_t data_out_length, 19 | const int16_t* __restrict coefficients, 20 | size_t coefficients_length, 21 | int factor, 22 | size_t delay) { 23 | size_t i = 0; 24 | size_t j = 0; 25 | int32_t out_s32 = 0; 26 | size_t endpos = delay + factor * (data_out_length - 1) + 1; 27 | 28 | // Return error if any of the running conditions doesn't meet. 29 | if (data_out_length == 0 || coefficients_length == 0 30 | || data_in_length < endpos) { 31 | return -1; 32 | } 33 | 34 | for (i = delay; i < endpos; i += factor) { 35 | out_s32 = 2048; // Round value, 0.5 in Q12. 36 | 37 | for (j = 0; j < coefficients_length; j++) { 38 | out_s32 += coefficients[j] * data_in[i - j]; // Q12. 39 | } 40 | 41 | out_s32 >>= 12; // Q0. 42 | 43 | // Saturate and store the output. 44 | *data_out++ = WebRtcSpl_SatW32ToW16(out_s32); 45 | } 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/resample_by_2_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | /* 13 | * This header file contains some internal resampling functions. 14 | * 15 | */ 16 | 17 | #ifndef WEBRTC_SPL_RESAMPLE_BY_2_INTERNAL_H_ 18 | #define WEBRTC_SPL_RESAMPLE_BY_2_INTERNAL_H_ 19 | 20 | #include "webrtc/typedefs.h" 21 | 22 | /******************************************************************* 23 | * resample_by_2_fast.c 24 | * Functions for internal use in the other resample functions 25 | ******************************************************************/ 26 | void WebRtcSpl_DownBy2IntToShort(int32_t *in, int32_t len, int16_t *out, 27 | int32_t *state); 28 | 29 | void WebRtcSpl_DownBy2ShortToInt(const int16_t *in, int32_t len, 30 | int32_t *out, int32_t *state); 31 | 32 | void WebRtcSpl_UpBy2ShortToInt(const int16_t *in, int32_t len, 33 | int32_t *out, int32_t *state); 34 | 35 | void WebRtcSpl_UpBy2IntToInt(const int32_t *in, int32_t len, int32_t *out, 36 | int32_t *state); 37 | 38 | void WebRtcSpl_UpBy2IntToShort(const int32_t *in, int32_t len, 39 | int16_t *out, int32_t *state); 40 | 41 | void WebRtcSpl_LPBy2ShortToInt(const int16_t* in, int32_t len, 42 | int32_t* out, int32_t* state); 43 | 44 | void WebRtcSpl_LPBy2IntToInt(const int32_t* in, int32_t len, int32_t* out, 45 | int32_t* state); 46 | 47 | #endif // WEBRTC_SPL_RESAMPLE_BY_2_INTERNAL_H_ 48 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/aec/echo_cancellation_internal.h: -------------------------------------------------------------------------------- 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 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_ECHO_CANCELLATION_INTERNAL_H_ 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_ECHO_CANCELLATION_INTERNAL_H_ 13 | 14 | #include "webrtc/common_audio/ring_buffer.h" 15 | #include "webrtc/modules/audio_processing/aec/aec_core.h" 16 | 17 | typedef struct { 18 | int delayCtr; 19 | int sampFreq; 20 | int splitSampFreq; 21 | int scSampFreq; 22 | float sampFactor; // scSampRate / sampFreq 23 | short skewMode; 24 | int bufSizeStart; 25 | int knownDelay; 26 | int rate_factor; 27 | 28 | short initFlag; // indicates if AEC has been initialized 29 | 30 | // Variables used for averaging far end buffer size 31 | short counter; 32 | int sum; 33 | short firstVal; 34 | short checkBufSizeCtr; 35 | 36 | // Variables used for delay shifts 37 | short msInSndCardBuf; 38 | short filtDelay; // Filtered delay estimate. 39 | int timeForDelayChange; 40 | int startup_phase; 41 | int checkBuffSize; 42 | short lastDelayDiff; 43 | 44 | #ifdef WEBRTC_AEC_DEBUG_DUMP 45 | FILE* bufFile; 46 | FILE* delayFile; 47 | FILE* skewFile; 48 | #endif 49 | 50 | // Structures 51 | void* resampler; 52 | 53 | int skewFrCtr; 54 | int resample; // if the skew is small enough we don't resample 55 | int highSkewCtr; 56 | float skew; 57 | 58 | RingBuffer* far_pre_buf; // Time domain far-end pre-buffer. 59 | 60 | int lastError; 61 | 62 | int farend_started; 63 | 64 | AecCore* aec; 65 | } Aec; 66 | 67 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_ECHO_CANCELLATION_INTERNAL_H_ 68 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/lpc_to_refl_coef.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | /* 13 | * This file contains the function WebRtcSpl_LpcToReflCoef(). 14 | * The description header can be found in signal_processing_library.h 15 | * 16 | */ 17 | 18 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 19 | 20 | #define SPL_LPC_TO_REFL_COEF_MAX_AR_MODEL_ORDER 50 21 | 22 | void WebRtcSpl_LpcToReflCoef(int16_t* a16, int use_order, int16_t* k16) 23 | { 24 | int m, k; 25 | int32_t tmp32[SPL_LPC_TO_REFL_COEF_MAX_AR_MODEL_ORDER]; 26 | int32_t tmp_inv_denom32; 27 | int16_t tmp_inv_denom16; 28 | 29 | k16[use_order - 1] = a16[use_order] << 3; // Q12<<3 => Q15 30 | for (m = use_order - 1; m > 0; m--) 31 | { 32 | // (1 - k^2) in Q30 33 | tmp_inv_denom32 = 1073741823 - k16[m] * k16[m]; 34 | // (1 - k^2) in Q15 35 | tmp_inv_denom16 = (int16_t)(tmp_inv_denom32 >> 15); 36 | 37 | for (k = 1; k <= m; k++) 38 | { 39 | // tmp[k] = (a[k] - RC[m] * a[m-k+1]) / (1.0 - RC[m]*RC[m]); 40 | 41 | // [Q12<<16 - (Q15*Q12)<<1] = [Q28 - Q28] = Q28 42 | tmp32[k] = (a16[k] << 16) - (k16[m] * a16[m - k + 1] << 1); 43 | 44 | tmp32[k] = WebRtcSpl_DivW32W16(tmp32[k], tmp_inv_denom16); //Q28/Q15 = Q13 45 | } 46 | 47 | for (k = 1; k < m; k++) 48 | { 49 | a16[k] = (int16_t)(tmp32[k] >> 1); // Q13>>1 => Q12 50 | } 51 | 52 | tmp32[m] = WEBRTC_SPL_SAT(8191, tmp32[m], -8191); 53 | k16[m - 1] = (int16_t)WEBRTC_SPL_LSHIFT_W32(tmp32[m], 2); //Q13<<2 => Q15 54 | } 55 | return; 56 | } 57 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/ns/noise_suppression.c: -------------------------------------------------------------------------------- 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 | #include "webrtc/modules/audio_processing/ns/include/noise_suppression.h" 12 | 13 | #include 14 | #include 15 | 16 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 17 | #include "webrtc/modules/audio_processing/ns/defines.h" 18 | #include "webrtc/modules/audio_processing/ns/ns_core.h" 19 | 20 | NsHandle* WebRtcNs_Create() { 21 | NoiseSuppressionC* self = malloc(sizeof(NoiseSuppressionC)); 22 | self->initFlag = 0; 23 | return (NsHandle*)self; 24 | } 25 | 26 | void WebRtcNs_Free(NsHandle* NS_inst) { 27 | free(NS_inst); 28 | } 29 | 30 | int WebRtcNs_Init(NsHandle* NS_inst, uint32_t fs) { 31 | return WebRtcNs_InitCore((NoiseSuppressionC*)NS_inst, fs); 32 | } 33 | 34 | int WebRtcNs_set_policy(NsHandle* NS_inst, int mode) { 35 | return WebRtcNs_set_policy_core((NoiseSuppressionC*)NS_inst, mode); 36 | } 37 | 38 | void WebRtcNs_Analyze(NsHandle* NS_inst, const float* spframe) { 39 | WebRtcNs_AnalyzeCore((NoiseSuppressionC*)NS_inst, spframe); 40 | } 41 | 42 | void WebRtcNs_Process(NsHandle* NS_inst, 43 | const float* const* spframe, 44 | size_t num_bands, 45 | float* const* outframe) { 46 | WebRtcNs_ProcessCore((NoiseSuppressionC*)NS_inst, spframe, num_bands, 47 | outframe); 48 | } 49 | 50 | float WebRtcNs_prior_speech_probability(NsHandle* handle) { 51 | NoiseSuppressionC* self = (NoiseSuppressionC*)handle; 52 | if (handle == NULL) { 53 | return -1; 54 | } 55 | if (self->initFlag == 0) { 56 | return -1; 57 | } 58 | return self->priorSpeechProb; 59 | } 60 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/logging/aec_logging_file_handling.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 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 | #include "webrtc/modules/audio_processing/logging/aec_logging_file_handling.h" 12 | 13 | #include 14 | #include 15 | 16 | #include "webrtc/base/checks.h" 17 | #include "webrtc/base/stringutils.h" 18 | #include "webrtc/common_audio/wav_file.h" 19 | #include "webrtc/typedefs.h" 20 | 21 | #ifdef WEBRTC_AEC_DEBUG_DUMP 22 | void WebRtcAec_ReopenWav(const char* name, 23 | int instance_index, 24 | int process_rate, 25 | int sample_rate, 26 | rtc_WavWriter** wav_file) { 27 | if (*wav_file) { 28 | if (rtc_WavSampleRate(*wav_file) == sample_rate) 29 | return; 30 | rtc_WavClose(*wav_file); 31 | } 32 | char filename[64]; 33 | int written = rtc::sprintfn(filename, sizeof(filename), "%s%d-%d.wav", name, 34 | instance_index, process_rate); 35 | 36 | // Ensure there was no buffer output error. 37 | RTC_DCHECK_GE(written, 0); 38 | // Ensure that the buffer size was sufficient. 39 | RTC_DCHECK_LT(static_cast(written), sizeof(filename)); 40 | 41 | *wav_file = rtc_WavOpen(filename, sample_rate, 1); 42 | } 43 | 44 | void WebRtcAec_RawFileOpen(const char* name, int instance_index, FILE** file) { 45 | char filename[64]; 46 | int written = rtc::sprintfn(filename, sizeof(filename), "%s_%d.dat", name, 47 | instance_index); 48 | 49 | // Ensure there was no buffer output error. 50 | RTC_DCHECK_GE(written, 0); 51 | // Ensure that the buffer size was sufficient. 52 | RTC_DCHECK_LT(static_cast(written), sizeof(filename)); 53 | 54 | *file = fopen(filename, "wb"); 55 | } 56 | 57 | #endif // WEBRTC_AEC_DEBUG_DUMP 58 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/system_wrappers/source/cpu_features.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | // Parts of this file derived from Chromium's base/cpu.cc. 12 | 13 | #include "webrtc/system_wrappers/interface/cpu_features_wrapper.h" 14 | 15 | #if defined(WEBRTC_ARCH_X86_FAMILY) && defined(_MSC_VER) 16 | #include 17 | #endif 18 | 19 | #include "webrtc/typedefs.h" 20 | 21 | // No CPU feature is available => straight C path. 22 | int GetCPUInfoNoASM(CPUFeature feature) { 23 | (void)feature; 24 | return 0; 25 | } 26 | 27 | #if defined(WEBRTC_ARCH_X86_FAMILY) 28 | #ifndef _MSC_VER 29 | // Intrinsic for "cpuid". 30 | #if defined(__pic__) && defined(__i386__) 31 | static inline void __cpuid(int cpu_info[4], int info_type) { 32 | __asm__ volatile( 33 | "mov %%ebx, %%edi\n" 34 | "cpuid\n" 35 | "xchg %%edi, %%ebx\n" 36 | : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) 37 | : "a"(info_type)); 38 | } 39 | #else 40 | static inline void __cpuid(int cpu_info[4], int info_type) { 41 | __asm__ volatile( 42 | "cpuid\n" 43 | : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) 44 | : "a"(info_type)); 45 | } 46 | #endif 47 | #endif // _MSC_VER 48 | #endif // WEBRTC_ARCH_X86_FAMILY 49 | 50 | #if defined(WEBRTC_ARCH_X86_FAMILY) 51 | // Actual feature detection for x86. 52 | static int GetCPUInfo(CPUFeature feature) { 53 | int cpu_info[4]; 54 | __cpuid(cpu_info, 1); 55 | if (feature == kSSE2) { 56 | return 0 != (cpu_info[3] & 0x04000000); 57 | } 58 | if (feature == kSSE3) { 59 | return 0 != (cpu_info[2] & 0x00000001); 60 | } 61 | return 0; 62 | } 63 | #else 64 | // Default to straight C for other platforms. 65 | static int GetCPUInfo(CPUFeature feature) { 66 | (void)feature; 67 | return 0; 68 | } 69 | #endif 70 | 71 | WebRtc_CPUInfo WebRtc_GetCPUInfo = GetCPUInfo; 72 | WebRtc_CPUInfo WebRtc_GetCPUInfoNoASM = GetCPUInfoNoASM; 73 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/auto_correlation.c: -------------------------------------------------------------------------------- 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 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 12 | 13 | #include 14 | 15 | size_t WebRtcSpl_AutoCorrelation(const int16_t* in_vector, 16 | size_t in_vector_length, 17 | size_t order, 18 | int32_t* result, 19 | int* scale) { 20 | int32_t sum = 0; 21 | size_t i = 0, j = 0; 22 | int16_t smax = 0; 23 | int scaling = 0; 24 | 25 | assert(order <= in_vector_length); 26 | 27 | // Find the maximum absolute value of the samples. 28 | smax = WebRtcSpl_MaxAbsValueW16(in_vector, in_vector_length); 29 | 30 | // In order to avoid overflow when computing the sum we should scale the 31 | // samples so that (in_vector_length * smax * smax) will not overflow. 32 | if (smax == 0) { 33 | scaling = 0; 34 | } else { 35 | // Number of bits in the sum loop. 36 | int nbits = WebRtcSpl_GetSizeInBits((uint32_t)in_vector_length); 37 | // Number of bits to normalize smax. 38 | int t = WebRtcSpl_NormW32(WEBRTC_SPL_MUL(smax, smax)); 39 | 40 | if (t > nbits) { 41 | scaling = 0; 42 | } else { 43 | scaling = nbits - t; 44 | } 45 | } 46 | 47 | // Perform the actual correlation calculation. 48 | for (i = 0; i < order + 1; i++) { 49 | sum = 0; 50 | /* Unroll the loop to improve performance. */ 51 | for (j = 0; i + j + 3 < in_vector_length; j += 4) { 52 | sum += (in_vector[j + 0] * in_vector[i + j + 0]) >> scaling; 53 | sum += (in_vector[j + 1] * in_vector[i + j + 1]) >> scaling; 54 | sum += (in_vector[j + 2] * in_vector[i + j + 2]) >> scaling; 55 | sum += (in_vector[j + 3] * in_vector[i + j + 3]) >> scaling; 56 | } 57 | for (; j < in_vector_length - i; j++) { 58 | sum += (in_vector[j] * in_vector[i + j]) >> scaling; 59 | } 60 | *result++ = sum; 61 | } 62 | 63 | *scale = scaling; 64 | return order + 1; 65 | } 66 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/copy_set_operations.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | /* 13 | * This file contains the implementation of functions 14 | * WebRtcSpl_MemSetW16() 15 | * WebRtcSpl_MemSetW32() 16 | * WebRtcSpl_MemCpyReversedOrder() 17 | * WebRtcSpl_CopyFromEndW16() 18 | * WebRtcSpl_ZerosArrayW16() 19 | * WebRtcSpl_ZerosArrayW32() 20 | * 21 | * The description header can be found in signal_processing_library.h 22 | * 23 | */ 24 | 25 | #include 26 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 27 | 28 | 29 | void WebRtcSpl_MemSetW16(int16_t *ptr, int16_t set_value, size_t length) 30 | { 31 | size_t j; 32 | int16_t *arrptr = ptr; 33 | 34 | for (j = length; j > 0; j--) 35 | { 36 | *arrptr++ = set_value; 37 | } 38 | } 39 | 40 | void WebRtcSpl_MemSetW32(int32_t *ptr, int32_t set_value, size_t length) 41 | { 42 | size_t j; 43 | int32_t *arrptr = ptr; 44 | 45 | for (j = length; j > 0; j--) 46 | { 47 | *arrptr++ = set_value; 48 | } 49 | } 50 | 51 | void WebRtcSpl_MemCpyReversedOrder(int16_t* dest, 52 | int16_t* source, 53 | size_t length) 54 | { 55 | size_t j; 56 | int16_t* destPtr = dest; 57 | int16_t* sourcePtr = source; 58 | 59 | for (j = 0; j < length; j++) 60 | { 61 | *destPtr-- = *sourcePtr++; 62 | } 63 | } 64 | 65 | void WebRtcSpl_CopyFromEndW16(const int16_t *vector_in, 66 | size_t length, 67 | size_t samples, 68 | int16_t *vector_out) 69 | { 70 | // Copy the last of the input vector to vector_out 71 | WEBRTC_SPL_MEMCPY_W16(vector_out, &vector_in[length - samples], samples); 72 | } 73 | 74 | void WebRtcSpl_ZerosArrayW16(int16_t *vector, size_t length) 75 | { 76 | WebRtcSpl_MemSetW16(vector, 0, length); 77 | } 78 | 79 | void WebRtcSpl_ZerosArrayW32(int32_t *vector, size_t length) 80 | { 81 | WebRtcSpl_MemSetW32(vector, 0, length); 82 | } 83 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/aec/aec_rdft.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_MAIN_SOURCE_AEC_RDFT_H_ 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_MAIN_SOURCE_AEC_RDFT_H_ 13 | 14 | #include "webrtc/modules/audio_processing/aec/aec_common.h" 15 | 16 | // These intrinsics were unavailable before VS 2008. 17 | // TODO(andrew): move to a common file. 18 | #if defined(_MSC_VER) && _MSC_VER < 1500 19 | #include 20 | static __inline __m128 _mm_castsi128_ps(__m128i a) { return *(__m128*)&a; } 21 | static __inline __m128i _mm_castps_si128(__m128 a) { return *(__m128i*)&a; } 22 | #endif 23 | 24 | // Constants shared by all paths (C, SSE2, NEON). 25 | extern const float rdft_w[64]; 26 | // Constants used by the C path. 27 | extern const float rdft_wk3ri_first[16]; 28 | extern const float rdft_wk3ri_second[16]; 29 | // Constants used by SSE2 and NEON but initialized in the C path. 30 | extern ALIGN16_BEG const float ALIGN16_END rdft_wk1r[32]; 31 | extern ALIGN16_BEG const float ALIGN16_END rdft_wk2r[32]; 32 | extern ALIGN16_BEG const float ALIGN16_END rdft_wk3r[32]; 33 | extern ALIGN16_BEG const float ALIGN16_END rdft_wk1i[32]; 34 | extern ALIGN16_BEG const float ALIGN16_END rdft_wk2i[32]; 35 | extern ALIGN16_BEG const float ALIGN16_END rdft_wk3i[32]; 36 | extern ALIGN16_BEG const float ALIGN16_END cftmdl_wk1r[4]; 37 | 38 | // code path selection function pointers 39 | typedef void (*RftSub128)(float* a); 40 | extern RftSub128 rftfsub_128; 41 | extern RftSub128 rftbsub_128; 42 | extern RftSub128 cft1st_128; 43 | extern RftSub128 cftmdl_128; 44 | extern RftSub128 cftfsub_128; 45 | extern RftSub128 cftbsub_128; 46 | extern RftSub128 bitrv2_128; 47 | 48 | // entry points 49 | void aec_rdft_init(void); 50 | void aec_rdft_init_sse2(void); 51 | void aec_rdft_forward_128(float* a); 52 | void aec_rdft_inverse_128(float* a); 53 | 54 | #if defined(MIPS_FPU_LE) 55 | void aec_rdft_init_mips(void); 56 | #endif 57 | #if defined(WEBRTC_DETECT_NEON) || defined(WEBRTC_HAS_NEON) 58 | void aec_rdft_init_neon(void); 59 | #endif 60 | 61 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_MAIN_SOURCE_AEC_RDFT_H_ 62 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/vector_scaling_operations_mips.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 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 | /* 13 | * This file contains implementations of the functions 14 | * WebRtcSpl_ScaleAndAddVectorsWithRound_mips() 15 | */ 16 | 17 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 18 | 19 | int WebRtcSpl_ScaleAndAddVectorsWithRound_mips(const int16_t* in_vector1, 20 | int16_t in_vector1_scale, 21 | const int16_t* in_vector2, 22 | int16_t in_vector2_scale, 23 | int right_shifts, 24 | int16_t* out_vector, 25 | size_t length) { 26 | int16_t r0 = 0, r1 = 0; 27 | int16_t *in1 = (int16_t*)in_vector1; 28 | int16_t *in2 = (int16_t*)in_vector2; 29 | int16_t *out = out_vector; 30 | size_t i = 0; 31 | int value32 = 0; 32 | 33 | if (in_vector1 == NULL || in_vector2 == NULL || out_vector == NULL || 34 | length == 0 || right_shifts < 0) { 35 | return -1; 36 | } 37 | for (i = 0; i < length; i++) { 38 | __asm __volatile ( 39 | "lh %[r0], 0(%[in1]) \n\t" 40 | "lh %[r1], 0(%[in2]) \n\t" 41 | "mult %[r0], %[in_vector1_scale] \n\t" 42 | "madd %[r1], %[in_vector2_scale] \n\t" 43 | "extrv_r.w %[value32], $ac0, %[right_shifts] \n\t" 44 | "addiu %[in1], %[in1], 2 \n\t" 45 | "addiu %[in2], %[in2], 2 \n\t" 46 | "sh %[value32], 0(%[out]) \n\t" 47 | "addiu %[out], %[out], 2 \n\t" 48 | : [value32] "=&r" (value32), [out] "+r" (out), [in1] "+r" (in1), 49 | [in2] "+r" (in2), [r0] "=&r" (r0), [r1] "=&r" (r1) 50 | : [in_vector1_scale] "r" (in_vector1_scale), 51 | [in_vector2_scale] "r" (in_vector2_scale), 52 | [right_shifts] "r" (right_shifts) 53 | : "hi", "lo", "memory" 54 | ); 55 | } 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/spl_sqrt_floor.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Written by Wilco Dijkstra, 1996. The following email exchange establishes the 3 | * license. 4 | * 5 | * From: Wilco Dijkstra 6 | * Date: Fri, Jun 24, 2011 at 3:20 AM 7 | * Subject: Re: sqrt routine 8 | * To: Kevin Ma 9 | * Hi Kevin, 10 | * Thanks for asking. Those routines are public domain (originally posted to 11 | * comp.sys.arm a long time ago), so you can use them freely for any purpose. 12 | * Cheers, 13 | * Wilco 14 | * 15 | * ----- Original Message ----- 16 | * From: "Kevin Ma" 17 | * To: 18 | * Sent: Thursday, June 23, 2011 11:44 PM 19 | * Subject: Fwd: sqrt routine 20 | * Hi Wilco, 21 | * I saw your sqrt routine from several web sites, including 22 | * http://www.finesse.demon.co.uk/steven/sqrt.html. 23 | * Just wonder if there's any copyright information with your Successive 24 | * approximation routines, or if I can freely use it for any purpose. 25 | * Thanks. 26 | * Kevin 27 | */ 28 | 29 | // Minor modifications in code style for WebRTC, 2012. 30 | 31 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 32 | 33 | /* 34 | * Algorithm: 35 | * Successive approximation of the equation (root + delta) ^ 2 = N 36 | * until delta < 1. If delta < 1 we have the integer part of SQRT (N). 37 | * Use delta = 2^i for i = 15 .. 0. 38 | * 39 | * Output precision is 16 bits. Note for large input values (close to 40 | * 0x7FFFFFFF), bit 15 (the highest bit of the low 16-bit half word) 41 | * contains the MSB information (a non-sign value). Do with caution 42 | * if you need to cast the output to int16_t type. 43 | * 44 | * If the input value is negative, it returns 0. 45 | */ 46 | 47 | #define WEBRTC_SPL_SQRT_ITER(N) \ 48 | try1 = root + (1 << (N)); \ 49 | if (value >= try1 << (N)) \ 50 | { \ 51 | value -= try1 << (N); \ 52 | root |= 2 << (N); \ 53 | } 54 | 55 | int32_t WebRtcSpl_SqrtFloor(int32_t value) 56 | { 57 | int32_t root = 0, try1; 58 | 59 | WEBRTC_SPL_SQRT_ITER (15); 60 | WEBRTC_SPL_SQRT_ITER (14); 61 | WEBRTC_SPL_SQRT_ITER (13); 62 | WEBRTC_SPL_SQRT_ITER (12); 63 | WEBRTC_SPL_SQRT_ITER (11); 64 | WEBRTC_SPL_SQRT_ITER (10); 65 | WEBRTC_SPL_SQRT_ITER ( 9); 66 | WEBRTC_SPL_SQRT_ITER ( 8); 67 | WEBRTC_SPL_SQRT_ITER ( 7); 68 | WEBRTC_SPL_SQRT_ITER ( 6); 69 | WEBRTC_SPL_SQRT_ITER ( 5); 70 | WEBRTC_SPL_SQRT_ITER ( 4); 71 | WEBRTC_SPL_SQRT_ITER ( 3); 72 | WEBRTC_SPL_SQRT_ITER ( 2); 73 | WEBRTC_SPL_SQRT_ITER ( 1); 74 | WEBRTC_SPL_SQRT_ITER ( 0); 75 | 76 | return root >> 1; 77 | } 78 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/ns/defines.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_DEFINES_H_ 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_DEFINES_H_ 13 | 14 | #define BLOCKL_MAX 160 // max processing block length: 160 15 | #define ANAL_BLOCKL_MAX 256 // max analysis block length: 256 16 | #define HALF_ANAL_BLOCKL 129 // half max analysis block length + 1 17 | #define NUM_HIGH_BANDS_MAX 2 // max number of high bands: 2 18 | 19 | #define QUANTILE (float)0.25 20 | 21 | #define SIMULT 3 22 | #define END_STARTUP_LONG 200 23 | #define END_STARTUP_SHORT 50 24 | #define FACTOR (float)40.0 25 | #define WIDTH (float)0.01 26 | 27 | // Length of fft work arrays. 28 | #define IP_LENGTH (ANAL_BLOCKL_MAX >> 1) // must be at least ceil(2 + sqrt(ANAL_BLOCKL_MAX/2)) 29 | #define W_LENGTH (ANAL_BLOCKL_MAX >> 1) 30 | 31 | //PARAMETERS FOR NEW METHOD 32 | #define DD_PR_SNR (float)0.98 // DD update of prior SNR 33 | #define LRT_TAVG (float)0.50 // tavg parameter for LRT (previously 0.90) 34 | #define SPECT_FL_TAVG (float)0.30 // tavg parameter for spectral flatness measure 35 | #define SPECT_DIFF_TAVG (float)0.30 // tavg parameter for spectral difference measure 36 | #define PRIOR_UPDATE (float)0.10 // update parameter of prior model 37 | #define NOISE_UPDATE (float)0.90 // update parameter for noise 38 | #define SPEECH_UPDATE (float)0.99 // update parameter when likely speech 39 | #define WIDTH_PR_MAP (float)4.0 // width parameter in sigmoid map for prior model 40 | #define LRT_FEATURE_THR (float)0.5 // default threshold for LRT feature 41 | #define SF_FEATURE_THR (float)0.5 // default threshold for Spectral Flatness feature 42 | #define SD_FEATURE_THR (float)0.5 // default threshold for Spectral Difference feature 43 | #define PROB_RANGE (float)0.20 // probability threshold for noise state in 44 | // speech/noise likelihood 45 | #define HIST_PAR_EST 1000 // histogram size for estimation of parameters 46 | #define GAMMA_PAUSE (float)0.05 // update for conservative noise estimate 47 | // 48 | #define B_LIM (float)0.5 // threshold in final energy gain factor calculation 49 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_DEFINES_H_ 50 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/ring_buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | // A ring buffer to hold arbitrary data. Provides no thread safety. Unless 12 | // otherwise specified, functions return 0 on success and -1 on error. 13 | 14 | #ifndef WEBRTC_COMMON_AUDIO_RING_BUFFER_H_ 15 | #define WEBRTC_COMMON_AUDIO_RING_BUFFER_H_ 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | #include // size_t 22 | 23 | typedef struct RingBuffer RingBuffer; 24 | 25 | // Creates and initializes the buffer. Returns NULL on failure. 26 | RingBuffer* WebRtc_CreateBuffer(size_t element_count, size_t element_size); 27 | void WebRtc_InitBuffer(RingBuffer* handle); 28 | void WebRtc_FreeBuffer(void* handle); 29 | 30 | // Reads data from the buffer. The |data_ptr| will point to the address where 31 | // it is located. If all |element_count| data are feasible to read without 32 | // buffer wrap around |data_ptr| will point to the location in the buffer. 33 | // Otherwise, the data will be copied to |data| (memory allocation done by the 34 | // user) and |data_ptr| points to the address of |data|. |data_ptr| is only 35 | // guaranteed to be valid until the next call to WebRtc_WriteBuffer(). 36 | // 37 | // To force a copying to |data|, pass a NULL |data_ptr|. 38 | // 39 | // Returns number of elements read. 40 | size_t WebRtc_ReadBuffer(RingBuffer* handle, 41 | void** data_ptr, 42 | void* data, 43 | size_t element_count); 44 | 45 | // Writes |data| to buffer and returns the number of elements written. 46 | size_t WebRtc_WriteBuffer(RingBuffer* handle, const void* data, 47 | size_t element_count); 48 | 49 | // Moves the buffer read position and returns the number of elements moved. 50 | // Positive |element_count| moves the read position towards the write position, 51 | // that is, flushing the buffer. Negative |element_count| moves the read 52 | // position away from the the write position, that is, stuffing the buffer. 53 | // Returns number of elements moved. 54 | int WebRtc_MoveReadPtr(RingBuffer* handle, int element_count); 55 | 56 | // Returns number of available elements to read. 57 | size_t WebRtc_available_read(const RingBuffer* handle); 58 | 59 | // Returns number of available elements for write. 60 | size_t WebRtc_available_write(const RingBuffer* handle); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif // WEBRTC_COMMON_AUDIO_RING_BUFFER_H_ 67 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/ns/include/noise_suppression_x.h: -------------------------------------------------------------------------------- 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 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_NS_INCLUDE_NOISE_SUPPRESSION_X_H_ 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_NS_INCLUDE_NOISE_SUPPRESSION_X_H_ 13 | 14 | #include "webrtc/typedefs.h" 15 | 16 | typedef struct NsxHandleT NsxHandle; 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /* 23 | * This function creates an instance of the fixed point Noise Suppression. 24 | */ 25 | NsxHandle* WebRtcNsx_Create(); 26 | 27 | /* 28 | * This function frees the dynamic memory of a specified Noise Suppression 29 | * instance. 30 | * 31 | * Input: 32 | * - nsxInst : Pointer to NS instance that should be freed 33 | */ 34 | void WebRtcNsx_Free(NsxHandle* nsxInst); 35 | 36 | /* 37 | * This function initializes a NS instance 38 | * 39 | * Input: 40 | * - nsxInst : Instance that should be initialized 41 | * - fs : sampling frequency 42 | * 43 | * Output: 44 | * - nsxInst : Initialized instance 45 | * 46 | * Return value : 0 - Ok 47 | * -1 - Error 48 | */ 49 | int WebRtcNsx_Init(NsxHandle* nsxInst, uint32_t fs); 50 | 51 | /* 52 | * This changes the aggressiveness of the noise suppression method. 53 | * 54 | * Input: 55 | * - nsxInst : Instance that should be initialized 56 | * - mode : 0: Mild, 1: Medium , 2: Aggressive 57 | * 58 | * Output: 59 | * - nsxInst : Initialized instance 60 | * 61 | * Return value : 0 - Ok 62 | * -1 - Error 63 | */ 64 | int WebRtcNsx_set_policy(NsxHandle* nsxInst, int mode); 65 | 66 | /* 67 | * This functions does noise suppression for the inserted speech frame. The 68 | * input and output signals should always be 10ms (80 or 160 samples). 69 | * 70 | * Input 71 | * - nsxInst : NSx instance. Needs to be initiated before call. 72 | * - speechFrame : Pointer to speech frame buffer for each band 73 | * - num_bands : Number of bands 74 | * 75 | * Output: 76 | * - nsxInst : Updated NSx instance 77 | * - outFrame : Pointer to output frame for each band 78 | */ 79 | void WebRtcNsx_Process(NsxHandle* nsxInst, 80 | const short* const* speechFrame, 81 | int num_bands, 82 | short* const* outFrame); 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_NS_INCLUDE_NOISE_SUPPRESSION_X_H_ 89 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/filter_ar.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | /* 13 | * This file contains the function WebRtcSpl_FilterAR(). 14 | * The description header can be found in signal_processing_library.h 15 | * 16 | */ 17 | 18 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 19 | 20 | size_t WebRtcSpl_FilterAR(const int16_t* a, 21 | size_t a_length, 22 | const int16_t* x, 23 | size_t x_length, 24 | int16_t* state, 25 | size_t state_length, 26 | int16_t* state_low, 27 | size_t state_low_length, 28 | int16_t* filtered, 29 | int16_t* filtered_low, 30 | size_t filtered_low_length) 31 | { 32 | int32_t o; 33 | int32_t oLOW; 34 | size_t i, j, stop; 35 | const int16_t* x_ptr = &x[0]; 36 | int16_t* filteredFINAL_ptr = filtered; 37 | int16_t* filteredFINAL_LOW_ptr = filtered_low; 38 | 39 | for (i = 0; i < x_length; i++) 40 | { 41 | // Calculate filtered[i] and filtered_low[i] 42 | const int16_t* a_ptr = &a[1]; 43 | int16_t* filtered_ptr = &filtered[i - 1]; 44 | int16_t* filtered_low_ptr = &filtered_low[i - 1]; 45 | int16_t* state_ptr = &state[state_length - 1]; 46 | int16_t* state_low_ptr = &state_low[state_length - 1]; 47 | 48 | o = (int32_t)(*x_ptr++) << 12; 49 | oLOW = (int32_t)0; 50 | 51 | stop = (i < a_length) ? i + 1 : a_length; 52 | for (j = 1; j < stop; j++) 53 | { 54 | o -= *a_ptr * *filtered_ptr--; 55 | oLOW -= *a_ptr++ * *filtered_low_ptr--; 56 | } 57 | for (j = i + 1; j < a_length; j++) 58 | { 59 | o -= *a_ptr * *state_ptr--; 60 | oLOW -= *a_ptr++ * *state_low_ptr--; 61 | } 62 | 63 | o += (oLOW >> 12); 64 | *filteredFINAL_ptr = (int16_t)((o + (int32_t)2048) >> 12); 65 | *filteredFINAL_LOW_ptr++ = (int16_t)(o - ((int32_t)(*filteredFINAL_ptr++) 66 | << 12)); 67 | } 68 | 69 | // Save the filter state 70 | if (x_length >= state_length) 71 | { 72 | WebRtcSpl_CopyFromEndW16(filtered, x_length, a_length - 1, state); 73 | WebRtcSpl_CopyFromEndW16(filtered_low, x_length, a_length - 1, state_low); 74 | } else 75 | { 76 | for (i = 0; i < state_length - x_length; i++) 77 | { 78 | state[i] = state[i + x_length]; 79 | state_low[i] = state_low[i + x_length]; 80 | } 81 | for (i = 0; i < x_length; i++) 82 | { 83 | state[state_length - x_length + i] = filtered[i]; 84 | state[state_length - x_length + i] = filtered_low[i]; 85 | } 86 | } 87 | 88 | return x_length; 89 | } 90 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/ilbc_specific_functions.c: -------------------------------------------------------------------------------- 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 | /* 13 | * This file contains implementations of the iLBC specific functions 14 | * WebRtcSpl_ReverseOrderMultArrayElements() 15 | * WebRtcSpl_ElementwiseVectorMult() 16 | * WebRtcSpl_AddVectorsAndShift() 17 | * WebRtcSpl_AddAffineVectorToVector() 18 | * WebRtcSpl_AffineTransformVector() 19 | * 20 | */ 21 | 22 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 23 | 24 | void WebRtcSpl_ReverseOrderMultArrayElements(int16_t *out, const int16_t *in, 25 | const int16_t *win, 26 | size_t vector_length, 27 | int16_t right_shifts) 28 | { 29 | size_t i; 30 | int16_t *outptr = out; 31 | const int16_t *inptr = in; 32 | const int16_t *winptr = win; 33 | for (i = 0; i < vector_length; i++) 34 | { 35 | *outptr++ = (int16_t)((*inptr++ * *winptr--) >> right_shifts); 36 | } 37 | } 38 | 39 | void WebRtcSpl_ElementwiseVectorMult(int16_t *out, const int16_t *in, 40 | const int16_t *win, size_t vector_length, 41 | int16_t right_shifts) 42 | { 43 | size_t i; 44 | int16_t *outptr = out; 45 | const int16_t *inptr = in; 46 | const int16_t *winptr = win; 47 | for (i = 0; i < vector_length; i++) 48 | { 49 | *outptr++ = (int16_t)((*inptr++ * *winptr++) >> right_shifts); 50 | } 51 | } 52 | 53 | void WebRtcSpl_AddVectorsAndShift(int16_t *out, const int16_t *in1, 54 | const int16_t *in2, size_t vector_length, 55 | int16_t right_shifts) 56 | { 57 | size_t i; 58 | int16_t *outptr = out; 59 | const int16_t *in1ptr = in1; 60 | const int16_t *in2ptr = in2; 61 | for (i = vector_length; i > 0; i--) 62 | { 63 | (*outptr++) = (int16_t)(((*in1ptr++) + (*in2ptr++)) >> right_shifts); 64 | } 65 | } 66 | 67 | void WebRtcSpl_AddAffineVectorToVector(int16_t *out, int16_t *in, 68 | int16_t gain, int32_t add_constant, 69 | int16_t right_shifts, 70 | size_t vector_length) 71 | { 72 | size_t i; 73 | 74 | for (i = 0; i < vector_length; i++) 75 | { 76 | out[i] += (int16_t)((in[i] * gain + add_constant) >> right_shifts); 77 | } 78 | } 79 | 80 | void WebRtcSpl_AffineTransformVector(int16_t *out, int16_t *in, 81 | int16_t gain, int32_t add_constant, 82 | int16_t right_shifts, size_t vector_length) 83 | { 84 | size_t i; 85 | 86 | for (i = 0; i < vector_length; i++) 87 | { 88 | out[i] = (int16_t)((in[i] * gain + add_constant) >> right_shifts); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/auto_corr_to_refl_coef.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | /* 13 | * This file contains the function WebRtcSpl_AutoCorrToReflCoef(). 14 | * The description header can be found in signal_processing_library.h 15 | * 16 | */ 17 | 18 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 19 | 20 | void WebRtcSpl_AutoCorrToReflCoef(const int32_t *R, int use_order, int16_t *K) 21 | { 22 | int i, n; 23 | int16_t tmp; 24 | const int32_t *rptr; 25 | int32_t L_num, L_den; 26 | int16_t *acfptr, *pptr, *wptr, *p1ptr, *w1ptr, ACF[WEBRTC_SPL_MAX_LPC_ORDER], 27 | P[WEBRTC_SPL_MAX_LPC_ORDER], W[WEBRTC_SPL_MAX_LPC_ORDER]; 28 | 29 | // Initialize loop and pointers. 30 | acfptr = ACF; 31 | rptr = R; 32 | pptr = P; 33 | p1ptr = &P[1]; 34 | w1ptr = &W[1]; 35 | wptr = w1ptr; 36 | 37 | // First loop; n=0. Determine shifting. 38 | tmp = WebRtcSpl_NormW32(*R); 39 | *acfptr = (int16_t)((*rptr++ << tmp) >> 16); 40 | *pptr++ = *acfptr++; 41 | 42 | // Initialize ACF, P and W. 43 | for (i = 1; i <= use_order; i++) 44 | { 45 | *acfptr = (int16_t)((*rptr++ << tmp) >> 16); 46 | *wptr++ = *acfptr; 47 | *pptr++ = *acfptr++; 48 | } 49 | 50 | // Compute reflection coefficients. 51 | for (n = 1; n <= use_order; n++, K++) 52 | { 53 | tmp = WEBRTC_SPL_ABS_W16(*p1ptr); 54 | if (*P < tmp) 55 | { 56 | for (i = n; i <= use_order; i++) 57 | *K++ = 0; 58 | 59 | return; 60 | } 61 | 62 | // Division: WebRtcSpl_div(tmp, *P) 63 | *K = 0; 64 | if (tmp != 0) 65 | { 66 | L_num = tmp; 67 | L_den = *P; 68 | i = 15; 69 | while (i--) 70 | { 71 | (*K) <<= 1; 72 | L_num <<= 1; 73 | if (L_num >= L_den) 74 | { 75 | L_num -= L_den; 76 | (*K)++; 77 | } 78 | } 79 | if (*p1ptr > 0) 80 | *K = -*K; 81 | } 82 | 83 | // Last iteration; don't do Schur recursion. 84 | if (n == use_order) 85 | return; 86 | 87 | // Schur recursion. 88 | pptr = P; 89 | wptr = w1ptr; 90 | tmp = (int16_t)(((int32_t)*p1ptr * (int32_t)*K + 16384) >> 15); 91 | *pptr = WebRtcSpl_AddSatW16(*pptr, tmp); 92 | pptr++; 93 | for (i = 1; i <= use_order - n; i++) 94 | { 95 | tmp = (int16_t)(((int32_t)*wptr * (int32_t)*K + 16384) >> 15); 96 | *pptr = WebRtcSpl_AddSatW16(*(pptr + 1), tmp); 97 | pptr++; 98 | tmp = (int16_t)(((int32_t)*pptr * (int32_t)*K + 16384) >> 15); 99 | *wptr = WebRtcSpl_AddSatW16(*wptr, tmp); 100 | wptr++; 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/spl_sqrt_floor_arm.S: -------------------------------------------------------------------------------- 1 | @ 2 | @ Written by Wilco Dijkstra, 1996. The following email exchange establishes the 3 | @ license. 4 | @ 5 | @ From: Wilco Dijkstra 6 | @ Date: Fri, Jun 24, 2011 at 3:20 AM 7 | @ Subject: Re: sqrt routine 8 | @ To: Kevin Ma 9 | @ Hi Kevin, 10 | @ Thanks for asking. Those routines are public domain (originally posted to 11 | @ comp.sys.arm a long time ago), so you can use them freely for any purpose. 12 | @ Cheers, 13 | @ Wilco 14 | @ 15 | @ ----- Original Message ----- 16 | @ From: "Kevin Ma" 17 | @ To: 18 | @ Sent: Thursday, June 23, 2011 11:44 PM 19 | @ Subject: Fwd: sqrt routine 20 | @ Hi Wilco, 21 | @ I saw your sqrt routine from several web sites, including 22 | @ http://www.finesse.demon.co.uk/steven/sqrt.html. 23 | @ Just wonder if there's any copyright information with your Successive 24 | @ approximation routines, or if I can freely use it for any purpose. 25 | @ Thanks. 26 | @ Kevin 27 | 28 | @ Minor modifications in code style for WebRTC, 2012. 29 | @ Output is bit-exact with the reference C code in spl_sqrt_floor.c. 30 | 31 | @ Input : r0 32 bit unsigned integer 32 | @ Output: r0 = INT (SQRT (r0)), precision is 16 bits 33 | @ Registers touched: r1, r2 34 | 35 | #include "webrtc/system_wrappers/interface/asm_defines.h" 36 | 37 | GLOBAL_FUNCTION WebRtcSpl_SqrtFloor 38 | .align 2 39 | DEFINE_FUNCTION WebRtcSpl_SqrtFloor 40 | mov r1, #3 << 30 41 | mov r2, #1 << 30 42 | 43 | @ unroll for i = 0 .. 15 44 | 45 | cmp r0, r2, ror #2 * 0 46 | subhs r0, r0, r2, ror #2 * 0 47 | adc r2, r1, r2, lsl #1 48 | 49 | cmp r0, r2, ror #2 * 1 50 | subhs r0, r0, r2, ror #2 * 1 51 | adc r2, r1, r2, lsl #1 52 | 53 | cmp r0, r2, ror #2 * 2 54 | subhs r0, r0, r2, ror #2 * 2 55 | adc r2, r1, r2, lsl #1 56 | 57 | cmp r0, r2, ror #2 * 3 58 | subhs r0, r0, r2, ror #2 * 3 59 | adc r2, r1, r2, lsl #1 60 | 61 | cmp r0, r2, ror #2 * 4 62 | subhs r0, r0, r2, ror #2 * 4 63 | adc r2, r1, r2, lsl #1 64 | 65 | cmp r0, r2, ror #2 * 5 66 | subhs r0, r0, r2, ror #2 * 5 67 | adc r2, r1, r2, lsl #1 68 | 69 | cmp r0, r2, ror #2 * 6 70 | subhs r0, r0, r2, ror #2 * 6 71 | adc r2, r1, r2, lsl #1 72 | 73 | cmp r0, r2, ror #2 * 7 74 | subhs r0, r0, r2, ror #2 * 7 75 | adc r2, r1, r2, lsl #1 76 | 77 | cmp r0, r2, ror #2 * 8 78 | subhs r0, r0, r2, ror #2 * 8 79 | adc r2, r1, r2, lsl #1 80 | 81 | cmp r0, r2, ror #2 * 9 82 | subhs r0, r0, r2, ror #2 * 9 83 | adc r2, r1, r2, lsl #1 84 | 85 | cmp r0, r2, ror #2 * 10 86 | subhs r0, r0, r2, ror #2 * 10 87 | adc r2, r1, r2, lsl #1 88 | 89 | cmp r0, r2, ror #2 * 11 90 | subhs r0, r0, r2, ror #2 * 11 91 | adc r2, r1, r2, lsl #1 92 | 93 | cmp r0, r2, ror #2 * 12 94 | subhs r0, r0, r2, ror #2 * 12 95 | adc r2, r1, r2, lsl #1 96 | 97 | cmp r0, r2, ror #2 * 13 98 | subhs r0, r0, r2, ror #2 * 13 99 | adc r2, r1, r2, lsl #1 100 | 101 | cmp r0, r2, ror #2 * 14 102 | subhs r0, r0, r2, ror #2 * 14 103 | adc r2, r1, r2, lsl #1 104 | 105 | cmp r0, r2, ror #2 * 15 106 | subhs r0, r0, r2, ror #2 * 15 107 | adc r2, r1, r2, lsl #1 108 | 109 | bic r0, r2, #3 << 30 @ for rounding add: cmp r0, r2 adc r2, #1 110 | bx lr 111 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/get_hanning_window.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | /* 13 | * This file contains the function WebRtcSpl_GetHanningWindow(). 14 | * The description header can be found in signal_processing_library.h 15 | * 16 | */ 17 | 18 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 19 | 20 | // Hanning table with 256 entries 21 | static const int16_t kHanningTable[] = { 22 | 1, 2, 6, 10, 15, 22, 30, 39, 23 | 50, 62, 75, 89, 104, 121, 138, 157, 24 | 178, 199, 222, 246, 271, 297, 324, 353, 25 | 383, 413, 446, 479, 513, 549, 586, 624, 26 | 663, 703, 744, 787, 830, 875, 920, 967, 27 | 1015, 1064, 1114, 1165, 1218, 1271, 1325, 1381, 28 | 1437, 1494, 1553, 1612, 1673, 1734, 1796, 1859, 29 | 1924, 1989, 2055, 2122, 2190, 2259, 2329, 2399, 30 | 2471, 2543, 2617, 2691, 2765, 2841, 2918, 2995, 31 | 3073, 3152, 3232, 3312, 3393, 3475, 3558, 3641, 32 | 3725, 3809, 3895, 3980, 4067, 4154, 4242, 4330, 33 | 4419, 4509, 4599, 4689, 4781, 4872, 4964, 5057, 34 | 5150, 5244, 5338, 5432, 5527, 5622, 5718, 5814, 35 | 5910, 6007, 6104, 6202, 6299, 6397, 6495, 6594, 36 | 6693, 6791, 6891, 6990, 7090, 7189, 7289, 7389, 37 | 7489, 7589, 7690, 7790, 7890, 7991, 8091, 8192, 38 | 8293, 8393, 8494, 8594, 8694, 8795, 8895, 8995, 39 | 9095, 9195, 9294, 9394, 9493, 9593, 9691, 9790, 40 | 9889, 9987, 10085, 10182, 10280, 10377, 10474, 10570, 41 | 10666, 10762, 10857, 10952, 11046, 11140, 11234, 11327, 42 | 11420, 11512, 11603, 11695, 11785, 11875, 11965, 12054, 43 | 12142, 12230, 12317, 12404, 12489, 12575, 12659, 12743, 44 | 12826, 12909, 12991, 13072, 13152, 13232, 13311, 13389, 45 | 13466, 13543, 13619, 13693, 13767, 13841, 13913, 13985, 46 | 14055, 14125, 14194, 14262, 14329, 14395, 14460, 14525, 47 | 14588, 14650, 14711, 14772, 14831, 14890, 14947, 15003, 48 | 15059, 15113, 15166, 15219, 15270, 15320, 15369, 15417, 49 | 15464, 15509, 15554, 15597, 15640, 15681, 15721, 15760, 50 | 15798, 15835, 15871, 15905, 15938, 15971, 16001, 16031, 51 | 16060, 16087, 16113, 16138, 16162, 16185, 16206, 16227, 52 | 16246, 16263, 16280, 16295, 16309, 16322, 16334, 16345, 53 | 16354, 16362, 16369, 16374, 16378, 16382, 16383, 16384 54 | }; 55 | 56 | void WebRtcSpl_GetHanningWindow(int16_t *v, size_t size) 57 | { 58 | size_t jj; 59 | int16_t *vptr1; 60 | 61 | int32_t index; 62 | int32_t factor = ((int32_t)0x40000000); 63 | 64 | factor = WebRtcSpl_DivW32W16(factor, (int16_t)size); 65 | if (size < 513) 66 | index = (int32_t)-0x200000; 67 | else 68 | index = (int32_t)-0x100000; 69 | vptr1 = v; 70 | 71 | for (jj = 0; jj < size; jj++) 72 | { 73 | index += factor; 74 | (*vptr1++) = kHanningTable[index >> 22]; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/cross_correlation_neon.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 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 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 12 | 13 | #include 14 | 15 | static inline void DotProductWithScaleNeon(int32_t* cross_correlation, 16 | const int16_t* vector1, 17 | const int16_t* vector2, 18 | size_t length, 19 | int scaling) { 20 | size_t i = 0; 21 | size_t len1 = length >> 3; 22 | size_t len2 = length & 7; 23 | int64x2_t sum0 = vdupq_n_s64(0); 24 | int64x2_t sum1 = vdupq_n_s64(0); 25 | 26 | for (i = len1; i > 0; i -= 1) { 27 | int16x8_t seq1_16x8 = vld1q_s16(vector1); 28 | int16x8_t seq2_16x8 = vld1q_s16(vector2); 29 | #if defined(WEBRTC_ARCH_ARM64) 30 | int32x4_t tmp0 = vmull_s16(vget_low_s16(seq1_16x8), 31 | vget_low_s16(seq2_16x8)); 32 | int32x4_t tmp1 = vmull_high_s16(seq1_16x8, seq2_16x8); 33 | #else 34 | int32x4_t tmp0 = vmull_s16(vget_low_s16(seq1_16x8), 35 | vget_low_s16(seq2_16x8)); 36 | int32x4_t tmp1 = vmull_s16(vget_high_s16(seq1_16x8), 37 | vget_high_s16(seq2_16x8)); 38 | #endif 39 | sum0 = vpadalq_s32(sum0, tmp0); 40 | sum1 = vpadalq_s32(sum1, tmp1); 41 | vector1 += 8; 42 | vector2 += 8; 43 | } 44 | 45 | // Calculate the rest of the samples. 46 | int64_t sum_res = 0; 47 | for (i = len2; i > 0; i -= 1) { 48 | sum_res += WEBRTC_SPL_MUL_16_16(*vector1, *vector2); 49 | vector1++; 50 | vector2++; 51 | } 52 | 53 | sum0 = vaddq_s64(sum0, sum1); 54 | #if defined(WEBRTC_ARCH_ARM64) 55 | int64_t sum2 = vaddvq_s64(sum0); 56 | *cross_correlation = (int32_t)((sum2 + sum_res) >> scaling); 57 | #else 58 | int64x1_t shift = vdup_n_s64(-scaling); 59 | int64x1_t sum2 = vadd_s64(vget_low_s64(sum0), vget_high_s64(sum0)); 60 | sum2 = vadd_s64(sum2, vdup_n_s64(sum_res)); 61 | sum2 = vshl_s64(sum2, shift); 62 | vst1_lane_s32(cross_correlation, vreinterpret_s32_s64(sum2), 0); 63 | #endif 64 | } 65 | 66 | /* NEON version of WebRtcSpl_CrossCorrelation() for ARM32/64 platforms. */ 67 | void WebRtcSpl_CrossCorrelationNeon(int32_t* cross_correlation, 68 | const int16_t* seq1, 69 | const int16_t* seq2, 70 | size_t dim_seq, 71 | size_t dim_cross_correlation, 72 | int right_shifts, 73 | int step_seq2) { 74 | size_t i = 0; 75 | 76 | for (i = 0; i < dim_cross_correlation; i++) { 77 | const int16_t* seq1_ptr = seq1; 78 | const int16_t* seq2_ptr = seq2 + (step_seq2 * i); 79 | 80 | DotProductWithScaleNeon(cross_correlation, 81 | seq1_ptr, 82 | seq2_ptr, 83 | dim_seq, 84 | right_shifts); 85 | cross_correlation++; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/logging/aec_logging.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 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 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_LOGGING_ 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_LOGGING_ 13 | 14 | #include 15 | 16 | #include "webrtc/modules/audio_processing/logging/aec_logging_file_handling.h" 17 | 18 | // To enable AEC logging, invoke GYP with -Daec_debug_dump=1. 19 | #ifdef WEBRTC_AEC_DEBUG_DUMP 20 | // Dumps a wav data to file. 21 | #define RTC_AEC_DEBUG_WAV_WRITE(file, data, num_samples) \ 22 | do { \ 23 | rtc_WavWriteSamples(file, data, num_samples); \ 24 | } while (0) 25 | 26 | // (Re)opens a wav file for writing using the specified sample rate. 27 | #define RTC_AEC_DEBUG_WAV_REOPEN(name, instance_index, process_rate, \ 28 | sample_rate, wav_file) \ 29 | do { \ 30 | WebRtcAec_ReopenWav(name, instance_index, process_rate, sample_rate, \ 31 | wav_file); \ 32 | } while (0) 33 | 34 | // Closes a wav file. 35 | #define RTC_AEC_DEBUG_WAV_CLOSE(wav_file) \ 36 | do { \ 37 | rtc_WavClose(wav_file); \ 38 | } while (0) 39 | 40 | // Dumps a raw data to file. 41 | #define RTC_AEC_DEBUG_RAW_WRITE(file, data, data_size) \ 42 | do { \ 43 | (void) fwrite(data, data_size, 1, file); \ 44 | } while (0) 45 | 46 | // Opens a raw data file for writing using the specified sample rate. 47 | #define RTC_AEC_DEBUG_RAW_OPEN(name, instance_counter, file) \ 48 | do { \ 49 | WebRtcAec_RawFileOpen(name, instance_counter, file); \ 50 | } while (0) 51 | 52 | // Closes a raw data file. 53 | #define RTC_AEC_DEBUG_RAW_CLOSE(file) \ 54 | do { \ 55 | fclose(file); \ 56 | } while (0) 57 | 58 | #else // RTC_AEC_DEBUG_DUMP 59 | #define RTC_AEC_DEBUG_WAV_WRITE(file, data, num_samples) \ 60 | do { \ 61 | } while (0) 62 | 63 | #define RTC_AEC_DEBUG_WAV_REOPEN(wav_file, name, instance_index, process_rate, \ 64 | sample_rate) \ 65 | do { \ 66 | } while (0) 67 | 68 | #define RTC_AEC_DEBUG_WAV_CLOSE(wav_file) \ 69 | do { \ 70 | } while (0) 71 | 72 | #define RTC_AEC_DEBUG_RAW_WRITE(file, data, data_size) \ 73 | do { \ 74 | } while (0) 75 | 76 | #define RTC_AEC_DEBUG_RAW_OPEN(file, name, instance_counter) \ 77 | do { \ 78 | } while (0) 79 | 80 | #define RTC_AEC_DEBUG_RAW_CLOSE(file) \ 81 | do { \ 82 | } while (0) 83 | 84 | #endif // WEBRTC_AEC_DEBUG_DUMP 85 | 86 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_LOGGING_ 87 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/real_fft.c: -------------------------------------------------------------------------------- 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 | #include "webrtc/common_audio/signal_processing/include/real_fft.h" 12 | 13 | #include 14 | 15 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 16 | 17 | struct RealFFT { 18 | int order; 19 | }; 20 | 21 | struct RealFFT* WebRtcSpl_CreateRealFFT(int order) { 22 | struct RealFFT* self = NULL; 23 | 24 | if (order > kMaxFFTOrder || order < 0) { 25 | return NULL; 26 | } 27 | 28 | self = malloc(sizeof(struct RealFFT)); 29 | if (self == NULL) { 30 | return NULL; 31 | } 32 | self->order = order; 33 | 34 | return self; 35 | } 36 | 37 | void WebRtcSpl_FreeRealFFT(struct RealFFT* self) { 38 | if (self != NULL) { 39 | free(self); 40 | } 41 | } 42 | 43 | // The C version FFT functions (i.e. WebRtcSpl_RealForwardFFT and 44 | // WebRtcSpl_RealInverseFFT) are real-valued FFT wrappers for complex-valued 45 | // FFT implementation in SPL. 46 | 47 | int WebRtcSpl_RealForwardFFT(struct RealFFT* self, 48 | const int16_t* real_data_in, 49 | int16_t* complex_data_out) { 50 | int i = 0; 51 | int j = 0; 52 | int result = 0; 53 | int n = 1 << self->order; 54 | // The complex-value FFT implementation needs a buffer to hold 2^order 55 | // 16-bit COMPLEX numbers, for both time and frequency data. 56 | int16_t complex_buffer[2 << kMaxFFTOrder]; 57 | 58 | // Insert zeros to the imaginary parts for complex forward FFT input. 59 | for (i = 0, j = 0; i < n; i += 1, j += 2) { 60 | complex_buffer[j] = real_data_in[i]; 61 | complex_buffer[j + 1] = 0; 62 | }; 63 | 64 | WebRtcSpl_ComplexBitReverse(complex_buffer, self->order); 65 | result = WebRtcSpl_ComplexFFT(complex_buffer, self->order, 1); 66 | 67 | // For real FFT output, use only the first N + 2 elements from 68 | // complex forward FFT. 69 | memcpy(complex_data_out, complex_buffer, sizeof(int16_t) * (n + 2)); 70 | 71 | return result; 72 | } 73 | 74 | int WebRtcSpl_RealInverseFFT(struct RealFFT* self, 75 | const int16_t* complex_data_in, 76 | int16_t* real_data_out) { 77 | int i = 0; 78 | int j = 0; 79 | int result = 0; 80 | int n = 1 << self->order; 81 | // Create the buffer specific to complex-valued FFT implementation. 82 | int16_t complex_buffer[2 << kMaxFFTOrder]; 83 | 84 | // For n-point FFT, first copy the first n + 2 elements into complex 85 | // FFT, then construct the remaining n - 2 elements by real FFT's 86 | // conjugate-symmetric properties. 87 | memcpy(complex_buffer, complex_data_in, sizeof(int16_t) * (n + 2)); 88 | for (i = n + 2; i < 2 * n; i += 2) { 89 | complex_buffer[i] = complex_data_in[2 * n - i]; 90 | complex_buffer[i + 1] = -complex_data_in[2 * n - i + 1]; 91 | } 92 | 93 | WebRtcSpl_ComplexBitReverse(complex_buffer, self->order); 94 | result = WebRtcSpl_ComplexIFFT(complex_buffer, self->order, 1); 95 | 96 | // Strip out the imaginary parts of the complex inverse FFT output. 97 | for (i = 0, j = 0; i < n; i += 1, j += 2) { 98 | real_data_out[i] = complex_buffer[j]; 99 | } 100 | 101 | return result; 102 | } 103 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/ns/nsx_defines.h: -------------------------------------------------------------------------------- 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 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_NSX_DEFINES_H_ 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_NSX_DEFINES_H_ 13 | 14 | #define ANAL_BLOCKL_MAX 256 /* Max analysis block length */ 15 | #define HALF_ANAL_BLOCKL 129 /* Half max analysis block length + 1 */ 16 | #define NUM_HIGH_BANDS_MAX 2 /* Max number of high bands */ 17 | #define SIMULT 3 18 | #define END_STARTUP_LONG 200 19 | #define END_STARTUP_SHORT 50 20 | #define FACTOR_Q16 2621440 /* 40 in Q16 */ 21 | #define FACTOR_Q7 5120 /* 40 in Q7 */ 22 | #define FACTOR_Q7_STARTUP 1024 /* 8 in Q7 */ 23 | #define WIDTH_Q8 3 /* 0.01 in Q8 (or 25 ) */ 24 | 25 | /* PARAMETERS FOR NEW METHOD */ 26 | #define DD_PR_SNR_Q11 2007 /* ~= Q11(0.98) DD update of prior SNR */ 27 | #define ONE_MINUS_DD_PR_SNR_Q11 41 /* DD update of prior SNR */ 28 | #define SPECT_FLAT_TAVG_Q14 4915 /* (0.30) tavg parameter for spectral flatness measure */ 29 | #define SPECT_DIFF_TAVG_Q8 77 /* (0.30) tavg parameter for spectral flatness measure */ 30 | #define PRIOR_UPDATE_Q14 1638 /* Q14(0.1) Update parameter of prior model */ 31 | #define NOISE_UPDATE_Q8 26 /* 26 ~= Q8(0.1) Update parameter for noise */ 32 | 33 | /* Probability threshold for noise state in speech/noise likelihood. */ 34 | #define ONE_MINUS_PROB_RANGE_Q8 205 /* 205 ~= Q8(0.8) */ 35 | #define HIST_PAR_EST 1000 /* Histogram size for estimation of parameters */ 36 | 37 | /* FEATURE EXTRACTION CONFIG */ 38 | /* Bin size of histogram */ 39 | #define BIN_SIZE_LRT 10 40 | /* Scale parameters: multiply dominant peaks of the histograms by scale factor to obtain. */ 41 | /* Thresholds for prior model */ 42 | #define FACTOR_1_LRT_DIFF 6 /* For LRT and spectral difference (5 times bigger) */ 43 | /* For spectral_flatness: used when noise is flatter than speech (10 times bigger). */ 44 | #define FACTOR_2_FLAT_Q10 922 45 | /* Peak limit for spectral flatness (varies between 0 and 1) */ 46 | #define THRES_PEAK_FLAT 24 /* * 2 * BIN_SIZE_FLAT_FX */ 47 | /* Limit on spacing of two highest peaks in histogram: spacing determined by bin size. */ 48 | #define LIM_PEAK_SPACE_FLAT_DIFF 4 /* * 2 * BIN_SIZE_DIFF_FX */ 49 | /* Limit on relevance of second peak */ 50 | #define LIM_PEAK_WEIGHT_FLAT_DIFF 2 51 | #define THRES_FLUCT_LRT 10240 /* = 20 * inst->modelUpdate; fluctuation limit of LRT feat. */ 52 | /* Limit on the max and min values for the feature thresholds */ 53 | #define MAX_FLAT_Q10 38912 /* * 2 * BIN_SIZE_FLAT_FX */ 54 | #define MIN_FLAT_Q10 4096 /* * 2 * BIN_SIZE_FLAT_FX */ 55 | #define MAX_DIFF 100 /* * 2 * BIN_SIZE_DIFF_FX */ 56 | #define MIN_DIFF 16 /* * 2 * BIN_SIZE_DIFF_FX */ 57 | /* Criteria of weight of histogram peak to accept/reject feature */ 58 | #define THRES_WEIGHT_FLAT_DIFF 154 /*(int)(0.3*(inst->modelUpdate)) for flatness and difference */ 59 | 60 | #define STAT_UPDATES 9 /* Update every 512 = 1 << 9 block */ 61 | #define ONE_MINUS_GAMMA_PAUSE_Q8 13 /* ~= Q8(0.05) Update for conservative noise estimate */ 62 | #define GAMMA_NOISE_TRANS_AND_SPEECH_Q8 3 /* ~= Q8(0.01) Update for transition and noise region */ 63 | 64 | #endif /* WEBRTC_MODULES_AUDIO_PROCESSING_NS_MAIN_SOURCE_NSX_DEFINES_H_ */ 65 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/ns/include/noise_suppression.h: -------------------------------------------------------------------------------- 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 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_NS_INCLUDE_NOISE_SUPPRESSION_H_ 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_NS_INCLUDE_NOISE_SUPPRESSION_H_ 13 | 14 | #include 15 | 16 | #include "webrtc/typedefs.h" 17 | 18 | typedef struct NsHandleT NsHandle; 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /* 25 | * This function creates an instance of the floating point Noise Suppression. 26 | */ 27 | NsHandle* WebRtcNs_Create(); 28 | 29 | /* 30 | * This function frees the dynamic memory of a specified noise suppression 31 | * instance. 32 | * 33 | * Input: 34 | * - NS_inst : Pointer to NS instance that should be freed 35 | */ 36 | void WebRtcNs_Free(NsHandle* NS_inst); 37 | 38 | /* 39 | * This function initializes a NS instance and has to be called before any other 40 | * processing is made. 41 | * 42 | * Input: 43 | * - NS_inst : Instance that should be initialized 44 | * - fs : sampling frequency 45 | * 46 | * Output: 47 | * - NS_inst : Initialized instance 48 | * 49 | * Return value : 0 - Ok 50 | * -1 - Error 51 | */ 52 | int WebRtcNs_Init(NsHandle* NS_inst, uint32_t fs); 53 | 54 | /* 55 | * This changes the aggressiveness of the noise suppression method. 56 | * 57 | * Input: 58 | * - NS_inst : Noise suppression instance. 59 | * - mode : 0: Mild, 1: Medium , 2: Aggressive 60 | * 61 | * Output: 62 | * - NS_inst : Updated instance. 63 | * 64 | * Return value : 0 - Ok 65 | * -1 - Error 66 | */ 67 | int WebRtcNs_set_policy(NsHandle* NS_inst, int mode); 68 | 69 | /* 70 | * This functions estimates the background noise for the inserted speech frame. 71 | * The input and output signals should always be 10ms (80 or 160 samples). 72 | * 73 | * Input 74 | * - NS_inst : Noise suppression instance. 75 | * - spframe : Pointer to speech frame buffer for L band 76 | * 77 | * Output: 78 | * - NS_inst : Updated NS instance 79 | */ 80 | void WebRtcNs_Analyze(NsHandle* NS_inst, const float* spframe); 81 | 82 | /* 83 | * This functions does Noise Suppression for the inserted speech frame. The 84 | * input and output signals should always be 10ms (80 or 160 samples). 85 | * 86 | * Input 87 | * - NS_inst : Noise suppression instance. 88 | * - spframe : Pointer to speech frame buffer for each band 89 | * - num_bands : Number of bands 90 | * 91 | * Output: 92 | * - NS_inst : Updated NS instance 93 | * - outframe : Pointer to output frame for each band 94 | */ 95 | void WebRtcNs_Process(NsHandle* NS_inst, 96 | const float* const* spframe, 97 | size_t num_bands, 98 | float* const* outframe); 99 | 100 | /* Returns the internally used prior speech probability of the current frame. 101 | * There is a frequency bin based one as well, with which this should not be 102 | * confused. 103 | * 104 | * Input 105 | * - handle : Noise suppression instance. 106 | * 107 | * Return value : Prior speech probability in interval [0.0, 1.0]. 108 | * -1 - NULL pointer or uninitialized instance. 109 | */ 110 | float WebRtcNs_prior_speech_probability(NsHandle* handle); 111 | 112 | #ifdef __cplusplus 113 | } 114 | #endif 115 | 116 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_NS_INCLUDE_NOISE_SUPPRESSION_H_ 117 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/include/spl_inl_armv7.h: -------------------------------------------------------------------------------- 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 the inline functions for ARM processors in 13 | * the fix point signal processing library. 14 | */ 15 | 16 | #ifndef WEBRTC_SPL_SPL_INL_ARMV7_H_ 17 | #define WEBRTC_SPL_SPL_INL_ARMV7_H_ 18 | 19 | /* TODO(kma): Replace some assembly code with GCC intrinsics 20 | * (e.g. __builtin_clz). 21 | */ 22 | 23 | /* This function produces result that is not bit exact with that by the generic 24 | * C version in some cases, although the former is at least as accurate as the 25 | * later. 26 | */ 27 | static __inline int32_t WEBRTC_SPL_MUL_16_32_RSFT16(int16_t a, int32_t b) { 28 | int32_t tmp = 0; 29 | __asm __volatile ("smulwb %0, %1, %2":"=r"(tmp):"r"(b), "r"(a)); 30 | return tmp; 31 | } 32 | 33 | static __inline int32_t WEBRTC_SPL_MUL_16_16(int16_t a, int16_t b) { 34 | int32_t tmp = 0; 35 | __asm __volatile ("smulbb %0, %1, %2":"=r"(tmp):"r"(a), "r"(b)); 36 | return tmp; 37 | } 38 | 39 | // TODO(kma): add unit test. 40 | static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) { 41 | int32_t tmp = 0; 42 | __asm __volatile ("smlabb %0, %1, %2, %3":"=r"(tmp):"r"(a), "r"(b), "r"(c)); 43 | return tmp; 44 | } 45 | 46 | static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) { 47 | int32_t s_sum = 0; 48 | 49 | __asm __volatile ("qadd16 %0, %1, %2":"=r"(s_sum):"r"(a), "r"(b)); 50 | 51 | return (int16_t) s_sum; 52 | } 53 | 54 | static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) { 55 | int32_t l_sum = 0; 56 | 57 | __asm __volatile ("qadd %0, %1, %2":"=r"(l_sum):"r"(l_var1), "r"(l_var2)); 58 | 59 | return l_sum; 60 | } 61 | 62 | static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) { 63 | int32_t l_sub = 0; 64 | 65 | __asm __volatile ("qsub %0, %1, %2":"=r"(l_sub):"r"(l_var1), "r"(l_var2)); 66 | 67 | return l_sub; 68 | } 69 | 70 | static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) { 71 | int32_t s_sub = 0; 72 | 73 | __asm __volatile ("qsub16 %0, %1, %2":"=r"(s_sub):"r"(var1), "r"(var2)); 74 | 75 | return (int16_t)s_sub; 76 | } 77 | 78 | static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) { 79 | int32_t tmp = 0; 80 | 81 | __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(n)); 82 | 83 | return (int16_t)(32 - tmp); 84 | } 85 | 86 | static __inline int16_t WebRtcSpl_NormW32(int32_t a) { 87 | int32_t tmp = 0; 88 | 89 | if (a == 0) { 90 | return 0; 91 | } 92 | else if (a < 0) { 93 | a ^= 0xFFFFFFFF; 94 | } 95 | 96 | __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(a)); 97 | 98 | return (int16_t)(tmp - 1); 99 | } 100 | 101 | static __inline int16_t WebRtcSpl_NormU32(uint32_t a) { 102 | int tmp = 0; 103 | 104 | if (a == 0) return 0; 105 | 106 | __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(a)); 107 | 108 | return (int16_t)tmp; 109 | } 110 | 111 | static __inline int16_t WebRtcSpl_NormW16(int16_t a) { 112 | int32_t tmp = 0; 113 | int32_t a_32 = a; 114 | 115 | if (a_32 == 0) { 116 | return 0; 117 | } 118 | else if (a_32 < 0) { 119 | a_32 ^= 0xFFFFFFFF; 120 | } 121 | 122 | __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(a_32)); 123 | 124 | return (int16_t)(tmp - 17); 125 | } 126 | 127 | // TODO(kma): add unit test. 128 | static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) { 129 | int32_t out = 0; 130 | 131 | __asm __volatile ("ssat %0, #16, %1" : "=r"(out) : "r"(value32)); 132 | 133 | return (int16_t)out; 134 | } 135 | 136 | #endif // WEBRTC_SPL_SPL_INL_ARMV7_H_ 137 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/division_operations.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | /* 13 | * This file contains implementations of the divisions 14 | * WebRtcSpl_DivU32U16() 15 | * WebRtcSpl_DivW32W16() 16 | * WebRtcSpl_DivW32W16ResW16() 17 | * WebRtcSpl_DivResultInQ31() 18 | * WebRtcSpl_DivW32HiLow() 19 | * 20 | * The description header can be found in signal_processing_library.h 21 | * 22 | */ 23 | 24 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 25 | 26 | uint32_t WebRtcSpl_DivU32U16(uint32_t num, uint16_t den) 27 | { 28 | // Guard against division with 0 29 | if (den != 0) 30 | { 31 | return (uint32_t)(num / den); 32 | } else 33 | { 34 | return (uint32_t)0xFFFFFFFF; 35 | } 36 | } 37 | 38 | int32_t WebRtcSpl_DivW32W16(int32_t num, int16_t den) 39 | { 40 | // Guard against division with 0 41 | if (den != 0) 42 | { 43 | return (int32_t)(num / den); 44 | } else 45 | { 46 | return (int32_t)0x7FFFFFFF; 47 | } 48 | } 49 | 50 | int16_t WebRtcSpl_DivW32W16ResW16(int32_t num, int16_t den) 51 | { 52 | // Guard against division with 0 53 | if (den != 0) 54 | { 55 | return (int16_t)(num / den); 56 | } else 57 | { 58 | return (int16_t)0x7FFF; 59 | } 60 | } 61 | 62 | int32_t WebRtcSpl_DivResultInQ31(int32_t num, int32_t den) 63 | { 64 | int32_t L_num = num; 65 | int32_t L_den = den; 66 | int32_t div = 0; 67 | int k = 31; 68 | int change_sign = 0; 69 | 70 | if (num == 0) 71 | return 0; 72 | 73 | if (num < 0) 74 | { 75 | change_sign++; 76 | L_num = -num; 77 | } 78 | if (den < 0) 79 | { 80 | change_sign++; 81 | L_den = -den; 82 | } 83 | while (k--) 84 | { 85 | div <<= 1; 86 | L_num <<= 1; 87 | if (L_num >= L_den) 88 | { 89 | L_num -= L_den; 90 | div++; 91 | } 92 | } 93 | if (change_sign == 1) 94 | { 95 | div = -div; 96 | } 97 | return div; 98 | } 99 | 100 | int32_t WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low) 101 | { 102 | int16_t approx, tmp_hi, tmp_low, num_hi, num_low; 103 | int32_t tmpW32; 104 | 105 | approx = (int16_t)WebRtcSpl_DivW32W16((int32_t)0x1FFFFFFF, den_hi); 106 | // result in Q14 (Note: 3FFFFFFF = 0.5 in Q30) 107 | 108 | // tmpW32 = 1/den = approx * (2.0 - den * approx) (in Q30) 109 | tmpW32 = (den_hi * approx << 1) + ((den_low * approx >> 15) << 1); 110 | // tmpW32 = den * approx 111 | 112 | tmpW32 = (int32_t)0x7fffffffL - tmpW32; // result in Q30 (tmpW32 = 2.0-(den*approx)) 113 | 114 | // Store tmpW32 in hi and low format 115 | tmp_hi = (int16_t)(tmpW32 >> 16); 116 | tmp_low = (int16_t)((tmpW32 - ((int32_t)tmp_hi << 16)) >> 1); 117 | 118 | // tmpW32 = 1/den in Q29 119 | tmpW32 = (tmp_hi * approx + (tmp_low * approx >> 15)) << 1; 120 | 121 | // 1/den in hi and low format 122 | tmp_hi = (int16_t)(tmpW32 >> 16); 123 | tmp_low = (int16_t)((tmpW32 - ((int32_t)tmp_hi << 16)) >> 1); 124 | 125 | // Store num in hi and low format 126 | num_hi = (int16_t)(num >> 16); 127 | num_low = (int16_t)((num - ((int32_t)num_hi << 16)) >> 1); 128 | 129 | // num * (1/den) by 32 bit multiplication (result in Q28) 130 | 131 | tmpW32 = num_hi * tmp_hi + (num_hi * tmp_low >> 15) + 132 | (num_low * tmp_hi >> 15); 133 | 134 | // Put result in Q31 (convert from Q28) 135 | tmpW32 = WEBRTC_SPL_LSHIFT_W32(tmpW32, 3); 136 | 137 | return tmpW32; 138 | } 139 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/wav_file.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 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 | #ifndef WEBRTC_COMMON_AUDIO_WAV_FILE_H_ 12 | #define WEBRTC_COMMON_AUDIO_WAV_FILE_H_ 13 | 14 | #ifdef __cplusplus 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #include "webrtc/base/constructormagic.h" 21 | 22 | namespace webrtc { 23 | 24 | // Interface to provide access to WAV file parameters. 25 | class WavFile { 26 | public: 27 | virtual ~WavFile() {} 28 | 29 | virtual int sample_rate() const = 0; 30 | virtual int num_channels() const = 0; 31 | virtual uint32_t num_samples() const = 0; 32 | }; 33 | 34 | // Simple C++ class for writing 16-bit PCM WAV files. All error handling is 35 | // by calls to RTC_CHECK(), making it unsuitable for anything but debug code. 36 | class WavWriter final : public WavFile { 37 | public: 38 | // Open a new WAV file for writing. 39 | WavWriter(const std::string& filename, int sample_rate, int num_channels); 40 | 41 | // Close the WAV file, after writing its header. 42 | ~WavWriter(); 43 | 44 | // Write additional samples to the file. Each sample is in the range 45 | // [-32768,32767], and there must be the previously specified number of 46 | // interleaved channels. 47 | void WriteSamples(const float* samples, size_t num_samples); 48 | void WriteSamples(const int16_t* samples, size_t num_samples); 49 | 50 | int sample_rate() const override { return sample_rate_; } 51 | int num_channels() const override { return num_channels_; } 52 | uint32_t num_samples() const override { return num_samples_; } 53 | 54 | private: 55 | void Close(); 56 | const int sample_rate_; 57 | const int num_channels_; 58 | uint32_t num_samples_; // Total number of samples written to file. 59 | FILE* file_handle_; // Output file, owned by this class 60 | 61 | RTC_DISALLOW_COPY_AND_ASSIGN(WavWriter); 62 | }; 63 | 64 | // Follows the conventions of WavWriter. 65 | class WavReader final : public WavFile { 66 | public: 67 | // Opens an existing WAV file for reading. 68 | explicit WavReader(const std::string& filename); 69 | 70 | // Close the WAV file. 71 | ~WavReader(); 72 | 73 | // Returns the number of samples read. If this is less than requested, 74 | // verifies that the end of the file was reached. 75 | size_t ReadSamples(size_t num_samples, float* samples); 76 | size_t ReadSamples(size_t num_samples, int16_t* samples); 77 | 78 | int sample_rate() const override { return sample_rate_; } 79 | int num_channels() const override { return num_channels_; } 80 | uint32_t num_samples() const override { return num_samples_; } 81 | 82 | private: 83 | void Close(); 84 | int sample_rate_; 85 | int num_channels_; 86 | uint32_t num_samples_; // Total number of samples in the file. 87 | uint32_t num_samples_remaining_; 88 | FILE* file_handle_; // Input file, owned by this class. 89 | 90 | RTC_DISALLOW_COPY_AND_ASSIGN(WavReader); 91 | }; 92 | 93 | } // namespace webrtc 94 | 95 | extern "C" { 96 | #endif // __cplusplus 97 | 98 | // C wrappers for the WavWriter class. 99 | typedef struct rtc_WavWriter rtc_WavWriter; 100 | rtc_WavWriter* rtc_WavOpen(const char* filename, 101 | int sample_rate, 102 | int num_channels); 103 | void rtc_WavClose(rtc_WavWriter* wf); 104 | void rtc_WavWriteSamples(rtc_WavWriter* wf, 105 | const float* samples, 106 | size_t num_samples); 107 | int rtc_WavSampleRate(const rtc_WavWriter* wf); 108 | int rtc_WavNumChannels(const rtc_WavWriter* wf); 109 | uint32_t rtc_WavNumSamples(const rtc_WavWriter* wf); 110 | 111 | #ifdef __cplusplus 112 | } // extern "C" 113 | #endif 114 | 115 | #endif // WEBRTC_COMMON_AUDIO_WAV_FILE_H_ 116 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/real_fft_unittest.cc: -------------------------------------------------------------------------------- 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 | #include "webrtc/common_audio/signal_processing/include/real_fft.h" 12 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 13 | #include "webrtc/test/testsupport/gtest_disable.h" 14 | #include "webrtc/typedefs.h" 15 | 16 | #include "testing/gtest/include/gtest/gtest.h" 17 | 18 | namespace webrtc { 19 | namespace { 20 | 21 | // FFT order. 22 | const int kOrder = 5; 23 | // Lengths for real FFT's time and frequency bufffers. 24 | // For N-point FFT, the length requirements from API are N and N+2 respectively. 25 | const int kTimeDataLength = 1 << kOrder; 26 | const int kFreqDataLength = (1 << kOrder) + 2; 27 | // For complex FFT's time and freq buffer. The implementation requires 28 | // 2*N 16-bit words. 29 | const int kComplexFftDataLength = 2 << kOrder; 30 | // Reference data for time signal. 31 | const int16_t kRefData[kTimeDataLength] = { 32 | 11739, 6848, -8688, 31980, -30295, 25242, 27085, 19410, 33 | -26299, 15607, -10791, 11778, -23819, 14498, -25772, 10076, 34 | 1173, 6848, -8688, 31980, -30295, 2522, 27085, 19410, 35 | -2629, 5607, -3, 1178, -23819, 1498, -25772, 10076 36 | }; 37 | 38 | class RealFFTTest : public ::testing::Test { 39 | protected: 40 | RealFFTTest() { 41 | WebRtcSpl_Init(); 42 | } 43 | }; 44 | 45 | TEST_F(RealFFTTest, CreateFailsOnBadInput) { 46 | RealFFT* fft = WebRtcSpl_CreateRealFFT(11); 47 | EXPECT_TRUE(fft == NULL); 48 | fft = WebRtcSpl_CreateRealFFT(-1); 49 | EXPECT_TRUE(fft == NULL); 50 | } 51 | 52 | TEST_F(RealFFTTest, RealAndComplexMatch) { 53 | int i = 0; 54 | int j = 0; 55 | int16_t real_fft_time[kTimeDataLength] = {0}; 56 | int16_t real_fft_freq[kFreqDataLength] = {0}; 57 | // One common buffer for complex FFT's time and frequency data. 58 | int16_t complex_fft_buff[kComplexFftDataLength] = {0}; 59 | 60 | // Prepare the inputs to forward FFT's. 61 | memcpy(real_fft_time, kRefData, sizeof(kRefData)); 62 | for (i = 0, j = 0; i < kTimeDataLength; i += 1, j += 2) { 63 | complex_fft_buff[j] = kRefData[i]; 64 | complex_fft_buff[j + 1] = 0; // Insert zero's to imaginary parts. 65 | }; 66 | 67 | // Create and run real forward FFT. 68 | RealFFT* fft = WebRtcSpl_CreateRealFFT(kOrder); 69 | EXPECT_TRUE(fft != NULL); 70 | EXPECT_EQ(0, WebRtcSpl_RealForwardFFT(fft, real_fft_time, real_fft_freq)); 71 | 72 | // Run complex forward FFT. 73 | WebRtcSpl_ComplexBitReverse(complex_fft_buff, kOrder); 74 | EXPECT_EQ(0, WebRtcSpl_ComplexFFT(complex_fft_buff, kOrder, 1)); 75 | 76 | // Verify the results between complex and real forward FFT. 77 | for (i = 0; i < kFreqDataLength; i++) { 78 | EXPECT_EQ(real_fft_freq[i], complex_fft_buff[i]); 79 | } 80 | 81 | // Prepare the inputs to inverse real FFT. 82 | // We use whatever data in complex_fft_buff[] since we don't care 83 | // about data contents. Only kFreqDataLength 16-bit words are copied 84 | // from complex_fft_buff to real_fft_freq since remaining words (2nd half) 85 | // are conjugate-symmetric to the first half in theory. 86 | memcpy(real_fft_freq, complex_fft_buff, sizeof(real_fft_freq)); 87 | 88 | // Run real inverse FFT. 89 | int real_scale = WebRtcSpl_RealInverseFFT(fft, real_fft_freq, real_fft_time); 90 | EXPECT_GE(real_scale, 0); 91 | 92 | // Run complex inverse FFT. 93 | WebRtcSpl_ComplexBitReverse(complex_fft_buff, kOrder); 94 | int complex_scale = WebRtcSpl_ComplexIFFT(complex_fft_buff, kOrder, 1); 95 | 96 | // Verify the results between complex and real inverse FFT. 97 | // They are not bit-exact, since complex IFFT doesn't produce 98 | // exactly conjugate-symmetric data (between first and second half). 99 | EXPECT_EQ(real_scale, complex_scale); 100 | for (i = 0, j = 0; i < kTimeDataLength; i += 1, j += 2) { 101 | EXPECT_LE(abs(real_fft_time[i] - complex_fft_buff[j]), 1); 102 | } 103 | 104 | WebRtcSpl_FreeRealFFT(fft); 105 | } 106 | 107 | } // namespace 108 | } // namespace webrtc 109 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/typedefs.h: -------------------------------------------------------------------------------- 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 | // This file contains platform-specific typedefs and defines. 12 | // Much of it is derived from Chromium's build/build_config.h. 13 | 14 | #ifndef WEBRTC_TYPEDEFS_H_ 15 | #define WEBRTC_TYPEDEFS_H_ 16 | 17 | // Processor architecture detection. For more info on what's defined, see: 18 | // http://msdn.microsoft.com/en-us/library/b0084kay.aspx 19 | // http://www.agner.org/optimize/calling_conventions.pdf 20 | // or with gcc, run: "echo | gcc -E -dM -" 21 | #if defined(_M_X64) || defined(__x86_64__) 22 | #define WEBRTC_ARCH_X86_FAMILY 23 | #define WEBRTC_ARCH_X86_64 24 | #define WEBRTC_ARCH_64_BITS 25 | #define WEBRTC_ARCH_LITTLE_ENDIAN 26 | #elif defined(__aarch64__) 27 | #define WEBRTC_ARCH_64_BITS 28 | #define WEBRTC_ARCH_LITTLE_ENDIAN 29 | #elif defined(_M_IX86) || defined(__i386__) 30 | #define WEBRTC_ARCH_X86_FAMILY 31 | #define WEBRTC_ARCH_X86 32 | #define WEBRTC_ARCH_32_BITS 33 | #define WEBRTC_ARCH_LITTLE_ENDIAN 34 | #elif defined(__ARMEL__) 35 | // TODO(ajm): We'd prefer to control platform defines here, but this is 36 | // currently provided by the Android makefiles. Commented to avoid duplicate 37 | // definition warnings. 38 | //#define WEBRTC_ARCH_ARM 39 | // TODO(ajm): Chromium uses the following two defines. Should we switch? 40 | //#define WEBRTC_ARCH_ARM_FAMILY 41 | //#define WEBRTC_ARCH_ARMEL 42 | #define WEBRTC_ARCH_32_BITS 43 | #define WEBRTC_ARCH_LITTLE_ENDIAN 44 | #elif defined(__MIPSEL__) 45 | #define WEBRTC_ARCH_32_BITS 46 | #define WEBRTC_ARCH_LITTLE_ENDIAN 47 | #elif defined(__pnacl__) 48 | #define WEBRTC_ARCH_32_BITS 49 | #define WEBRTC_ARCH_LITTLE_ENDIAN 50 | #else 51 | #error Please add support for your architecture in typedefs.h 52 | #endif 53 | 54 | #if !(defined(WEBRTC_ARCH_LITTLE_ENDIAN) ^ defined(WEBRTC_ARCH_BIG_ENDIAN)) 55 | #error Define either WEBRTC_ARCH_LITTLE_ENDIAN or WEBRTC_ARCH_BIG_ENDIAN 56 | #endif 57 | 58 | // TODO(zhongwei.yao): WEBRTC_CPU_DETECTION is only used in one place; we should 59 | // probably just remove it. 60 | #if (defined(WEBRTC_ARCH_X86_FAMILY) && !defined(__SSE2__)) || \ 61 | defined(WEBRTC_DETECT_NEON) 62 | #define WEBRTC_CPU_DETECTION 63 | #endif 64 | 65 | #if !defined(_MSC_VER) 66 | #include 67 | #else 68 | // Define C99 equivalent types, since pre-2010 MSVC doesn't provide stdint.h. 69 | typedef signed char int8_t; 70 | typedef signed short int16_t; 71 | typedef signed int int32_t; 72 | typedef __int64 int64_t; 73 | typedef unsigned char uint8_t; 74 | typedef unsigned short uint16_t; 75 | typedef unsigned int uint32_t; 76 | typedef unsigned __int64 uint64_t; 77 | #endif 78 | 79 | // Annotate a function indicating the caller must examine the return value. 80 | // Use like: 81 | // int foo() WARN_UNUSED_RESULT; 82 | // TODO(ajm): Hack to avoid multiple definitions until the base/ of webrtc and 83 | // libjingle are merged. 84 | #if !defined(WARN_UNUSED_RESULT) 85 | #if defined(__GNUC__) 86 | #define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) 87 | #else 88 | #define WARN_UNUSED_RESULT 89 | #endif 90 | #endif // WARN_UNUSED_RESULT 91 | 92 | // Put after a variable that might not be used, to prevent compiler warnings: 93 | // int result ATTRIBUTE_UNUSED = DoSomething(); 94 | // assert(result == 17); 95 | #ifndef ATTRIBUTE_UNUSED 96 | #if defined(__GNUC__) || defined(__clang__) 97 | #define ATTRIBUTE_UNUSED __attribute__((unused)) 98 | #else 99 | #define ATTRIBUTE_UNUSED 100 | #endif 101 | #endif 102 | 103 | // Macro to be used for switch-case fallthrough (required for enabling 104 | // -Wimplicit-fallthrough warning on Clang). 105 | #ifndef FALLTHROUGH 106 | #if defined(__clang__) 107 | #define FALLTHROUGH() [[clang::fallthrough]] 108 | #else 109 | #define FALLTHROUGH() do { } while (0) 110 | #endif 111 | #endif 112 | 113 | // Annotate a function that will not return control flow to the caller. 114 | #if defined(_MSC_VER) 115 | #define NO_RETURN __declspec(noreturn) 116 | #elif defined(__GNUC__) 117 | #define NO_RETURN __attribute__((noreturn)) 118 | #else 119 | #define NO_RETURN 120 | #endif 121 | 122 | #endif // WEBRTC_TYPEDEFS_H_ 123 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/aecm/aecm_defines.h: -------------------------------------------------------------------------------- 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 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AECM_AECM_DEFINES_H_ 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_AECM_AECM_DEFINES_H_ 13 | 14 | #define AECM_DYNAMIC_Q /* Turn on/off dynamic Q-domain. */ 15 | 16 | /* Algorithm parameters */ 17 | #define FRAME_LEN 80 /* Total frame length, 10 ms. */ 18 | 19 | #define PART_LEN 64 /* Length of partition. */ 20 | #define PART_LEN_SHIFT 7 /* Length of (PART_LEN * 2) in base 2. */ 21 | 22 | #define PART_LEN1 (PART_LEN + 1) /* Unique fft coefficients. */ 23 | #define PART_LEN2 (PART_LEN << 1) /* Length of partition * 2. */ 24 | #define PART_LEN4 (PART_LEN << 2) /* Length of partition * 4. */ 25 | #define FAR_BUF_LEN PART_LEN4 /* Length of buffers. */ 26 | #define MAX_DELAY 100 27 | 28 | /* Counter parameters */ 29 | #define CONV_LEN 512 /* Convergence length used at startup. */ 30 | #define CONV_LEN2 (CONV_LEN << 1) /* Used at startup. */ 31 | 32 | /* Energy parameters */ 33 | #define MAX_BUF_LEN 64 /* History length of energy signals. */ 34 | #define FAR_ENERGY_MIN 1025 /* Lowest Far energy level: At least 2 */ 35 | /* in energy. */ 36 | #define FAR_ENERGY_DIFF 929 /* Allowed difference between max */ 37 | /* and min. */ 38 | #define ENERGY_DEV_OFFSET 0 /* The energy error offset in Q8. */ 39 | #define ENERGY_DEV_TOL 400 /* The energy estimation tolerance (Q8). */ 40 | #define FAR_ENERGY_VAD_REGION 230 /* Far VAD tolerance region. */ 41 | 42 | /* Stepsize parameters */ 43 | #define MU_MIN 10 /* Min stepsize 2^-MU_MIN (far end energy */ 44 | /* dependent). */ 45 | #define MU_MAX 1 /* Max stepsize 2^-MU_MAX (far end energy */ 46 | /* dependent). */ 47 | #define MU_DIFF 9 /* MU_MIN - MU_MAX */ 48 | 49 | /* Channel parameters */ 50 | #define MIN_MSE_COUNT 20 /* Min number of consecutive blocks with enough */ 51 | /* far end energy to compare channel estimates. */ 52 | #define MIN_MSE_DIFF 29 /* The ratio between adapted and stored channel to */ 53 | /* accept a new storage (0.8 in Q-MSE_RESOLUTION). */ 54 | #define MSE_RESOLUTION 5 /* MSE parameter resolution. */ 55 | #define RESOLUTION_CHANNEL16 12 /* W16 Channel in Q-RESOLUTION_CHANNEL16. */ 56 | #define RESOLUTION_CHANNEL32 28 /* W32 Channel in Q-RESOLUTION_CHANNEL. */ 57 | #define CHANNEL_VAD 16 /* Minimum energy in frequency band */ 58 | /* to update channel. */ 59 | 60 | /* Suppression gain parameters: SUPGAIN parameters in Q-(RESOLUTION_SUPGAIN). */ 61 | #define RESOLUTION_SUPGAIN 8 /* Channel in Q-(RESOLUTION_SUPGAIN). */ 62 | #define SUPGAIN_DEFAULT (1 << RESOLUTION_SUPGAIN) /* Default. */ 63 | #define SUPGAIN_ERROR_PARAM_A 3072 /* Estimation error parameter */ 64 | /* (Maximum gain) (8 in Q8). */ 65 | #define SUPGAIN_ERROR_PARAM_B 1536 /* Estimation error parameter */ 66 | /* (Gain before going down). */ 67 | #define SUPGAIN_ERROR_PARAM_D SUPGAIN_DEFAULT /* Estimation error parameter */ 68 | /* (Should be the same as Default) (1 in Q8). */ 69 | #define SUPGAIN_EPC_DT 200 /* SUPGAIN_ERROR_PARAM_C * ENERGY_DEV_TOL */ 70 | 71 | /* Defines for "check delay estimation" */ 72 | #define CORR_WIDTH 31 /* Number of samples to correlate over. */ 73 | #define CORR_MAX 16 /* Maximum correlation offset. */ 74 | #define CORR_MAX_BUF 63 75 | #define CORR_DEV 4 76 | #define CORR_MAX_LEVEL 20 77 | #define CORR_MAX_LOW 4 78 | #define CORR_BUF_LEN (CORR_MAX << 1) + 1 79 | /* Note that CORR_WIDTH + 2*CORR_MAX <= MAX_BUF_LEN. */ 80 | 81 | #define ONE_Q14 (1 << 14) 82 | 83 | /* NLP defines */ 84 | #define NLP_COMP_LOW 3277 /* 0.2 in Q14 */ 85 | #define NLP_COMP_HIGH ONE_Q14 /* 1 in Q14 */ 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/include/real_fft.h: -------------------------------------------------------------------------------- 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 | #ifndef WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_ 12 | #define WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_ 13 | 14 | #include "webrtc/typedefs.h" 15 | 16 | // For ComplexFFT(), the maximum fft order is 10; 17 | // for OpenMax FFT in ARM, it is 12; 18 | // WebRTC APM uses orders of only 7 and 8. 19 | enum {kMaxFFTOrder = 10}; 20 | 21 | struct RealFFT; 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | struct RealFFT* WebRtcSpl_CreateRealFFT(int order); 28 | void WebRtcSpl_FreeRealFFT(struct RealFFT* self); 29 | 30 | // Compute an FFT for a real-valued signal of length of 2^order, 31 | // where 1 < order <= MAX_FFT_ORDER. Transform length is determined by the 32 | // specification structure, which must be initialized prior to calling the FFT 33 | // function with WebRtcSpl_CreateRealFFT(). 34 | // The relationship between the input and output sequences can 35 | // be expressed in terms of the DFT, i.e.: 36 | // x[n] = (2^(-scalefactor)/N) . SUM[k=0,...,N-1] X[k].e^(jnk.2.pi/N) 37 | // n=0,1,2,...N-1 38 | // N=2^order. 39 | // The conjugate-symmetric output sequence is represented using a CCS vector, 40 | // which is of length N+2, and is organized as follows: 41 | // Index: 0 1 2 3 4 5 . . . N-2 N-1 N N+1 42 | // Component: R0 0 R1 I1 R2 I2 . . . R[N/2-1] I[N/2-1] R[N/2] 0 43 | // where R[n] and I[n], respectively, denote the real and imaginary components 44 | // for FFT bin 'n'. Bins are numbered from 0 to N/2, where N is the FFT length. 45 | // Bin index 0 corresponds to the DC component, and bin index N/2 corresponds to 46 | // the foldover frequency. 47 | // 48 | // Input Arguments: 49 | // self - pointer to preallocated and initialized FFT specification structure. 50 | // real_data_in - the input signal. For an ARM Neon platform, it must be 51 | // aligned on a 32-byte boundary. 52 | // 53 | // Output Arguments: 54 | // complex_data_out - the output complex signal with (2^order + 2) 16-bit 55 | // elements. For an ARM Neon platform, it must be different 56 | // from real_data_in, and aligned on a 32-byte boundary. 57 | // 58 | // Return Value: 59 | // 0 - FFT calculation is successful. 60 | // -1 - Error with bad arguments (NULL pointers). 61 | int WebRtcSpl_RealForwardFFT(struct RealFFT* self, 62 | const int16_t* real_data_in, 63 | int16_t* complex_data_out); 64 | 65 | // Compute the inverse FFT for a conjugate-symmetric input sequence of length of 66 | // 2^order, where 1 < order <= MAX_FFT_ORDER. Transform length is determined by 67 | // the specification structure, which must be initialized prior to calling the 68 | // FFT function with WebRtcSpl_CreateRealFFT(). 69 | // For a transform of length M, the input sequence is represented using a packed 70 | // CCS vector of length M+2, which is explained in the comments for 71 | // WebRtcSpl_RealForwardFFTC above. 72 | // 73 | // Input Arguments: 74 | // self - pointer to preallocated and initialized FFT specification structure. 75 | // complex_data_in - the input complex signal with (2^order + 2) 16-bit 76 | // elements. For an ARM Neon platform, it must be aligned on 77 | // a 32-byte boundary. 78 | // 79 | // Output Arguments: 80 | // real_data_out - the output real signal. For an ARM Neon platform, it must 81 | // be different to complex_data_in, and aligned on a 32-byte 82 | // boundary. 83 | // 84 | // Return Value: 85 | // 0 or a positive number - a value that the elements in the |real_data_out| 86 | // should be shifted left with in order to get 87 | // correct physical values. 88 | // -1 - Error with bad arguments (NULL pointers). 89 | int WebRtcSpl_RealInverseFFT(struct RealFFT* self, 90 | const int16_t* complex_data_in, 91 | int16_t* real_data_out); 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | 97 | #endif // WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_ 98 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/include/spl_inl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 the inline functions in 13 | // the fix point signal processing library. 14 | 15 | #ifndef WEBRTC_SPL_SPL_INL_H_ 16 | #define WEBRTC_SPL_SPL_INL_H_ 17 | 18 | #ifdef WEBRTC_ARCH_ARM_V7 19 | #include "webrtc/common_audio/signal_processing/include/spl_inl_armv7.h" 20 | #else 21 | 22 | #if defined(MIPS32_LE) 23 | #include "webrtc/common_audio/signal_processing/include/spl_inl_mips.h" 24 | #endif 25 | 26 | #if !defined(MIPS_DSP_R1_LE) 27 | static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) { 28 | int16_t out16 = (int16_t) value32; 29 | 30 | if (value32 > 32767) 31 | out16 = 32767; 32 | else if (value32 < -32768) 33 | out16 = -32768; 34 | 35 | return out16; 36 | } 37 | 38 | static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) { 39 | int32_t l_sum; 40 | 41 | // Perform long addition 42 | l_sum = l_var1 + l_var2; 43 | 44 | if (l_var1 < 0) { // Check for underflow. 45 | if ((l_var2 < 0) && (l_sum >= 0)) { 46 | l_sum = (int32_t)0x80000000; 47 | } 48 | } else { // Check for overflow. 49 | if ((l_var2 > 0) && (l_sum < 0)) { 50 | l_sum = (int32_t)0x7FFFFFFF; 51 | } 52 | } 53 | 54 | return l_sum; 55 | } 56 | 57 | static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) { 58 | int32_t l_diff; 59 | 60 | // Perform subtraction. 61 | l_diff = l_var1 - l_var2; 62 | 63 | if (l_var1 < 0) { // Check for underflow. 64 | if ((l_var2 > 0) && (l_diff > 0)) { 65 | l_diff = (int32_t)0x80000000; 66 | } 67 | } else { // Check for overflow. 68 | if ((l_var2 < 0) && (l_diff < 0)) { 69 | l_diff = (int32_t)0x7FFFFFFF; 70 | } 71 | } 72 | 73 | return l_diff; 74 | } 75 | 76 | static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) { 77 | return WebRtcSpl_SatW32ToW16((int32_t) a + (int32_t) b); 78 | } 79 | 80 | static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) { 81 | return WebRtcSpl_SatW32ToW16((int32_t) var1 - (int32_t) var2); 82 | } 83 | #endif // #if !defined(MIPS_DSP_R1_LE) 84 | 85 | #if !defined(MIPS32_LE) 86 | static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) { 87 | int16_t bits; 88 | 89 | if (0xFFFF0000 & n) { 90 | bits = 16; 91 | } else { 92 | bits = 0; 93 | } 94 | if (0x0000FF00 & (n >> bits)) bits += 8; 95 | if (0x000000F0 & (n >> bits)) bits += 4; 96 | if (0x0000000C & (n >> bits)) bits += 2; 97 | if (0x00000002 & (n >> bits)) bits += 1; 98 | if (0x00000001 & (n >> bits)) bits += 1; 99 | 100 | return bits; 101 | } 102 | 103 | static __inline int16_t WebRtcSpl_NormW32(int32_t a) { 104 | int16_t zeros; 105 | 106 | if (a == 0) { 107 | return 0; 108 | } 109 | else if (a < 0) { 110 | a = ~a; 111 | } 112 | 113 | if (!(0xFFFF8000 & a)) { 114 | zeros = 16; 115 | } else { 116 | zeros = 0; 117 | } 118 | if (!(0xFF800000 & (a << zeros))) zeros += 8; 119 | if (!(0xF8000000 & (a << zeros))) zeros += 4; 120 | if (!(0xE0000000 & (a << zeros))) zeros += 2; 121 | if (!(0xC0000000 & (a << zeros))) zeros += 1; 122 | 123 | return zeros; 124 | } 125 | 126 | static __inline int16_t WebRtcSpl_NormU32(uint32_t a) { 127 | int16_t zeros; 128 | 129 | if (a == 0) return 0; 130 | 131 | if (!(0xFFFF0000 & a)) { 132 | zeros = 16; 133 | } else { 134 | zeros = 0; 135 | } 136 | if (!(0xFF000000 & (a << zeros))) zeros += 8; 137 | if (!(0xF0000000 & (a << zeros))) zeros += 4; 138 | if (!(0xC0000000 & (a << zeros))) zeros += 2; 139 | if (!(0x80000000 & (a << zeros))) zeros += 1; 140 | 141 | return zeros; 142 | } 143 | 144 | static __inline int16_t WebRtcSpl_NormW16(int16_t a) { 145 | int16_t zeros; 146 | 147 | if (a == 0) { 148 | return 0; 149 | } 150 | else if (a < 0) { 151 | a = ~a; 152 | } 153 | 154 | if (!(0xFF80 & a)) { 155 | zeros = 8; 156 | } else { 157 | zeros = 0; 158 | } 159 | if (!(0xF800 & (a << zeros))) zeros += 4; 160 | if (!(0xE000 & (a << zeros))) zeros += 2; 161 | if (!(0xC000 & (a << zeros))) zeros += 1; 162 | 163 | return zeros; 164 | } 165 | 166 | static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) { 167 | return (a * b + c); 168 | } 169 | #endif // #if !defined(MIPS32_LE) 170 | 171 | #endif // WEBRTC_ARCH_ARM_V7 172 | 173 | #endif // WEBRTC_SPL_SPL_INL_H_ 174 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/complex_bit_reverse.c: -------------------------------------------------------------------------------- 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 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 12 | 13 | /* Tables for data buffer indexes that are bit reversed and thus need to be 14 | * swapped. Note that, index_7[{0, 2, 4, ...}] are for the left side of the swap 15 | * operations, while index_7[{1, 3, 5, ...}] are for the right side of the 16 | * operation. Same for index_8. 17 | */ 18 | 19 | /* Indexes for the case of stages == 7. */ 20 | static const int16_t index_7[112] = { 21 | 1, 64, 2, 32, 3, 96, 4, 16, 5, 80, 6, 48, 7, 112, 9, 72, 10, 40, 11, 104, 22 | 12, 24, 13, 88, 14, 56, 15, 120, 17, 68, 18, 36, 19, 100, 21, 84, 22, 52, 23 | 23, 116, 25, 76, 26, 44, 27, 108, 29, 92, 30, 60, 31, 124, 33, 66, 35, 98, 24 | 37, 82, 38, 50, 39, 114, 41, 74, 43, 106, 45, 90, 46, 58, 47, 122, 49, 70, 25 | 51, 102, 53, 86, 55, 118, 57, 78, 59, 110, 61, 94, 63, 126, 67, 97, 69, 26 | 81, 71, 113, 75, 105, 77, 89, 79, 121, 83, 101, 87, 117, 91, 109, 95, 125, 27 | 103, 115, 111, 123 28 | }; 29 | 30 | /* Indexes for the case of stages == 8. */ 31 | static const int16_t index_8[240] = { 32 | 1, 128, 2, 64, 3, 192, 4, 32, 5, 160, 6, 96, 7, 224, 8, 16, 9, 144, 10, 80, 33 | 11, 208, 12, 48, 13, 176, 14, 112, 15, 240, 17, 136, 18, 72, 19, 200, 20, 34 | 40, 21, 168, 22, 104, 23, 232, 25, 152, 26, 88, 27, 216, 28, 56, 29, 184, 35 | 30, 120, 31, 248, 33, 132, 34, 68, 35, 196, 37, 164, 38, 100, 39, 228, 41, 36 | 148, 42, 84, 43, 212, 44, 52, 45, 180, 46, 116, 47, 244, 49, 140, 50, 76, 37 | 51, 204, 53, 172, 54, 108, 55, 236, 57, 156, 58, 92, 59, 220, 61, 188, 62, 38 | 124, 63, 252, 65, 130, 67, 194, 69, 162, 70, 98, 71, 226, 73, 146, 74, 82, 39 | 75, 210, 77, 178, 78, 114, 79, 242, 81, 138, 83, 202, 85, 170, 86, 106, 87, 40 | 234, 89, 154, 91, 218, 93, 186, 94, 122, 95, 250, 97, 134, 99, 198, 101, 41 | 166, 103, 230, 105, 150, 107, 214, 109, 182, 110, 118, 111, 246, 113, 142, 42 | 115, 206, 117, 174, 119, 238, 121, 158, 123, 222, 125, 190, 127, 254, 131, 43 | 193, 133, 161, 135, 225, 137, 145, 139, 209, 141, 177, 143, 241, 147, 201, 44 | 149, 169, 151, 233, 155, 217, 157, 185, 159, 249, 163, 197, 167, 229, 171, 45 | 213, 173, 181, 175, 245, 179, 205, 183, 237, 187, 221, 191, 253, 199, 227, 46 | 203, 211, 207, 243, 215, 235, 223, 251, 239, 247 47 | }; 48 | 49 | void WebRtcSpl_ComplexBitReverse(int16_t* __restrict complex_data, int stages) { 50 | /* For any specific value of stages, we know exactly the indexes that are 51 | * bit reversed. Currently (Feb. 2012) in WebRTC the only possible values of 52 | * stages are 7 and 8, so we use tables to save unnecessary iterations and 53 | * calculations for these two cases. 54 | */ 55 | if (stages == 7 || stages == 8) { 56 | int m = 0; 57 | int length = 112; 58 | const int16_t* index = index_7; 59 | 60 | if (stages == 8) { 61 | length = 240; 62 | index = index_8; 63 | } 64 | 65 | /* Decimation in time. Swap the elements with bit-reversed indexes. */ 66 | for (m = 0; m < length; m += 2) { 67 | /* We declare a int32_t* type pointer, to load both the 16-bit real 68 | * and imaginary elements from complex_data in one instruction, reducing 69 | * complexity. 70 | */ 71 | int32_t* complex_data_ptr = (int32_t*)complex_data; 72 | int32_t temp = 0; 73 | 74 | temp = complex_data_ptr[index[m]]; /* Real and imaginary */ 75 | complex_data_ptr[index[m]] = complex_data_ptr[index[m + 1]]; 76 | complex_data_ptr[index[m + 1]] = temp; 77 | } 78 | } 79 | else { 80 | int m = 0, mr = 0, l = 0; 81 | int n = 1 << stages; 82 | int nn = n - 1; 83 | 84 | /* Decimation in time - re-order data */ 85 | for (m = 1; m <= nn; ++m) { 86 | int32_t* complex_data_ptr = (int32_t*)complex_data; 87 | int32_t temp = 0; 88 | 89 | /* Find out indexes that are bit-reversed. */ 90 | l = n; 91 | do { 92 | l >>= 1; 93 | } while (l > nn - mr); 94 | mr = (mr & (l - 1)) + l; 95 | 96 | if (mr <= m) { 97 | continue; 98 | } 99 | 100 | /* Swap the elements with bit-reversed indexes. 101 | * This is similar to the loop in the stages == 7 or 8 cases. 102 | */ 103 | temp = complex_data_ptr[m]; /* Real and imaginary */ 104 | complex_data_ptr[m] = complex_data_ptr[mr]; 105 | complex_data_ptr[mr] = temp; 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/Android.mk: -------------------------------------------------------------------------------- 1 | 2 | LOCAL_PATH := $(call my-dir) 3 | 4 | common_CFLAGS := -fexceptions -DWEBRTC_POSIX=1 -Isrc/ 5 | common_LDFLAGS := 6 | 7 | common_SRC_FILES := \ 8 | src/webrtc/modules/audio_processing/aec/aec_core.c \ 9 | src/webrtc/modules/audio_processing/aec/aec_rdft.c \ 10 | src/webrtc/modules/audio_processing/aec/aec_resampler.c \ 11 | src/webrtc/modules/audio_processing/aec/echo_cancellation.c \ 12 | src/webrtc/modules/audio_processing/aecm/aecm_core.c \ 13 | src/webrtc/modules/audio_processing/aecm/echo_control_mobile.c \ 14 | src/webrtc/modules/audio_processing/ns/noise_suppression.c \ 15 | src/webrtc/modules/audio_processing/ns/noise_suppression_x.c \ 16 | src/webrtc/modules/audio_processing/ns/ns_core.c \ 17 | src/webrtc/modules/audio_processing/ns/nsx_core.c \ 18 | src/webrtc/modules/audio_processing/utility/delay_estimator_wrapper.c \ 19 | src/webrtc/modules/audio_processing/utility/delay_estimator.c \ 20 | src/webrtc/common_audio/fft4g.c \ 21 | src/webrtc/common_audio/ring_buffer.c \ 22 | src/webrtc/common_audio/signal_processing/complex_bit_reverse.c \ 23 | src/webrtc/common_audio/signal_processing/complex_fft.c \ 24 | src/webrtc/common_audio/signal_processing/copy_set_operations.c \ 25 | src/webrtc/common_audio/signal_processing/cross_correlation.c \ 26 | src/webrtc/common_audio/signal_processing/division_operations.c \ 27 | src/webrtc/common_audio/signal_processing/downsample_fast.c \ 28 | src/webrtc/common_audio/signal_processing/energy.c \ 29 | src/webrtc/common_audio/signal_processing/get_scaling_square.c \ 30 | src/webrtc/common_audio/signal_processing/min_max_operations.c \ 31 | src/webrtc/common_audio/signal_processing/randomization_functions.c \ 32 | src/webrtc/common_audio/signal_processing/real_fft.c \ 33 | src/webrtc/common_audio/signal_processing/spl_init.c \ 34 | src/webrtc/common_audio/signal_processing/spl_sqrt.c \ 35 | src/webrtc/common_audio/signal_processing/spl_sqrt_floor.c \ 36 | src/webrtc/common_audio/signal_processing/vector_scaling_operations.c 37 | 38 | 39 | ifneq ($(findstring arm,$(TARGET_ARCH_ABI)),) 40 | common_SRC_FILES += \ 41 | src/webrtc/modules/audio_processing/aec/aec_core_neon.c \ 42 | src/webrtc/modules/audio_processing/aec/aec_rdft_neon.c \ 43 | src/webrtc/modules/audio_processing/aecm/aecm_core_c.c \ 44 | src/webrtc/modules/audio_processing/aecm/aecm_core_neon.c \ 45 | src/webrtc/modules/audio_processing/ns/nsx_core_c.c \ 46 | src/webrtc/modules/audio_processing/ns/nsx_core_neon.c \ 47 | src/webrtc/common_audio/signal_processing/cross_correlation_neon.c \ 48 | src/webrtc/common_audio/signal_processing/downsample_fast_neon.c \ 49 | src/webrtc/common_audio/signal_processing/min_max_operations_neon.c 50 | 51 | common_CFLAGS += -DWEBRTC_HAS_NEON 52 | ifeq ($(TARGET_ARCH_ABI), armeabi) 53 | common_CFLAGS += -mfloat-abi=softfp -mfpu=neon -march=armv7 54 | else ifeq ($(TARGET_ARCH_ABI), armeabi-v7a) 55 | common_CFLAGS += -march=armv7-a -mfloat-abi=softfp -mfpu=neon 56 | common_LDFLAGS += -Wl,--fix-cortex-a8 57 | else ifeq ($(TARGET_ARCH_ABI), arm64-v8a) 58 | common_CFLAGS += -DWEBRTC_ARCH_ARM64 59 | endif 60 | 61 | else ifeq ($(TARGET_ARCH_ABI), mips) 62 | common_SRC_FILES += \ 63 | src/webrtc/modules/audio_processing/aec/aec_core_mips.c \ 64 | src/webrtc/modules/audio_processing/aec/aec_rdft_mips.c \ 65 | src/webrtc/modules/audio_processing/aecm/aecm_core_mips.c \ 66 | src/webrtc/modules/audio_processing/ns/nsx_core_mips.c \ 67 | src/webrtc/common_audio/signal_processing/cross_correlation_mips.c \ 68 | src/webrtc/common_audio/signal_processing/downsample_fast_mips.c \ 69 | src/webrtc/common_audio/signal_processing/min_max_operations_mips.c 70 | 71 | common_CFLAGS += -DMIPS_FPU_LE 72 | 73 | else ifneq ($(findstring x86,$(TARGET_ARCH_ABI)),) 74 | common_SRC_FILES += \ 75 | src/webrtc/modules/audio_processing/aec/aec_core_sse2.c \ 76 | src/webrtc/modules/audio_processing/aec/aec_rdft_sse2.c \ 77 | src/webrtc/modules/audio_processing/aecm/aecm_core_c.c \ 78 | src/webrtc/modules/audio_processing/ns/nsx_core_c.c \ 79 | src/webrtc/system_wrappers/source/cpu_features.cc 80 | 81 | endif 82 | 83 | common_C_INCLUDES = $(LOCAL_PATH)/include 84 | 85 | include $(CLEAR_VARS) 86 | LOCAL_MODULE:= libwebrtc 87 | LOCAL_CPP_EXTENSION := .cc 88 | LOCAL_SRC_FILES := $(common_SRC_FILES) 89 | LOCAL_CFLAGS += $(common_CFLAGS) 90 | LOCAL_LDFLAGS += $(common_LDFLAGS) 91 | LOCAL_C_INCLUDES += $(common_C_INCLUDES) 92 | 93 | include $(BUILD_SHARED_LIBRARY) 94 | 95 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/complex_bit_reverse_arm.S: -------------------------------------------------------------------------------- 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 | @ This file contains the function WebRtcSpl_ComplexBitReverse(), optimized 12 | @ for ARMv5 platforms. 13 | @ Reference C code is in file complex_bit_reverse.c. Bit-exact. 14 | 15 | #include "webrtc/system_wrappers/interface/asm_defines.h" 16 | 17 | GLOBAL_FUNCTION WebRtcSpl_ComplexBitReverse 18 | .align 2 19 | DEFINE_FUNCTION WebRtcSpl_ComplexBitReverse 20 | push {r4-r7} 21 | 22 | cmp r1, #7 23 | adr r3, index_7 @ Table pointer. 24 | mov r4, #112 @ Number of interations. 25 | beq PRE_LOOP_STAGES_7_OR_8 26 | 27 | cmp r1, #8 28 | adr r3, index_8 @ Table pointer. 29 | mov r4, #240 @ Number of interations. 30 | beq PRE_LOOP_STAGES_7_OR_8 31 | 32 | mov r3, #1 @ Initialize m. 33 | mov r1, r3, asl r1 @ n = 1 << stages; 34 | subs r6, r1, #1 @ nn = n - 1; 35 | ble END 36 | 37 | mov r5, r0 @ &complex_data 38 | mov r4, #0 @ ml 39 | 40 | LOOP_GENERIC: 41 | rsb r12, r4, r6 @ l > nn - mr 42 | mov r2, r1 @ n 43 | 44 | LOOP_SHIFT: 45 | asr r2, #1 @ l >>= 1; 46 | cmp r2, r12 47 | bgt LOOP_SHIFT 48 | 49 | sub r12, r2, #1 50 | and r4, r12, r4 51 | add r4, r2 @ mr = (mr & (l - 1)) + l; 52 | cmp r4, r3 @ mr <= m ? 53 | ble UPDATE_REGISTERS 54 | 55 | mov r12, r4, asl #2 56 | ldr r7, [r5, #4] @ complex_data[2 * m, 2 * m + 1]. 57 | @ Offset 4 due to m incrementing from 1. 58 | ldr r2, [r0, r12] @ complex_data[2 * mr, 2 * mr + 1]. 59 | str r7, [r0, r12] 60 | str r2, [r5, #4] 61 | 62 | UPDATE_REGISTERS: 63 | add r3, r3, #1 64 | add r5, #4 65 | cmp r3, r1 66 | bne LOOP_GENERIC 67 | 68 | b END 69 | 70 | PRE_LOOP_STAGES_7_OR_8: 71 | add r4, r3, r4, asl #1 72 | 73 | LOOP_STAGES_7_OR_8: 74 | ldrsh r2, [r3], #2 @ index[m] 75 | ldrsh r5, [r3], #2 @ index[m + 1] 76 | ldr r1, [r0, r2] @ complex_data[index[m], index[m] + 1] 77 | ldr r12, [r0, r5] @ complex_data[index[m + 1], index[m + 1] + 1] 78 | cmp r3, r4 79 | str r1, [r0, r5] 80 | str r12, [r0, r2] 81 | bne LOOP_STAGES_7_OR_8 82 | 83 | END: 84 | pop {r4-r7} 85 | bx lr 86 | 87 | @ The index tables. Note the values are doubles of the actual indexes for 16-bit 88 | @ elements, different from the generic C code. It actually provides byte offsets 89 | @ for the indexes. 90 | 91 | .align 2 92 | index_7: @ Indexes for stages == 7. 93 | .short 4, 256, 8, 128, 12, 384, 16, 64, 20, 320, 24, 192, 28, 448, 36, 288 94 | .short 40, 160, 44, 416, 48, 96, 52, 352, 56, 224, 60, 480, 68, 272, 72, 144 95 | .short 76, 400, 84, 336, 88, 208, 92, 464, 100, 304, 104, 176, 108, 432, 116 96 | .short 368, 120, 240, 124, 496, 132, 264, 140, 392, 148, 328, 152, 200, 156 97 | .short 456, 164, 296, 172, 424, 180, 360, 184, 232, 188, 488, 196, 280, 204 98 | .short 408, 212, 344, 220, 472, 228, 312, 236, 440, 244, 376, 252, 504, 268 99 | .short 388, 276, 324, 284, 452, 300, 420, 308, 356, 316, 484, 332, 404, 348 100 | .short 468, 364, 436, 380, 500, 412, 460, 444, 492 101 | 102 | index_8: @ Indexes for stages == 8. 103 | .short 4, 512, 8, 256, 12, 768, 16, 128, 20, 640, 24, 384, 28, 896, 32, 64 104 | .short 36, 576, 40, 320, 44, 832, 48, 192, 52, 704, 56, 448, 60, 960, 68, 544 105 | .short 72, 288, 76, 800, 80, 160, 84, 672, 88, 416, 92, 928, 100, 608, 104 106 | .short 352, 108, 864, 112, 224, 116, 736, 120, 480, 124, 992, 132, 528, 136 107 | .short 272, 140, 784, 148, 656, 152, 400, 156, 912, 164, 592, 168, 336, 172 108 | .short 848, 176, 208, 180, 720, 184, 464, 188, 976, 196, 560, 200, 304, 204 109 | .short 816, 212, 688, 216, 432, 220, 944, 228, 624, 232, 368, 236, 880, 244 110 | .short 752, 248, 496, 252, 1008, 260, 520, 268, 776, 276, 648, 280, 392, 284 111 | .short 904, 292, 584, 296, 328, 300, 840, 308, 712, 312, 456, 316, 968, 324 112 | .short 552, 332, 808, 340, 680, 344, 424, 348, 936, 356, 616, 364, 872, 372 113 | .short 744, 376, 488, 380, 1000, 388, 536, 396, 792, 404, 664, 412, 920, 420 114 | .short 600, 428, 856, 436, 728, 440, 472, 444, 984, 452, 568, 460, 824, 468 115 | .short 696, 476, 952, 484, 632, 492, 888, 500, 760, 508, 1016, 524, 772, 532 116 | .short 644, 540, 900, 548, 580, 556, 836, 564, 708, 572, 964, 588, 804, 596 117 | .short 676, 604, 932, 620, 868, 628, 740, 636, 996, 652, 788, 668, 916, 684 118 | .short 852, 692, 724, 700, 980, 716, 820, 732, 948, 748, 884, 764, 1012, 796 119 | .short 908, 812, 844, 828, 972, 860, 940, 892, 1004, 956, 988 120 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/aec/aec_core.h: -------------------------------------------------------------------------------- 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 | * Specifies the interface for the AEC core. 13 | */ 14 | 15 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_H_ 16 | #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_H_ 17 | 18 | #include 19 | 20 | #include "webrtc/typedefs.h" 21 | 22 | #define FRAME_LEN 80 23 | #define PART_LEN 64 // Length of partition 24 | #define PART_LEN1 (PART_LEN + 1) // Unique fft coefficients 25 | #define PART_LEN2 (PART_LEN * 2) // Length of partition * 2 26 | #define NUM_HIGH_BANDS_MAX 2 // Max number of high bands 27 | 28 | typedef float complex_t[2]; 29 | // For performance reasons, some arrays of complex numbers are replaced by twice 30 | // as long arrays of float, all the real parts followed by all the imaginary 31 | // ones (complex_t[SIZE] -> float[2][SIZE]). This allows SIMD optimizations and 32 | // is better than two arrays (one for the real parts and one for the imaginary 33 | // parts) as this other way would require two pointers instead of one and cause 34 | // extra register spilling. This also allows the offsets to be calculated at 35 | // compile time. 36 | 37 | // Metrics 38 | enum { 39 | kOffsetLevel = -100 40 | }; 41 | 42 | typedef struct Stats { 43 | float instant; 44 | float average; 45 | float min; 46 | float max; 47 | float sum; 48 | float hisum; 49 | float himean; 50 | int counter; 51 | int hicounter; 52 | } Stats; 53 | 54 | typedef struct AecCore AecCore; 55 | 56 | AecCore* WebRtcAec_CreateAec(); // Returns NULL on error. 57 | void WebRtcAec_FreeAec(AecCore* aec); 58 | int WebRtcAec_InitAec(AecCore* aec, int sampFreq); 59 | void WebRtcAec_InitAec_SSE2(void); 60 | #if defined(MIPS_FPU_LE) 61 | void WebRtcAec_InitAec_mips(void); 62 | #endif 63 | #if defined(WEBRTC_DETECT_NEON) || defined(WEBRTC_HAS_NEON) 64 | void WebRtcAec_InitAec_neon(void); 65 | #endif 66 | 67 | void WebRtcAec_BufferFarendPartition(AecCore* aec, const float* farend); 68 | void WebRtcAec_ProcessFrames(AecCore* aec, 69 | const float* const* nearend, 70 | size_t num_bands, 71 | size_t num_samples, 72 | int knownDelay, 73 | float* const* out); 74 | 75 | // A helper function to call WebRtc_MoveReadPtr() for all far-end buffers. 76 | // Returns the number of elements moved, and adjusts |system_delay| by the 77 | // corresponding amount in ms. 78 | int WebRtcAec_MoveFarReadPtr(AecCore* aec, int elements); 79 | 80 | // Calculates the median, standard deviation and amount of poor values among the 81 | // delay estimates aggregated up to the first call to the function. After that 82 | // first call the metrics are aggregated and updated every second. With poor 83 | // values we mean values that most likely will cause the AEC to perform poorly. 84 | // TODO(bjornv): Consider changing tests and tools to handle constant 85 | // constant aggregation window throughout the session instead. 86 | int WebRtcAec_GetDelayMetricsCore(AecCore* self, int* median, int* std, 87 | float* fraction_poor_delays); 88 | 89 | // Returns the echo state (1: echo, 0: no echo). 90 | int WebRtcAec_echo_state(AecCore* self); 91 | 92 | // Gets statistics of the echo metrics ERL, ERLE, A_NLP. 93 | void WebRtcAec_GetEchoStats(AecCore* self, 94 | Stats* erl, 95 | Stats* erle, 96 | Stats* a_nlp); 97 | #ifdef WEBRTC_AEC_DEBUG_DUMP 98 | void* WebRtcAec_far_time_buf(AecCore* self); 99 | #endif 100 | 101 | // Sets local configuration modes. 102 | void WebRtcAec_SetConfigCore(AecCore* self, 103 | int nlp_mode, 104 | int metrics_mode, 105 | int delay_logging); 106 | 107 | // Non-zero enables, zero disables. 108 | void WebRtcAec_enable_delay_agnostic(AecCore* self, int enable); 109 | 110 | // Returns non-zero if delay agnostic (i.e., signal based delay estimation) is 111 | // enabled and zero if disabled. 112 | int WebRtcAec_delay_agnostic_enabled(AecCore* self); 113 | 114 | // Enables or disables extended filter mode. Non-zero enables, zero disables. 115 | void WebRtcAec_enable_extended_filter(AecCore* self, int enable); 116 | 117 | // Returns non-zero if extended filter mode is enabled and zero if disabled. 118 | int WebRtcAec_extended_filter_enabled(AecCore* self); 119 | 120 | // Returns the current |system_delay|, i.e., the buffered difference between 121 | // far-end and near-end. 122 | int WebRtcAec_system_delay(AecCore* self); 123 | 124 | // Sets the |system_delay| to |value|. Note that if the value is changed 125 | // improperly, there can be a performance regression. So it should be used with 126 | // care. 127 | void WebRtcAec_SetSystemDelay(AecCore* self, int delay); 128 | 129 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_H_ 130 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/spl_init.c: -------------------------------------------------------------------------------- 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 | /* The global function contained in this file initializes SPL function 12 | * pointers, currently only for ARM platforms. 13 | * 14 | * Some code came from common/rtcd.c in the WebM project. 15 | */ 16 | 17 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 18 | #include "webrtc/system_wrappers/interface/cpu_features_wrapper.h" 19 | 20 | /* Declare function pointers. */ 21 | MaxAbsValueW16 WebRtcSpl_MaxAbsValueW16; 22 | MaxAbsValueW32 WebRtcSpl_MaxAbsValueW32; 23 | MaxValueW16 WebRtcSpl_MaxValueW16; 24 | MaxValueW32 WebRtcSpl_MaxValueW32; 25 | MinValueW16 WebRtcSpl_MinValueW16; 26 | MinValueW32 WebRtcSpl_MinValueW32; 27 | CrossCorrelation WebRtcSpl_CrossCorrelation; 28 | DownsampleFast WebRtcSpl_DownsampleFast; 29 | ScaleAndAddVectorsWithRound WebRtcSpl_ScaleAndAddVectorsWithRound; 30 | 31 | #if (defined(WEBRTC_DETECT_NEON) || !defined(WEBRTC_HAS_NEON)) && \ 32 | !defined(MIPS32_LE) 33 | /* Initialize function pointers to the generic C version. */ 34 | static void InitPointersToC() { 35 | WebRtcSpl_MaxAbsValueW16 = WebRtcSpl_MaxAbsValueW16C; 36 | WebRtcSpl_MaxAbsValueW32 = WebRtcSpl_MaxAbsValueW32C; 37 | WebRtcSpl_MaxValueW16 = WebRtcSpl_MaxValueW16C; 38 | WebRtcSpl_MaxValueW32 = WebRtcSpl_MaxValueW32C; 39 | WebRtcSpl_MinValueW16 = WebRtcSpl_MinValueW16C; 40 | WebRtcSpl_MinValueW32 = WebRtcSpl_MinValueW32C; 41 | WebRtcSpl_CrossCorrelation = WebRtcSpl_CrossCorrelationC; 42 | WebRtcSpl_DownsampleFast = WebRtcSpl_DownsampleFastC; 43 | WebRtcSpl_ScaleAndAddVectorsWithRound = 44 | WebRtcSpl_ScaleAndAddVectorsWithRoundC; 45 | } 46 | #endif 47 | 48 | #if defined(WEBRTC_DETECT_NEON) || defined(WEBRTC_HAS_NEON) 49 | /* Initialize function pointers to the Neon version. */ 50 | static void InitPointersToNeon() { 51 | WebRtcSpl_MaxAbsValueW16 = WebRtcSpl_MaxAbsValueW16Neon; 52 | WebRtcSpl_MaxAbsValueW32 = WebRtcSpl_MaxAbsValueW32Neon; 53 | WebRtcSpl_MaxValueW16 = WebRtcSpl_MaxValueW16Neon; 54 | WebRtcSpl_MaxValueW32 = WebRtcSpl_MaxValueW32Neon; 55 | WebRtcSpl_MinValueW16 = WebRtcSpl_MinValueW16Neon; 56 | WebRtcSpl_MinValueW32 = WebRtcSpl_MinValueW32Neon; 57 | WebRtcSpl_CrossCorrelation = WebRtcSpl_CrossCorrelationNeon; 58 | WebRtcSpl_DownsampleFast = WebRtcSpl_DownsampleFastNeon; 59 | WebRtcSpl_ScaleAndAddVectorsWithRound = 60 | WebRtcSpl_ScaleAndAddVectorsWithRoundC; 61 | } 62 | #endif 63 | 64 | #if defined(MIPS32_LE) 65 | /* Initialize function pointers to the MIPS version. */ 66 | static void InitPointersToMIPS() { 67 | WebRtcSpl_MaxAbsValueW16 = WebRtcSpl_MaxAbsValueW16_mips; 68 | WebRtcSpl_MaxValueW16 = WebRtcSpl_MaxValueW16_mips; 69 | WebRtcSpl_MaxValueW32 = WebRtcSpl_MaxValueW32_mips; 70 | WebRtcSpl_MinValueW16 = WebRtcSpl_MinValueW16_mips; 71 | WebRtcSpl_MinValueW32 = WebRtcSpl_MinValueW32_mips; 72 | WebRtcSpl_CrossCorrelation = WebRtcSpl_CrossCorrelation_mips; 73 | WebRtcSpl_DownsampleFast = WebRtcSpl_DownsampleFast_mips; 74 | #if defined(MIPS_DSP_R1_LE) 75 | WebRtcSpl_MaxAbsValueW32 = WebRtcSpl_MaxAbsValueW32_mips; 76 | WebRtcSpl_ScaleAndAddVectorsWithRound = 77 | WebRtcSpl_ScaleAndAddVectorsWithRound_mips; 78 | #else 79 | WebRtcSpl_MaxAbsValueW32 = WebRtcSpl_MaxAbsValueW32C; 80 | WebRtcSpl_ScaleAndAddVectorsWithRound = 81 | WebRtcSpl_ScaleAndAddVectorsWithRoundC; 82 | #endif 83 | } 84 | #endif 85 | 86 | static void InitFunctionPointers(void) { 87 | #if defined(WEBRTC_DETECT_NEON) 88 | if ((WebRtc_GetCPUFeaturesARM() & kCPUFeatureNEON) != 0) { 89 | InitPointersToNeon(); 90 | } else { 91 | InitPointersToC(); 92 | } 93 | #elif defined(WEBRTC_HAS_NEON) 94 | InitPointersToNeon(); 95 | #elif defined(MIPS32_LE) 96 | InitPointersToMIPS(); 97 | #else 98 | InitPointersToC(); 99 | #endif /* WEBRTC_DETECT_NEON */ 100 | } 101 | 102 | #if defined(WEBRTC_POSIX) 103 | #include 104 | 105 | static void once(void (*func)(void)) { 106 | static pthread_once_t lock = PTHREAD_ONCE_INIT; 107 | pthread_once(&lock, func); 108 | } 109 | 110 | #elif defined(_WIN32) 111 | #include 112 | 113 | static void once(void (*func)(void)) { 114 | /* Didn't use InitializeCriticalSection() since there's no race-free context 115 | * in which to execute it. 116 | * 117 | * TODO(kma): Change to different implementation (e.g. 118 | * InterlockedCompareExchangePointer) to avoid issues similar to 119 | * http://code.google.com/p/webm/issues/detail?id=467. 120 | */ 121 | static CRITICAL_SECTION lock = {(void *)((size_t)-1), -1, 0, 0, 0, 0}; 122 | static int done = 0; 123 | 124 | EnterCriticalSection(&lock); 125 | if (!done) { 126 | func(); 127 | done = 1; 128 | } 129 | LeaveCriticalSection(&lock); 130 | } 131 | 132 | /* There's no fallback version as an #else block here to ensure thread safety. 133 | * In case of neither pthread for WEBRTC_POSIX nor _WIN32 is present, build 134 | * system should pick it up. 135 | */ 136 | #endif /* WEBRTC_POSIX */ 137 | 138 | void WebRtcSpl_Init() { 139 | once(InitFunctionPointers); 140 | } 141 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/spl_sqrt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | /* 13 | * This file contains the function WebRtcSpl_Sqrt(). 14 | * The description header can be found in signal_processing_library.h 15 | * 16 | */ 17 | 18 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 19 | 20 | #include 21 | 22 | int32_t WebRtcSpl_SqrtLocal(int32_t in); 23 | 24 | int32_t WebRtcSpl_SqrtLocal(int32_t in) 25 | { 26 | 27 | int16_t x_half, t16; 28 | int32_t A, B, x2; 29 | 30 | /* The following block performs: 31 | y=in/2 32 | x=y-2^30 33 | x_half=x/2^31 34 | t = 1 + (x_half) - 0.5*((x_half)^2) + 0.5*((x_half)^3) - 0.625*((x_half)^4) 35 | + 0.875*((x_half)^5) 36 | */ 37 | 38 | B = in / 2; 39 | 40 | B = B - ((int32_t)0x40000000); // B = in/2 - 1/2 41 | x_half = (int16_t)(B >> 16); // x_half = x/2 = (in-1)/2 42 | B = B + ((int32_t)0x40000000); // B = 1 + x/2 43 | B = B + ((int32_t)0x40000000); // Add 0.5 twice (since 1.0 does not exist in Q31) 44 | 45 | x2 = ((int32_t)x_half) * ((int32_t)x_half) * 2; // A = (x/2)^2 46 | A = -x2; // A = -(x/2)^2 47 | B = B + (A >> 1); // B = 1 + x/2 - 0.5*(x/2)^2 48 | 49 | A >>= 16; 50 | A = A * A * 2; // A = (x/2)^4 51 | t16 = (int16_t)(A >> 16); 52 | B += -20480 * t16 * 2; // B = B - 0.625*A 53 | // After this, B = 1 + x/2 - 0.5*(x/2)^2 - 0.625*(x/2)^4 54 | 55 | A = x_half * t16 * 2; // A = (x/2)^5 56 | t16 = (int16_t)(A >> 16); 57 | B += 28672 * t16 * 2; // B = B + 0.875*A 58 | // After this, B = 1 + x/2 - 0.5*(x/2)^2 - 0.625*(x/2)^4 + 0.875*(x/2)^5 59 | 60 | t16 = (int16_t)(x2 >> 16); 61 | A = x_half * t16 * 2; // A = x/2^3 62 | 63 | B = B + (A >> 1); // B = B + 0.5*A 64 | // After this, B = 1 + x/2 - 0.5*(x/2)^2 + 0.5*(x/2)^3 - 0.625*(x/2)^4 + 0.875*(x/2)^5 65 | 66 | B = B + ((int32_t)32768); // Round off bit 67 | 68 | return B; 69 | } 70 | 71 | int32_t WebRtcSpl_Sqrt(int32_t value) 72 | { 73 | /* 74 | Algorithm: 75 | 76 | Six term Taylor Series is used here to compute the square root of a number 77 | y^0.5 = (1+x)^0.5 where x = y-1 78 | = 1+(x/2)-0.5*((x/2)^2+0.5*((x/2)^3-0.625*((x/2)^4+0.875*((x/2)^5) 79 | 0.5 <= x < 1 80 | 81 | Example of how the algorithm works, with ut=sqrt(in), and 82 | with in=73632 and ut=271 (even shift value case): 83 | 84 | in=73632 85 | y= in/131072 86 | x=y-1 87 | t = 1 + (x/2) - 0.5*((x/2)^2) + 0.5*((x/2)^3) - 0.625*((x/2)^4) + 0.875*((x/2)^5) 88 | ut=t*(1/sqrt(2))*512 89 | 90 | or: 91 | 92 | in=73632 93 | in2=73632*2^14 94 | y= in2/2^31 95 | x=y-1 96 | t = 1 + (x/2) - 0.5*((x/2)^2) + 0.5*((x/2)^3) - 0.625*((x/2)^4) + 0.875*((x/2)^5) 97 | ut=t*(1/sqrt(2)) 98 | ut2=ut*2^9 99 | 100 | which gives: 101 | 102 | in = 73632 103 | in2 = 1206386688 104 | y = 0.56176757812500 105 | x = -0.43823242187500 106 | t = 0.74973506527313 107 | ut = 0.53014274874797 108 | ut2 = 2.714330873589594e+002 109 | 110 | or: 111 | 112 | in=73632 113 | in2=73632*2^14 114 | y=in2/2 115 | x=y-2^30 116 | x_half=x/2^31 117 | t = 1 + (x_half) - 0.5*((x_half)^2) + 0.5*((x_half)^3) - 0.625*((x_half)^4) 118 | + 0.875*((x_half)^5) 119 | ut=t*(1/sqrt(2)) 120 | ut2=ut*2^9 121 | 122 | which gives: 123 | 124 | in = 73632 125 | in2 = 1206386688 126 | y = 603193344 127 | x = -470548480 128 | x_half = -0.21911621093750 129 | t = 0.74973506527313 130 | ut = 0.53014274874797 131 | ut2 = 2.714330873589594e+002 132 | 133 | */ 134 | 135 | int16_t x_norm, nshift, t16, sh; 136 | int32_t A; 137 | 138 | int16_t k_sqrt_2 = 23170; // 1/sqrt2 (==5a82) 139 | 140 | A = value; 141 | 142 | if (A == 0) 143 | return (int32_t)0; // sqrt(0) = 0 144 | 145 | sh = WebRtcSpl_NormW32(A); // # shifts to normalize A 146 | A = WEBRTC_SPL_LSHIFT_W32(A, sh); // Normalize A 147 | if (A < (WEBRTC_SPL_WORD32_MAX - 32767)) 148 | { 149 | A = A + ((int32_t)32768); // Round off bit 150 | } else 151 | { 152 | A = WEBRTC_SPL_WORD32_MAX; 153 | } 154 | 155 | x_norm = (int16_t)(A >> 16); // x_norm = AH 156 | 157 | nshift = (sh / 2); 158 | assert(nshift >= 0); 159 | 160 | A = (int32_t)WEBRTC_SPL_LSHIFT_W32((int32_t)x_norm, 16); 161 | A = WEBRTC_SPL_ABS_W32(A); // A = abs(x_norm<<16) 162 | A = WebRtcSpl_SqrtLocal(A); // A = sqrt(A) 163 | 164 | if (2 * nshift == sh) { 165 | // Even shift value case 166 | 167 | t16 = (int16_t)(A >> 16); // t16 = AH 168 | 169 | A = k_sqrt_2 * t16 * 2; // A = 1/sqrt(2)*t16 170 | A = A + ((int32_t)32768); // Round off 171 | A = A & ((int32_t)0x7fff0000); // Round off 172 | 173 | A >>= 15; // A = A>>16 174 | 175 | } else 176 | { 177 | A >>= 16; // A = A>>16 178 | } 179 | 180 | A = A & ((int32_t)0x0000ffff); 181 | A >>= nshift; // De-normalize the result. 182 | 183 | return A; 184 | } 185 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/vector_scaling_operations.c: -------------------------------------------------------------------------------- 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 | /* 13 | * This file contains implementations of the functions 14 | * WebRtcSpl_VectorBitShiftW16() 15 | * WebRtcSpl_VectorBitShiftW32() 16 | * WebRtcSpl_VectorBitShiftW32ToW16() 17 | * WebRtcSpl_ScaleVector() 18 | * WebRtcSpl_ScaleVectorWithSat() 19 | * WebRtcSpl_ScaleAndAddVectors() 20 | * WebRtcSpl_ScaleAndAddVectorsWithRoundC() 21 | */ 22 | 23 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 24 | 25 | void WebRtcSpl_VectorBitShiftW16(int16_t *res, size_t length, 26 | const int16_t *in, int16_t right_shifts) 27 | { 28 | size_t i; 29 | 30 | if (right_shifts > 0) 31 | { 32 | for (i = length; i > 0; i--) 33 | { 34 | (*res++) = ((*in++) >> right_shifts); 35 | } 36 | } else 37 | { 38 | for (i = length; i > 0; i--) 39 | { 40 | (*res++) = ((*in++) << (-right_shifts)); 41 | } 42 | } 43 | } 44 | 45 | void WebRtcSpl_VectorBitShiftW32(int32_t *out_vector, 46 | size_t vector_length, 47 | const int32_t *in_vector, 48 | int16_t right_shifts) 49 | { 50 | size_t i; 51 | 52 | if (right_shifts > 0) 53 | { 54 | for (i = vector_length; i > 0; i--) 55 | { 56 | (*out_vector++) = ((*in_vector++) >> right_shifts); 57 | } 58 | } else 59 | { 60 | for (i = vector_length; i > 0; i--) 61 | { 62 | (*out_vector++) = ((*in_vector++) << (-right_shifts)); 63 | } 64 | } 65 | } 66 | 67 | void WebRtcSpl_VectorBitShiftW32ToW16(int16_t* out, size_t length, 68 | const int32_t* in, int right_shifts) { 69 | size_t i; 70 | int32_t tmp_w32; 71 | 72 | if (right_shifts >= 0) { 73 | for (i = length; i > 0; i--) { 74 | tmp_w32 = (*in++) >> right_shifts; 75 | (*out++) = WebRtcSpl_SatW32ToW16(tmp_w32); 76 | } 77 | } else { 78 | int left_shifts = -right_shifts; 79 | for (i = length; i > 0; i--) { 80 | tmp_w32 = (*in++) << left_shifts; 81 | (*out++) = WebRtcSpl_SatW32ToW16(tmp_w32); 82 | } 83 | } 84 | } 85 | 86 | void WebRtcSpl_ScaleVector(const int16_t *in_vector, int16_t *out_vector, 87 | int16_t gain, size_t in_vector_length, 88 | int16_t right_shifts) 89 | { 90 | // Performs vector operation: out_vector = (gain*in_vector)>>right_shifts 91 | size_t i; 92 | const int16_t *inptr; 93 | int16_t *outptr; 94 | 95 | inptr = in_vector; 96 | outptr = out_vector; 97 | 98 | for (i = 0; i < in_vector_length; i++) 99 | { 100 | *outptr++ = (int16_t)((*inptr++ * gain) >> right_shifts); 101 | } 102 | } 103 | 104 | void WebRtcSpl_ScaleVectorWithSat(const int16_t *in_vector, int16_t *out_vector, 105 | int16_t gain, size_t in_vector_length, 106 | int16_t right_shifts) 107 | { 108 | // Performs vector operation: out_vector = (gain*in_vector)>>right_shifts 109 | size_t i; 110 | const int16_t *inptr; 111 | int16_t *outptr; 112 | 113 | inptr = in_vector; 114 | outptr = out_vector; 115 | 116 | for (i = 0; i < in_vector_length; i++) { 117 | *outptr++ = WebRtcSpl_SatW32ToW16((*inptr++ * gain) >> right_shifts); 118 | } 119 | } 120 | 121 | void WebRtcSpl_ScaleAndAddVectors(const int16_t *in1, int16_t gain1, int shift1, 122 | const int16_t *in2, int16_t gain2, int shift2, 123 | int16_t *out, size_t vector_length) 124 | { 125 | // Performs vector operation: out = (gain1*in1)>>shift1 + (gain2*in2)>>shift2 126 | size_t i; 127 | const int16_t *in1ptr; 128 | const int16_t *in2ptr; 129 | int16_t *outptr; 130 | 131 | in1ptr = in1; 132 | in2ptr = in2; 133 | outptr = out; 134 | 135 | for (i = 0; i < vector_length; i++) 136 | { 137 | *outptr++ = (int16_t)((gain1 * *in1ptr++) >> shift1) + 138 | (int16_t)((gain2 * *in2ptr++) >> shift2); 139 | } 140 | } 141 | 142 | // C version of WebRtcSpl_ScaleAndAddVectorsWithRound() for generic platforms. 143 | int WebRtcSpl_ScaleAndAddVectorsWithRoundC(const int16_t* in_vector1, 144 | int16_t in_vector1_scale, 145 | const int16_t* in_vector2, 146 | int16_t in_vector2_scale, 147 | int right_shifts, 148 | int16_t* out_vector, 149 | size_t length) { 150 | size_t i = 0; 151 | int round_value = (1 << right_shifts) >> 1; 152 | 153 | if (in_vector1 == NULL || in_vector2 == NULL || out_vector == NULL || 154 | length == 0 || right_shifts < 0) { 155 | return -1; 156 | } 157 | 158 | for (i = 0; i < length; i++) { 159 | out_vector[i] = (int16_t)(( 160 | in_vector1[i] * in_vector1_scale + in_vector2[i] * in_vector2_scale + 161 | round_value) >> right_shifts); 162 | } 163 | 164 | return 0; 165 | } 166 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/aec/aec_resampler.c: -------------------------------------------------------------------------------- 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 | /* Resamples a signal to an arbitrary rate. Used by the AEC to compensate for 12 | * clock skew by resampling the farend signal. 13 | */ 14 | 15 | #include "webrtc/modules/audio_processing/aec/aec_resampler.h" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "webrtc/modules/audio_processing/aec/aec_core.h" 23 | 24 | enum { 25 | kEstimateLengthFrames = 400 26 | }; 27 | 28 | typedef struct { 29 | float buffer[kResamplerBufferSize]; 30 | float position; 31 | 32 | int deviceSampleRateHz; 33 | int skewData[kEstimateLengthFrames]; 34 | int skewDataIndex; 35 | float skewEstimate; 36 | } AecResampler; 37 | 38 | static int EstimateSkew(const int* rawSkew, 39 | int size, 40 | int absLimit, 41 | float* skewEst); 42 | 43 | void* WebRtcAec_CreateResampler() { 44 | return malloc(sizeof(AecResampler)); 45 | } 46 | 47 | int WebRtcAec_InitResampler(void* resampInst, int deviceSampleRateHz) { 48 | AecResampler* obj = (AecResampler*)resampInst; 49 | memset(obj->buffer, 0, sizeof(obj->buffer)); 50 | obj->position = 0.0; 51 | 52 | obj->deviceSampleRateHz = deviceSampleRateHz; 53 | memset(obj->skewData, 0, sizeof(obj->skewData)); 54 | obj->skewDataIndex = 0; 55 | obj->skewEstimate = 0.0; 56 | 57 | return 0; 58 | } 59 | 60 | void WebRtcAec_FreeResampler(void* resampInst) { 61 | AecResampler* obj = (AecResampler*)resampInst; 62 | free(obj); 63 | } 64 | 65 | void WebRtcAec_ResampleLinear(void* resampInst, 66 | const float* inspeech, 67 | size_t size, 68 | float skew, 69 | float* outspeech, 70 | size_t* size_out) { 71 | AecResampler* obj = (AecResampler*)resampInst; 72 | 73 | float* y; 74 | float be, tnew; 75 | size_t tn, mm; 76 | 77 | assert(size <= 2 * FRAME_LEN); 78 | assert(resampInst != NULL); 79 | assert(inspeech != NULL); 80 | assert(outspeech != NULL); 81 | assert(size_out != NULL); 82 | 83 | // Add new frame data in lookahead 84 | memcpy(&obj->buffer[FRAME_LEN + kResamplingDelay], 85 | inspeech, 86 | size * sizeof(inspeech[0])); 87 | 88 | // Sample rate ratio 89 | be = 1 + skew; 90 | 91 | // Loop over input frame 92 | mm = 0; 93 | y = &obj->buffer[FRAME_LEN]; // Point at current frame 94 | 95 | tnew = be * mm + obj->position; 96 | tn = (size_t)tnew; 97 | 98 | while (tn < size) { 99 | 100 | // Interpolation 101 | outspeech[mm] = y[tn] + (tnew - tn) * (y[tn + 1] - y[tn]); 102 | mm++; 103 | 104 | tnew = be * mm + obj->position; 105 | tn = (int)tnew; 106 | } 107 | 108 | *size_out = mm; 109 | obj->position += (*size_out) * be - size; 110 | 111 | // Shift buffer 112 | memmove(obj->buffer, 113 | &obj->buffer[size], 114 | (kResamplerBufferSize - size) * sizeof(obj->buffer[0])); 115 | } 116 | 117 | int WebRtcAec_GetSkew(void* resampInst, int rawSkew, float* skewEst) { 118 | AecResampler* obj = (AecResampler*)resampInst; 119 | int err = 0; 120 | 121 | if (obj->skewDataIndex < kEstimateLengthFrames) { 122 | obj->skewData[obj->skewDataIndex] = rawSkew; 123 | obj->skewDataIndex++; 124 | } else if (obj->skewDataIndex == kEstimateLengthFrames) { 125 | err = EstimateSkew( 126 | obj->skewData, kEstimateLengthFrames, obj->deviceSampleRateHz, skewEst); 127 | obj->skewEstimate = *skewEst; 128 | obj->skewDataIndex++; 129 | } else { 130 | *skewEst = obj->skewEstimate; 131 | } 132 | 133 | return err; 134 | } 135 | 136 | int EstimateSkew(const int* rawSkew, 137 | int size, 138 | int deviceSampleRateHz, 139 | float* skewEst) { 140 | const int absLimitOuter = (int)(0.04f * deviceSampleRateHz); 141 | const int absLimitInner = (int)(0.0025f * deviceSampleRateHz); 142 | int i = 0; 143 | int n = 0; 144 | float rawAvg = 0; 145 | float err = 0; 146 | float rawAbsDev = 0; 147 | int upperLimit = 0; 148 | int lowerLimit = 0; 149 | float cumSum = 0; 150 | float x = 0; 151 | float x2 = 0; 152 | float y = 0; 153 | float xy = 0; 154 | float xAvg = 0; 155 | float denom = 0; 156 | float skew = 0; 157 | 158 | *skewEst = 0; // Set in case of error below. 159 | for (i = 0; i < size; i++) { 160 | if ((rawSkew[i] < absLimitOuter && rawSkew[i] > -absLimitOuter)) { 161 | n++; 162 | rawAvg += rawSkew[i]; 163 | } 164 | } 165 | 166 | if (n == 0) { 167 | return -1; 168 | } 169 | assert(n > 0); 170 | rawAvg /= n; 171 | 172 | for (i = 0; i < size; i++) { 173 | if ((rawSkew[i] < absLimitOuter && rawSkew[i] > -absLimitOuter)) { 174 | err = rawSkew[i] - rawAvg; 175 | rawAbsDev += err >= 0 ? err : -err; 176 | } 177 | } 178 | assert(n > 0); 179 | rawAbsDev /= n; 180 | upperLimit = (int)(rawAvg + 5 * rawAbsDev + 1); // +1 for ceiling. 181 | lowerLimit = (int)(rawAvg - 5 * rawAbsDev - 1); // -1 for floor. 182 | 183 | n = 0; 184 | for (i = 0; i < size; i++) { 185 | if ((rawSkew[i] < absLimitInner && rawSkew[i] > -absLimitInner) || 186 | (rawSkew[i] < upperLimit && rawSkew[i] > lowerLimit)) { 187 | n++; 188 | cumSum += rawSkew[i]; 189 | x += n; 190 | x2 += n * n; 191 | y += cumSum; 192 | xy += n * cumSum; 193 | } 194 | } 195 | 196 | if (n == 0) { 197 | return -1; 198 | } 199 | assert(n > 0); 200 | xAvg = x / n; 201 | denom = x2 - xAvg * x; 202 | 203 | if (denom != 0) { 204 | skew = (xy - xAvg * y) / denom; 205 | } 206 | 207 | *skewEst = skew; 208 | return 0; 209 | } 210 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/min_max_operations.c: -------------------------------------------------------------------------------- 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 file contains the implementation of functions 13 | * WebRtcSpl_MaxAbsValueW16C() 14 | * WebRtcSpl_MaxAbsValueW32C() 15 | * WebRtcSpl_MaxValueW16C() 16 | * WebRtcSpl_MaxValueW32C() 17 | * WebRtcSpl_MinValueW16C() 18 | * WebRtcSpl_MinValueW32C() 19 | * WebRtcSpl_MaxAbsIndexW16() 20 | * WebRtcSpl_MaxIndexW16() 21 | * WebRtcSpl_MaxIndexW32() 22 | * WebRtcSpl_MinIndexW16() 23 | * WebRtcSpl_MinIndexW32() 24 | * 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 31 | 32 | // TODO(bjorn/kma): Consolidate function pairs (e.g. combine 33 | // WebRtcSpl_MaxAbsValueW16C and WebRtcSpl_MaxAbsIndexW16 into a single one.) 34 | // TODO(kma): Move the next six functions into min_max_operations_c.c. 35 | 36 | // Maximum absolute value of word16 vector. C version for generic platforms. 37 | int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, size_t length) { 38 | size_t i = 0; 39 | int absolute = 0, maximum = 0; 40 | 41 | assert(length > 0); 42 | 43 | for (i = 0; i < length; i++) { 44 | absolute = abs((int)vector[i]); 45 | 46 | if (absolute > maximum) { 47 | maximum = absolute; 48 | } 49 | } 50 | 51 | // Guard the case for abs(-32768). 52 | if (maximum > WEBRTC_SPL_WORD16_MAX) { 53 | maximum = WEBRTC_SPL_WORD16_MAX; 54 | } 55 | 56 | return (int16_t)maximum; 57 | } 58 | 59 | // Maximum absolute value of word32 vector. C version for generic platforms. 60 | int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, size_t length) { 61 | // Use uint32_t for the local variables, to accommodate the return value 62 | // of abs(0x80000000), which is 0x80000000. 63 | 64 | uint32_t absolute = 0, maximum = 0; 65 | size_t i = 0; 66 | 67 | assert(length > 0); 68 | 69 | for (i = 0; i < length; i++) { 70 | absolute = abs((int)vector[i]); 71 | if (absolute > maximum) { 72 | maximum = absolute; 73 | } 74 | } 75 | 76 | maximum = WEBRTC_SPL_MIN(maximum, WEBRTC_SPL_WORD32_MAX); 77 | 78 | return (int32_t)maximum; 79 | } 80 | 81 | // Maximum value of word16 vector. C version for generic platforms. 82 | int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, size_t length) { 83 | int16_t maximum = WEBRTC_SPL_WORD16_MIN; 84 | size_t i = 0; 85 | 86 | assert(length > 0); 87 | 88 | for (i = 0; i < length; i++) { 89 | if (vector[i] > maximum) 90 | maximum = vector[i]; 91 | } 92 | return maximum; 93 | } 94 | 95 | // Maximum value of word32 vector. C version for generic platforms. 96 | int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, size_t length) { 97 | int32_t maximum = WEBRTC_SPL_WORD32_MIN; 98 | size_t i = 0; 99 | 100 | assert(length > 0); 101 | 102 | for (i = 0; i < length; i++) { 103 | if (vector[i] > maximum) 104 | maximum = vector[i]; 105 | } 106 | return maximum; 107 | } 108 | 109 | // Minimum value of word16 vector. C version for generic platforms. 110 | int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, size_t length) { 111 | int16_t minimum = WEBRTC_SPL_WORD16_MAX; 112 | size_t i = 0; 113 | 114 | assert(length > 0); 115 | 116 | for (i = 0; i < length; i++) { 117 | if (vector[i] < minimum) 118 | minimum = vector[i]; 119 | } 120 | return minimum; 121 | } 122 | 123 | // Minimum value of word32 vector. C version for generic platforms. 124 | int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, size_t length) { 125 | int32_t minimum = WEBRTC_SPL_WORD32_MAX; 126 | size_t i = 0; 127 | 128 | assert(length > 0); 129 | 130 | for (i = 0; i < length; i++) { 131 | if (vector[i] < minimum) 132 | minimum = vector[i]; 133 | } 134 | return minimum; 135 | } 136 | 137 | // Index of maximum absolute value in a word16 vector. 138 | size_t WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length) { 139 | // Use type int for local variables, to accomodate the value of abs(-32768). 140 | 141 | size_t i = 0, index = 0; 142 | int absolute = 0, maximum = 0; 143 | 144 | assert(length > 0); 145 | 146 | for (i = 0; i < length; i++) { 147 | absolute = abs((int)vector[i]); 148 | 149 | if (absolute > maximum) { 150 | maximum = absolute; 151 | index = i; 152 | } 153 | } 154 | 155 | return index; 156 | } 157 | 158 | // Index of maximum value in a word16 vector. 159 | size_t WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length) { 160 | size_t i = 0, index = 0; 161 | int16_t maximum = WEBRTC_SPL_WORD16_MIN; 162 | 163 | assert(length > 0); 164 | 165 | for (i = 0; i < length; i++) { 166 | if (vector[i] > maximum) { 167 | maximum = vector[i]; 168 | index = i; 169 | } 170 | } 171 | 172 | return index; 173 | } 174 | 175 | // Index of maximum value in a word32 vector. 176 | size_t WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length) { 177 | size_t i = 0, index = 0; 178 | int32_t maximum = WEBRTC_SPL_WORD32_MIN; 179 | 180 | assert(length > 0); 181 | 182 | for (i = 0; i < length; i++) { 183 | if (vector[i] > maximum) { 184 | maximum = vector[i]; 185 | index = i; 186 | } 187 | } 188 | 189 | return index; 190 | } 191 | 192 | // Index of minimum value in a word16 vector. 193 | size_t WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length) { 194 | size_t i = 0, index = 0; 195 | int16_t minimum = WEBRTC_SPL_WORD16_MAX; 196 | 197 | assert(length > 0); 198 | 199 | for (i = 0; i < length; i++) { 200 | if (vector[i] < minimum) { 201 | minimum = vector[i]; 202 | index = i; 203 | } 204 | } 205 | 206 | return index; 207 | } 208 | 209 | // Index of minimum value in a word32 vector. 210 | size_t WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length) { 211 | size_t i = 0, index = 0; 212 | int32_t minimum = WEBRTC_SPL_WORD32_MAX; 213 | 214 | assert(length > 0); 215 | 216 | for (i = 0; i < length; i++) { 217 | if (vector[i] < minimum) { 218 | minimum = vector[i]; 219 | index = i; 220 | } 221 | } 222 | 223 | return index; 224 | } 225 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/cross_correlation_mips.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 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 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 12 | 13 | void WebRtcSpl_CrossCorrelation_mips(int32_t* cross_correlation, 14 | const int16_t* seq1, 15 | const int16_t* seq2, 16 | size_t dim_seq, 17 | size_t dim_cross_correlation, 18 | int right_shifts, 19 | int step_seq2) { 20 | 21 | int32_t t0 = 0, t1 = 0, t2 = 0, t3 = 0, sum = 0; 22 | int16_t *pseq2 = NULL; 23 | int16_t *pseq1 = NULL; 24 | int16_t *pseq1_0 = (int16_t*)&seq1[0]; 25 | int16_t *pseq2_0 = (int16_t*)&seq2[0]; 26 | int k = 0; 27 | 28 | __asm __volatile ( 29 | ".set push \n\t" 30 | ".set noreorder \n\t" 31 | "sll %[step_seq2], %[step_seq2], 1 \n\t" 32 | "andi %[t0], %[dim_seq], 1 \n\t" 33 | "bgtz %[t0], 3f \n\t" 34 | " nop \n\t" 35 | "1: \n\t" 36 | "move %[pseq1], %[pseq1_0] \n\t" 37 | "move %[pseq2], %[pseq2_0] \n\t" 38 | "sra %[k], %[dim_seq], 1 \n\t" 39 | "addiu %[dim_cc], %[dim_cc], -1 \n\t" 40 | "xor %[sum], %[sum], %[sum] \n\t" 41 | "2: \n\t" 42 | "lh %[t0], 0(%[pseq1]) \n\t" 43 | "lh %[t1], 0(%[pseq2]) \n\t" 44 | "lh %[t2], 2(%[pseq1]) \n\t" 45 | "lh %[t3], 2(%[pseq2]) \n\t" 46 | "mul %[t0], %[t0], %[t1] \n\t" 47 | "addiu %[k], %[k], -1 \n\t" 48 | "mul %[t2], %[t2], %[t3] \n\t" 49 | "addiu %[pseq1], %[pseq1], 4 \n\t" 50 | "addiu %[pseq2], %[pseq2], 4 \n\t" 51 | "srav %[t0], %[t0], %[right_shifts] \n\t" 52 | "addu %[sum], %[sum], %[t0] \n\t" 53 | "srav %[t2], %[t2], %[right_shifts] \n\t" 54 | "bgtz %[k], 2b \n\t" 55 | " addu %[sum], %[sum], %[t2] \n\t" 56 | "addu %[pseq2_0], %[pseq2_0], %[step_seq2] \n\t" 57 | "sw %[sum], 0(%[cc]) \n\t" 58 | "bgtz %[dim_cc], 1b \n\t" 59 | " addiu %[cc], %[cc], 4 \n\t" 60 | "b 6f \n\t" 61 | " nop \n\t" 62 | "3: \n\t" 63 | "move %[pseq1], %[pseq1_0] \n\t" 64 | "move %[pseq2], %[pseq2_0] \n\t" 65 | "sra %[k], %[dim_seq], 1 \n\t" 66 | "addiu %[dim_cc], %[dim_cc], -1 \n\t" 67 | "beqz %[k], 5f \n\t" 68 | " xor %[sum], %[sum], %[sum] \n\t" 69 | "4: \n\t" 70 | "lh %[t0], 0(%[pseq1]) \n\t" 71 | "lh %[t1], 0(%[pseq2]) \n\t" 72 | "lh %[t2], 2(%[pseq1]) \n\t" 73 | "lh %[t3], 2(%[pseq2]) \n\t" 74 | "mul %[t0], %[t0], %[t1] \n\t" 75 | "addiu %[k], %[k], -1 \n\t" 76 | "mul %[t2], %[t2], %[t3] \n\t" 77 | "addiu %[pseq1], %[pseq1], 4 \n\t" 78 | "addiu %[pseq2], %[pseq2], 4 \n\t" 79 | "srav %[t0], %[t0], %[right_shifts] \n\t" 80 | "addu %[sum], %[sum], %[t0] \n\t" 81 | "srav %[t2], %[t2], %[right_shifts] \n\t" 82 | "bgtz %[k], 4b \n\t" 83 | " addu %[sum], %[sum], %[t2] \n\t" 84 | "5: \n\t" 85 | "lh %[t0], 0(%[pseq1]) \n\t" 86 | "lh %[t1], 0(%[pseq2]) \n\t" 87 | "mul %[t0], %[t0], %[t1] \n\t" 88 | "srav %[t0], %[t0], %[right_shifts] \n\t" 89 | "addu %[sum], %[sum], %[t0] \n\t" 90 | "addu %[pseq2_0], %[pseq2_0], %[step_seq2] \n\t" 91 | "sw %[sum], 0(%[cc]) \n\t" 92 | "bgtz %[dim_cc], 3b \n\t" 93 | " addiu %[cc], %[cc], 4 \n\t" 94 | "6: \n\t" 95 | ".set pop \n\t" 96 | : [step_seq2] "+r" (step_seq2), [t0] "=&r" (t0), [t1] "=&r" (t1), 97 | [t2] "=&r" (t2), [t3] "=&r" (t3), [pseq1] "=&r" (pseq1), 98 | [pseq2] "=&r" (pseq2), [pseq1_0] "+r" (pseq1_0), [pseq2_0] "+r" (pseq2_0), 99 | [k] "=&r" (k), [dim_cc] "+r" (dim_cross_correlation), [sum] "=&r" (sum), 100 | [cc] "+r" (cross_correlation) 101 | : [dim_seq] "r" (dim_seq), [right_shifts] "r" (right_shifts) 102 | : "hi", "lo", "memory" 103 | ); 104 | } 105 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/resample_48khz.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | /* 13 | * This file contains resampling functions between 48 kHz and nb/wb. 14 | * The description header can be found in signal_processing_library.h 15 | * 16 | */ 17 | 18 | #include 19 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 20 | #include "webrtc/common_audio/signal_processing/resample_by_2_internal.h" 21 | 22 | //////////////////////////// 23 | ///// 48 kHz -> 16 kHz ///// 24 | //////////////////////////// 25 | 26 | // 48 -> 16 resampler 27 | void WebRtcSpl_Resample48khzTo16khz(const int16_t* in, int16_t* out, 28 | WebRtcSpl_State48khzTo16khz* state, int32_t* tmpmem) 29 | { 30 | ///// 48 --> 48(LP) ///// 31 | // int16_t in[480] 32 | // int32_t out[480] 33 | ///// 34 | WebRtcSpl_LPBy2ShortToInt(in, 480, tmpmem + 16, state->S_48_48); 35 | 36 | ///// 48 --> 32 ///// 37 | // int32_t in[480] 38 | // int32_t out[320] 39 | ///// 40 | // copy state to and from input array 41 | memcpy(tmpmem + 8, state->S_48_32, 8 * sizeof(int32_t)); 42 | memcpy(state->S_48_32, tmpmem + 488, 8 * sizeof(int32_t)); 43 | WebRtcSpl_Resample48khzTo32khz(tmpmem + 8, tmpmem, 160); 44 | 45 | ///// 32 --> 16 ///// 46 | // int32_t in[320] 47 | // int16_t out[160] 48 | ///// 49 | WebRtcSpl_DownBy2IntToShort(tmpmem, 320, out, state->S_32_16); 50 | } 51 | 52 | // initialize state of 48 -> 16 resampler 53 | void WebRtcSpl_ResetResample48khzTo16khz(WebRtcSpl_State48khzTo16khz* state) 54 | { 55 | memset(state->S_48_48, 0, 16 * sizeof(int32_t)); 56 | memset(state->S_48_32, 0, 8 * sizeof(int32_t)); 57 | memset(state->S_32_16, 0, 8 * sizeof(int32_t)); 58 | } 59 | 60 | //////////////////////////// 61 | ///// 16 kHz -> 48 kHz ///// 62 | //////////////////////////// 63 | 64 | // 16 -> 48 resampler 65 | void WebRtcSpl_Resample16khzTo48khz(const int16_t* in, int16_t* out, 66 | WebRtcSpl_State16khzTo48khz* state, int32_t* tmpmem) 67 | { 68 | ///// 16 --> 32 ///// 69 | // int16_t in[160] 70 | // int32_t out[320] 71 | ///// 72 | WebRtcSpl_UpBy2ShortToInt(in, 160, tmpmem + 16, state->S_16_32); 73 | 74 | ///// 32 --> 24 ///// 75 | // int32_t in[320] 76 | // int32_t out[240] 77 | // copy state to and from input array 78 | ///// 79 | memcpy(tmpmem + 8, state->S_32_24, 8 * sizeof(int32_t)); 80 | memcpy(state->S_32_24, tmpmem + 328, 8 * sizeof(int32_t)); 81 | WebRtcSpl_Resample32khzTo24khz(tmpmem + 8, tmpmem, 80); 82 | 83 | ///// 24 --> 48 ///// 84 | // int32_t in[240] 85 | // int16_t out[480] 86 | ///// 87 | WebRtcSpl_UpBy2IntToShort(tmpmem, 240, out, state->S_24_48); 88 | } 89 | 90 | // initialize state of 16 -> 48 resampler 91 | void WebRtcSpl_ResetResample16khzTo48khz(WebRtcSpl_State16khzTo48khz* state) 92 | { 93 | memset(state->S_16_32, 0, 8 * sizeof(int32_t)); 94 | memset(state->S_32_24, 0, 8 * sizeof(int32_t)); 95 | memset(state->S_24_48, 0, 8 * sizeof(int32_t)); 96 | } 97 | 98 | //////////////////////////// 99 | ///// 48 kHz -> 8 kHz ///// 100 | //////////////////////////// 101 | 102 | // 48 -> 8 resampler 103 | void WebRtcSpl_Resample48khzTo8khz(const int16_t* in, int16_t* out, 104 | WebRtcSpl_State48khzTo8khz* state, int32_t* tmpmem) 105 | { 106 | ///// 48 --> 24 ///// 107 | // int16_t in[480] 108 | // int32_t out[240] 109 | ///// 110 | WebRtcSpl_DownBy2ShortToInt(in, 480, tmpmem + 256, state->S_48_24); 111 | 112 | ///// 24 --> 24(LP) ///// 113 | // int32_t in[240] 114 | // int32_t out[240] 115 | ///// 116 | WebRtcSpl_LPBy2IntToInt(tmpmem + 256, 240, tmpmem + 16, state->S_24_24); 117 | 118 | ///// 24 --> 16 ///// 119 | // int32_t in[240] 120 | // int32_t out[160] 121 | ///// 122 | // copy state to and from input array 123 | memcpy(tmpmem + 8, state->S_24_16, 8 * sizeof(int32_t)); 124 | memcpy(state->S_24_16, tmpmem + 248, 8 * sizeof(int32_t)); 125 | WebRtcSpl_Resample48khzTo32khz(tmpmem + 8, tmpmem, 80); 126 | 127 | ///// 16 --> 8 ///// 128 | // int32_t in[160] 129 | // int16_t out[80] 130 | ///// 131 | WebRtcSpl_DownBy2IntToShort(tmpmem, 160, out, state->S_16_8); 132 | } 133 | 134 | // initialize state of 48 -> 8 resampler 135 | void WebRtcSpl_ResetResample48khzTo8khz(WebRtcSpl_State48khzTo8khz* state) 136 | { 137 | memset(state->S_48_24, 0, 8 * sizeof(int32_t)); 138 | memset(state->S_24_24, 0, 16 * sizeof(int32_t)); 139 | memset(state->S_24_16, 0, 8 * sizeof(int32_t)); 140 | memset(state->S_16_8, 0, 8 * sizeof(int32_t)); 141 | } 142 | 143 | //////////////////////////// 144 | ///// 8 kHz -> 48 kHz ///// 145 | //////////////////////////// 146 | 147 | // 8 -> 48 resampler 148 | void WebRtcSpl_Resample8khzTo48khz(const int16_t* in, int16_t* out, 149 | WebRtcSpl_State8khzTo48khz* state, int32_t* tmpmem) 150 | { 151 | ///// 8 --> 16 ///// 152 | // int16_t in[80] 153 | // int32_t out[160] 154 | ///// 155 | WebRtcSpl_UpBy2ShortToInt(in, 80, tmpmem + 264, state->S_8_16); 156 | 157 | ///// 16 --> 12 ///// 158 | // int32_t in[160] 159 | // int32_t out[120] 160 | ///// 161 | // copy state to and from input array 162 | memcpy(tmpmem + 256, state->S_16_12, 8 * sizeof(int32_t)); 163 | memcpy(state->S_16_12, tmpmem + 416, 8 * sizeof(int32_t)); 164 | WebRtcSpl_Resample32khzTo24khz(tmpmem + 256, tmpmem + 240, 40); 165 | 166 | ///// 12 --> 24 ///// 167 | // int32_t in[120] 168 | // int16_t out[240] 169 | ///// 170 | WebRtcSpl_UpBy2IntToInt(tmpmem + 240, 120, tmpmem, state->S_12_24); 171 | 172 | ///// 24 --> 48 ///// 173 | // int32_t in[240] 174 | // int16_t out[480] 175 | ///// 176 | WebRtcSpl_UpBy2IntToShort(tmpmem, 240, out, state->S_24_48); 177 | } 178 | 179 | // initialize state of 8 -> 48 resampler 180 | void WebRtcSpl_ResetResample8khzTo48khz(WebRtcSpl_State8khzTo48khz* state) 181 | { 182 | memset(state->S_8_16, 0, 8 * sizeof(int32_t)); 183 | memset(state->S_16_12, 0, 8 * sizeof(int32_t)); 184 | memset(state->S_12_24, 0, 8 * sizeof(int32_t)); 185 | memset(state->S_24_48, 0, 8 * sizeof(int32_t)); 186 | } 187 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/resample_by_2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | /* 13 | * This file contains the resampling by two functions. 14 | * The description header can be found in signal_processing_library.h 15 | * 16 | */ 17 | 18 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 19 | 20 | #ifdef WEBRTC_ARCH_ARM_V7 21 | 22 | // allpass filter coefficients. 23 | static const uint32_t kResampleAllpass1[3] = {3284, 24441, 49528 << 15}; 24 | static const uint32_t kResampleAllpass2[3] = 25 | {12199, 37471 << 15, 60255 << 15}; 26 | 27 | // Multiply two 32-bit values and accumulate to another input value. 28 | // Return: state + ((diff * tbl_value) >> 16) 29 | 30 | static __inline int32_t MUL_ACCUM_1(int32_t tbl_value, 31 | int32_t diff, 32 | int32_t state) { 33 | int32_t result; 34 | __asm __volatile ("smlawb %0, %1, %2, %3": "=r"(result): "r"(diff), 35 | "r"(tbl_value), "r"(state)); 36 | return result; 37 | } 38 | 39 | // Multiply two 32-bit values and accumulate to another input value. 40 | // Return: Return: state + (((diff << 1) * tbl_value) >> 32) 41 | // 42 | // The reason to introduce this function is that, in case we can't use smlawb 43 | // instruction (in MUL_ACCUM_1) due to input value range, we can still use 44 | // smmla to save some cycles. 45 | 46 | static __inline int32_t MUL_ACCUM_2(int32_t tbl_value, 47 | int32_t diff, 48 | int32_t state) { 49 | int32_t result; 50 | __asm __volatile ("smmla %0, %1, %2, %3": "=r"(result): "r"(diff << 1), 51 | "r"(tbl_value), "r"(state)); 52 | return result; 53 | } 54 | 55 | #else 56 | 57 | // allpass filter coefficients. 58 | static const uint16_t kResampleAllpass1[3] = {3284, 24441, 49528}; 59 | static const uint16_t kResampleAllpass2[3] = {12199, 37471, 60255}; 60 | 61 | // Multiply a 32-bit value with a 16-bit value and accumulate to another input: 62 | #define MUL_ACCUM_1(a, b, c) WEBRTC_SPL_SCALEDIFF32(a, b, c) 63 | #define MUL_ACCUM_2(a, b, c) WEBRTC_SPL_SCALEDIFF32(a, b, c) 64 | 65 | #endif // WEBRTC_ARCH_ARM_V7 66 | 67 | 68 | // decimator 69 | #if !defined(MIPS32_LE) 70 | void WebRtcSpl_DownsampleBy2(const int16_t* in, size_t len, 71 | int16_t* out, int32_t* filtState) { 72 | int32_t tmp1, tmp2, diff, in32, out32; 73 | size_t i; 74 | 75 | register int32_t state0 = filtState[0]; 76 | register int32_t state1 = filtState[1]; 77 | register int32_t state2 = filtState[2]; 78 | register int32_t state3 = filtState[3]; 79 | register int32_t state4 = filtState[4]; 80 | register int32_t state5 = filtState[5]; 81 | register int32_t state6 = filtState[6]; 82 | register int32_t state7 = filtState[7]; 83 | 84 | for (i = (len >> 1); i > 0; i--) { 85 | // lower allpass filter 86 | in32 = (int32_t)(*in++) << 10; 87 | diff = in32 - state1; 88 | tmp1 = MUL_ACCUM_1(kResampleAllpass2[0], diff, state0); 89 | state0 = in32; 90 | diff = tmp1 - state2; 91 | tmp2 = MUL_ACCUM_2(kResampleAllpass2[1], diff, state1); 92 | state1 = tmp1; 93 | diff = tmp2 - state3; 94 | state3 = MUL_ACCUM_2(kResampleAllpass2[2], diff, state2); 95 | state2 = tmp2; 96 | 97 | // upper allpass filter 98 | in32 = (int32_t)(*in++) << 10; 99 | diff = in32 - state5; 100 | tmp1 = MUL_ACCUM_1(kResampleAllpass1[0], diff, state4); 101 | state4 = in32; 102 | diff = tmp1 - state6; 103 | tmp2 = MUL_ACCUM_1(kResampleAllpass1[1], diff, state5); 104 | state5 = tmp1; 105 | diff = tmp2 - state7; 106 | state7 = MUL_ACCUM_2(kResampleAllpass1[2], diff, state6); 107 | state6 = tmp2; 108 | 109 | // add two allpass outputs, divide by two and round 110 | out32 = (state3 + state7 + 1024) >> 11; 111 | 112 | // limit amplitude to prevent wrap-around, and write to output array 113 | *out++ = WebRtcSpl_SatW32ToW16(out32); 114 | } 115 | 116 | filtState[0] = state0; 117 | filtState[1] = state1; 118 | filtState[2] = state2; 119 | filtState[3] = state3; 120 | filtState[4] = state4; 121 | filtState[5] = state5; 122 | filtState[6] = state6; 123 | filtState[7] = state7; 124 | } 125 | #endif // #if defined(MIPS32_LE) 126 | 127 | 128 | void WebRtcSpl_UpsampleBy2(const int16_t* in, size_t len, 129 | int16_t* out, int32_t* filtState) { 130 | int32_t tmp1, tmp2, diff, in32, out32; 131 | size_t i; 132 | 133 | register int32_t state0 = filtState[0]; 134 | register int32_t state1 = filtState[1]; 135 | register int32_t state2 = filtState[2]; 136 | register int32_t state3 = filtState[3]; 137 | register int32_t state4 = filtState[4]; 138 | register int32_t state5 = filtState[5]; 139 | register int32_t state6 = filtState[6]; 140 | register int32_t state7 = filtState[7]; 141 | 142 | for (i = len; i > 0; i--) { 143 | // lower allpass filter 144 | in32 = (int32_t)(*in++) << 10; 145 | diff = in32 - state1; 146 | tmp1 = MUL_ACCUM_1(kResampleAllpass1[0], diff, state0); 147 | state0 = in32; 148 | diff = tmp1 - state2; 149 | tmp2 = MUL_ACCUM_1(kResampleAllpass1[1], diff, state1); 150 | state1 = tmp1; 151 | diff = tmp2 - state3; 152 | state3 = MUL_ACCUM_2(kResampleAllpass1[2], diff, state2); 153 | state2 = tmp2; 154 | 155 | // round; limit amplitude to prevent wrap-around; write to output array 156 | out32 = (state3 + 512) >> 10; 157 | *out++ = WebRtcSpl_SatW32ToW16(out32); 158 | 159 | // upper allpass filter 160 | diff = in32 - state5; 161 | tmp1 = MUL_ACCUM_1(kResampleAllpass2[0], diff, state4); 162 | state4 = in32; 163 | diff = tmp1 - state6; 164 | tmp2 = MUL_ACCUM_2(kResampleAllpass2[1], diff, state5); 165 | state5 = tmp1; 166 | diff = tmp2 - state7; 167 | state7 = MUL_ACCUM_2(kResampleAllpass2[2], diff, state6); 168 | state6 = tmp2; 169 | 170 | // round; limit amplitude to prevent wrap-around; write to output array 171 | out32 = (state7 + 512) >> 10; 172 | *out++ = WebRtcSpl_SatW32ToW16(out32); 173 | } 174 | 175 | filtState[0] = state0; 176 | filtState[1] = state1; 177 | filtState[2] = state2; 178 | filtState[3] = state3; 179 | filtState[4] = state4; 180 | filtState[5] = state5; 181 | filtState[6] = state6; 182 | filtState[7] = state7; 183 | } 184 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/common_audio/signal_processing/randomization_functions.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | /* 13 | * This file contains implementations of the randomization functions 14 | * WebRtcSpl_RandU() 15 | * WebRtcSpl_RandN() 16 | * WebRtcSpl_RandUArray() 17 | * 18 | * The description header can be found in signal_processing_library.h 19 | * 20 | */ 21 | 22 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" 23 | 24 | static const uint32_t kMaxSeedUsed = 0x80000000; 25 | 26 | static const int16_t kRandNTable[] = { 27 | 9178, -7260, 40, 10189, 4894, -3531, -13779, 14764, 28 | -4008, -8884, -8990, 1008, 7368, 5184, 3251, -5817, 29 | -9786, 5963, 1770, 8066, -7135, 10772, -2298, 1361, 30 | 6484, 2241, -8633, 792, 199, -3344, 6553, -10079, 31 | -15040, 95, 11608, -12469, 14161, -4176, 2476, 6403, 32 | 13685, -16005, 6646, 2239, 10916, -3004, -602, -3141, 33 | 2142, 14144, -5829, 5305, 8209, 4713, 2697, -5112, 34 | 16092, -1210, -2891, -6631, -5360, -11878, -6781, -2739, 35 | -6392, 536, 10923, 10872, 5059, -4748, -7770, 5477, 36 | 38, -1025, -2892, 1638, 6304, 14375, -11028, 1553, 37 | -1565, 10762, -393, 4040, 5257, 12310, 6554, -4799, 38 | 4899, -6354, 1603, -1048, -2220, 8247, -186, -8944, 39 | -12004, 2332, 4801, -4933, 6371, 131, 8614, -5927, 40 | -8287, -22760, 4033, -15162, 3385, 3246, 3153, -5250, 41 | 3766, 784, 6494, -62, 3531, -1582, 15572, 662, 42 | -3952, -330, -3196, 669, 7236, -2678, -6569, 23319, 43 | -8645, -741, 14830, -15976, 4903, 315, -11342, 10311, 44 | 1858, -7777, 2145, 5436, 5677, -113, -10033, 826, 45 | -1353, 17210, 7768, 986, -1471, 8291, -4982, 8207, 46 | -14911, -6255, -2449, -11881, -7059, -11703, -4338, 8025, 47 | 7538, -2823, -12490, 9470, -1613, -2529, -10092, -7807, 48 | 9480, 6970, -12844, 5123, 3532, 4816, 4803, -8455, 49 | -5045, 14032, -4378, -1643, 5756, -11041, -2732, -16618, 50 | -6430, -18375, -3320, 6098, 5131, -4269, -8840, 2482, 51 | -7048, 1547, -21890, -6505, -7414, -424, -11722, 7955, 52 | 1653, -17299, 1823, 473, -9232, 3337, 1111, 873, 53 | 4018, -8982, 9889, 3531, -11763, -3799, 7373, -4539, 54 | 3231, 7054, -8537, 7616, 6244, 16635, 447, -2915, 55 | 13967, 705, -2669, -1520, -1771, -16188, 5956, 5117, 56 | 6371, -9936, -1448, 2480, 5128, 7550, -8130, 5236, 57 | 8213, -6443, 7707, -1950, -13811, 7218, 7031, -3883, 58 | 67, 5731, -2874, 13480, -3743, 9298, -3280, 3552, 59 | -4425, -18, -3785, -9988, -5357, 5477, -11794, 2117, 60 | 1416, -9935, 3376, 802, -5079, -8243, 12652, 66, 61 | 3653, -2368, 6781, -21895, -7227, 2487, 7839, -385, 62 | 6646, -7016, -4658, 5531, -1705, 834, 129, 3694, 63 | -1343, 2238, -22640, -6417, -11139, 11301, -2945, -3494, 64 | -5626, 185, -3615, -2041, -7972, -3106, -60, -23497, 65 | -1566, 17064, 3519, 2518, 304, -6805, -10269, 2105, 66 | 1936, -426, -736, -8122, -1467, 4238, -6939, -13309, 67 | 360, 7402, -7970, 12576, 3287, 12194, -6289, -16006, 68 | 9171, 4042, -9193, 9123, -2512, 6388, -4734, -8739, 69 | 1028, -5406, -1696, 5889, -666, -4736, 4971, 3565, 70 | 9362, -6292, 3876, -3652, -19666, 7523, -4061, 391, 71 | -11773, 7502, -3763, 4929, -9478, 13278, 2805, 4496, 72 | 7814, 16419, 12455, -14773, 2127, -2746, 3763, 4847, 73 | 3698, 6978, 4751, -6957, -3581, -45, 6252, 1513, 74 | -4797, -7925, 11270, 16188, -2359, -5269, 9376, -10777, 75 | 7262, 20031, -6515, -2208, -5353, 8085, -1341, -1303, 76 | 7333, 5576, 3625, 5763, -7931, 9833, -3371, -10305, 77 | 6534, -13539, -9971, 997, 8464, -4064, -1495, 1857, 78 | 13624, 5458, 9490, -11086, -4524, 12022, -550, -198, 79 | 408, -8455, -7068, 10289, 9712, -3366, 9028, -7621, 80 | -5243, 2362, 6909, 4672, -4933, -1799, 4709, -4563, 81 | -62, -566, 1624, -7010, 14730, -17791, -3697, -2344, 82 | -1741, 7099, -9509, -6855, -1989, 3495, -2289, 2031, 83 | 12784, 891, 14189, -3963, -5683, 421, -12575, 1724, 84 | -12682, -5970, -8169, 3143, -1824, -5488, -5130, 8536, 85 | 12799, 794, 5738, 3459, -11689, -258, -3738, -3775, 86 | -8742, 2333, 8312, -9383, 10331, 13119, 8398, 10644, 87 | -19433, -6446, -16277, -11793, 16284, 9345, 15222, 15834, 88 | 2009, -7349, 130, -14547, 338, -5998, 3337, 21492, 89 | 2406, 7703, -951, 11196, -564, 3406, 2217, 4806, 90 | 2374, -5797, 11839, 8940, -11874, 18213, 2855, 10492 91 | }; 92 | 93 | static uint32_t IncreaseSeed(uint32_t* seed) { 94 | seed[0] = (seed[0] * ((int32_t)69069) + 1) & (kMaxSeedUsed - 1); 95 | return seed[0]; 96 | } 97 | 98 | int16_t WebRtcSpl_RandU(uint32_t* seed) { 99 | return (int16_t)(IncreaseSeed(seed) >> 16); 100 | } 101 | 102 | int16_t WebRtcSpl_RandN(uint32_t* seed) { 103 | return kRandNTable[IncreaseSeed(seed) >> 23]; 104 | } 105 | 106 | // Creates an array of uniformly distributed variables. 107 | int16_t WebRtcSpl_RandUArray(int16_t* vector, 108 | int16_t vector_length, 109 | uint32_t* seed) { 110 | int i; 111 | for (i = 0; i < vector_length; i++) { 112 | vector[i] = WebRtcSpl_RandU(seed); 113 | } 114 | return vector_length; 115 | } 116 | -------------------------------------------------------------------------------- /webrtc-android-jni/jni/src/webrtc/modules/audio_processing/ns/ns_core.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 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 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_NS_NS_CORE_H_ 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_NS_NS_CORE_H_ 13 | 14 | #include "webrtc/modules/audio_processing/ns/defines.h" 15 | 16 | typedef struct NSParaExtract_ { 17 | // Bin size of histogram. 18 | float binSizeLrt; 19 | float binSizeSpecFlat; 20 | float binSizeSpecDiff; 21 | // Range of histogram over which LRT threshold is computed. 22 | float rangeAvgHistLrt; 23 | // Scale parameters: multiply dominant peaks of the histograms by scale factor 24 | // to obtain thresholds for prior model. 25 | float factor1ModelPars; // For LRT and spectral difference. 26 | float factor2ModelPars; // For spectral_flatness: used when noise is flatter 27 | // than speech. 28 | // Peak limit for spectral flatness (varies between 0 and 1). 29 | float thresPosSpecFlat; 30 | // Limit on spacing of two highest peaks in histogram: spacing determined by 31 | // bin size. 32 | float limitPeakSpacingSpecFlat; 33 | float limitPeakSpacingSpecDiff; 34 | // Limit on relevance of second peak. 35 | float limitPeakWeightsSpecFlat; 36 | float limitPeakWeightsSpecDiff; 37 | // Limit on fluctuation of LRT feature. 38 | float thresFluctLrt; 39 | // Limit on the max and min values for the feature thresholds. 40 | float maxLrt; 41 | float minLrt; 42 | float maxSpecFlat; 43 | float minSpecFlat; 44 | float maxSpecDiff; 45 | float minSpecDiff; 46 | // Criteria of weight of histogram peak to accept/reject feature. 47 | int thresWeightSpecFlat; 48 | int thresWeightSpecDiff; 49 | 50 | } NSParaExtract; 51 | 52 | typedef struct NoiseSuppressionC_ { 53 | uint32_t fs; 54 | size_t blockLen; 55 | size_t windShift; 56 | size_t anaLen; 57 | size_t magnLen; 58 | int aggrMode; 59 | const float* window; 60 | float analyzeBuf[ANAL_BLOCKL_MAX]; 61 | float dataBuf[ANAL_BLOCKL_MAX]; 62 | float syntBuf[ANAL_BLOCKL_MAX]; 63 | 64 | int initFlag; 65 | // Parameters for quantile noise estimation. 66 | float density[SIMULT * HALF_ANAL_BLOCKL]; 67 | float lquantile[SIMULT * HALF_ANAL_BLOCKL]; 68 | float quantile[HALF_ANAL_BLOCKL]; 69 | int counter[SIMULT]; 70 | int updates; 71 | // Parameters for Wiener filter. 72 | float smooth[HALF_ANAL_BLOCKL]; 73 | float overdrive; 74 | float denoiseBound; 75 | int gainmap; 76 | // FFT work arrays. 77 | size_t ip[IP_LENGTH]; 78 | float wfft[W_LENGTH]; 79 | 80 | // Parameters for new method: some not needed, will reduce/cleanup later. 81 | int32_t blockInd; // Frame index counter. 82 | int modelUpdatePars[4]; // Parameters for updating or estimating. 83 | // Thresholds/weights for prior model. 84 | float priorModelPars[7]; // Parameters for prior model. 85 | float noise[HALF_ANAL_BLOCKL]; // Noise spectrum from current frame. 86 | float noisePrev[HALF_ANAL_BLOCKL]; // Noise spectrum from previous frame. 87 | // Magnitude spectrum of previous analyze frame. 88 | float magnPrevAnalyze[HALF_ANAL_BLOCKL]; 89 | // Magnitude spectrum of previous process frame. 90 | float magnPrevProcess[HALF_ANAL_BLOCKL]; 91 | float logLrtTimeAvg[HALF_ANAL_BLOCKL]; // Log LRT factor with time-smoothing. 92 | float priorSpeechProb; // Prior speech/noise probability. 93 | float featureData[7]; 94 | // Conservative noise spectrum estimate. 95 | float magnAvgPause[HALF_ANAL_BLOCKL]; 96 | float signalEnergy; // Energy of |magn|. 97 | float sumMagn; 98 | float whiteNoiseLevel; // Initial noise estimate. 99 | float initMagnEst[HALF_ANAL_BLOCKL]; // Initial magnitude spectrum estimate. 100 | float pinkNoiseNumerator; // Pink noise parameter: numerator. 101 | float pinkNoiseExp; // Pink noise parameter: power of frequencies. 102 | float parametricNoise[HALF_ANAL_BLOCKL]; 103 | // Parameters for feature extraction. 104 | NSParaExtract featureExtractionParams; 105 | // Histograms for parameter estimation. 106 | int histLrt[HIST_PAR_EST]; 107 | int histSpecFlat[HIST_PAR_EST]; 108 | int histSpecDiff[HIST_PAR_EST]; 109 | // Quantities for high band estimate. 110 | float speechProb[HALF_ANAL_BLOCKL]; // Final speech/noise prob: prior + LRT. 111 | // Buffering data for HB. 112 | float dataBufHB[NUM_HIGH_BANDS_MAX][ANAL_BLOCKL_MAX]; 113 | 114 | } NoiseSuppressionC; 115 | 116 | #ifdef __cplusplus 117 | extern "C" { 118 | #endif 119 | 120 | /**************************************************************************** 121 | * WebRtcNs_InitCore(...) 122 | * 123 | * This function initializes a noise suppression instance 124 | * 125 | * Input: 126 | * - self : Instance that should be initialized 127 | * - fs : Sampling frequency 128 | * 129 | * Output: 130 | * - self : Initialized instance 131 | * 132 | * Return value : 0 - Ok 133 | * -1 - Error 134 | */ 135 | int WebRtcNs_InitCore(NoiseSuppressionC* self, uint32_t fs); 136 | 137 | /**************************************************************************** 138 | * WebRtcNs_set_policy_core(...) 139 | * 140 | * This changes the aggressiveness of the noise suppression method. 141 | * 142 | * Input: 143 | * - self : Instance that should be initialized 144 | * - mode : 0: Mild (6dB), 1: Medium (10dB), 2: Aggressive (15dB) 145 | * 146 | * Output: 147 | * - self : Initialized instance 148 | * 149 | * Return value : 0 - Ok 150 | * -1 - Error 151 | */ 152 | int WebRtcNs_set_policy_core(NoiseSuppressionC* self, int mode); 153 | 154 | /**************************************************************************** 155 | * WebRtcNs_AnalyzeCore 156 | * 157 | * Estimate the background noise. 158 | * 159 | * Input: 160 | * - self : Instance that should be initialized 161 | * - speechFrame : Input speech frame for lower band 162 | * 163 | * Output: 164 | * - self : Updated instance 165 | */ 166 | void WebRtcNs_AnalyzeCore(NoiseSuppressionC* self, const float* speechFrame); 167 | 168 | /**************************************************************************** 169 | * WebRtcNs_ProcessCore 170 | * 171 | * Do noise suppression. 172 | * 173 | * Input: 174 | * - self : Instance that should be initialized 175 | * - inFrame : Input speech frame for each band 176 | * - num_bands : Number of bands 177 | * 178 | * Output: 179 | * - self : Updated instance 180 | * - outFrame : Output speech frame for each band 181 | */ 182 | void WebRtcNs_ProcessCore(NoiseSuppressionC* self, 183 | const float* const* inFrame, 184 | size_t num_bands, 185 | float* const* outFrame); 186 | 187 | #ifdef __cplusplus 188 | } 189 | #endif 190 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_NS_NS_CORE_H_ 191 | --------------------------------------------------------------------------------