From 111275bfbd5bcc55539c0f09af1cec716114afd3 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sun, 24 Apr 2016 21:11:47 +0100 Subject: AudioCore: Implement interpolation --- src/audio_core/interpolate.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/audio_core/interpolate.h (limited to 'src/audio_core/interpolate.h') diff --git a/src/audio_core/interpolate.h b/src/audio_core/interpolate.h new file mode 100644 index 000000000..a4c0a453d --- /dev/null +++ b/src/audio_core/interpolate.h @@ -0,0 +1,41 @@ +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include + +#include "common/common_types.h" + +namespace AudioInterp { + +/// A variable length buffer of signed PCM16 stereo samples. +using StereoBuffer16 = std::vector>; + +struct State { + // Two historical samples. + std::array xn1 = {}; ///< x[n-1] + std::array xn2 = {}; ///< x[n-2] +}; + +/** + * No interpolation. This is equivalent to a zero-order hold. There is a two-sample predelay. + * @param input Input buffer. + * @param rate_multiplier Stretch factor. Must be a positive non-zero value. + * rate_multiplier > 1.0 performs decimation and rate_multipler < 1.0 performs upsampling. + * @return The resampled audio buffer. + */ +StereoBuffer16 None(State& state, const StereoBuffer16& input, float rate_multiplier); + +/** + * Linear interpolation. This is equivalent to a first-order hold. There is a two-sample predelay. + * @param input Input buffer. + * @param rate_multiplier Stretch factor. Must be a positive non-zero value. + * rate_multiplier > 1.0 performs decimation and rate_multipler < 1.0 performs upsampling. + * @return The resampled audio buffer. + */ +StereoBuffer16 Linear(State& state, const StereoBuffer16& input, float rate_multiplier); + +} // namespace AudioInterp -- cgit v1.2.3