Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1086)

Side by Side Diff: webrtc/modules/audio_processing/ns/ns_core.c

Issue 1230503003: Update a ton of audio code to use size_t more correctly and in general reduce (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Resync Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 WebRtcNs_set_policy_core(self, 0); 210 WebRtcNs_set_policy_core(self, 0);
211 211
212 self->initFlag = 1; 212 self->initFlag = 1;
213 return 0; 213 return 0;
214 } 214 }
215 215
216 // Estimate noise. 216 // Estimate noise.
217 static void NoiseEstimation(NoiseSuppressionC* self, 217 static void NoiseEstimation(NoiseSuppressionC* self,
218 float* magn, 218 float* magn,
219 float* noise) { 219 float* noise) {
220 int i, s, offset; 220 size_t i, s, offset;
221 float lmagn[HALF_ANAL_BLOCKL], delta; 221 float lmagn[HALF_ANAL_BLOCKL], delta;
222 222
223 if (self->updates < END_STARTUP_LONG) { 223 if (self->updates < END_STARTUP_LONG) {
224 self->updates++; 224 self->updates++;
225 } 225 }
226 226
227 for (i = 0; i < self->magnLen; i++) { 227 for (i = 0; i < self->magnLen; i++) {
228 lmagn[i] = (float)log(magn[i]); 228 lmagn[i] = (float)log(magn[i]);
229 } 229 }
230 230
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 } 515 }
516 } 516 }
517 } // End of flag == 1. 517 } // End of flag == 1.
518 } 518 }
519 519
520 // Compute spectral flatness on input spectrum. 520 // Compute spectral flatness on input spectrum.
521 // |magnIn| is the magnitude spectrum. 521 // |magnIn| is the magnitude spectrum.
522 // Spectral flatness is returned in self->featureData[0]. 522 // Spectral flatness is returned in self->featureData[0].
523 static void ComputeSpectralFlatness(NoiseSuppressionC* self, 523 static void ComputeSpectralFlatness(NoiseSuppressionC* self,
524 const float* magnIn) { 524 const float* magnIn) {
525 int i; 525 size_t i;
526 int shiftLP = 1; // Option to remove first bin(s) from spectral measures. 526 size_t shiftLP = 1; // Option to remove first bin(s) from spectral measures.
527 float avgSpectralFlatnessNum, avgSpectralFlatnessDen, spectralTmp; 527 float avgSpectralFlatnessNum, avgSpectralFlatnessDen, spectralTmp;
528 528
529 // Compute spectral measures. 529 // Compute spectral measures.
530 // For flatness. 530 // For flatness.
531 avgSpectralFlatnessNum = 0.0; 531 avgSpectralFlatnessNum = 0.0;
532 avgSpectralFlatnessDen = self->sumMagn; 532 avgSpectralFlatnessDen = self->sumMagn;
533 for (i = 0; i < shiftLP; i++) { 533 for (i = 0; i < shiftLP; i++) {
534 avgSpectralFlatnessDen -= magnIn[i]; 534 avgSpectralFlatnessDen -= magnIn[i];
535 } 535 }
536 // Compute log of ratio of the geometric to arithmetic mean: check for log(0) 536 // Compute log of ratio of the geometric to arithmetic mean: check for log(0)
(...skipping 24 matching lines...) Expand all
561 // * |magn| is the signal magnitude spectrum estimate. 561 // * |magn| is the signal magnitude spectrum estimate.
562 // * |noise| is the magnitude noise spectrum estimate. 562 // * |noise| is the magnitude noise spectrum estimate.
563 // Outputs: 563 // Outputs:
564 // * |snrLocPrior| is the computed prior SNR. 564 // * |snrLocPrior| is the computed prior SNR.
565 // * |snrLocPost| is the computed post SNR. 565 // * |snrLocPost| is the computed post SNR.
566 static void ComputeSnr(const NoiseSuppressionC* self, 566 static void ComputeSnr(const NoiseSuppressionC* self,
567 const float* magn, 567 const float* magn,
568 const float* noise, 568 const float* noise,
569 float* snrLocPrior, 569 float* snrLocPrior,
570 float* snrLocPost) { 570 float* snrLocPost) {
571 int i; 571 size_t i;
572 572
573 for (i = 0; i < self->magnLen; i++) { 573 for (i = 0; i < self->magnLen; i++) {
574 // Previous post SNR. 574 // Previous post SNR.
575 // Previous estimate: based on previous frame with gain filter. 575 // Previous estimate: based on previous frame with gain filter.
576 float previousEstimateStsa = self->magnPrevAnalyze[i] / 576 float previousEstimateStsa = self->magnPrevAnalyze[i] /
577 (self->noisePrev[i] + 0.0001f) * self->smooth[i]; 577 (self->noisePrev[i] + 0.0001f) * self->smooth[i];
578 // Post SNR. 578 // Post SNR.
579 snrLocPost[i] = 0.f; 579 snrLocPost[i] = 0.f;
580 if (magn[i] > noise[i]) { 580 if (magn[i] > noise[i]) {
581 snrLocPost[i] = magn[i] / (noise[i] + 0.0001f) - 1.f; 581 snrLocPost[i] = magn[i] / (noise[i] + 0.0001f) - 1.f;
582 } 582 }
583 // DD estimate is sum of two terms: current estimate and previous estimate. 583 // DD estimate is sum of two terms: current estimate and previous estimate.
584 // Directed decision update of snrPrior. 584 // Directed decision update of snrPrior.
585 snrLocPrior[i] = 585 snrLocPrior[i] =
586 DD_PR_SNR * previousEstimateStsa + (1.f - DD_PR_SNR) * snrLocPost[i]; 586 DD_PR_SNR * previousEstimateStsa + (1.f - DD_PR_SNR) * snrLocPost[i];
587 } // End of loop over frequencies. 587 } // End of loop over frequencies.
588 } 588 }
589 589
590 // Compute the difference measure between input spectrum and a template/learned 590 // Compute the difference measure between input spectrum and a template/learned
591 // noise spectrum. 591 // noise spectrum.
592 // |magnIn| is the input spectrum. 592 // |magnIn| is the input spectrum.
593 // The reference/template spectrum is self->magnAvgPause[i]. 593 // The reference/template spectrum is self->magnAvgPause[i].
594 // Returns (normalized) spectral difference in self->featureData[4]. 594 // Returns (normalized) spectral difference in self->featureData[4].
595 static void ComputeSpectralDifference(NoiseSuppressionC* self, 595 static void ComputeSpectralDifference(NoiseSuppressionC* self,
596 const float* magnIn) { 596 const float* magnIn) {
597 // avgDiffNormMagn = var(magnIn) - cov(magnIn, magnAvgPause)^2 / 597 // avgDiffNormMagn = var(magnIn) - cov(magnIn, magnAvgPause)^2 /
598 // var(magnAvgPause) 598 // var(magnAvgPause)
599 int i; 599 size_t i;
600 float avgPause, avgMagn, covMagnPause, varPause, varMagn, avgDiffNormMagn; 600 float avgPause, avgMagn, covMagnPause, varPause, varMagn, avgDiffNormMagn;
601 601
602 avgPause = 0.0; 602 avgPause = 0.0;
603 avgMagn = self->sumMagn; 603 avgMagn = self->sumMagn;
604 // Compute average quantities. 604 // Compute average quantities.
605 for (i = 0; i < self->magnLen; i++) { 605 for (i = 0; i < self->magnLen; i++) {
606 // Conservative smooth noise spectrum from pause frames. 606 // Conservative smooth noise spectrum from pause frames.
607 avgPause += self->magnAvgPause[i]; 607 avgPause += self->magnAvgPause[i];
608 } 608 }
609 avgPause /= self->magnLen; 609 avgPause /= self->magnLen;
(...skipping 26 matching lines...) Expand all
636 // Compute speech/noise probability. 636 // Compute speech/noise probability.
637 // Speech/noise probability is returned in |probSpeechFinal|. 637 // Speech/noise probability is returned in |probSpeechFinal|.
638 // |magn| is the input magnitude spectrum. 638 // |magn| is the input magnitude spectrum.
639 // |noise| is the noise spectrum. 639 // |noise| is the noise spectrum.
640 // |snrLocPrior| is the prior SNR for each frequency. 640 // |snrLocPrior| is the prior SNR for each frequency.
641 // |snrLocPost| is the post SNR for each frequency. 641 // |snrLocPost| is the post SNR for each frequency.
642 static void SpeechNoiseProb(NoiseSuppressionC* self, 642 static void SpeechNoiseProb(NoiseSuppressionC* self,
643 float* probSpeechFinal, 643 float* probSpeechFinal,
644 const float* snrLocPrior, 644 const float* snrLocPrior,
645 const float* snrLocPost) { 645 const float* snrLocPost) {
646 int i, sgnMap; 646 size_t i;
647 int sgnMap;
647 float invLrt, gainPrior, indPrior; 648 float invLrt, gainPrior, indPrior;
648 float logLrtTimeAvgKsum, besselTmp; 649 float logLrtTimeAvgKsum, besselTmp;
649 float indicator0, indicator1, indicator2; 650 float indicator0, indicator1, indicator2;
650 float tmpFloat1, tmpFloat2; 651 float tmpFloat1, tmpFloat2;
651 float weightIndPrior0, weightIndPrior1, weightIndPrior2; 652 float weightIndPrior0, weightIndPrior1, weightIndPrior2;
652 float threshPrior0, threshPrior1, threshPrior2; 653 float threshPrior0, threshPrior1, threshPrior2;
653 float widthPrior, widthPrior0, widthPrior1, widthPrior2; 654 float widthPrior, widthPrior0, widthPrior1, widthPrior2;
654 655
655 widthPrior0 = WIDTH_PR_MAP; 656 widthPrior0 = WIDTH_PR_MAP;
656 // Width for pause region: lower range, so increase width in tanh map. 657 // Width for pause region: lower range, so increase width in tanh map.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 // * |magn| is the signal magnitude spectrum estimate. 796 // * |magn| is the signal magnitude spectrum estimate.
796 // * |snrLocPrior| is the prior SNR. 797 // * |snrLocPrior| is the prior SNR.
797 // * |snrLocPost| is the post SNR. 798 // * |snrLocPost| is the post SNR.
798 // Output: 799 // Output:
799 // * |noise| is the updated noise magnitude spectrum estimate. 800 // * |noise| is the updated noise magnitude spectrum estimate.
800 static void UpdateNoiseEstimate(NoiseSuppressionC* self, 801 static void UpdateNoiseEstimate(NoiseSuppressionC* self,
801 const float* magn, 802 const float* magn,
802 const float* snrLocPrior, 803 const float* snrLocPrior,
803 const float* snrLocPost, 804 const float* snrLocPost,
804 float* noise) { 805 float* noise) {
805 int i; 806 size_t i;
806 float probSpeech, probNonSpeech; 807 float probSpeech, probNonSpeech;
807 // Time-avg parameter for noise update. 808 // Time-avg parameter for noise update.
808 float gammaNoiseTmp = NOISE_UPDATE; 809 float gammaNoiseTmp = NOISE_UPDATE;
809 float gammaNoiseOld; 810 float gammaNoiseOld;
810 float noiseUpdateTmp; 811 float noiseUpdateTmp;
811 812
812 for (i = 0; i < self->magnLen; i++) { 813 for (i = 0; i < self->magnLen; i++) {
813 probSpeech = self->speechProb[i]; 814 probSpeech = self->speechProb[i];
814 probNonSpeech = 1.f - probSpeech; 815 probNonSpeech = 1.f - probSpeech;
815 // Temporary noise update: 816 // Temporary noise update:
(...skipping 30 matching lines...) Expand all
846 } 847 }
847 848
848 // Updates |buffer| with a new |frame|. 849 // Updates |buffer| with a new |frame|.
849 // Inputs: 850 // Inputs:
850 // * |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.
851 // * |frame_length| is the length of the new frame. 852 // * |frame_length| is the length of the new frame.
852 // * |buffer_length| is the length of the buffer. 853 // * |buffer_length| is the length of the buffer.
853 // Output: 854 // Output:
854 // * |buffer| is the updated buffer. 855 // * |buffer| is the updated buffer.
855 static void UpdateBuffer(const float* frame, 856 static void UpdateBuffer(const float* frame,
856 int frame_length, 857 size_t frame_length,
857 int buffer_length, 858 size_t buffer_length,
858 float* buffer) { 859 float* buffer) {
859 assert(buffer_length < 2 * frame_length); 860 assert(buffer_length < 2 * frame_length);
860 861
861 memcpy(buffer, 862 memcpy(buffer,
862 buffer + frame_length, 863 buffer + frame_length,
863 sizeof(*buffer) * (buffer_length - frame_length)); 864 sizeof(*buffer) * (buffer_length - frame_length));
864 if (frame) { 865 if (frame) {
865 memcpy(buffer + buffer_length - frame_length, 866 memcpy(buffer + buffer_length - frame_length,
866 frame, 867 frame,
867 sizeof(*buffer) * frame_length); 868 sizeof(*buffer) * frame_length);
(...skipping 10 matching lines...) Expand all
878 // * |time_data_length| is the length of the analysis buffer. 879 // * |time_data_length| is the length of the analysis buffer.
879 // * |magnitude_length| is the length of the spectrum magnitude, which equals 880 // * |magnitude_length| is the length of the spectrum magnitude, which equals
880 // the length of both |real| and |imag| (time_data_length / 2 + 1). 881 // the length of both |real| and |imag| (time_data_length / 2 + 1).
881 // Outputs: 882 // Outputs:
882 // * |time_data| is the signal in the frequency domain. 883 // * |time_data| is the signal in the frequency domain.
883 // * |real| is the real part of the frequency domain. 884 // * |real| is the real part of the frequency domain.
884 // * |imag| is the imaginary part of the frequency domain. 885 // * |imag| is the imaginary part of the frequency domain.
885 // * |magn| is the calculated signal magnitude in the frequency domain. 886 // * |magn| is the calculated signal magnitude in the frequency domain.
886 static void FFT(NoiseSuppressionC* self, 887 static void FFT(NoiseSuppressionC* self,
887 float* time_data, 888 float* time_data,
888 int time_data_length, 889 size_t time_data_length,
889 int magnitude_length, 890 size_t magnitude_length,
890 float* real, 891 float* real,
891 float* imag, 892 float* imag,
892 float* magn) { 893 float* magn) {
893 int i; 894 size_t i;
894 895
895 assert(magnitude_length == time_data_length / 2 + 1); 896 assert(magnitude_length == time_data_length / 2 + 1);
896 897
897 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);
898 899
899 imag[0] = 0; 900 imag[0] = 0;
900 real[0] = time_data[0]; 901 real[0] = time_data[0];
901 magn[0] = fabsf(real[0]) + 1.f; 902 magn[0] = fabsf(real[0]) + 1.f;
902 imag[magnitude_length - 1] = 0; 903 imag[magnitude_length - 1] = 0;
903 real[magnitude_length - 1] = time_data[1]; 904 real[magnitude_length - 1] = time_data[1];
(...skipping 12 matching lines...) Expand all
916 // * |imag| is the imaginary part of the frequency domain. 917 // * |imag| is the imaginary part of the frequency domain.
917 // * |magnitude_length| is the length of the spectrum magnitude, which equals 918 // * |magnitude_length| is the length of the spectrum magnitude, which equals
918 // the length of both |real| and |imag|. 919 // the length of both |real| and |imag|.
919 // * |time_data_length| is the length of the analysis buffer 920 // * |time_data_length| is the length of the analysis buffer
920 // (2 * (magnitude_length - 1)). 921 // (2 * (magnitude_length - 1)).
921 // Output: 922 // Output:
922 // * |time_data| is the signal in the time domain. 923 // * |time_data| is the signal in the time domain.
923 static void IFFT(NoiseSuppressionC* self, 924 static void IFFT(NoiseSuppressionC* self,
924 const float* real, 925 const float* real,
925 const float* imag, 926 const float* imag,
926 int magnitude_length, 927 size_t magnitude_length,
927 int time_data_length, 928 size_t time_data_length,
928 float* time_data) { 929 float* time_data) {
929 int i; 930 size_t i;
930 931
931 assert(time_data_length == 2 * (magnitude_length - 1)); 932 assert(time_data_length == 2 * (magnitude_length - 1));
932 933
933 time_data[0] = real[0]; 934 time_data[0] = real[0];
934 time_data[1] = real[magnitude_length - 1]; 935 time_data[1] = real[magnitude_length - 1];
935 for (i = 1; i < magnitude_length - 1; ++i) { 936 for (i = 1; i < magnitude_length - 1; ++i) {
936 time_data[2 * i] = real[i]; 937 time_data[2 * i] = real[i];
937 time_data[2 * i + 1] = imag[i]; 938 time_data[2 * i + 1] = imag[i];
938 } 939 }
939 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);
940 941
941 for (i = 0; i < time_data_length; ++i) { 942 for (i = 0; i < time_data_length; ++i) {
942 time_data[i] *= 2.f / time_data_length; // FFT scaling. 943 time_data[i] *= 2.f / time_data_length; // FFT scaling.
943 } 944 }
944 } 945 }
945 946
946 // Calculates the energy of a buffer. 947 // Calculates the energy of a buffer.
947 // Inputs: 948 // Inputs:
948 // * |buffer| is the buffer over which the energy is calculated. 949 // * |buffer| is the buffer over which the energy is calculated.
949 // * |length| is the length of the buffer. 950 // * |length| is the length of the buffer.
950 // Returns the calculated energy. 951 // Returns the calculated energy.
951 static float Energy(const float* buffer, int length) { 952 static float Energy(const float* buffer, size_t length) {
952 int i; 953 size_t i;
953 float energy = 0.f; 954 float energy = 0.f;
954 955
955 for (i = 0; i < length; ++i) { 956 for (i = 0; i < length; ++i) {
956 energy += buffer[i] * buffer[i]; 957 energy += buffer[i] * buffer[i];
957 } 958 }
958 959
959 return energy; 960 return energy;
960 } 961 }
961 962
962 // Windows a buffer. 963 // Windows a buffer.
963 // Inputs: 964 // Inputs:
964 // * |window| is the window by which to multiply. 965 // * |window| is the window by which to multiply.
965 // * |data| is the data without windowing. 966 // * |data| is the data without windowing.
966 // * |length| is the length of the window and data. 967 // * |length| is the length of the window and data.
967 // Output: 968 // Output:
968 // * |data_windowed| is the windowed data. 969 // * |data_windowed| is the windowed data.
969 static void Windowing(const float* window, 970 static void Windowing(const float* window,
970 const float* data, 971 const float* data,
971 int length, 972 size_t length,
972 float* data_windowed) { 973 float* data_windowed) {
973 int i; 974 size_t i;
974 975
975 for (i = 0; i < length; ++i) { 976 for (i = 0; i < length; ++i) {
976 data_windowed[i] = window[i] * data[i]; 977 data_windowed[i] = window[i] * data[i];
977 } 978 }
978 } 979 }
979 980
980 // Estimate prior SNR decision-directed and compute DD based Wiener Filter. 981 // Estimate prior SNR decision-directed and compute DD based Wiener Filter.
981 // Input: 982 // Input:
982 // * |magn| is the signal magnitude spectrum estimate. 983 // * |magn| is the signal magnitude spectrum estimate.
983 // Output: 984 // Output:
984 // * |theFilter| is the frequency response of the computed Wiener filter. 985 // * |theFilter| is the frequency response of the computed Wiener filter.
985 static void ComputeDdBasedWienerFilter(const NoiseSuppressionC* self, 986 static void ComputeDdBasedWienerFilter(const NoiseSuppressionC* self,
986 const float* magn, 987 const float* magn,
987 float* theFilter) { 988 float* theFilter) {
988 int i; 989 size_t i;
989 float snrPrior, previousEstimateStsa, currentEstimateStsa; 990 float snrPrior, previousEstimateStsa, currentEstimateStsa;
990 991
991 for (i = 0; i < self->magnLen; i++) { 992 for (i = 0; i < self->magnLen; i++) {
992 // Previous estimate: based on previous frame with gain filter. 993 // Previous estimate: based on previous frame with gain filter.
993 previousEstimateStsa = self->magnPrevProcess[i] / 994 previousEstimateStsa = self->magnPrevProcess[i] /
994 (self->noisePrev[i] + 0.0001f) * self->smooth[i]; 995 (self->noisePrev[i] + 0.0001f) * self->smooth[i];
995 // Post and prior SNR. 996 // Post and prior SNR.
996 currentEstimateStsa = 0.f; 997 currentEstimateStsa = 0.f;
997 if (magn[i] > self->noise[i]) { 998 if (magn[i] > self->noise[i]) {
998 currentEstimateStsa = magn[i] / (self->noise[i] + 0.0001f) - 1.f; 999 currentEstimateStsa = magn[i] / (self->noise[i] + 0.0001f) - 1.f;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 } else if (mode == 3) { 1035 } else if (mode == 3) {
1035 // self->overdrive = 1.3f; 1036 // self->overdrive = 1.3f;
1036 self->overdrive = 1.25f; 1037 self->overdrive = 1.25f;
1037 self->denoiseBound = 0.09f; 1038 self->denoiseBound = 0.09f;
1038 self->gainmap = 1; 1039 self->gainmap = 1;
1039 } 1040 }
1040 return 0; 1041 return 0;
1041 } 1042 }
1042 1043
1043 void WebRtcNs_AnalyzeCore(NoiseSuppressionC* self, const float* speechFrame) { 1044 void WebRtcNs_AnalyzeCore(NoiseSuppressionC* self, const float* speechFrame) {
1044 int i; 1045 size_t i;
1045 const int kStartBand = 5; // Skip first frequency bins during estimation. 1046 const size_t kStartBand = 5; // Skip first frequency bins during estimation.
1046 int updateParsFlag; 1047 int updateParsFlag;
1047 float energy; 1048 float energy;
1048 float signalEnergy = 0.f; 1049 float signalEnergy = 0.f;
1049 float sumMagn = 0.f; 1050 float sumMagn = 0.f;
1050 float tmpFloat1, tmpFloat2, tmpFloat3; 1051 float tmpFloat1, tmpFloat2, tmpFloat3;
1051 float winData[ANAL_BLOCKL_MAX]; 1052 float winData[ANAL_BLOCKL_MAX];
1052 float magn[HALF_ANAL_BLOCKL], noise[HALF_ANAL_BLOCKL]; 1053 float magn[HALF_ANAL_BLOCKL], noise[HALF_ANAL_BLOCKL];
1053 float snrLocPost[HALF_ANAL_BLOCKL], snrLocPrior[HALF_ANAL_BLOCKL]; 1054 float snrLocPost[HALF_ANAL_BLOCKL], snrLocPrior[HALF_ANAL_BLOCKL];
1054 float real[ANAL_BLOCKL_MAX], imag[HALF_ANAL_BLOCKL]; 1055 float real[ANAL_BLOCKL_MAX], imag[HALF_ANAL_BLOCKL];
1055 // Variables during startup. 1056 // Variables during startup.
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 SpeechNoiseProb(self, self->speechProb, snrLocPrior, snrLocPost); 1176 SpeechNoiseProb(self, self->speechProb, snrLocPrior, snrLocPost);
1176 UpdateNoiseEstimate(self, magn, snrLocPrior, snrLocPost, noise); 1177 UpdateNoiseEstimate(self, magn, snrLocPrior, snrLocPost, noise);
1177 1178
1178 // Keep track of noise spectrum for next frame. 1179 // Keep track of noise spectrum for next frame.
1179 memcpy(self->noise, noise, sizeof(*noise) * self->magnLen); 1180 memcpy(self->noise, noise, sizeof(*noise) * self->magnLen);
1180 memcpy(self->magnPrevAnalyze, magn, sizeof(*magn) * self->magnLen); 1181 memcpy(self->magnPrevAnalyze, magn, sizeof(*magn) * self->magnLen);
1181 } 1182 }
1182 1183
1183 void WebRtcNs_ProcessCore(NoiseSuppressionC* self, 1184 void WebRtcNs_ProcessCore(NoiseSuppressionC* self,
1184 const float* const* speechFrame, 1185 const float* const* speechFrame,
1185 int num_bands, 1186 size_t num_bands,
1186 float* const* outFrame) { 1187 float* const* outFrame) {
1187 // Main routine for noise reduction. 1188 // Main routine for noise reduction.
1188 int flagHB = 0; 1189 int flagHB = 0;
1189 int i, j; 1190 size_t i, j;
1190 1191
1191 float energy1, energy2, gain, factor, factor1, factor2; 1192 float energy1, energy2, gain, factor, factor1, factor2;
1192 float fout[BLOCKL_MAX]; 1193 float fout[BLOCKL_MAX];
1193 float winData[ANAL_BLOCKL_MAX]; 1194 float winData[ANAL_BLOCKL_MAX];
1194 float magn[HALF_ANAL_BLOCKL]; 1195 float magn[HALF_ANAL_BLOCKL];
1195 float theFilter[HALF_ANAL_BLOCKL], theFilterTmp[HALF_ANAL_BLOCKL]; 1196 float theFilter[HALF_ANAL_BLOCKL], theFilterTmp[HALF_ANAL_BLOCKL];
1196 float real[ANAL_BLOCKL_MAX], imag[HALF_ANAL_BLOCKL]; 1197 float real[ANAL_BLOCKL_MAX], imag[HALF_ANAL_BLOCKL];
1197 1198
1198 // SWB variables. 1199 // SWB variables.
1199 int deltaBweHB = 1; 1200 int deltaBweHB = 1;
1200 int deltaGainHB = 1; 1201 int deltaGainHB = 1;
1201 float decayBweHB = 1.0; 1202 float decayBweHB = 1.0;
1202 float gainMapParHB = 1.0; 1203 float gainMapParHB = 1.0;
1203 float gainTimeDomainHB = 1.0; 1204 float gainTimeDomainHB = 1.0;
1204 float avgProbSpeechHB, avgProbSpeechHBTmp, avgFilterGainHB, gainModHB; 1205 float avgProbSpeechHB, avgProbSpeechHBTmp, avgFilterGainHB, gainModHB;
1205 float sumMagnAnalyze, sumMagnProcess; 1206 float sumMagnAnalyze, sumMagnProcess;
1206 1207
1207 // Check that initiation has been done. 1208 // Check that initiation has been done.
1208 assert(self->initFlag == 1); 1209 assert(self->initFlag == 1);
1209 assert((num_bands - 1) <= NUM_HIGH_BANDS_MAX); 1210 assert((num_bands - 1) <= NUM_HIGH_BANDS_MAX);
1210 1211
1211 const float* const* speechFrameHB = NULL; 1212 const float* const* speechFrameHB = NULL;
1212 float* const* outFrameHB = NULL; 1213 float* const* outFrameHB = NULL;
1213 int num_high_bands = 0; 1214 size_t num_high_bands = 0;
1214 if (num_bands > 1) { 1215 if (num_bands > 1) {
1215 speechFrameHB = &speechFrame[1]; 1216 speechFrameHB = &speechFrame[1];
1216 outFrameHB = &outFrame[1]; 1217 outFrameHB = &outFrame[1];
1217 num_high_bands = num_bands - 1; 1218 num_high_bands = num_bands - 1;
1218 flagHB = 1; 1219 flagHB = 1;
1219 // Range for averaging low band quantities for H band gain. 1220 // Range for averaging low band quantities for H band gain.
1220 deltaBweHB = (int)self->magnLen / 4; 1221 deltaBweHB = (int)self->magnLen / 4;
1221 deltaGainHB = deltaBweHB; 1222 deltaGainHB = deltaBweHB;
1222 } 1223 }
1223 1224
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 for (i = 0; i < num_high_bands; ++i) { 1407 for (i = 0; i < num_high_bands; ++i) {
1407 for (j = 0; j < self->blockLen; j++) { 1408 for (j = 0; j < self->blockLen; j++) {
1408 outFrameHB[i][j] = 1409 outFrameHB[i][j] =
1409 WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX, 1410 WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX,
1410 gainTimeDomainHB * self->dataBufHB[i][j], 1411 gainTimeDomainHB * self->dataBufHB[i][j],
1411 WEBRTC_SPL_WORD16_MIN); 1412 WEBRTC_SPL_WORD16_MIN);
1412 } 1413 }
1413 } 1414 }
1414 } // End of H band gain computation. 1415 } // End of H band gain computation.
1415 } 1416 }
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/ns/ns_core.h ('k') | webrtc/modules/audio_processing/ns/nsx_core.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698