aboutsummaryrefslogtreecommitdiff
path: root/src/audio_core/interpolate.h
blob: ba46b5ad78670c61a8a4be98cd7f04dc57f69f82 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2016 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <array>
#include <deque>
#include "audio_core/audio_types.h"
#include "common/common_types.h"

namespace AudioCore::AudioInterp {

/// A variable length buffer of signed PCM16 stereo samples.
using StereoBuffer16 = std::deque<std::array<s16, 2>>;

struct State {
    /// Two historical samples.
    std::array<s16, 2> xn1 = {}; ///< x[n-1]
    std::array<s16, 2> xn2 = {}; ///< x[n-2]
    /// Current fractional position.
    u64 fposition = 0;
};

/**
 * No interpolation. This is equivalent to a zero-order hold. There is a two-sample predelay.
 * @param state Interpolation state.
 * @param input Input buffer.
 * @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.
 */
void None(State& state, StereoBuffer16& input, float rate, StereoFrame16& output,
          std::size_t& outputi);

/**
 * Linear interpolation. This is equivalent to a first-order hold. There is a two-sample predelay.
 * @param state Interpolation state.
 * @param input Input buffer.
 * @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.
 */
void Linear(State& state, StereoBuffer16& input, float rate, StereoFrame16& output,
            std::size_t& outputi);

} // namespace AudioCore::AudioInterp