blob: 0183f9117bcd2a9418fc6971b8143f0b3d385a87 [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
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
17namespace webrtc {
18
19class Resampler;
20class PushSincResampler;
21
22// Wraps the old resampler and new arbitrary rate conversion resampler. The
23// old resampler will be used whenever it supports the requested rates, and
24// otherwise the sinc resampler will be enabled.
25class 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,
33 int num_channels);
34
35 // Returns the total number of samples provided in destination (e.g. 32 kHz,
36 // 2 channel audio gives 640 samples).
37 int Resample(const int16_t* src, int src_length, int16_t* dst,
38 int dst_capacity);
39
40 bool use_sinc_resampler() const { return use_sinc_resampler_; }
41
42 private:
43 int ResampleSinc(const int16_t* src, int src_length, int16_t* dst,
44 int dst_capacity);
45
46 scoped_ptr<Resampler> resampler_;
47 scoped_ptr<PushSincResampler> sinc_resampler_;
48 scoped_ptr<PushSincResampler> sinc_resampler_right_;
49 int src_sample_rate_hz_;
50 int dst_sample_rate_hz_;
51 int num_channels_;
52 bool use_sinc_resampler_;
53 scoped_array<int16_t> src_left_;
54 scoped_array<int16_t> src_right_;
55 scoped_array<int16_t> dst_left_;
56 scoped_array<int16_t> dst_right_;
57};
58
59} // namespace webrtc
60
61#endif // WEBRTC_COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_