blob: 046415b87e8cab6afd8a4e2d80e989df0a56fc7e [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
Mirko Bonadei71207422017-09-15 13:58:09 +020016#include "typedefs.h" // NOLINT(build/include)
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000017
18namespace webrtc {
19
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000020class PushSincResampler;
21
andrew@webrtc.orgc1eb5602013-06-03 19:00:29 +000022// Wraps PushSincResampler to provide stereo support.
23// TODO(ajm): add support for an arbitrary number of channels.
andrew@webrtc.orgf5a33f12014-04-19 00:32:07 +000024template <typename T>
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000025class PushResampler {
26 public:
27 PushResampler();
28 virtual ~PushResampler();
29
30 // Must be called whenever the parameters change. Free to be called at any
31 // time as it is a no-op if parameters have not changed since the last call.
32 int InitializeIfNeeded(int src_sample_rate_hz, int dst_sample_rate_hz,
Peter Kasting69558702016-01-12 16:26:35 -080033 size_t num_channels);
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000034
35 // Returns the total number of samples provided in destination (e.g. 32 kHz,
36 // 2 channel audio gives 640 samples).
Peter Kastingdce40cf2015-08-24 14:52:23 -070037 int Resample(const T* src, size_t src_length, T* dst, size_t dst_capacity);
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000038
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000039 private:
kwibergc2b785d2016-02-24 05:22:32 -080040 std::unique_ptr<PushSincResampler> sinc_resampler_;
41 std::unique_ptr<PushSincResampler> sinc_resampler_right_;
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000042 int src_sample_rate_hz_;
43 int dst_sample_rate_hz_;
Peter Kasting69558702016-01-12 16:26:35 -080044 size_t num_channels_;
kwibergc2b785d2016-02-24 05:22:32 -080045 std::unique_ptr<T[]> src_left_;
46 std::unique_ptr<T[]> src_right_;
47 std::unique_ptr<T[]> dst_left_;
48 std::unique_ptr<T[]> dst_right_;
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000049};
50
51} // namespace webrtc
52
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020053#endif // COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_