blob: 068e270988128e0e0f8abe09955229c72320ef59 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
2 * Copyright (c) 2011 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
12/*
13 * A wrapper for resampling a numerous amount of sampling combinations.
14 */
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#ifndef COMMON_AUDIO_RESAMPLER_INCLUDE_RESAMPLER_H_
17#define COMMON_AUDIO_RESAMPLER_INCLUDE_RESAMPLER_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000018
Peter Kastingdce40cf2015-08-24 14:52:23 -070019#include <stddef.h>
20
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000022
Andrew MacDonald2c9c83d2015-03-30 10:08:22 -070023namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000024
wtc@chromium.org45539412015-03-20 23:28:07 +000025// All methods return 0 on success and -1 on failure.
oprypin67fdb802017-03-09 06:25:06 -080026class Resampler {
27 public:
28 Resampler();
29 Resampler(int inFreq, int outFreq, size_t num_channels);
30 ~Resampler();
niklase@google.com470e71d2011-07-07 08:21:25 +000031
oprypin67fdb802017-03-09 06:25:06 -080032 // Reset all states
33 int Reset(int inFreq, int outFreq, size_t num_channels);
niklase@google.com470e71d2011-07-07 08:21:25 +000034
oprypin67fdb802017-03-09 06:25:06 -080035 // Reset all states if any parameter has changed
36 int ResetIfNeeded(int inFreq, int outFreq, size_t num_channels);
niklase@google.com470e71d2011-07-07 08:21:25 +000037
oprypin67fdb802017-03-09 06:25:06 -080038 // Resample samplesIn to samplesOut.
39 int Push(const int16_t* samplesIn, size_t lengthIn, int16_t* samplesOut,
40 size_t maxLen, size_t& outLen); // NOLINT: to avoid changing APIs
niklase@google.com470e71d2011-07-07 08:21:25 +000041
oprypin67fdb802017-03-09 06:25:06 -080042 private:
43 enum ResamplerMode {
44 kResamplerMode1To1,
45 kResamplerMode1To2,
46 kResamplerMode1To3,
47 kResamplerMode1To4,
48 kResamplerMode1To6,
49 kResamplerMode1To12,
50 kResamplerMode2To3,
51 kResamplerMode2To11,
52 kResamplerMode4To11,
53 kResamplerMode8To11,
54 kResamplerMode11To16,
55 kResamplerMode11To32,
56 kResamplerMode2To1,
57 kResamplerMode3To1,
58 kResamplerMode4To1,
59 kResamplerMode6To1,
60 kResamplerMode12To1,
61 kResamplerMode3To2,
62 kResamplerMode11To2,
63 kResamplerMode11To4,
64 kResamplerMode11To8
65 };
niklase@google.com470e71d2011-07-07 08:21:25 +000066
oprypin67fdb802017-03-09 06:25:06 -080067 // Generic pointers since we don't know what states we'll need
68 void* state1_;
69 void* state2_;
70 void* state3_;
Andrew MacDonald2c9c83d2015-03-30 10:08:22 -070071
oprypin67fdb802017-03-09 06:25:06 -080072 // Storage if needed
73 int16_t* in_buffer_;
74 int16_t* out_buffer_;
75 size_t in_buffer_size_;
76 size_t out_buffer_size_;
77 size_t in_buffer_size_max_;
78 size_t out_buffer_size_max_;
niklase@google.com470e71d2011-07-07 08:21:25 +000079
oprypin67fdb802017-03-09 06:25:06 -080080 int my_in_frequency_khz_;
81 int my_out_frequency_khz_;
82 ResamplerMode my_mode_;
83 size_t num_channels_;
niklase@google.com470e71d2011-07-07 08:21:25 +000084
oprypin67fdb802017-03-09 06:25:06 -080085 // Extra instance for stereo
86 Resampler* slave_left_;
87 Resampler* slave_right_;
niklase@google.com470e71d2011-07-07 08:21:25 +000088};
89
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000090} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000091
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020092#endif // COMMON_AUDIO_RESAMPLER_INCLUDE_RESAMPLER_H_