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