sfFDN
Loading...
Searching...
No Matches
fdn.h
1// Copyright (C) 2025 Alexandre St-Onge
2// SPDX-License-Identifier: MIT
3#pragma once
4
5#include "attributes.h"
6#include "audio_buffer.h"
7#include "audio_processor.h"
8#include "delaybank.h"
9
10#include <cstddef>
11#include <cstdint>
12#include <span>
13
14namespace sfFDN
15{
16
18class FDN : public AudioProcessor
19{
20 public:
28 FDN(uint32_t order, uint32_t block_size, bool transpose = false);
29
30 ~FDN() override = default;
31
32 FDN(const FDN&) = delete;
33 FDN& operator=(const FDN&) = delete;
34
37 FDN(FDN&& other) noexcept;
38
42 FDN& operator=(FDN&& other) noexcept;
43
49 void SetOrder(uint32_t order);
50
54 uint32_t GetOrder() const;
55
62 void SetTranspose(bool transpose);
63
70 bool GetTranspose() const;
71
82 bool SetInputGains(std::unique_ptr<AudioProcessor> gains);
83
92 bool SetOutputGains(std::unique_ptr<AudioProcessor> gains);
93
103 bool SetInputGains(std::span<const float> gains);
104
115 bool SetOutputGains(std::span<const float> gains);
116
121
126
129 void SetDirectGain(float gain);
130
139 bool SetLoopFilter(std::unique_ptr<AudioProcessor> filter_bank);
140
145
151 bool SetDelayBank(const DelayBankOptions& config);
152
160 bool SetDelays(std::span<const float> delays,
162
166 const DelayBank& GetDelayBank() const;
167
175 bool SetFeedbackMatrix(std::unique_ptr<AudioProcessor> mixing_matrix);
176
181
190 bool SetTCFilter(std::unique_ptr<AudioProcessor> filter);
191
196
204 void Process(const AudioBuffer& input, AudioBuffer& output) noexcept SFFDN_NONBLOCKING override;
205
209 uint32_t InputChannelCount() const noexcept SFFDN_NONBLOCKING override
210 {
211 return 1;
212 }
213
217 uint32_t OutputChannelCount() const noexcept SFFDN_NONBLOCKING override
218 {
219 return 1;
220 }
221
225 void Clear() override;
226
230 std::unique_ptr<AudioProcessor> Clone() const override;
231
235 std::unique_ptr<FDN> CloneFDN() const;
236
237 private:
238 void TickInternal(const AudioBuffer& input, AudioBuffer& output) noexcept SFFDN_NONBLOCKING;
239 void Tick(const AudioBuffer& input, AudioBuffer& output) noexcept SFFDN_NONBLOCKING;
240 void TickTranspose(const AudioBuffer& input, AudioBuffer& output) noexcept SFFDN_NONBLOCKING;
241 void TickTransposeInternal(const AudioBuffer& input, AudioBuffer& output) noexcept SFFDN_NONBLOCKING;
242
243 DelayBank delay_bank_;
244 std::unique_ptr<AudioProcessor> filter_bank_;
245 std::unique_ptr<AudioProcessor> mixing_matrix_;
246
247 std::unique_ptr<AudioProcessor> input_gains_;
248 std::unique_ptr<AudioProcessor> output_gains_;
249
250 uint32_t order_;
251 uint32_t block_size_;
252 float direct_gain_;
253
254 std::vector<float> feedback_;
255 std::vector<float> temp_buffer_;
256
257 std::unique_ptr<AudioProcessor> tc_filter_;
258
259 bool transpose_;
260};
261} // 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 bank of parallel delay lines, each with its own delay setting.
Definition delaybank.h:26
FDN (Feedback Delay Network) class.
Definition fdn.h:19
const DelayBank & GetDelayBank() const
Get the Delay Bank.
FDN(FDN &&other) noexcept
Move constructor for the FDN.
AudioProcessor * GetFeedbackMatrix() const
Get the Feedback Matrix AudioProcessor.
AudioProcessor * GetTCFilter() const
Get the Tone Correction Filter AudioProcessor.
bool GetTranspose() const
Get whether the FDN is using transposed configuration.
uint32_t GetOrder() const
Get the FDN's order (number of channels).
uint32_t OutputChannelCount() const noexcept SFFDN_NONBLOCKING override
Returns the number of output channels this processor produces.
Definition fdn.h:217
uint32_t InputChannelCount() const noexcept SFFDN_NONBLOCKING override
Returns the number of input channels this processor expects.
Definition fdn.h:209
bool SetOutputGains(std::unique_ptr< AudioProcessor > gains)
Set the Output Gains AudioProcessor.
AudioProcessor * GetOutputGains() const
Get the Output Gains AudioProcessor.
bool SetTCFilter(std::unique_ptr< AudioProcessor > filter)
Set the Tone Correction Filter AudioProcessor.
bool SetDelayBank(const DelayBankOptions &config)
Set the delay bank.
void SetDirectGain(float gain)
Set the direct gain applied to the input signal when mixed to the output.
std::unique_ptr< AudioProcessor > Clone() const override
Creates a copy of the FDN.
bool SetLoopFilter(std::unique_ptr< AudioProcessor > filter_bank)
Set the Filter Bank AudioProcessor.
std::unique_ptr< FDN > CloneFDN() const
Creates a copy of the FDN.
FDN & operator=(FDN &&other) noexcept
Move assignment operator for the FDN.
bool SetOutputGains(std::span< const float > gains)
Set the Output Gains from a span of floats.
bool SetInputGains(std::span< const float > gains)
Set the Input Gains from a span of floats.
bool SetInputGains(std::unique_ptr< AudioProcessor > gains)
Set the Input Gains AudioProcessor.
bool SetFeedbackMatrix(std::unique_ptr< AudioProcessor > mixing_matrix)
Set the Feedback Matrix AudioProcessor.
void Process(const AudioBuffer &input, AudioBuffer &output) noexcept SFFDN_NONBLOCKING override
Process audio buffers.
void SetTranspose(bool transpose)
Set whether to use transposed configuration.
AudioProcessor * GetLoopFilter() const
Get the Filter Bank AudioProcessor.
void SetOrder(uint32_t order)
Set the number of channels of the FDN.
bool SetDelays(std::span< const float > delays, DelayInterpolationType interpolation_type=DelayInterpolationType::None)
Set the delays.
void Clear() override
Clears the internal state of the FDN.
FDN(uint32_t order, uint32_t block_size, bool transpose=false)
Constructs an FDN with a specified order (number of channels).
AudioProcessor * GetInputGains() const
Get the Input Gains AudioProcessor.
DelayInterpolationType
Types of interpolation for fractional delay lengths.
Definition types.h:67
@ None
No interpolation. The delay length will be rounded to the nearest integer value.
Options for configuring a delay bank.
Definition types.h:232