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 "audio_buffer.h"
6#include "audio_processor.h"
7#include "delaybank.h"
8
9#include <cstddef>
10#include <cstdint>
11#include <span>
12
13namespace sfFDN
14{
15
17class FDN : public AudioProcessor
18{
19 public:
27 FDN(uint32_t order, uint32_t block_size = 0, bool transpose = false);
28
29 ~FDN() = default;
30
31 FDN(const FDN&) = delete;
32 FDN& operator=(const FDN&) = delete;
33
36 FDN(FDN&&) noexcept;
37
41 FDN& operator=(FDN&&) noexcept;
42
48 void SetOrder(uint32_t order);
49
53 uint32_t GetOrder() const;
54
61 void SetTranspose(bool transpose);
62
69 bool GetTranspose() const;
70
81 bool SetInputGains(std::unique_ptr<AudioProcessor> gains);
82
91 bool SetOutputGains(std::unique_ptr<AudioProcessor> gains);
92
102 bool SetInputGains(std::span<const float> gains);
103
114 bool SetOutputGains(std::span<const float> gains);
115
120
125
128 void SetDirectGain(float gain);
129
138 bool SetLoopFilter(std::unique_ptr<AudioProcessor> filter_bank);
139
144
150 bool SetDelayBank(const DelayBankOptions& config);
151
159 bool SetDelays(const std::span<const float> delays,
161
165 const DelayBank& GetDelayBank() const;
166
174 bool SetFeedbackMatrix(std::unique_ptr<AudioProcessor> mixing_matrix);
175
180
189 bool SetTCFilter(std::unique_ptr<AudioProcessor> filter);
190
195
203 void Process(const AudioBuffer& input, AudioBuffer& output) noexcept override;
204
208 uint32_t InputChannelCount() const override
209 {
210 return 1;
211 }
212
216 uint32_t OutputChannelCount() const override
217 {
218 return 1;
219 }
220
224 void Clear() override;
225
229 std::unique_ptr<AudioProcessor> Clone() const override;
230
234 std::unique_ptr<FDN> CloneFDN() const;
235
236 private:
237 void TickInternal(const AudioBuffer& input, AudioBuffer& output);
238 void Tick(const AudioBuffer& input, AudioBuffer& output);
239 void TickTranspose(const AudioBuffer& input, AudioBuffer& output);
240 void TickTransposeInternal(const AudioBuffer& input, AudioBuffer& output);
241
242 DelayBank delay_bank_;
243 std::unique_ptr<AudioProcessor> filter_bank_;
244 std::unique_ptr<AudioProcessor> mixing_matrix_;
245
246 std::unique_ptr<AudioProcessor> input_gains_;
247 std::unique_ptr<AudioProcessor> output_gains_;
248
249 uint32_t order_;
250 uint32_t block_size_;
251 float direct_gain_;
252
253 std::vector<float> feedback_;
254 std::vector<float> temp_buffer_;
255
256 std::unique_ptr<AudioProcessor> tc_filter_;
257
258 bool transpose_;
259};
260} // 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 bank of parallel delay lines, each with its own delay setting.
Definition delaybank.h:26
FDN (Feedback Delay Network) class.
Definition fdn.h:18
const DelayBank & GetDelayBank() const
Get the Delay Bank.
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).
FDN(FDN &&) noexcept
Move constructor for the FDN.
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.
uint32_t InputChannelCount() const override
Returns the number of input channels this processor expects.
Definition fdn.h:208
FDN(uint32_t order, uint32_t block_size=0, bool transpose=false)
Constructs an FDN with a specified order (number of channels).
bool SetLoopFilter(std::unique_ptr< AudioProcessor > filter_bank)
Set the Filter Bank AudioProcessor.
void Process(const AudioBuffer &input, AudioBuffer &output) noexcept override
Process audio buffers.
std::unique_ptr< FDN > CloneFDN() const
Creates a copy of the FDN.
bool SetDelays(const std::span< const float > delays, DelayInterpolationType interpolation_type=DelayInterpolationType::None)
Set the delays.
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 SetTranspose(bool transpose)
Set whether to use transposed configuration.
AudioProcessor * GetLoopFilter() const
Get the Filter Bank AudioProcessor.
uint32_t OutputChannelCount() const override
Returns the number of output channels this processor produces.
Definition fdn.h:216
void SetOrder(uint32_t order)
Set the number of channels of the FDN.
void Clear() override
Clears the internal state of the FDN.
AudioProcessor * GetInputGains() const
Get the Input Gains AudioProcessor.
DelayInterpolationType
Types of interpolation for fractional delay lengths.
Definition types.h:65
@ None
No interpolation. The delay length will be rounded to the nearest integer value.
Options for configuring a delay bank.
Definition types.h:198