sfFDN
Loading...
Searching...
No Matches
delay.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
8#include <cstdint>
9#include <span>
10#include <vector>
11
12namespace sfFDN
13{
14
16class Delay
17{
18 public:
24 Delay(uint32_t delay = 0, uint32_t max_delay = 4095);
25
27 void Clear();
28
35 void SetMaximumDelay(uint32_t delay);
36
41 uint32_t GetMaximumDelay() const noexcept SFFDN_NONBLOCKING;
42
47 void SetDelay(uint32_t delay) noexcept SFFDN_NONBLOCKING;
48
50 uint32_t GetDelay() const noexcept SFFDN_NONBLOCKING
51 {
52 return delay_;
53 };
54
59 float LastOut() const noexcept SFFDN_NONBLOCKING;
60
65 float NextOut() const noexcept SFFDN_NONBLOCKING;
66
72 float Tick(float input) noexcept SFFDN_NONBLOCKING;
73
79 float TapOut(uint32_t tap) const noexcept SFFDN_NONBLOCKING;
80
88 void Process(AudioBuffer input, AudioBuffer& output) noexcept SFFDN_NONBLOCKING;
89
98 bool AddNextInputs(std::span<const float> input) noexcept SFFDN_NONBLOCKING;
99
101 bool CanAddNextInputs(size_t sample_count) const noexcept SFFDN_NONBLOCKING;
102
109 void GetNextOutputs(std::span<float> output) noexcept SFFDN_NONBLOCKING;
110
117 void GetNextOutputsAt(std::span<uint32_t> taps, std::span<float> output,
118 std::span<float> coeffs) noexcept SFFDN_NONBLOCKING;
119
128 std::span<float> GetNextOutputBuffers(uint32_t size) noexcept SFFDN_NONBLOCKING;
129
138 std::span<float> GetNextInputBuffers(uint32_t size) noexcept SFFDN_NONBLOCKING;
139
146 void GetNextReadAndWriteBuffers(std::span<float>& read_buffer, std::span<float>& write_buffer,
147 uint32_t size) noexcept SFFDN_NONBLOCKING;
148
154 void AdvanceWrite(uint32_t sample_count) noexcept SFFDN_NONBLOCKING;
155
161 void AdvanceRead(uint32_t sample_count) noexcept SFFDN_NONBLOCKING;
162
163 private:
164 size_t GetAvailableReadCount() const noexcept SFFDN_NONBLOCKING;
165 size_t GetAvailableWriteCount() const noexcept SFFDN_NONBLOCKING;
166
167 uint32_t in_point_;
168 uint32_t out_point_;
169 uint32_t delay_;
170 std::vector<float> buffer_;
171 float last_frame_;
172};
173
174} // namespace sfFDN
A class representing an audio buffer with multiple channels of non-interleaved audio data.
Definition audio_buffer.h:20
A simple non-interpolating delay line implementation.
Definition delay.h:17
float Tick(float input) noexcept SFFDN_NONBLOCKING
Processes the next input sample.
uint32_t GetMaximumDelay() const noexcept SFFDN_NONBLOCKING
Gets the maximum delay-line length.
void AdvanceWrite(uint32_t sample_count) noexcept SFFDN_NONBLOCKING
Advances the write pointer of the delay line by a specified number of samples.
uint32_t GetDelay() const noexcept SFFDN_NONBLOCKING
Returns the current delay in samples.
Definition delay.h:50
std::span< float > GetNextOutputBuffers(uint32_t size) noexcept SFFDN_NONBLOCKING
Get a span pointing to the next writable region of the buffer.
std::span< float > GetNextInputBuffers(uint32_t size) noexcept SFFDN_NONBLOCKING
Get a span pointing to the next writable region of the buffer.
void GetNextOutputsAt(std::span< uint32_t > taps, std::span< float > output, std::span< float > coeffs) noexcept SFFDN_NONBLOCKING
Gets the next output samples from the delay line at specific tap points.
bool AddNextInputs(std::span< const float > input) noexcept SFFDN_NONBLOCKING
Adds the next input samples to the delay line.
float NextOut() const noexcept SFFDN_NONBLOCKING
Returns the next output sample.
void AdvanceRead(uint32_t sample_count) noexcept SFFDN_NONBLOCKING
Advances the read pointer of the delay line by a specified number of samples.
void SetDelay(uint32_t delay) noexcept SFFDN_NONBLOCKING
Sets the delay for the delay line.
bool CanAddNextInputs(size_t sample_count) const noexcept SFFDN_NONBLOCKING
Returns whether the complete input block can be added without overwriting unread samples.
void GetNextReadAndWriteBuffers(std::span< float > &read_buffer, std::span< float > &write_buffer, uint32_t size) noexcept SFFDN_NONBLOCKING
Gets the next read and write buffers for the delay line.
float TapOut(uint32_t tap) const noexcept SFFDN_NONBLOCKING
Taps the output of the delay line at a specific point.
Delay(uint32_t delay=0, uint32_t max_delay=4095)
Constructs a delay line with a specified delay and maximum delay.
void GetNextOutputs(std::span< float > output) noexcept SFFDN_NONBLOCKING
Gets the next output samples from the delay line.
void Process(AudioBuffer input, AudioBuffer &output) noexcept SFFDN_NONBLOCKING
Processes a block of input samples.
void Clear()
Clears the delay line, resetting the internal buffer.
float LastOut() const noexcept SFFDN_NONBLOCKING
Returns the last output sample from the delay line.
void SetMaximumDelay(uint32_t delay)
Sets the maximum delay for the delay line.