OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <assert.h> | |
12 #include <math.h> | 11 #include <math.h> |
13 #include <string.h> | 12 #include <string.h> |
14 #include <stdlib.h> | 13 #include <stdlib.h> |
15 | 14 |
| 15 #include "webrtc/base/checks.h" |
16 #include "webrtc/common_audio/fft4g.h" | 16 #include "webrtc/common_audio/fft4g.h" |
17 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 17 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
18 #include "webrtc/modules/audio_processing/ns/noise_suppression.h" | 18 #include "webrtc/modules/audio_processing/ns/noise_suppression.h" |
19 #include "webrtc/modules/audio_processing/ns/ns_core.h" | 19 #include "webrtc/modules/audio_processing/ns/ns_core.h" |
20 #include "webrtc/modules/audio_processing/ns/windows_private.h" | 20 #include "webrtc/modules/audio_processing/ns/windows_private.h" |
21 | 21 |
22 // Set Feature Extraction Parameters. | 22 // Set Feature Extraction Parameters. |
23 static void set_feature_extraction_parameters(NoiseSuppressionC* self) { | 23 static void set_feature_extraction_parameters(NoiseSuppressionC* self) { |
24 // Bin size of histogram. | 24 // Bin size of histogram. |
25 self->featureExtractionParams.binSizeLrt = 0.1f; | 25 self->featureExtractionParams.binSizeLrt = 0.1f; |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 // Inputs: | 850 // Inputs: |
851 // * |frame| is a new speech frame or NULL for setting to zero. | 851 // * |frame| is a new speech frame or NULL for setting to zero. |
852 // * |frame_length| is the length of the new frame. | 852 // * |frame_length| is the length of the new frame. |
853 // * |buffer_length| is the length of the buffer. | 853 // * |buffer_length| is the length of the buffer. |
854 // Output: | 854 // Output: |
855 // * |buffer| is the updated buffer. | 855 // * |buffer| is the updated buffer. |
856 static void UpdateBuffer(const float* frame, | 856 static void UpdateBuffer(const float* frame, |
857 size_t frame_length, | 857 size_t frame_length, |
858 size_t buffer_length, | 858 size_t buffer_length, |
859 float* buffer) { | 859 float* buffer) { |
860 assert(buffer_length < 2 * frame_length); | 860 RTC_DCHECK_LT(buffer_length, 2 * frame_length); |
861 | 861 |
862 memcpy(buffer, | 862 memcpy(buffer, |
863 buffer + frame_length, | 863 buffer + frame_length, |
864 sizeof(*buffer) * (buffer_length - frame_length)); | 864 sizeof(*buffer) * (buffer_length - frame_length)); |
865 if (frame) { | 865 if (frame) { |
866 memcpy(buffer + buffer_length - frame_length, | 866 memcpy(buffer + buffer_length - frame_length, |
867 frame, | 867 frame, |
868 sizeof(*buffer) * frame_length); | 868 sizeof(*buffer) * frame_length); |
869 } else { | 869 } else { |
870 memset(buffer + buffer_length - frame_length, | 870 memset(buffer + buffer_length - frame_length, |
(...skipping 15 matching lines...) Expand all Loading... |
886 // * |magn| is the calculated signal magnitude in the frequency domain. | 886 // * |magn| is the calculated signal magnitude in the frequency domain. |
887 static void FFT(NoiseSuppressionC* self, | 887 static void FFT(NoiseSuppressionC* self, |
888 float* time_data, | 888 float* time_data, |
889 size_t time_data_length, | 889 size_t time_data_length, |
890 size_t magnitude_length, | 890 size_t magnitude_length, |
891 float* real, | 891 float* real, |
892 float* imag, | 892 float* imag, |
893 float* magn) { | 893 float* magn) { |
894 size_t i; | 894 size_t i; |
895 | 895 |
896 assert(magnitude_length == time_data_length / 2 + 1); | 896 RTC_DCHECK_EQ(magnitude_length, time_data_length / 2 + 1); |
897 | 897 |
898 WebRtc_rdft(time_data_length, 1, time_data, self->ip, self->wfft); | 898 WebRtc_rdft(time_data_length, 1, time_data, self->ip, self->wfft); |
899 | 899 |
900 imag[0] = 0; | 900 imag[0] = 0; |
901 real[0] = time_data[0]; | 901 real[0] = time_data[0]; |
902 magn[0] = fabsf(real[0]) + 1.f; | 902 magn[0] = fabsf(real[0]) + 1.f; |
903 imag[magnitude_length - 1] = 0; | 903 imag[magnitude_length - 1] = 0; |
904 real[magnitude_length - 1] = time_data[1]; | 904 real[magnitude_length - 1] = time_data[1]; |
905 magn[magnitude_length - 1] = fabsf(real[magnitude_length - 1]) + 1.f; | 905 magn[magnitude_length - 1] = fabsf(real[magnitude_length - 1]) + 1.f; |
906 for (i = 1; i < magnitude_length - 1; ++i) { | 906 for (i = 1; i < magnitude_length - 1; ++i) { |
(...skipping 15 matching lines...) Expand all Loading... |
922 // Output: | 922 // Output: |
923 // * |time_data| is the signal in the time domain. | 923 // * |time_data| is the signal in the time domain. |
924 static void IFFT(NoiseSuppressionC* self, | 924 static void IFFT(NoiseSuppressionC* self, |
925 const float* real, | 925 const float* real, |
926 const float* imag, | 926 const float* imag, |
927 size_t magnitude_length, | 927 size_t magnitude_length, |
928 size_t time_data_length, | 928 size_t time_data_length, |
929 float* time_data) { | 929 float* time_data) { |
930 size_t i; | 930 size_t i; |
931 | 931 |
932 assert(time_data_length == 2 * (magnitude_length - 1)); | 932 RTC_DCHECK_EQ(time_data_length, 2 * (magnitude_length - 1)); |
933 | 933 |
934 time_data[0] = real[0]; | 934 time_data[0] = real[0]; |
935 time_data[1] = real[magnitude_length - 1]; | 935 time_data[1] = real[magnitude_length - 1]; |
936 for (i = 1; i < magnitude_length - 1; ++i) { | 936 for (i = 1; i < magnitude_length - 1; ++i) { |
937 time_data[2 * i] = real[i]; | 937 time_data[2 * i] = real[i]; |
938 time_data[2 * i + 1] = imag[i]; | 938 time_data[2 * i + 1] = imag[i]; |
939 } | 939 } |
940 WebRtc_rdft(time_data_length, -1, time_data, self->ip, self->wfft); | 940 WebRtc_rdft(time_data_length, -1, time_data, self->ip, self->wfft); |
941 | 941 |
942 for (i = 0; i < time_data_length; ++i) { | 942 for (i = 0; i < time_data_length; ++i) { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 float real[ANAL_BLOCKL_MAX], imag[HALF_ANAL_BLOCKL]; | 1055 float real[ANAL_BLOCKL_MAX], imag[HALF_ANAL_BLOCKL]; |
1056 // Variables during startup. | 1056 // Variables during startup. |
1057 float sum_log_i = 0.0; | 1057 float sum_log_i = 0.0; |
1058 float sum_log_i_square = 0.0; | 1058 float sum_log_i_square = 0.0; |
1059 float sum_log_magn = 0.0; | 1059 float sum_log_magn = 0.0; |
1060 float sum_log_i_log_magn = 0.0; | 1060 float sum_log_i_log_magn = 0.0; |
1061 float parametric_exp = 0.0; | 1061 float parametric_exp = 0.0; |
1062 float parametric_num = 0.0; | 1062 float parametric_num = 0.0; |
1063 | 1063 |
1064 // Check that initiation has been done. | 1064 // Check that initiation has been done. |
1065 assert(self->initFlag == 1); | 1065 RTC_DCHECK_EQ(1, self->initFlag); |
1066 updateParsFlag = self->modelUpdatePars[0]; | 1066 updateParsFlag = self->modelUpdatePars[0]; |
1067 | 1067 |
1068 // Update analysis buffer for L band. | 1068 // Update analysis buffer for L band. |
1069 UpdateBuffer(speechFrame, self->blockLen, self->anaLen, self->analyzeBuf); | 1069 UpdateBuffer(speechFrame, self->blockLen, self->anaLen, self->analyzeBuf); |
1070 | 1070 |
1071 Windowing(self->window, self->analyzeBuf, self->anaLen, winData); | 1071 Windowing(self->window, self->analyzeBuf, self->anaLen, winData); |
1072 energy = Energy(winData, self->anaLen); | 1072 energy = Energy(winData, self->anaLen); |
1073 if (energy == 0.0) { | 1073 if (energy == 0.0) { |
1074 // We want to avoid updating statistics in this case: | 1074 // We want to avoid updating statistics in this case: |
1075 // Updating feature statistics when we have zeros only will cause | 1075 // Updating feature statistics when we have zeros only will cause |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 // SWB variables. | 1199 // SWB variables. |
1200 int deltaBweHB = 1; | 1200 int deltaBweHB = 1; |
1201 int deltaGainHB = 1; | 1201 int deltaGainHB = 1; |
1202 float decayBweHB = 1.0; | 1202 float decayBweHB = 1.0; |
1203 float gainMapParHB = 1.0; | 1203 float gainMapParHB = 1.0; |
1204 float gainTimeDomainHB = 1.0; | 1204 float gainTimeDomainHB = 1.0; |
1205 float avgProbSpeechHB, avgProbSpeechHBTmp, avgFilterGainHB, gainModHB; | 1205 float avgProbSpeechHB, avgProbSpeechHBTmp, avgFilterGainHB, gainModHB; |
1206 float sumMagnAnalyze, sumMagnProcess; | 1206 float sumMagnAnalyze, sumMagnProcess; |
1207 | 1207 |
1208 // Check that initiation has been done. | 1208 // Check that initiation has been done. |
1209 assert(self->initFlag == 1); | 1209 RTC_DCHECK_EQ(1, self->initFlag); |
1210 assert((num_bands - 1) <= NUM_HIGH_BANDS_MAX); | 1210 RTC_DCHECK_LE(num_bands - 1, NUM_HIGH_BANDS_MAX); |
1211 | 1211 |
1212 const float* const* speechFrameHB = NULL; | 1212 const float* const* speechFrameHB = NULL; |
1213 float* const* outFrameHB = NULL; | 1213 float* const* outFrameHB = NULL; |
1214 size_t num_high_bands = 0; | 1214 size_t num_high_bands = 0; |
1215 if (num_bands > 1) { | 1215 if (num_bands > 1) { |
1216 speechFrameHB = &speechFrame[1]; | 1216 speechFrameHB = &speechFrame[1]; |
1217 outFrameHB = &outFrame[1]; | 1217 outFrameHB = &outFrame[1]; |
1218 num_high_bands = num_bands - 1; | 1218 num_high_bands = num_bands - 1; |
1219 flagHB = 1; | 1219 flagHB = 1; |
1220 // Range for averaging low band quantities for H band gain. | 1220 // Range for averaging low band quantities for H band gain. |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1407 for (i = 0; i < num_high_bands; ++i) { | 1407 for (i = 0; i < num_high_bands; ++i) { |
1408 for (j = 0; j < self->blockLen; j++) { | 1408 for (j = 0; j < self->blockLen; j++) { |
1409 outFrameHB[i][j] = | 1409 outFrameHB[i][j] = |
1410 WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX, | 1410 WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX, |
1411 gainTimeDomainHB * self->dataBufHB[i][j], | 1411 gainTimeDomainHB * self->dataBufHB[i][j], |
1412 WEBRTC_SPL_WORD16_MIN); | 1412 WEBRTC_SPL_WORD16_MIN); |
1413 } | 1413 } |
1414 } | 1414 } |
1415 } // End of H band gain computation. | 1415 } // End of H band gain computation. |
1416 } | 1416 } |
OLD | NEW |