Bump to WebRTC M131 release
Ongoing fixes and improvements, transient suppressor is gone. Also, dropping isac because it doesn't seem to be useful, and is just build system deadweight now. Upstream references: Version: 131.0.6778.200 WebRTC: 79aff54b0fa9238ce3518dd9eaf9610cd6f22e82 Chromium: 2a19506ad24af755f2a215a4c61f775393e0db42
This commit is contained in:
@ -15,105 +15,109 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "api/audio/audio_frame.h"
|
||||
#include "common_audio/include/audio_util.h"
|
||||
#include "common_audio/resampler/push_sinc_resampler.h"
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
template <typename T>
|
||||
PushResampler<T>::PushResampler()
|
||||
: src_sample_rate_hz_(0), dst_sample_rate_hz_(0), num_channels_(0) {}
|
||||
namespace {
|
||||
// Maximum concurrent number of channels for `PushResampler<>`.
|
||||
// Note that this may be different from what the maximum is for audio codecs.
|
||||
constexpr int kMaxNumberOfChannels = 8;
|
||||
} // namespace
|
||||
|
||||
template <typename T>
|
||||
PushResampler<T>::~PushResampler() {}
|
||||
PushResampler<T>::PushResampler() = default;
|
||||
|
||||
template <typename T>
|
||||
int PushResampler<T>::InitializeIfNeeded(int src_sample_rate_hz,
|
||||
int dst_sample_rate_hz,
|
||||
size_t num_channels) {
|
||||
// These checks used to be factored out of this template function due to
|
||||
// Windows debug build issues with clang. http://crbug.com/615050
|
||||
RTC_DCHECK_GT(src_sample_rate_hz, 0);
|
||||
RTC_DCHECK_GT(dst_sample_rate_hz, 0);
|
||||
RTC_DCHECK_GT(num_channels, 0);
|
||||
|
||||
if (src_sample_rate_hz == src_sample_rate_hz_ &&
|
||||
dst_sample_rate_hz == dst_sample_rate_hz_ &&
|
||||
num_channels == num_channels_) {
|
||||
// No-op if settings haven't changed.
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (src_sample_rate_hz <= 0 || dst_sample_rate_hz <= 0 || num_channels <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
src_sample_rate_hz_ = src_sample_rate_hz;
|
||||
dst_sample_rate_hz_ = dst_sample_rate_hz;
|
||||
num_channels_ = num_channels;
|
||||
|
||||
const size_t src_size_10ms_mono =
|
||||
static_cast<size_t>(src_sample_rate_hz / 100);
|
||||
const size_t dst_size_10ms_mono =
|
||||
static_cast<size_t>(dst_sample_rate_hz / 100);
|
||||
channel_resamplers_.clear();
|
||||
for (size_t i = 0; i < num_channels; ++i) {
|
||||
channel_resamplers_.push_back(ChannelResampler());
|
||||
auto channel_resampler = channel_resamplers_.rbegin();
|
||||
channel_resampler->resampler = std::make_unique<PushSincResampler>(
|
||||
src_size_10ms_mono, dst_size_10ms_mono);
|
||||
channel_resampler->source.resize(src_size_10ms_mono);
|
||||
channel_resampler->destination.resize(dst_size_10ms_mono);
|
||||
}
|
||||
|
||||
channel_data_array_.resize(num_channels_);
|
||||
|
||||
return 0;
|
||||
PushResampler<T>::PushResampler(size_t src_samples_per_channel,
|
||||
size_t dst_samples_per_channel,
|
||||
size_t num_channels) {
|
||||
EnsureInitialized(src_samples_per_channel, dst_samples_per_channel,
|
||||
num_channels);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int PushResampler<T>::Resample(const T* src,
|
||||
size_t src_length,
|
||||
T* dst,
|
||||
size_t dst_capacity) {
|
||||
// These checks used to be factored out of this template function due to
|
||||
// Windows debug build issues with clang. http://crbug.com/615050
|
||||
const size_t src_size_10ms = (src_sample_rate_hz_ / 100) * num_channels_;
|
||||
const size_t dst_size_10ms = (dst_sample_rate_hz_ / 100) * num_channels_;
|
||||
RTC_DCHECK_EQ(src_length, src_size_10ms);
|
||||
RTC_DCHECK_GE(dst_capacity, dst_size_10ms);
|
||||
PushResampler<T>::~PushResampler() = default;
|
||||
|
||||
if (src_sample_rate_hz_ == dst_sample_rate_hz_) {
|
||||
template <typename T>
|
||||
void PushResampler<T>::EnsureInitialized(size_t src_samples_per_channel,
|
||||
size_t dst_samples_per_channel,
|
||||
size_t num_channels) {
|
||||
RTC_DCHECK_GT(src_samples_per_channel, 0);
|
||||
RTC_DCHECK_GT(dst_samples_per_channel, 0);
|
||||
RTC_DCHECK_GT(num_channels, 0);
|
||||
RTC_DCHECK_LE(src_samples_per_channel, kMaxSamplesPerChannel10ms);
|
||||
RTC_DCHECK_LE(dst_samples_per_channel, kMaxSamplesPerChannel10ms);
|
||||
RTC_DCHECK_LE(num_channels, kMaxNumberOfChannels);
|
||||
|
||||
if (src_samples_per_channel == SamplesPerChannel(source_view_) &&
|
||||
dst_samples_per_channel == SamplesPerChannel(destination_view_) &&
|
||||
num_channels == NumChannels(source_view_)) {
|
||||
// No-op if settings haven't changed.
|
||||
return;
|
||||
}
|
||||
|
||||
// Allocate two buffers for all source and destination channels.
|
||||
// Then organize source and destination views together with an array of
|
||||
// resamplers for each channel in the deinterlaved buffers.
|
||||
source_.reset(new T[src_samples_per_channel * num_channels]);
|
||||
destination_.reset(new T[dst_samples_per_channel * num_channels]);
|
||||
source_view_ = DeinterleavedView<T>(source_.get(), src_samples_per_channel,
|
||||
num_channels);
|
||||
destination_view_ = DeinterleavedView<T>(
|
||||
destination_.get(), dst_samples_per_channel, num_channels);
|
||||
resamplers_.resize(num_channels);
|
||||
for (size_t i = 0; i < num_channels; ++i) {
|
||||
resamplers_[i] = std::make_unique<PushSincResampler>(
|
||||
src_samples_per_channel, dst_samples_per_channel);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int PushResampler<T>::Resample(InterleavedView<const T> src,
|
||||
InterleavedView<T> dst) {
|
||||
EnsureInitialized(SamplesPerChannel(src), SamplesPerChannel(dst),
|
||||
NumChannels(src));
|
||||
|
||||
RTC_DCHECK_EQ(NumChannels(src), NumChannels(source_view_));
|
||||
RTC_DCHECK_EQ(NumChannels(dst), NumChannels(destination_view_));
|
||||
RTC_DCHECK_EQ(SamplesPerChannel(src), SamplesPerChannel(source_view_));
|
||||
RTC_DCHECK_EQ(SamplesPerChannel(dst), SamplesPerChannel(destination_view_));
|
||||
|
||||
if (SamplesPerChannel(src) == SamplesPerChannel(dst)) {
|
||||
// The old resampler provides this memcpy facility in the case of matching
|
||||
// sample rates, so reproduce it here for the sinc resampler.
|
||||
memcpy(dst, src, src_length * sizeof(T));
|
||||
return static_cast<int>(src_length);
|
||||
CopySamples(dst, src);
|
||||
return static_cast<int>(src.data().size());
|
||||
}
|
||||
|
||||
const size_t src_length_mono = src_length / num_channels_;
|
||||
const size_t dst_capacity_mono = dst_capacity / num_channels_;
|
||||
Deinterleave(src, source_view_);
|
||||
|
||||
for (size_t ch = 0; ch < num_channels_; ++ch) {
|
||||
channel_data_array_[ch] = channel_resamplers_[ch].source.data();
|
||||
for (size_t i = 0; i < resamplers_.size(); ++i) {
|
||||
size_t dst_length_mono =
|
||||
resamplers_[i]->Resample(source_view_[i], destination_view_[i]);
|
||||
RTC_DCHECK_EQ(dst_length_mono, SamplesPerChannel(dst));
|
||||
}
|
||||
|
||||
Deinterleave(src, src_length_mono, num_channels_, channel_data_array_.data());
|
||||
Interleave<T>(destination_view_, dst);
|
||||
return static_cast<int>(dst.size());
|
||||
}
|
||||
|
||||
size_t dst_length_mono = 0;
|
||||
template <typename T>
|
||||
int PushResampler<T>::Resample(MonoView<const T> src, MonoView<T> dst) {
|
||||
RTC_DCHECK_EQ(resamplers_.size(), 1);
|
||||
RTC_DCHECK_EQ(SamplesPerChannel(src), SamplesPerChannel(source_view_));
|
||||
RTC_DCHECK_EQ(SamplesPerChannel(dst), SamplesPerChannel(destination_view_));
|
||||
|
||||
for (auto& resampler : channel_resamplers_) {
|
||||
dst_length_mono = resampler.resampler->Resample(
|
||||
resampler.source.data(), src_length_mono, resampler.destination.data(),
|
||||
dst_capacity_mono);
|
||||
if (SamplesPerChannel(src) == SamplesPerChannel(dst)) {
|
||||
CopySamples(dst, src);
|
||||
return static_cast<int>(src.size());
|
||||
}
|
||||
|
||||
for (size_t ch = 0; ch < num_channels_; ++ch) {
|
||||
channel_data_array_[ch] = channel_resamplers_[ch].destination.data();
|
||||
}
|
||||
|
||||
Interleave(channel_data_array_.data(), dst_length_mono, num_channels_, dst);
|
||||
return static_cast<int>(dst_length_mono * num_channels_);
|
||||
return resamplers_[0]->Resample(src, dst);
|
||||
}
|
||||
|
||||
// Explictly generate required instantiations.
|
||||
|
Reference in New Issue
Block a user