Deluge Firmware
1.3.0
Build date: 2026.11.28
Toggle main menu visibility
Loading...
Searching...
No Matches
interpolate.h
1
#pragma once
2
#include "definitions_cxx.hpp"
3
#include "deluge/dsp/stereo_sample.h"
4
#include <array>
5
#include <cstdint>
6
7
extern
const
int16_t windowedSincKernel[][17][16];
8
9
namespace
deluge::dsp {
10
struct
[[gnu::hot]] Interpolator {
11
12
Interpolator() =
default
;
13
StereoSample
interpolate(
size_t
channels, int32_t whichKernel, uint32_t oscPos);
14
StereoSample
interpolateLinear(
size_t
channels, uint32_t oscPos);
15
17
[[nodiscard]]
constexpr
int16_t
l
(
size_t
i)
const
{
return
history_l_[head_ + i]; }
18
[[nodiscard]]
constexpr
int16_t r(
size_t
i)
const
{
return
history_r_[head_ + i]; }
19
20
constexpr
void
setL(
size_t
i, int16_t value) { set(history_l_, i, value); }
21
constexpr
void
setR(
size_t
i, int16_t value) { set(history_r_, i, value); }
22
24
[[gnu::always_inline]]
constexpr
void
push
(int16_t left, int16_t right) {
25
jumpForward
(1);
26
setL(0, left);
27
setR(0, right);
28
}
29
32
[[gnu::always_inline]]
constexpr
void
jumpForward
(
size_t
num_samples) {
33
head_ = (head_ - num_samples) & (kInterpolationMaxNumSamples - 1);
34
}
35
36
private
:
37
static_assert
((kInterpolationMaxNumSamples & (kInterpolationMaxNumSamples - 1)) == 0,
38
"set() relies on this being a power of two"
);
39
40
using
History = std::array<int16_t, 2 * kInterpolationMaxNumSamples>;
41
42
[[gnu::always_inline]]
constexpr
void
set(History& history,
size_t
i, int16_t value)
const
{
43
size_t
pos = head_ + i;
// Below 2 * kInterpolationMaxNumSamples, so flipping this bit finds its other copy
44
history[pos] = value;
45
history[pos ^ kInterpolationMaxNumSamples] = value;
46
}
47
48
// These are ring buffers, holding each sample twice, kInterpolationMaxNumSamples apart. That way the latest
49
// kInterpolationMaxNumSamples are always in order from head_ onwards, however far round head_ has got - so
50
// interpolate() can load them straight into NEON registers, and adding a sample doesn't mean shuffling all the
51
// others along.
52
// Value-initialised: interpolate() reads the full kInterpolationMaxNumSamples-tap window via SIMD, so any tap not
53
// yet set must be a defined 0 rather than whatever the allocation left behind (the live-input pitch-shifter feeds
54
// these incrementally on warm-up).
55
alignas
(
sizeof
(int32_t) * 4) History history_l_{};
56
alignas
(
sizeof
(int32_t) * 4) History history_r_{};
57
size_t
head_ = 0;
58
};
59
}
// namespace deluge::dsp
StereoSample
Definition
stereo_sample.h:25
deluge::dsp::Interpolator::l
constexpr int16_t l(size_t i) const
The i-th most recent sample, where 0 is the newest.
Definition
interpolate.h:17
deluge::dsp::Interpolator::push
constexpr void push(int16_t left, int16_t right)
Adds a newer sample, dropping the oldest. For mono, right is ignored.
Definition
interpolate.h:24
deluge::dsp::Interpolator::jumpForward
constexpr void jumpForward(size_t num_samples)
Definition
interpolate.h:32