sfFDN
Loading...
Searching...
No Matches
schroeder_allpass.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/filterbank.h"
9#include "sffdn/oscillator.h"
10#include "sffdn/types.h"
11
12#include <cstddef>
13#include <cstdint>
14#include <span>
15
16namespace sfFDN
17{
18
24{
25 public:
27 SchroederAllpass() = default;
28
33 SchroederAllpass(uint32_t delay, float g);
34
35 SchroederAllpass(const SchroederAllpass&) = delete;
36 SchroederAllpass& operator=(const SchroederAllpass&) = delete;
37
41
46
47 ~SchroederAllpass() = default;
48
52 void SetDelay(uint32_t delay);
53
57 void SetG(float g);
58
60 uint32_t GetDelay() const
61 {
62 return delay_.GetDelay();
63 }
64
66 float GetG() const
67 {
68 return g_;
69 }
70
75 float Tick(float input) noexcept SFFDN_NONBLOCKING;
76
82 void ProcessBlock(std::span<const float> in, std::span<float> out) noexcept SFFDN_NONBLOCKING;
83
89 void ProcessBlockAccumulate(std::span<const float> in, std::span<float> out) noexcept SFFDN_NONBLOCKING;
90
94 void Clear();
95
96 private:
97 Delay delay_;
98 float g_{};
99
100 void Tick8(std::span<const float, 8> in, std::span<float, 8> out) noexcept SFFDN_NONBLOCKING;
101};
102
115{
116 public:
122 TimeVaryingSchroederAllpass(uint32_t delay, float gain, const ModulationOptions& modulation);
123
127 void SetDelay(uint32_t delay);
128
130 uint32_t GetDelay() const noexcept SFFDN_NONBLOCKING
131 {
132 return delay_.GetDelay();
133 }
134
136 float GetG() const noexcept SFFDN_NONBLOCKING
137 {
138 return gain_;
139 }
140
142 float Tick(float input) noexcept SFFDN_NONBLOCKING;
143
149 float Tick(float input, float gain) noexcept SFFDN_NONBLOCKING;
150
152 void ProcessBlock(std::span<const float> in, std::span<float> out) noexcept SFFDN_NONBLOCKING;
153
155 void ProcessBlockAccumulate(std::span<const float> in, std::span<float> out) noexcept SFFDN_NONBLOCKING;
156
158 void Clear();
159
160 private:
161 Delay delay_;
162 SineWave lfo_;
163 float gain_;
164};
165
168{
169 public:
172
177
181 SchroederAllpassSection(uint32_t filter_count);
182
184 SchroederAllpassSection& operator=(const SchroederAllpassSection&) = delete;
185
189
194
195 ~SchroederAllpassSection() override = default;
196
200 void SetFilterCount(uint32_t filter_count);
201
205 void SetParallel(bool parallel);
206
211 void SetDelays(std::span<const uint32_t> delays);
212
217 void SetGains(std::span<const float> gains);
218
222 void SetGain(float gain);
223
225 std::vector<uint32_t> GetDelays() const;
226
228 std::vector<float> GetGains() const;
229
235 void Process(const AudioBuffer& input, AudioBuffer& output) noexcept SFFDN_NONBLOCKING override;
236
240 uint32_t InputChannelCount() const noexcept SFFDN_NONBLOCKING override;
241
245 uint32_t OutputChannelCount() const noexcept SFFDN_NONBLOCKING override;
246
250 void Clear() override;
251
255 std::unique_ptr<AudioProcessor> Clone() const override;
256
257 private:
258 std::vector<SchroederAllpass> allpasses_;
259 bool parallel_ = false;
260};
261
262std::unique_ptr<FilterBank> MakeMultichannelSchroederAllpassSection(
264
267{
268 public:
273
278 ~TimeVaryingSchroederAllpassSection() override = default;
279
280 void Process(const AudioBuffer& input, AudioBuffer& output) noexcept SFFDN_NONBLOCKING override;
281 uint32_t InputChannelCount() const noexcept SFFDN_NONBLOCKING override;
282 uint32_t OutputChannelCount() const noexcept SFFDN_NONBLOCKING override;
283 void Clear() override;
284 std::unique_ptr<AudioProcessor> Clone() const override;
285
286 private:
287 std::vector<TimeVaryingSchroederAllpass> allpasses_;
288 bool parallel_{false};
289};
290
292std::unique_ptr<FilterBank> MakeMultichannelTimeVaryingSchroederAllpassSection(
293 const MultichannelTimeVaryingSchroederAllpassSectionOptions& options);
294
295} // namespace sfFDN
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
A simple non-interpolating delay line implementation.
Definition delay.h:17
uint32_t GetDelay() const noexcept SFFDN_NONBLOCKING
Returns the current delay in samples.
Definition delay.h:50
Implements a bank of filters.
Definition filterbank.h:19
A section of Schroeder allpass filters in series.
Definition schroeder_allpass.h:168
void SetDelays(std::span< const uint32_t > delays)
Sets the delays for each allpass filter in the section.
SchroederAllpassSection(const SchroederAllpassSectionOptions &config)
Constructs a SchroederAllpassSection with a given configuration.
uint32_t InputChannelCount() const noexcept SFFDN_NONBLOCKING override
Gets the number of input channels supported.
void SetGains(std::span< const float > gains)
Sets the feedback gains for each allpass filter in the section.
std::unique_ptr< AudioProcessor > Clone() const override
Creates a copy of the SchroederAllpassSection.
void SetGain(float gain)
Sets the feedback gain for all allpass filters in the section.
std::vector< uint32_t > GetDelays() const
Gets the current delays for each allpass filter in the section.
void SetFilterCount(uint32_t filter_count)
Sets the number of allpass filters in the section.
SchroederAllpassSection & operator=(SchroederAllpassSection &&other) noexcept
Move assignment operator for the SchroederAllpassSection.
uint32_t OutputChannelCount() const noexcept SFFDN_NONBLOCKING override
Gets the number of output channels supported.
void SetParallel(bool parallel)
Sets whether the allpass filters in the section are processed in parallel.
void Clear() override
Clears the internal state of the processor.
SchroederAllpassSection()=default
Constructs an empty SchroederAllpassSection.
SchroederAllpassSection(SchroederAllpassSection &&other) noexcept
Move constructor for the SchroederAllpassSection.
void Process(const AudioBuffer &input, AudioBuffer &output) noexcept SFFDN_NONBLOCKING override
Processes a block of audio through the section.
SchroederAllpassSection(uint32_t filter_count)
Constructs a SchroederAllpassSection with a given number of filters.
std::vector< float > GetGains() const
Gets the current feedback gains for each allpass filter in the section.
A single Schroeder allpass filter.
Definition schroeder_allpass.h:24
void SetDelay(uint32_t delay)
Sets the delay in samples.
SchroederAllpass(uint32_t delay, float g)
Constructs a SchroederAllpass filter.
float Tick(float input) noexcept SFFDN_NONBLOCKING
Processes a single sample through the filter.
SchroederAllpass(SchroederAllpass &&)=default
Move constructor for the SchroederAllpass filter.
void Clear()
Clears the filter state.
float GetG() const
Gets the filter gain.
Definition schroeder_allpass.h:66
void ProcessBlock(std::span< const float > in, std::span< float > out) noexcept SFFDN_NONBLOCKING
Processes a block of samples through the filter.
SchroederAllpass()=default
Constructs a SchroederAllpass filter.
uint32_t GetDelay() const
Gets the current delay in samples.
Definition schroeder_allpass.h:60
void ProcessBlockAccumulate(std::span< const float > in, std::span< float > out) noexcept SFFDN_NONBLOCKING
Processes a block of samples through the filter and accumulates the output.
SchroederAllpass & operator=(SchroederAllpass &&)=default
Move assignment operator for the SchroederAllpass filter.
void SetG(float g)
Sets the feedback gain.
A sine wave oscillator.
Definition oscillator.h:33
A single-channel section of energy-preserving time-varying Schroeder allpasses.
Definition schroeder_allpass.h:267
TimeVaryingSchroederAllpassSection(const TimeVaryingSchroederAllpassSectionOptions &config)
Constructs a section from its stage configurations.
An energy-preserving Schroeder allpass with a fixed delay and optionally modulated gain.
Definition schroeder_allpass.h:115
float GetG() const noexcept SFFDN_NONBLOCKING
Returns the base gain.
Definition schroeder_allpass.h:136
TimeVaryingSchroederAllpass(uint32_t delay, float gain, const ModulationOptions &modulation)
Constructs an allpass with sinusoidal gain modulation.
void ProcessBlockAccumulate(std::span< const float > in, std::span< float > out) noexcept SFFDN_NONBLOCKING
Processes a block and accumulates the result in out.
void Clear()
Clears the delay state and restores the configured modulation phase.
float Tick(float input) noexcept SFFDN_NONBLOCKING
Processes one sample using the configured sinusoidally modulated gain.
uint32_t GetDelay() const noexcept SFFDN_NONBLOCKING
Returns the delay in samples.
Definition schroeder_allpass.h:130
float Tick(float input, float gain) noexcept SFFDN_NONBLOCKING
Processes one sample with an explicit valid gain in the open interval (-1, 1).
void ProcessBlock(std::span< const float > in, std::span< float > out) noexcept SFFDN_NONBLOCKING
Processes a block using the configured sinusoidally modulated gain.
void SetDelay(uint32_t delay)
Sets the fixed integer delay in samples.
Options for configuring signal modulation.
Definition types.h:180
Options for configuring a multichannel bank of Schroeder allpass sections.
Definition types.h:327
Options for configuring a Schroeder allpass section consisting of N Schroeder allpass in series or in...
Definition types.h:316
Options for configuring an energy-preserving time-varying Schroeder allpass section.
Definition types.h:337