2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-05-02 23:56:37 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-28 08:11:59 +00:00
|
|
|
#include "webrtc/modules/audio_processing/audio_buffer.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2014-04-22 21:00:04 +00:00
|
|
|
#include "webrtc/common_audio/resampler/push_sinc_resampler.h"
|
2013-05-28 08:11:59 +00:00
|
|
|
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
2014-11-26 20:21:38 +00:00
|
|
|
#include "webrtc/modules/audio_processing/channel_buffer.h"
|
2014-11-27 23:40:25 +00:00
|
|
|
#include "webrtc/modules/audio_processing/common.h"
|
2011-11-15 16:57:56 +00:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
namespace webrtc {
|
|
|
|
|
namespace {
|
|
|
|
|
|
2014-04-24 18:28:56 +00:00
|
|
|
bool HasKeyboardChannel(AudioProcessing::ChannelLayout layout) {
|
|
|
|
|
switch (layout) {
|
|
|
|
|
case AudioProcessing::kMono:
|
|
|
|
|
case AudioProcessing::kStereo:
|
|
|
|
|
return false;
|
|
|
|
|
case AudioProcessing::kMonoAndKeyboard:
|
|
|
|
|
case AudioProcessing::kStereoAndKeyboard:
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
assert(false);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int KeyboardChannelIndex(AudioProcessing::ChannelLayout layout) {
|
|
|
|
|
switch (layout) {
|
|
|
|
|
case AudioProcessing::kMono:
|
|
|
|
|
case AudioProcessing::kStereo:
|
|
|
|
|
assert(false);
|
|
|
|
|
return -1;
|
|
|
|
|
case AudioProcessing::kMonoAndKeyboard:
|
|
|
|
|
return 1;
|
|
|
|
|
case AudioProcessing::kStereoAndKeyboard:
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
assert(false);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 04:58:14 +00:00
|
|
|
template <typename T>
|
|
|
|
|
void StereoToMono(const T* left, const T* right, T* out,
|
2014-04-22 21:00:04 +00:00
|
|
|
int samples_per_channel) {
|
2014-10-31 04:58:14 +00:00
|
|
|
for (int i = 0; i < samples_per_channel; ++i)
|
2014-04-22 21:00:04 +00:00
|
|
|
out[i] = (left[i] + right[i]) / 2;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2014-04-22 21:00:04 +00:00
|
|
|
} // namespace
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2014-04-22 21:00:04 +00:00
|
|
|
AudioBuffer::AudioBuffer(int input_samples_per_channel,
|
|
|
|
|
int num_input_channels,
|
|
|
|
|
int process_samples_per_channel,
|
|
|
|
|
int num_process_channels,
|
|
|
|
|
int output_samples_per_channel)
|
|
|
|
|
: input_samples_per_channel_(input_samples_per_channel),
|
|
|
|
|
num_input_channels_(num_input_channels),
|
|
|
|
|
proc_samples_per_channel_(process_samples_per_channel),
|
|
|
|
|
num_proc_channels_(num_process_channels),
|
|
|
|
|
output_samples_per_channel_(output_samples_per_channel),
|
|
|
|
|
samples_per_split_channel_(proc_samples_per_channel_),
|
2014-07-17 08:27:39 +00:00
|
|
|
mixed_low_pass_valid_(false),
|
2011-09-19 15:28:51 +00:00
|
|
|
reference_copied_(false),
|
|
|
|
|
activity_(AudioFrame::kVadUnknown),
|
2014-04-24 18:28:56 +00:00
|
|
|
keyboard_data_(NULL),
|
2014-05-15 11:17:21 +00:00
|
|
|
channels_(new IFChannelBuffer(proc_samples_per_channel_,
|
|
|
|
|
num_proc_channels_)) {
|
2014-04-22 21:00:04 +00:00
|
|
|
assert(input_samples_per_channel_ > 0);
|
|
|
|
|
assert(proc_samples_per_channel_ > 0);
|
|
|
|
|
assert(output_samples_per_channel_ > 0);
|
|
|
|
|
assert(num_input_channels_ > 0 && num_input_channels_ <= 2);
|
|
|
|
|
assert(num_proc_channels_ <= num_input_channels);
|
|
|
|
|
|
|
|
|
|
if (num_input_channels_ == 2 && num_proc_channels_ == 1) {
|
|
|
|
|
input_buffer_.reset(new ChannelBuffer<float>(input_samples_per_channel_,
|
|
|
|
|
num_proc_channels_));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (input_samples_per_channel_ != proc_samples_per_channel_ ||
|
|
|
|
|
output_samples_per_channel_ != proc_samples_per_channel_) {
|
|
|
|
|
// Create an intermediate buffer for resampling.
|
|
|
|
|
process_buffer_.reset(new ChannelBuffer<float>(proc_samples_per_channel_,
|
|
|
|
|
num_proc_channels_));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (input_samples_per_channel_ != proc_samples_per_channel_) {
|
|
|
|
|
input_resamplers_.reserve(num_proc_channels_);
|
|
|
|
|
for (int i = 0; i < num_proc_channels_; ++i) {
|
|
|
|
|
input_resamplers_.push_back(
|
|
|
|
|
new PushSincResampler(input_samples_per_channel_,
|
|
|
|
|
proc_samples_per_channel_));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (output_samples_per_channel_ != proc_samples_per_channel_) {
|
|
|
|
|
output_resamplers_.reserve(num_proc_channels_);
|
|
|
|
|
for (int i = 0; i < num_proc_channels_; ++i) {
|
|
|
|
|
output_resamplers_.push_back(
|
|
|
|
|
new PushSincResampler(proc_samples_per_channel_,
|
|
|
|
|
output_samples_per_channel_));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-17 23:01:23 +00:00
|
|
|
if (proc_samples_per_channel_ == kSamplesPer32kHzChannel ||
|
|
|
|
|
proc_samples_per_channel_ == kSamplesPer48kHzChannel) {
|
2011-07-07 08:21:25 +00:00
|
|
|
samples_per_split_channel_ = kSamplesPer16kHzChannel;
|
2014-11-26 20:21:38 +00:00
|
|
|
split_channels_.push_back(new IFChannelBuffer(samples_per_split_channel_,
|
|
|
|
|
num_proc_channels_));
|
|
|
|
|
split_channels_.push_back(new IFChannelBuffer(samples_per_split_channel_,
|
2014-07-17 09:46:37 +00:00
|
|
|
num_proc_channels_));
|
2014-11-14 22:18:10 +00:00
|
|
|
splitting_filter_.reset(new SplittingFilter(num_proc_channels_));
|
2014-11-17 23:01:23 +00:00
|
|
|
if (proc_samples_per_channel_ == kSamplesPer48kHzChannel) {
|
2014-11-26 20:21:38 +00:00
|
|
|
split_channels_.push_back(new IFChannelBuffer(samples_per_split_channel_,
|
|
|
|
|
num_proc_channels_));
|
2014-11-17 23:01:23 +00:00
|
|
|
}
|
2014-04-22 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-24 18:28:56 +00:00
|
|
|
AudioBuffer::~AudioBuffer() {}
|
|
|
|
|
|
2014-04-22 21:00:04 +00:00
|
|
|
void AudioBuffer::CopyFrom(const float* const* data,
|
|
|
|
|
int samples_per_channel,
|
|
|
|
|
AudioProcessing::ChannelLayout layout) {
|
|
|
|
|
assert(samples_per_channel == input_samples_per_channel_);
|
|
|
|
|
assert(ChannelsFromLayout(layout) == num_input_channels_);
|
|
|
|
|
InitForNewData();
|
|
|
|
|
|
2014-04-24 18:28:56 +00:00
|
|
|
if (HasKeyboardChannel(layout)) {
|
|
|
|
|
keyboard_data_ = data[KeyboardChannelIndex(layout)];
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-22 21:00:04 +00:00
|
|
|
// Downmix.
|
|
|
|
|
const float* const* data_ptr = data;
|
|
|
|
|
if (num_input_channels_ == 2 && num_proc_channels_ == 1) {
|
|
|
|
|
StereoToMono(data[0],
|
|
|
|
|
data[1],
|
|
|
|
|
input_buffer_->channel(0),
|
|
|
|
|
input_samples_per_channel_);
|
|
|
|
|
data_ptr = input_buffer_->channels();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Resample.
|
|
|
|
|
if (input_samples_per_channel_ != proc_samples_per_channel_) {
|
|
|
|
|
for (int i = 0; i < num_proc_channels_; ++i) {
|
|
|
|
|
input_resamplers_[i]->Resample(data_ptr[i],
|
|
|
|
|
input_samples_per_channel_,
|
|
|
|
|
process_buffer_->channel(i),
|
|
|
|
|
proc_samples_per_channel_);
|
|
|
|
|
}
|
|
|
|
|
data_ptr = process_buffer_->channels();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 04:58:14 +00:00
|
|
|
// Convert to the S16 range.
|
2014-04-22 21:00:04 +00:00
|
|
|
for (int i = 0; i < num_proc_channels_; ++i) {
|
2014-10-31 04:58:14 +00:00
|
|
|
FloatToFloatS16(data_ptr[i], proc_samples_per_channel_,
|
|
|
|
|
channels_->fbuf()->channel(i));
|
2014-04-22 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioBuffer::CopyTo(int samples_per_channel,
|
|
|
|
|
AudioProcessing::ChannelLayout layout,
|
|
|
|
|
float* const* data) {
|
|
|
|
|
assert(samples_per_channel == output_samples_per_channel_);
|
|
|
|
|
assert(ChannelsFromLayout(layout) == num_proc_channels_);
|
|
|
|
|
|
2014-10-31 04:58:14 +00:00
|
|
|
// Convert to the float range.
|
2014-04-22 21:00:04 +00:00
|
|
|
float* const* data_ptr = data;
|
|
|
|
|
if (output_samples_per_channel_ != proc_samples_per_channel_) {
|
|
|
|
|
// Convert to an intermediate buffer for subsequent resampling.
|
|
|
|
|
data_ptr = process_buffer_->channels();
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < num_proc_channels_; ++i) {
|
2014-10-31 04:58:14 +00:00
|
|
|
FloatS16ToFloat(channels_->fbuf()->channel(i), proc_samples_per_channel_,
|
|
|
|
|
data_ptr[i]);
|
2014-04-22 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Resample.
|
|
|
|
|
if (output_samples_per_channel_ != proc_samples_per_channel_) {
|
|
|
|
|
for (int i = 0; i < num_proc_channels_; ++i) {
|
|
|
|
|
output_resamplers_[i]->Resample(data_ptr[i],
|
|
|
|
|
proc_samples_per_channel_,
|
|
|
|
|
data[i],
|
|
|
|
|
output_samples_per_channel_);
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-22 21:00:04 +00:00
|
|
|
void AudioBuffer::InitForNewData() {
|
2014-04-24 18:28:56 +00:00
|
|
|
keyboard_data_ = NULL;
|
2014-07-17 08:27:39 +00:00
|
|
|
mixed_low_pass_valid_ = false;
|
2014-03-04 20:58:13 +00:00
|
|
|
reference_copied_ = false;
|
|
|
|
|
activity_ = AudioFrame::kVadUnknown;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-30 16:44:13 +00:00
|
|
|
const int16_t* AudioBuffer::data(int channel) const {
|
2014-07-18 07:50:29 +00:00
|
|
|
return channels_->ibuf_const()->channel(channel);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-30 16:44:13 +00:00
|
|
|
int16_t* AudioBuffer::data(int channel) {
|
2014-07-17 08:27:39 +00:00
|
|
|
mixed_low_pass_valid_ = false;
|
2014-07-18 07:50:29 +00:00
|
|
|
return channels_->ibuf()->channel(channel);
|
2014-04-30 16:44:13 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-14 22:18:10 +00:00
|
|
|
const int16_t* const* AudioBuffer::channels() const {
|
|
|
|
|
return channels_->ibuf_const()->channels();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int16_t* const* AudioBuffer::channels() {
|
|
|
|
|
mixed_low_pass_valid_ = false;
|
|
|
|
|
return channels_->ibuf()->channels();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-03 09:47:33 +00:00
|
|
|
const float* AudioBuffer::data_f(int channel) const {
|
2014-07-18 07:50:29 +00:00
|
|
|
return channels_->fbuf_const()->channel(channel);
|
2014-05-15 11:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-03 09:47:33 +00:00
|
|
|
float* AudioBuffer::data_f(int channel) {
|
2014-07-17 08:27:39 +00:00
|
|
|
mixed_low_pass_valid_ = false;
|
2014-07-18 07:50:29 +00:00
|
|
|
return channels_->fbuf()->channel(channel);
|
2014-07-03 09:47:33 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-25 20:52:08 +00:00
|
|
|
const float* const* AudioBuffer::channels_f() const {
|
|
|
|
|
return channels_->fbuf_const()->channels();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float* const* AudioBuffer::channels_f() {
|
|
|
|
|
mixed_low_pass_valid_ = false;
|
|
|
|
|
return channels_->fbuf()->channels();
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-30 16:44:13 +00:00
|
|
|
const int16_t* AudioBuffer::low_pass_split_data(int channel) const {
|
2014-11-26 20:21:38 +00:00
|
|
|
return split_channels_.size() > 0
|
|
|
|
|
? split_channels_[0]->ibuf_const()->channel(channel)
|
2014-07-17 09:46:37 +00:00
|
|
|
: data(channel);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-30 16:44:13 +00:00
|
|
|
int16_t* AudioBuffer::low_pass_split_data(int channel) {
|
2014-07-17 08:27:39 +00:00
|
|
|
mixed_low_pass_valid_ = false;
|
2014-11-26 20:21:38 +00:00
|
|
|
return split_channels_.size() > 0
|
|
|
|
|
? split_channels_[0]->ibuf()->channel(channel)
|
2014-07-18 07:50:29 +00:00
|
|
|
: data(channel);
|
2014-04-30 16:44:13 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-14 22:18:10 +00:00
|
|
|
const int16_t* const* AudioBuffer::low_pass_split_channels() const {
|
2014-11-26 20:21:38 +00:00
|
|
|
return split_channels_.size() > 0
|
|
|
|
|
? split_channels_[0]->ibuf_const()->channels()
|
2014-11-14 22:18:10 +00:00
|
|
|
: channels();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int16_t* const* AudioBuffer::low_pass_split_channels() {
|
|
|
|
|
mixed_low_pass_valid_ = false;
|
2014-11-26 20:21:38 +00:00
|
|
|
return split_channels_.size() > 0 ? split_channels_[0]->ibuf()->channels()
|
2014-11-14 22:18:10 +00:00
|
|
|
: channels();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-03 09:47:33 +00:00
|
|
|
const float* AudioBuffer::low_pass_split_data_f(int channel) const {
|
2014-11-26 20:21:38 +00:00
|
|
|
return split_channels_.size() > 0
|
|
|
|
|
? split_channels_[0]->fbuf_const()->channel(channel)
|
2014-07-17 09:46:37 +00:00
|
|
|
: data_f(channel);
|
2014-05-15 11:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-03 09:47:33 +00:00
|
|
|
float* AudioBuffer::low_pass_split_data_f(int channel) {
|
2014-07-17 08:27:39 +00:00
|
|
|
mixed_low_pass_valid_ = false;
|
2014-11-26 20:21:38 +00:00
|
|
|
return split_channels_.size() > 0
|
|
|
|
|
? split_channels_[0]->fbuf()->channel(channel)
|
2014-07-18 07:50:29 +00:00
|
|
|
: data_f(channel);
|
2014-07-03 09:47:33 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-25 20:52:08 +00:00
|
|
|
const float* const* AudioBuffer::low_pass_split_channels_f() const {
|
2014-11-26 20:21:38 +00:00
|
|
|
return split_channels_.size() > 0
|
|
|
|
|
? split_channels_[0]->fbuf_const()->channels()
|
2014-09-25 20:52:08 +00:00
|
|
|
: channels_f();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float* const* AudioBuffer::low_pass_split_channels_f() {
|
|
|
|
|
mixed_low_pass_valid_ = false;
|
2014-11-26 20:21:38 +00:00
|
|
|
return split_channels_.size() > 0
|
|
|
|
|
? split_channels_[0]->fbuf()->channels()
|
2014-09-25 20:52:08 +00:00
|
|
|
: channels_f();
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-30 16:44:13 +00:00
|
|
|
const int16_t* AudioBuffer::high_pass_split_data(int channel) const {
|
2014-11-26 20:21:38 +00:00
|
|
|
return split_channels_.size() > 1
|
|
|
|
|
? split_channels_[1]->ibuf_const()->channel(channel)
|
2014-07-17 09:46:37 +00:00
|
|
|
: NULL;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-30 16:44:13 +00:00
|
|
|
int16_t* AudioBuffer::high_pass_split_data(int channel) {
|
2014-11-26 20:21:38 +00:00
|
|
|
return split_channels_.size() > 1
|
|
|
|
|
? split_channels_[1]->ibuf()->channel(channel)
|
2014-07-18 07:50:29 +00:00
|
|
|
: NULL;
|
2014-04-30 16:44:13 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-14 22:18:10 +00:00
|
|
|
const int16_t* const* AudioBuffer::high_pass_split_channels() const {
|
2014-11-26 20:21:38 +00:00
|
|
|
return split_channels_.size() > 1
|
|
|
|
|
? split_channels_[1]->ibuf_const()->channels()
|
2014-11-14 22:18:10 +00:00
|
|
|
: NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int16_t* const* AudioBuffer::high_pass_split_channels() {
|
2014-11-26 20:21:38 +00:00
|
|
|
return split_channels_.size() > 1 ? split_channels_[1]->ibuf()->channels()
|
2014-11-14 22:18:10 +00:00
|
|
|
: NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-03 09:47:33 +00:00
|
|
|
const float* AudioBuffer::high_pass_split_data_f(int channel) const {
|
2014-11-26 20:21:38 +00:00
|
|
|
return split_channels_.size() > 1
|
|
|
|
|
? split_channels_[1]->fbuf_const()->channel(channel)
|
2014-07-17 09:46:37 +00:00
|
|
|
: NULL;
|
2014-05-15 11:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-03 09:47:33 +00:00
|
|
|
float* AudioBuffer::high_pass_split_data_f(int channel) {
|
2014-11-26 20:21:38 +00:00
|
|
|
return split_channels_.size() > 1
|
|
|
|
|
? split_channels_[1]->fbuf()->channel(channel)
|
2014-07-18 07:50:29 +00:00
|
|
|
: NULL;
|
2014-07-03 09:47:33 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-25 20:52:08 +00:00
|
|
|
const float* const* AudioBuffer::high_pass_split_channels_f() const {
|
2014-11-26 20:21:38 +00:00
|
|
|
return split_channels_.size() > 1
|
|
|
|
|
? split_channels_[1]->fbuf_const()->channels()
|
2014-09-25 20:52:08 +00:00
|
|
|
: NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float* const* AudioBuffer::high_pass_split_channels_f() {
|
2014-11-26 20:21:38 +00:00
|
|
|
return split_channels_.size() > 1
|
|
|
|
|
? split_channels_[1]->fbuf()->channels()
|
2014-09-25 20:52:08 +00:00
|
|
|
: NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-17 23:01:23 +00:00
|
|
|
const float* const* AudioBuffer::super_high_pass_split_channels_f() const {
|
2014-11-26 20:21:38 +00:00
|
|
|
return split_channels_.size() > 2
|
|
|
|
|
? split_channels_[2]->fbuf_const()->channels()
|
2014-11-17 23:01:23 +00:00
|
|
|
: NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float* const* AudioBuffer::super_high_pass_split_channels_f() {
|
2014-11-26 20:21:38 +00:00
|
|
|
return split_channels_.size() > 2
|
|
|
|
|
? split_channels_[2]->fbuf()->channels()
|
2014-11-17 23:01:23 +00:00
|
|
|
: NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-17 08:27:39 +00:00
|
|
|
const int16_t* AudioBuffer::mixed_low_pass_data() {
|
|
|
|
|
// Currently only mixing stereo to mono is supported.
|
|
|
|
|
assert(num_proc_channels_ == 1 || num_proc_channels_ == 2);
|
2011-11-15 16:57:56 +00:00
|
|
|
|
2014-07-17 08:27:39 +00:00
|
|
|
if (num_proc_channels_ == 1) {
|
|
|
|
|
return low_pass_split_data(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!mixed_low_pass_valid_) {
|
|
|
|
|
if (!mixed_low_pass_channels_.get()) {
|
|
|
|
|
mixed_low_pass_channels_.reset(
|
|
|
|
|
new ChannelBuffer<int16_t>(samples_per_split_channel_, 1));
|
|
|
|
|
}
|
|
|
|
|
StereoToMono(low_pass_split_data(0),
|
|
|
|
|
low_pass_split_data(1),
|
|
|
|
|
mixed_low_pass_channels_->data(),
|
|
|
|
|
samples_per_split_channel_);
|
|
|
|
|
mixed_low_pass_valid_ = true;
|
|
|
|
|
}
|
|
|
|
|
return mixed_low_pass_channels_->data();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-30 16:44:13 +00:00
|
|
|
const int16_t* AudioBuffer::low_pass_reference(int channel) const {
|
2011-07-07 08:21:25 +00:00
|
|
|
if (!reference_copied_) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-22 21:00:04 +00:00
|
|
|
return low_pass_reference_channels_->channel(channel);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-24 18:28:56 +00:00
|
|
|
const float* AudioBuffer::keyboard_data() const {
|
|
|
|
|
return keyboard_data_;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-19 15:28:51 +00:00
|
|
|
void AudioBuffer::set_activity(AudioFrame::VADActivity activity) {
|
|
|
|
|
activity_ = activity;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:57:56 +00:00
|
|
|
AudioFrame::VADActivity AudioBuffer::activity() const {
|
2011-09-19 15:28:51 +00:00
|
|
|
return activity_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioBuffer::num_channels() const {
|
2014-04-22 21:00:04 +00:00
|
|
|
return num_proc_channels_;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-19 15:28:51 +00:00
|
|
|
int AudioBuffer::samples_per_channel() const {
|
2014-04-22 21:00:04 +00:00
|
|
|
return proc_samples_per_channel_;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-19 15:28:51 +00:00
|
|
|
int AudioBuffer::samples_per_split_channel() const {
|
2011-07-07 08:21:25 +00:00
|
|
|
return samples_per_split_channel_;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-24 18:28:56 +00:00
|
|
|
int AudioBuffer::samples_per_keyboard_channel() const {
|
|
|
|
|
// We don't resample the keyboard channel.
|
|
|
|
|
return input_samples_per_channel_;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-19 15:28:51 +00:00
|
|
|
// TODO(andrew): Do deinterleaving and mixing in one step?
|
|
|
|
|
void AudioBuffer::DeinterleaveFrom(AudioFrame* frame) {
|
2014-04-22 21:00:04 +00:00
|
|
|
assert(proc_samples_per_channel_ == input_samples_per_channel_);
|
Enable render downmixing to mono in AudioProcessing.
In practice, we have been doing this since time immemorial, but have
relied on the user to do the downmixing (first voice engine then
Chromium). It's more logical for this burden to fall on AudioProcessing,
however, who can be expected to know that this is a reasonable approach
for AEC. Permitting two render channels results in running two AECs
serially.
Critically, in my recent change to have Chromium adopt the float
interface:
https://codereview.chromium.org/420603004
I removed the downmixing by Chromium, forgetting that we hadn't yet
enabled this feature in AudioProcessing. This corrects that oversight.
The change in paths hit by production users is very minor. As commented
it required adding downmixing to the int16_t path to satisfy
bit-exactness tests.
For reference, find the ApmTest.Process errors here:
https://paste.googleplex.com/6372007910309888
BUG=webrtc:3853
TESTED=listened to the files output from the Process test, and verified
that they sound as expected: higher echo while the AEC is adapting, but
afterwards very close.
R=aluebs@webrtc.org, bjornv@webrtc.org, kwiberg@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/31459004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7292 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-09-24 20:06:23 +00:00
|
|
|
assert(frame->num_channels_ == num_input_channels_);
|
2014-04-22 21:00:04 +00:00
|
|
|
assert(frame->samples_per_channel_ == proc_samples_per_channel_);
|
|
|
|
|
InitForNewData();
|
2012-05-02 23:56:37 +00:00
|
|
|
activity_ = frame->vad_activity_;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
Enable render downmixing to mono in AudioProcessing.
In practice, we have been doing this since time immemorial, but have
relied on the user to do the downmixing (first voice engine then
Chromium). It's more logical for this burden to fall on AudioProcessing,
however, who can be expected to know that this is a reasonable approach
for AEC. Permitting two render channels results in running two AECs
serially.
Critically, in my recent change to have Chromium adopt the float
interface:
https://codereview.chromium.org/420603004
I removed the downmixing by Chromium, forgetting that we hadn't yet
enabled this feature in AudioProcessing. This corrects that oversight.
The change in paths hit by production users is very minor. As commented
it required adding downmixing to the int16_t path to satisfy
bit-exactness tests.
For reference, find the ApmTest.Process errors here:
https://paste.googleplex.com/6372007910309888
BUG=webrtc:3853
TESTED=listened to the files output from the Process test, and verified
that they sound as expected: higher echo while the AEC is adapting, but
afterwards very close.
R=aluebs@webrtc.org, bjornv@webrtc.org, kwiberg@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/31459004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7292 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-09-24 20:06:23 +00:00
|
|
|
if (num_input_channels_ == 2 && num_proc_channels_ == 1) {
|
|
|
|
|
// Downmix directly; no explicit deinterleaving needed.
|
|
|
|
|
int16_t* downmixed = channels_->ibuf()->channel(0);
|
|
|
|
|
for (int i = 0; i < input_samples_per_channel_; ++i) {
|
2014-10-31 04:58:14 +00:00
|
|
|
downmixed[i] = (frame->data_[i * 2] + frame->data_[i * 2 + 1]) / 2;
|
Enable render downmixing to mono in AudioProcessing.
In practice, we have been doing this since time immemorial, but have
relied on the user to do the downmixing (first voice engine then
Chromium). It's more logical for this burden to fall on AudioProcessing,
however, who can be expected to know that this is a reasonable approach
for AEC. Permitting two render channels results in running two AECs
serially.
Critically, in my recent change to have Chromium adopt the float
interface:
https://codereview.chromium.org/420603004
I removed the downmixing by Chromium, forgetting that we hadn't yet
enabled this feature in AudioProcessing. This corrects that oversight.
The change in paths hit by production users is very minor. As commented
it required adding downmixing to the int16_t path to satisfy
bit-exactness tests.
For reference, find the ApmTest.Process errors here:
https://paste.googleplex.com/6372007910309888
BUG=webrtc:3853
TESTED=listened to the files output from the Process test, and verified
that they sound as expected: higher echo while the AEC is adapting, but
afterwards very close.
R=aluebs@webrtc.org, bjornv@webrtc.org, kwiberg@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/31459004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7292 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-09-24 20:06:23 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
assert(num_proc_channels_ == num_input_channels_);
|
|
|
|
|
int16_t* interleaved = frame->data_;
|
|
|
|
|
for (int i = 0; i < num_proc_channels_; ++i) {
|
|
|
|
|
int16_t* deinterleaved = channels_->ibuf()->channel(i);
|
|
|
|
|
int interleaved_idx = i;
|
|
|
|
|
for (int j = 0; j < proc_samples_per_channel_; ++j) {
|
|
|
|
|
deinterleaved[j] = interleaved[interleaved_idx];
|
|
|
|
|
interleaved_idx += num_proc_channels_;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:57:56 +00:00
|
|
|
void AudioBuffer::InterleaveTo(AudioFrame* frame, bool data_changed) const {
|
2014-04-22 21:00:04 +00:00
|
|
|
assert(proc_samples_per_channel_ == output_samples_per_channel_);
|
|
|
|
|
assert(num_proc_channels_ == num_input_channels_);
|
|
|
|
|
assert(frame->num_channels_ == num_proc_channels_);
|
|
|
|
|
assert(frame->samples_per_channel_ == proc_samples_per_channel_);
|
2012-05-02 23:56:37 +00:00
|
|
|
frame->vad_activity_ = activity_;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-11-15 16:57:56 +00:00
|
|
|
if (!data_changed) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-02 23:56:37 +00:00
|
|
|
int16_t* interleaved = frame->data_;
|
2014-04-22 21:00:04 +00:00
|
|
|
for (int i = 0; i < num_proc_channels_; i++) {
|
2014-05-15 11:17:21 +00:00
|
|
|
int16_t* deinterleaved = channels_->ibuf()->channel(i);
|
2011-09-19 15:28:51 +00:00
|
|
|
int interleaved_idx = i;
|
2014-04-22 21:00:04 +00:00
|
|
|
for (int j = 0; j < proc_samples_per_channel_; j++) {
|
2011-07-07 08:21:25 +00:00
|
|
|
interleaved[interleaved_idx] = deinterleaved[j];
|
2014-04-22 21:00:04 +00:00
|
|
|
interleaved_idx += num_proc_channels_;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioBuffer::CopyLowPassToReference() {
|
|
|
|
|
reference_copied_ = true;
|
2014-04-22 21:00:04 +00:00
|
|
|
if (!low_pass_reference_channels_.get()) {
|
|
|
|
|
low_pass_reference_channels_.reset(
|
|
|
|
|
new ChannelBuffer<int16_t>(samples_per_split_channel_,
|
|
|
|
|
num_proc_channels_));
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < num_proc_channels_; i++) {
|
|
|
|
|
low_pass_reference_channels_->CopyFrom(low_pass_split_data(i), i);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
2014-04-22 21:00:04 +00:00
|
|
|
|
2014-11-14 22:18:10 +00:00
|
|
|
void AudioBuffer::SplitIntoFrequencyBands() {
|
2014-11-26 20:21:38 +00:00
|
|
|
splitting_filter_->Analysis(channels_.get(),
|
|
|
|
|
split_channels_.get());
|
2014-11-14 22:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioBuffer::MergeFrequencyBands() {
|
2014-11-26 20:21:38 +00:00
|
|
|
splitting_filter_->Synthesis(split_channels_.get(),
|
|
|
|
|
channels_.get());
|
2014-11-14 22:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
} // namespace webrtc
|