mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-20 00:57:49 +01:00

Start introducing ArrayView to AudioFrame and code that flows down from there. In this first step: * Add `data_view()` that returns a read-only ArrayView for the audio buffer. When AudioFrame is not initialized however, data_view() will return a nullptr whereas the current data() method never returns nullptr. * Add `mutable_data()` that requires two arguments for properly setting the samples per channel and number of channels that's required for accurately reserving the returned mutable ArrayView. A notable behavior change is that if the requested number of channels is larger than supported or the calculated buffer size is too large, the function will trigger a check. * Add TODOs for following work. Bug: chromium:335805780 Change-Id: I2937de800422589ebe6a3840b3caadf3d9ff8b00 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/347982 Reviewed-by: Per Åhgren <peah@webrtc.org> Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42202}
62 lines
2.1 KiB
C++
62 lines
2.1 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/array_view.h"
|
|
|
|
namespace webrtc {
|
|
|
|
class PushSincResampler;
|
|
|
|
// Wraps PushSincResampler to provide stereo support.
|
|
// Note: This implementation assumes 10ms buffer sizes throughout.
|
|
// TODO(ajm): add support for an arbitrary number of channels.
|
|
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(rtc::ArrayView<const T> src, rtc::ArrayView<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_;
|
|
|
|
struct ChannelResampler {
|
|
std::unique_ptr<PushSincResampler> resampler;
|
|
std::vector<T> source;
|
|
std::vector<T> destination;
|
|
};
|
|
|
|
std::vector<ChannelResampler> channel_resamplers_;
|
|
};
|
|
} // namespace webrtc
|
|
|
|
#endif // COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_
|