blob: 6e0b175003ff54dc2ad34e07237bff1521bcd69e [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
andrew@webrtc.org293d22b2012-01-30 22:04:26 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000011#include <math.h>
ajm@google.com59e41402011-07-28 17:34:04 +000012#include <stdio.h>
kwiberg62eaacf2016-02-17 06:39:05 -080013
andrew@webrtc.org07bf9a02012-05-05 00:32:00 +000014#include <algorithm>
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000015#include <limits>
kwiberg62eaacf2016-02-17 06:39:05 -080016#include <memory>
bjornv@webrtc.org3e102492013-02-14 15:29:09 +000017#include <queue>
andrew@webrtc.org07bf9a02012-05-05 00:32:00 +000018
pkasting25702cb2016-01-08 13:50:27 -080019#include "webrtc/base/arraysize.h"
kwiberg9e2be5f2016-09-14 05:23:22 -070020#include "webrtc/base/checks.h"
kwiberg77eab702016-09-28 17:42:01 -070021#include "webrtc/base/ignore_wundef.h"
andrew@webrtc.org27c69802014-02-18 20:24:56 +000022#include "webrtc/common_audio/include/audio_util.h"
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000023#include "webrtc/common_audio/resampler/include/push_resampler.h"
24#include "webrtc/common_audio/resampler/push_sinc_resampler.h"
bjornv@webrtc.org3e102492013-02-14 15:29:09 +000025#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
mgraczyk@chromium.org0f663de2015-03-13 00:13:32 +000026#include "webrtc/modules/audio_processing/beamformer/mock_nonlinear_beamformer.h"
aluebs@webrtc.org87893762014-11-27 23:40:25 +000027#include "webrtc/modules/audio_processing/common.h"
bjornv@webrtc.org3e102492013-02-14 15:29:09 +000028#include "webrtc/modules/audio_processing/include/audio_processing.h"
Andrew MacDonaldcb05b722015-05-07 22:17:51 -070029#include "webrtc/modules/audio_processing/test/protobuf_utils.h"
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000030#include "webrtc/modules/audio_processing/test/test_utils.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010031#include "webrtc/modules/include/module_common_types.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010032#include "webrtc/system_wrappers/include/event_wrapper.h"
33#include "webrtc/system_wrappers/include/trace.h"
kwiberg77eab702016-09-28 17:42:01 -070034#include "webrtc/test/gtest.h"
bjornv@webrtc.org3e102492013-02-14 15:29:09 +000035#include "webrtc/test/testsupport/fileutils.h"
kwiberg77eab702016-09-28 17:42:01 -070036
37RTC_PUSH_IGNORING_WUNDEF()
leozwang@webrtc.orga3736342012-03-16 21:36:00 +000038#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
leozwang@webrtc.org534e4952012-10-22 21:21:52 +000039#include "external/webrtc/webrtc/modules/audio_processing/test/unittest.pb.h"
leozwang@webrtc.orga3736342012-03-16 21:36:00 +000040#else
kjellander78ddd732016-02-09 08:13:06 -080041#include "webrtc/modules/audio_processing/unittest.pb.h"
leozwang@webrtc.orga3736342012-03-16 21:36:00 +000042#endif
kwiberg77eab702016-09-28 17:42:01 -070043RTC_POP_IGNORING_WUNDEF()
niklase@google.com470e71d2011-07-07 08:21:25 +000044
andrew@webrtc.org27c69802014-02-18 20:24:56 +000045namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000046namespace {
andrew@webrtc.org17e40642014-03-04 20:58:13 +000047
ekmeyerson60d9b332015-08-14 10:35:55 -070048// TODO(ekmeyerson): Switch to using StreamConfig and ProcessingConfig where
49// applicable.
50
bjornv@webrtc.orgbbd47fc2014-01-13 08:54:34 +000051// TODO(bjornv): This is not feasible until the functionality has been
bjornv@webrtc.org8dd60cc2014-09-11 08:36:35 +000052// re-implemented; see comment at the bottom of this file. For now, the user has
53// to hard code the |write_ref_data| value.
ajm@google.com59e41402011-07-28 17:34:04 +000054// When false, this will compare the output data with the results stored to
niklase@google.com470e71d2011-07-07 08:21:25 +000055// file. This is the typical case. When the file should be updated, it can
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +000056// be set to true with the command-line switch --write_ref_data.
57bool write_ref_data = false;
pkasting25702cb2016-01-08 13:50:27 -080058const google::protobuf::int32 kChannels[] = {1, 2};
Alejandro Luebs47748742015-05-22 12:00:21 -070059const int kSampleRates[] = {8000, 16000, 32000, 48000};
andrew@webrtc.orgecac9b72012-05-02 00:04:10 +000060
aluebseb3603b2016-04-20 15:27:58 -070061#if defined(WEBRTC_AUDIOPROC_FIXED_PROFILE)
62// Android doesn't support 48kHz.
63const int kProcessSampleRates[] = {8000, 16000, 32000};
64#elif defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE)
Alejandro Luebs47748742015-05-22 12:00:21 -070065const int kProcessSampleRates[] = {8000, 16000, 32000, 48000};
aluebseb3603b2016-04-20 15:27:58 -070066#endif
andrew@webrtc.org07bf9a02012-05-05 00:32:00 +000067
ekmeyerson60d9b332015-08-14 10:35:55 -070068enum StreamDirection { kForward = 0, kReverse };
69
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000070void ConvertToFloat(const int16_t* int_data, ChannelBuffer<float>* cb) {
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +000071 ChannelBuffer<int16_t> cb_int(cb->num_frames(),
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000072 cb->num_channels());
73 Deinterleave(int_data,
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +000074 cb->num_frames(),
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000075 cb->num_channels(),
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000076 cb_int.channels());
Peter Kasting69558702016-01-12 16:26:35 -080077 for (size_t i = 0; i < cb->num_channels(); ++i) {
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +000078 S16ToFloat(cb_int.channels()[i],
79 cb->num_frames(),
80 cb->channels()[i]);
81 }
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000082}
andrew@webrtc.org17e40642014-03-04 20:58:13 +000083
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +000084void ConvertToFloat(const AudioFrame& frame, ChannelBuffer<float>* cb) {
85 ConvertToFloat(frame.data_, cb);
86}
87
andrew@webrtc.org103657b2014-04-24 18:28:56 +000088// Number of channels including the keyboard channel.
Peter Kasting69558702016-01-12 16:26:35 -080089size_t TotalChannelsFromLayout(AudioProcessing::ChannelLayout layout) {
andrew@webrtc.org103657b2014-04-24 18:28:56 +000090 switch (layout) {
91 case AudioProcessing::kMono:
92 return 1;
93 case AudioProcessing::kMonoAndKeyboard:
94 case AudioProcessing::kStereo:
95 return 2;
96 case AudioProcessing::kStereoAndKeyboard:
97 return 3;
98 }
kwiberg9e2be5f2016-09-14 05:23:22 -070099 RTC_NOTREACHED();
pkasting25702cb2016-01-08 13:50:27 -0800100 return 0;
andrew@webrtc.org103657b2014-04-24 18:28:56 +0000101}
102
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000103int TruncateToMultipleOf10(int value) {
104 return (value / 10) * 10;
105}
106
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000107void MixStereoToMono(const float* stereo, float* mono,
pkasting25702cb2016-01-08 13:50:27 -0800108 size_t samples_per_channel) {
109 for (size_t i = 0; i < samples_per_channel; ++i)
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000110 mono[i] = (stereo[i * 2] + stereo[i * 2 + 1]) / 2;
andrew@webrtc.org81865342012-10-27 00:28:27 +0000111}
112
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000113void MixStereoToMono(const int16_t* stereo, int16_t* mono,
pkasting25702cb2016-01-08 13:50:27 -0800114 size_t samples_per_channel) {
115 for (size_t i = 0; i < samples_per_channel; ++i)
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000116 mono[i] = (stereo[i * 2] + stereo[i * 2 + 1]) >> 1;
117}
118
pkasting25702cb2016-01-08 13:50:27 -0800119void CopyLeftToRightChannel(int16_t* stereo, size_t samples_per_channel) {
120 for (size_t i = 0; i < samples_per_channel; i++) {
andrew@webrtc.org81865342012-10-27 00:28:27 +0000121 stereo[i * 2 + 1] = stereo[i * 2];
122 }
123}
124
pkasting25702cb2016-01-08 13:50:27 -0800125void VerifyChannelsAreEqual(int16_t* stereo, size_t samples_per_channel) {
126 for (size_t i = 0; i < samples_per_channel; i++) {
andrew@webrtc.org81865342012-10-27 00:28:27 +0000127 EXPECT_EQ(stereo[i * 2 + 1], stereo[i * 2]);
128 }
129}
130
131void SetFrameTo(AudioFrame* frame, int16_t value) {
Peter Kastingdce40cf2015-08-24 14:52:23 -0700132 for (size_t i = 0; i < frame->samples_per_channel_ * frame->num_channels_;
133 ++i) {
andrew@webrtc.org81865342012-10-27 00:28:27 +0000134 frame->data_[i] = value;
135 }
136}
137
138void SetFrameTo(AudioFrame* frame, int16_t left, int16_t right) {
Peter Kasting69558702016-01-12 16:26:35 -0800139 ASSERT_EQ(2u, frame->num_channels_);
Peter Kastingdce40cf2015-08-24 14:52:23 -0700140 for (size_t i = 0; i < frame->samples_per_channel_ * 2; i += 2) {
andrew@webrtc.org81865342012-10-27 00:28:27 +0000141 frame->data_[i] = left;
142 frame->data_[i + 1] = right;
143 }
144}
145
andrew@webrtc.org27c69802014-02-18 20:24:56 +0000146void ScaleFrame(AudioFrame* frame, float scale) {
Peter Kastingdce40cf2015-08-24 14:52:23 -0700147 for (size_t i = 0; i < frame->samples_per_channel_ * frame->num_channels_;
148 ++i) {
andrew@webrtc.org4fc4add2014-10-30 03:40:10 +0000149 frame->data_[i] = FloatS16ToS16(frame->data_[i] * scale);
andrew@webrtc.org27c69802014-02-18 20:24:56 +0000150 }
151}
152
andrew@webrtc.org81865342012-10-27 00:28:27 +0000153bool FrameDataAreEqual(const AudioFrame& frame1, const AudioFrame& frame2) {
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000154 if (frame1.samples_per_channel_ != frame2.samples_per_channel_) {
andrew@webrtc.org81865342012-10-27 00:28:27 +0000155 return false;
156 }
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000157 if (frame1.num_channels_ != frame2.num_channels_) {
andrew@webrtc.org81865342012-10-27 00:28:27 +0000158 return false;
159 }
160 if (memcmp(frame1.data_, frame2.data_,
161 frame1.samples_per_channel_ * frame1.num_channels_ *
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000162 sizeof(int16_t))) {
andrew@webrtc.org81865342012-10-27 00:28:27 +0000163 return false;
164 }
165 return true;
166}
167
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000168void EnableAllAPComponents(AudioProcessing* ap) {
169#if defined(WEBRTC_AUDIOPROC_FIXED_PROFILE)
170 EXPECT_NOERR(ap->echo_control_mobile()->Enable(true));
171
172 EXPECT_NOERR(ap->gain_control()->set_mode(GainControl::kAdaptiveDigital));
173 EXPECT_NOERR(ap->gain_control()->Enable(true));
174#elif defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE)
175 EXPECT_NOERR(ap->echo_cancellation()->enable_drift_compensation(true));
176 EXPECT_NOERR(ap->echo_cancellation()->enable_metrics(true));
177 EXPECT_NOERR(ap->echo_cancellation()->enable_delay_logging(true));
178 EXPECT_NOERR(ap->echo_cancellation()->Enable(true));
179
180 EXPECT_NOERR(ap->gain_control()->set_mode(GainControl::kAdaptiveAnalog));
181 EXPECT_NOERR(ap->gain_control()->set_analog_level_limits(0, 255));
182 EXPECT_NOERR(ap->gain_control()->Enable(true));
183#endif
184
185 EXPECT_NOERR(ap->high_pass_filter()->Enable(true));
186 EXPECT_NOERR(ap->level_estimator()->Enable(true));
187 EXPECT_NOERR(ap->noise_suppression()->Enable(true));
188
189 EXPECT_NOERR(ap->voice_detection()->Enable(true));
190}
191
bjornv@webrtc.org8dd60cc2014-09-11 08:36:35 +0000192// These functions are only used by ApmTest.Process.
andrew@webrtc.orgd7696c42013-12-03 23:39:16 +0000193template <class T>
194T AbsValue(T a) {
195 return a > 0 ? a: -a;
196}
197
198int16_t MaxAudioFrame(const AudioFrame& frame) {
pkasting25702cb2016-01-08 13:50:27 -0800199 const size_t length = frame.samples_per_channel_ * frame.num_channels_;
andrew@webrtc.orgd7696c42013-12-03 23:39:16 +0000200 int16_t max_data = AbsValue(frame.data_[0]);
pkasting25702cb2016-01-08 13:50:27 -0800201 for (size_t i = 1; i < length; i++) {
andrew@webrtc.orgd7696c42013-12-03 23:39:16 +0000202 max_data = std::max(max_data, AbsValue(frame.data_[i]));
203 }
204
205 return max_data;
206}
207
fischman@webrtc.orgf8be8df2013-12-17 23:46:39 +0000208#if defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE)
andrew@webrtc.org81865342012-10-27 00:28:27 +0000209void TestStats(const AudioProcessing::Statistic& test,
andrew@webrtc.org27c69802014-02-18 20:24:56 +0000210 const audioproc::Test::Statistic& reference) {
minyue58530ed2016-05-24 05:50:12 -0700211 EXPECT_EQ(reference.instant(), test.instant);
212 EXPECT_EQ(reference.average(), test.average);
213 EXPECT_EQ(reference.maximum(), test.maximum);
214 EXPECT_EQ(reference.minimum(), test.minimum);
andrew@webrtc.org81865342012-10-27 00:28:27 +0000215}
216
217void WriteStatsMessage(const AudioProcessing::Statistic& output,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000218 audioproc::Test::Statistic* msg) {
219 msg->set_instant(output.instant);
220 msg->set_average(output.average);
221 msg->set_maximum(output.maximum);
222 msg->set_minimum(output.minimum);
andrew@webrtc.org81865342012-10-27 00:28:27 +0000223}
fischman@webrtc.orgf8be8df2013-12-17 23:46:39 +0000224#endif
andrew@webrtc.org81865342012-10-27 00:28:27 +0000225
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000226void OpenFileAndWriteMessage(const std::string filename,
227 const ::google::protobuf::MessageLite& msg) {
andrew@webrtc.org81865342012-10-27 00:28:27 +0000228 FILE* file = fopen(filename.c_str(), "wb");
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000229 ASSERT_TRUE(file != NULL);
230
231 int32_t size = msg.ByteSize();
andrew@webrtc.org81865342012-10-27 00:28:27 +0000232 ASSERT_GT(size, 0);
kwiberg62eaacf2016-02-17 06:39:05 -0800233 std::unique_ptr<uint8_t[]> array(new uint8_t[size]);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000234 ASSERT_TRUE(msg.SerializeToArray(array.get(), size));
andrew@webrtc.org81865342012-10-27 00:28:27 +0000235
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000236 ASSERT_EQ(1u, fwrite(&size, sizeof(size), 1, file));
andrew@webrtc.org81865342012-10-27 00:28:27 +0000237 ASSERT_EQ(static_cast<size_t>(size),
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000238 fwrite(array.get(), sizeof(array[0]), size, file));
andrew@webrtc.org81865342012-10-27 00:28:27 +0000239 fclose(file);
240}
241
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000242std::string ResourceFilePath(std::string name, int sample_rate_hz) {
243 std::ostringstream ss;
244 // Resource files are all stereo.
245 ss << name << sample_rate_hz / 1000 << "_stereo";
246 return test::ResourcePath(ss.str(), "pcm");
247}
248
pbos@webrtc.orga525c982015-01-12 17:31:18 +0000249// Temporary filenames unique to this process. Used to be able to run these
250// tests in parallel as each process needs to be running in isolation they can't
251// have competing filenames.
252std::map<std::string, std::string> temp_filenames;
253
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000254std::string OutputFilePath(std::string name,
andrew@webrtc.orgf26c9e82014-04-24 03:46:46 +0000255 int input_rate,
256 int output_rate,
ekmeyerson60d9b332015-08-14 10:35:55 -0700257 int reverse_input_rate,
258 int reverse_output_rate,
Peter Kasting69558702016-01-12 16:26:35 -0800259 size_t num_input_channels,
260 size_t num_output_channels,
261 size_t num_reverse_input_channels,
262 size_t num_reverse_output_channels,
ekmeyerson60d9b332015-08-14 10:35:55 -0700263 StreamDirection file_direction) {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000264 std::ostringstream ss;
ekmeyerson60d9b332015-08-14 10:35:55 -0700265 ss << name << "_i" << num_input_channels << "_" << input_rate / 1000 << "_ir"
266 << num_reverse_input_channels << "_" << reverse_input_rate / 1000 << "_";
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000267 if (num_output_channels == 1) {
268 ss << "mono";
269 } else if (num_output_channels == 2) {
270 ss << "stereo";
271 } else {
kwiberg9e2be5f2016-09-14 05:23:22 -0700272 RTC_NOTREACHED();
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000273 }
ekmeyerson60d9b332015-08-14 10:35:55 -0700274 ss << output_rate / 1000;
275 if (num_reverse_output_channels == 1) {
276 ss << "_rmono";
277 } else if (num_reverse_output_channels == 2) {
278 ss << "_rstereo";
279 } else {
kwiberg9e2be5f2016-09-14 05:23:22 -0700280 RTC_NOTREACHED();
ekmeyerson60d9b332015-08-14 10:35:55 -0700281 }
282 ss << reverse_output_rate / 1000;
283 ss << "_d" << file_direction << "_pcm";
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000284
pbos@webrtc.orga525c982015-01-12 17:31:18 +0000285 std::string filename = ss.str();
pbosbb36fdf2015-07-09 07:48:14 -0700286 if (temp_filenames[filename].empty())
pbos@webrtc.orga525c982015-01-12 17:31:18 +0000287 temp_filenames[filename] = test::TempFilename(test::OutputPath(), filename);
288 return temp_filenames[filename];
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000289}
290
pbos@webrtc.org200ac002015-02-03 14:14:01 +0000291void ClearTempFiles() {
292 for (auto& kv : temp_filenames)
293 remove(kv.second.c_str());
294}
295
Kári Tristan Helgason470c0882016-10-03 13:13:29 +0200296void OpenFileAndReadMessage(std::string filename,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000297 ::google::protobuf::MessageLite* msg) {
andrew@webrtc.org81865342012-10-27 00:28:27 +0000298 FILE* file = fopen(filename.c_str(), "rb");
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000299 ASSERT_TRUE(file != NULL);
300 ReadMessageFromFile(file, msg);
andrew@webrtc.org81865342012-10-27 00:28:27 +0000301 fclose(file);
302}
303
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +0000304// Reads a 10 ms chunk of int16 interleaved audio from the given (assumed
305// stereo) file, converts to deinterleaved float (optionally downmixing) and
306// returns the result in |cb|. Returns false if the file ended (or on error) and
307// true otherwise.
308//
309// |int_data| and |float_data| are just temporary space that must be
310// sufficiently large to hold the 10 ms chunk.
311bool ReadChunk(FILE* file, int16_t* int_data, float* float_data,
312 ChannelBuffer<float>* cb) {
313 // The files always contain stereo audio.
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +0000314 size_t frame_size = cb->num_frames() * 2;
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +0000315 size_t read_count = fread(int_data, sizeof(int16_t), frame_size, file);
316 if (read_count != frame_size) {
317 // Check that the file really ended.
kwiberg9e2be5f2016-09-14 05:23:22 -0700318 RTC_DCHECK(feof(file));
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +0000319 return false; // This is expected.
320 }
321
322 S16ToFloat(int_data, frame_size, float_data);
323 if (cb->num_channels() == 1) {
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +0000324 MixStereoToMono(float_data, cb->channels()[0], cb->num_frames());
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +0000325 } else {
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +0000326 Deinterleave(float_data, cb->num_frames(), 2,
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +0000327 cb->channels());
328 }
329
330 return true;
331}
332
niklase@google.com470e71d2011-07-07 08:21:25 +0000333class ApmTest : public ::testing::Test {
334 protected:
335 ApmTest();
336 virtual void SetUp();
337 virtual void TearDown();
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000338
339 static void SetUpTestCase() {
340 Trace::CreateTrace();
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000341 }
342
343 static void TearDownTestCase() {
344 Trace::ReturnTrace();
pbos@webrtc.org200ac002015-02-03 14:14:01 +0000345 ClearTempFiles();
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000346 }
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +0000347
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000348 // Used to select between int and float interface tests.
349 enum Format {
350 kIntFormat,
351 kFloatFormat
352 };
353
354 void Init(int sample_rate_hz,
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000355 int output_sample_rate_hz,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000356 int reverse_sample_rate_hz,
Peter Kasting69558702016-01-12 16:26:35 -0800357 size_t num_input_channels,
358 size_t num_output_channels,
359 size_t num_reverse_channels,
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +0000360 bool open_output_file);
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000361 void Init(AudioProcessing* ap);
andrew@webrtc.org07bf9a02012-05-05 00:32:00 +0000362 void EnableAllComponents();
363 bool ReadFrame(FILE* file, AudioFrame* frame);
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000364 bool ReadFrame(FILE* file, AudioFrame* frame, ChannelBuffer<float>* cb);
andrew@webrtc.org27c69802014-02-18 20:24:56 +0000365 void ReadFrameWithRewind(FILE* file, AudioFrame* frame);
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000366 void ReadFrameWithRewind(FILE* file, AudioFrame* frame,
367 ChannelBuffer<float>* cb);
andrew@webrtc.org81865342012-10-27 00:28:27 +0000368 void ProcessWithDefaultStreamParameters(AudioFrame* frame);
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000369 void ProcessDelayVerificationTest(int delay_ms, int system_delay_ms,
370 int delay_min, int delay_max);
Michael Graczyk86c6d332015-07-23 11:41:39 -0700371 void TestChangingChannelsInt16Interface(
Peter Kasting69558702016-01-12 16:26:35 -0800372 size_t num_channels,
Michael Graczyk86c6d332015-07-23 11:41:39 -0700373 AudioProcessing::Error expected_return);
Peter Kasting69558702016-01-12 16:26:35 -0800374 void TestChangingForwardChannels(size_t num_in_channels,
375 size_t num_out_channels,
Michael Graczyk86c6d332015-07-23 11:41:39 -0700376 AudioProcessing::Error expected_return);
Peter Kasting69558702016-01-12 16:26:35 -0800377 void TestChangingReverseChannels(size_t num_rev_channels,
Michael Graczyk86c6d332015-07-23 11:41:39 -0700378 AudioProcessing::Error expected_return);
andrew@webrtc.org27c69802014-02-18 20:24:56 +0000379 void RunQuantizedVolumeDoesNotGetStuckTest(int sample_rate);
380 void RunManualVolumeChangeIsPossibleTest(int sample_rate);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000381 void StreamParametersTest(Format format);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000382 int ProcessStreamChooser(Format format);
383 int AnalyzeReverseStreamChooser(Format format);
384 void ProcessDebugDump(const std::string& in_filename,
385 const std::string& out_filename,
ivocd66b44d2016-01-15 03:06:36 -0800386 Format format,
387 int max_size_bytes);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000388 void VerifyDebugDumpTest(Format format);
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +0000389
390 const std::string output_path_;
391 const std::string ref_path_;
392 const std::string ref_filename_;
kwiberg62eaacf2016-02-17 06:39:05 -0800393 std::unique_ptr<AudioProcessing> apm_;
andrew@webrtc.orgf3930e92013-09-18 22:37:32 +0000394 AudioFrame* frame_;
395 AudioFrame* revframe_;
kwiberg62eaacf2016-02-17 06:39:05 -0800396 std::unique_ptr<ChannelBuffer<float> > float_cb_;
397 std::unique_ptr<ChannelBuffer<float> > revfloat_cb_;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000398 int output_sample_rate_hz_;
Peter Kasting69558702016-01-12 16:26:35 -0800399 size_t num_output_channels_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000400 FILE* far_file_;
401 FILE* near_file_;
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +0000402 FILE* out_file_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000403};
404
405ApmTest::ApmTest()
andrew@webrtc.org27c69802014-02-18 20:24:56 +0000406 : output_path_(test::OutputPath()),
Kári Tristan Helgason470c0882016-10-03 13:13:29 +0200407#ifndef WEBRTC_IOS
andrew@webrtc.org27c69802014-02-18 20:24:56 +0000408 ref_path_(test::ProjectRootPath() + "data/audio_processing/"),
Kári Tristan Helgason470c0882016-10-03 13:13:29 +0200409#else
410 // On iOS test data is flat in the project root dir
411 ref_path_(test::ProjectRootPath()),
412#endif
andrew@webrtc.org293d22b2012-01-30 22:04:26 +0000413#if defined(WEBRTC_AUDIOPROC_FIXED_PROFILE)
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +0000414 ref_filename_(ref_path_ + "output_data_fixed.pb"),
andrew@webrtc.org293d22b2012-01-30 22:04:26 +0000415#elif defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE)
aluebs@webrtc.orgf17ee9c2015-01-29 00:03:53 +0000416#if defined(WEBRTC_MAC)
417 // A different file for Mac is needed because on this platform the AEC
418 // constant |kFixedDelayMs| value is 20 and not 50 as it is on the rest.
419 ref_filename_(ref_path_ + "output_data_mac.pb"),
420#else
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +0000421 ref_filename_(ref_path_ + "output_data_float.pb"),
kjellander@webrtc.org61f07c32011-10-18 06:54:58 +0000422#endif
aluebs@webrtc.orgf17ee9c2015-01-29 00:03:53 +0000423#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000424 frame_(NULL),
ajm@google.com22e65152011-07-18 18:03:01 +0000425 revframe_(NULL),
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000426 output_sample_rate_hz_(0),
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000427 num_output_channels_(0),
ajm@google.com22e65152011-07-18 18:03:01 +0000428 far_file_(NULL),
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +0000429 near_file_(NULL),
aluebs@webrtc.orgc9ee4122014-02-03 14:41:57 +0000430 out_file_(NULL) {
431 Config config;
432 config.Set<ExperimentalAgc>(new ExperimentalAgc(false));
433 apm_.reset(AudioProcessing::Create(config));
434}
niklase@google.com470e71d2011-07-07 08:21:25 +0000435
436void ApmTest::SetUp() {
andrew@webrtc.orgf3930e92013-09-18 22:37:32 +0000437 ASSERT_TRUE(apm_.get() != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000438
439 frame_ = new AudioFrame();
440 revframe_ = new AudioFrame();
441
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000442 Init(32000, 32000, 32000, 2, 2, 2, false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000443}
444
445void ApmTest::TearDown() {
446 if (frame_) {
447 delete frame_;
448 }
449 frame_ = NULL;
450
451 if (revframe_) {
452 delete revframe_;
453 }
454 revframe_ = NULL;
455
456 if (far_file_) {
457 ASSERT_EQ(0, fclose(far_file_));
458 }
459 far_file_ = NULL;
460
461 if (near_file_) {
462 ASSERT_EQ(0, fclose(near_file_));
463 }
464 near_file_ = NULL;
465
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +0000466 if (out_file_) {
467 ASSERT_EQ(0, fclose(out_file_));
468 }
469 out_file_ = NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +0000470}
471
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000472void ApmTest::Init(AudioProcessing* ap) {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000473 ASSERT_EQ(kNoErr,
Michael Graczyk86c6d332015-07-23 11:41:39 -0700474 ap->Initialize(
475 {{{frame_->sample_rate_hz_, frame_->num_channels_},
476 {output_sample_rate_hz_, num_output_channels_},
ekmeyerson60d9b332015-08-14 10:35:55 -0700477 {revframe_->sample_rate_hz_, revframe_->num_channels_},
Michael Graczyk86c6d332015-07-23 11:41:39 -0700478 {revframe_->sample_rate_hz_, revframe_->num_channels_}}}));
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000479}
480
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000481void ApmTest::Init(int sample_rate_hz,
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000482 int output_sample_rate_hz,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000483 int reverse_sample_rate_hz,
Peter Kasting69558702016-01-12 16:26:35 -0800484 size_t num_input_channels,
485 size_t num_output_channels,
486 size_t num_reverse_channels,
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +0000487 bool open_output_file) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000488 SetContainerFormat(sample_rate_hz, num_input_channels, frame_, &float_cb_);
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000489 output_sample_rate_hz_ = output_sample_rate_hz;
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000490 num_output_channels_ = num_output_channels;
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +0000491
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000492 SetContainerFormat(reverse_sample_rate_hz, num_reverse_channels, revframe_,
493 &revfloat_cb_);
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000494 Init(apm_.get());
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000495
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +0000496 if (far_file_) {
497 ASSERT_EQ(0, fclose(far_file_));
498 }
499 std::string filename = ResourceFilePath("far", sample_rate_hz);
500 far_file_ = fopen(filename.c_str(), "rb");
501 ASSERT_TRUE(far_file_ != NULL) << "Could not open file " <<
502 filename << "\n";
503
504 if (near_file_) {
505 ASSERT_EQ(0, fclose(near_file_));
506 }
507 filename = ResourceFilePath("near", sample_rate_hz);
508 near_file_ = fopen(filename.c_str(), "rb");
509 ASSERT_TRUE(near_file_ != NULL) << "Could not open file " <<
510 filename << "\n";
511
512 if (open_output_file) {
513 if (out_file_) {
514 ASSERT_EQ(0, fclose(out_file_));
515 }
ekmeyerson60d9b332015-08-14 10:35:55 -0700516 filename = OutputFilePath(
517 "out", sample_rate_hz, output_sample_rate_hz, reverse_sample_rate_hz,
518 reverse_sample_rate_hz, num_input_channels, num_output_channels,
519 num_reverse_channels, num_reverse_channels, kForward);
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +0000520 out_file_ = fopen(filename.c_str(), "wb");
521 ASSERT_TRUE(out_file_ != NULL) << "Could not open file " <<
522 filename << "\n";
523 }
524}
525
andrew@webrtc.org07bf9a02012-05-05 00:32:00 +0000526void ApmTest::EnableAllComponents() {
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000527 EnableAllAPComponents(apm_.get());
andrew@webrtc.org07bf9a02012-05-05 00:32:00 +0000528}
529
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000530bool ApmTest::ReadFrame(FILE* file, AudioFrame* frame,
531 ChannelBuffer<float>* cb) {
andrew@webrtc.org07bf9a02012-05-05 00:32:00 +0000532 // The files always contain stereo audio.
533 size_t frame_size = frame->samples_per_channel_ * 2;
534 size_t read_count = fread(frame->data_,
535 sizeof(int16_t),
536 frame_size,
537 file);
538 if (read_count != frame_size) {
539 // Check that the file really ended.
540 EXPECT_NE(0, feof(file));
541 return false; // This is expected.
542 }
543
544 if (frame->num_channels_ == 1) {
545 MixStereoToMono(frame->data_, frame->data_,
546 frame->samples_per_channel_);
547 }
548
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000549 if (cb) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000550 ConvertToFloat(*frame, cb);
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000551 }
andrew@webrtc.org07bf9a02012-05-05 00:32:00 +0000552 return true;
ajm@google.coma769fa52011-07-13 21:57:58 +0000553}
554
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000555bool ApmTest::ReadFrame(FILE* file, AudioFrame* frame) {
556 return ReadFrame(file, frame, NULL);
557}
558
andrew@webrtc.org27c69802014-02-18 20:24:56 +0000559// If the end of the file has been reached, rewind it and attempt to read the
560// frame again.
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000561void ApmTest::ReadFrameWithRewind(FILE* file, AudioFrame* frame,
562 ChannelBuffer<float>* cb) {
563 if (!ReadFrame(near_file_, frame_, cb)) {
andrew@webrtc.org27c69802014-02-18 20:24:56 +0000564 rewind(near_file_);
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000565 ASSERT_TRUE(ReadFrame(near_file_, frame_, cb));
andrew@webrtc.org27c69802014-02-18 20:24:56 +0000566 }
567}
568
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000569void ApmTest::ReadFrameWithRewind(FILE* file, AudioFrame* frame) {
570 ReadFrameWithRewind(file, frame, NULL);
571}
572
andrew@webrtc.org81865342012-10-27 00:28:27 +0000573void ApmTest::ProcessWithDefaultStreamParameters(AudioFrame* frame) {
574 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(0));
andrew@webrtc.org6be1e932013-03-01 18:47:28 +0000575 apm_->echo_cancellation()->set_stream_drift_samples(0);
andrew@webrtc.org81865342012-10-27 00:28:27 +0000576 EXPECT_EQ(apm_->kNoError,
577 apm_->gain_control()->set_stream_analog_level(127));
578 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame));
andrew@webrtc.org755b04a2011-11-15 16:57:56 +0000579}
580
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000581int ApmTest::ProcessStreamChooser(Format format) {
582 if (format == kIntFormat) {
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000583 return apm_->ProcessStream(frame_);
584 }
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000585 return apm_->ProcessStream(float_cb_->channels(),
586 frame_->samples_per_channel_,
587 frame_->sample_rate_hz_,
588 LayoutFromChannels(frame_->num_channels_),
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000589 output_sample_rate_hz_,
590 LayoutFromChannels(num_output_channels_),
591 float_cb_->channels());
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000592}
593
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000594int ApmTest::AnalyzeReverseStreamChooser(Format format) {
595 if (format == kIntFormat) {
aluebsb0319552016-03-17 20:39:53 -0700596 return apm_->ProcessReverseStream(revframe_);
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000597 }
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000598 return apm_->AnalyzeReverseStream(
599 revfloat_cb_->channels(),
600 revframe_->samples_per_channel_,
601 revframe_->sample_rate_hz_,
602 LayoutFromChannels(revframe_->num_channels_));
603}
604
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000605void ApmTest::ProcessDelayVerificationTest(int delay_ms, int system_delay_ms,
606 int delay_min, int delay_max) {
607 // The |revframe_| and |frame_| should include the proper frame information,
608 // hence can be used for extracting information.
andrew@webrtc.org27c69802014-02-18 20:24:56 +0000609 AudioFrame tmp_frame;
610 std::queue<AudioFrame*> frame_queue;
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000611 bool causal = true;
612
613 tmp_frame.CopyFrom(*revframe_);
614 SetFrameTo(&tmp_frame, 0);
615
616 EXPECT_EQ(apm_->kNoError, apm_->Initialize());
617 // Initialize the |frame_queue| with empty frames.
618 int frame_delay = delay_ms / 10;
619 while (frame_delay < 0) {
andrew@webrtc.org27c69802014-02-18 20:24:56 +0000620 AudioFrame* frame = new AudioFrame();
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000621 frame->CopyFrom(tmp_frame);
622 frame_queue.push(frame);
623 frame_delay++;
624 causal = false;
625 }
626 while (frame_delay > 0) {
andrew@webrtc.org27c69802014-02-18 20:24:56 +0000627 AudioFrame* frame = new AudioFrame();
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000628 frame->CopyFrom(tmp_frame);
629 frame_queue.push(frame);
630 frame_delay--;
631 }
bjornv@webrtc.orgbbd47fc2014-01-13 08:54:34 +0000632 // Run for 4.5 seconds, skipping statistics from the first 2.5 seconds. We
633 // need enough frames with audio to have reliable estimates, but as few as
634 // possible to keep processing time down. 4.5 seconds seemed to be a good
635 // compromise for this recording.
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000636 for (int frame_count = 0; frame_count < 450; ++frame_count) {
andrew@webrtc.org27c69802014-02-18 20:24:56 +0000637 AudioFrame* frame = new AudioFrame();
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000638 frame->CopyFrom(tmp_frame);
639 // Use the near end recording, since that has more speech in it.
640 ASSERT_TRUE(ReadFrame(near_file_, frame));
641 frame_queue.push(frame);
andrew@webrtc.org27c69802014-02-18 20:24:56 +0000642 AudioFrame* reverse_frame = frame;
643 AudioFrame* process_frame = frame_queue.front();
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000644 if (!causal) {
645 reverse_frame = frame_queue.front();
646 // When we call ProcessStream() the frame is modified, so we can't use the
647 // pointer directly when things are non-causal. Use an intermediate frame
648 // and copy the data.
649 process_frame = &tmp_frame;
650 process_frame->CopyFrom(*frame);
651 }
aluebsb0319552016-03-17 20:39:53 -0700652 EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(reverse_frame));
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000653 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(system_delay_ms));
654 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(process_frame));
655 frame = frame_queue.front();
656 frame_queue.pop();
657 delete frame;
658
bjornv@webrtc.orgbbd47fc2014-01-13 08:54:34 +0000659 if (frame_count == 250) {
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000660 int median;
661 int std;
bjornv@webrtc.orgb1786db2015-02-03 06:06:26 +0000662 float poor_fraction;
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000663 // Discard the first delay metrics to avoid convergence effects.
664 EXPECT_EQ(apm_->kNoError,
bjornv@webrtc.orgb1786db2015-02-03 06:06:26 +0000665 apm_->echo_cancellation()->GetDelayMetrics(&median, &std,
666 &poor_fraction));
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000667 }
668 }
669
670 rewind(near_file_);
671 while (!frame_queue.empty()) {
andrew@webrtc.org27c69802014-02-18 20:24:56 +0000672 AudioFrame* frame = frame_queue.front();
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000673 frame_queue.pop();
674 delete frame;
675 }
676 // Calculate expected delay estimate and acceptable regions. Further,
677 // limit them w.r.t. AEC delay estimation support.
Peter Kastingdce40cf2015-08-24 14:52:23 -0700678 const size_t samples_per_ms =
679 std::min(static_cast<size_t>(16), frame_->samples_per_channel_ / 10);
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000680 int expected_median = std::min(std::max(delay_ms - system_delay_ms,
681 delay_min), delay_max);
Peter Kastingdce40cf2015-08-24 14:52:23 -0700682 int expected_median_high = std::min(
683 std::max(expected_median + static_cast<int>(96 / samples_per_ms),
684 delay_min),
685 delay_max);
686 int expected_median_low = std::min(
687 std::max(expected_median - static_cast<int>(96 / samples_per_ms),
688 delay_min),
689 delay_max);
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000690 // Verify delay metrics.
691 int median;
692 int std;
bjornv@webrtc.orgb1786db2015-02-03 06:06:26 +0000693 float poor_fraction;
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000694 EXPECT_EQ(apm_->kNoError,
bjornv@webrtc.orgb1786db2015-02-03 06:06:26 +0000695 apm_->echo_cancellation()->GetDelayMetrics(&median, &std,
696 &poor_fraction));
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000697 EXPECT_GE(expected_median_high, median);
698 EXPECT_LE(expected_median_low, median);
699}
700
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000701void ApmTest::StreamParametersTest(Format format) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000702 // No errors when the components are disabled.
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000703 EXPECT_EQ(apm_->kNoError, ProcessStreamChooser(format));
niklase@google.com470e71d2011-07-07 08:21:25 +0000704
andrew@webrtc.org1e916932011-11-29 18:28:57 +0000705 // -- Missing AGC level --
niklase@google.com470e71d2011-07-07 08:21:25 +0000706 EXPECT_EQ(apm_->kNoError, apm_->gain_control()->Enable(true));
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000707 EXPECT_EQ(apm_->kStreamParameterNotSetError,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000708 ProcessStreamChooser(format));
niklase@google.com470e71d2011-07-07 08:21:25 +0000709
andrew@webrtc.org1e916932011-11-29 18:28:57 +0000710 // Resets after successful ProcessStream().
niklase@google.com470e71d2011-07-07 08:21:25 +0000711 EXPECT_EQ(apm_->kNoError,
712 apm_->gain_control()->set_stream_analog_level(127));
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000713 EXPECT_EQ(apm_->kNoError, ProcessStreamChooser(format));
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000714 EXPECT_EQ(apm_->kStreamParameterNotSetError,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000715 ProcessStreamChooser(format));
niklase@google.com470e71d2011-07-07 08:21:25 +0000716
andrew@webrtc.org1e916932011-11-29 18:28:57 +0000717 // Other stream parameters set correctly.
718 EXPECT_EQ(apm_->kNoError, apm_->echo_cancellation()->Enable(true));
niklase@google.com470e71d2011-07-07 08:21:25 +0000719 EXPECT_EQ(apm_->kNoError,
720 apm_->echo_cancellation()->enable_drift_compensation(true));
andrew@webrtc.org1e916932011-11-29 18:28:57 +0000721 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(100));
andrew@webrtc.org6be1e932013-03-01 18:47:28 +0000722 apm_->echo_cancellation()->set_stream_drift_samples(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000723 EXPECT_EQ(apm_->kStreamParameterNotSetError,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000724 ProcessStreamChooser(format));
andrew@webrtc.org1e916932011-11-29 18:28:57 +0000725 EXPECT_EQ(apm_->kNoError, apm_->gain_control()->Enable(false));
726 EXPECT_EQ(apm_->kNoError,
727 apm_->echo_cancellation()->enable_drift_compensation(false));
728
729 // -- Missing delay --
andrew@webrtc.org1e916932011-11-29 18:28:57 +0000730 EXPECT_EQ(apm_->kNoError, apm_->echo_cancellation()->Enable(true));
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000731 EXPECT_EQ(apm_->kNoError, ProcessStreamChooser(format));
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000732 EXPECT_EQ(apm_->kStreamParameterNotSetError,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000733 ProcessStreamChooser(format));
andrew@webrtc.org1e916932011-11-29 18:28:57 +0000734
735 // Resets after successful ProcessStream().
736 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(100));
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000737 EXPECT_EQ(apm_->kNoError, ProcessStreamChooser(format));
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000738 EXPECT_EQ(apm_->kStreamParameterNotSetError,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000739 ProcessStreamChooser(format));
andrew@webrtc.org1e916932011-11-29 18:28:57 +0000740
741 // Other stream parameters set correctly.
742 EXPECT_EQ(apm_->kNoError, apm_->gain_control()->Enable(true));
743 EXPECT_EQ(apm_->kNoError,
744 apm_->echo_cancellation()->enable_drift_compensation(true));
andrew@webrtc.org6be1e932013-03-01 18:47:28 +0000745 apm_->echo_cancellation()->set_stream_drift_samples(0);
andrew@webrtc.org1e916932011-11-29 18:28:57 +0000746 EXPECT_EQ(apm_->kNoError,
747 apm_->gain_control()->set_stream_analog_level(127));
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000748 EXPECT_EQ(apm_->kStreamParameterNotSetError,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000749 ProcessStreamChooser(format));
andrew@webrtc.org1e916932011-11-29 18:28:57 +0000750 EXPECT_EQ(apm_->kNoError, apm_->gain_control()->Enable(false));
751
752 // -- Missing drift --
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000753 EXPECT_EQ(apm_->kStreamParameterNotSetError,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000754 ProcessStreamChooser(format));
andrew@webrtc.org1e916932011-11-29 18:28:57 +0000755
756 // Resets after successful ProcessStream().
757 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(100));
andrew@webrtc.org6be1e932013-03-01 18:47:28 +0000758 apm_->echo_cancellation()->set_stream_drift_samples(0);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000759 EXPECT_EQ(apm_->kNoError, ProcessStreamChooser(format));
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000760 EXPECT_EQ(apm_->kStreamParameterNotSetError,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000761 ProcessStreamChooser(format));
andrew@webrtc.org1e916932011-11-29 18:28:57 +0000762
763 // Other stream parameters set correctly.
niklase@google.com470e71d2011-07-07 08:21:25 +0000764 EXPECT_EQ(apm_->kNoError, apm_->gain_control()->Enable(true));
765 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(100));
766 EXPECT_EQ(apm_->kNoError,
767 apm_->gain_control()->set_stream_analog_level(127));
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000768 EXPECT_EQ(apm_->kStreamParameterNotSetError,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000769 ProcessStreamChooser(format));
niklase@google.com470e71d2011-07-07 08:21:25 +0000770
andrew@webrtc.org1e916932011-11-29 18:28:57 +0000771 // -- No stream parameters --
niklase@google.com470e71d2011-07-07 08:21:25 +0000772 EXPECT_EQ(apm_->kNoError,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000773 AnalyzeReverseStreamChooser(format));
niklase@google.com470e71d2011-07-07 08:21:25 +0000774 EXPECT_EQ(apm_->kStreamParameterNotSetError,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000775 ProcessStreamChooser(format));
niklase@google.com470e71d2011-07-07 08:21:25 +0000776
andrew@webrtc.org1e916932011-11-29 18:28:57 +0000777 // -- All there --
niklase@google.com470e71d2011-07-07 08:21:25 +0000778 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(100));
andrew@webrtc.org6be1e932013-03-01 18:47:28 +0000779 apm_->echo_cancellation()->set_stream_drift_samples(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000780 EXPECT_EQ(apm_->kNoError,
781 apm_->gain_control()->set_stream_analog_level(127));
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000782 EXPECT_EQ(apm_->kNoError, ProcessStreamChooser(format));
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000783}
784
785TEST_F(ApmTest, StreamParametersInt) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000786 StreamParametersTest(kIntFormat);
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000787}
788
789TEST_F(ApmTest, StreamParametersFloat) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000790 StreamParametersTest(kFloatFormat);
niklase@google.com470e71d2011-07-07 08:21:25 +0000791}
792
andrew@webrtc.org5f23d642012-05-29 21:14:06 +0000793TEST_F(ApmTest, DefaultDelayOffsetIsZero) {
794 EXPECT_EQ(0, apm_->delay_offset_ms());
795 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(50));
796 EXPECT_EQ(50, apm_->stream_delay_ms());
797}
798
799TEST_F(ApmTest, DelayOffsetWithLimitsIsSetProperly) {
800 // High limit of 500 ms.
andrew@webrtc.org6f9f8172012-03-06 19:03:39 +0000801 apm_->set_delay_offset_ms(100);
802 EXPECT_EQ(100, apm_->delay_offset_ms());
803 EXPECT_EQ(apm_->kBadStreamParameterWarning, apm_->set_stream_delay_ms(450));
andrew@webrtc.org5f23d642012-05-29 21:14:06 +0000804 EXPECT_EQ(500, apm_->stream_delay_ms());
andrew@webrtc.org6f9f8172012-03-06 19:03:39 +0000805 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(100));
806 EXPECT_EQ(200, apm_->stream_delay_ms());
807
andrew@webrtc.org5f23d642012-05-29 21:14:06 +0000808 // Low limit of 0 ms.
andrew@webrtc.org6f9f8172012-03-06 19:03:39 +0000809 apm_->set_delay_offset_ms(-50);
810 EXPECT_EQ(-50, apm_->delay_offset_ms());
andrew@webrtc.org5f23d642012-05-29 21:14:06 +0000811 EXPECT_EQ(apm_->kBadStreamParameterWarning, apm_->set_stream_delay_ms(20));
812 EXPECT_EQ(0, apm_->stream_delay_ms());
andrew@webrtc.org6f9f8172012-03-06 19:03:39 +0000813 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(100));
814 EXPECT_EQ(50, apm_->stream_delay_ms());
815}
816
Michael Graczyk86c6d332015-07-23 11:41:39 -0700817void ApmTest::TestChangingChannelsInt16Interface(
Peter Kasting69558702016-01-12 16:26:35 -0800818 size_t num_channels,
Michael Graczyk86c6d332015-07-23 11:41:39 -0700819 AudioProcessing::Error expected_return) {
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000820 frame_->num_channels_ = num_channels;
821 EXPECT_EQ(expected_return, apm_->ProcessStream(frame_));
aluebsb0319552016-03-17 20:39:53 -0700822 EXPECT_EQ(expected_return, apm_->ProcessReverseStream(frame_));
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000823}
824
Michael Graczyk86c6d332015-07-23 11:41:39 -0700825void ApmTest::TestChangingForwardChannels(
Peter Kasting69558702016-01-12 16:26:35 -0800826 size_t num_in_channels,
827 size_t num_out_channels,
Michael Graczyk86c6d332015-07-23 11:41:39 -0700828 AudioProcessing::Error expected_return) {
829 const StreamConfig input_stream = {frame_->sample_rate_hz_, num_in_channels};
830 const StreamConfig output_stream = {output_sample_rate_hz_, num_out_channels};
831
832 EXPECT_EQ(expected_return,
833 apm_->ProcessStream(float_cb_->channels(), input_stream,
834 output_stream, float_cb_->channels()));
835}
836
837void ApmTest::TestChangingReverseChannels(
Peter Kasting69558702016-01-12 16:26:35 -0800838 size_t num_rev_channels,
Michael Graczyk86c6d332015-07-23 11:41:39 -0700839 AudioProcessing::Error expected_return) {
840 const ProcessingConfig processing_config = {
ekmeyerson60d9b332015-08-14 10:35:55 -0700841 {{frame_->sample_rate_hz_, apm_->num_input_channels()},
842 {output_sample_rate_hz_, apm_->num_output_channels()},
843 {frame_->sample_rate_hz_, num_rev_channels},
844 {frame_->sample_rate_hz_, num_rev_channels}}};
Michael Graczyk86c6d332015-07-23 11:41:39 -0700845
ekmeyerson60d9b332015-08-14 10:35:55 -0700846 EXPECT_EQ(
847 expected_return,
848 apm_->ProcessReverseStream(
849 float_cb_->channels(), processing_config.reverse_input_stream(),
850 processing_config.reverse_output_stream(), float_cb_->channels()));
Michael Graczyk86c6d332015-07-23 11:41:39 -0700851}
852
853TEST_F(ApmTest, ChannelsInt16Interface) {
854 // Testing number of invalid and valid channels.
855 Init(16000, 16000, 16000, 4, 4, 4, false);
856
857 TestChangingChannelsInt16Interface(0, apm_->kBadNumberChannelsError);
858
Peter Kasting69558702016-01-12 16:26:35 -0800859 for (size_t i = 1; i < 4; i++) {
Michael Graczyk86c6d332015-07-23 11:41:39 -0700860 TestChangingChannelsInt16Interface(i, kNoErr);
niklase@google.com470e71d2011-07-07 08:21:25 +0000861 EXPECT_EQ(i, apm_->num_input_channels());
andrew@webrtc.org30be8272014-09-24 20:06:23 +0000862 // We always force the number of reverse channels used for processing to 1.
Peter Kasting69558702016-01-12 16:26:35 -0800863 EXPECT_EQ(1u, apm_->num_reverse_channels());
niklase@google.com470e71d2011-07-07 08:21:25 +0000864 }
865}
866
Michael Graczyk86c6d332015-07-23 11:41:39 -0700867TEST_F(ApmTest, Channels) {
868 // Testing number of invalid and valid channels.
869 Init(16000, 16000, 16000, 4, 4, 4, false);
870
871 TestChangingForwardChannels(0, 1, apm_->kBadNumberChannelsError);
872 TestChangingReverseChannels(0, apm_->kBadNumberChannelsError);
873
Peter Kasting69558702016-01-12 16:26:35 -0800874 for (size_t i = 1; i < 4; ++i) {
875 for (size_t j = 0; j < 1; ++j) {
Michael Graczyk86c6d332015-07-23 11:41:39 -0700876 // Output channels much be one or match input channels.
877 if (j == 1 || i == j) {
878 TestChangingForwardChannels(i, j, kNoErr);
879 TestChangingReverseChannels(i, kNoErr);
880
881 EXPECT_EQ(i, apm_->num_input_channels());
882 EXPECT_EQ(j, apm_->num_output_channels());
883 // The number of reverse channels used for processing to is always 1.
Peter Kasting69558702016-01-12 16:26:35 -0800884 EXPECT_EQ(1u, apm_->num_reverse_channels());
Michael Graczyk86c6d332015-07-23 11:41:39 -0700885 } else {
886 TestChangingForwardChannels(i, j,
887 AudioProcessing::kBadNumberChannelsError);
888 }
889 }
890 }
891}
892
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000893TEST_F(ApmTest, SampleRatesInt) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000894 // Testing invalid sample rates
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000895 SetContainerFormat(10000, 2, frame_, &float_cb_);
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000896 EXPECT_EQ(apm_->kBadSampleRateError, ProcessStreamChooser(kIntFormat));
niklase@google.com470e71d2011-07-07 08:21:25 +0000897 // Testing valid sample rates
Alejandro Luebs47748742015-05-22 12:00:21 -0700898 int fs[] = {8000, 16000, 32000, 48000};
pkasting25702cb2016-01-08 13:50:27 -0800899 for (size_t i = 0; i < arraysize(fs); i++) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000900 SetContainerFormat(fs[i], 2, frame_, &float_cb_);
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000901 EXPECT_NOERR(ProcessStreamChooser(kIntFormat));
niklase@google.com470e71d2011-07-07 08:21:25 +0000902 }
903}
904
niklase@google.com470e71d2011-07-07 08:21:25 +0000905TEST_F(ApmTest, EchoCancellation) {
906 EXPECT_EQ(apm_->kNoError,
907 apm_->echo_cancellation()->enable_drift_compensation(true));
908 EXPECT_TRUE(apm_->echo_cancellation()->is_drift_compensation_enabled());
909 EXPECT_EQ(apm_->kNoError,
910 apm_->echo_cancellation()->enable_drift_compensation(false));
911 EXPECT_FALSE(apm_->echo_cancellation()->is_drift_compensation_enabled());
912
niklase@google.com470e71d2011-07-07 08:21:25 +0000913 EchoCancellation::SuppressionLevel level[] = {
914 EchoCancellation::kLowSuppression,
915 EchoCancellation::kModerateSuppression,
916 EchoCancellation::kHighSuppression,
917 };
pkasting25702cb2016-01-08 13:50:27 -0800918 for (size_t i = 0; i < arraysize(level); i++) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000919 EXPECT_EQ(apm_->kNoError,
920 apm_->echo_cancellation()->set_suppression_level(level[i]));
921 EXPECT_EQ(level[i],
922 apm_->echo_cancellation()->suppression_level());
923 }
924
925 EchoCancellation::Metrics metrics;
926 EXPECT_EQ(apm_->kNotEnabledError,
927 apm_->echo_cancellation()->GetMetrics(&metrics));
928
929 EXPECT_EQ(apm_->kNoError,
930 apm_->echo_cancellation()->enable_metrics(true));
931 EXPECT_TRUE(apm_->echo_cancellation()->are_metrics_enabled());
932 EXPECT_EQ(apm_->kNoError,
933 apm_->echo_cancellation()->enable_metrics(false));
934 EXPECT_FALSE(apm_->echo_cancellation()->are_metrics_enabled());
935
bjornv@google.com1ba3dbe2011-10-03 08:18:10 +0000936 int median = 0;
937 int std = 0;
bjornv@webrtc.orgb1786db2015-02-03 06:06:26 +0000938 float poor_fraction = 0;
bjornv@google.com1ba3dbe2011-10-03 08:18:10 +0000939 EXPECT_EQ(apm_->kNotEnabledError,
bjornv@webrtc.orgb1786db2015-02-03 06:06:26 +0000940 apm_->echo_cancellation()->GetDelayMetrics(&median, &std,
941 &poor_fraction));
bjornv@google.com1ba3dbe2011-10-03 08:18:10 +0000942
943 EXPECT_EQ(apm_->kNoError,
944 apm_->echo_cancellation()->enable_delay_logging(true));
945 EXPECT_TRUE(apm_->echo_cancellation()->is_delay_logging_enabled());
946 EXPECT_EQ(apm_->kNoError,
947 apm_->echo_cancellation()->enable_delay_logging(false));
948 EXPECT_FALSE(apm_->echo_cancellation()->is_delay_logging_enabled());
949
niklase@google.com470e71d2011-07-07 08:21:25 +0000950 EXPECT_EQ(apm_->kNoError, apm_->echo_cancellation()->Enable(true));
951 EXPECT_TRUE(apm_->echo_cancellation()->is_enabled());
952 EXPECT_EQ(apm_->kNoError, apm_->echo_cancellation()->Enable(false));
953 EXPECT_FALSE(apm_->echo_cancellation()->is_enabled());
bjornv@webrtc.org91d11b32013-03-05 16:53:09 +0000954
955 EXPECT_EQ(apm_->kNoError, apm_->echo_cancellation()->Enable(true));
956 EXPECT_TRUE(apm_->echo_cancellation()->is_enabled());
957 EXPECT_TRUE(apm_->echo_cancellation()->aec_core() != NULL);
958 EXPECT_EQ(apm_->kNoError, apm_->echo_cancellation()->Enable(false));
959 EXPECT_FALSE(apm_->echo_cancellation()->is_enabled());
960 EXPECT_FALSE(apm_->echo_cancellation()->aec_core() != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000961}
962
bjornv@webrtc.org84f8ec12014-06-19 12:14:33 +0000963TEST_F(ApmTest, DISABLED_EchoCancellationReportsCorrectDelays) {
bjornv@webrtc.orgbac00122015-01-02 09:23:49 +0000964 // TODO(bjornv): Fix this test to work with DA-AEC.
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000965 // Enable AEC only.
966 EXPECT_EQ(apm_->kNoError,
967 apm_->echo_cancellation()->enable_drift_compensation(false));
968 EXPECT_EQ(apm_->kNoError,
969 apm_->echo_cancellation()->enable_metrics(false));
970 EXPECT_EQ(apm_->kNoError,
971 apm_->echo_cancellation()->enable_delay_logging(true));
972 EXPECT_EQ(apm_->kNoError, apm_->echo_cancellation()->Enable(true));
bjornv@webrtc.org5c3f4e32014-06-19 09:51:29 +0000973 Config config;
henrik.lundin0f133b92015-07-02 00:17:55 -0700974 config.Set<DelayAgnostic>(new DelayAgnostic(false));
bjornv@webrtc.org5c3f4e32014-06-19 09:51:29 +0000975 apm_->SetExtraOptions(config);
bjornv@webrtc.org3e102492013-02-14 15:29:09 +0000976
977 // Internally in the AEC the amount of lookahead the delay estimation can
978 // handle is 15 blocks and the maximum delay is set to 60 blocks.
979 const int kLookaheadBlocks = 15;
980 const int kMaxDelayBlocks = 60;
981 // The AEC has a startup time before it actually starts to process. This
982 // procedure can flush the internal far-end buffer, which of course affects
983 // the delay estimation. Therefore, we set a system_delay high enough to
984 // avoid that. The smallest system_delay you can report without flushing the
985 // buffer is 66 ms in 8 kHz.
986 //
987 // It is known that for 16 kHz (and 32 kHz) sampling frequency there is an
988 // additional stuffing of 8 ms on the fly, but it seems to have no impact on
989 // delay estimation. This should be noted though. In case of test failure,
990 // this could be the cause.
991 const int kSystemDelayMs = 66;
992 // Test a couple of corner cases and verify that the estimated delay is
993 // within a valid region (set to +-1.5 blocks). Note that these cases are
994 // sampling frequency dependent.
pkasting25702cb2016-01-08 13:50:27 -0800995 for (size_t i = 0; i < arraysize(kProcessSampleRates); i++) {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +0000996 Init(kProcessSampleRates[i],
997 kProcessSampleRates[i],
998 kProcessSampleRates[i],
999 2,
1000 2,
1001 2,
1002 false);
bjornv@webrtc.org3e102492013-02-14 15:29:09 +00001003 // Sampling frequency dependent variables.
Peter Kastingdce40cf2015-08-24 14:52:23 -07001004 const int num_ms_per_block =
1005 std::max(4, static_cast<int>(640 / frame_->samples_per_channel_));
bjornv@webrtc.org3e102492013-02-14 15:29:09 +00001006 const int delay_min_ms = -kLookaheadBlocks * num_ms_per_block;
1007 const int delay_max_ms = (kMaxDelayBlocks - 1) * num_ms_per_block;
1008
1009 // 1) Verify correct delay estimate at lookahead boundary.
1010 int delay_ms = TruncateToMultipleOf10(kSystemDelayMs + delay_min_ms);
1011 ProcessDelayVerificationTest(delay_ms, kSystemDelayMs, delay_min_ms,
1012 delay_max_ms);
1013 // 2) A delay less than maximum lookahead should give an delay estimate at
1014 // the boundary (= -kLookaheadBlocks * num_ms_per_block).
1015 delay_ms -= 20;
1016 ProcessDelayVerificationTest(delay_ms, kSystemDelayMs, delay_min_ms,
1017 delay_max_ms);
1018 // 3) Three values around zero delay. Note that we need to compensate for
1019 // the fake system_delay.
1020 delay_ms = TruncateToMultipleOf10(kSystemDelayMs - 10);
1021 ProcessDelayVerificationTest(delay_ms, kSystemDelayMs, delay_min_ms,
1022 delay_max_ms);
1023 delay_ms = TruncateToMultipleOf10(kSystemDelayMs);
1024 ProcessDelayVerificationTest(delay_ms, kSystemDelayMs, delay_min_ms,
1025 delay_max_ms);
1026 delay_ms = TruncateToMultipleOf10(kSystemDelayMs + 10);
1027 ProcessDelayVerificationTest(delay_ms, kSystemDelayMs, delay_min_ms,
1028 delay_max_ms);
1029 // 4) Verify correct delay estimate at maximum delay boundary.
1030 delay_ms = TruncateToMultipleOf10(kSystemDelayMs + delay_max_ms);
1031 ProcessDelayVerificationTest(delay_ms, kSystemDelayMs, delay_min_ms,
1032 delay_max_ms);
1033 // 5) A delay above the maximum delay should give an estimate at the
1034 // boundary (= (kMaxDelayBlocks - 1) * num_ms_per_block).
1035 delay_ms += 20;
1036 ProcessDelayVerificationTest(delay_ms, kSystemDelayMs, delay_min_ms,
1037 delay_max_ms);
1038 }
1039}
1040
niklase@google.com470e71d2011-07-07 08:21:25 +00001041TEST_F(ApmTest, EchoControlMobile) {
niklase@google.com470e71d2011-07-07 08:21:25 +00001042 // Turn AECM on (and AEC off)
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00001043 Init(16000, 16000, 16000, 2, 2, 2, false);
niklase@google.com470e71d2011-07-07 08:21:25 +00001044 EXPECT_EQ(apm_->kNoError, apm_->echo_control_mobile()->Enable(true));
1045 EXPECT_TRUE(apm_->echo_control_mobile()->is_enabled());
1046
niklase@google.com470e71d2011-07-07 08:21:25 +00001047 // Toggle routing modes
1048 EchoControlMobile::RoutingMode mode[] = {
1049 EchoControlMobile::kQuietEarpieceOrHeadset,
1050 EchoControlMobile::kEarpiece,
1051 EchoControlMobile::kLoudEarpiece,
1052 EchoControlMobile::kSpeakerphone,
1053 EchoControlMobile::kLoudSpeakerphone,
1054 };
pkasting25702cb2016-01-08 13:50:27 -08001055 for (size_t i = 0; i < arraysize(mode); i++) {
niklase@google.com470e71d2011-07-07 08:21:25 +00001056 EXPECT_EQ(apm_->kNoError,
1057 apm_->echo_control_mobile()->set_routing_mode(mode[i]));
1058 EXPECT_EQ(mode[i],
1059 apm_->echo_control_mobile()->routing_mode());
1060 }
1061 // Turn comfort noise off/on
1062 EXPECT_EQ(apm_->kNoError,
1063 apm_->echo_control_mobile()->enable_comfort_noise(false));
1064 EXPECT_FALSE(apm_->echo_control_mobile()->is_comfort_noise_enabled());
1065 EXPECT_EQ(apm_->kNoError,
1066 apm_->echo_control_mobile()->enable_comfort_noise(true));
1067 EXPECT_TRUE(apm_->echo_control_mobile()->is_comfort_noise_enabled());
bjornv@google.comc4b939c2011-07-13 08:09:56 +00001068 // Set and get echo path
ajm@google.com22e65152011-07-18 18:03:01 +00001069 const size_t echo_path_size =
1070 apm_->echo_control_mobile()->echo_path_size_bytes();
kwiberg62eaacf2016-02-17 06:39:05 -08001071 std::unique_ptr<char[]> echo_path_in(new char[echo_path_size]);
1072 std::unique_ptr<char[]> echo_path_out(new char[echo_path_size]);
bjornv@google.comc4b939c2011-07-13 08:09:56 +00001073 EXPECT_EQ(apm_->kNullPointerError,
1074 apm_->echo_control_mobile()->SetEchoPath(NULL, echo_path_size));
1075 EXPECT_EQ(apm_->kNullPointerError,
1076 apm_->echo_control_mobile()->GetEchoPath(NULL, echo_path_size));
1077 EXPECT_EQ(apm_->kBadParameterError,
andrew@webrtc.org3119ecf2011-11-01 17:00:18 +00001078 apm_->echo_control_mobile()->GetEchoPath(echo_path_out.get(), 1));
bjornv@google.comc4b939c2011-07-13 08:09:56 +00001079 EXPECT_EQ(apm_->kNoError,
andrew@webrtc.org3119ecf2011-11-01 17:00:18 +00001080 apm_->echo_control_mobile()->GetEchoPath(echo_path_out.get(),
bjornv@google.comc4b939c2011-07-13 08:09:56 +00001081 echo_path_size));
ajm@google.com22e65152011-07-18 18:03:01 +00001082 for (size_t i = 0; i < echo_path_size; i++) {
bjornv@google.comc4b939c2011-07-13 08:09:56 +00001083 echo_path_in[i] = echo_path_out[i] + 1;
1084 }
1085 EXPECT_EQ(apm_->kBadParameterError,
andrew@webrtc.org3119ecf2011-11-01 17:00:18 +00001086 apm_->echo_control_mobile()->SetEchoPath(echo_path_in.get(), 1));
bjornv@google.comc4b939c2011-07-13 08:09:56 +00001087 EXPECT_EQ(apm_->kNoError,
andrew@webrtc.org3119ecf2011-11-01 17:00:18 +00001088 apm_->echo_control_mobile()->SetEchoPath(echo_path_in.get(),
1089 echo_path_size));
bjornv@google.comc4b939c2011-07-13 08:09:56 +00001090 EXPECT_EQ(apm_->kNoError,
andrew@webrtc.org3119ecf2011-11-01 17:00:18 +00001091 apm_->echo_control_mobile()->GetEchoPath(echo_path_out.get(),
1092 echo_path_size));
ajm@google.com22e65152011-07-18 18:03:01 +00001093 for (size_t i = 0; i < echo_path_size; i++) {
bjornv@google.comc4b939c2011-07-13 08:09:56 +00001094 EXPECT_EQ(echo_path_in[i], echo_path_out[i]);
1095 }
andrew@webrtc.org75f19482012-02-09 17:16:18 +00001096
1097 // Process a few frames with NS in the default disabled state. This exercises
1098 // a different codepath than with it enabled.
1099 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(0));
1100 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1101 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(0));
1102 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1103
niklase@google.com470e71d2011-07-07 08:21:25 +00001104 // Turn AECM off
1105 EXPECT_EQ(apm_->kNoError, apm_->echo_control_mobile()->Enable(false));
1106 EXPECT_FALSE(apm_->echo_control_mobile()->is_enabled());
1107}
1108
aluebs@webrtc.orgc9ee4122014-02-03 14:41:57 +00001109TEST_F(ApmTest, GainControl) {
niklase@google.com470e71d2011-07-07 08:21:25 +00001110 // Testing gain modes
niklase@google.com470e71d2011-07-07 08:21:25 +00001111 EXPECT_EQ(apm_->kNoError,
1112 apm_->gain_control()->set_mode(
1113 apm_->gain_control()->mode()));
1114
1115 GainControl::Mode mode[] = {
1116 GainControl::kAdaptiveAnalog,
1117 GainControl::kAdaptiveDigital,
1118 GainControl::kFixedDigital
1119 };
pkasting25702cb2016-01-08 13:50:27 -08001120 for (size_t i = 0; i < arraysize(mode); i++) {
niklase@google.com470e71d2011-07-07 08:21:25 +00001121 EXPECT_EQ(apm_->kNoError,
1122 apm_->gain_control()->set_mode(mode[i]));
1123 EXPECT_EQ(mode[i], apm_->gain_control()->mode());
1124 }
1125 // Testing invalid target levels
1126 EXPECT_EQ(apm_->kBadParameterError,
1127 apm_->gain_control()->set_target_level_dbfs(-3));
1128 EXPECT_EQ(apm_->kBadParameterError,
1129 apm_->gain_control()->set_target_level_dbfs(-40));
1130 // Testing valid target levels
1131 EXPECT_EQ(apm_->kNoError,
1132 apm_->gain_control()->set_target_level_dbfs(
1133 apm_->gain_control()->target_level_dbfs()));
1134
1135 int level_dbfs[] = {0, 6, 31};
pkasting25702cb2016-01-08 13:50:27 -08001136 for (size_t i = 0; i < arraysize(level_dbfs); i++) {
niklase@google.com470e71d2011-07-07 08:21:25 +00001137 EXPECT_EQ(apm_->kNoError,
1138 apm_->gain_control()->set_target_level_dbfs(level_dbfs[i]));
1139 EXPECT_EQ(level_dbfs[i], apm_->gain_control()->target_level_dbfs());
1140 }
1141
1142 // Testing invalid compression gains
1143 EXPECT_EQ(apm_->kBadParameterError,
1144 apm_->gain_control()->set_compression_gain_db(-1));
1145 EXPECT_EQ(apm_->kBadParameterError,
1146 apm_->gain_control()->set_compression_gain_db(100));
1147
1148 // Testing valid compression gains
1149 EXPECT_EQ(apm_->kNoError,
1150 apm_->gain_control()->set_compression_gain_db(
1151 apm_->gain_control()->compression_gain_db()));
1152
1153 int gain_db[] = {0, 10, 90};
pkasting25702cb2016-01-08 13:50:27 -08001154 for (size_t i = 0; i < arraysize(gain_db); i++) {
niklase@google.com470e71d2011-07-07 08:21:25 +00001155 EXPECT_EQ(apm_->kNoError,
1156 apm_->gain_control()->set_compression_gain_db(gain_db[i]));
1157 EXPECT_EQ(gain_db[i], apm_->gain_control()->compression_gain_db());
1158 }
1159
1160 // Testing limiter off/on
1161 EXPECT_EQ(apm_->kNoError, apm_->gain_control()->enable_limiter(false));
1162 EXPECT_FALSE(apm_->gain_control()->is_limiter_enabled());
1163 EXPECT_EQ(apm_->kNoError, apm_->gain_control()->enable_limiter(true));
1164 EXPECT_TRUE(apm_->gain_control()->is_limiter_enabled());
1165
1166 // Testing invalid level limits
1167 EXPECT_EQ(apm_->kBadParameterError,
1168 apm_->gain_control()->set_analog_level_limits(-1, 512));
1169 EXPECT_EQ(apm_->kBadParameterError,
1170 apm_->gain_control()->set_analog_level_limits(100000, 512));
1171 EXPECT_EQ(apm_->kBadParameterError,
1172 apm_->gain_control()->set_analog_level_limits(512, -1));
1173 EXPECT_EQ(apm_->kBadParameterError,
1174 apm_->gain_control()->set_analog_level_limits(512, 100000));
1175 EXPECT_EQ(apm_->kBadParameterError,
1176 apm_->gain_control()->set_analog_level_limits(512, 255));
1177
1178 // Testing valid level limits
1179 EXPECT_EQ(apm_->kNoError,
1180 apm_->gain_control()->set_analog_level_limits(
1181 apm_->gain_control()->analog_level_minimum(),
1182 apm_->gain_control()->analog_level_maximum()));
1183
1184 int min_level[] = {0, 255, 1024};
pkasting25702cb2016-01-08 13:50:27 -08001185 for (size_t i = 0; i < arraysize(min_level); i++) {
niklase@google.com470e71d2011-07-07 08:21:25 +00001186 EXPECT_EQ(apm_->kNoError,
1187 apm_->gain_control()->set_analog_level_limits(min_level[i], 1024));
1188 EXPECT_EQ(min_level[i], apm_->gain_control()->analog_level_minimum());
1189 }
1190
1191 int max_level[] = {0, 1024, 65535};
pkasting25702cb2016-01-08 13:50:27 -08001192 for (size_t i = 0; i < arraysize(min_level); i++) {
niklase@google.com470e71d2011-07-07 08:21:25 +00001193 EXPECT_EQ(apm_->kNoError,
1194 apm_->gain_control()->set_analog_level_limits(0, max_level[i]));
1195 EXPECT_EQ(max_level[i], apm_->gain_control()->analog_level_maximum());
1196 }
1197
1198 // TODO(ajm): stream_is_saturated() and stream_analog_level()
1199
1200 // Turn AGC off
1201 EXPECT_EQ(apm_->kNoError, apm_->gain_control()->Enable(false));
1202 EXPECT_FALSE(apm_->gain_control()->is_enabled());
1203}
1204
andrew@webrtc.org27c69802014-02-18 20:24:56 +00001205void ApmTest::RunQuantizedVolumeDoesNotGetStuckTest(int sample_rate) {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00001206 Init(sample_rate, sample_rate, sample_rate, 2, 2, 2, false);
andrew@webrtc.org27c69802014-02-18 20:24:56 +00001207 EXPECT_EQ(apm_->kNoError,
1208 apm_->gain_control()->set_mode(GainControl::kAdaptiveAnalog));
1209 EXPECT_EQ(apm_->kNoError, apm_->gain_control()->Enable(true));
1210
1211 int out_analog_level = 0;
1212 for (int i = 0; i < 2000; ++i) {
1213 ReadFrameWithRewind(near_file_, frame_);
1214 // Ensure the audio is at a low level, so the AGC will try to increase it.
1215 ScaleFrame(frame_, 0.25);
1216
1217 // Always pass in the same volume.
1218 EXPECT_EQ(apm_->kNoError,
1219 apm_->gain_control()->set_stream_analog_level(100));
1220 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1221 out_analog_level = apm_->gain_control()->stream_analog_level();
1222 }
1223
1224 // Ensure the AGC is still able to reach the maximum.
1225 EXPECT_EQ(255, out_analog_level);
1226}
1227
1228// Verifies that despite volume slider quantization, the AGC can continue to
1229// increase its volume.
1230TEST_F(ApmTest, QuantizedVolumeDoesNotGetStuck) {
pkasting25702cb2016-01-08 13:50:27 -08001231 for (size_t i = 0; i < arraysize(kSampleRates); ++i) {
andrew@webrtc.org27c69802014-02-18 20:24:56 +00001232 RunQuantizedVolumeDoesNotGetStuckTest(kSampleRates[i]);
1233 }
1234}
1235
1236void ApmTest::RunManualVolumeChangeIsPossibleTest(int sample_rate) {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00001237 Init(sample_rate, sample_rate, sample_rate, 2, 2, 2, false);
andrew@webrtc.org27c69802014-02-18 20:24:56 +00001238 EXPECT_EQ(apm_->kNoError,
1239 apm_->gain_control()->set_mode(GainControl::kAdaptiveAnalog));
1240 EXPECT_EQ(apm_->kNoError, apm_->gain_control()->Enable(true));
1241
1242 int out_analog_level = 100;
1243 for (int i = 0; i < 1000; ++i) {
1244 ReadFrameWithRewind(near_file_, frame_);
1245 // Ensure the audio is at a low level, so the AGC will try to increase it.
1246 ScaleFrame(frame_, 0.25);
1247
1248 EXPECT_EQ(apm_->kNoError,
1249 apm_->gain_control()->set_stream_analog_level(out_analog_level));
1250 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1251 out_analog_level = apm_->gain_control()->stream_analog_level();
1252 }
1253
1254 // Ensure the volume was raised.
1255 EXPECT_GT(out_analog_level, 100);
1256 int highest_level_reached = out_analog_level;
1257 // Simulate a user manual volume change.
1258 out_analog_level = 100;
1259
1260 for (int i = 0; i < 300; ++i) {
1261 ReadFrameWithRewind(near_file_, frame_);
1262 ScaleFrame(frame_, 0.25);
1263
1264 EXPECT_EQ(apm_->kNoError,
1265 apm_->gain_control()->set_stream_analog_level(out_analog_level));
1266 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1267 out_analog_level = apm_->gain_control()->stream_analog_level();
1268 // Check that AGC respected the manually adjusted volume.
1269 EXPECT_LT(out_analog_level, highest_level_reached);
1270 }
1271 // Check that the volume was still raised.
1272 EXPECT_GT(out_analog_level, 100);
1273}
1274
1275TEST_F(ApmTest, ManualVolumeChangeIsPossible) {
pkasting25702cb2016-01-08 13:50:27 -08001276 for (size_t i = 0; i < arraysize(kSampleRates); ++i) {
andrew@webrtc.org27c69802014-02-18 20:24:56 +00001277 RunManualVolumeChangeIsPossibleTest(kSampleRates[i]);
1278 }
1279}
1280
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +00001281#if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS)
1282TEST_F(ApmTest, AgcOnlyAdaptsWhenTargetSignalIsPresent) {
1283 const int kSampleRateHz = 16000;
pkasting25702cb2016-01-08 13:50:27 -08001284 const size_t kSamplesPerChannel =
1285 static_cast<size_t>(AudioProcessing::kChunkSizeMs * kSampleRateHz / 1000);
Peter Kasting69558702016-01-12 16:26:35 -08001286 const size_t kNumInputChannels = 2;
1287 const size_t kNumOutputChannels = 1;
pkasting25702cb2016-01-08 13:50:27 -08001288 const size_t kNumChunks = 700;
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +00001289 const float kScaleFactor = 0.25f;
1290 Config config;
1291 std::vector<webrtc::Point> geometry;
1292 geometry.push_back(webrtc::Point(0.f, 0.f, 0.f));
1293 geometry.push_back(webrtc::Point(0.05f, 0.f, 0.f));
1294 config.Set<Beamforming>(new Beamforming(true, geometry));
mgraczyk@chromium.org0f663de2015-03-13 00:13:32 +00001295 testing::NiceMock<MockNonlinearBeamformer>* beamformer =
Alejandro Luebsf4022ff2016-07-01 17:19:09 -07001296 new testing::NiceMock<MockNonlinearBeamformer>(geometry, 1u);
kwiberg62eaacf2016-02-17 06:39:05 -08001297 std::unique_ptr<AudioProcessing> apm(
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +00001298 AudioProcessing::Create(config, beamformer));
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +00001299 EXPECT_EQ(kNoErr, apm->gain_control()->Enable(true));
1300 ChannelBuffer<float> src_buf(kSamplesPerChannel, kNumInputChannels);
1301 ChannelBuffer<float> dest_buf(kSamplesPerChannel, kNumOutputChannels);
pkasting25702cb2016-01-08 13:50:27 -08001302 const size_t max_length = kSamplesPerChannel * std::max(kNumInputChannels,
1303 kNumOutputChannels);
kwiberg62eaacf2016-02-17 06:39:05 -08001304 std::unique_ptr<int16_t[]> int_data(new int16_t[max_length]);
1305 std::unique_ptr<float[]> float_data(new float[max_length]);
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +00001306 std::string filename = ResourceFilePath("far", kSampleRateHz);
1307 FILE* far_file = fopen(filename.c_str(), "rb");
1308 ASSERT_TRUE(far_file != NULL) << "Could not open file " << filename << "\n";
1309 const int kDefaultVolume = apm->gain_control()->stream_analog_level();
1310 const int kDefaultCompressionGain =
1311 apm->gain_control()->compression_gain_db();
1312 bool is_target = false;
1313 EXPECT_CALL(*beamformer, is_target_present())
1314 .WillRepeatedly(testing::ReturnPointee(&is_target));
pkasting25702cb2016-01-08 13:50:27 -08001315 for (size_t i = 0; i < kNumChunks; ++i) {
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +00001316 ASSERT_TRUE(ReadChunk(far_file,
1317 int_data.get(),
1318 float_data.get(),
1319 &src_buf));
Peter Kasting69558702016-01-12 16:26:35 -08001320 for (size_t j = 0; j < kNumInputChannels; ++j) {
pkasting25702cb2016-01-08 13:50:27 -08001321 for (size_t k = 0; k < kSamplesPerChannel; ++k) {
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +00001322 src_buf.channels()[j][k] *= kScaleFactor;
1323 }
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +00001324 }
1325 EXPECT_EQ(kNoErr,
1326 apm->ProcessStream(src_buf.channels(),
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +00001327 src_buf.num_frames(),
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +00001328 kSampleRateHz,
1329 LayoutFromChannels(src_buf.num_channels()),
1330 kSampleRateHz,
1331 LayoutFromChannels(dest_buf.num_channels()),
1332 dest_buf.channels()));
1333 }
1334 EXPECT_EQ(kDefaultVolume,
1335 apm->gain_control()->stream_analog_level());
1336 EXPECT_EQ(kDefaultCompressionGain,
1337 apm->gain_control()->compression_gain_db());
1338 rewind(far_file);
1339 is_target = true;
pkasting25702cb2016-01-08 13:50:27 -08001340 for (size_t i = 0; i < kNumChunks; ++i) {
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +00001341 ASSERT_TRUE(ReadChunk(far_file,
1342 int_data.get(),
1343 float_data.get(),
1344 &src_buf));
Peter Kasting69558702016-01-12 16:26:35 -08001345 for (size_t j = 0; j < kNumInputChannels; ++j) {
pkasting25702cb2016-01-08 13:50:27 -08001346 for (size_t k = 0; k < kSamplesPerChannel; ++k) {
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +00001347 src_buf.channels()[j][k] *= kScaleFactor;
1348 }
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +00001349 }
1350 EXPECT_EQ(kNoErr,
1351 apm->ProcessStream(src_buf.channels(),
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +00001352 src_buf.num_frames(),
aluebs@webrtc.orgd82f55d2015-01-15 18:07:21 +00001353 kSampleRateHz,
1354 LayoutFromChannels(src_buf.num_channels()),
1355 kSampleRateHz,
1356 LayoutFromChannels(dest_buf.num_channels()),
1357 dest_buf.channels()));
1358 }
1359 EXPECT_LT(kDefaultVolume,
1360 apm->gain_control()->stream_analog_level());
1361 EXPECT_LT(kDefaultCompressionGain,
1362 apm->gain_control()->compression_gain_db());
1363 ASSERT_EQ(0, fclose(far_file));
1364}
1365#endif
1366
niklase@google.com470e71d2011-07-07 08:21:25 +00001367TEST_F(ApmTest, NoiseSuppression) {
andrew@webrtc.org648af742012-02-08 01:57:29 +00001368 // Test valid suppression levels.
niklase@google.com470e71d2011-07-07 08:21:25 +00001369 NoiseSuppression::Level level[] = {
1370 NoiseSuppression::kLow,
1371 NoiseSuppression::kModerate,
1372 NoiseSuppression::kHigh,
1373 NoiseSuppression::kVeryHigh
1374 };
pkasting25702cb2016-01-08 13:50:27 -08001375 for (size_t i = 0; i < arraysize(level); i++) {
niklase@google.com470e71d2011-07-07 08:21:25 +00001376 EXPECT_EQ(apm_->kNoError,
1377 apm_->noise_suppression()->set_level(level[i]));
1378 EXPECT_EQ(level[i], apm_->noise_suppression()->level());
1379 }
1380
andrew@webrtc.org648af742012-02-08 01:57:29 +00001381 // Turn NS on/off
niklase@google.com470e71d2011-07-07 08:21:25 +00001382 EXPECT_EQ(apm_->kNoError, apm_->noise_suppression()->Enable(true));
1383 EXPECT_TRUE(apm_->noise_suppression()->is_enabled());
1384 EXPECT_EQ(apm_->kNoError, apm_->noise_suppression()->Enable(false));
1385 EXPECT_FALSE(apm_->noise_suppression()->is_enabled());
1386}
1387
1388TEST_F(ApmTest, HighPassFilter) {
andrew@webrtc.org648af742012-02-08 01:57:29 +00001389 // Turn HP filter on/off
niklase@google.com470e71d2011-07-07 08:21:25 +00001390 EXPECT_EQ(apm_->kNoError, apm_->high_pass_filter()->Enable(true));
1391 EXPECT_TRUE(apm_->high_pass_filter()->is_enabled());
1392 EXPECT_EQ(apm_->kNoError, apm_->high_pass_filter()->Enable(false));
1393 EXPECT_FALSE(apm_->high_pass_filter()->is_enabled());
1394}
1395
1396TEST_F(ApmTest, LevelEstimator) {
andrew@webrtc.org648af742012-02-08 01:57:29 +00001397 // Turn level estimator on/off
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00001398 EXPECT_EQ(apm_->kNoError, apm_->level_estimator()->Enable(false));
niklase@google.com470e71d2011-07-07 08:21:25 +00001399 EXPECT_FALSE(apm_->level_estimator()->is_enabled());
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00001400
1401 EXPECT_EQ(apm_->kNotEnabledError, apm_->level_estimator()->RMS());
1402
1403 EXPECT_EQ(apm_->kNoError, apm_->level_estimator()->Enable(true));
1404 EXPECT_TRUE(apm_->level_estimator()->is_enabled());
1405
1406 // Run this test in wideband; in super-wb, the splitting filter distorts the
1407 // audio enough to cause deviation from the expectation for small values.
andrew@webrtc.org63a50982012-05-02 23:56:37 +00001408 frame_->samples_per_channel_ = 160;
1409 frame_->num_channels_ = 2;
1410 frame_->sample_rate_hz_ = 16000;
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00001411
1412 // Min value if no frames have been processed.
1413 EXPECT_EQ(127, apm_->level_estimator()->RMS());
1414
1415 // Min value on zero frames.
1416 SetFrameTo(frame_, 0);
1417 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1418 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1419 EXPECT_EQ(127, apm_->level_estimator()->RMS());
1420
1421 // Try a few RMS values.
1422 // (These also test that the value resets after retrieving it.)
1423 SetFrameTo(frame_, 32767);
1424 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1425 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1426 EXPECT_EQ(0, apm_->level_estimator()->RMS());
1427
1428 SetFrameTo(frame_, 30000);
1429 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1430 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1431 EXPECT_EQ(1, apm_->level_estimator()->RMS());
1432
1433 SetFrameTo(frame_, 10000);
1434 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1435 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1436 EXPECT_EQ(10, apm_->level_estimator()->RMS());
1437
1438 SetFrameTo(frame_, 10);
1439 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1440 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1441 EXPECT_EQ(70, apm_->level_estimator()->RMS());
1442
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00001443 // Verify reset after enable/disable.
1444 SetFrameTo(frame_, 32767);
1445 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1446 EXPECT_EQ(apm_->kNoError, apm_->level_estimator()->Enable(false));
1447 EXPECT_EQ(apm_->kNoError, apm_->level_estimator()->Enable(true));
1448 SetFrameTo(frame_, 1);
1449 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1450 EXPECT_EQ(90, apm_->level_estimator()->RMS());
1451
1452 // Verify reset after initialize.
1453 SetFrameTo(frame_, 32767);
1454 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1455 EXPECT_EQ(apm_->kNoError, apm_->Initialize());
1456 SetFrameTo(frame_, 1);
1457 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1458 EXPECT_EQ(90, apm_->level_estimator()->RMS());
niklase@google.com470e71d2011-07-07 08:21:25 +00001459}
1460
1461TEST_F(ApmTest, VoiceDetection) {
1462 // Test external VAD
1463 EXPECT_EQ(apm_->kNoError,
1464 apm_->voice_detection()->set_stream_has_voice(true));
1465 EXPECT_TRUE(apm_->voice_detection()->stream_has_voice());
1466 EXPECT_EQ(apm_->kNoError,
1467 apm_->voice_detection()->set_stream_has_voice(false));
1468 EXPECT_FALSE(apm_->voice_detection()->stream_has_voice());
1469
andrew@webrtc.org648af742012-02-08 01:57:29 +00001470 // Test valid likelihoods
niklase@google.com470e71d2011-07-07 08:21:25 +00001471 VoiceDetection::Likelihood likelihood[] = {
1472 VoiceDetection::kVeryLowLikelihood,
1473 VoiceDetection::kLowLikelihood,
1474 VoiceDetection::kModerateLikelihood,
1475 VoiceDetection::kHighLikelihood
1476 };
pkasting25702cb2016-01-08 13:50:27 -08001477 for (size_t i = 0; i < arraysize(likelihood); i++) {
niklase@google.com470e71d2011-07-07 08:21:25 +00001478 EXPECT_EQ(apm_->kNoError,
1479 apm_->voice_detection()->set_likelihood(likelihood[i]));
1480 EXPECT_EQ(likelihood[i], apm_->voice_detection()->likelihood());
1481 }
1482
1483 /* TODO(bjornv): Enable once VAD supports other frame lengths than 10 ms
andrew@webrtc.org648af742012-02-08 01:57:29 +00001484 // Test invalid frame sizes
niklase@google.com470e71d2011-07-07 08:21:25 +00001485 EXPECT_EQ(apm_->kBadParameterError,
1486 apm_->voice_detection()->set_frame_size_ms(12));
1487
andrew@webrtc.org648af742012-02-08 01:57:29 +00001488 // Test valid frame sizes
niklase@google.com470e71d2011-07-07 08:21:25 +00001489 for (int i = 10; i <= 30; i += 10) {
1490 EXPECT_EQ(apm_->kNoError,
1491 apm_->voice_detection()->set_frame_size_ms(i));
1492 EXPECT_EQ(i, apm_->voice_detection()->frame_size_ms());
1493 }
1494 */
1495
andrew@webrtc.org648af742012-02-08 01:57:29 +00001496 // Turn VAD on/off
niklase@google.com470e71d2011-07-07 08:21:25 +00001497 EXPECT_EQ(apm_->kNoError, apm_->voice_detection()->Enable(true));
1498 EXPECT_TRUE(apm_->voice_detection()->is_enabled());
1499 EXPECT_EQ(apm_->kNoError, apm_->voice_detection()->Enable(false));
1500 EXPECT_FALSE(apm_->voice_detection()->is_enabled());
1501
andrew@webrtc.orged083d42011-09-19 15:28:51 +00001502 // Test that AudioFrame activity is maintained when VAD is disabled.
1503 EXPECT_EQ(apm_->kNoError, apm_->voice_detection()->Enable(false));
1504 AudioFrame::VADActivity activity[] = {
1505 AudioFrame::kVadActive,
1506 AudioFrame::kVadPassive,
1507 AudioFrame::kVadUnknown
1508 };
pkasting25702cb2016-01-08 13:50:27 -08001509 for (size_t i = 0; i < arraysize(activity); i++) {
andrew@webrtc.org63a50982012-05-02 23:56:37 +00001510 frame_->vad_activity_ = activity[i];
andrew@webrtc.orged083d42011-09-19 15:28:51 +00001511 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
andrew@webrtc.org63a50982012-05-02 23:56:37 +00001512 EXPECT_EQ(activity[i], frame_->vad_activity_);
andrew@webrtc.orged083d42011-09-19 15:28:51 +00001513 }
1514
1515 // Test that AudioFrame activity is set when VAD is enabled.
1516 EXPECT_EQ(apm_->kNoError, apm_->voice_detection()->Enable(true));
andrew@webrtc.org63a50982012-05-02 23:56:37 +00001517 frame_->vad_activity_ = AudioFrame::kVadUnknown;
andrew@webrtc.orged083d42011-09-19 15:28:51 +00001518 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
andrew@webrtc.org63a50982012-05-02 23:56:37 +00001519 EXPECT_NE(AudioFrame::kVadUnknown, frame_->vad_activity_);
andrew@webrtc.orged083d42011-09-19 15:28:51 +00001520
niklase@google.com470e71d2011-07-07 08:21:25 +00001521 // TODO(bjornv): Add tests for streamed voice; stream_has_voice()
1522}
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00001523
andrew@webrtc.orgecac9b72012-05-02 00:04:10 +00001524TEST_F(ApmTest, AllProcessingDisabledByDefault) {
1525 EXPECT_FALSE(apm_->echo_cancellation()->is_enabled());
1526 EXPECT_FALSE(apm_->echo_control_mobile()->is_enabled());
1527 EXPECT_FALSE(apm_->gain_control()->is_enabled());
1528 EXPECT_FALSE(apm_->high_pass_filter()->is_enabled());
1529 EXPECT_FALSE(apm_->level_estimator()->is_enabled());
1530 EXPECT_FALSE(apm_->noise_suppression()->is_enabled());
1531 EXPECT_FALSE(apm_->voice_detection()->is_enabled());
1532}
1533
1534TEST_F(ApmTest, NoProcessingWhenAllComponentsDisabled) {
pkasting25702cb2016-01-08 13:50:27 -08001535 for (size_t i = 0; i < arraysize(kSampleRates); i++) {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00001536 Init(kSampleRates[i], kSampleRates[i], kSampleRates[i], 2, 2, 2, false);
andrew@webrtc.orgecac9b72012-05-02 00:04:10 +00001537 SetFrameTo(frame_, 1000, 2000);
andrew@webrtc.orgae1a58b2013-01-22 04:44:30 +00001538 AudioFrame frame_copy;
1539 frame_copy.CopyFrom(*frame_);
andrew@webrtc.orgecac9b72012-05-02 00:04:10 +00001540 for (int j = 0; j < 1000; j++) {
1541 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1542 EXPECT_TRUE(FrameDataAreEqual(*frame_, frame_copy));
ekmeyerson60d9b332015-08-14 10:35:55 -07001543 EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(frame_));
1544 EXPECT_TRUE(FrameDataAreEqual(*frame_, frame_copy));
andrew@webrtc.orgecac9b72012-05-02 00:04:10 +00001545 }
1546 }
1547}
1548
mgraczyk@chromium.orgd6e84d92015-01-14 01:33:54 +00001549TEST_F(ApmTest, NoProcessingWhenAllComponentsDisabledFloat) {
1550 // Test that ProcessStream copies input to output even with no processing.
1551 const size_t kSamples = 80;
1552 const int sample_rate = 8000;
1553 const float src[kSamples] = {
1554 -1.0f, 0.0f, 1.0f
1555 };
1556 float dest[kSamples] = {};
1557
1558 auto src_channels = &src[0];
1559 auto dest_channels = &dest[0];
1560
1561 apm_.reset(AudioProcessing::Create());
1562 EXPECT_NOERR(apm_->ProcessStream(
1563 &src_channels, kSamples, sample_rate, LayoutFromChannels(1),
1564 sample_rate, LayoutFromChannels(1), &dest_channels));
1565
1566 for (size_t i = 0; i < kSamples; ++i) {
1567 EXPECT_EQ(src[i], dest[i]);
1568 }
ekmeyerson60d9b332015-08-14 10:35:55 -07001569
1570 // Same for ProcessReverseStream.
1571 float rev_dest[kSamples] = {};
1572 auto rev_dest_channels = &rev_dest[0];
1573
1574 StreamConfig input_stream = {sample_rate, 1};
1575 StreamConfig output_stream = {sample_rate, 1};
1576 EXPECT_NOERR(apm_->ProcessReverseStream(&src_channels, input_stream,
1577 output_stream, &rev_dest_channels));
1578
1579 for (size_t i = 0; i < kSamples; ++i) {
1580 EXPECT_EQ(src[i], rev_dest[i]);
1581 }
mgraczyk@chromium.orgd6e84d92015-01-14 01:33:54 +00001582}
1583
andrew@webrtc.org07bf9a02012-05-05 00:32:00 +00001584TEST_F(ApmTest, IdenticalInputChannelsResultInIdenticalOutputChannels) {
1585 EnableAllComponents();
1586
pkasting25702cb2016-01-08 13:50:27 -08001587 for (size_t i = 0; i < arraysize(kProcessSampleRates); i++) {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00001588 Init(kProcessSampleRates[i],
1589 kProcessSampleRates[i],
1590 kProcessSampleRates[i],
1591 2,
1592 2,
1593 2,
1594 false);
andrew@webrtc.org07bf9a02012-05-05 00:32:00 +00001595 int analog_level = 127;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00001596 ASSERT_EQ(0, feof(far_file_));
1597 ASSERT_EQ(0, feof(near_file_));
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001598 while (ReadFrame(far_file_, revframe_) && ReadFrame(near_file_, frame_)) {
andrew@webrtc.org07bf9a02012-05-05 00:32:00 +00001599 CopyLeftToRightChannel(revframe_->data_, revframe_->samples_per_channel_);
1600
aluebsb0319552016-03-17 20:39:53 -07001601 ASSERT_EQ(kNoErr, apm_->ProcessReverseStream(revframe_));
andrew@webrtc.org07bf9a02012-05-05 00:32:00 +00001602
andrew@webrtc.org07bf9a02012-05-05 00:32:00 +00001603 CopyLeftToRightChannel(frame_->data_, frame_->samples_per_channel_);
1604 frame_->vad_activity_ = AudioFrame::kVadUnknown;
1605
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00001606 ASSERT_EQ(kNoErr, apm_->set_stream_delay_ms(0));
andrew@webrtc.org6be1e932013-03-01 18:47:28 +00001607 apm_->echo_cancellation()->set_stream_drift_samples(0);
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00001608 ASSERT_EQ(kNoErr,
andrew@webrtc.org07bf9a02012-05-05 00:32:00 +00001609 apm_->gain_control()->set_stream_analog_level(analog_level));
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00001610 ASSERT_EQ(kNoErr, apm_->ProcessStream(frame_));
andrew@webrtc.org07bf9a02012-05-05 00:32:00 +00001611 analog_level = apm_->gain_control()->stream_analog_level();
1612
1613 VerifyChannelsAreEqual(frame_->data_, frame_->samples_per_channel_);
1614 }
bjornv@webrtc.org3e102492013-02-14 15:29:09 +00001615 rewind(far_file_);
1616 rewind(near_file_);
andrew@webrtc.org07bf9a02012-05-05 00:32:00 +00001617 }
1618}
1619
bjornv@webrtc.orgcb0ea432014-06-09 08:21:52 +00001620TEST_F(ApmTest, SplittingFilter) {
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00001621 // Verify the filter is not active through undistorted audio when:
1622 // 1. No components are enabled...
1623 SetFrameTo(frame_, 1000);
andrew@webrtc.orgae1a58b2013-01-22 04:44:30 +00001624 AudioFrame frame_copy;
1625 frame_copy.CopyFrom(*frame_);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00001626 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1627 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1628 EXPECT_TRUE(FrameDataAreEqual(*frame_, frame_copy));
1629
1630 // 2. Only the level estimator is enabled...
1631 SetFrameTo(frame_, 1000);
andrew@webrtc.orgae1a58b2013-01-22 04:44:30 +00001632 frame_copy.CopyFrom(*frame_);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00001633 EXPECT_EQ(apm_->kNoError, apm_->level_estimator()->Enable(true));
1634 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1635 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1636 EXPECT_TRUE(FrameDataAreEqual(*frame_, frame_copy));
1637 EXPECT_EQ(apm_->kNoError, apm_->level_estimator()->Enable(false));
1638
1639 // 3. Only VAD is enabled...
1640 SetFrameTo(frame_, 1000);
andrew@webrtc.orgae1a58b2013-01-22 04:44:30 +00001641 frame_copy.CopyFrom(*frame_);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00001642 EXPECT_EQ(apm_->kNoError, apm_->voice_detection()->Enable(true));
1643 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1644 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1645 EXPECT_TRUE(FrameDataAreEqual(*frame_, frame_copy));
1646 EXPECT_EQ(apm_->kNoError, apm_->voice_detection()->Enable(false));
1647
1648 // 4. Both VAD and the level estimator are enabled...
1649 SetFrameTo(frame_, 1000);
andrew@webrtc.orgae1a58b2013-01-22 04:44:30 +00001650 frame_copy.CopyFrom(*frame_);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00001651 EXPECT_EQ(apm_->kNoError, apm_->level_estimator()->Enable(true));
1652 EXPECT_EQ(apm_->kNoError, apm_->voice_detection()->Enable(true));
1653 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1654 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1655 EXPECT_TRUE(FrameDataAreEqual(*frame_, frame_copy));
1656 EXPECT_EQ(apm_->kNoError, apm_->level_estimator()->Enable(false));
1657 EXPECT_EQ(apm_->kNoError, apm_->voice_detection()->Enable(false));
1658
1659 // 5. Not using super-wb.
andrew@webrtc.org63a50982012-05-02 23:56:37 +00001660 frame_->samples_per_channel_ = 160;
1661 frame_->num_channels_ = 2;
1662 frame_->sample_rate_hz_ = 16000;
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00001663 // Enable AEC, which would require the filter in super-wb. We rely on the
1664 // first few frames of data being unaffected by the AEC.
1665 // TODO(andrew): This test, and the one below, rely rather tenuously on the
1666 // behavior of the AEC. Think of something more robust.
1667 EXPECT_EQ(apm_->kNoError, apm_->echo_cancellation()->Enable(true));
bjornv@webrtc.orgcb0ea432014-06-09 08:21:52 +00001668 // Make sure we have extended filter enabled. This makes sure nothing is
1669 // touched until we have a farend frame.
1670 Config config;
Henrik Lundin441f6342015-06-09 16:03:13 +02001671 config.Set<ExtendedFilter>(new ExtendedFilter(true));
bjornv@webrtc.orgcb0ea432014-06-09 08:21:52 +00001672 apm_->SetExtraOptions(config);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00001673 SetFrameTo(frame_, 1000);
andrew@webrtc.orgae1a58b2013-01-22 04:44:30 +00001674 frame_copy.CopyFrom(*frame_);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00001675 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(0));
andrew@webrtc.org6be1e932013-03-01 18:47:28 +00001676 apm_->echo_cancellation()->set_stream_drift_samples(0);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00001677 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1678 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(0));
andrew@webrtc.org6be1e932013-03-01 18:47:28 +00001679 apm_->echo_cancellation()->set_stream_drift_samples(0);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00001680 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1681 EXPECT_TRUE(FrameDataAreEqual(*frame_, frame_copy));
1682
1683 // Check the test is valid. We should have distortion from the filter
1684 // when AEC is enabled (which won't affect the audio).
andrew@webrtc.org63a50982012-05-02 23:56:37 +00001685 frame_->samples_per_channel_ = 320;
1686 frame_->num_channels_ = 2;
1687 frame_->sample_rate_hz_ = 32000;
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00001688 SetFrameTo(frame_, 1000);
andrew@webrtc.orgae1a58b2013-01-22 04:44:30 +00001689 frame_copy.CopyFrom(*frame_);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00001690 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(0));
andrew@webrtc.org6be1e932013-03-01 18:47:28 +00001691 apm_->echo_cancellation()->set_stream_drift_samples(0);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00001692 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1693 EXPECT_FALSE(FrameDataAreEqual(*frame_, frame_copy));
1694}
1695
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001696#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
1697void ApmTest::ProcessDebugDump(const std::string& in_filename,
1698 const std::string& out_filename,
ivocd66b44d2016-01-15 03:06:36 -08001699 Format format,
1700 int max_size_bytes) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001701 FILE* in_file = fopen(in_filename.c_str(), "rb");
1702 ASSERT_TRUE(in_file != NULL);
1703 audioproc::Event event_msg;
1704 bool first_init = true;
1705
1706 while (ReadMessageFromFile(in_file, &event_msg)) {
1707 if (event_msg.type() == audioproc::Event::INIT) {
1708 const audioproc::Init msg = event_msg.init();
1709 int reverse_sample_rate = msg.sample_rate();
1710 if (msg.has_reverse_sample_rate()) {
1711 reverse_sample_rate = msg.reverse_sample_rate();
1712 }
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00001713 int output_sample_rate = msg.sample_rate();
1714 if (msg.has_output_sample_rate()) {
1715 output_sample_rate = msg.output_sample_rate();
1716 }
1717
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001718 Init(msg.sample_rate(),
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00001719 output_sample_rate,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001720 reverse_sample_rate,
1721 msg.num_input_channels(),
1722 msg.num_output_channels(),
1723 msg.num_reverse_channels(),
1724 false);
1725 if (first_init) {
1726 // StartDebugRecording() writes an additional init message. Don't start
1727 // recording until after the first init to avoid the extra message.
ivocd66b44d2016-01-15 03:06:36 -08001728 EXPECT_NOERR(
1729 apm_->StartDebugRecording(out_filename.c_str(), max_size_bytes));
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001730 first_init = false;
1731 }
1732
1733 } else if (event_msg.type() == audioproc::Event::REVERSE_STREAM) {
1734 const audioproc::ReverseStream msg = event_msg.reverse_stream();
1735
1736 if (msg.channel_size() > 0) {
Peter Kasting69558702016-01-12 16:26:35 -08001737 ASSERT_EQ(revframe_->num_channels_,
1738 static_cast<size_t>(msg.channel_size()));
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001739 for (int i = 0; i < msg.channel_size(); ++i) {
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +00001740 memcpy(revfloat_cb_->channels()[i],
1741 msg.channel(i).data(),
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001742 msg.channel(i).size());
1743 }
1744 } else {
1745 memcpy(revframe_->data_, msg.data().data(), msg.data().size());
1746 if (format == kFloatFormat) {
1747 // We're using an int16 input file; convert to float.
1748 ConvertToFloat(*revframe_, revfloat_cb_.get());
1749 }
1750 }
1751 AnalyzeReverseStreamChooser(format);
1752
1753 } else if (event_msg.type() == audioproc::Event::STREAM) {
1754 const audioproc::Stream msg = event_msg.stream();
1755 // ProcessStream could have changed this for the output frame.
1756 frame_->num_channels_ = apm_->num_input_channels();
1757
1758 EXPECT_NOERR(apm_->gain_control()->set_stream_analog_level(msg.level()));
1759 EXPECT_NOERR(apm_->set_stream_delay_ms(msg.delay()));
1760 apm_->echo_cancellation()->set_stream_drift_samples(msg.drift());
1761 if (msg.has_keypress()) {
1762 apm_->set_stream_key_pressed(msg.keypress());
1763 } else {
1764 apm_->set_stream_key_pressed(true);
1765 }
1766
1767 if (msg.input_channel_size() > 0) {
Peter Kasting69558702016-01-12 16:26:35 -08001768 ASSERT_EQ(frame_->num_channels_,
1769 static_cast<size_t>(msg.input_channel_size()));
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001770 for (int i = 0; i < msg.input_channel_size(); ++i) {
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +00001771 memcpy(float_cb_->channels()[i],
1772 msg.input_channel(i).data(),
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001773 msg.input_channel(i).size());
1774 }
1775 } else {
1776 memcpy(frame_->data_, msg.input_data().data(), msg.input_data().size());
1777 if (format == kFloatFormat) {
1778 // We're using an int16 input file; convert to float.
1779 ConvertToFloat(*frame_, float_cb_.get());
1780 }
1781 }
1782 ProcessStreamChooser(format);
1783 }
1784 }
1785 EXPECT_NOERR(apm_->StopDebugRecording());
1786 fclose(in_file);
1787}
1788
1789void ApmTest::VerifyDebugDumpTest(Format format) {
1790 const std::string in_filename = test::ResourcePath("ref03", "aecdump");
henrik.lundin@webrtc.org1092ea02014-04-02 07:46:49 +00001791 std::string format_string;
1792 switch (format) {
1793 case kIntFormat:
1794 format_string = "_int";
1795 break;
1796 case kFloatFormat:
1797 format_string = "_float";
1798 break;
1799 }
pbos@webrtc.orga525c982015-01-12 17:31:18 +00001800 const std::string ref_filename = test::TempFilename(
1801 test::OutputPath(), std::string("ref") + format_string + "_aecdump");
1802 const std::string out_filename = test::TempFilename(
1803 test::OutputPath(), std::string("out") + format_string + "_aecdump");
ivocd66b44d2016-01-15 03:06:36 -08001804 const std::string limited_filename = test::TempFilename(
1805 test::OutputPath(), std::string("limited") + format_string + "_aecdump");
1806 const size_t logging_limit_bytes = 100000;
1807 // We expect at least this many bytes in the created logfile.
1808 const size_t logging_expected_bytes = 95000;
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001809 EnableAllComponents();
ivocd66b44d2016-01-15 03:06:36 -08001810 ProcessDebugDump(in_filename, ref_filename, format, -1);
1811 ProcessDebugDump(ref_filename, out_filename, format, -1);
1812 ProcessDebugDump(ref_filename, limited_filename, format, logging_limit_bytes);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001813
1814 FILE* ref_file = fopen(ref_filename.c_str(), "rb");
1815 FILE* out_file = fopen(out_filename.c_str(), "rb");
ivocd66b44d2016-01-15 03:06:36 -08001816 FILE* limited_file = fopen(limited_filename.c_str(), "rb");
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001817 ASSERT_TRUE(ref_file != NULL);
1818 ASSERT_TRUE(out_file != NULL);
ivocd66b44d2016-01-15 03:06:36 -08001819 ASSERT_TRUE(limited_file != NULL);
kwiberg62eaacf2016-02-17 06:39:05 -08001820 std::unique_ptr<uint8_t[]> ref_bytes;
1821 std::unique_ptr<uint8_t[]> out_bytes;
1822 std::unique_ptr<uint8_t[]> limited_bytes;
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001823
1824 size_t ref_size = ReadMessageBytesFromFile(ref_file, &ref_bytes);
1825 size_t out_size = ReadMessageBytesFromFile(out_file, &out_bytes);
ivocd66b44d2016-01-15 03:06:36 -08001826 size_t limited_size = ReadMessageBytesFromFile(limited_file, &limited_bytes);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001827 size_t bytes_read = 0;
ivocd66b44d2016-01-15 03:06:36 -08001828 size_t bytes_read_limited = 0;
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001829 while (ref_size > 0 && out_size > 0) {
1830 bytes_read += ref_size;
ivocd66b44d2016-01-15 03:06:36 -08001831 bytes_read_limited += limited_size;
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001832 EXPECT_EQ(ref_size, out_size);
ivocd66b44d2016-01-15 03:06:36 -08001833 EXPECT_GE(ref_size, limited_size);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001834 EXPECT_EQ(0, memcmp(ref_bytes.get(), out_bytes.get(), ref_size));
ivocd66b44d2016-01-15 03:06:36 -08001835 EXPECT_EQ(0, memcmp(ref_bytes.get(), limited_bytes.get(), limited_size));
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001836 ref_size = ReadMessageBytesFromFile(ref_file, &ref_bytes);
1837 out_size = ReadMessageBytesFromFile(out_file, &out_bytes);
ivocd66b44d2016-01-15 03:06:36 -08001838 limited_size = ReadMessageBytesFromFile(limited_file, &limited_bytes);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001839 }
1840 EXPECT_GT(bytes_read, 0u);
ivocd66b44d2016-01-15 03:06:36 -08001841 EXPECT_GT(bytes_read_limited, logging_expected_bytes);
1842 EXPECT_LE(bytes_read_limited, logging_limit_bytes);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001843 EXPECT_NE(0, feof(ref_file));
1844 EXPECT_NE(0, feof(out_file));
ivocd66b44d2016-01-15 03:06:36 -08001845 EXPECT_NE(0, feof(limited_file));
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001846 ASSERT_EQ(0, fclose(ref_file));
1847 ASSERT_EQ(0, fclose(out_file));
ivocd66b44d2016-01-15 03:06:36 -08001848 ASSERT_EQ(0, fclose(limited_file));
Peter Boströmfade1792015-05-12 10:44:11 +02001849 remove(ref_filename.c_str());
1850 remove(out_filename.c_str());
ivocd66b44d2016-01-15 03:06:36 -08001851 remove(limited_filename.c_str());
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001852}
1853
pbosc7a65692016-05-06 12:50:04 -07001854TEST_F(ApmTest, VerifyDebugDumpInt) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001855 VerifyDebugDumpTest(kIntFormat);
1856}
1857
pbosc7a65692016-05-06 12:50:04 -07001858TEST_F(ApmTest, VerifyDebugDumpFloat) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001859 VerifyDebugDumpTest(kFloatFormat);
1860}
1861#endif
1862
andrew@webrtc.org7bf26462011-12-03 00:03:31 +00001863// TODO(andrew): expand test to verify output.
pbosc7a65692016-05-06 12:50:04 -07001864TEST_F(ApmTest, DebugDump) {
pbos@webrtc.orga525c982015-01-12 17:31:18 +00001865 const std::string filename =
1866 test::TempFilename(test::OutputPath(), "debug_aec");
henrikg@webrtc.org863b5362013-12-06 16:05:17 +00001867 EXPECT_EQ(apm_->kNullPointerError,
ivocd66b44d2016-01-15 03:06:36 -08001868 apm_->StartDebugRecording(static_cast<const char*>(NULL), -1));
andrew@webrtc.org7bf26462011-12-03 00:03:31 +00001869
1870#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
1871 // Stopping without having started should be OK.
1872 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording());
1873
ivocd66b44d2016-01-15 03:06:36 -08001874 EXPECT_EQ(apm_->kNoError, apm_->StartDebugRecording(filename.c_str(), -1));
andrew@webrtc.org7bf26462011-12-03 00:03:31 +00001875 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
aluebsb0319552016-03-17 20:39:53 -07001876 EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(revframe_));
andrew@webrtc.org7bf26462011-12-03 00:03:31 +00001877 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording());
1878
1879 // Verify the file has been written.
andrew@webrtc.orgf5d8c3b2012-01-24 21:35:39 +00001880 FILE* fid = fopen(filename.c_str(), "r");
1881 ASSERT_TRUE(fid != NULL);
1882
andrew@webrtc.org7bf26462011-12-03 00:03:31 +00001883 // Clean it up.
andrew@webrtc.orgf5d8c3b2012-01-24 21:35:39 +00001884 ASSERT_EQ(0, fclose(fid));
andrew@webrtc.org7bf26462011-12-03 00:03:31 +00001885 ASSERT_EQ(0, remove(filename.c_str()));
1886#else
1887 EXPECT_EQ(apm_->kUnsupportedFunctionError,
ivocd66b44d2016-01-15 03:06:36 -08001888 apm_->StartDebugRecording(filename.c_str(), -1));
andrew@webrtc.org7bf26462011-12-03 00:03:31 +00001889 EXPECT_EQ(apm_->kUnsupportedFunctionError, apm_->StopDebugRecording());
1890
1891 // Verify the file has NOT been written.
1892 ASSERT_TRUE(fopen(filename.c_str(), "r") == NULL);
1893#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
1894}
1895
henrikg@webrtc.org863b5362013-12-06 16:05:17 +00001896// TODO(andrew): expand test to verify output.
pbosc7a65692016-05-06 12:50:04 -07001897TEST_F(ApmTest, DebugDumpFromFileHandle) {
henrikg@webrtc.org863b5362013-12-06 16:05:17 +00001898 FILE* fid = NULL;
ivocd66b44d2016-01-15 03:06:36 -08001899 EXPECT_EQ(apm_->kNullPointerError, apm_->StartDebugRecording(fid, -1));
pbos@webrtc.orga525c982015-01-12 17:31:18 +00001900 const std::string filename =
1901 test::TempFilename(test::OutputPath(), "debug_aec");
henrikg@webrtc.org863b5362013-12-06 16:05:17 +00001902 fid = fopen(filename.c_str(), "w");
1903 ASSERT_TRUE(fid);
1904
1905#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
1906 // Stopping without having started should be OK.
1907 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording());
1908
ivocd66b44d2016-01-15 03:06:36 -08001909 EXPECT_EQ(apm_->kNoError, apm_->StartDebugRecording(fid, -1));
aluebsb0319552016-03-17 20:39:53 -07001910 EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(revframe_));
henrikg@webrtc.org863b5362013-12-06 16:05:17 +00001911 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
1912 EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording());
1913
1914 // Verify the file has been written.
1915 fid = fopen(filename.c_str(), "r");
1916 ASSERT_TRUE(fid != NULL);
1917
1918 // Clean it up.
1919 ASSERT_EQ(0, fclose(fid));
1920 ASSERT_EQ(0, remove(filename.c_str()));
1921#else
1922 EXPECT_EQ(apm_->kUnsupportedFunctionError,
ivocd66b44d2016-01-15 03:06:36 -08001923 apm_->StartDebugRecording(fid, -1));
henrikg@webrtc.org863b5362013-12-06 16:05:17 +00001924 EXPECT_EQ(apm_->kUnsupportedFunctionError, apm_->StopDebugRecording());
1925
1926 ASSERT_EQ(0, fclose(fid));
1927#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
1928}
1929
andrew@webrtc.org8328e7c2014-10-31 04:58:14 +00001930TEST_F(ApmTest, FloatAndIntInterfacesGiveSimilarResults) {
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001931 audioproc::OutputData ref_data;
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00001932 OpenFileAndReadMessage(ref_filename_, &ref_data);
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001933
1934 Config config;
1935 config.Set<ExperimentalAgc>(new ExperimentalAgc(false));
kwiberg62eaacf2016-02-17 06:39:05 -08001936 std::unique_ptr<AudioProcessing> fapm(AudioProcessing::Create(config));
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001937 EnableAllComponents();
1938 EnableAllAPComponents(fapm.get());
1939 for (int i = 0; i < ref_data.test_size(); i++) {
1940 printf("Running test %d of %d...\n", i + 1, ref_data.test_size());
1941
1942 audioproc::Test* test = ref_data.mutable_test(i);
1943 // TODO(ajm): Restore downmixing test cases.
1944 if (test->num_input_channels() != test->num_output_channels())
1945 continue;
1946
Peter Kasting69558702016-01-12 16:26:35 -08001947 const size_t num_render_channels =
1948 static_cast<size_t>(test->num_reverse_channels());
1949 const size_t num_input_channels =
1950 static_cast<size_t>(test->num_input_channels());
1951 const size_t num_output_channels =
1952 static_cast<size_t>(test->num_output_channels());
pkasting25702cb2016-01-08 13:50:27 -08001953 const size_t samples_per_channel = static_cast<size_t>(
1954 test->sample_rate() * AudioProcessing::kChunkSizeMs / 1000);
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001955
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00001956 Init(test->sample_rate(), test->sample_rate(), test->sample_rate(),
1957 num_input_channels, num_output_channels, num_render_channels, true);
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001958 Init(fapm.get());
1959
1960 ChannelBuffer<int16_t> output_cb(samples_per_channel, num_input_channels);
andrew@webrtc.org8328e7c2014-10-31 04:58:14 +00001961 ChannelBuffer<int16_t> output_int16(samples_per_channel,
1962 num_input_channels);
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001963
1964 int analog_level = 127;
aluebs776593b2016-03-15 14:04:58 -07001965 size_t num_bad_chunks = 0;
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001966 while (ReadFrame(far_file_, revframe_, revfloat_cb_.get()) &&
1967 ReadFrame(near_file_, frame_, float_cb_.get())) {
1968 frame_->vad_activity_ = AudioFrame::kVadUnknown;
1969
aluebsb0319552016-03-17 20:39:53 -07001970 EXPECT_NOERR(apm_->ProcessReverseStream(revframe_));
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001971 EXPECT_NOERR(fapm->AnalyzeReverseStream(
1972 revfloat_cb_->channels(),
1973 samples_per_channel,
1974 test->sample_rate(),
1975 LayoutFromChannels(num_render_channels)));
1976
1977 EXPECT_NOERR(apm_->set_stream_delay_ms(0));
1978 EXPECT_NOERR(fapm->set_stream_delay_ms(0));
1979 apm_->echo_cancellation()->set_stream_drift_samples(0);
1980 fapm->echo_cancellation()->set_stream_drift_samples(0);
1981 EXPECT_NOERR(apm_->gain_control()->set_stream_analog_level(analog_level));
1982 EXPECT_NOERR(fapm->gain_control()->set_stream_analog_level(analog_level));
1983
1984 EXPECT_NOERR(apm_->ProcessStream(frame_));
andrew@webrtc.org8328e7c2014-10-31 04:58:14 +00001985 Deinterleave(frame_->data_, samples_per_channel, num_output_channels,
1986 output_int16.channels());
1987
andrew@webrtc.org17e40642014-03-04 20:58:13 +00001988 EXPECT_NOERR(fapm->ProcessStream(
1989 float_cb_->channels(),
1990 samples_per_channel,
1991 test->sample_rate(),
1992 LayoutFromChannels(num_input_channels),
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00001993 test->sample_rate(),
1994 LayoutFromChannels(num_output_channels),
1995 float_cb_->channels()));
Peter Kasting69558702016-01-12 16:26:35 -08001996 for (size_t j = 0; j < num_output_channels; ++j) {
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +00001997 FloatToS16(float_cb_->channels()[j],
1998 samples_per_channel,
1999 output_cb.channels()[j]);
andrew@webrtc.org8328e7c2014-10-31 04:58:14 +00002000 float variance = 0;
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +00002001 float snr = ComputeSNR(output_int16.channels()[j],
2002 output_cb.channels()[j],
andrew@webrtc.org8328e7c2014-10-31 04:58:14 +00002003 samples_per_channel, &variance);
aluebs776593b2016-03-15 14:04:58 -07002004
andrew@webrtc.org8328e7c2014-10-31 04:58:14 +00002005 const float kVarianceThreshold = 20;
2006 const float kSNRThreshold = 20;
aluebs776593b2016-03-15 14:04:58 -07002007
andrew@webrtc.org8328e7c2014-10-31 04:58:14 +00002008 // Skip frames with low energy.
aluebs776593b2016-03-15 14:04:58 -07002009 if (sqrt(variance) > kVarianceThreshold && snr < kSNRThreshold) {
2010 ++num_bad_chunks;
andrew@webrtc.org8328e7c2014-10-31 04:58:14 +00002011 }
2012 }
andrew@webrtc.org17e40642014-03-04 20:58:13 +00002013
2014 analog_level = fapm->gain_control()->stream_analog_level();
2015 EXPECT_EQ(apm_->gain_control()->stream_analog_level(),
2016 fapm->gain_control()->stream_analog_level());
2017 EXPECT_EQ(apm_->echo_cancellation()->stream_has_echo(),
2018 fapm->echo_cancellation()->stream_has_echo());
andrew@webrtc.org8328e7c2014-10-31 04:58:14 +00002019 EXPECT_NEAR(apm_->noise_suppression()->speech_probability(),
2020 fapm->noise_suppression()->speech_probability(),
Alejandro Luebs47748742015-05-22 12:00:21 -07002021 0.01);
andrew@webrtc.org17e40642014-03-04 20:58:13 +00002022
2023 // Reset in case of downmixing.
Peter Kasting69558702016-01-12 16:26:35 -08002024 frame_->num_channels_ = static_cast<size_t>(test->num_input_channels());
andrew@webrtc.org17e40642014-03-04 20:58:13 +00002025 }
aluebs776593b2016-03-15 14:04:58 -07002026
2027#if defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE)
2028 const size_t kMaxNumBadChunks = 0;
2029#elif defined(WEBRTC_AUDIOPROC_FIXED_PROFILE)
2030 // There are a few chunks in the fixed-point profile that give low SNR.
2031 // Listening confirmed the difference is acceptable.
2032 const size_t kMaxNumBadChunks = 60;
2033#endif
2034 EXPECT_LE(num_bad_chunks, kMaxNumBadChunks);
2035
andrew@webrtc.org17e40642014-03-04 20:58:13 +00002036 rewind(far_file_);
2037 rewind(near_file_);
2038 }
2039}
2040
andrew@webrtc.org75f19482012-02-09 17:16:18 +00002041// TODO(andrew): Add a test to process a few frames with different combinations
2042// of enabled components.
2043
bjornv@webrtc.orgdc0b37d2014-09-23 05:03:44 +00002044TEST_F(ApmTest, Process) {
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002045 GOOGLE_PROTOBUF_VERIFY_VERSION;
andrew@webrtc.org27c69802014-02-18 20:24:56 +00002046 audioproc::OutputData ref_data;
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002047
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +00002048 if (!write_ref_data) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00002049 OpenFileAndReadMessage(ref_filename_, &ref_data);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002050 } else {
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +00002051 // Write the desired tests to the protobuf reference file.
pkasting25702cb2016-01-08 13:50:27 -08002052 for (size_t i = 0; i < arraysize(kChannels); i++) {
2053 for (size_t j = 0; j < arraysize(kChannels); j++) {
2054 for (size_t l = 0; l < arraysize(kProcessSampleRates); l++) {
andrew@webrtc.org27c69802014-02-18 20:24:56 +00002055 audioproc::Test* test = ref_data.add_test();
andrew@webrtc.org60730cf2014-01-07 17:45:09 +00002056 test->set_num_reverse_channels(kChannels[i]);
2057 test->set_num_input_channels(kChannels[j]);
2058 test->set_num_output_channels(kChannels[j]);
2059 test->set_sample_rate(kProcessSampleRates[l]);
aluebs@webrtc.orgf17ee9c2015-01-29 00:03:53 +00002060 test->set_use_aec_extended_filter(false);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002061 }
2062 }
2063 }
aluebs@webrtc.orgf17ee9c2015-01-29 00:03:53 +00002064#if defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE)
2065 // To test the extended filter mode.
2066 audioproc::Test* test = ref_data.add_test();
2067 test->set_num_reverse_channels(2);
2068 test->set_num_input_channels(2);
2069 test->set_num_output_channels(2);
2070 test->set_sample_rate(AudioProcessing::kSampleRate32kHz);
2071 test->set_use_aec_extended_filter(true);
2072#endif
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002073 }
2074
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +00002075 for (int i = 0; i < ref_data.test_size(); i++) {
2076 printf("Running test %d of %d...\n", i + 1, ref_data.test_size());
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002077
andrew@webrtc.org27c69802014-02-18 20:24:56 +00002078 audioproc::Test* test = ref_data.mutable_test(i);
andrew@webrtc.org60730cf2014-01-07 17:45:09 +00002079 // TODO(ajm): We no longer allow different input and output channels. Skip
2080 // these tests for now, but they should be removed from the set.
2081 if (test->num_input_channels() != test->num_output_channels())
2082 continue;
2083
aluebs@webrtc.orgf17ee9c2015-01-29 00:03:53 +00002084 Config config;
2085 config.Set<ExperimentalAgc>(new ExperimentalAgc(false));
Henrik Lundin441f6342015-06-09 16:03:13 +02002086 config.Set<ExtendedFilter>(
2087 new ExtendedFilter(test->use_aec_extended_filter()));
aluebs@webrtc.orgf17ee9c2015-01-29 00:03:53 +00002088 apm_.reset(AudioProcessing::Create(config));
2089
2090 EnableAllComponents();
2091
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002092 Init(test->sample_rate(),
2093 test->sample_rate(),
2094 test->sample_rate(),
Peter Kasting69558702016-01-12 16:26:35 -08002095 static_cast<size_t>(test->num_input_channels()),
2096 static_cast<size_t>(test->num_output_channels()),
2097 static_cast<size_t>(test->num_reverse_channels()),
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002098 true);
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +00002099
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002100 int frame_count = 0;
2101 int has_echo_count = 0;
2102 int has_voice_count = 0;
2103 int is_saturated_count = 0;
2104 int analog_level = 127;
2105 int analog_level_average = 0;
2106 int max_output_average = 0;
bjornv@webrtc.org08329f42012-07-12 21:00:43 +00002107 float ns_speech_prob_average = 0.0f;
minyue58530ed2016-05-24 05:50:12 -07002108#if defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE)
2109 int stats_index = 0;
2110#endif
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002111
andrew@webrtc.org17e40642014-03-04 20:58:13 +00002112 while (ReadFrame(far_file_, revframe_) && ReadFrame(near_file_, frame_)) {
aluebsb0319552016-03-17 20:39:53 -07002113 EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(revframe_));
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002114
andrew@webrtc.org07bf9a02012-05-05 00:32:00 +00002115 frame_->vad_activity_ = AudioFrame::kVadUnknown;
2116
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002117 EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(0));
andrew@webrtc.org6be1e932013-03-01 18:47:28 +00002118 apm_->echo_cancellation()->set_stream_drift_samples(0);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002119 EXPECT_EQ(apm_->kNoError,
2120 apm_->gain_control()->set_stream_analog_level(analog_level));
2121
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002122 EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
andrew@webrtc.org17e40642014-03-04 20:58:13 +00002123
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +00002124 // Ensure the frame was downmixed properly.
Peter Kasting69558702016-01-12 16:26:35 -08002125 EXPECT_EQ(static_cast<size_t>(test->num_output_channels()),
2126 frame_->num_channels_);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002127
2128 max_output_average += MaxAudioFrame(*frame_);
2129
2130 if (apm_->echo_cancellation()->stream_has_echo()) {
2131 has_echo_count++;
2132 }
2133
2134 analog_level = apm_->gain_control()->stream_analog_level();
2135 analog_level_average += analog_level;
2136 if (apm_->gain_control()->stream_is_saturated()) {
2137 is_saturated_count++;
2138 }
2139 if (apm_->voice_detection()->stream_has_voice()) {
2140 has_voice_count++;
andrew@webrtc.org63a50982012-05-02 23:56:37 +00002141 EXPECT_EQ(AudioFrame::kVadActive, frame_->vad_activity_);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002142 } else {
andrew@webrtc.org63a50982012-05-02 23:56:37 +00002143 EXPECT_EQ(AudioFrame::kVadPassive, frame_->vad_activity_);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002144 }
2145
bjornv@webrtc.org08329f42012-07-12 21:00:43 +00002146 ns_speech_prob_average += apm_->noise_suppression()->speech_probability();
2147
andrew@webrtc.org07bf9a02012-05-05 00:32:00 +00002148 size_t frame_size = frame_->samples_per_channel_ * frame_->num_channels_;
andrew@webrtc.org63a50982012-05-02 23:56:37 +00002149 size_t write_count = fwrite(frame_->data_,
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +00002150 sizeof(int16_t),
2151 frame_size,
2152 out_file_);
2153 ASSERT_EQ(frame_size, write_count);
2154
2155 // Reset in case of downmixing.
Peter Kasting69558702016-01-12 16:26:35 -08002156 frame_->num_channels_ = static_cast<size_t>(test->num_input_channels());
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002157 frame_count++;
minyue58530ed2016-05-24 05:50:12 -07002158
2159#if defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE)
2160 const int kStatsAggregationFrameNum = 100; // 1 second.
2161 if (frame_count % kStatsAggregationFrameNum == 0) {
2162 // Get echo metrics.
2163 EchoCancellation::Metrics echo_metrics;
2164 EXPECT_EQ(apm_->kNoError,
2165 apm_->echo_cancellation()->GetMetrics(&echo_metrics));
2166
2167 // Get delay metrics.
2168 int median = 0;
2169 int std = 0;
2170 float fraction_poor_delays = 0;
2171 EXPECT_EQ(apm_->kNoError,
2172 apm_->echo_cancellation()->GetDelayMetrics(
2173 &median, &std, &fraction_poor_delays));
2174
2175 // Get RMS.
2176 int rms_level = apm_->level_estimator()->RMS();
2177 EXPECT_LE(0, rms_level);
2178 EXPECT_GE(127, rms_level);
2179
2180 if (!write_ref_data) {
2181 const audioproc::Test::EchoMetrics& reference =
2182 test->echo_metrics(stats_index);
2183 TestStats(echo_metrics.residual_echo_return_loss,
2184 reference.residual_echo_return_loss());
2185 TestStats(echo_metrics.echo_return_loss,
2186 reference.echo_return_loss());
2187 TestStats(echo_metrics.echo_return_loss_enhancement,
2188 reference.echo_return_loss_enhancement());
2189 TestStats(echo_metrics.a_nlp,
2190 reference.a_nlp());
2191 EXPECT_EQ(echo_metrics.divergent_filter_fraction,
2192 reference.divergent_filter_fraction());
2193
2194 const audioproc::Test::DelayMetrics& reference_delay =
2195 test->delay_metrics(stats_index);
2196 EXPECT_EQ(reference_delay.median(), median);
2197 EXPECT_EQ(reference_delay.std(), std);
2198 EXPECT_EQ(reference_delay.fraction_poor_delays(),
2199 fraction_poor_delays);
2200
2201 EXPECT_EQ(test->rms_level(stats_index), rms_level);
2202
2203 ++stats_index;
2204 } else {
2205 audioproc::Test::EchoMetrics* message =
2206 test->add_echo_metrics();
2207 WriteStatsMessage(echo_metrics.residual_echo_return_loss,
2208 message->mutable_residual_echo_return_loss());
2209 WriteStatsMessage(echo_metrics.echo_return_loss,
2210 message->mutable_echo_return_loss());
2211 WriteStatsMessage(echo_metrics.echo_return_loss_enhancement,
2212 message->mutable_echo_return_loss_enhancement());
2213 WriteStatsMessage(echo_metrics.a_nlp,
2214 message->mutable_a_nlp());
2215 message->set_divergent_filter_fraction(
2216 echo_metrics.divergent_filter_fraction);
2217
2218 audioproc::Test::DelayMetrics* message_delay =
2219 test->add_delay_metrics();
2220 message_delay->set_median(median);
2221 message_delay->set_std(std);
2222 message_delay->set_fraction_poor_delays(fraction_poor_delays);
2223
2224 test->add_rms_level(rms_level);
2225 }
2226 }
2227#endif // defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE).
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002228 }
2229 max_output_average /= frame_count;
2230 analog_level_average /= frame_count;
bjornv@webrtc.org08329f42012-07-12 21:00:43 +00002231 ns_speech_prob_average /= frame_count;
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002232
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +00002233 if (!write_ref_data) {
bjornv@webrtc.org8dd60cc2014-09-11 08:36:35 +00002234 const int kIntNear = 1;
bjornv@webrtc.orgdc0b37d2014-09-23 05:03:44 +00002235 // When running the test on a N7 we get a {2, 6} difference of
2236 // |has_voice_count| and |max_output_average| is up to 18 higher.
2237 // All numbers being consistently higher on N7 compare to ref_data.
2238 // TODO(bjornv): If we start getting more of these offsets on Android we
2239 // should consider a different approach. Either using one slack for all,
2240 // or generate a separate android reference.
2241#if defined(WEBRTC_ANDROID)
2242 const int kHasVoiceCountOffset = 3;
Alejandro Luebs2a5609d2016-04-05 18:16:54 -07002243 const int kHasVoiceCountNear = 4;
bjornv@webrtc.orgdc0b37d2014-09-23 05:03:44 +00002244 const int kMaxOutputAverageOffset = 9;
2245 const int kMaxOutputAverageNear = 9;
2246#else
2247 const int kHasVoiceCountOffset = 0;
2248 const int kHasVoiceCountNear = kIntNear;
2249 const int kMaxOutputAverageOffset = 0;
2250 const int kMaxOutputAverageNear = kIntNear;
2251#endif
bjornv@webrtc.org8dd60cc2014-09-11 08:36:35 +00002252 EXPECT_NEAR(test->has_echo_count(), has_echo_count, kIntNear);
bjornv@webrtc.orgdc0b37d2014-09-23 05:03:44 +00002253 EXPECT_NEAR(test->has_voice_count(),
2254 has_voice_count - kHasVoiceCountOffset,
2255 kHasVoiceCountNear);
bjornv@webrtc.org8dd60cc2014-09-11 08:36:35 +00002256 EXPECT_NEAR(test->is_saturated_count(), is_saturated_count, kIntNear);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002257
bjornv@webrtc.org8dd60cc2014-09-11 08:36:35 +00002258 EXPECT_NEAR(test->analog_level_average(), analog_level_average, kIntNear);
bjornv@webrtc.orgdc0b37d2014-09-23 05:03:44 +00002259 EXPECT_NEAR(test->max_output_average(),
2260 max_output_average - kMaxOutputAverageOffset,
2261 kMaxOutputAverageNear);
andrew@webrtc.org293d22b2012-01-30 22:04:26 +00002262#if defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE)
bjornv@webrtc.org8dd60cc2014-09-11 08:36:35 +00002263 const double kFloatNear = 0.0005;
bjornv@webrtc.org8dd60cc2014-09-11 08:36:35 +00002264 EXPECT_NEAR(test->ns_speech_probability_average(),
2265 ns_speech_prob_average,
2266 kFloatNear);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002267#endif
2268 } else {
2269 test->set_has_echo_count(has_echo_count);
2270 test->set_has_voice_count(has_voice_count);
2271 test->set_is_saturated_count(is_saturated_count);
2272
2273 test->set_analog_level_average(analog_level_average);
2274 test->set_max_output_average(max_output_average);
2275
andrew@webrtc.org293d22b2012-01-30 22:04:26 +00002276#if defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE)
bjornv@webrtc.org08329f42012-07-12 21:00:43 +00002277 EXPECT_LE(0.0f, ns_speech_prob_average);
2278 EXPECT_GE(1.0f, ns_speech_prob_average);
2279 test->set_ns_speech_probability_average(ns_speech_prob_average);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002280#endif
2281 }
2282
2283 rewind(far_file_);
2284 rewind(near_file_);
2285 }
2286
andrew@webrtc.orgdaacee82012-02-07 00:01:04 +00002287 if (write_ref_data) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +00002288 OpenFileAndWriteMessage(ref_filename_, ref_data);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +00002289 }
2290}
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002291
andrew@webrtc.org103657b2014-04-24 18:28:56 +00002292TEST_F(ApmTest, NoErrorsWithKeyboardChannel) {
2293 struct ChannelFormat {
2294 AudioProcessing::ChannelLayout in_layout;
2295 AudioProcessing::ChannelLayout out_layout;
2296 };
2297 ChannelFormat cf[] = {
2298 {AudioProcessing::kMonoAndKeyboard, AudioProcessing::kMono},
2299 {AudioProcessing::kStereoAndKeyboard, AudioProcessing::kMono},
2300 {AudioProcessing::kStereoAndKeyboard, AudioProcessing::kStereo},
2301 };
andrew@webrtc.org103657b2014-04-24 18:28:56 +00002302
kwiberg62eaacf2016-02-17 06:39:05 -08002303 std::unique_ptr<AudioProcessing> ap(AudioProcessing::Create());
andrew@webrtc.org103657b2014-04-24 18:28:56 +00002304 // Enable one component just to ensure some processing takes place.
2305 ap->noise_suppression()->Enable(true);
pkasting25702cb2016-01-08 13:50:27 -08002306 for (size_t i = 0; i < arraysize(cf); ++i) {
andrew@webrtc.org103657b2014-04-24 18:28:56 +00002307 const int in_rate = 44100;
2308 const int out_rate = 48000;
2309 ChannelBuffer<float> in_cb(SamplesFromRate(in_rate),
2310 TotalChannelsFromLayout(cf[i].in_layout));
2311 ChannelBuffer<float> out_cb(SamplesFromRate(out_rate),
2312 ChannelsFromLayout(cf[i].out_layout));
2313
2314 // Run over a few chunks.
2315 for (int j = 0; j < 10; ++j) {
2316 EXPECT_NOERR(ap->ProcessStream(
2317 in_cb.channels(),
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +00002318 in_cb.num_frames(),
andrew@webrtc.org103657b2014-04-24 18:28:56 +00002319 in_rate,
2320 cf[i].in_layout,
2321 out_rate,
2322 cf[i].out_layout,
2323 out_cb.channels()));
2324 }
2325 }
2326}
2327
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002328// Compares the reference and test arrays over a region around the expected
2329// delay. Finds the highest SNR in that region and adds the variance and squared
2330// error results to the supplied accumulators.
2331void UpdateBestSNR(const float* ref,
2332 const float* test,
pkasting25702cb2016-01-08 13:50:27 -08002333 size_t length,
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002334 int expected_delay,
2335 double* variance_acc,
2336 double* sq_error_acc) {
2337 double best_snr = std::numeric_limits<double>::min();
2338 double best_variance = 0;
2339 double best_sq_error = 0;
2340 // Search over a region of eight samples around the expected delay.
2341 for (int delay = std::max(expected_delay - 4, 0); delay <= expected_delay + 4;
2342 ++delay) {
2343 double sq_error = 0;
2344 double variance = 0;
pkasting25702cb2016-01-08 13:50:27 -08002345 for (size_t i = 0; i < length - delay; ++i) {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002346 double error = test[i + delay] - ref[i];
2347 sq_error += error * error;
2348 variance += ref[i] * ref[i];
2349 }
2350
2351 if (sq_error == 0) {
2352 *variance_acc += variance;
2353 return;
2354 }
2355 double snr = variance / sq_error;
2356 if (snr > best_snr) {
2357 best_snr = snr;
2358 best_variance = variance;
2359 best_sq_error = sq_error;
2360 }
2361 }
2362
2363 *variance_acc += best_variance;
2364 *sq_error_acc += best_sq_error;
2365}
2366
2367// Used to test a multitude of sample rate and channel combinations. It works
2368// by first producing a set of reference files (in SetUpTestCase) that are
2369// assumed to be correct, as the used parameters are verified by other tests
2370// in this collection. Primarily the reference files are all produced at
2371// "native" rates which do not involve any resampling.
2372
2373// Each test pass produces an output file with a particular format. The output
2374// is matched against the reference file closest to its internal processing
2375// format. If necessary the output is resampled back to its process format.
2376// Due to the resampling distortion, we don't expect identical results, but
2377// enforce SNR thresholds which vary depending on the format. 0 is a special
2378// case SNR which corresponds to inf, or zero error.
ekmeyerson60d9b332015-08-14 10:35:55 -07002379typedef std::tr1::tuple<int, int, int, int, double, double>
2380 AudioProcessingTestData;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002381class AudioProcessingTest
2382 : public testing::TestWithParam<AudioProcessingTestData> {
2383 public:
2384 AudioProcessingTest()
2385 : input_rate_(std::tr1::get<0>(GetParam())),
2386 output_rate_(std::tr1::get<1>(GetParam())),
ekmeyerson60d9b332015-08-14 10:35:55 -07002387 reverse_input_rate_(std::tr1::get<2>(GetParam())),
2388 reverse_output_rate_(std::tr1::get<3>(GetParam())),
2389 expected_snr_(std::tr1::get<4>(GetParam())),
2390 expected_reverse_snr_(std::tr1::get<5>(GetParam())) {}
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002391
2392 virtual ~AudioProcessingTest() {}
2393
2394 static void SetUpTestCase() {
2395 // Create all needed output reference files.
Alejandro Luebs47748742015-05-22 12:00:21 -07002396 const int kNativeRates[] = {8000, 16000, 32000, 48000};
Peter Kasting69558702016-01-12 16:26:35 -08002397 const size_t kNumChannels[] = {1, 2};
pkasting25702cb2016-01-08 13:50:27 -08002398 for (size_t i = 0; i < arraysize(kNativeRates); ++i) {
2399 for (size_t j = 0; j < arraysize(kNumChannels); ++j) {
2400 for (size_t k = 0; k < arraysize(kNumChannels); ++k) {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002401 // The reference files always have matching input and output channels.
ekmeyerson60d9b332015-08-14 10:35:55 -07002402 ProcessFormat(kNativeRates[i], kNativeRates[i], kNativeRates[i],
2403 kNativeRates[i], kNumChannels[j], kNumChannels[j],
2404 kNumChannels[k], kNumChannels[k], "ref");
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002405 }
2406 }
2407 }
2408 }
2409
pbos@webrtc.org200ac002015-02-03 14:14:01 +00002410 static void TearDownTestCase() {
2411 ClearTempFiles();
2412 }
ekmeyerson60d9b332015-08-14 10:35:55 -07002413
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002414 // Runs a process pass on files with the given parameters and dumps the output
ekmeyerson60d9b332015-08-14 10:35:55 -07002415 // to a file specified with |output_file_prefix|. Both forward and reverse
2416 // output streams are dumped.
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002417 static void ProcessFormat(int input_rate,
2418 int output_rate,
ekmeyerson60d9b332015-08-14 10:35:55 -07002419 int reverse_input_rate,
2420 int reverse_output_rate,
Peter Kasting69558702016-01-12 16:26:35 -08002421 size_t num_input_channels,
2422 size_t num_output_channels,
2423 size_t num_reverse_input_channels,
2424 size_t num_reverse_output_channels,
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002425 std::string output_file_prefix) {
andrew@webrtc.org8328e7c2014-10-31 04:58:14 +00002426 Config config;
2427 config.Set<ExperimentalAgc>(new ExperimentalAgc(false));
kwiberg62eaacf2016-02-17 06:39:05 -08002428 std::unique_ptr<AudioProcessing> ap(AudioProcessing::Create(config));
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002429 EnableAllAPComponents(ap.get());
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002430
ekmeyerson60d9b332015-08-14 10:35:55 -07002431 ProcessingConfig processing_config = {
2432 {{input_rate, num_input_channels},
2433 {output_rate, num_output_channels},
2434 {reverse_input_rate, num_reverse_input_channels},
2435 {reverse_output_rate, num_reverse_output_channels}}};
2436 ap->Initialize(processing_config);
2437
2438 FILE* far_file =
2439 fopen(ResourceFilePath("far", reverse_input_rate).c_str(), "rb");
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002440 FILE* near_file = fopen(ResourceFilePath("near", input_rate).c_str(), "rb");
ekmeyerson60d9b332015-08-14 10:35:55 -07002441 FILE* out_file =
2442 fopen(OutputFilePath(output_file_prefix, input_rate, output_rate,
2443 reverse_input_rate, reverse_output_rate,
2444 num_input_channels, num_output_channels,
2445 num_reverse_input_channels,
2446 num_reverse_output_channels, kForward).c_str(),
2447 "wb");
2448 FILE* rev_out_file =
2449 fopen(OutputFilePath(output_file_prefix, input_rate, output_rate,
2450 reverse_input_rate, reverse_output_rate,
2451 num_input_channels, num_output_channels,
2452 num_reverse_input_channels,
2453 num_reverse_output_channels, kReverse).c_str(),
2454 "wb");
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002455 ASSERT_TRUE(far_file != NULL);
2456 ASSERT_TRUE(near_file != NULL);
2457 ASSERT_TRUE(out_file != NULL);
ekmeyerson60d9b332015-08-14 10:35:55 -07002458 ASSERT_TRUE(rev_out_file != NULL);
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002459
2460 ChannelBuffer<float> fwd_cb(SamplesFromRate(input_rate),
2461 num_input_channels);
ekmeyerson60d9b332015-08-14 10:35:55 -07002462 ChannelBuffer<float> rev_cb(SamplesFromRate(reverse_input_rate),
2463 num_reverse_input_channels);
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002464 ChannelBuffer<float> out_cb(SamplesFromRate(output_rate),
2465 num_output_channels);
ekmeyerson60d9b332015-08-14 10:35:55 -07002466 ChannelBuffer<float> rev_out_cb(SamplesFromRate(reverse_output_rate),
2467 num_reverse_output_channels);
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002468
2469 // Temporary buffers.
2470 const int max_length =
ekmeyerson60d9b332015-08-14 10:35:55 -07002471 2 * std::max(std::max(out_cb.num_frames(), rev_out_cb.num_frames()),
2472 std::max(fwd_cb.num_frames(), rev_cb.num_frames()));
kwiberg62eaacf2016-02-17 06:39:05 -08002473 std::unique_ptr<float[]> float_data(new float[max_length]);
2474 std::unique_ptr<int16_t[]> int_data(new int16_t[max_length]);
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002475
2476 int analog_level = 127;
2477 while (ReadChunk(far_file, int_data.get(), float_data.get(), &rev_cb) &&
2478 ReadChunk(near_file, int_data.get(), float_data.get(), &fwd_cb)) {
ekmeyerson60d9b332015-08-14 10:35:55 -07002479 EXPECT_NOERR(ap->ProcessReverseStream(
2480 rev_cb.channels(), processing_config.reverse_input_stream(),
2481 processing_config.reverse_output_stream(), rev_out_cb.channels()));
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002482
2483 EXPECT_NOERR(ap->set_stream_delay_ms(0));
2484 ap->echo_cancellation()->set_stream_drift_samples(0);
2485 EXPECT_NOERR(ap->gain_control()->set_stream_analog_level(analog_level));
2486
2487 EXPECT_NOERR(ap->ProcessStream(
2488 fwd_cb.channels(),
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +00002489 fwd_cb.num_frames(),
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002490 input_rate,
2491 LayoutFromChannels(num_input_channels),
2492 output_rate,
2493 LayoutFromChannels(num_output_channels),
2494 out_cb.channels()));
2495
ekmeyerson60d9b332015-08-14 10:35:55 -07002496 // Dump forward output to file.
2497 Interleave(out_cb.channels(), out_cb.num_frames(), out_cb.num_channels(),
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002498 float_data.get());
pkasting25702cb2016-01-08 13:50:27 -08002499 size_t out_length = out_cb.num_channels() * out_cb.num_frames();
ekmeyerson60d9b332015-08-14 10:35:55 -07002500
pkasting25702cb2016-01-08 13:50:27 -08002501 ASSERT_EQ(out_length,
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002502 fwrite(float_data.get(), sizeof(float_data[0]),
aluebs@webrtc.orgd35a5c32015-02-10 22:52:15 +00002503 out_length, out_file));
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002504
ekmeyerson60d9b332015-08-14 10:35:55 -07002505 // Dump reverse output to file.
2506 Interleave(rev_out_cb.channels(), rev_out_cb.num_frames(),
2507 rev_out_cb.num_channels(), float_data.get());
pkasting25702cb2016-01-08 13:50:27 -08002508 size_t rev_out_length =
2509 rev_out_cb.num_channels() * rev_out_cb.num_frames();
ekmeyerson60d9b332015-08-14 10:35:55 -07002510
pkasting25702cb2016-01-08 13:50:27 -08002511 ASSERT_EQ(rev_out_length,
ekmeyerson60d9b332015-08-14 10:35:55 -07002512 fwrite(float_data.get(), sizeof(float_data[0]), rev_out_length,
2513 rev_out_file));
2514
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002515 analog_level = ap->gain_control()->stream_analog_level();
2516 }
2517 fclose(far_file);
2518 fclose(near_file);
2519 fclose(out_file);
ekmeyerson60d9b332015-08-14 10:35:55 -07002520 fclose(rev_out_file);
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002521 }
2522
2523 protected:
2524 int input_rate_;
2525 int output_rate_;
ekmeyerson60d9b332015-08-14 10:35:55 -07002526 int reverse_input_rate_;
2527 int reverse_output_rate_;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002528 double expected_snr_;
ekmeyerson60d9b332015-08-14 10:35:55 -07002529 double expected_reverse_snr_;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002530};
2531
bjornv@webrtc.org2812b592014-06-02 11:27:29 +00002532TEST_P(AudioProcessingTest, Formats) {
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002533 struct ChannelFormat {
2534 int num_input;
2535 int num_output;
ekmeyerson60d9b332015-08-14 10:35:55 -07002536 int num_reverse_input;
2537 int num_reverse_output;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002538 };
2539 ChannelFormat cf[] = {
ekmeyerson60d9b332015-08-14 10:35:55 -07002540 {1, 1, 1, 1},
2541 {1, 1, 2, 1},
2542 {2, 1, 1, 1},
2543 {2, 1, 2, 1},
2544 {2, 2, 1, 1},
2545 {2, 2, 2, 2},
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002546 };
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002547
pkasting25702cb2016-01-08 13:50:27 -08002548 for (size_t i = 0; i < arraysize(cf); ++i) {
ekmeyerson60d9b332015-08-14 10:35:55 -07002549 ProcessFormat(input_rate_, output_rate_, reverse_input_rate_,
2550 reverse_output_rate_, cf[i].num_input, cf[i].num_output,
2551 cf[i].num_reverse_input, cf[i].num_reverse_output, "out");
Alejandro Luebs47748742015-05-22 12:00:21 -07002552
ekmeyerson60d9b332015-08-14 10:35:55 -07002553 // Verify output for both directions.
2554 std::vector<StreamDirection> stream_directions;
2555 stream_directions.push_back(kForward);
2556 stream_directions.push_back(kReverse);
2557 for (StreamDirection file_direction : stream_directions) {
2558 const int in_rate = file_direction ? reverse_input_rate_ : input_rate_;
2559 const int out_rate = file_direction ? reverse_output_rate_ : output_rate_;
2560 const int out_num =
2561 file_direction ? cf[i].num_reverse_output : cf[i].num_output;
2562 const double expected_snr =
2563 file_direction ? expected_reverse_snr_ : expected_snr_;
2564
2565 const int min_ref_rate = std::min(in_rate, out_rate);
2566 int ref_rate;
2567
2568 if (min_ref_rate > 32000) {
2569 ref_rate = 48000;
2570 } else if (min_ref_rate > 16000) {
2571 ref_rate = 32000;
2572 } else if (min_ref_rate > 8000) {
2573 ref_rate = 16000;
2574 } else {
2575 ref_rate = 8000;
2576 }
aluebs776593b2016-03-15 14:04:58 -07002577#ifdef WEBRTC_ARCH_ARM_FAMILY
perkjdfc28702016-03-09 16:23:23 -08002578 if (file_direction == kForward) {
aluebs776593b2016-03-15 14:04:58 -07002579 ref_rate = std::min(ref_rate, 32000);
perkjdfc28702016-03-09 16:23:23 -08002580 }
2581#endif
ekmeyerson60d9b332015-08-14 10:35:55 -07002582 FILE* out_file = fopen(
2583 OutputFilePath("out", input_rate_, output_rate_, reverse_input_rate_,
2584 reverse_output_rate_, cf[i].num_input,
2585 cf[i].num_output, cf[i].num_reverse_input,
2586 cf[i].num_reverse_output, file_direction).c_str(),
2587 "rb");
2588 // The reference files always have matching input and output channels.
2589 FILE* ref_file = fopen(
2590 OutputFilePath("ref", ref_rate, ref_rate, ref_rate, ref_rate,
2591 cf[i].num_output, cf[i].num_output,
2592 cf[i].num_reverse_output, cf[i].num_reverse_output,
2593 file_direction).c_str(),
2594 "rb");
2595 ASSERT_TRUE(out_file != NULL);
2596 ASSERT_TRUE(ref_file != NULL);
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002597
pkasting25702cb2016-01-08 13:50:27 -08002598 const size_t ref_length = SamplesFromRate(ref_rate) * out_num;
2599 const size_t out_length = SamplesFromRate(out_rate) * out_num;
ekmeyerson60d9b332015-08-14 10:35:55 -07002600 // Data from the reference file.
kwiberg62eaacf2016-02-17 06:39:05 -08002601 std::unique_ptr<float[]> ref_data(new float[ref_length]);
ekmeyerson60d9b332015-08-14 10:35:55 -07002602 // Data from the output file.
kwiberg62eaacf2016-02-17 06:39:05 -08002603 std::unique_ptr<float[]> out_data(new float[out_length]);
ekmeyerson60d9b332015-08-14 10:35:55 -07002604 // Data from the resampled output, in case the reference and output rates
2605 // don't match.
kwiberg62eaacf2016-02-17 06:39:05 -08002606 std::unique_ptr<float[]> cmp_data(new float[ref_length]);
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002607
ekmeyerson60d9b332015-08-14 10:35:55 -07002608 PushResampler<float> resampler;
2609 resampler.InitializeIfNeeded(out_rate, ref_rate, out_num);
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002610
ekmeyerson60d9b332015-08-14 10:35:55 -07002611 // Compute the resampling delay of the output relative to the reference,
2612 // to find the region over which we should search for the best SNR.
2613 float expected_delay_sec = 0;
2614 if (in_rate != ref_rate) {
2615 // Input resampling delay.
2616 expected_delay_sec +=
2617 PushSincResampler::AlgorithmicDelaySeconds(in_rate);
2618 }
2619 if (out_rate != ref_rate) {
2620 // Output resampling delay.
2621 expected_delay_sec +=
2622 PushSincResampler::AlgorithmicDelaySeconds(ref_rate);
2623 // Delay of converting the output back to its processing rate for
2624 // testing.
2625 expected_delay_sec +=
2626 PushSincResampler::AlgorithmicDelaySeconds(out_rate);
2627 }
2628 int expected_delay =
2629 floor(expected_delay_sec * ref_rate + 0.5f) * out_num;
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002630
ekmeyerson60d9b332015-08-14 10:35:55 -07002631 double variance = 0;
2632 double sq_error = 0;
2633 while (fread(out_data.get(), sizeof(out_data[0]), out_length, out_file) &&
2634 fread(ref_data.get(), sizeof(ref_data[0]), ref_length, ref_file)) {
2635 float* out_ptr = out_data.get();
2636 if (out_rate != ref_rate) {
2637 // Resample the output back to its internal processing rate if
2638 // necssary.
pkasting25702cb2016-01-08 13:50:27 -08002639 ASSERT_EQ(ref_length,
2640 static_cast<size_t>(resampler.Resample(
2641 out_ptr, out_length, cmp_data.get(), ref_length)));
ekmeyerson60d9b332015-08-14 10:35:55 -07002642 out_ptr = cmp_data.get();
2643 }
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002644
ekmeyerson60d9b332015-08-14 10:35:55 -07002645 // Update the |sq_error| and |variance| accumulators with the highest
2646 // SNR of reference vs output.
2647 UpdateBestSNR(ref_data.get(), out_ptr, ref_length, expected_delay,
2648 &variance, &sq_error);
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002649 }
2650
ekmeyerson60d9b332015-08-14 10:35:55 -07002651 std::cout << "(" << input_rate_ << ", " << output_rate_ << ", "
2652 << reverse_input_rate_ << ", " << reverse_output_rate_ << ", "
2653 << cf[i].num_input << ", " << cf[i].num_output << ", "
2654 << cf[i].num_reverse_input << ", " << cf[i].num_reverse_output
2655 << ", " << file_direction << "): ";
2656 if (sq_error > 0) {
2657 double snr = 10 * log10(variance / sq_error);
2658 EXPECT_GE(snr, expected_snr);
2659 EXPECT_NE(0, expected_snr);
2660 std::cout << "SNR=" << snr << " dB" << std::endl;
2661 } else {
aluebs776593b2016-03-15 14:04:58 -07002662 std::cout << "SNR=inf dB" << std::endl;
ekmeyerson60d9b332015-08-14 10:35:55 -07002663 }
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002664
ekmeyerson60d9b332015-08-14 10:35:55 -07002665 fclose(out_file);
2666 fclose(ref_file);
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002667 }
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002668 }
2669}
2670
2671#if defined(WEBRTC_AUDIOPROC_FLOAT_PROFILE)
2672INSTANTIATE_TEST_CASE_P(
ekmeyerson60d9b332015-08-14 10:35:55 -07002673 CommonFormats,
2674 AudioProcessingTest,
2675 testing::Values(std::tr1::make_tuple(48000, 48000, 48000, 48000, 0, 0),
peah0bf612b2016-04-06 02:47:46 -07002676 std::tr1::make_tuple(48000, 48000, 32000, 48000, 40, 30),
2677 std::tr1::make_tuple(48000, 48000, 16000, 48000, 40, 20),
ekmeyerson60d9b332015-08-14 10:35:55 -07002678 std::tr1::make_tuple(48000, 44100, 48000, 44100, 20, 20),
2679 std::tr1::make_tuple(48000, 44100, 32000, 44100, 20, 15),
2680 std::tr1::make_tuple(48000, 44100, 16000, 44100, 20, 15),
2681 std::tr1::make_tuple(48000, 32000, 48000, 32000, 30, 35),
2682 std::tr1::make_tuple(48000, 32000, 32000, 32000, 30, 0),
2683 std::tr1::make_tuple(48000, 32000, 16000, 32000, 30, 20),
2684 std::tr1::make_tuple(48000, 16000, 48000, 16000, 25, 20),
2685 std::tr1::make_tuple(48000, 16000, 32000, 16000, 25, 20),
2686 std::tr1::make_tuple(48000, 16000, 16000, 16000, 25, 0),
Alejandro Luebs47748742015-05-22 12:00:21 -07002687
ekmeyerson60d9b332015-08-14 10:35:55 -07002688 std::tr1::make_tuple(44100, 48000, 48000, 48000, 30, 0),
2689 std::tr1::make_tuple(44100, 48000, 32000, 48000, 30, 30),
2690 std::tr1::make_tuple(44100, 48000, 16000, 48000, 30, 20),
2691 std::tr1::make_tuple(44100, 44100, 48000, 44100, 20, 20),
2692 std::tr1::make_tuple(44100, 44100, 32000, 44100, 20, 15),
2693 std::tr1::make_tuple(44100, 44100, 16000, 44100, 20, 15),
2694 std::tr1::make_tuple(44100, 32000, 48000, 32000, 30, 35),
2695 std::tr1::make_tuple(44100, 32000, 32000, 32000, 30, 0),
2696 std::tr1::make_tuple(44100, 32000, 16000, 32000, 30, 20),
2697 std::tr1::make_tuple(44100, 16000, 48000, 16000, 25, 20),
2698 std::tr1::make_tuple(44100, 16000, 32000, 16000, 25, 20),
2699 std::tr1::make_tuple(44100, 16000, 16000, 16000, 25, 0),
Alejandro Luebs47748742015-05-22 12:00:21 -07002700
ekmeyerson60d9b332015-08-14 10:35:55 -07002701 std::tr1::make_tuple(32000, 48000, 48000, 48000, 30, 0),
2702 std::tr1::make_tuple(32000, 48000, 32000, 48000, 35, 30),
2703 std::tr1::make_tuple(32000, 48000, 16000, 48000, 30, 20),
2704 std::tr1::make_tuple(32000, 44100, 48000, 44100, 20, 20),
2705 std::tr1::make_tuple(32000, 44100, 32000, 44100, 20, 15),
2706 std::tr1::make_tuple(32000, 44100, 16000, 44100, 20, 15),
2707 std::tr1::make_tuple(32000, 32000, 48000, 32000, 40, 35),
2708 std::tr1::make_tuple(32000, 32000, 32000, 32000, 0, 0),
2709 std::tr1::make_tuple(32000, 32000, 16000, 32000, 40, 20),
2710 std::tr1::make_tuple(32000, 16000, 48000, 16000, 25, 20),
2711 std::tr1::make_tuple(32000, 16000, 32000, 16000, 25, 20),
2712 std::tr1::make_tuple(32000, 16000, 16000, 16000, 25, 0),
Alejandro Luebs47748742015-05-22 12:00:21 -07002713
ekmeyerson60d9b332015-08-14 10:35:55 -07002714 std::tr1::make_tuple(16000, 48000, 48000, 48000, 25, 0),
2715 std::tr1::make_tuple(16000, 48000, 32000, 48000, 25, 30),
2716 std::tr1::make_tuple(16000, 48000, 16000, 48000, 25, 20),
2717 std::tr1::make_tuple(16000, 44100, 48000, 44100, 15, 20),
2718 std::tr1::make_tuple(16000, 44100, 32000, 44100, 15, 15),
2719 std::tr1::make_tuple(16000, 44100, 16000, 44100, 15, 15),
2720 std::tr1::make_tuple(16000, 32000, 48000, 32000, 25, 35),
2721 std::tr1::make_tuple(16000, 32000, 32000, 32000, 25, 0),
2722 std::tr1::make_tuple(16000, 32000, 16000, 32000, 25, 20),
2723 std::tr1::make_tuple(16000, 16000, 48000, 16000, 40, 20),
aluebseb3603b2016-04-20 15:27:58 -07002724 std::tr1::make_tuple(16000, 16000, 32000, 16000, 40, 20),
ekmeyerson60d9b332015-08-14 10:35:55 -07002725 std::tr1::make_tuple(16000, 16000, 16000, 16000, 0, 0)));
Alejandro Luebs47748742015-05-22 12:00:21 -07002726
2727#elif defined(WEBRTC_AUDIOPROC_FIXED_PROFILE)
2728INSTANTIATE_TEST_CASE_P(
ekmeyerson60d9b332015-08-14 10:35:55 -07002729 CommonFormats,
2730 AudioProcessingTest,
perkjdfc28702016-03-09 16:23:23 -08002731 testing::Values(std::tr1::make_tuple(48000, 48000, 48000, 48000, 20, 0),
2732 std::tr1::make_tuple(48000, 48000, 32000, 48000, 20, 30),
2733 std::tr1::make_tuple(48000, 48000, 16000, 48000, 20, 20),
2734 std::tr1::make_tuple(48000, 44100, 48000, 44100, 15, 20),
2735 std::tr1::make_tuple(48000, 44100, 32000, 44100, 15, 15),
2736 std::tr1::make_tuple(48000, 44100, 16000, 44100, 15, 15),
ekmeyerson60d9b332015-08-14 10:35:55 -07002737 std::tr1::make_tuple(48000, 32000, 48000, 32000, 20, 35),
2738 std::tr1::make_tuple(48000, 32000, 32000, 32000, 20, 0),
2739 std::tr1::make_tuple(48000, 32000, 16000, 32000, 20, 20),
2740 std::tr1::make_tuple(48000, 16000, 48000, 16000, 20, 20),
2741 std::tr1::make_tuple(48000, 16000, 32000, 16000, 20, 20),
2742 std::tr1::make_tuple(48000, 16000, 16000, 16000, 20, 0),
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002743
aluebs776593b2016-03-15 14:04:58 -07002744 std::tr1::make_tuple(44100, 48000, 48000, 48000, 15, 0),
2745 std::tr1::make_tuple(44100, 48000, 32000, 48000, 15, 30),
2746 std::tr1::make_tuple(44100, 48000, 16000, 48000, 15, 20),
ekmeyerson60d9b332015-08-14 10:35:55 -07002747 std::tr1::make_tuple(44100, 44100, 48000, 44100, 15, 20),
2748 std::tr1::make_tuple(44100, 44100, 32000, 44100, 15, 15),
2749 std::tr1::make_tuple(44100, 44100, 16000, 44100, 15, 15),
2750 std::tr1::make_tuple(44100, 32000, 48000, 32000, 20, 35),
2751 std::tr1::make_tuple(44100, 32000, 32000, 32000, 20, 0),
2752 std::tr1::make_tuple(44100, 32000, 16000, 32000, 20, 20),
2753 std::tr1::make_tuple(44100, 16000, 48000, 16000, 20, 20),
2754 std::tr1::make_tuple(44100, 16000, 32000, 16000, 20, 20),
2755 std::tr1::make_tuple(44100, 16000, 16000, 16000, 20, 0),
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002756
aluebs776593b2016-03-15 14:04:58 -07002757 std::tr1::make_tuple(32000, 48000, 48000, 48000, 35, 0),
2758 std::tr1::make_tuple(32000, 48000, 32000, 48000, 65, 30),
2759 std::tr1::make_tuple(32000, 48000, 16000, 48000, 40, 20),
2760 std::tr1::make_tuple(32000, 44100, 48000, 44100, 20, 20),
2761 std::tr1::make_tuple(32000, 44100, 32000, 44100, 20, 15),
2762 std::tr1::make_tuple(32000, 44100, 16000, 44100, 20, 15),
2763 std::tr1::make_tuple(32000, 32000, 48000, 32000, 35, 35),
2764 std::tr1::make_tuple(32000, 32000, 32000, 32000, 0, 0),
2765 std::tr1::make_tuple(32000, 32000, 16000, 32000, 40, 20),
ekmeyerson60d9b332015-08-14 10:35:55 -07002766 std::tr1::make_tuple(32000, 16000, 48000, 16000, 20, 20),
2767 std::tr1::make_tuple(32000, 16000, 32000, 16000, 20, 20),
2768 std::tr1::make_tuple(32000, 16000, 16000, 16000, 20, 0),
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002769
ekmeyerson60d9b332015-08-14 10:35:55 -07002770 std::tr1::make_tuple(16000, 48000, 48000, 48000, 25, 0),
2771 std::tr1::make_tuple(16000, 48000, 32000, 48000, 25, 30),
2772 std::tr1::make_tuple(16000, 48000, 16000, 48000, 25, 20),
2773 std::tr1::make_tuple(16000, 44100, 48000, 44100, 15, 20),
2774 std::tr1::make_tuple(16000, 44100, 32000, 44100, 15, 15),
2775 std::tr1::make_tuple(16000, 44100, 16000, 44100, 15, 15),
2776 std::tr1::make_tuple(16000, 32000, 48000, 32000, 25, 35),
2777 std::tr1::make_tuple(16000, 32000, 32000, 32000, 25, 0),
2778 std::tr1::make_tuple(16000, 32000, 16000, 32000, 25, 20),
2779 std::tr1::make_tuple(16000, 16000, 48000, 16000, 35, 20),
aluebseb3603b2016-04-20 15:27:58 -07002780 std::tr1::make_tuple(16000, 16000, 32000, 16000, 35, 20),
ekmeyerson60d9b332015-08-14 10:35:55 -07002781 std::tr1::make_tuple(16000, 16000, 16000, 16000, 0, 0)));
andrew@webrtc.orgddbb8a22014-04-22 21:00:04 +00002782#endif
2783
niklase@google.com470e71d2011-07-07 08:21:25 +00002784} // namespace
andrew@webrtc.org27c69802014-02-18 20:24:56 +00002785} // namespace webrtc