2016-04-24 22:11:47 +02:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
2017-09-25 20:06:42 +02:00
|
|
|
#include <deque>
|
2017-12-20 19:44:32 +01:00
|
|
|
#include "audio_core/audio_types.h"
|
2016-04-24 22:11:47 +02:00
|
|
|
#include "common/common_types.h"
|
|
|
|
|
2019-02-18 05:41:48 +01:00
|
|
|
namespace AudioCore::AudioInterp {
|
2016-04-24 22:11:47 +02:00
|
|
|
|
|
|
|
/// A variable length buffer of signed PCM16 stereo samples.
|
2017-09-25 20:06:42 +02:00
|
|
|
using StereoBuffer16 = std::deque<std::array<s16, 2>>;
|
2016-04-24 22:11:47 +02:00
|
|
|
|
|
|
|
struct State {
|
2017-08-03 13:22:51 +02:00
|
|
|
/// Two historical samples.
|
2016-04-24 22:11:47 +02:00
|
|
|
std::array<s16, 2> xn1 = {}; ///< x[n-1]
|
|
|
|
std::array<s16, 2> xn2 = {}; ///< x[n-2]
|
2017-08-03 13:22:51 +02:00
|
|
|
/// Current fractional position.
|
|
|
|
u64 fposition = 0;
|
2016-04-24 22:11:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* No interpolation. This is equivalent to a zero-order hold. There is a two-sample predelay.
|
2017-02-27 02:58:51 +01:00
|
|
|
* @param state Interpolation state.
|
2016-04-24 22:11:47 +02:00
|
|
|
* @param input Input buffer.
|
2017-08-03 13:22:51 +02:00
|
|
|
* @param rate Stretch factor. Must be a positive non-zero value.
|
|
|
|
* rate > 1.0 performs decimation and rate < 1.0 performs upsampling.
|
|
|
|
* @param output The resampled audio buffer.
|
|
|
|
* @param outputi The index of output to start writing to.
|
2016-04-24 22:11:47 +02:00
|
|
|
*/
|
2018-09-06 22:03:28 +02:00
|
|
|
void None(State& state, StereoBuffer16& input, float rate, StereoFrame16& output,
|
|
|
|
std::size_t& outputi);
|
2016-04-24 22:11:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Linear interpolation. This is equivalent to a first-order hold. There is a two-sample predelay.
|
2017-02-27 02:58:51 +01:00
|
|
|
* @param state Interpolation state.
|
2016-04-24 22:11:47 +02:00
|
|
|
* @param input Input buffer.
|
2017-08-03 13:22:51 +02:00
|
|
|
* @param rate Stretch factor. Must be a positive non-zero value.
|
|
|
|
* rate > 1.0 performs decimation and rate < 1.0 performs upsampling.
|
|
|
|
* @param output The resampled audio buffer.
|
|
|
|
* @param outputi The index of output to start writing to.
|
2016-04-24 22:11:47 +02:00
|
|
|
*/
|
2017-12-20 19:44:32 +01:00
|
|
|
void Linear(State& state, StereoBuffer16& input, float rate, StereoFrame16& output,
|
2018-09-06 22:03:28 +02:00
|
|
|
std::size_t& outputi);
|
2016-04-24 22:11:47 +02:00
|
|
|
|
2019-02-18 05:41:48 +01:00
|
|
|
} // namespace AudioCore::AudioInterp
|