APM: Replace all remaining usage of AudioFrame outside interfaces
This CL replaces all remaining usage of AudioFrame within APM, with the exception of the AudioProcessing interface. The main changes are within the unittests. Bug: webrtc:5298 Change-Id: I219cdd08f81a8679b28d9dd1359a56837945f3d4 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/170362 Reviewed-by: Sam Zackrisson <saza@webrtc.org> Commit-Queue: Per Åhgren <peah@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30831}
This commit is contained in:
@ -19,6 +19,7 @@
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "common_audio/channel_buffer.h"
|
||||
#include "common_audio/include/audio_util.h"
|
||||
#include "modules/audio_processing/include/audio_processing.h"
|
||||
#include "modules/audio_processing/test/api_call_statistics.h"
|
||||
#include "modules/audio_processing/test/fake_recording_device.h"
|
||||
@ -30,6 +31,50 @@
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
static const int kChunksPerSecond = 1000 / AudioProcessing::kChunkSizeMs;
|
||||
|
||||
struct Int16Frame {
|
||||
void SetFormat(int sample_rate_hz, int num_channels) {
|
||||
this->sample_rate_hz = sample_rate_hz;
|
||||
samples_per_channel =
|
||||
rtc::CheckedDivExact(sample_rate_hz, kChunksPerSecond);
|
||||
this->num_channels = num_channels;
|
||||
config = StreamConfig(sample_rate_hz, num_channels, /*has_keyboard=*/false);
|
||||
}
|
||||
|
||||
void CopyTo(ChannelBuffer<float>* dest) {
|
||||
RTC_DCHECK(dest);
|
||||
RTC_CHECK_EQ(num_channels, dest->num_channels());
|
||||
RTC_CHECK_EQ(samples_per_channel, dest->num_frames());
|
||||
// Copy the data from the input buffer.
|
||||
std::vector<float> tmp(samples_per_channel * num_channels);
|
||||
S16ToFloat(data.data(), tmp.size(), tmp.data());
|
||||
Deinterleave(tmp.data(), samples_per_channel, num_channels,
|
||||
dest->channels());
|
||||
}
|
||||
|
||||
void CopyFrom(const ChannelBuffer<float>& src) {
|
||||
RTC_CHECK_EQ(src.num_channels(), num_channels);
|
||||
RTC_CHECK_EQ(src.num_frames(), samples_per_channel);
|
||||
data.resize(num_channels * samples_per_channel);
|
||||
int16_t* dest_data = data.data();
|
||||
for (int ch = 0; ch < num_channels; ++ch) {
|
||||
for (int sample = 0; sample < samples_per_channel; ++sample) {
|
||||
dest_data[sample * num_channels + ch] =
|
||||
src.channels()[ch][sample] * 32767;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int sample_rate_hz;
|
||||
int samples_per_channel;
|
||||
int num_channels;
|
||||
|
||||
StreamConfig config;
|
||||
|
||||
std::vector<int16_t> data;
|
||||
};
|
||||
|
||||
// Holds all the parameters available for controlling the simulation.
|
||||
struct SimulationSettings {
|
||||
SimulationSettings();
|
||||
@ -101,13 +146,9 @@ struct SimulationSettings {
|
||||
std::vector<float>* processed_capture_samples = nullptr;
|
||||
};
|
||||
|
||||
// Copies samples present in a ChannelBuffer into an AudioFrame.
|
||||
void CopyToAudioFrame(const ChannelBuffer<float>& src, AudioFrame* dest);
|
||||
|
||||
// Provides common functionality for performing audioprocessing simulations.
|
||||
class AudioProcessingSimulator {
|
||||
public:
|
||||
static const int kChunksPerSecond = 1000 / AudioProcessing::kChunkSizeMs;
|
||||
|
||||
AudioProcessingSimulator(const SimulationSettings& settings,
|
||||
std::unique_ptr<AudioProcessingBuilder> ap_builder);
|
||||
@ -158,8 +199,8 @@ class AudioProcessingSimulator {
|
||||
StreamConfig reverse_out_config_;
|
||||
std::unique_ptr<ChannelBufferWavReader> buffer_reader_;
|
||||
std::unique_ptr<ChannelBufferWavReader> reverse_buffer_reader_;
|
||||
AudioFrame rev_frame_;
|
||||
AudioFrame fwd_frame_;
|
||||
Int16Frame rev_frame_;
|
||||
Int16Frame fwd_frame_;
|
||||
bool bitexact_output_ = true;
|
||||
int aec_dump_mic_level_ = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user