Vital
Loading...
Searching...
No Matches
delay.h
Go to the documentation of this file.
1#pragma once
2
3#include "processor.h"
4
5#include "memory.h"
6#include "one_pole_filter.h"
7
8namespace vital {
9
46 template<class MemoryType>
47 class Delay : public Processor {
48 public:
50 static constexpr mono_float kSpreadOctaveRange = 8.0f;
51 static constexpr mono_float kDefaultPeriod = 100.0f;
52 static constexpr mono_float kDelayHalfLife = 0.02f;
53 static constexpr mono_float kMinDampNote = 60.0f;
54 static constexpr mono_float kMaxDampNote = 136.0f;
55
63 return utils::max(spread * kSpreadOctaveRange * kNotesPerOctave, 0.0f);
64 }
65
67 enum {
78 };
79
91
97 Delay(int size) : Processor(Delay::kNumInputs, 1) {
98 memory_ = std::make_unique<MemoryType>(size);
99 last_frequency_ = 2.0f;
100 feedback_ = 0.0f;
101 wet_ = 0.0f;
102 dry_ = 0.0f;
103
104 filter_gain_ = 0.0f;
105 low_coefficient_ = 0.0f;
106 high_coefficient_ = 0.0f;
107 period_ = utils::min(kDefaultPeriod, size - 1);
108 hardReset();
109 }
110
114 virtual ~Delay() { }
115
116 Processor* clone() const override { VITAL_ASSERT(false); return nullptr; }
117
121 void hardReset() override;
122
128 void setMaxSamples(int max_samples);
129
135 virtual void process(int num_samples) override;
136
143 virtual void processWithInput(const poly_float* audio_in, int num_samples) override;
144
155 void processCleanUnfiltered(const poly_float* audio_in, int num_samples,
156 poly_float current_period, poly_float current_feedback,
157 poly_float current_wet, poly_float current_dry);
158
169 void processUnfiltered(const poly_float* audio_in, int num_samples,
170 poly_float current_period, poly_float current_feedback,
171 poly_float current_wet, poly_float current_dry);
172
186 void process(const poly_float* audio_in, int num_samples,
187 poly_float current_period, poly_float current_feedback, poly_float current_filter_gain,
188 poly_float current_low_coefficient, poly_float current_high_coefficient,
189 poly_float current_wet, poly_float current_dry);
190
202 void processDamped(const poly_float* audio_in, int num_samples,
203 poly_float current_period, poly_float current_feedback,
204 poly_float current_low_coefficient,
205 poly_float current_wet, poly_float current_dry);
206
220 void processPingPong(const poly_float* audio_in, int num_samples,
221 poly_float current_period, poly_float current_feedback, poly_float current_filter_gain,
222 poly_float current_low_coefficient, poly_float current_high_coefficient,
223 poly_float current_wet, poly_float current_dry);
224
238 void processMonoPingPong(const poly_float* audio_in, int num_samples,
239 poly_float current_period, poly_float current_feedback, poly_float current_filter_gain,
240 poly_float current_low_coefficient, poly_float current_high_coefficient,
241 poly_float current_wet, poly_float current_dry);
242
247 poly_float wet, poly_float dry);
248
252 poly_float tickUnfiltered(poly_float audio_in, poly_float period, poly_float feedback,
253 poly_float wet, poly_float dry);
254
258 poly_float tick(poly_float audio_in, poly_float period, poly_float feedback,
259 poly_float filter_gain, poly_float low_coefficient, poly_float high_coefficient,
260 poly_float wet, poly_float dry);
261
266 poly_float feedback, poly_float low_coefficient,
267 poly_float wet, poly_float dry);
268
272 poly_float tickPingPong(poly_float audio_in, poly_float period, poly_float feedback,
273 poly_float filter_gain, poly_float low_coefficient, poly_float high_coefficient,
274 poly_float wet, poly_float dry);
275
280 poly_float filter_gain, poly_float low_coefficient, poly_float high_coefficient,
281 poly_float wet, poly_float dry);
282
283 protected:
287 Delay() : Processor(0, 0) { }
288
289 std::unique_ptr<MemoryType> memory_;
295
299
302
303 JUCE_LEAK_DETECTOR(Delay)
304 };
305
308
311
312} // namespace vital
A flexible delay line effect processor that can operate in various styles and apply filtering.
Definition delay.h:47
poly_float tickCleanUnfiltered(poly_float audio_in, poly_float period, poly_float feedback, poly_float wet, poly_float dry)
A single-sample tick for a clean, unfiltered delay line.
Definition delay.cpp:368
poly_float wet_
Current wet mix value.
Definition delay.h:292
virtual ~Delay()
Virtual destructor.
Definition delay.h:114
void processCleanUnfiltered(const poly_float *audio_in, int num_samples, poly_float current_period, poly_float current_feedback, poly_float current_wet, poly_float current_dry)
Processes a clean, unfiltered delay without clamping or filtering.
Definition delay.cpp:183
poly_float tickMonoPingPong(poly_float audio_in, poly_float period, poly_float feedback, poly_float filter_gain, poly_float low_coefficient, poly_float high_coefficient, poly_float wet, poly_float dry)
A single-sample tick for a mono ping-pong delay line.
Definition delay.cpp:438
poly_float feedback_
Current feedback value.
Definition delay.h:291
Style
Styles of delay.
Definition delay.h:81
@ kNumStyles
Definition delay.h:86
@ kClampedDampened
Definition delay.h:87
@ kMono
Definition delay.h:82
@ kMidPingPong
Definition delay.h:85
@ kPingPong
Definition delay.h:84
@ kClampedUnfiltered
Definition delay.h:88
@ kStereo
Definition delay.h:83
@ kUnclampedUnfiltered
Definition delay.h:89
void processPingPong(const poly_float *audio_in, int num_samples, poly_float current_period, poly_float current_feedback, poly_float current_filter_gain, poly_float current_low_coefficient, poly_float current_high_coefficient, poly_float current_wet, poly_float current_dry)
Processes a ping-pong delay, alternating the delayed signal between channels.
Definition delay.cpp:298
virtual void processWithInput(const poly_float *audio_in, int num_samples) override
Processes a block of audio from a given input buffer.
Definition delay.cpp:83
OnePoleFilter low_pass_
Low-pass filter for damping/frequency shaping.
Definition delay.h:300
poly_float tick(poly_float audio_in, poly_float period, poly_float feedback, poly_float filter_gain, poly_float low_coefficient, poly_float high_coefficient, poly_float wet, poly_float dry)
A single-sample tick for a filtered delay line.
Definition delay.cpp:392
static constexpr mono_float kDefaultPeriod
Default delay period in samples.
Definition delay.h:51
static poly_float getFilterRadius(poly_float spread)
Computes the filter radius based on spread.
Definition delay.h:62
std::unique_ptr< MemoryType > memory_
Internal memory buffer for delay line.
Definition delay.h:289
Processor * clone() const override
Clones this Processor for polyphonic expansion. Must be overridden by subclasses.
Definition delay.h:116
void processMonoPingPong(const poly_float *audio_in, int num_samples, poly_float current_period, poly_float current_feedback, poly_float current_filter_gain, poly_float current_low_coefficient, poly_float current_high_coefficient, poly_float current_wet, poly_float current_dry)
Processes a mono ping-pong delay, collapsing input before ping-ponging.
Definition delay.cpp:333
poly_float last_frequency_
Tracks last frequency for smoothing delay time changes.
Definition delay.h:290
Delay()
Protected default constructor for derived classes.
Definition delay.h:287
poly_float filter_gain_
Gain applied before filtering stages.
Definition delay.h:298
virtual void process(int num_samples) override
Processes a block of audio using the connected inputs.
Definition delay.cpp:68
@ kFrequency
Base delay frequency.
Definition delay.h:70
@ kFeedback
Feedback amount.
Definition delay.h:72
@ kWet
Wet mix amount.
Definition delay.h:69
@ kFilterCutoff
Filter cutoff (in MIDI note).
Definition delay.h:75
@ kNumInputs
Definition delay.h:77
@ kDamping
Damping control.
Definition delay.h:73
@ kFilterSpread
Filter spread around cutoff.
Definition delay.h:76
@ kStyle
Delay style selection.
Definition delay.h:74
@ kFrequencyAux
Auxiliary delay frequency (for stereo/ping-pong).
Definition delay.h:71
@ kAudio
Input audio signal.
Definition delay.h:68
poly_float tickDamped(poly_float audio_in, poly_float period, poly_float feedback, poly_float low_coefficient, poly_float wet, poly_float dry)
A single-sample tick for a damped delay line using a low-pass filter.
Definition delay.cpp:408
void hardReset() override
Hard-resets the delay line and internal filters.
Definition delay.cpp:43
void processUnfiltered(const poly_float *audio_in, int num_samples, poly_float current_period, poly_float current_feedback, poly_float current_wet, poly_float current_dry)
Processes an unfiltered delay with possible feedback saturation.
Definition delay.cpp:208
static constexpr mono_float kMinDampNote
Minimum MIDI note for damping frequency.
Definition delay.h:53
poly_float low_coefficient_
Low-pass filter coefficient.
Definition delay.h:296
void setMaxSamples(int max_samples)
Sets the maximum number of samples for the delay.
Definition delay.cpp:57
Delay(int size)
Constructs a Delay processor with a given memory size.
Definition delay.h:97
poly_float period_
Current delay period in samples.
Definition delay.h:294
static constexpr mono_float kMaxDampNote
Maximum MIDI note for damping frequency.
Definition delay.h:54
poly_float tickUnfiltered(poly_float audio_in, poly_float period, poly_float feedback, poly_float wet, poly_float dry)
A single-sample tick for an unfiltered delay line with saturation.
Definition delay.cpp:380
void processDamped(const poly_float *audio_in, int num_samples, poly_float current_period, poly_float current_feedback, poly_float current_low_coefficient, poly_float current_wet, poly_float current_dry)
Processes a damped delay line using a low-pass filter for damping.
Definition delay.cpp:268
OnePoleFilter high_pass_
High-pass filter for shaping.
Definition delay.h:301
static constexpr mono_float kDelayHalfLife
Time constant for smoothing frequency transitions.
Definition delay.h:52
poly_float high_coefficient_
High-pass filter coefficient.
Definition delay.h:297
poly_float dry_
Current dry mix value.
Definition delay.h:293
static constexpr mono_float kSpreadOctaveRange
Constants for internal calculations.
Definition delay.h:50
poly_float tickPingPong(poly_float audio_in, poly_float period, poly_float feedback, poly_float filter_gain, poly_float low_coefficient, poly_float high_coefficient, poly_float wet, poly_float dry)
A single-sample tick for a ping-pong delay line.
Definition delay.cpp:422
A one-pole filter implementation with optional nonlinear saturation.
Definition one_pole_filter.h:22
Base class for all signal-processing units in Vital.
Definition processor.h:212
#define VITAL_ASSERT(x)
Definition common.h:11
Declares classes for time-domain memory storage and retrieval with cubic interpolation.
force_inline poly_float min(poly_float left, poly_float right)
Returns the minimum of two poly_floats lane-by-lane.
Definition poly_utils.h:334
force_inline poly_float max(poly_float left, poly_float right)
Returns the maximum of two poly_floats lane-by-lane.
Definition poly_utils.h:327
Contains classes and functions used within the Vital synthesizer framework.
Delay< StereoMemory > StereoDelay
StereoDelay is a Delay processor specialized with StereoMemory.
Definition delay.h:307
constexpr int kNotesPerOctave
Number of semitones per octave.
Definition common.h:51
Delay< Memory > MultiDelay
MultiDelay is a Delay processor specialized with Memory.
Definition delay.h:310
float mono_float
Definition common.h:33
Declares the Processor class and related structures for handling audio processing in a polyphonic con...
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600