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:
@ -14,45 +14,44 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "api/audio/audio_view.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class PushSincResampler;
|
||||
|
||||
// Wraps PushSincResampler to provide stereo support.
|
||||
// TODO(ajm): add support for an arbitrary number of channels.
|
||||
// Note: This implementation assumes 10ms buffer sizes throughout.
|
||||
template <typename T>
|
||||
class PushResampler {
|
||||
class PushResampler final {
|
||||
public:
|
||||
PushResampler();
|
||||
virtual ~PushResampler();
|
||||
|
||||
// Must be called whenever the parameters change. Free to be called at any
|
||||
// time as it is a no-op if parameters have not changed since the last call.
|
||||
int InitializeIfNeeded(int src_sample_rate_hz,
|
||||
int dst_sample_rate_hz,
|
||||
size_t num_channels);
|
||||
PushResampler(size_t src_samples_per_channel,
|
||||
size_t dst_samples_per_channel,
|
||||
size_t num_channels);
|
||||
~PushResampler();
|
||||
|
||||
// Returns the total number of samples provided in destination (e.g. 32 kHz,
|
||||
// 2 channel audio gives 640 samples).
|
||||
int Resample(const T* src, size_t src_length, T* dst, size_t dst_capacity);
|
||||
int Resample(InterleavedView<const T> src, InterleavedView<T> dst);
|
||||
// For when a deinterleaved/mono channel already exists and we can skip the
|
||||
// deinterleaved operation.
|
||||
int Resample(MonoView<const T> src, MonoView<T> dst);
|
||||
|
||||
private:
|
||||
int src_sample_rate_hz_;
|
||||
int dst_sample_rate_hz_;
|
||||
size_t num_channels_;
|
||||
// Vector that is needed to provide the proper inputs and outputs to the
|
||||
// interleave/de-interleave methods used in Resample. This needs to be
|
||||
// heap-allocated on the state to support an arbitrary number of channels
|
||||
// without doing run-time heap-allocations in the Resample method.
|
||||
std::vector<T*> channel_data_array_;
|
||||
// Ensures that source and destination buffers for deinterleaving are
|
||||
// correctly configured prior to resampling that requires deinterleaving.
|
||||
void EnsureInitialized(size_t src_samples_per_channel,
|
||||
size_t dst_samples_per_channel,
|
||||
size_t num_channels);
|
||||
|
||||
struct ChannelResampler {
|
||||
std::unique_ptr<PushSincResampler> resampler;
|
||||
std::vector<T> source;
|
||||
std::vector<T> destination;
|
||||
};
|
||||
// Buffers used for when a deinterleaving step is necessary.
|
||||
std::unique_ptr<T[]> source_;
|
||||
std::unique_ptr<T[]> destination_;
|
||||
DeinterleavedView<T> source_view_;
|
||||
DeinterleavedView<T> destination_view_;
|
||||
|
||||
std::vector<ChannelResampler> channel_resamplers_;
|
||||
std::vector<std::unique_ptr<PushSincResampler>> resamplers_;
|
||||
};
|
||||
} // namespace webrtc
|
||||
|
||||
|
@ -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.
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "api/audio/audio_view.h"
|
||||
#include "common_audio/resampler/sinc_resampler.h"
|
||||
|
||||
namespace webrtc {
|
||||
@ -40,6 +41,12 @@ class PushSincResampler : public SincResamplerCallback {
|
||||
// at least as large as `destination_frames`. Returns the number of samples
|
||||
// provided in destination (for convenience, since this will always be equal
|
||||
// to `destination_frames`).
|
||||
template <typename S, typename D>
|
||||
size_t Resample(const MonoView<S>& source, const MonoView<D>& destination) {
|
||||
return Resample(&source[0], SamplesPerChannel(source), &destination[0],
|
||||
SamplesPerChannel(destination));
|
||||
}
|
||||
|
||||
size_t Resample(const int16_t* source,
|
||||
size_t source_frames,
|
||||
int16_t* destination,
|
||||
|
Reference in New Issue
Block a user