Tommi cfdbb0d371 Update PushResampler to use a single buffer for source, destination.
PushResampler now uses a single buffer for the deinterleaved
channel sources and another for the deinterleaved destinations.
Before, there was a dedicated buffer per channel (source and dest).
This reduces allocations and allows for using DeinterleavedView for
both which simplifies some checks.

Bug: chromium:335805780
Change-Id: I553a36164109127fa332ab17918d53832d442303
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/351542
Reviewed-by: Per Åhgren <peah@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42415}
2024-05-30 14:37:50 +00:00

52 lines
1.6 KiB
C++

/*
* Copyright (c) 2013 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 COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_
#define COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_
#include <memory>
#include <vector>
#include "api/audio/audio_view.h"
namespace webrtc {
class PushSincResampler;
// Wraps PushSincResampler to provide stereo support.
// Note: This implementation assumes 10ms buffer sizes throughout.
template <typename T>
class PushResampler {
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);
// Returns the total number of samples provided in destination (e.g. 32 kHz,
// 2 channel audio gives 640 samples).
int Resample(InterleavedView<const T> src, InterleavedView<T> dst);
private:
std::unique_ptr<T[]> source_;
std::unique_ptr<T[]> destination_;
DeinterleavedView<T> source_view_;
DeinterleavedView<T> destination_view_;
std::vector<std::unique_ptr<PushSincResampler>> resamplers_;
};
} // namespace webrtc
#endif // COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_