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/types.h"
10
11#include <cstddef>
12#include <cstdint>
13#include <span>
14
15namespace sfFDN
16{
17
23{
24 public:
26 SchroederAllpass() = default;
27
32 SchroederAllpass(uint32_t delay, float g);
33
34 SchroederAllpass(const SchroederAllpass&) = delete;
35 SchroederAllpass& operator=(const SchroederAllpass&) = delete;
36
40
45
46 ~SchroederAllpass() = default;
47
51 void SetDelay(uint32_t delay);
52
56 void SetG(float g);
57
59 uint32_t GetDelay() const
60 {
61 return delay_.GetDelay();
62 }
63
65 float GetG() const
66 {
67 return g_;
68 }
69
74 float Tick(float input);
75
81 void ProcessBlock(std::span<const float> in, std::span<float> out);
82
88 void ProcessBlockAccumulate(std::span<const float> in, std::span<float> out);
89
93 void Clear();
94
95 private:
96 Delay delay_;
97 float g_{};
98
99 void Tick8(std::span<const float, 8> in, std::span<float, 8> out);
100};
101
104{
105 public:
108
113
117 SchroederAllpassSection(uint32_t filter_count);
118
120 SchroederAllpassSection& operator=(const SchroederAllpassSection&) = delete;
121
125
130
131 ~SchroederAllpassSection() = default;
132
136 void SetFilterCount(uint32_t filter_count);
137
141 void SetParallel(bool parallel);
142
147 void SetDelays(std::span<const uint32_t> delays);
148
153 void SetGains(std::span<const float> gains);
154
158 void SetGain(float gain);
159
161 std::vector<uint32_t> GetDelays() const;
162
164 std::vector<float> GetGains() const;
165
171 void Process(const AudioBuffer& input, AudioBuffer& output) noexcept override;
172
176 uint32_t InputChannelCount() const override;
177
181 uint32_t OutputChannelCount() const override;
182
186 void Clear() override;
187
191 std::unique_ptr<AudioProcessor> Clone() const override;
192
193 private:
194 std::vector<SchroederAllpass> allpasses_;
195 bool parallel_ = false;
196};
197
198std::unique_ptr<FilterBank> MakeMultichannelSchroederAllpassSection(
200
201// /** \brief Implements parallel Schroeder allpass sections. */
202// class ParallelSchroederAllpassSection : public AudioProcessor
203// {
204// public:
205// /** \brief Constructs a ParallelSchroederAllpassSection with a given number of channels and stages.
206// * @param channel_count The number of parallel channels.
207// * @param stage_count The number of allpass filters in each channel.
208// */
209// ParallelSchroederAllpassSection(uint32_t channel_count, uint32_t stage_count);
210
211// ParallelSchroederAllpassSection(const ParallelSchroederAllpassSection&) = delete;
212// ParallelSchroederAllpassSection& operator=(const ParallelSchroederAllpassSection&) = delete;
213
214// ParallelSchroederAllpassSection(ParallelSchroederAllpassSection&&) noexcept;
215// ParallelSchroederAllpassSection& operator=(ParallelSchroederAllpassSection&&) noexcept;
216
217// /** @brief Sets the delays for each allpass filter in the section.
218// * @param delays A span of delay values in samples.
219// * The size of the span must be equal to (channel_count * stage_count).
220// */
221// void SetDelays(std::span<const uint32_t> delays);
222
223// /** @brief Sets the feedback gains for each allpass filter in the section.
224// * @param gains A span of feedback gain values.
225// * The size of the span must be equal to (channel_count * stage_count).
226// */
227// void SetGains(std::span<const float> gains);
228
229// /** @brief Processes a block of audio through the section.
230// * @param input The input audio buffer.
231// * @param output The output audio buffer.
232// * The input and output buffers must have the same number of samples and channels equal to InputChannelCount().
233// */
234// void Process(const AudioBuffer& input, AudioBuffer& output) noexcept override;
235
236// /** @brief Gets the number of input channels supported.*/
237// uint32_t InputChannelCount() const override;
238
239// /** @brief Gets the number of output channels supported.*/
240// uint32_t OutputChannelCount() const override;
241
242// /** @brief Clears the internal state of the processor.
243// * This function resets the internal state of all allpass filters in the section.
244// */
245// void Clear() override;
246
247// /** @brief Creates a copy of the ParallelSchroederAllpassSection.
248// * @return A unique pointer to the cloned ParallelSchroederAllpassSection.
249// */
250// std::unique_ptr<AudioProcessor> Clone() const override;
251
252// private:
253// std::vector<SchroederAllpassSection> allpasses_;
254// uint32_t stage_count_;
255// };
256} // namespace sfFDN
A class representing an audio buffer with multiple channels of non-interleaved audio data.
Definition audio_buffer.h:18
Base class for audio processors.
Definition audio_processor.h:23
A simple non-interpolating delay line implementation.
Definition delay.h:16
uint32_t GetDelay(void) const
Returns the current delay in samples.
Definition delay.h:49
Implements a bank of filters.
Definition filterbank.h:19
A section of Schroeder allpass filters in series.
Definition schroeder_allpass.h:104
SchroederAllpassSection(SchroederAllpassSection &&) noexcept
Move constructor for the SchroederAllpassSection.
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.
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 Process(const AudioBuffer &input, AudioBuffer &output) noexcept override
Processes a block of audio through the section.
void SetFilterCount(uint32_t filter_count)
Sets the number of allpass filters in the section.
uint32_t OutputChannelCount() const 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.
uint32_t InputChannelCount() const override
Gets the number of input channels supported.
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:23
void SetDelay(uint32_t delay)
Sets the delay in samples.
SchroederAllpass(uint32_t delay, float g)
Constructs a SchroederAllpass 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:65
SchroederAllpass()=default
Constructs a SchroederAllpass filter.
uint32_t GetDelay() const
Gets the current delay in samples.
Definition schroeder_allpass.h:59
void ProcessBlockAccumulate(std::span< const float > in, std::span< float > out)
Processes a block of samples through the filter and accumulates the output.
void ProcessBlock(std::span< const float > in, std::span< float > out)
Processes a block of samples through the filter.
float Tick(float input)
Processes a single sample through the filter.
SchroederAllpass & operator=(SchroederAllpass &&)=default
Move assignment operator for the SchroederAllpass filter.
void SetG(float g)
Sets the feedback gain.
Options for configuring a multichannel bank of Schroeder allpass sections.
Definition types.h:287
Options for configuring a Schroeder allpass section consisting of N Schroeder allpass in series or in...
Definition types.h:276