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 | |
| 11 | #ifndef WEBRTC_COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_ |
| 12 | #define WEBRTC_COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_ |
| 13 | |
| 14 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
| 15 | #include "webrtc/typedefs.h" |
| 16 | |
| 17 | namespace webrtc { |
| 18 | |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 19 | class PushSincResampler; |
| 20 | |
andrew@webrtc.org | c1eb560 | 2013-06-03 19:00:29 +0000 | [diff] [blame] | 21 | // Wraps PushSincResampler to provide stereo support. |
| 22 | // TODO(ajm): add support for an arbitrary number of channels. |
andrew@webrtc.org | f5a33f1 | 2014-04-19 00:32:07 +0000 | [diff] [blame^] | 23 | template <typename T> |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 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, int dst_sample_rate_hz, |
| 32 | int num_channels); |
| 33 | |
| 34 | // Returns the total number of samples provided in destination (e.g. 32 kHz, |
| 35 | // 2 channel audio gives 640 samples). |
andrew@webrtc.org | f5a33f1 | 2014-04-19 00:32:07 +0000 | [diff] [blame^] | 36 | int Resample(const T* src, int src_length, T* dst, int dst_capacity); |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 37 | |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 38 | private: |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 39 | scoped_ptr<PushSincResampler> sinc_resampler_; |
| 40 | scoped_ptr<PushSincResampler> sinc_resampler_right_; |
| 41 | int src_sample_rate_hz_; |
| 42 | int dst_sample_rate_hz_; |
| 43 | int num_channels_; |
andrew@webrtc.org | f5a33f1 | 2014-04-19 00:32:07 +0000 | [diff] [blame^] | 44 | scoped_ptr<T[]> src_left_; |
| 45 | scoped_ptr<T[]> src_right_; |
| 46 | scoped_ptr<T[]> dst_left_; |
| 47 | scoped_ptr<T[]> dst_right_; |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | } // namespace webrtc |
| 51 | |
| 52 | #endif // WEBRTC_COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_ |