sfFDN
Loading...
Searching...
No Matches
delay_interp.h
1// Copyright (C) 2025 Alexandre St-Onge
2// SPDX-License-Identifier: MIT
3#pragma once
4
5#include "sffdn/audio_buffer.h"
6#include "sffdn/audio_processor.h"
7#include "sffdn/delay.h"
8#include "sffdn/filter.h"
9#include "sffdn/types.h"
10
11#include <array>
12#include <cstddef>
13#include <cstdint>
14
15namespace sfFDN
16{
17
23{
24 public:
29 DelayInterp(const DelayOptions& config = {});
30
32 void Clear() override;
33
35 uint32_t GetMaximumDelay() const;
36
41 void SetMaximumDelay(uint32_t delay);
42
49 void SetDelay(float delay) noexcept SFFDN_NONBLOCKING;
50
52 float GetDelay() const;
53
59 float Tick(float input) noexcept SFFDN_NONBLOCKING;
60
72 float NextOut() noexcept SFFDN_NONBLOCKING;
73
79 void Advance(float input) noexcept SFFDN_NONBLOCKING;
80
89 float TapOut(uint32_t tap) const noexcept SFFDN_NONBLOCKING;
90
96 void Process(const AudioBuffer& input, AudioBuffer& output) noexcept SFFDN_NONBLOCKING override;
97
106 bool AddNextInputs(std::span<const float> input) noexcept SFFDN_NONBLOCKING;
107
116 void GetNextOutputs(std::span<float> output) noexcept SFFDN_NONBLOCKING;
117
118 uint32_t InputChannelCount() const noexcept SFFDN_NONBLOCKING override
119 {
120 return 1;
121 }
122
123 uint32_t OutputChannelCount() const noexcept SFFDN_NONBLOCKING override
124 {
125 return 1;
126 }
127
128 std::unique_ptr<AudioProcessor> Clone() const override;
129
130 private:
131 static constexpr std::size_t kLagrangeOrder = 3;
132 static constexpr std::size_t kLagrangeTapCount = kLagrangeOrder + 1;
133
134 Delay delayline_;
135
136 float delay_;
137 uint32_t int_delay_;
138 float frac_delay_;
140
141 AllpassFilter allpass_;
142
143 std::array<float, kLagrangeTapCount> lagrange_coeffs_{};
144 float linear_last_out_;
145
146 float next_out_ = 0.f;
147 bool has_next_out_ = false;
148};
149
150} // namespace sfFDN
Implements a simple allpass filter with differential equation .
Definition filter.h:100
A class representing an audio buffer with multiple channels of non-interleaved audio data.
Definition audio_buffer.h:20
Base class for audio processors.
Definition audio_processor.h:24
Delay line with interpolation.
Definition delay_interp.h:23
void GetNextOutputs(std::span< float > output) noexcept SFFDN_NONBLOCKING
Gets the next output samples from the delay line.
void SetMaximumDelay(uint32_t delay)
Sets the maximum delay for the delay line.
DelayInterp(const DelayOptions &config={})
Constructs a delay line with interpolation.
bool AddNextInputs(std::span< const float > input) noexcept SFFDN_NONBLOCKING
Adds the next input samples to the delay line.
float TapOut(uint32_t tap) const noexcept SFFDN_NONBLOCKING
Taps the delay line at a fixed integer delay, without interpolation.
uint32_t GetMaximumDelay() const
Gets the maximum delay-line length.
void Clear() override
Clears all internal states of the delay line.
float GetDelay() const
Returns the current delay in samples.
std::unique_ptr< AudioProcessor > Clone() const override
Creates a copy of the audio processor.
uint32_t OutputChannelCount() const noexcept SFFDN_NONBLOCKING override
Returns the number of output channels this processor produces.
Definition delay_interp.h:123
uint32_t InputChannelCount() const noexcept SFFDN_NONBLOCKING override
Returns the number of input channels this processor expects.
Definition delay_interp.h:118
float NextOut() noexcept SFFDN_NONBLOCKING
Returns the next output sample without writing a new input sample.
void Process(const AudioBuffer &input, AudioBuffer &output) noexcept SFFDN_NONBLOCKING override
Processes a block of input samples.
void SetDelay(float delay) noexcept SFFDN_NONBLOCKING
Sets the delay for the delay line.
float Tick(float input) noexcept SFFDN_NONBLOCKING
Processes a single sample through the delay line.
void Advance(float input) noexcept SFFDN_NONBLOCKING
Writes the next input sample into the delay line and advances it.
A simple non-interpolating delay line implementation.
Definition delay.h:17
DelayInterpolationType
Types of interpolation for fractional delay lengths.
Definition types.h:67
Options for configuring delays.
Definition types.h:219