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 <math.h> | 11 #include <math.h> |
12 #include <stdio.h> | 12 #include <stdio.h> |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <limits> | 14 #include <limits> |
15 #include <queue> | 15 #include <queue> |
16 | 16 |
17 #include "webrtc/base/arraysize.h" | |
17 #include "webrtc/base/scoped_ptr.h" | 18 #include "webrtc/base/scoped_ptr.h" |
18 #include "webrtc/common_audio/include/audio_util.h" | 19 #include "webrtc/common_audio/include/audio_util.h" |
19 #include "webrtc/common_audio/resampler/include/push_resampler.h" | 20 #include "webrtc/common_audio/resampler/include/push_resampler.h" |
20 #include "webrtc/common_audio/resampler/push_sinc_resampler.h" | 21 #include "webrtc/common_audio/resampler/push_sinc_resampler.h" |
21 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" | 22 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" |
22 #include "webrtc/modules/audio_processing/beamformer/mock_nonlinear_beamformer.h " | 23 #include "webrtc/modules/audio_processing/beamformer/mock_nonlinear_beamformer.h " |
23 #include "webrtc/modules/audio_processing/common.h" | 24 #include "webrtc/modules/audio_processing/common.h" |
24 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 25 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
25 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" | 26 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" |
26 #include "webrtc/modules/audio_processing/test/test_utils.h" | 27 #include "webrtc/modules/audio_processing/test/test_utils.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
43 // TODO(ekmeyerson): Switch to using StreamConfig and ProcessingConfig where | 44 // TODO(ekmeyerson): Switch to using StreamConfig and ProcessingConfig where |
44 // applicable. | 45 // applicable. |
45 | 46 |
46 // TODO(bjornv): This is not feasible until the functionality has been | 47 // TODO(bjornv): This is not feasible until the functionality has been |
47 // re-implemented; see comment at the bottom of this file. For now, the user has | 48 // re-implemented; see comment at the bottom of this file. For now, the user has |
48 // to hard code the |write_ref_data| value. | 49 // to hard code the |write_ref_data| value. |
49 // When false, this will compare the output data with the results stored to | 50 // When false, this will compare the output data with the results stored to |
50 // file. This is the typical case. When the file should be updated, it can | 51 // file. This is the typical case. When the file should be updated, it can |
51 // be set to true with the command-line switch --write_ref_data. | 52 // be set to true with the command-line switch --write_ref_data. |
52 bool write_ref_data = false; | 53 bool write_ref_data = false; |
53 const int kChannels[] = {1, 2}; | 54 const google::protobuf::int32 kChannels[] = {1, 2}; |
hlundin-webrtc
2016/01/07 10:57:06
Why?
hlundin-webrtc
2016/01/07 11:00:06
OK, I see why. Never mind.
| |
54 const size_t kChannelsSize = sizeof(kChannels) / sizeof(*kChannels); | |
55 | |
56 const int kSampleRates[] = {8000, 16000, 32000, 48000}; | 55 const int kSampleRates[] = {8000, 16000, 32000, 48000}; |
57 const size_t kSampleRatesSize = sizeof(kSampleRates) / sizeof(*kSampleRates); | |
58 | 56 |
59 #if defined(WEBRTC_AUDIOPROC_FIXED_PROFILE) | 57 #if defined(WEBRTC_AUDIOPROC_FIXED_PROFILE) |
60 // AECM doesn't support super-wb. | 58 // AECM doesn't support super-wb. |
61 const int kProcessSampleRates[] = {8000, 16000}; | 59 const int kProcessSampleRates[] = {8000, 16000}; |
62 #elif defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE) | 60 #elif defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE) |
63 const int kProcessSampleRates[] = {8000, 16000, 32000, 48000}; | 61 const int kProcessSampleRates[] = {8000, 16000, 32000, 48000}; |
64 #endif | 62 #endif |
65 const size_t kProcessSampleRatesSize = sizeof(kProcessSampleRates) / | |
66 sizeof(*kProcessSampleRates); | |
67 | 63 |
68 enum StreamDirection { kForward = 0, kReverse }; | 64 enum StreamDirection { kForward = 0, kReverse }; |
69 | 65 |
70 void ConvertToFloat(const int16_t* int_data, ChannelBuffer<float>* cb) { | 66 void ConvertToFloat(const int16_t* int_data, ChannelBuffer<float>* cb) { |
71 ChannelBuffer<int16_t> cb_int(cb->num_frames(), | 67 ChannelBuffer<int16_t> cb_int(cb->num_frames(), |
72 cb->num_channels()); | 68 cb->num_channels()); |
73 Deinterleave(int_data, | 69 Deinterleave(int_data, |
74 cb->num_frames(), | 70 cb->num_frames(), |
75 cb->num_channels(), | 71 cb->num_channels(), |
76 cb_int.channels()); | 72 cb_int.channels()); |
(...skipping 13 matching lines...) Expand all Loading... | |
90 switch (layout) { | 86 switch (layout) { |
91 case AudioProcessing::kMono: | 87 case AudioProcessing::kMono: |
92 return 1; | 88 return 1; |
93 case AudioProcessing::kMonoAndKeyboard: | 89 case AudioProcessing::kMonoAndKeyboard: |
94 case AudioProcessing::kStereo: | 90 case AudioProcessing::kStereo: |
95 return 2; | 91 return 2; |
96 case AudioProcessing::kStereoAndKeyboard: | 92 case AudioProcessing::kStereoAndKeyboard: |
97 return 3; | 93 return 3; |
98 } | 94 } |
99 assert(false); | 95 assert(false); |
100 return -1; | 96 return 0; |
101 } | 97 } |
102 | 98 |
103 int TruncateToMultipleOf10(int value) { | 99 int TruncateToMultipleOf10(int value) { |
104 return (value / 10) * 10; | 100 return (value / 10) * 10; |
105 } | 101 } |
106 | 102 |
107 void MixStereoToMono(const float* stereo, float* mono, | 103 void MixStereoToMono(const float* stereo, float* mono, |
108 int samples_per_channel) { | 104 size_t samples_per_channel) { |
109 for (int i = 0; i < samples_per_channel; ++i) | 105 for (size_t i = 0; i < samples_per_channel; ++i) |
110 mono[i] = (stereo[i * 2] + stereo[i * 2 + 1]) / 2; | 106 mono[i] = (stereo[i * 2] + stereo[i * 2 + 1]) / 2; |
111 } | 107 } |
112 | 108 |
113 void MixStereoToMono(const int16_t* stereo, int16_t* mono, | 109 void MixStereoToMono(const int16_t* stereo, int16_t* mono, |
114 int samples_per_channel) { | 110 size_t samples_per_channel) { |
115 for (int i = 0; i < samples_per_channel; ++i) | 111 for (size_t i = 0; i < samples_per_channel; ++i) |
116 mono[i] = (stereo[i * 2] + stereo[i * 2 + 1]) >> 1; | 112 mono[i] = (stereo[i * 2] + stereo[i * 2 + 1]) >> 1; |
117 } | 113 } |
118 | 114 |
119 void CopyLeftToRightChannel(int16_t* stereo, int samples_per_channel) { | 115 void CopyLeftToRightChannel(int16_t* stereo, size_t samples_per_channel) { |
120 for (int i = 0; i < samples_per_channel; i++) { | 116 for (size_t i = 0; i < samples_per_channel; i++) { |
121 stereo[i * 2 + 1] = stereo[i * 2]; | 117 stereo[i * 2 + 1] = stereo[i * 2]; |
122 } | 118 } |
123 } | 119 } |
124 | 120 |
125 void VerifyChannelsAreEqual(int16_t* stereo, int samples_per_channel) { | 121 void VerifyChannelsAreEqual(int16_t* stereo, size_t samples_per_channel) { |
126 for (int i = 0; i < samples_per_channel; i++) { | 122 for (size_t i = 0; i < samples_per_channel; i++) { |
127 EXPECT_EQ(stereo[i * 2 + 1], stereo[i * 2]); | 123 EXPECT_EQ(stereo[i * 2 + 1], stereo[i * 2]); |
128 } | 124 } |
129 } | 125 } |
130 | 126 |
131 void SetFrameTo(AudioFrame* frame, int16_t value) { | 127 void SetFrameTo(AudioFrame* frame, int16_t value) { |
132 for (size_t i = 0; i < frame->samples_per_channel_ * frame->num_channels_; | 128 for (size_t i = 0; i < frame->samples_per_channel_ * frame->num_channels_; |
133 ++i) { | 129 ++i) { |
134 frame->data_[i] = value; | 130 frame->data_[i] = value; |
135 } | 131 } |
136 } | 132 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 EXPECT_NOERR(ap->voice_detection()->Enable(true)); | 185 EXPECT_NOERR(ap->voice_detection()->Enable(true)); |
190 } | 186 } |
191 | 187 |
192 // These functions are only used by ApmTest.Process. | 188 // These functions are only used by ApmTest.Process. |
193 template <class T> | 189 template <class T> |
194 T AbsValue(T a) { | 190 T AbsValue(T a) { |
195 return a > 0 ? a: -a; | 191 return a > 0 ? a: -a; |
196 } | 192 } |
197 | 193 |
198 int16_t MaxAudioFrame(const AudioFrame& frame) { | 194 int16_t MaxAudioFrame(const AudioFrame& frame) { |
199 const int length = frame.samples_per_channel_ * frame.num_channels_; | 195 const size_t length = frame.samples_per_channel_ * frame.num_channels_; |
200 int16_t max_data = AbsValue(frame.data_[0]); | 196 int16_t max_data = AbsValue(frame.data_[0]); |
201 for (int i = 1; i < length; i++) { | 197 for (size_t i = 1; i < length; i++) { |
202 max_data = std::max(max_data, AbsValue(frame.data_[i])); | 198 max_data = std::max(max_data, AbsValue(frame.data_[i])); |
203 } | 199 } |
204 | 200 |
205 return max_data; | 201 return max_data; |
206 } | 202 } |
207 | 203 |
208 #if defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE) | 204 #if defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE) |
209 void TestStats(const AudioProcessing::Statistic& test, | 205 void TestStats(const AudioProcessing::Statistic& test, |
210 const audioproc::Test::Statistic& reference) { | 206 const audioproc::Test::Statistic& reference) { |
211 EXPECT_EQ(reference.instant(), test.instant); | 207 EXPECT_EQ(reference.instant(), test.instant); |
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
892 } | 888 } |
893 } | 889 } |
894 } | 890 } |
895 | 891 |
896 TEST_F(ApmTest, SampleRatesInt) { | 892 TEST_F(ApmTest, SampleRatesInt) { |
897 // Testing invalid sample rates | 893 // Testing invalid sample rates |
898 SetContainerFormat(10000, 2, frame_, &float_cb_); | 894 SetContainerFormat(10000, 2, frame_, &float_cb_); |
899 EXPECT_EQ(apm_->kBadSampleRateError, ProcessStreamChooser(kIntFormat)); | 895 EXPECT_EQ(apm_->kBadSampleRateError, ProcessStreamChooser(kIntFormat)); |
900 // Testing valid sample rates | 896 // Testing valid sample rates |
901 int fs[] = {8000, 16000, 32000, 48000}; | 897 int fs[] = {8000, 16000, 32000, 48000}; |
902 for (size_t i = 0; i < sizeof(fs) / sizeof(*fs); i++) { | 898 for (size_t i = 0; i < arraysize(fs); i++) { |
903 SetContainerFormat(fs[i], 2, frame_, &float_cb_); | 899 SetContainerFormat(fs[i], 2, frame_, &float_cb_); |
904 EXPECT_NOERR(ProcessStreamChooser(kIntFormat)); | 900 EXPECT_NOERR(ProcessStreamChooser(kIntFormat)); |
905 } | 901 } |
906 } | 902 } |
907 | 903 |
908 TEST_F(ApmTest, EchoCancellation) { | 904 TEST_F(ApmTest, EchoCancellation) { |
909 EXPECT_EQ(apm_->kNoError, | 905 EXPECT_EQ(apm_->kNoError, |
910 apm_->echo_cancellation()->enable_drift_compensation(true)); | 906 apm_->echo_cancellation()->enable_drift_compensation(true)); |
911 EXPECT_TRUE(apm_->echo_cancellation()->is_drift_compensation_enabled()); | 907 EXPECT_TRUE(apm_->echo_cancellation()->is_drift_compensation_enabled()); |
912 EXPECT_EQ(apm_->kNoError, | 908 EXPECT_EQ(apm_->kNoError, |
913 apm_->echo_cancellation()->enable_drift_compensation(false)); | 909 apm_->echo_cancellation()->enable_drift_compensation(false)); |
914 EXPECT_FALSE(apm_->echo_cancellation()->is_drift_compensation_enabled()); | 910 EXPECT_FALSE(apm_->echo_cancellation()->is_drift_compensation_enabled()); |
915 | 911 |
916 EchoCancellation::SuppressionLevel level[] = { | 912 EchoCancellation::SuppressionLevel level[] = { |
917 EchoCancellation::kLowSuppression, | 913 EchoCancellation::kLowSuppression, |
918 EchoCancellation::kModerateSuppression, | 914 EchoCancellation::kModerateSuppression, |
919 EchoCancellation::kHighSuppression, | 915 EchoCancellation::kHighSuppression, |
920 }; | 916 }; |
921 for (size_t i = 0; i < sizeof(level)/sizeof(*level); i++) { | 917 for (size_t i = 0; i < arraysize(level); i++) { |
922 EXPECT_EQ(apm_->kNoError, | 918 EXPECT_EQ(apm_->kNoError, |
923 apm_->echo_cancellation()->set_suppression_level(level[i])); | 919 apm_->echo_cancellation()->set_suppression_level(level[i])); |
924 EXPECT_EQ(level[i], | 920 EXPECT_EQ(level[i], |
925 apm_->echo_cancellation()->suppression_level()); | 921 apm_->echo_cancellation()->suppression_level()); |
926 } | 922 } |
927 | 923 |
928 EchoCancellation::Metrics metrics; | 924 EchoCancellation::Metrics metrics; |
929 EXPECT_EQ(apm_->kNotEnabledError, | 925 EXPECT_EQ(apm_->kNotEnabledError, |
930 apm_->echo_cancellation()->GetMetrics(&metrics)); | 926 apm_->echo_cancellation()->GetMetrics(&metrics)); |
931 | 927 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
988 // buffer is 66 ms in 8 kHz. | 984 // buffer is 66 ms in 8 kHz. |
989 // | 985 // |
990 // It is known that for 16 kHz (and 32 kHz) sampling frequency there is an | 986 // It is known that for 16 kHz (and 32 kHz) sampling frequency there is an |
991 // additional stuffing of 8 ms on the fly, but it seems to have no impact on | 987 // additional stuffing of 8 ms on the fly, but it seems to have no impact on |
992 // delay estimation. This should be noted though. In case of test failure, | 988 // delay estimation. This should be noted though. In case of test failure, |
993 // this could be the cause. | 989 // this could be the cause. |
994 const int kSystemDelayMs = 66; | 990 const int kSystemDelayMs = 66; |
995 // Test a couple of corner cases and verify that the estimated delay is | 991 // Test a couple of corner cases and verify that the estimated delay is |
996 // within a valid region (set to +-1.5 blocks). Note that these cases are | 992 // within a valid region (set to +-1.5 blocks). Note that these cases are |
997 // sampling frequency dependent. | 993 // sampling frequency dependent. |
998 for (size_t i = 0; i < kProcessSampleRatesSize; i++) { | 994 for (size_t i = 0; i < arraysize(kProcessSampleRates); i++) { |
999 Init(kProcessSampleRates[i], | 995 Init(kProcessSampleRates[i], |
1000 kProcessSampleRates[i], | 996 kProcessSampleRates[i], |
1001 kProcessSampleRates[i], | 997 kProcessSampleRates[i], |
1002 2, | 998 2, |
1003 2, | 999 2, |
1004 2, | 1000 2, |
1005 false); | 1001 false); |
1006 // Sampling frequency dependent variables. | 1002 // Sampling frequency dependent variables. |
1007 const int num_ms_per_block = | 1003 const int num_ms_per_block = |
1008 std::max(4, static_cast<int>(640 / frame_->samples_per_channel_)); | 1004 std::max(4, static_cast<int>(640 / frame_->samples_per_channel_)); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1060 EXPECT_TRUE(apm_->echo_control_mobile()->is_enabled()); | 1056 EXPECT_TRUE(apm_->echo_control_mobile()->is_enabled()); |
1061 | 1057 |
1062 // Toggle routing modes | 1058 // Toggle routing modes |
1063 EchoControlMobile::RoutingMode mode[] = { | 1059 EchoControlMobile::RoutingMode mode[] = { |
1064 EchoControlMobile::kQuietEarpieceOrHeadset, | 1060 EchoControlMobile::kQuietEarpieceOrHeadset, |
1065 EchoControlMobile::kEarpiece, | 1061 EchoControlMobile::kEarpiece, |
1066 EchoControlMobile::kLoudEarpiece, | 1062 EchoControlMobile::kLoudEarpiece, |
1067 EchoControlMobile::kSpeakerphone, | 1063 EchoControlMobile::kSpeakerphone, |
1068 EchoControlMobile::kLoudSpeakerphone, | 1064 EchoControlMobile::kLoudSpeakerphone, |
1069 }; | 1065 }; |
1070 for (size_t i = 0; i < sizeof(mode)/sizeof(*mode); i++) { | 1066 for (size_t i = 0; i < arraysize(mode); i++) { |
1071 EXPECT_EQ(apm_->kNoError, | 1067 EXPECT_EQ(apm_->kNoError, |
1072 apm_->echo_control_mobile()->set_routing_mode(mode[i])); | 1068 apm_->echo_control_mobile()->set_routing_mode(mode[i])); |
1073 EXPECT_EQ(mode[i], | 1069 EXPECT_EQ(mode[i], |
1074 apm_->echo_control_mobile()->routing_mode()); | 1070 apm_->echo_control_mobile()->routing_mode()); |
1075 } | 1071 } |
1076 // Turn comfort noise off/on | 1072 // Turn comfort noise off/on |
1077 EXPECT_EQ(apm_->kNoError, | 1073 EXPECT_EQ(apm_->kNoError, |
1078 apm_->echo_control_mobile()->enable_comfort_noise(false)); | 1074 apm_->echo_control_mobile()->enable_comfort_noise(false)); |
1079 EXPECT_FALSE(apm_->echo_control_mobile()->is_comfort_noise_enabled()); | 1075 EXPECT_FALSE(apm_->echo_control_mobile()->is_comfort_noise_enabled()); |
1080 EXPECT_EQ(apm_->kNoError, | 1076 EXPECT_EQ(apm_->kNoError, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1125 // Testing gain modes | 1121 // Testing gain modes |
1126 EXPECT_EQ(apm_->kNoError, | 1122 EXPECT_EQ(apm_->kNoError, |
1127 apm_->gain_control()->set_mode( | 1123 apm_->gain_control()->set_mode( |
1128 apm_->gain_control()->mode())); | 1124 apm_->gain_control()->mode())); |
1129 | 1125 |
1130 GainControl::Mode mode[] = { | 1126 GainControl::Mode mode[] = { |
1131 GainControl::kAdaptiveAnalog, | 1127 GainControl::kAdaptiveAnalog, |
1132 GainControl::kAdaptiveDigital, | 1128 GainControl::kAdaptiveDigital, |
1133 GainControl::kFixedDigital | 1129 GainControl::kFixedDigital |
1134 }; | 1130 }; |
1135 for (size_t i = 0; i < sizeof(mode)/sizeof(*mode); i++) { | 1131 for (size_t i = 0; i < arraysize(mode); i++) { |
1136 EXPECT_EQ(apm_->kNoError, | 1132 EXPECT_EQ(apm_->kNoError, |
1137 apm_->gain_control()->set_mode(mode[i])); | 1133 apm_->gain_control()->set_mode(mode[i])); |
1138 EXPECT_EQ(mode[i], apm_->gain_control()->mode()); | 1134 EXPECT_EQ(mode[i], apm_->gain_control()->mode()); |
1139 } | 1135 } |
1140 // Testing invalid target levels | 1136 // Testing invalid target levels |
1141 EXPECT_EQ(apm_->kBadParameterError, | 1137 EXPECT_EQ(apm_->kBadParameterError, |
1142 apm_->gain_control()->set_target_level_dbfs(-3)); | 1138 apm_->gain_control()->set_target_level_dbfs(-3)); |
1143 EXPECT_EQ(apm_->kBadParameterError, | 1139 EXPECT_EQ(apm_->kBadParameterError, |
1144 apm_->gain_control()->set_target_level_dbfs(-40)); | 1140 apm_->gain_control()->set_target_level_dbfs(-40)); |
1145 // Testing valid target levels | 1141 // Testing valid target levels |
1146 EXPECT_EQ(apm_->kNoError, | 1142 EXPECT_EQ(apm_->kNoError, |
1147 apm_->gain_control()->set_target_level_dbfs( | 1143 apm_->gain_control()->set_target_level_dbfs( |
1148 apm_->gain_control()->target_level_dbfs())); | 1144 apm_->gain_control()->target_level_dbfs())); |
1149 | 1145 |
1150 int level_dbfs[] = {0, 6, 31}; | 1146 int level_dbfs[] = {0, 6, 31}; |
1151 for (size_t i = 0; i < sizeof(level_dbfs)/sizeof(*level_dbfs); i++) { | 1147 for (size_t i = 0; i < arraysize(level_dbfs); i++) { |
1152 EXPECT_EQ(apm_->kNoError, | 1148 EXPECT_EQ(apm_->kNoError, |
1153 apm_->gain_control()->set_target_level_dbfs(level_dbfs[i])); | 1149 apm_->gain_control()->set_target_level_dbfs(level_dbfs[i])); |
1154 EXPECT_EQ(level_dbfs[i], apm_->gain_control()->target_level_dbfs()); | 1150 EXPECT_EQ(level_dbfs[i], apm_->gain_control()->target_level_dbfs()); |
1155 } | 1151 } |
1156 | 1152 |
1157 // Testing invalid compression gains | 1153 // Testing invalid compression gains |
1158 EXPECT_EQ(apm_->kBadParameterError, | 1154 EXPECT_EQ(apm_->kBadParameterError, |
1159 apm_->gain_control()->set_compression_gain_db(-1)); | 1155 apm_->gain_control()->set_compression_gain_db(-1)); |
1160 EXPECT_EQ(apm_->kBadParameterError, | 1156 EXPECT_EQ(apm_->kBadParameterError, |
1161 apm_->gain_control()->set_compression_gain_db(100)); | 1157 apm_->gain_control()->set_compression_gain_db(100)); |
1162 | 1158 |
1163 // Testing valid compression gains | 1159 // Testing valid compression gains |
1164 EXPECT_EQ(apm_->kNoError, | 1160 EXPECT_EQ(apm_->kNoError, |
1165 apm_->gain_control()->set_compression_gain_db( | 1161 apm_->gain_control()->set_compression_gain_db( |
1166 apm_->gain_control()->compression_gain_db())); | 1162 apm_->gain_control()->compression_gain_db())); |
1167 | 1163 |
1168 int gain_db[] = {0, 10, 90}; | 1164 int gain_db[] = {0, 10, 90}; |
1169 for (size_t i = 0; i < sizeof(gain_db)/sizeof(*gain_db); i++) { | 1165 for (size_t i = 0; i < arraysize(gain_db); i++) { |
1170 EXPECT_EQ(apm_->kNoError, | 1166 EXPECT_EQ(apm_->kNoError, |
1171 apm_->gain_control()->set_compression_gain_db(gain_db[i])); | 1167 apm_->gain_control()->set_compression_gain_db(gain_db[i])); |
1172 EXPECT_EQ(gain_db[i], apm_->gain_control()->compression_gain_db()); | 1168 EXPECT_EQ(gain_db[i], apm_->gain_control()->compression_gain_db()); |
1173 } | 1169 } |
1174 | 1170 |
1175 // Testing limiter off/on | 1171 // Testing limiter off/on |
1176 EXPECT_EQ(apm_->kNoError, apm_->gain_control()->enable_limiter(false)); | 1172 EXPECT_EQ(apm_->kNoError, apm_->gain_control()->enable_limiter(false)); |
1177 EXPECT_FALSE(apm_->gain_control()->is_limiter_enabled()); | 1173 EXPECT_FALSE(apm_->gain_control()->is_limiter_enabled()); |
1178 EXPECT_EQ(apm_->kNoError, apm_->gain_control()->enable_limiter(true)); | 1174 EXPECT_EQ(apm_->kNoError, apm_->gain_control()->enable_limiter(true)); |
1179 EXPECT_TRUE(apm_->gain_control()->is_limiter_enabled()); | 1175 EXPECT_TRUE(apm_->gain_control()->is_limiter_enabled()); |
(...skipping 10 matching lines...) Expand all Loading... | |
1190 EXPECT_EQ(apm_->kBadParameterError, | 1186 EXPECT_EQ(apm_->kBadParameterError, |
1191 apm_->gain_control()->set_analog_level_limits(512, 255)); | 1187 apm_->gain_control()->set_analog_level_limits(512, 255)); |
1192 | 1188 |
1193 // Testing valid level limits | 1189 // Testing valid level limits |
1194 EXPECT_EQ(apm_->kNoError, | 1190 EXPECT_EQ(apm_->kNoError, |
1195 apm_->gain_control()->set_analog_level_limits( | 1191 apm_->gain_control()->set_analog_level_limits( |
1196 apm_->gain_control()->analog_level_minimum(), | 1192 apm_->gain_control()->analog_level_minimum(), |
1197 apm_->gain_control()->analog_level_maximum())); | 1193 apm_->gain_control()->analog_level_maximum())); |
1198 | 1194 |
1199 int min_level[] = {0, 255, 1024}; | 1195 int min_level[] = {0, 255, 1024}; |
1200 for (size_t i = 0; i < sizeof(min_level)/sizeof(*min_level); i++) { | 1196 for (size_t i = 0; i < arraysize(min_level); i++) { |
1201 EXPECT_EQ(apm_->kNoError, | 1197 EXPECT_EQ(apm_->kNoError, |
1202 apm_->gain_control()->set_analog_level_limits(min_level[i], 1024)); | 1198 apm_->gain_control()->set_analog_level_limits(min_level[i], 1024)); |
1203 EXPECT_EQ(min_level[i], apm_->gain_control()->analog_level_minimum()); | 1199 EXPECT_EQ(min_level[i], apm_->gain_control()->analog_level_minimum()); |
1204 } | 1200 } |
1205 | 1201 |
1206 int max_level[] = {0, 1024, 65535}; | 1202 int max_level[] = {0, 1024, 65535}; |
1207 for (size_t i = 0; i < sizeof(min_level)/sizeof(*min_level); i++) { | 1203 for (size_t i = 0; i < arraysize(min_level); i++) { |
1208 EXPECT_EQ(apm_->kNoError, | 1204 EXPECT_EQ(apm_->kNoError, |
1209 apm_->gain_control()->set_analog_level_limits(0, max_level[i])); | 1205 apm_->gain_control()->set_analog_level_limits(0, max_level[i])); |
1210 EXPECT_EQ(max_level[i], apm_->gain_control()->analog_level_maximum()); | 1206 EXPECT_EQ(max_level[i], apm_->gain_control()->analog_level_maximum()); |
1211 } | 1207 } |
1212 | 1208 |
1213 // TODO(ajm): stream_is_saturated() and stream_analog_level() | 1209 // TODO(ajm): stream_is_saturated() and stream_analog_level() |
1214 | 1210 |
1215 // Turn AGC off | 1211 // Turn AGC off |
1216 EXPECT_EQ(apm_->kNoError, apm_->gain_control()->Enable(false)); | 1212 EXPECT_EQ(apm_->kNoError, apm_->gain_control()->Enable(false)); |
1217 EXPECT_FALSE(apm_->gain_control()->is_enabled()); | 1213 EXPECT_FALSE(apm_->gain_control()->is_enabled()); |
(...skipping 18 matching lines...) Expand all Loading... | |
1236 out_analog_level = apm_->gain_control()->stream_analog_level(); | 1232 out_analog_level = apm_->gain_control()->stream_analog_level(); |
1237 } | 1233 } |
1238 | 1234 |
1239 // Ensure the AGC is still able to reach the maximum. | 1235 // Ensure the AGC is still able to reach the maximum. |
1240 EXPECT_EQ(255, out_analog_level); | 1236 EXPECT_EQ(255, out_analog_level); |
1241 } | 1237 } |
1242 | 1238 |
1243 // Verifies that despite volume slider quantization, the AGC can continue to | 1239 // Verifies that despite volume slider quantization, the AGC can continue to |
1244 // increase its volume. | 1240 // increase its volume. |
1245 TEST_F(ApmTest, QuantizedVolumeDoesNotGetStuck) { | 1241 TEST_F(ApmTest, QuantizedVolumeDoesNotGetStuck) { |
1246 for (size_t i = 0; i < kSampleRatesSize; ++i) { | 1242 for (size_t i = 0; i < arraysize(kSampleRates); ++i) { |
1247 RunQuantizedVolumeDoesNotGetStuckTest(kSampleRates[i]); | 1243 RunQuantizedVolumeDoesNotGetStuckTest(kSampleRates[i]); |
1248 } | 1244 } |
1249 } | 1245 } |
1250 | 1246 |
1251 void ApmTest::RunManualVolumeChangeIsPossibleTest(int sample_rate) { | 1247 void ApmTest::RunManualVolumeChangeIsPossibleTest(int sample_rate) { |
1252 Init(sample_rate, sample_rate, sample_rate, 2, 2, 2, false); | 1248 Init(sample_rate, sample_rate, sample_rate, 2, 2, 2, false); |
1253 EXPECT_EQ(apm_->kNoError, | 1249 EXPECT_EQ(apm_->kNoError, |
1254 apm_->gain_control()->set_mode(GainControl::kAdaptiveAnalog)); | 1250 apm_->gain_control()->set_mode(GainControl::kAdaptiveAnalog)); |
1255 EXPECT_EQ(apm_->kNoError, apm_->gain_control()->Enable(true)); | 1251 EXPECT_EQ(apm_->kNoError, apm_->gain_control()->Enable(true)); |
1256 | 1252 |
(...skipping 24 matching lines...) Expand all Loading... | |
1281 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); | 1277 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); |
1282 out_analog_level = apm_->gain_control()->stream_analog_level(); | 1278 out_analog_level = apm_->gain_control()->stream_analog_level(); |
1283 // Check that AGC respected the manually adjusted volume. | 1279 // Check that AGC respected the manually adjusted volume. |
1284 EXPECT_LT(out_analog_level, highest_level_reached); | 1280 EXPECT_LT(out_analog_level, highest_level_reached); |
1285 } | 1281 } |
1286 // Check that the volume was still raised. | 1282 // Check that the volume was still raised. |
1287 EXPECT_GT(out_analog_level, 100); | 1283 EXPECT_GT(out_analog_level, 100); |
1288 } | 1284 } |
1289 | 1285 |
1290 TEST_F(ApmTest, ManualVolumeChangeIsPossible) { | 1286 TEST_F(ApmTest, ManualVolumeChangeIsPossible) { |
1291 for (size_t i = 0; i < kSampleRatesSize; ++i) { | 1287 for (size_t i = 0; i < arraysize(kSampleRates); ++i) { |
1292 RunManualVolumeChangeIsPossibleTest(kSampleRates[i]); | 1288 RunManualVolumeChangeIsPossibleTest(kSampleRates[i]); |
1293 } | 1289 } |
1294 } | 1290 } |
1295 | 1291 |
1296 #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS) | 1292 #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS) |
1297 TEST_F(ApmTest, AgcOnlyAdaptsWhenTargetSignalIsPresent) { | 1293 TEST_F(ApmTest, AgcOnlyAdaptsWhenTargetSignalIsPresent) { |
1298 const int kSampleRateHz = 16000; | 1294 const int kSampleRateHz = 16000; |
1299 const int kSamplesPerChannel = | 1295 const size_t kSamplesPerChannel = |
1300 AudioProcessing::kChunkSizeMs * kSampleRateHz / 1000; | 1296 static_cast<size_t>(AudioProcessing::kChunkSizeMs * kSampleRateHz / 1000); |
1301 const int kNumInputChannels = 2; | 1297 const int kNumInputChannels = 2; |
1302 const int kNumOutputChannels = 1; | 1298 const int kNumOutputChannels = 1; |
1303 const int kNumChunks = 700; | 1299 const size_t kNumChunks = 700; |
1304 const float kScaleFactor = 0.25f; | 1300 const float kScaleFactor = 0.25f; |
1305 Config config; | 1301 Config config; |
1306 std::vector<webrtc::Point> geometry; | 1302 std::vector<webrtc::Point> geometry; |
1307 geometry.push_back(webrtc::Point(0.f, 0.f, 0.f)); | 1303 geometry.push_back(webrtc::Point(0.f, 0.f, 0.f)); |
1308 geometry.push_back(webrtc::Point(0.05f, 0.f, 0.f)); | 1304 geometry.push_back(webrtc::Point(0.05f, 0.f, 0.f)); |
1309 config.Set<Beamforming>(new Beamforming(true, geometry)); | 1305 config.Set<Beamforming>(new Beamforming(true, geometry)); |
1310 testing::NiceMock<MockNonlinearBeamformer>* beamformer = | 1306 testing::NiceMock<MockNonlinearBeamformer>* beamformer = |
1311 new testing::NiceMock<MockNonlinearBeamformer>(geometry); | 1307 new testing::NiceMock<MockNonlinearBeamformer>(geometry); |
1312 rtc::scoped_ptr<AudioProcessing> apm( | 1308 rtc::scoped_ptr<AudioProcessing> apm( |
1313 AudioProcessing::Create(config, beamformer)); | 1309 AudioProcessing::Create(config, beamformer)); |
1314 EXPECT_EQ(kNoErr, apm->gain_control()->Enable(true)); | 1310 EXPECT_EQ(kNoErr, apm->gain_control()->Enable(true)); |
1315 ChannelBuffer<float> src_buf(kSamplesPerChannel, kNumInputChannels); | 1311 ChannelBuffer<float> src_buf(kSamplesPerChannel, kNumInputChannels); |
1316 ChannelBuffer<float> dest_buf(kSamplesPerChannel, kNumOutputChannels); | 1312 ChannelBuffer<float> dest_buf(kSamplesPerChannel, kNumOutputChannels); |
1317 const int max_length = kSamplesPerChannel * std::max(kNumInputChannels, | 1313 const size_t max_length = kSamplesPerChannel * std::max(kNumInputChannels, |
1318 kNumOutputChannels); | 1314 kNumOutputChannels); |
1319 rtc::scoped_ptr<int16_t[]> int_data(new int16_t[max_length]); | 1315 rtc::scoped_ptr<int16_t[]> int_data(new int16_t[max_length]); |
1320 rtc::scoped_ptr<float[]> float_data(new float[max_length]); | 1316 rtc::scoped_ptr<float[]> float_data(new float[max_length]); |
1321 std::string filename = ResourceFilePath("far", kSampleRateHz); | 1317 std::string filename = ResourceFilePath("far", kSampleRateHz); |
1322 FILE* far_file = fopen(filename.c_str(), "rb"); | 1318 FILE* far_file = fopen(filename.c_str(), "rb"); |
1323 ASSERT_TRUE(far_file != NULL) << "Could not open file " << filename << "\n"; | 1319 ASSERT_TRUE(far_file != NULL) << "Could not open file " << filename << "\n"; |
1324 const int kDefaultVolume = apm->gain_control()->stream_analog_level(); | 1320 const int kDefaultVolume = apm->gain_control()->stream_analog_level(); |
1325 const int kDefaultCompressionGain = | 1321 const int kDefaultCompressionGain = |
1326 apm->gain_control()->compression_gain_db(); | 1322 apm->gain_control()->compression_gain_db(); |
1327 bool is_target = false; | 1323 bool is_target = false; |
1328 EXPECT_CALL(*beamformer, is_target_present()) | 1324 EXPECT_CALL(*beamformer, is_target_present()) |
1329 .WillRepeatedly(testing::ReturnPointee(&is_target)); | 1325 .WillRepeatedly(testing::ReturnPointee(&is_target)); |
1330 for (int i = 0; i < kNumChunks; ++i) { | 1326 for (size_t i = 0; i < kNumChunks; ++i) { |
1331 ASSERT_TRUE(ReadChunk(far_file, | 1327 ASSERT_TRUE(ReadChunk(far_file, |
1332 int_data.get(), | 1328 int_data.get(), |
1333 float_data.get(), | 1329 float_data.get(), |
1334 &src_buf)); | 1330 &src_buf)); |
1335 for (int j = 0; j < kNumInputChannels; ++j) { | 1331 for (int j = 0; j < kNumInputChannels; ++j) { |
1336 for (int k = 0; k < kSamplesPerChannel; ++k) { | 1332 for (size_t k = 0; k < kSamplesPerChannel; ++k) { |
1337 src_buf.channels()[j][k] *= kScaleFactor; | 1333 src_buf.channels()[j][k] *= kScaleFactor; |
1338 } | 1334 } |
1339 } | 1335 } |
1340 EXPECT_EQ(kNoErr, | 1336 EXPECT_EQ(kNoErr, |
1341 apm->ProcessStream(src_buf.channels(), | 1337 apm->ProcessStream(src_buf.channels(), |
1342 src_buf.num_frames(), | 1338 src_buf.num_frames(), |
1343 kSampleRateHz, | 1339 kSampleRateHz, |
1344 LayoutFromChannels(src_buf.num_channels()), | 1340 LayoutFromChannels(src_buf.num_channels()), |
1345 kSampleRateHz, | 1341 kSampleRateHz, |
1346 LayoutFromChannels(dest_buf.num_channels()), | 1342 LayoutFromChannels(dest_buf.num_channels()), |
1347 dest_buf.channels())); | 1343 dest_buf.channels())); |
1348 } | 1344 } |
1349 EXPECT_EQ(kDefaultVolume, | 1345 EXPECT_EQ(kDefaultVolume, |
1350 apm->gain_control()->stream_analog_level()); | 1346 apm->gain_control()->stream_analog_level()); |
1351 EXPECT_EQ(kDefaultCompressionGain, | 1347 EXPECT_EQ(kDefaultCompressionGain, |
1352 apm->gain_control()->compression_gain_db()); | 1348 apm->gain_control()->compression_gain_db()); |
1353 rewind(far_file); | 1349 rewind(far_file); |
1354 is_target = true; | 1350 is_target = true; |
1355 for (int i = 0; i < kNumChunks; ++i) { | 1351 for (size_t i = 0; i < kNumChunks; ++i) { |
1356 ASSERT_TRUE(ReadChunk(far_file, | 1352 ASSERT_TRUE(ReadChunk(far_file, |
1357 int_data.get(), | 1353 int_data.get(), |
1358 float_data.get(), | 1354 float_data.get(), |
1359 &src_buf)); | 1355 &src_buf)); |
1360 for (int j = 0; j < kNumInputChannels; ++j) { | 1356 for (int j = 0; j < kNumInputChannels; ++j) { |
1361 for (int k = 0; k < kSamplesPerChannel; ++k) { | 1357 for (size_t k = 0; k < kSamplesPerChannel; ++k) { |
1362 src_buf.channels()[j][k] *= kScaleFactor; | 1358 src_buf.channels()[j][k] *= kScaleFactor; |
1363 } | 1359 } |
1364 } | 1360 } |
1365 EXPECT_EQ(kNoErr, | 1361 EXPECT_EQ(kNoErr, |
1366 apm->ProcessStream(src_buf.channels(), | 1362 apm->ProcessStream(src_buf.channels(), |
1367 src_buf.num_frames(), | 1363 src_buf.num_frames(), |
1368 kSampleRateHz, | 1364 kSampleRateHz, |
1369 LayoutFromChannels(src_buf.num_channels()), | 1365 LayoutFromChannels(src_buf.num_channels()), |
1370 kSampleRateHz, | 1366 kSampleRateHz, |
1371 LayoutFromChannels(dest_buf.num_channels()), | 1367 LayoutFromChannels(dest_buf.num_channels()), |
1372 dest_buf.channels())); | 1368 dest_buf.channels())); |
1373 } | 1369 } |
1374 EXPECT_LT(kDefaultVolume, | 1370 EXPECT_LT(kDefaultVolume, |
1375 apm->gain_control()->stream_analog_level()); | 1371 apm->gain_control()->stream_analog_level()); |
1376 EXPECT_LT(kDefaultCompressionGain, | 1372 EXPECT_LT(kDefaultCompressionGain, |
1377 apm->gain_control()->compression_gain_db()); | 1373 apm->gain_control()->compression_gain_db()); |
1378 ASSERT_EQ(0, fclose(far_file)); | 1374 ASSERT_EQ(0, fclose(far_file)); |
1379 } | 1375 } |
1380 #endif | 1376 #endif |
1381 | 1377 |
1382 TEST_F(ApmTest, NoiseSuppression) { | 1378 TEST_F(ApmTest, NoiseSuppression) { |
1383 // Test valid suppression levels. | 1379 // Test valid suppression levels. |
1384 NoiseSuppression::Level level[] = { | 1380 NoiseSuppression::Level level[] = { |
1385 NoiseSuppression::kLow, | 1381 NoiseSuppression::kLow, |
1386 NoiseSuppression::kModerate, | 1382 NoiseSuppression::kModerate, |
1387 NoiseSuppression::kHigh, | 1383 NoiseSuppression::kHigh, |
1388 NoiseSuppression::kVeryHigh | 1384 NoiseSuppression::kVeryHigh |
1389 }; | 1385 }; |
1390 for (size_t i = 0; i < sizeof(level)/sizeof(*level); i++) { | 1386 for (size_t i = 0; i < arraysize(level); i++) { |
1391 EXPECT_EQ(apm_->kNoError, | 1387 EXPECT_EQ(apm_->kNoError, |
1392 apm_->noise_suppression()->set_level(level[i])); | 1388 apm_->noise_suppression()->set_level(level[i])); |
1393 EXPECT_EQ(level[i], apm_->noise_suppression()->level()); | 1389 EXPECT_EQ(level[i], apm_->noise_suppression()->level()); |
1394 } | 1390 } |
1395 | 1391 |
1396 // Turn NS on/off | 1392 // Turn NS on/off |
1397 EXPECT_EQ(apm_->kNoError, apm_->noise_suppression()->Enable(true)); | 1393 EXPECT_EQ(apm_->kNoError, apm_->noise_suppression()->Enable(true)); |
1398 EXPECT_TRUE(apm_->noise_suppression()->is_enabled()); | 1394 EXPECT_TRUE(apm_->noise_suppression()->is_enabled()); |
1399 EXPECT_EQ(apm_->kNoError, apm_->noise_suppression()->Enable(false)); | 1395 EXPECT_EQ(apm_->kNoError, apm_->noise_suppression()->Enable(false)); |
1400 EXPECT_FALSE(apm_->noise_suppression()->is_enabled()); | 1396 EXPECT_FALSE(apm_->noise_suppression()->is_enabled()); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1482 apm_->voice_detection()->set_stream_has_voice(false)); | 1478 apm_->voice_detection()->set_stream_has_voice(false)); |
1483 EXPECT_FALSE(apm_->voice_detection()->stream_has_voice()); | 1479 EXPECT_FALSE(apm_->voice_detection()->stream_has_voice()); |
1484 | 1480 |
1485 // Test valid likelihoods | 1481 // Test valid likelihoods |
1486 VoiceDetection::Likelihood likelihood[] = { | 1482 VoiceDetection::Likelihood likelihood[] = { |
1487 VoiceDetection::kVeryLowLikelihood, | 1483 VoiceDetection::kVeryLowLikelihood, |
1488 VoiceDetection::kLowLikelihood, | 1484 VoiceDetection::kLowLikelihood, |
1489 VoiceDetection::kModerateLikelihood, | 1485 VoiceDetection::kModerateLikelihood, |
1490 VoiceDetection::kHighLikelihood | 1486 VoiceDetection::kHighLikelihood |
1491 }; | 1487 }; |
1492 for (size_t i = 0; i < sizeof(likelihood)/sizeof(*likelihood); i++) { | 1488 for (size_t i = 0; i < arraysize(likelihood); i++) { |
1493 EXPECT_EQ(apm_->kNoError, | 1489 EXPECT_EQ(apm_->kNoError, |
1494 apm_->voice_detection()->set_likelihood(likelihood[i])); | 1490 apm_->voice_detection()->set_likelihood(likelihood[i])); |
1495 EXPECT_EQ(likelihood[i], apm_->voice_detection()->likelihood()); | 1491 EXPECT_EQ(likelihood[i], apm_->voice_detection()->likelihood()); |
1496 } | 1492 } |
1497 | 1493 |
1498 /* TODO(bjornv): Enable once VAD supports other frame lengths than 10 ms | 1494 /* TODO(bjornv): Enable once VAD supports other frame lengths than 10 ms |
1499 // Test invalid frame sizes | 1495 // Test invalid frame sizes |
1500 EXPECT_EQ(apm_->kBadParameterError, | 1496 EXPECT_EQ(apm_->kBadParameterError, |
1501 apm_->voice_detection()->set_frame_size_ms(12)); | 1497 apm_->voice_detection()->set_frame_size_ms(12)); |
1502 | 1498 |
(...skipping 11 matching lines...) Expand all Loading... | |
1514 EXPECT_EQ(apm_->kNoError, apm_->voice_detection()->Enable(false)); | 1510 EXPECT_EQ(apm_->kNoError, apm_->voice_detection()->Enable(false)); |
1515 EXPECT_FALSE(apm_->voice_detection()->is_enabled()); | 1511 EXPECT_FALSE(apm_->voice_detection()->is_enabled()); |
1516 | 1512 |
1517 // Test that AudioFrame activity is maintained when VAD is disabled. | 1513 // Test that AudioFrame activity is maintained when VAD is disabled. |
1518 EXPECT_EQ(apm_->kNoError, apm_->voice_detection()->Enable(false)); | 1514 EXPECT_EQ(apm_->kNoError, apm_->voice_detection()->Enable(false)); |
1519 AudioFrame::VADActivity activity[] = { | 1515 AudioFrame::VADActivity activity[] = { |
1520 AudioFrame::kVadActive, | 1516 AudioFrame::kVadActive, |
1521 AudioFrame::kVadPassive, | 1517 AudioFrame::kVadPassive, |
1522 AudioFrame::kVadUnknown | 1518 AudioFrame::kVadUnknown |
1523 }; | 1519 }; |
1524 for (size_t i = 0; i < sizeof(activity)/sizeof(*activity); i++) { | 1520 for (size_t i = 0; i < arraysize(activity); i++) { |
1525 frame_->vad_activity_ = activity[i]; | 1521 frame_->vad_activity_ = activity[i]; |
1526 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); | 1522 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); |
1527 EXPECT_EQ(activity[i], frame_->vad_activity_); | 1523 EXPECT_EQ(activity[i], frame_->vad_activity_); |
1528 } | 1524 } |
1529 | 1525 |
1530 // Test that AudioFrame activity is set when VAD is enabled. | 1526 // Test that AudioFrame activity is set when VAD is enabled. |
1531 EXPECT_EQ(apm_->kNoError, apm_->voice_detection()->Enable(true)); | 1527 EXPECT_EQ(apm_->kNoError, apm_->voice_detection()->Enable(true)); |
1532 frame_->vad_activity_ = AudioFrame::kVadUnknown; | 1528 frame_->vad_activity_ = AudioFrame::kVadUnknown; |
1533 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); | 1529 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); |
1534 EXPECT_NE(AudioFrame::kVadUnknown, frame_->vad_activity_); | 1530 EXPECT_NE(AudioFrame::kVadUnknown, frame_->vad_activity_); |
1535 | 1531 |
1536 // TODO(bjornv): Add tests for streamed voice; stream_has_voice() | 1532 // TODO(bjornv): Add tests for streamed voice; stream_has_voice() |
1537 } | 1533 } |
1538 | 1534 |
1539 TEST_F(ApmTest, AllProcessingDisabledByDefault) { | 1535 TEST_F(ApmTest, AllProcessingDisabledByDefault) { |
1540 EXPECT_FALSE(apm_->echo_cancellation()->is_enabled()); | 1536 EXPECT_FALSE(apm_->echo_cancellation()->is_enabled()); |
1541 EXPECT_FALSE(apm_->echo_control_mobile()->is_enabled()); | 1537 EXPECT_FALSE(apm_->echo_control_mobile()->is_enabled()); |
1542 EXPECT_FALSE(apm_->gain_control()->is_enabled()); | 1538 EXPECT_FALSE(apm_->gain_control()->is_enabled()); |
1543 EXPECT_FALSE(apm_->high_pass_filter()->is_enabled()); | 1539 EXPECT_FALSE(apm_->high_pass_filter()->is_enabled()); |
1544 EXPECT_FALSE(apm_->level_estimator()->is_enabled()); | 1540 EXPECT_FALSE(apm_->level_estimator()->is_enabled()); |
1545 EXPECT_FALSE(apm_->noise_suppression()->is_enabled()); | 1541 EXPECT_FALSE(apm_->noise_suppression()->is_enabled()); |
1546 EXPECT_FALSE(apm_->voice_detection()->is_enabled()); | 1542 EXPECT_FALSE(apm_->voice_detection()->is_enabled()); |
1547 } | 1543 } |
1548 | 1544 |
1549 TEST_F(ApmTest, NoProcessingWhenAllComponentsDisabled) { | 1545 TEST_F(ApmTest, NoProcessingWhenAllComponentsDisabled) { |
1550 for (size_t i = 0; i < kSampleRatesSize; i++) { | 1546 for (size_t i = 0; i < arraysize(kSampleRates); i++) { |
1551 Init(kSampleRates[i], kSampleRates[i], kSampleRates[i], 2, 2, 2, false); | 1547 Init(kSampleRates[i], kSampleRates[i], kSampleRates[i], 2, 2, 2, false); |
1552 SetFrameTo(frame_, 1000, 2000); | 1548 SetFrameTo(frame_, 1000, 2000); |
1553 AudioFrame frame_copy; | 1549 AudioFrame frame_copy; |
1554 frame_copy.CopyFrom(*frame_); | 1550 frame_copy.CopyFrom(*frame_); |
1555 for (int j = 0; j < 1000; j++) { | 1551 for (int j = 0; j < 1000; j++) { |
1556 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); | 1552 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_)); |
1557 EXPECT_TRUE(FrameDataAreEqual(*frame_, frame_copy)); | 1553 EXPECT_TRUE(FrameDataAreEqual(*frame_, frame_copy)); |
1558 EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(frame_)); | 1554 EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(frame_)); |
1559 EXPECT_TRUE(FrameDataAreEqual(*frame_, frame_copy)); | 1555 EXPECT_TRUE(FrameDataAreEqual(*frame_, frame_copy)); |
1560 } | 1556 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1592 output_stream, &rev_dest_channels)); | 1588 output_stream, &rev_dest_channels)); |
1593 | 1589 |
1594 for (size_t i = 0; i < kSamples; ++i) { | 1590 for (size_t i = 0; i < kSamples; ++i) { |
1595 EXPECT_EQ(src[i], rev_dest[i]); | 1591 EXPECT_EQ(src[i], rev_dest[i]); |
1596 } | 1592 } |
1597 } | 1593 } |
1598 | 1594 |
1599 TEST_F(ApmTest, IdenticalInputChannelsResultInIdenticalOutputChannels) { | 1595 TEST_F(ApmTest, IdenticalInputChannelsResultInIdenticalOutputChannels) { |
1600 EnableAllComponents(); | 1596 EnableAllComponents(); |
1601 | 1597 |
1602 for (size_t i = 0; i < kProcessSampleRatesSize; i++) { | 1598 for (size_t i = 0; i < arraysize(kProcessSampleRates); i++) { |
1603 Init(kProcessSampleRates[i], | 1599 Init(kProcessSampleRates[i], |
1604 kProcessSampleRates[i], | 1600 kProcessSampleRates[i], |
1605 kProcessSampleRates[i], | 1601 kProcessSampleRates[i], |
1606 2, | 1602 2, |
1607 2, | 1603 2, |
1608 2, | 1604 2, |
1609 false); | 1605 false); |
1610 int analog_level = 127; | 1606 int analog_level = 127; |
1611 ASSERT_EQ(0, feof(far_file_)); | 1607 ASSERT_EQ(0, feof(far_file_)); |
1612 ASSERT_EQ(0, feof(near_file_)); | 1608 ASSERT_EQ(0, feof(near_file_)); |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1931 printf("Running test %d of %d...\n", i + 1, ref_data.test_size()); | 1927 printf("Running test %d of %d...\n", i + 1, ref_data.test_size()); |
1932 | 1928 |
1933 audioproc::Test* test = ref_data.mutable_test(i); | 1929 audioproc::Test* test = ref_data.mutable_test(i); |
1934 // TODO(ajm): Restore downmixing test cases. | 1930 // TODO(ajm): Restore downmixing test cases. |
1935 if (test->num_input_channels() != test->num_output_channels()) | 1931 if (test->num_input_channels() != test->num_output_channels()) |
1936 continue; | 1932 continue; |
1937 | 1933 |
1938 const int num_render_channels = test->num_reverse_channels(); | 1934 const int num_render_channels = test->num_reverse_channels(); |
1939 const int num_input_channels = test->num_input_channels(); | 1935 const int num_input_channels = test->num_input_channels(); |
1940 const int num_output_channels = test->num_output_channels(); | 1936 const int num_output_channels = test->num_output_channels(); |
1941 const int samples_per_channel = test->sample_rate() * | 1937 const size_t samples_per_channel = static_cast<size_t>( |
1942 AudioProcessing::kChunkSizeMs / 1000; | 1938 test->sample_rate() * AudioProcessing::kChunkSizeMs / 1000); |
1943 | 1939 |
1944 Init(test->sample_rate(), test->sample_rate(), test->sample_rate(), | 1940 Init(test->sample_rate(), test->sample_rate(), test->sample_rate(), |
1945 num_input_channels, num_output_channels, num_render_channels, true); | 1941 num_input_channels, num_output_channels, num_render_channels, true); |
1946 Init(fapm.get()); | 1942 Init(fapm.get()); |
1947 | 1943 |
1948 ChannelBuffer<int16_t> output_cb(samples_per_channel, num_input_channels); | 1944 ChannelBuffer<int16_t> output_cb(samples_per_channel, num_input_channels); |
1949 ChannelBuffer<int16_t> output_int16(samples_per_channel, | 1945 ChannelBuffer<int16_t> output_int16(samples_per_channel, |
1950 num_input_channels); | 1946 num_input_channels); |
1951 | 1947 |
1952 int analog_level = 127; | 1948 int analog_level = 127; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2024 // of enabled components. | 2020 // of enabled components. |
2025 | 2021 |
2026 TEST_F(ApmTest, Process) { | 2022 TEST_F(ApmTest, Process) { |
2027 GOOGLE_PROTOBUF_VERIFY_VERSION; | 2023 GOOGLE_PROTOBUF_VERIFY_VERSION; |
2028 audioproc::OutputData ref_data; | 2024 audioproc::OutputData ref_data; |
2029 | 2025 |
2030 if (!write_ref_data) { | 2026 if (!write_ref_data) { |
2031 OpenFileAndReadMessage(ref_filename_, &ref_data); | 2027 OpenFileAndReadMessage(ref_filename_, &ref_data); |
2032 } else { | 2028 } else { |
2033 // Write the desired tests to the protobuf reference file. | 2029 // Write the desired tests to the protobuf reference file. |
2034 for (size_t i = 0; i < kChannelsSize; i++) { | 2030 for (size_t i = 0; i < arraysize(kChannels); i++) { |
2035 for (size_t j = 0; j < kChannelsSize; j++) { | 2031 for (size_t j = 0; j < arraysize(kChannels); j++) { |
2036 for (size_t l = 0; l < kProcessSampleRatesSize; l++) { | 2032 for (size_t l = 0; l < arraysize(kProcessSampleRates); l++) { |
2037 audioproc::Test* test = ref_data.add_test(); | 2033 audioproc::Test* test = ref_data.add_test(); |
2038 test->set_num_reverse_channels(kChannels[i]); | 2034 test->set_num_reverse_channels(kChannels[i]); |
2039 test->set_num_input_channels(kChannels[j]); | 2035 test->set_num_input_channels(kChannels[j]); |
2040 test->set_num_output_channels(kChannels[j]); | 2036 test->set_num_output_channels(kChannels[j]); |
2041 test->set_sample_rate(kProcessSampleRates[l]); | 2037 test->set_sample_rate(kProcessSampleRates[l]); |
2042 test->set_use_aec_extended_filter(false); | 2038 test->set_use_aec_extended_filter(false); |
2043 } | 2039 } |
2044 } | 2040 } |
2045 } | 2041 } |
2046 #if defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE) | 2042 #if defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE) |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2253 TEST_F(ApmTest, NoErrorsWithKeyboardChannel) { | 2249 TEST_F(ApmTest, NoErrorsWithKeyboardChannel) { |
2254 struct ChannelFormat { | 2250 struct ChannelFormat { |
2255 AudioProcessing::ChannelLayout in_layout; | 2251 AudioProcessing::ChannelLayout in_layout; |
2256 AudioProcessing::ChannelLayout out_layout; | 2252 AudioProcessing::ChannelLayout out_layout; |
2257 }; | 2253 }; |
2258 ChannelFormat cf[] = { | 2254 ChannelFormat cf[] = { |
2259 {AudioProcessing::kMonoAndKeyboard, AudioProcessing::kMono}, | 2255 {AudioProcessing::kMonoAndKeyboard, AudioProcessing::kMono}, |
2260 {AudioProcessing::kStereoAndKeyboard, AudioProcessing::kMono}, | 2256 {AudioProcessing::kStereoAndKeyboard, AudioProcessing::kMono}, |
2261 {AudioProcessing::kStereoAndKeyboard, AudioProcessing::kStereo}, | 2257 {AudioProcessing::kStereoAndKeyboard, AudioProcessing::kStereo}, |
2262 }; | 2258 }; |
2263 size_t channel_format_size = sizeof(cf) / sizeof(*cf); | |
2264 | 2259 |
2265 rtc::scoped_ptr<AudioProcessing> ap(AudioProcessing::Create()); | 2260 rtc::scoped_ptr<AudioProcessing> ap(AudioProcessing::Create()); |
2266 // Enable one component just to ensure some processing takes place. | 2261 // Enable one component just to ensure some processing takes place. |
2267 ap->noise_suppression()->Enable(true); | 2262 ap->noise_suppression()->Enable(true); |
2268 for (size_t i = 0; i < channel_format_size; ++i) { | 2263 for (size_t i = 0; i < arraysize(cf); ++i) { |
2269 const int in_rate = 44100; | 2264 const int in_rate = 44100; |
2270 const int out_rate = 48000; | 2265 const int out_rate = 48000; |
2271 ChannelBuffer<float> in_cb(SamplesFromRate(in_rate), | 2266 ChannelBuffer<float> in_cb(SamplesFromRate(in_rate), |
2272 TotalChannelsFromLayout(cf[i].in_layout)); | 2267 TotalChannelsFromLayout(cf[i].in_layout)); |
2273 ChannelBuffer<float> out_cb(SamplesFromRate(out_rate), | 2268 ChannelBuffer<float> out_cb(SamplesFromRate(out_rate), |
2274 ChannelsFromLayout(cf[i].out_layout)); | 2269 ChannelsFromLayout(cf[i].out_layout)); |
2275 | 2270 |
2276 // Run over a few chunks. | 2271 // Run over a few chunks. |
2277 for (int j = 0; j < 10; ++j) { | 2272 for (int j = 0; j < 10; ++j) { |
2278 EXPECT_NOERR(ap->ProcessStream( | 2273 EXPECT_NOERR(ap->ProcessStream( |
2279 in_cb.channels(), | 2274 in_cb.channels(), |
2280 in_cb.num_frames(), | 2275 in_cb.num_frames(), |
2281 in_rate, | 2276 in_rate, |
2282 cf[i].in_layout, | 2277 cf[i].in_layout, |
2283 out_rate, | 2278 out_rate, |
2284 cf[i].out_layout, | 2279 cf[i].out_layout, |
2285 out_cb.channels())); | 2280 out_cb.channels())); |
2286 } | 2281 } |
2287 } | 2282 } |
2288 } | 2283 } |
2289 | 2284 |
2290 // Compares the reference and test arrays over a region around the expected | 2285 // Compares the reference and test arrays over a region around the expected |
2291 // delay. Finds the highest SNR in that region and adds the variance and squared | 2286 // delay. Finds the highest SNR in that region and adds the variance and squared |
2292 // error results to the supplied accumulators. | 2287 // error results to the supplied accumulators. |
2293 void UpdateBestSNR(const float* ref, | 2288 void UpdateBestSNR(const float* ref, |
2294 const float* test, | 2289 const float* test, |
2295 int length, | 2290 size_t length, |
2296 int expected_delay, | 2291 int expected_delay, |
2297 double* variance_acc, | 2292 double* variance_acc, |
2298 double* sq_error_acc) { | 2293 double* sq_error_acc) { |
2299 double best_snr = std::numeric_limits<double>::min(); | 2294 double best_snr = std::numeric_limits<double>::min(); |
2300 double best_variance = 0; | 2295 double best_variance = 0; |
2301 double best_sq_error = 0; | 2296 double best_sq_error = 0; |
2302 // Search over a region of eight samples around the expected delay. | 2297 // Search over a region of eight samples around the expected delay. |
2303 for (int delay = std::max(expected_delay - 4, 0); delay <= expected_delay + 4; | 2298 for (int delay = std::max(expected_delay - 4, 0); delay <= expected_delay + 4; |
2304 ++delay) { | 2299 ++delay) { |
2305 double sq_error = 0; | 2300 double sq_error = 0; |
2306 double variance = 0; | 2301 double variance = 0; |
2307 for (int i = 0; i < length - delay; ++i) { | 2302 for (size_t i = 0; i < length - delay; ++i) { |
2308 double error = test[i + delay] - ref[i]; | 2303 double error = test[i + delay] - ref[i]; |
2309 sq_error += error * error; | 2304 sq_error += error * error; |
2310 variance += ref[i] * ref[i]; | 2305 variance += ref[i] * ref[i]; |
2311 } | 2306 } |
2312 | 2307 |
2313 if (sq_error == 0) { | 2308 if (sq_error == 0) { |
2314 *variance_acc += variance; | 2309 *variance_acc += variance; |
2315 return; | 2310 return; |
2316 } | 2311 } |
2317 double snr = variance / sq_error; | 2312 double snr = variance / sq_error; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2349 reverse_input_rate_(std::tr1::get<2>(GetParam())), | 2344 reverse_input_rate_(std::tr1::get<2>(GetParam())), |
2350 reverse_output_rate_(std::tr1::get<3>(GetParam())), | 2345 reverse_output_rate_(std::tr1::get<3>(GetParam())), |
2351 expected_snr_(std::tr1::get<4>(GetParam())), | 2346 expected_snr_(std::tr1::get<4>(GetParam())), |
2352 expected_reverse_snr_(std::tr1::get<5>(GetParam())) {} | 2347 expected_reverse_snr_(std::tr1::get<5>(GetParam())) {} |
2353 | 2348 |
2354 virtual ~AudioProcessingTest() {} | 2349 virtual ~AudioProcessingTest() {} |
2355 | 2350 |
2356 static void SetUpTestCase() { | 2351 static void SetUpTestCase() { |
2357 // Create all needed output reference files. | 2352 // Create all needed output reference files. |
2358 const int kNativeRates[] = {8000, 16000, 32000, 48000}; | 2353 const int kNativeRates[] = {8000, 16000, 32000, 48000}; |
2359 const size_t kNativeRatesSize = | |
2360 sizeof(kNativeRates) / sizeof(*kNativeRates); | |
2361 const int kNumChannels[] = {1, 2}; | 2354 const int kNumChannels[] = {1, 2}; |
2362 const size_t kNumChannelsSize = | 2355 for (size_t i = 0; i < arraysize(kNativeRates); ++i) { |
2363 sizeof(kNumChannels) / sizeof(*kNumChannels); | 2356 for (size_t j = 0; j < arraysize(kNumChannels); ++j) { |
2364 for (size_t i = 0; i < kNativeRatesSize; ++i) { | 2357 for (size_t k = 0; k < arraysize(kNumChannels); ++k) { |
2365 for (size_t j = 0; j < kNumChannelsSize; ++j) { | |
2366 for (size_t k = 0; k < kNumChannelsSize; ++k) { | |
2367 // The reference files always have matching input and output channels. | 2358 // The reference files always have matching input and output channels. |
2368 ProcessFormat(kNativeRates[i], kNativeRates[i], kNativeRates[i], | 2359 ProcessFormat(kNativeRates[i], kNativeRates[i], kNativeRates[i], |
2369 kNativeRates[i], kNumChannels[j], kNumChannels[j], | 2360 kNativeRates[i], kNumChannels[j], kNumChannels[j], |
2370 kNumChannels[k], kNumChannels[k], "ref"); | 2361 kNumChannels[k], kNumChannels[k], "ref"); |
2371 } | 2362 } |
2372 } | 2363 } |
2373 } | 2364 } |
2374 } | 2365 } |
2375 | 2366 |
2376 static void TearDownTestCase() { | 2367 static void TearDownTestCase() { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2455 fwd_cb.num_frames(), | 2446 fwd_cb.num_frames(), |
2456 input_rate, | 2447 input_rate, |
2457 LayoutFromChannels(num_input_channels), | 2448 LayoutFromChannels(num_input_channels), |
2458 output_rate, | 2449 output_rate, |
2459 LayoutFromChannels(num_output_channels), | 2450 LayoutFromChannels(num_output_channels), |
2460 out_cb.channels())); | 2451 out_cb.channels())); |
2461 | 2452 |
2462 // Dump forward output to file. | 2453 // Dump forward output to file. |
2463 Interleave(out_cb.channels(), out_cb.num_frames(), out_cb.num_channels(), | 2454 Interleave(out_cb.channels(), out_cb.num_frames(), out_cb.num_channels(), |
2464 float_data.get()); | 2455 float_data.get()); |
2465 int out_length = out_cb.num_channels() * out_cb.num_frames(); | 2456 size_t out_length = out_cb.num_channels() * out_cb.num_frames(); |
2466 | 2457 |
2467 ASSERT_EQ(static_cast<size_t>(out_length), | 2458 ASSERT_EQ(out_length, |
2468 fwrite(float_data.get(), sizeof(float_data[0]), | 2459 fwrite(float_data.get(), sizeof(float_data[0]), |
2469 out_length, out_file)); | 2460 out_length, out_file)); |
2470 | 2461 |
2471 // Dump reverse output to file. | 2462 // Dump reverse output to file. |
2472 Interleave(rev_out_cb.channels(), rev_out_cb.num_frames(), | 2463 Interleave(rev_out_cb.channels(), rev_out_cb.num_frames(), |
2473 rev_out_cb.num_channels(), float_data.get()); | 2464 rev_out_cb.num_channels(), float_data.get()); |
2474 int rev_out_length = rev_out_cb.num_channels() * rev_out_cb.num_frames(); | 2465 size_t rev_out_length = |
2466 rev_out_cb.num_channels() * rev_out_cb.num_frames(); | |
2475 | 2467 |
2476 ASSERT_EQ(static_cast<size_t>(rev_out_length), | 2468 ASSERT_EQ(rev_out_length, |
2477 fwrite(float_data.get(), sizeof(float_data[0]), rev_out_length, | 2469 fwrite(float_data.get(), sizeof(float_data[0]), rev_out_length, |
2478 rev_out_file)); | 2470 rev_out_file)); |
2479 | 2471 |
2480 analog_level = ap->gain_control()->stream_analog_level(); | 2472 analog_level = ap->gain_control()->stream_analog_level(); |
2481 } | 2473 } |
2482 fclose(far_file); | 2474 fclose(far_file); |
2483 fclose(near_file); | 2475 fclose(near_file); |
2484 fclose(out_file); | 2476 fclose(out_file); |
2485 fclose(rev_out_file); | 2477 fclose(rev_out_file); |
2486 } | 2478 } |
(...skipping 15 matching lines...) Expand all Loading... | |
2502 int num_reverse_output; | 2494 int num_reverse_output; |
2503 }; | 2495 }; |
2504 ChannelFormat cf[] = { | 2496 ChannelFormat cf[] = { |
2505 {1, 1, 1, 1}, | 2497 {1, 1, 1, 1}, |
2506 {1, 1, 2, 1}, | 2498 {1, 1, 2, 1}, |
2507 {2, 1, 1, 1}, | 2499 {2, 1, 1, 1}, |
2508 {2, 1, 2, 1}, | 2500 {2, 1, 2, 1}, |
2509 {2, 2, 1, 1}, | 2501 {2, 2, 1, 1}, |
2510 {2, 2, 2, 2}, | 2502 {2, 2, 2, 2}, |
2511 }; | 2503 }; |
2512 size_t channel_format_size = sizeof(cf) / sizeof(*cf); | |
2513 | 2504 |
2514 for (size_t i = 0; i < channel_format_size; ++i) { | 2505 for (size_t i = 0; i < arraysize(cf); ++i) { |
2515 ProcessFormat(input_rate_, output_rate_, reverse_input_rate_, | 2506 ProcessFormat(input_rate_, output_rate_, reverse_input_rate_, |
2516 reverse_output_rate_, cf[i].num_input, cf[i].num_output, | 2507 reverse_output_rate_, cf[i].num_input, cf[i].num_output, |
2517 cf[i].num_reverse_input, cf[i].num_reverse_output, "out"); | 2508 cf[i].num_reverse_input, cf[i].num_reverse_output, "out"); |
2518 | 2509 |
2519 // Verify output for both directions. | 2510 // Verify output for both directions. |
2520 std::vector<StreamDirection> stream_directions; | 2511 std::vector<StreamDirection> stream_directions; |
2521 stream_directions.push_back(kForward); | 2512 stream_directions.push_back(kForward); |
2522 stream_directions.push_back(kReverse); | 2513 stream_directions.push_back(kReverse); |
2523 for (StreamDirection file_direction : stream_directions) { | 2514 for (StreamDirection file_direction : stream_directions) { |
2524 const int in_rate = file_direction ? reverse_input_rate_ : input_rate_; | 2515 const int in_rate = file_direction ? reverse_input_rate_ : input_rate_; |
(...skipping 29 matching lines...) Expand all Loading... | |
2554 // The reference files always have matching input and output channels. | 2545 // The reference files always have matching input and output channels. |
2555 FILE* ref_file = fopen( | 2546 FILE* ref_file = fopen( |
2556 OutputFilePath("ref", ref_rate, ref_rate, ref_rate, ref_rate, | 2547 OutputFilePath("ref", ref_rate, ref_rate, ref_rate, ref_rate, |
2557 cf[i].num_output, cf[i].num_output, | 2548 cf[i].num_output, cf[i].num_output, |
2558 cf[i].num_reverse_output, cf[i].num_reverse_output, | 2549 cf[i].num_reverse_output, cf[i].num_reverse_output, |
2559 file_direction).c_str(), | 2550 file_direction).c_str(), |
2560 "rb"); | 2551 "rb"); |
2561 ASSERT_TRUE(out_file != NULL); | 2552 ASSERT_TRUE(out_file != NULL); |
2562 ASSERT_TRUE(ref_file != NULL); | 2553 ASSERT_TRUE(ref_file != NULL); |
2563 | 2554 |
2564 const int ref_length = SamplesFromRate(ref_rate) * out_num; | 2555 const size_t ref_length = SamplesFromRate(ref_rate) * out_num; |
2565 const int out_length = SamplesFromRate(out_rate) * out_num; | 2556 const size_t out_length = SamplesFromRate(out_rate) * out_num; |
2566 // Data from the reference file. | 2557 // Data from the reference file. |
2567 rtc::scoped_ptr<float[]> ref_data(new float[ref_length]); | 2558 rtc::scoped_ptr<float[]> ref_data(new float[ref_length]); |
2568 // Data from the output file. | 2559 // Data from the output file. |
2569 rtc::scoped_ptr<float[]> out_data(new float[out_length]); | 2560 rtc::scoped_ptr<float[]> out_data(new float[out_length]); |
2570 // Data from the resampled output, in case the reference and output rates | 2561 // Data from the resampled output, in case the reference and output rates |
2571 // don't match. | 2562 // don't match. |
2572 rtc::scoped_ptr<float[]> cmp_data(new float[ref_length]); | 2563 rtc::scoped_ptr<float[]> cmp_data(new float[ref_length]); |
2573 | 2564 |
2574 PushResampler<float> resampler; | 2565 PushResampler<float> resampler; |
2575 resampler.InitializeIfNeeded(out_rate, ref_rate, out_num); | 2566 resampler.InitializeIfNeeded(out_rate, ref_rate, out_num); |
(...skipping 19 matching lines...) Expand all Loading... | |
2595 floor(expected_delay_sec * ref_rate + 0.5f) * out_num; | 2586 floor(expected_delay_sec * ref_rate + 0.5f) * out_num; |
2596 | 2587 |
2597 double variance = 0; | 2588 double variance = 0; |
2598 double sq_error = 0; | 2589 double sq_error = 0; |
2599 while (fread(out_data.get(), sizeof(out_data[0]), out_length, out_file) && | 2590 while (fread(out_data.get(), sizeof(out_data[0]), out_length, out_file) && |
2600 fread(ref_data.get(), sizeof(ref_data[0]), ref_length, ref_file)) { | 2591 fread(ref_data.get(), sizeof(ref_data[0]), ref_length, ref_file)) { |
2601 float* out_ptr = out_data.get(); | 2592 float* out_ptr = out_data.get(); |
2602 if (out_rate != ref_rate) { | 2593 if (out_rate != ref_rate) { |
2603 // Resample the output back to its internal processing rate if | 2594 // Resample the output back to its internal processing rate if |
2604 // necssary. | 2595 // necssary. |
2605 ASSERT_EQ(ref_length, resampler.Resample(out_ptr, out_length, | 2596 ASSERT_EQ(ref_length, |
2606 cmp_data.get(), ref_length)); | 2597 static_cast<size_t>(resampler.Resample( |
2598 out_ptr, out_length, cmp_data.get(), ref_length))); | |
2607 out_ptr = cmp_data.get(); | 2599 out_ptr = cmp_data.get(); |
2608 } | 2600 } |
2609 | 2601 |
2610 // Update the |sq_error| and |variance| accumulators with the highest | 2602 // Update the |sq_error| and |variance| accumulators with the highest |
2611 // SNR of reference vs output. | 2603 // SNR of reference vs output. |
2612 UpdateBestSNR(ref_data.get(), out_ptr, ref_length, expected_delay, | 2604 UpdateBestSNR(ref_data.get(), out_ptr, ref_length, expected_delay, |
2613 &variance, &sq_error); | 2605 &variance, &sq_error); |
2614 } | 2606 } |
2615 | 2607 |
2616 std::cout << "(" << input_rate_ << ", " << output_rate_ << ", " | 2608 std::cout << "(" << input_rate_ << ", " << output_rate_ << ", " |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2743 std::tr1::make_tuple(16000, 32000, 48000, 32000, 25, 35), | 2735 std::tr1::make_tuple(16000, 32000, 48000, 32000, 25, 35), |
2744 std::tr1::make_tuple(16000, 32000, 32000, 32000, 25, 0), | 2736 std::tr1::make_tuple(16000, 32000, 32000, 32000, 25, 0), |
2745 std::tr1::make_tuple(16000, 32000, 16000, 32000, 25, 20), | 2737 std::tr1::make_tuple(16000, 32000, 16000, 32000, 25, 20), |
2746 std::tr1::make_tuple(16000, 16000, 48000, 16000, 35, 20), | 2738 std::tr1::make_tuple(16000, 16000, 48000, 16000, 35, 20), |
2747 std::tr1::make_tuple(16000, 16000, 32000, 16000, 40, 20), | 2739 std::tr1::make_tuple(16000, 16000, 32000, 16000, 40, 20), |
2748 std::tr1::make_tuple(16000, 16000, 16000, 16000, 0, 0))); | 2740 std::tr1::make_tuple(16000, 16000, 16000, 16000, 0, 0))); |
2749 #endif | 2741 #endif |
2750 | 2742 |
2751 } // namespace | 2743 } // namespace |
2752 } // namespace webrtc | 2744 } // namespace webrtc |
OLD | NEW |