blob: 770a992618aebae10e4eea53d4aa2010fd9efd12 [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
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000019class PushSincResampler;
20
andrew@webrtc.orgc1eb5602013-06-03 19:00:29 +000021// Wraps PushSincResampler to provide stereo support.
22// TODO(ajm): add support for an arbitrary number of channels.
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000023class PushResampler {
24 public:
25 PushResampler();
26 virtual ~PushResampler();
27
28 // Must be called whenever the parameters change. Free to be called at any
29 // time as it is a no-op if parameters have not changed since the last call.
30 int InitializeIfNeeded(int src_sample_rate_hz, int dst_sample_rate_hz,
31 int num_channels);
32
33 // Returns the total number of samples provided in destination (e.g. 32 kHz,
34 // 2 channel audio gives 640 samples).
35 int Resample(const int16_t* src, int src_length, int16_t* dst,
36 int dst_capacity);
37
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000038 private:
39 int ResampleSinc(const int16_t* src, int src_length, int16_t* dst,
40 int dst_capacity);
41
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000042 scoped_ptr<PushSincResampler> sinc_resampler_;
43 scoped_ptr<PushSincResampler> sinc_resampler_right_;
44 int src_sample_rate_hz_;
45 int dst_sample_rate_hz_;
46 int num_channels_;
andrew@webrtc.org50b2efe2013-04-29 17:27:29 +000047 scoped_array<int16_t> src_left_;
48 scoped_array<int16_t> src_right_;
49 scoped_array<int16_t> dst_left_;
50 scoped_array<int16_t> dst_right_;
51};
52
53} // namespace webrtc
54
55#endif // WEBRTC_COMMON_AUDIO_RESAMPLER_INCLUDE_PUSH_RESAMPLER_H_