Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
interp.hpp
Go to the documentation of this file.
1#pragma once
2
3// Fractional-position reconstruction shared by the resampler, the modulated
4// delay lines, and the ensemble chorus.
5//
6// 4-point Hermite is the engine's one interpolator. It is not band-limited on
7// its own — the anti-alias / reconstruction filters carry that job — but it has
8// a continuous first derivative, which is what keeps a swept read position from
9// producing the zipper that linear interpolation gives on a slow sweep.
10
12
13#include <array>
14#include <cstddef>
15
16namespace pulp::signal::fdn {
17
18// y0..y3 straddle the read position; t in [0, 1) is the fraction between y1
19// and y2.
20//
21// The arithmetic is signal::Interpolator::hermite — this is an argument-order
22// adapter, not a second implementation. The shared entry point names its points
23// by position relative to the sample being read (ym1, y0, y1, y2), which reads
24// naturally at a call site that already has an index; a ring buffer walking
25// four consecutive taps has no such index, so the callers here are clearer with
26// a flat y0..y3. One curve, two spellings of the same four points.
27inline double hermite4(double y0, double y1, double y2, double y3, double t) {
28 return Interpolator::hermite<double>(t, y0, y1, y2, y3);
29}
30
31// The same curve at the caller's precision — the block kernels' spelling.
32template <typename T> inline T hermite4_t(T y0, T y1, T y2, T y3, T t) {
33 return Interpolator::hermite<T>(t, y0, y1, y2, y3);
34}
35
36// A 4-sample sliding window over a source stream, for consumers that pull
37// samples one at a time rather than indexing a buffer (the resampler).
39public:
40 void reset() { h_ = {0.0, 0.0, 0.0, 0.0}; }
41
42 void push(double sample) {
43 h_[0] = h_[1];
44 h_[1] = h_[2];
45 h_[2] = h_[3];
46 h_[3] = sample;
47 }
48
49 // `t` is the fraction past h_[2] — the most recent fully-arrived sample —
50 // toward h_[3], so a read never needs a sample that has not been pushed.
51 double read(double t) const { return hermite4(h_[0], h_[1], h_[2], h_[3], t); }
52
53private:
54 std::array<double, 4> h_{};
55};
56
57} // namespace pulp::signal::fdn
Definition interp.hpp:38
double read(double t) const
Definition interp.hpp:51
void reset()
Definition interp.hpp:40
void push(double sample)
Definition interp.hpp:42
High-quality sample interpolation for delay lines and resampling.
Definition config.hpp:15
T hermite4_t(T y0, T y1, T y2, T y3, T t)
Definition interp.hpp:32
double hermite4(double y0, double y1, double y2, double y3, double t)
Definition interp.hpp:27
static SampleType hermite(SampleType frac, SampleType ym1, SampleType y0, SampleType y1, SampleType y2)
Cubic Hermite (Catmull-Rom) interpolation.
Definition interpolator.hpp:41