OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <math.h> | 11 #include <math.h> |
12 #include <stdio.h> | 12 #include <stdio.h> |
| 13 |
13 #include <algorithm> | 14 #include <algorithm> |
14 #include <limits> | 15 #include <limits> |
| 16 #include <memory> |
15 #include <queue> | 17 #include <queue> |
16 | 18 |
17 #include "webrtc/base/arraysize.h" | 19 #include "webrtc/base/arraysize.h" |
18 #include "webrtc/base/scoped_ptr.h" | |
19 #include "webrtc/common_audio/include/audio_util.h" | 20 #include "webrtc/common_audio/include/audio_util.h" |
20 #include "webrtc/common_audio/resampler/include/push_resampler.h" | 21 #include "webrtc/common_audio/resampler/include/push_resampler.h" |
21 #include "webrtc/common_audio/resampler/push_sinc_resampler.h" | 22 #include "webrtc/common_audio/resampler/push_sinc_resampler.h" |
22 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 23 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
23 #include "webrtc/modules/audio_processing/beamformer/mock_nonlinear_beamformer.h
" | 24 #include "webrtc/modules/audio_processing/beamformer/mock_nonlinear_beamformer.h
" |
24 #include "webrtc/modules/audio_processing/common.h" | 25 #include "webrtc/modules/audio_processing/common.h" |
25 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 26 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
26 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" | 27 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" |
27 #include "webrtc/modules/audio_processing/test/test_utils.h" | 28 #include "webrtc/modules/audio_processing/test/test_utils.h" |
28 #include "webrtc/modules/include/module_common_types.h" | 29 #include "webrtc/modules/include/module_common_types.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 #endif | 220 #endif |
220 | 221 |
221 void OpenFileAndWriteMessage(const std::string filename, | 222 void OpenFileAndWriteMessage(const std::string filename, |
222 const ::google::protobuf::MessageLite& msg) { | 223 const ::google::protobuf::MessageLite& msg) { |
223 #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID) | 224 #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID) |
224 FILE* file = fopen(filename.c_str(), "wb"); | 225 FILE* file = fopen(filename.c_str(), "wb"); |
225 ASSERT_TRUE(file != NULL); | 226 ASSERT_TRUE(file != NULL); |
226 | 227 |
227 int32_t size = msg.ByteSize(); | 228 int32_t size = msg.ByteSize(); |
228 ASSERT_GT(size, 0); | 229 ASSERT_GT(size, 0); |
229 rtc::scoped_ptr<uint8_t[]> array(new uint8_t[size]); | 230 std::unique_ptr<uint8_t[]> array(new uint8_t[size]); |
230 ASSERT_TRUE(msg.SerializeToArray(array.get(), size)); | 231 ASSERT_TRUE(msg.SerializeToArray(array.get(), size)); |
231 | 232 |
232 ASSERT_EQ(1u, fwrite(&size, sizeof(size), 1, file)); | 233 ASSERT_EQ(1u, fwrite(&size, sizeof(size), 1, file)); |
233 ASSERT_EQ(static_cast<size_t>(size), | 234 ASSERT_EQ(static_cast<size_t>(size), |
234 fwrite(array.get(), sizeof(array[0]), size, file)); | 235 fwrite(array.get(), sizeof(array[0]), size, file)); |
235 fclose(file); | 236 fclose(file); |
236 #else | 237 #else |
237 std::cout << "Warning: Writing new reference is only allowed on Linux!" | 238 std::cout << "Warning: Writing new reference is only allowed on Linux!" |
238 << std::endl; | 239 << std::endl; |
239 #endif | 240 #endif |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 int AnalyzeReverseStreamChooser(Format format); | 384 int AnalyzeReverseStreamChooser(Format format); |
384 void ProcessDebugDump(const std::string& in_filename, | 385 void ProcessDebugDump(const std::string& in_filename, |
385 const std::string& out_filename, | 386 const std::string& out_filename, |
386 Format format, | 387 Format format, |
387 int max_size_bytes); | 388 int max_size_bytes); |
388 void VerifyDebugDumpTest(Format format); | 389 void VerifyDebugDumpTest(Format format); |
389 | 390 |
390 const std::string output_path_; | 391 const std::string output_path_; |
391 const std::string ref_path_; | 392 const std::string ref_path_; |
392 const std::string ref_filename_; | 393 const std::string ref_filename_; |
393 rtc::scoped_ptr<AudioProcessing> apm_; | 394 std::unique_ptr<AudioProcessing> apm_; |
394 AudioFrame* frame_; | 395 AudioFrame* frame_; |
395 AudioFrame* revframe_; | 396 AudioFrame* revframe_; |
396 rtc::scoped_ptr<ChannelBuffer<float> > float_cb_; | 397 std::unique_ptr<ChannelBuffer<float> > float_cb_; |
397 rtc::scoped_ptr<ChannelBuffer<float> > revfloat_cb_; | 398 std::unique_ptr<ChannelBuffer<float> > revfloat_cb_; |
398 int output_sample_rate_hz_; | 399 int output_sample_rate_hz_; |
399 size_t num_output_channels_; | 400 size_t num_output_channels_; |
400 FILE* far_file_; | 401 FILE* far_file_; |
401 FILE* near_file_; | 402 FILE* near_file_; |
402 FILE* out_file_; | 403 FILE* out_file_; |
403 }; | 404 }; |
404 | 405 |
405 ApmTest::ApmTest() | 406 ApmTest::ApmTest() |
406 : output_path_(test::OutputPath()), | 407 : output_path_(test::OutputPath()), |
407 ref_path_(test::ProjectRootPath() + "data/audio_processing/"), | 408 ref_path_(test::ProjectRootPath() + "data/audio_processing/"), |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 // Turn comfort noise off/on | 1073 // Turn comfort noise off/on |
1073 EXPECT_EQ(apm_->kNoError, | 1074 EXPECT_EQ(apm_->kNoError, |
1074 apm_->echo_control_mobile()->enable_comfort_noise(false)); | 1075 apm_->echo_control_mobile()->enable_comfort_noise(false)); |
1075 EXPECT_FALSE(apm_->echo_control_mobile()->is_comfort_noise_enabled()); | 1076 EXPECT_FALSE(apm_->echo_control_mobile()->is_comfort_noise_enabled()); |
1076 EXPECT_EQ(apm_->kNoError, | 1077 EXPECT_EQ(apm_->kNoError, |
1077 apm_->echo_control_mobile()->enable_comfort_noise(true)); | 1078 apm_->echo_control_mobile()->enable_comfort_noise(true)); |
1078 EXPECT_TRUE(apm_->echo_control_mobile()->is_comfort_noise_enabled()); | 1079 EXPECT_TRUE(apm_->echo_control_mobile()->is_comfort_noise_enabled()); |
1079 // Set and get echo path | 1080 // Set and get echo path |
1080 const size_t echo_path_size = | 1081 const size_t echo_path_size = |
1081 apm_->echo_control_mobile()->echo_path_size_bytes(); | 1082 apm_->echo_control_mobile()->echo_path_size_bytes(); |
1082 rtc::scoped_ptr<char[]> echo_path_in(new char[echo_path_size]); | 1083 std::unique_ptr<char[]> echo_path_in(new char[echo_path_size]); |
1083 rtc::scoped_ptr<char[]> echo_path_out(new char[echo_path_size]); | 1084 std::unique_ptr<char[]> echo_path_out(new char[echo_path_size]); |
1084 EXPECT_EQ(apm_->kNullPointerError, | 1085 EXPECT_EQ(apm_->kNullPointerError, |
1085 apm_->echo_control_mobile()->SetEchoPath(NULL, echo_path_size)); | 1086 apm_->echo_control_mobile()->SetEchoPath(NULL, echo_path_size)); |
1086 EXPECT_EQ(apm_->kNullPointerError, | 1087 EXPECT_EQ(apm_->kNullPointerError, |
1087 apm_->echo_control_mobile()->GetEchoPath(NULL, echo_path_size)); | 1088 apm_->echo_control_mobile()->GetEchoPath(NULL, echo_path_size)); |
1088 EXPECT_EQ(apm_->kBadParameterError, | 1089 EXPECT_EQ(apm_->kBadParameterError, |
1089 apm_->echo_control_mobile()->GetEchoPath(echo_path_out.get(), 1)); | 1090 apm_->echo_control_mobile()->GetEchoPath(echo_path_out.get(), 1)); |
1090 EXPECT_EQ(apm_->kNoError, | 1091 EXPECT_EQ(apm_->kNoError, |
1091 apm_->echo_control_mobile()->GetEchoPath(echo_path_out.get(), | 1092 apm_->echo_control_mobile()->GetEchoPath(echo_path_out.get(), |
1092 echo_path_size)); | 1093 echo_path_size)); |
1093 for (size_t i = 0; i < echo_path_size; i++) { | 1094 for (size_t i = 0; i < echo_path_size; i++) { |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 const size_t kNumOutputChannels = 1; | 1299 const size_t kNumOutputChannels = 1; |
1299 const size_t kNumChunks = 700; | 1300 const size_t kNumChunks = 700; |
1300 const float kScaleFactor = 0.25f; | 1301 const float kScaleFactor = 0.25f; |
1301 Config config; | 1302 Config config; |
1302 std::vector<webrtc::Point> geometry; | 1303 std::vector<webrtc::Point> geometry; |
1303 geometry.push_back(webrtc::Point(0.f, 0.f, 0.f)); | 1304 geometry.push_back(webrtc::Point(0.f, 0.f, 0.f)); |
1304 geometry.push_back(webrtc::Point(0.05f, 0.f, 0.f)); | 1305 geometry.push_back(webrtc::Point(0.05f, 0.f, 0.f)); |
1305 config.Set<Beamforming>(new Beamforming(true, geometry)); | 1306 config.Set<Beamforming>(new Beamforming(true, geometry)); |
1306 testing::NiceMock<MockNonlinearBeamformer>* beamformer = | 1307 testing::NiceMock<MockNonlinearBeamformer>* beamformer = |
1307 new testing::NiceMock<MockNonlinearBeamformer>(geometry); | 1308 new testing::NiceMock<MockNonlinearBeamformer>(geometry); |
1308 rtc::scoped_ptr<AudioProcessing> apm( | 1309 std::unique_ptr<AudioProcessing> apm( |
1309 AudioProcessing::Create(config, beamformer)); | 1310 AudioProcessing::Create(config, beamformer)); |
1310 EXPECT_EQ(kNoErr, apm->gain_control()->Enable(true)); | 1311 EXPECT_EQ(kNoErr, apm->gain_control()->Enable(true)); |
1311 ChannelBuffer<float> src_buf(kSamplesPerChannel, kNumInputChannels); | 1312 ChannelBuffer<float> src_buf(kSamplesPerChannel, kNumInputChannels); |
1312 ChannelBuffer<float> dest_buf(kSamplesPerChannel, kNumOutputChannels); | 1313 ChannelBuffer<float> dest_buf(kSamplesPerChannel, kNumOutputChannels); |
1313 const size_t max_length = kSamplesPerChannel * std::max(kNumInputChannels, | 1314 const size_t max_length = kSamplesPerChannel * std::max(kNumInputChannels, |
1314 kNumOutputChannels); | 1315 kNumOutputChannels); |
1315 rtc::scoped_ptr<int16_t[]> int_data(new int16_t[max_length]); | 1316 std::unique_ptr<int16_t[]> int_data(new int16_t[max_length]); |
1316 rtc::scoped_ptr<float[]> float_data(new float[max_length]); | 1317 std::unique_ptr<float[]> float_data(new float[max_length]); |
1317 std::string filename = ResourceFilePath("far", kSampleRateHz); | 1318 std::string filename = ResourceFilePath("far", kSampleRateHz); |
1318 FILE* far_file = fopen(filename.c_str(), "rb"); | 1319 FILE* far_file = fopen(filename.c_str(), "rb"); |
1319 ASSERT_TRUE(far_file != NULL) << "Could not open file " << filename << "\n"; | 1320 ASSERT_TRUE(far_file != NULL) << "Could not open file " << filename << "\n"; |
1320 const int kDefaultVolume = apm->gain_control()->stream_analog_level(); | 1321 const int kDefaultVolume = apm->gain_control()->stream_analog_level(); |
1321 const int kDefaultCompressionGain = | 1322 const int kDefaultCompressionGain = |
1322 apm->gain_control()->compression_gain_db(); | 1323 apm->gain_control()->compression_gain_db(); |
1323 bool is_target = false; | 1324 bool is_target = false; |
1324 EXPECT_CALL(*beamformer, is_target_present()) | 1325 EXPECT_CALL(*beamformer, is_target_present()) |
1325 .WillRepeatedly(testing::ReturnPointee(&is_target)); | 1326 .WillRepeatedly(testing::ReturnPointee(&is_target)); |
1326 for (size_t i = 0; i < kNumChunks; ++i) { | 1327 for (size_t i = 0; i < kNumChunks; ++i) { |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1821 ProcessDebugDump(in_filename, ref_filename, format, -1); | 1822 ProcessDebugDump(in_filename, ref_filename, format, -1); |
1822 ProcessDebugDump(ref_filename, out_filename, format, -1); | 1823 ProcessDebugDump(ref_filename, out_filename, format, -1); |
1823 ProcessDebugDump(ref_filename, limited_filename, format, logging_limit_bytes); | 1824 ProcessDebugDump(ref_filename, limited_filename, format, logging_limit_bytes); |
1824 | 1825 |
1825 FILE* ref_file = fopen(ref_filename.c_str(), "rb"); | 1826 FILE* ref_file = fopen(ref_filename.c_str(), "rb"); |
1826 FILE* out_file = fopen(out_filename.c_str(), "rb"); | 1827 FILE* out_file = fopen(out_filename.c_str(), "rb"); |
1827 FILE* limited_file = fopen(limited_filename.c_str(), "rb"); | 1828 FILE* limited_file = fopen(limited_filename.c_str(), "rb"); |
1828 ASSERT_TRUE(ref_file != NULL); | 1829 ASSERT_TRUE(ref_file != NULL); |
1829 ASSERT_TRUE(out_file != NULL); | 1830 ASSERT_TRUE(out_file != NULL); |
1830 ASSERT_TRUE(limited_file != NULL); | 1831 ASSERT_TRUE(limited_file != NULL); |
1831 rtc::scoped_ptr<uint8_t[]> ref_bytes; | 1832 std::unique_ptr<uint8_t[]> ref_bytes; |
1832 rtc::scoped_ptr<uint8_t[]> out_bytes; | 1833 std::unique_ptr<uint8_t[]> out_bytes; |
1833 rtc::scoped_ptr<uint8_t[]> limited_bytes; | 1834 std::unique_ptr<uint8_t[]> limited_bytes; |
1834 | 1835 |
1835 size_t ref_size = ReadMessageBytesFromFile(ref_file, &ref_bytes); | 1836 size_t ref_size = ReadMessageBytesFromFile(ref_file, &ref_bytes); |
1836 size_t out_size = ReadMessageBytesFromFile(out_file, &out_bytes); | 1837 size_t out_size = ReadMessageBytesFromFile(out_file, &out_bytes); |
1837 size_t limited_size = ReadMessageBytesFromFile(limited_file, &limited_bytes); | 1838 size_t limited_size = ReadMessageBytesFromFile(limited_file, &limited_bytes); |
1838 size_t bytes_read = 0; | 1839 size_t bytes_read = 0; |
1839 size_t bytes_read_limited = 0; | 1840 size_t bytes_read_limited = 0; |
1840 while (ref_size > 0 && out_size > 0) { | 1841 while (ref_size > 0 && out_size > 0) { |
1841 bytes_read += ref_size; | 1842 bytes_read += ref_size; |
1842 bytes_read_limited += limited_size; | 1843 bytes_read_limited += limited_size; |
1843 EXPECT_EQ(ref_size, out_size); | 1844 EXPECT_EQ(ref_size, out_size); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1937 ASSERT_EQ(0, fclose(fid)); | 1938 ASSERT_EQ(0, fclose(fid)); |
1938 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 1939 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
1939 } | 1940 } |
1940 | 1941 |
1941 TEST_F(ApmTest, FloatAndIntInterfacesGiveSimilarResults) { | 1942 TEST_F(ApmTest, FloatAndIntInterfacesGiveSimilarResults) { |
1942 audioproc::OutputData ref_data; | 1943 audioproc::OutputData ref_data; |
1943 OpenFileAndReadMessage(ref_filename_, &ref_data); | 1944 OpenFileAndReadMessage(ref_filename_, &ref_data); |
1944 | 1945 |
1945 Config config; | 1946 Config config; |
1946 config.Set<ExperimentalAgc>(new ExperimentalAgc(false)); | 1947 config.Set<ExperimentalAgc>(new ExperimentalAgc(false)); |
1947 rtc::scoped_ptr<AudioProcessing> fapm(AudioProcessing::Create(config)); | 1948 std::unique_ptr<AudioProcessing> fapm(AudioProcessing::Create(config)); |
1948 EnableAllComponents(); | 1949 EnableAllComponents(); |
1949 EnableAllAPComponents(fapm.get()); | 1950 EnableAllAPComponents(fapm.get()); |
1950 for (int i = 0; i < ref_data.test_size(); i++) { | 1951 for (int i = 0; i < ref_data.test_size(); i++) { |
1951 printf("Running test %d of %d...\n", i + 1, ref_data.test_size()); | 1952 printf("Running test %d of %d...\n", i + 1, ref_data.test_size()); |
1952 | 1953 |
1953 audioproc::Test* test = ref_data.mutable_test(i); | 1954 audioproc::Test* test = ref_data.mutable_test(i); |
1954 // TODO(ajm): Restore downmixing test cases. | 1955 // TODO(ajm): Restore downmixing test cases. |
1955 if (test->num_input_channels() != test->num_output_channels()) | 1956 if (test->num_input_channels() != test->num_output_channels()) |
1956 continue; | 1957 continue; |
1957 | 1958 |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2278 struct ChannelFormat { | 2279 struct ChannelFormat { |
2279 AudioProcessing::ChannelLayout in_layout; | 2280 AudioProcessing::ChannelLayout in_layout; |
2280 AudioProcessing::ChannelLayout out_layout; | 2281 AudioProcessing::ChannelLayout out_layout; |
2281 }; | 2282 }; |
2282 ChannelFormat cf[] = { | 2283 ChannelFormat cf[] = { |
2283 {AudioProcessing::kMonoAndKeyboard, AudioProcessing::kMono}, | 2284 {AudioProcessing::kMonoAndKeyboard, AudioProcessing::kMono}, |
2284 {AudioProcessing::kStereoAndKeyboard, AudioProcessing::kMono}, | 2285 {AudioProcessing::kStereoAndKeyboard, AudioProcessing::kMono}, |
2285 {AudioProcessing::kStereoAndKeyboard, AudioProcessing::kStereo}, | 2286 {AudioProcessing::kStereoAndKeyboard, AudioProcessing::kStereo}, |
2286 }; | 2287 }; |
2287 | 2288 |
2288 rtc::scoped_ptr<AudioProcessing> ap(AudioProcessing::Create()); | 2289 std::unique_ptr<AudioProcessing> ap(AudioProcessing::Create()); |
2289 // Enable one component just to ensure some processing takes place. | 2290 // Enable one component just to ensure some processing takes place. |
2290 ap->noise_suppression()->Enable(true); | 2291 ap->noise_suppression()->Enable(true); |
2291 for (size_t i = 0; i < arraysize(cf); ++i) { | 2292 for (size_t i = 0; i < arraysize(cf); ++i) { |
2292 const int in_rate = 44100; | 2293 const int in_rate = 44100; |
2293 const int out_rate = 48000; | 2294 const int out_rate = 48000; |
2294 ChannelBuffer<float> in_cb(SamplesFromRate(in_rate), | 2295 ChannelBuffer<float> in_cb(SamplesFromRate(in_rate), |
2295 TotalChannelsFromLayout(cf[i].in_layout)); | 2296 TotalChannelsFromLayout(cf[i].in_layout)); |
2296 ChannelBuffer<float> out_cb(SamplesFromRate(out_rate), | 2297 ChannelBuffer<float> out_cb(SamplesFromRate(out_rate), |
2297 ChannelsFromLayout(cf[i].out_layout)); | 2298 ChannelsFromLayout(cf[i].out_layout)); |
2298 | 2299 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2403 int output_rate, | 2404 int output_rate, |
2404 int reverse_input_rate, | 2405 int reverse_input_rate, |
2405 int reverse_output_rate, | 2406 int reverse_output_rate, |
2406 size_t num_input_channels, | 2407 size_t num_input_channels, |
2407 size_t num_output_channels, | 2408 size_t num_output_channels, |
2408 size_t num_reverse_input_channels, | 2409 size_t num_reverse_input_channels, |
2409 size_t num_reverse_output_channels, | 2410 size_t num_reverse_output_channels, |
2410 std::string output_file_prefix) { | 2411 std::string output_file_prefix) { |
2411 Config config; | 2412 Config config; |
2412 config.Set<ExperimentalAgc>(new ExperimentalAgc(false)); | 2413 config.Set<ExperimentalAgc>(new ExperimentalAgc(false)); |
2413 rtc::scoped_ptr<AudioProcessing> ap(AudioProcessing::Create(config)); | 2414 std::unique_ptr<AudioProcessing> ap(AudioProcessing::Create(config)); |
2414 EnableAllAPComponents(ap.get()); | 2415 EnableAllAPComponents(ap.get()); |
2415 | 2416 |
2416 ProcessingConfig processing_config = { | 2417 ProcessingConfig processing_config = { |
2417 {{input_rate, num_input_channels}, | 2418 {{input_rate, num_input_channels}, |
2418 {output_rate, num_output_channels}, | 2419 {output_rate, num_output_channels}, |
2419 {reverse_input_rate, num_reverse_input_channels}, | 2420 {reverse_input_rate, num_reverse_input_channels}, |
2420 {reverse_output_rate, num_reverse_output_channels}}}; | 2421 {reverse_output_rate, num_reverse_output_channels}}}; |
2421 ap->Initialize(processing_config); | 2422 ap->Initialize(processing_config); |
2422 | 2423 |
2423 FILE* far_file = | 2424 FILE* far_file = |
(...skipping 24 matching lines...) Expand all Loading... |
2448 num_reverse_input_channels); | 2449 num_reverse_input_channels); |
2449 ChannelBuffer<float> out_cb(SamplesFromRate(output_rate), | 2450 ChannelBuffer<float> out_cb(SamplesFromRate(output_rate), |
2450 num_output_channels); | 2451 num_output_channels); |
2451 ChannelBuffer<float> rev_out_cb(SamplesFromRate(reverse_output_rate), | 2452 ChannelBuffer<float> rev_out_cb(SamplesFromRate(reverse_output_rate), |
2452 num_reverse_output_channels); | 2453 num_reverse_output_channels); |
2453 | 2454 |
2454 // Temporary buffers. | 2455 // Temporary buffers. |
2455 const int max_length = | 2456 const int max_length = |
2456 2 * std::max(std::max(out_cb.num_frames(), rev_out_cb.num_frames()), | 2457 2 * std::max(std::max(out_cb.num_frames(), rev_out_cb.num_frames()), |
2457 std::max(fwd_cb.num_frames(), rev_cb.num_frames())); | 2458 std::max(fwd_cb.num_frames(), rev_cb.num_frames())); |
2458 rtc::scoped_ptr<float[]> float_data(new float[max_length]); | 2459 std::unique_ptr<float[]> float_data(new float[max_length]); |
2459 rtc::scoped_ptr<int16_t[]> int_data(new int16_t[max_length]); | 2460 std::unique_ptr<int16_t[]> int_data(new int16_t[max_length]); |
2460 | 2461 |
2461 int analog_level = 127; | 2462 int analog_level = 127; |
2462 while (ReadChunk(far_file, int_data.get(), float_data.get(), &rev_cb) && | 2463 while (ReadChunk(far_file, int_data.get(), float_data.get(), &rev_cb) && |
2463 ReadChunk(near_file, int_data.get(), float_data.get(), &fwd_cb)) { | 2464 ReadChunk(near_file, int_data.get(), float_data.get(), &fwd_cb)) { |
2464 EXPECT_NOERR(ap->ProcessReverseStream( | 2465 EXPECT_NOERR(ap->ProcessReverseStream( |
2465 rev_cb.channels(), processing_config.reverse_input_stream(), | 2466 rev_cb.channels(), processing_config.reverse_input_stream(), |
2466 processing_config.reverse_output_stream(), rev_out_cb.channels())); | 2467 processing_config.reverse_output_stream(), rev_out_cb.channels())); |
2467 | 2468 |
2468 EXPECT_NOERR(ap->set_stream_delay_ms(0)); | 2469 EXPECT_NOERR(ap->set_stream_delay_ms(0)); |
2469 ap->echo_cancellation()->set_stream_drift_samples(0); | 2470 ap->echo_cancellation()->set_stream_drift_samples(0); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2576 cf[i].num_output, cf[i].num_output, | 2577 cf[i].num_output, cf[i].num_output, |
2577 cf[i].num_reverse_output, cf[i].num_reverse_output, | 2578 cf[i].num_reverse_output, cf[i].num_reverse_output, |
2578 file_direction).c_str(), | 2579 file_direction).c_str(), |
2579 "rb"); | 2580 "rb"); |
2580 ASSERT_TRUE(out_file != NULL); | 2581 ASSERT_TRUE(out_file != NULL); |
2581 ASSERT_TRUE(ref_file != NULL); | 2582 ASSERT_TRUE(ref_file != NULL); |
2582 | 2583 |
2583 const size_t ref_length = SamplesFromRate(ref_rate) * out_num; | 2584 const size_t ref_length = SamplesFromRate(ref_rate) * out_num; |
2584 const size_t out_length = SamplesFromRate(out_rate) * out_num; | 2585 const size_t out_length = SamplesFromRate(out_rate) * out_num; |
2585 // Data from the reference file. | 2586 // Data from the reference file. |
2586 rtc::scoped_ptr<float[]> ref_data(new float[ref_length]); | 2587 std::unique_ptr<float[]> ref_data(new float[ref_length]); |
2587 // Data from the output file. | 2588 // Data from the output file. |
2588 rtc::scoped_ptr<float[]> out_data(new float[out_length]); | 2589 std::unique_ptr<float[]> out_data(new float[out_length]); |
2589 // Data from the resampled output, in case the reference and output rates | 2590 // Data from the resampled output, in case the reference and output rates |
2590 // don't match. | 2591 // don't match. |
2591 rtc::scoped_ptr<float[]> cmp_data(new float[ref_length]); | 2592 std::unique_ptr<float[]> cmp_data(new float[ref_length]); |
2592 | 2593 |
2593 PushResampler<float> resampler; | 2594 PushResampler<float> resampler; |
2594 resampler.InitializeIfNeeded(out_rate, ref_rate, out_num); | 2595 resampler.InitializeIfNeeded(out_rate, ref_rate, out_num); |
2595 | 2596 |
2596 // Compute the resampling delay of the output relative to the reference, | 2597 // Compute the resampling delay of the output relative to the reference, |
2597 // to find the region over which we should search for the best SNR. | 2598 // to find the region over which we should search for the best SNR. |
2598 float expected_delay_sec = 0; | 2599 float expected_delay_sec = 0; |
2599 if (in_rate != ref_rate) { | 2600 if (in_rate != ref_rate) { |
2600 // Input resampling delay. | 2601 // Input resampling delay. |
2601 expected_delay_sec += | 2602 expected_delay_sec += |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2763 std::tr1::make_tuple(16000, 32000, 48000, 32000, 25, 35), | 2764 std::tr1::make_tuple(16000, 32000, 48000, 32000, 25, 35), |
2764 std::tr1::make_tuple(16000, 32000, 32000, 32000, 25, 0), | 2765 std::tr1::make_tuple(16000, 32000, 32000, 32000, 25, 0), |
2765 std::tr1::make_tuple(16000, 32000, 16000, 32000, 25, 20), | 2766 std::tr1::make_tuple(16000, 32000, 16000, 32000, 25, 20), |
2766 std::tr1::make_tuple(16000, 16000, 48000, 16000, 35, 20), | 2767 std::tr1::make_tuple(16000, 16000, 48000, 16000, 35, 20), |
2767 std::tr1::make_tuple(16000, 16000, 32000, 16000, 40, 20), | 2768 std::tr1::make_tuple(16000, 16000, 32000, 16000, 40, 20), |
2768 std::tr1::make_tuple(16000, 16000, 16000, 16000, 0, 0))); | 2769 std::tr1::make_tuple(16000, 16000, 16000, 16000, 0, 0))); |
2769 #endif | 2770 #endif |
2770 | 2771 |
2771 } // namespace | 2772 } // namespace |
2772 } // namespace webrtc | 2773 } // namespace webrtc |
OLD | NEW |