andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_ |
| 12 | #define COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_ |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 13 | |
kwiberg | c2b785d | 2016-02-24 05:22:32 -0800 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame^] | 16 | #include "typedefs.h" // NOLINT(build/include) |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 20 | class PushSincResampler; |
| 21 | |
andrew@webrtc.org | c1eb560 | 2013-06-03 19:00:29 +0000 | [diff] [blame] | 22 | // Wraps PushSincResampler to provide stereo support. |
| 23 | // TODO(ajm): add support for an arbitrary number of channels. |
andrew@webrtc.org | f5a33f1 | 2014-04-19 00:32:07 +0000 | [diff] [blame] | 24 | template <typename T> |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 25 | class 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 Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 33 | size_t num_channels); |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 34 | |
| 35 | // Returns the total number of samples provided in destination (e.g. 32 kHz, |
| 36 | // 2 channel audio gives 640 samples). |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 37 | int Resample(const T* src, size_t src_length, T* dst, size_t dst_capacity); |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 38 | |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 39 | private: |
kwiberg | c2b785d | 2016-02-24 05:22:32 -0800 | [diff] [blame] | 40 | std::unique_ptr<PushSincResampler> sinc_resampler_; |
| 41 | std::unique_ptr<PushSincResampler> sinc_resampler_right_; |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 42 | int src_sample_rate_hz_; |
| 43 | int dst_sample_rate_hz_; |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 44 | size_t num_channels_; |
kwiberg | c2b785d | 2016-02-24 05:22:32 -0800 | [diff] [blame] | 45 | 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.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | } // namespace webrtc |
| 52 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 53 | #endif // COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_ |