andrew@webrtc.org | dea537b | 2013-04-26 14:56:51 +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_PUSH_SINC_RESAMPLER_H_ |
| 12 | #define WEBRTC_COMMON_AUDIO_RESAMPLER_PUSH_SINC_RESAMPLER_H_ |
| 13 | |
| 14 | #include "webrtc/common_audio/resampler/sinc_resampler.h" |
| 15 | #include "webrtc/system_wrappers/interface/constructor_magic.h" |
| 16 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
| 17 | #include "webrtc/typedefs.h" |
| 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | // A thin wrapper over SincResampler to provide a push-based interface as |
| 22 | // required by WebRTC. |
| 23 | class PushSincResampler : public SincResamplerCallback { |
| 24 | public: |
| 25 | // Provide the size of the source and destination blocks in samples. These |
| 26 | // must correspond to the same time duration (typically 10 ms) as the sample |
| 27 | // ratio is inferred from them. |
| 28 | PushSincResampler(int src_block_size, int dst_block_size); |
| 29 | virtual ~PushSincResampler(); |
| 30 | |
| 31 | // Perform the resampling. |source_length| must always equal the |
| 32 | // |src_block_size| provided at construction. |destination_capacity| must be |
| 33 | // at least as large as |dst_block_size|. Returns the number of samples |
| 34 | // provided in destination (for convenience, since this will always be equal |
| 35 | // to |dst_block_size|). |
| 36 | int Resample(const int16_t* source, int source_length, |
| 37 | int16_t* destination, int destination_capacity); |
| 38 | |
| 39 | // Implements SincResamplerCallback. |
| 40 | virtual void Run(float* destination, int frames); |
| 41 | |
| 42 | private: |
| 43 | scoped_ptr<SincResampler> resampler_; |
| 44 | scoped_array<float> float_buffer_; |
| 45 | const int16_t* source_ptr_; |
| 46 | const int dst_size_; |
| 47 | |
| 48 | DISALLOW_COPY_AND_ASSIGN(PushSincResampler); |
| 49 | }; |
| 50 | |
| 51 | } // namespace webrtc |
| 52 | |
| 53 | #endif // WEBRTC_COMMON_AUDIO_RESAMPLER_PUSH_SINC_RESAMPLER_H_ |