Debian Codegraph @

Xpjproject/third_party/webrtc_aec3/src/common_audio/resampler/include/push_resampler.h

raw symbols SCIP
1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #ifndef COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_
12 #define COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_
13
14 #include <memory>
15 #include <vector>
16
17 namespace webrtc {
18
19 class PushSincResampler;
20
21 // Wraps PushSincResampler to provide stereo support.
22 // TODO(ajm): add support for an arbitrary number of channels.
23 template <typename T>
24 class PushResampler {
25 public:
26 PushResampler();
27 virtual ~PushResampler();
28
29 // Must be called whenever the parameters change. Free to be called at any
30 // time as it is a no-op if parameters have not changed since the last call.
31 int InitializeIfNeeded(int src_sample_rate_hz,
32 int dst_sample_rate_hz,
33 size_t num_channels);
34
35 // Returns the total number of samples provided in destination (e.g. 32 kHz,
36 // 2 channel audio gives 640 samples).
37 int Resample(const T* src, size_t src_length, T* dst, size_t dst_capacity);
38
39 private:
40 int src_sample_rate_hz_;
41 int dst_sample_rate_hz_;
42 size_t num_channels_;
43 // Vector that is needed to provide the proper inputs and outputs to the
44 // interleave/de-interleave methods used in Resample. This needs to be
45 // heap-allocated on the state to support an arbitrary number of channels
46 // without doing run-time heap-allocations in the Resample method.
47 std::vector<T*> channel_data_array_;
48
49 struct ChannelResampler {
50 std::unique_ptr<PushSincResampler> resampler;
51 std::vector<T> source;
52 std::vector<T> destination;
53 };
54
55 std::vector<ChannelResampler> channel_resamplers_;
56 };
57 } // namespace webrtc
58
59 #endif // COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_