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 "audio_buffer.h"
6
7#include <cstdint>
8#include <span>
9#include <vector>
10
11namespace sfFDN
12{
13
15class Delay
16{
17 public:
23 Delay(uint32_t delay = 0, uint32_t max_delay = 4095);
24
26 void Clear();
27
34 void SetMaximumDelay(uint32_t delay);
35
40 uint32_t GetMaximumDelay() const;
41
46 void SetDelay(uint32_t delay);
47
49 uint32_t GetDelay(void) const
50 {
51 return delay_;
52 };
53
58 float LastOut() const;
59
64 float NextOut() const;
65
71 float Tick(float input);
72
78 float TapOut(uint32_t tap) const;
79
87 void Process(const AudioBuffer input, AudioBuffer& output);
88
97 bool AddNextInputs(std::span<const float> input);
98
103 void GetNextOutputs(std::span<float> output);
104
111 void GetNextOutputsAt(std::span<uint32_t> taps, std::span<float> output, std::span<float> coeffs);
112
121 std::span<float> GetNextOutputBuffers(uint32_t size);
122
131 std::span<float> GetNextInputBuffers(uint32_t size);
132
139 void GetNextReadAndWriteBuffers(std::span<float>& read_buffer, std::span<float>& write_buffer, uint32_t size);
140
146 void AdvanceWrite(uint32_t sample_count);
147
153 void AdvanceRead(uint32_t sample_count);
154
155 private:
156 uint32_t in_point_;
157 uint32_t out_point_;
158 uint32_t delay_;
159 std::vector<float> buffer_;
160 float last_frame_;
161};
162
163} // namespace sfFDN
A class representing an audio buffer with multiple channels of non-interleaved audio data.
Definition audio_buffer.h:18
A simple non-interpolating delay line implementation.
Definition delay.h:16
void SetDelay(uint32_t delay)
Sets the delay for the delay line.
std::span< float > GetNextOutputBuffers(uint32_t size)
Get a span pointing to the next writable region of the buffer.
void GetNextReadAndWriteBuffers(std::span< float > &read_buffer, std::span< float > &write_buffer, uint32_t size)
Gets the next read and write buffers for the delay line.
void Process(const AudioBuffer input, AudioBuffer &output)
Processes a block of input samples.
float NextOut() const
Returns the next output sample.
uint32_t GetDelay(void) const
Returns the current delay in samples.
Definition delay.h:49
float LastOut() const
Returns the last output sample from the delay line.
bool AddNextInputs(std::span< const float > input)
Adds the next input samples to the delay line.
void AdvanceWrite(uint32_t sample_count)
Advances the write pointer of the delay line by a specified number of samples.
float TapOut(uint32_t tap) const
Taps the output of the delay line at a specific point.
uint32_t GetMaximumDelay() const
Gets the maximum delay-line length.
void AdvanceRead(uint32_t sample_count)
Advances the read pointer of the delay line by a specified number of samples.
Delay(uint32_t delay=0, uint32_t max_delay=4095)
Constructs a delay line with a specified delay and maximum delay.
float Tick(float input)
Processes the next input sample.
std::span< float > GetNextInputBuffers(uint32_t size)
Get a span pointing to the next writable region of the buffer.
void Clear()
Clears the delay line, resetting the internal buffer.
void GetNextOutputs(std::span< float > output)
Gets the next output samples from the delay line.
void SetMaximumDelay(uint32_t delay)
Sets the maximum delay for the delay line.
void GetNextOutputsAt(std::span< uint32_t > taps, std::span< float > output, std::span< float > coeffs)
Gets the next output samples from the delay line at specific tap points.