blob: 082cdc628409573c399fb4a3a46387cd1bd4f5c4 [file] [log] [blame]
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +00001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_
12#define COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000013
kwibergc2b785d2016-02-24 05:22:32 -080014#include <memory>
15
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000016namespace webrtc {
17
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000018class PushSincResampler;
19
andrew@webrtc.orgc1eb5602013-06-03 19:00:29 +000020// Wraps PushSincResampler to provide stereo support.
21// TODO(ajm): add support for an arbitrary number of channels.
andrew@webrtc.orgf5a33f12014-04-19 00:32:07 +000022template <typename T>
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000023class PushResampler {
24 public:
25 PushResampler();
26 virtual ~PushResampler();
27
28 // Must be called whenever the parameters change. Free to be called at any
29 // time as it is a no-op if parameters have not changed since the last call.
Yves Gerey665174f2018-06-19 15:03:05 +020030 int InitializeIfNeeded(int src_sample_rate_hz,
31 int dst_sample_rate_hz,
Peter Kasting69558702016-01-12 16:26:35 -080032 size_t num_channels);
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000033
34 // Returns the total number of samples provided in destination (e.g. 32 kHz,
35 // 2 channel audio gives 640 samples).
Peter Kastingdce40cf2015-08-24 14:52:23 -070036 int Resample(const T* src, size_t src_length, T* dst, size_t dst_capacity);
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000037
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000038 private:
kwibergc2b785d2016-02-24 05:22:32 -080039 std::unique_ptr<PushSincResampler> sinc_resampler_;
40 std::unique_ptr<PushSincResampler> sinc_resampler_right_;
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000041 int src_sample_rate_hz_;
42 int dst_sample_rate_hz_;
Peter Kasting69558702016-01-12 16:26:35 -080043 size_t num_channels_;
kwibergc2b785d2016-02-24 05:22:32 -080044 std::unique_ptr<T[]> src_left_;
45 std::unique_ptr<T[]> src_right_;
46 std::unique_ptr<T[]> dst_left_;
47 std::unique_ptr<T[]> dst_right_;
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000048};
49
50} // namespace webrtc
51
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020052#endif // COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_