Added a perf test for the residual echo detector.
This perf tests the echo detector in 3 scenarios: standalone, as part of APM with only the echo detector enabled and as part of a normally configured APM. BUG=webrtc:6525 Review-Url: https://codereview.webrtc.org/2517523003 Cr-Commit-Position: refs/heads/master@{#15224}
This commit is contained in:
parent
37a2111d7c
commit
3cfb3efd69
@ -627,6 +627,7 @@ if (rtc_include_tests) {
|
||||
"modules/audio_coding/neteq/test/neteq_performance_unittest.cc",
|
||||
"modules/audio_processing/audio_processing_performance_unittest.cc",
|
||||
"modules/audio_processing/level_controller/level_controller_complexity_unittest.cc",
|
||||
"modules/audio_processing/residual_echo_detector_complexity_unittest.cc",
|
||||
"modules/remote_bitrate_estimator/remote_bitrate_estimators_test.cc",
|
||||
"video/full_stack.cc",
|
||||
]
|
||||
|
||||
@ -388,6 +388,10 @@ if (rtc_include_tests) {
|
||||
sources = [
|
||||
"test/audio_buffer_tools.cc",
|
||||
"test/audio_buffer_tools.h",
|
||||
"test/performance_timer.cc",
|
||||
"test/performance_timer.h",
|
||||
"test/simulator_buffers.cc",
|
||||
"test/simulator_buffers.h",
|
||||
"test/test_utils.cc",
|
||||
"test/test_utils.h",
|
||||
]
|
||||
|
||||
@ -18,6 +18,8 @@
|
||||
#include "webrtc/modules/audio_processing/level_controller/level_controller.h"
|
||||
#include "webrtc/modules/audio_processing/test/audio_buffer_tools.h"
|
||||
#include "webrtc/modules/audio_processing/test/bitexactness_tools.h"
|
||||
#include "webrtc/modules/audio_processing/test/performance_timer.h"
|
||||
#include "webrtc/modules/audio_processing/test/simulator_buffers.h"
|
||||
#include "webrtc/system_wrappers/include/clock.h"
|
||||
#include "webrtc/test/gtest.h"
|
||||
#include "webrtc/test/testsupport/perf_test.h"
|
||||
@ -27,131 +29,7 @@ namespace {
|
||||
|
||||
const size_t kNumFramesToProcess = 100;
|
||||
|
||||
struct SimulatorBuffers {
|
||||
SimulatorBuffers(int render_input_sample_rate_hz,
|
||||
int capture_input_sample_rate_hz,
|
||||
int render_output_sample_rate_hz,
|
||||
int capture_output_sample_rate_hz,
|
||||
size_t num_render_input_channels,
|
||||
size_t num_capture_input_channels,
|
||||
size_t num_render_output_channels,
|
||||
size_t num_capture_output_channels) {
|
||||
Random rand_gen(42);
|
||||
CreateConfigAndBuffer(render_input_sample_rate_hz,
|
||||
num_render_input_channels, &rand_gen,
|
||||
&render_input_buffer, &render_input_config,
|
||||
&render_input, &render_input_samples);
|
||||
|
||||
CreateConfigAndBuffer(render_output_sample_rate_hz,
|
||||
num_render_output_channels, &rand_gen,
|
||||
&render_output_buffer, &render_output_config,
|
||||
&render_output, &render_output_samples);
|
||||
|
||||
CreateConfigAndBuffer(capture_input_sample_rate_hz,
|
||||
num_capture_input_channels, &rand_gen,
|
||||
&capture_input_buffer, &capture_input_config,
|
||||
&capture_input, &capture_input_samples);
|
||||
|
||||
CreateConfigAndBuffer(capture_output_sample_rate_hz,
|
||||
num_capture_output_channels, &rand_gen,
|
||||
&capture_output_buffer, &capture_output_config,
|
||||
&capture_output, &capture_output_samples);
|
||||
|
||||
UpdateInputBuffers();
|
||||
}
|
||||
|
||||
void CreateConfigAndBuffer(int sample_rate_hz,
|
||||
size_t num_channels,
|
||||
Random* rand_gen,
|
||||
std::unique_ptr<AudioBuffer>* buffer,
|
||||
StreamConfig* config,
|
||||
std::vector<float*>* buffer_data,
|
||||
std::vector<float>* buffer_data_samples) {
|
||||
int samples_per_channel = rtc::CheckedDivExact(sample_rate_hz, 100);
|
||||
*config = StreamConfig(sample_rate_hz, num_channels, false);
|
||||
buffer->reset(new AudioBuffer(config->num_frames(), config->num_channels(),
|
||||
config->num_frames(), config->num_channels(),
|
||||
config->num_frames()));
|
||||
|
||||
buffer_data_samples->resize(samples_per_channel * num_channels);
|
||||
for (auto& v : *buffer_data_samples) {
|
||||
v = rand_gen->Rand<float>();
|
||||
}
|
||||
|
||||
buffer_data->resize(num_channels);
|
||||
for (size_t ch = 0; ch < num_channels; ++ch) {
|
||||
(*buffer_data)[ch] = &(*buffer_data_samples)[ch * samples_per_channel];
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateInputBuffers() {
|
||||
test::CopyVectorToAudioBuffer(capture_input_config, capture_input_samples,
|
||||
capture_input_buffer.get());
|
||||
test::CopyVectorToAudioBuffer(render_input_config, render_input_samples,
|
||||
render_input_buffer.get());
|
||||
}
|
||||
|
||||
std::unique_ptr<AudioBuffer> render_input_buffer;
|
||||
std::unique_ptr<AudioBuffer> capture_input_buffer;
|
||||
std::unique_ptr<AudioBuffer> render_output_buffer;
|
||||
std::unique_ptr<AudioBuffer> capture_output_buffer;
|
||||
StreamConfig render_input_config;
|
||||
StreamConfig capture_input_config;
|
||||
StreamConfig render_output_config;
|
||||
StreamConfig capture_output_config;
|
||||
std::vector<float*> render_input;
|
||||
std::vector<float> render_input_samples;
|
||||
std::vector<float*> capture_input;
|
||||
std::vector<float> capture_input_samples;
|
||||
std::vector<float*> render_output;
|
||||
std::vector<float> render_output_samples;
|
||||
std::vector<float*> capture_output;
|
||||
std::vector<float> capture_output_samples;
|
||||
};
|
||||
|
||||
class SubmodulePerformanceTimer {
|
||||
public:
|
||||
SubmodulePerformanceTimer() : clock_(webrtc::Clock::GetRealTimeClock()) {
|
||||
timestamps_us_.reserve(kNumFramesToProcess);
|
||||
}
|
||||
|
||||
void StartTimer() {
|
||||
start_timestamp_us_ = rtc::Optional<int64_t>(clock_->TimeInMicroseconds());
|
||||
}
|
||||
void StopTimer() {
|
||||
RTC_DCHECK(start_timestamp_us_);
|
||||
timestamps_us_.push_back(clock_->TimeInMicroseconds() -
|
||||
*start_timestamp_us_);
|
||||
}
|
||||
|
||||
double GetDurationAverage() const {
|
||||
RTC_DCHECK(!timestamps_us_.empty());
|
||||
return static_cast<double>(std::accumulate(timestamps_us_.begin(),
|
||||
timestamps_us_.end(), 0)) /
|
||||
timestamps_us_.size();
|
||||
}
|
||||
|
||||
double GetDurationStandardDeviation() const {
|
||||
RTC_DCHECK(!timestamps_us_.empty());
|
||||
double average_duration = GetDurationAverage();
|
||||
|
||||
double variance = std::accumulate(
|
||||
timestamps_us_.begin(), timestamps_us_.end(), 0.0,
|
||||
[average_duration](const double& a, const int64_t& b) {
|
||||
return a + (b - average_duration) * (b - average_duration);
|
||||
});
|
||||
|
||||
return sqrt(variance / timestamps_us_.size());
|
||||
}
|
||||
|
||||
private:
|
||||
webrtc::Clock* clock_;
|
||||
rtc::Optional<int64_t> start_timestamp_us_;
|
||||
std::vector<int64_t> timestamps_us_;
|
||||
};
|
||||
|
||||
std::string FormPerformanceMeasureString(
|
||||
const SubmodulePerformanceTimer& timer) {
|
||||
std::string FormPerformanceMeasureString(const test::PerformanceTimer& timer) {
|
||||
std::string s = std::to_string(timer.GetDurationAverage());
|
||||
s += ", ";
|
||||
s += std::to_string(timer.GetDurationStandardDeviation());
|
||||
@ -159,10 +37,10 @@ std::string FormPerformanceMeasureString(
|
||||
}
|
||||
|
||||
void RunStandaloneSubmodule(int sample_rate_hz, size_t num_channels) {
|
||||
SimulatorBuffers buffers(sample_rate_hz, sample_rate_hz, sample_rate_hz,
|
||||
sample_rate_hz, num_channels, num_channels,
|
||||
num_channels, num_channels);
|
||||
SubmodulePerformanceTimer timer;
|
||||
test::SimulatorBuffers buffers(sample_rate_hz, sample_rate_hz, sample_rate_hz,
|
||||
sample_rate_hz, num_channels, num_channels,
|
||||
num_channels, num_channels);
|
||||
test::PerformanceTimer timer(kNumFramesToProcess);
|
||||
|
||||
LevelController level_controller;
|
||||
level_controller.Initialize(sample_rate_hz);
|
||||
@ -190,13 +68,13 @@ void RunTogetherWithApm(std::string test_description,
|
||||
size_t num_channels,
|
||||
bool use_mobile_aec,
|
||||
bool include_default_apm_processing) {
|
||||
SimulatorBuffers buffers(
|
||||
test::SimulatorBuffers buffers(
|
||||
render_input_sample_rate_hz, capture_input_sample_rate_hz,
|
||||
render_output_sample_rate_hz, capture_output_sample_rate_hz, num_channels,
|
||||
num_channels, num_channels, num_channels);
|
||||
SubmodulePerformanceTimer render_timer;
|
||||
SubmodulePerformanceTimer capture_timer;
|
||||
SubmodulePerformanceTimer total_timer;
|
||||
test::PerformanceTimer render_timer(kNumFramesToProcess);
|
||||
test::PerformanceTimer capture_timer(kNumFramesToProcess);
|
||||
test::PerformanceTimer total_timer(kNumFramesToProcess);
|
||||
|
||||
webrtc::Config config;
|
||||
AudioProcessing::Config apm_config;
|
||||
|
||||
@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
|
||||
#include "webrtc/base/array_view.h"
|
||||
#include "webrtc/base/random.h"
|
||||
#include "webrtc/modules/audio_processing/audio_buffer.h"
|
||||
#include "webrtc/modules/audio_processing/include/audio_processing.h"
|
||||
#include "webrtc/modules/audio_processing/residual_echo_detector.h"
|
||||
#include "webrtc/modules/audio_processing/test/audio_buffer_tools.h"
|
||||
#include "webrtc/modules/audio_processing/test/performance_timer.h"
|
||||
#include "webrtc/modules/audio_processing/test/simulator_buffers.h"
|
||||
#include "webrtc/system_wrappers/include/clock.h"
|
||||
#include "webrtc/test/gtest.h"
|
||||
#include "webrtc/test/testsupport/perf_test.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
|
||||
const size_t kNumFramesToProcess = 100;
|
||||
const int kSampleRate = AudioProcessing::kSampleRate48kHz;
|
||||
const int kNumberOfChannels = 1;
|
||||
|
||||
std::string FormPerformanceMeasureString(const test::PerformanceTimer& timer) {
|
||||
std::string s = std::to_string(timer.GetDurationAverage());
|
||||
s += ", ";
|
||||
s += std::to_string(timer.GetDurationStandardDeviation());
|
||||
return s;
|
||||
}
|
||||
|
||||
void RunStandaloneSubmodule() {
|
||||
test::SimulatorBuffers buffers(
|
||||
kSampleRate, kSampleRate, kSampleRate, kSampleRate, kNumberOfChannels,
|
||||
kNumberOfChannels, kNumberOfChannels, kNumberOfChannels);
|
||||
test::PerformanceTimer timer(kNumFramesToProcess);
|
||||
|
||||
ResidualEchoDetector echo_detector;
|
||||
echo_detector.Initialize();
|
||||
|
||||
for (size_t frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) {
|
||||
buffers.UpdateInputBuffers();
|
||||
|
||||
timer.StartTimer();
|
||||
echo_detector.AnalyzeRenderAudio(rtc::ArrayView<const float>(
|
||||
buffers.render_input_buffer->split_bands_const_f(0)[kBand0To8kHz],
|
||||
buffers.render_input_buffer->num_frames_per_band()));
|
||||
echo_detector.AnalyzeCaptureAudio(rtc::ArrayView<const float>(
|
||||
buffers.capture_input_buffer->split_bands_const_f(0)[kBand0To8kHz],
|
||||
buffers.capture_input_buffer->num_frames_per_band()));
|
||||
timer.StopTimer();
|
||||
}
|
||||
webrtc::test::PrintResultMeanAndError(
|
||||
"echo_detector_call_durations", "", "StandaloneEchoDetector",
|
||||
FormPerformanceMeasureString(timer), "us", false);
|
||||
}
|
||||
|
||||
void RunTogetherWithApm(std::string test_description,
|
||||
bool use_mobile_aec,
|
||||
bool include_default_apm_processing) {
|
||||
test::SimulatorBuffers buffers(
|
||||
kSampleRate, kSampleRate, kSampleRate, kSampleRate, kNumberOfChannels,
|
||||
kNumberOfChannels, kNumberOfChannels, kNumberOfChannels);
|
||||
test::PerformanceTimer render_timer(kNumFramesToProcess);
|
||||
test::PerformanceTimer capture_timer(kNumFramesToProcess);
|
||||
test::PerformanceTimer total_timer(kNumFramesToProcess);
|
||||
|
||||
webrtc::Config config;
|
||||
AudioProcessing::Config apm_config;
|
||||
if (include_default_apm_processing) {
|
||||
config.Set<DelayAgnostic>(new DelayAgnostic(true));
|
||||
config.Set<ExtendedFilter>(new ExtendedFilter(true));
|
||||
}
|
||||
apm_config.level_controller.enabled = include_default_apm_processing;
|
||||
apm_config.residual_echo_detector.enabled = true;
|
||||
|
||||
std::unique_ptr<AudioProcessing> apm;
|
||||
apm.reset(AudioProcessing::Create(config));
|
||||
ASSERT_TRUE(apm.get());
|
||||
apm->ApplyConfig(apm_config);
|
||||
|
||||
ASSERT_EQ(AudioProcessing::kNoError,
|
||||
apm->gain_control()->Enable(include_default_apm_processing));
|
||||
if (use_mobile_aec) {
|
||||
ASSERT_EQ(AudioProcessing::kNoError,
|
||||
apm->echo_cancellation()->Enable(false));
|
||||
ASSERT_EQ(AudioProcessing::kNoError, apm->echo_control_mobile()->Enable(
|
||||
include_default_apm_processing));
|
||||
} else {
|
||||
ASSERT_EQ(AudioProcessing::kNoError,
|
||||
apm->echo_cancellation()->Enable(include_default_apm_processing));
|
||||
ASSERT_EQ(AudioProcessing::kNoError,
|
||||
apm->echo_control_mobile()->Enable(false));
|
||||
}
|
||||
ASSERT_EQ(AudioProcessing::kNoError,
|
||||
apm->high_pass_filter()->Enable(include_default_apm_processing));
|
||||
ASSERT_EQ(AudioProcessing::kNoError,
|
||||
apm->noise_suppression()->Enable(include_default_apm_processing));
|
||||
ASSERT_EQ(AudioProcessing::kNoError,
|
||||
apm->voice_detection()->Enable(include_default_apm_processing));
|
||||
ASSERT_EQ(AudioProcessing::kNoError,
|
||||
apm->level_estimator()->Enable(include_default_apm_processing));
|
||||
|
||||
StreamConfig stream_config(kSampleRate, kNumberOfChannels, false);
|
||||
|
||||
for (size_t frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) {
|
||||
buffers.UpdateInputBuffers();
|
||||
|
||||
total_timer.StartTimer();
|
||||
render_timer.StartTimer();
|
||||
ASSERT_EQ(
|
||||
AudioProcessing::kNoError,
|
||||
apm->ProcessReverseStream(&buffers.render_input[0], stream_config,
|
||||
stream_config, &buffers.render_output[0]));
|
||||
|
||||
render_timer.StopTimer();
|
||||
|
||||
capture_timer.StartTimer();
|
||||
ASSERT_EQ(AudioProcessing::kNoError, apm->set_stream_delay_ms(0));
|
||||
if (include_default_apm_processing) {
|
||||
apm->gain_control()->set_stream_analog_level(0);
|
||||
if (!use_mobile_aec) {
|
||||
apm->echo_cancellation()->set_stream_drift_samples(0);
|
||||
}
|
||||
}
|
||||
ASSERT_EQ(AudioProcessing::kNoError,
|
||||
apm->ProcessStream(&buffers.capture_input[0], stream_config,
|
||||
stream_config, &buffers.capture_output[0]));
|
||||
|
||||
capture_timer.StopTimer();
|
||||
total_timer.StopTimer();
|
||||
}
|
||||
|
||||
webrtc::test::PrintResultMeanAndError(
|
||||
"echo_detector_call_durations", "_render", test_description,
|
||||
FormPerformanceMeasureString(render_timer), "us", false);
|
||||
webrtc::test::PrintResultMeanAndError(
|
||||
"echo_detector_call_durations", "_capture", test_description,
|
||||
FormPerformanceMeasureString(capture_timer), "us", false);
|
||||
webrtc::test::PrintResultMeanAndError(
|
||||
"echo_detector_call_durations", "_total", test_description,
|
||||
FormPerformanceMeasureString(total_timer), "us", false);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(EchoDetectorPerformanceTest, StandaloneProcessing) {
|
||||
RunStandaloneSubmodule();
|
||||
}
|
||||
|
||||
TEST(EchoDetectorPerformanceTest, ProcessingViaApm) {
|
||||
RunTogetherWithApm("SimpleEchoDetectorViaApm", false, false);
|
||||
}
|
||||
|
||||
TEST(EchoDetectorPerformanceTest, InteractionWithDefaultApm) {
|
||||
RunTogetherWithApm("EchoDetectorAndDefaultDesktopApm", false, true);
|
||||
RunTogetherWithApm("EchoDetectorAndDefaultMobileApm", true, true);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
59
webrtc/modules/audio_processing/test/performance_timer.cc
Normal file
59
webrtc/modules/audio_processing/test/performance_timer.cc
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "webrtc/modules/audio_processing/test/performance_timer.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <numeric>
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
PerformanceTimer::PerformanceTimer(int num_frames_to_process)
|
||||
: clock_(webrtc::Clock::GetRealTimeClock()) {
|
||||
timestamps_us_.reserve(num_frames_to_process);
|
||||
}
|
||||
|
||||
PerformanceTimer::~PerformanceTimer() = default;
|
||||
|
||||
void PerformanceTimer::StartTimer() {
|
||||
start_timestamp_us_ = rtc::Optional<int64_t>(clock_->TimeInMicroseconds());
|
||||
}
|
||||
|
||||
void PerformanceTimer::StopTimer() {
|
||||
RTC_DCHECK(start_timestamp_us_);
|
||||
timestamps_us_.push_back(clock_->TimeInMicroseconds() - *start_timestamp_us_);
|
||||
}
|
||||
|
||||
double PerformanceTimer::GetDurationAverage() const {
|
||||
RTC_DCHECK(!timestamps_us_.empty());
|
||||
return static_cast<double>(
|
||||
std::accumulate(timestamps_us_.begin(), timestamps_us_.end(), 0)) /
|
||||
timestamps_us_.size();
|
||||
}
|
||||
|
||||
double PerformanceTimer::GetDurationStandardDeviation() const {
|
||||
RTC_DCHECK(!timestamps_us_.empty());
|
||||
double average_duration = GetDurationAverage();
|
||||
|
||||
double variance = std::accumulate(
|
||||
timestamps_us_.begin(), timestamps_us_.end(), 0.0,
|
||||
[average_duration](const double& a, const int64_t& b) {
|
||||
return a + (b - average_duration) * (b - average_duration);
|
||||
});
|
||||
|
||||
return sqrt(variance / timestamps_us_.size());
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
42
webrtc/modules/audio_processing/test/performance_timer.h
Normal file
42
webrtc/modules/audio_processing/test/performance_timer.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_TEST_PERFORMANCE_TIMER_H_
|
||||
#define WEBRTC_MODULES_AUDIO_PROCESSING_TEST_PERFORMANCE_TIMER_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "webrtc/base/optional.h"
|
||||
#include "webrtc/system_wrappers/include/clock.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
class PerformanceTimer {
|
||||
public:
|
||||
explicit PerformanceTimer(int num_frames_to_process);
|
||||
~PerformanceTimer();
|
||||
|
||||
void StartTimer();
|
||||
void StopTimer();
|
||||
|
||||
double GetDurationAverage() const;
|
||||
double GetDurationStandardDeviation() const;
|
||||
|
||||
private:
|
||||
webrtc::Clock* clock_;
|
||||
rtc::Optional<int64_t> start_timestamp_us_;
|
||||
std::vector<int64_t> timestamps_us_;
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_PERFORMANCE_TIMER_H_
|
||||
85
webrtc/modules/audio_processing/test/simulator_buffers.cc
Normal file
85
webrtc/modules/audio_processing/test/simulator_buffers.cc
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "webrtc/modules/audio_processing/test/simulator_buffers.h"
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
#include "webrtc/modules/audio_processing/test/audio_buffer_tools.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
SimulatorBuffers::SimulatorBuffers(int render_input_sample_rate_hz,
|
||||
int capture_input_sample_rate_hz,
|
||||
int render_output_sample_rate_hz,
|
||||
int capture_output_sample_rate_hz,
|
||||
size_t num_render_input_channels,
|
||||
size_t num_capture_input_channels,
|
||||
size_t num_render_output_channels,
|
||||
size_t num_capture_output_channels) {
|
||||
Random rand_gen(42);
|
||||
CreateConfigAndBuffer(render_input_sample_rate_hz, num_render_input_channels,
|
||||
&rand_gen, &render_input_buffer, &render_input_config,
|
||||
&render_input, &render_input_samples);
|
||||
|
||||
CreateConfigAndBuffer(render_output_sample_rate_hz,
|
||||
num_render_output_channels, &rand_gen,
|
||||
&render_output_buffer, &render_output_config,
|
||||
&render_output, &render_output_samples);
|
||||
|
||||
CreateConfigAndBuffer(capture_input_sample_rate_hz,
|
||||
num_capture_input_channels, &rand_gen,
|
||||
&capture_input_buffer, &capture_input_config,
|
||||
&capture_input, &capture_input_samples);
|
||||
|
||||
CreateConfigAndBuffer(capture_output_sample_rate_hz,
|
||||
num_capture_output_channels, &rand_gen,
|
||||
&capture_output_buffer, &capture_output_config,
|
||||
&capture_output, &capture_output_samples);
|
||||
|
||||
UpdateInputBuffers();
|
||||
}
|
||||
|
||||
SimulatorBuffers::~SimulatorBuffers() = default;
|
||||
|
||||
void SimulatorBuffers::CreateConfigAndBuffer(
|
||||
int sample_rate_hz,
|
||||
size_t num_channels,
|
||||
Random* rand_gen,
|
||||
std::unique_ptr<AudioBuffer>* buffer,
|
||||
StreamConfig* config,
|
||||
std::vector<float*>* buffer_data,
|
||||
std::vector<float>* buffer_data_samples) {
|
||||
int samples_per_channel = rtc::CheckedDivExact(sample_rate_hz, 100);
|
||||
*config = StreamConfig(sample_rate_hz, num_channels, false);
|
||||
buffer->reset(new AudioBuffer(config->num_frames(), config->num_channels(),
|
||||
config->num_frames(), config->num_channels(),
|
||||
config->num_frames()));
|
||||
|
||||
buffer_data_samples->resize(samples_per_channel * num_channels);
|
||||
for (auto& v : *buffer_data_samples) {
|
||||
v = rand_gen->Rand<float>();
|
||||
}
|
||||
|
||||
buffer_data->resize(num_channels);
|
||||
for (size_t ch = 0; ch < num_channels; ++ch) {
|
||||
(*buffer_data)[ch] = &(*buffer_data_samples)[ch * samples_per_channel];
|
||||
}
|
||||
}
|
||||
|
||||
void SimulatorBuffers::UpdateInputBuffers() {
|
||||
test::CopyVectorToAudioBuffer(capture_input_config, capture_input_samples,
|
||||
capture_input_buffer.get());
|
||||
test::CopyVectorToAudioBuffer(render_input_config, render_input_samples,
|
||||
render_input_buffer.get());
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
66
webrtc/modules/audio_processing/test/simulator_buffers.h
Normal file
66
webrtc/modules/audio_processing/test/simulator_buffers.h
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_TEST_SIMULATOR_BUFFERS_H_
|
||||
#define WEBRTC_MODULES_AUDIO_PROCESSING_TEST_SIMULATOR_BUFFERS_H_
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "webrtc/base/random.h"
|
||||
#include "webrtc/modules/audio_processing/audio_buffer.h"
|
||||
#include "webrtc/modules/audio_processing/include/audio_processing.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
struct SimulatorBuffers {
|
||||
SimulatorBuffers(int render_input_sample_rate_hz,
|
||||
int capture_input_sample_rate_hz,
|
||||
int render_output_sample_rate_hz,
|
||||
int capture_output_sample_rate_hz,
|
||||
size_t num_render_input_channels,
|
||||
size_t num_capture_input_channels,
|
||||
size_t num_render_output_channels,
|
||||
size_t num_capture_output_channels);
|
||||
~SimulatorBuffers();
|
||||
|
||||
void CreateConfigAndBuffer(int sample_rate_hz,
|
||||
size_t num_channels,
|
||||
Random* rand_gen,
|
||||
std::unique_ptr<AudioBuffer>* buffer,
|
||||
StreamConfig* config,
|
||||
std::vector<float*>* buffer_data,
|
||||
std::vector<float>* buffer_data_samples);
|
||||
|
||||
void UpdateInputBuffers();
|
||||
|
||||
std::unique_ptr<AudioBuffer> render_input_buffer;
|
||||
std::unique_ptr<AudioBuffer> capture_input_buffer;
|
||||
std::unique_ptr<AudioBuffer> render_output_buffer;
|
||||
std::unique_ptr<AudioBuffer> capture_output_buffer;
|
||||
StreamConfig render_input_config;
|
||||
StreamConfig capture_input_config;
|
||||
StreamConfig render_output_config;
|
||||
StreamConfig capture_output_config;
|
||||
std::vector<float*> render_input;
|
||||
std::vector<float> render_input_samples;
|
||||
std::vector<float*> capture_input;
|
||||
std::vector<float> capture_input_samples;
|
||||
std::vector<float*> render_output;
|
||||
std::vector<float> render_output_samples;
|
||||
std::vector<float*> capture_output;
|
||||
std::vector<float> capture_output_samples;
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_SIMULATOR_BUFFERS_H_
|
||||
Loading…
x
Reference in New Issue
Block a user