blob: 05b93d1909f6eb796bedd9bdd1aa48fc2a2d9e69 [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.
Yves Gerey665174f2018-06-19 15:03:05 +020032 int InitializeIfNeeded(int src_sample_rate_hz,
33 int dst_sample_rate_hz,
Peter Kasting69558702016-01-12 16:26:35 -080034 size_t num_channels);
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000035
36 // Returns the total number of samples provided in destination (e.g. 32 kHz,
37 // 2 channel audio gives 640 samples).
Peter Kastingdce40cf2015-08-24 14:52:23 -070038 int Resample(const T* src, size_t src_length, T* dst, size_t dst_capacity);
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000039
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000040 private:
kwibergc2b785d2016-02-24 05:22:32 -080041 std::unique_ptr<PushSincResampler> sinc_resampler_;
42 std::unique_ptr<PushSincResampler> sinc_resampler_right_;
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000043 int src_sample_rate_hz_;
44 int dst_sample_rate_hz_;
Peter Kasting69558702016-01-12 16:26:35 -080045 size_t num_channels_;
kwibergc2b785d2016-02-24 05:22:32 -080046 std::unique_ptr<T[]> src_left_;
47 std::unique_ptr<T[]> src_right_;
48 std::unique_ptr<T[]> dst_left_;
49 std::unique_ptr<T[]> dst_right_;
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000050};
51
52} // namespace webrtc
53
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020054#endif // COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_