2011-07-07 08:21:25 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A wrapper for resampling a numerous amount of sampling combinations.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef COMMON_AUDIO_RESAMPLER_INCLUDE_RESAMPLER_H_
|
|
|
|
|
#define COMMON_AUDIO_RESAMPLER_INCLUDE_RESAMPLER_H_
|
2011-07-07 08:21:25 +00:00
|
|
|
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
#include <stddef.h>
|
|
|
|
|
|
2017-09-15 13:58:09 +02:00
|
|
|
#include "typedefs.h" // NOLINT(build/include)
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-03-30 10:08:22 -07:00
|
|
|
namespace webrtc {
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-03-20 23:28:07 +00:00
|
|
|
// All methods return 0 on success and -1 on failure.
|
2017-03-09 06:25:06 -08:00
|
|
|
class Resampler {
|
|
|
|
|
public:
|
|
|
|
|
Resampler();
|
|
|
|
|
Resampler(int inFreq, int outFreq, size_t num_channels);
|
|
|
|
|
~Resampler();
|
|
|
|
|
|
|
|
|
|
// Reset all states
|
|
|
|
|
int Reset(int inFreq, int outFreq, size_t num_channels);
|
|
|
|
|
|
|
|
|
|
// Reset all states if any parameter has changed
|
|
|
|
|
int ResetIfNeeded(int inFreq, int outFreq, size_t num_channels);
|
|
|
|
|
|
|
|
|
|
// Resample samplesIn to samplesOut.
|
|
|
|
|
int Push(const int16_t* samplesIn, size_t lengthIn, int16_t* samplesOut,
|
|
|
|
|
size_t maxLen, size_t& outLen); // NOLINT: to avoid changing APIs
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
enum ResamplerMode {
|
|
|
|
|
kResamplerMode1To1,
|
|
|
|
|
kResamplerMode1To2,
|
|
|
|
|
kResamplerMode1To3,
|
|
|
|
|
kResamplerMode1To4,
|
|
|
|
|
kResamplerMode1To6,
|
|
|
|
|
kResamplerMode1To12,
|
|
|
|
|
kResamplerMode2To3,
|
|
|
|
|
kResamplerMode2To11,
|
|
|
|
|
kResamplerMode4To11,
|
|
|
|
|
kResamplerMode8To11,
|
|
|
|
|
kResamplerMode11To16,
|
|
|
|
|
kResamplerMode11To32,
|
|
|
|
|
kResamplerMode2To1,
|
|
|
|
|
kResamplerMode3To1,
|
|
|
|
|
kResamplerMode4To1,
|
|
|
|
|
kResamplerMode6To1,
|
|
|
|
|
kResamplerMode12To1,
|
|
|
|
|
kResamplerMode3To2,
|
|
|
|
|
kResamplerMode11To2,
|
|
|
|
|
kResamplerMode11To4,
|
|
|
|
|
kResamplerMode11To8
|
|
|
|
|
};
|
|
|
|
|
|
2017-10-30 10:05:10 +01:00
|
|
|
// Computes the resampler mode for a given sampling frequency pair.
|
|
|
|
|
// Returns -1 for unsupported frequency pairs.
|
|
|
|
|
static int ComputeResamplerMode(int in_freq_hz,
|
|
|
|
|
int out_freq_hz,
|
|
|
|
|
ResamplerMode* mode);
|
|
|
|
|
|
2017-03-09 06:25:06 -08:00
|
|
|
// Generic pointers since we don't know what states we'll need
|
|
|
|
|
void* state1_;
|
|
|
|
|
void* state2_;
|
|
|
|
|
void* state3_;
|
|
|
|
|
|
|
|
|
|
// Storage if needed
|
|
|
|
|
int16_t* in_buffer_;
|
|
|
|
|
int16_t* out_buffer_;
|
|
|
|
|
size_t in_buffer_size_;
|
|
|
|
|
size_t out_buffer_size_;
|
|
|
|
|
size_t in_buffer_size_max_;
|
|
|
|
|
size_t out_buffer_size_max_;
|
|
|
|
|
|
|
|
|
|
int my_in_frequency_khz_;
|
|
|
|
|
int my_out_frequency_khz_;
|
|
|
|
|
ResamplerMode my_mode_;
|
|
|
|
|
size_t num_channels_;
|
|
|
|
|
|
|
|
|
|
// Extra instance for stereo
|
|
|
|
|
Resampler* slave_left_;
|
|
|
|
|
Resampler* slave_right_;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
|
|
|
|
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace webrtc
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // COMMON_AUDIO_RESAMPLER_INCLUDE_RESAMPLER_H_
|