Vital
Loading...
Searching...
No Matches
delay_module.cpp
Go to the documentation of this file.
1#include "delay_module.h"
2
3#include "delay.h"
4#include "memory.h"
5
6namespace vital {
7
8 DelayModule::DelayModule(const Output* beats_per_second) : SynthModule(0, 1), beats_per_second_(beats_per_second) {
9 int size = kMaxDelayTime * getSampleRate();
10 // Initialize delay with max possible delay samples.
11 delay_ = new StereoDelay(size);
13 }
14
16
25
26 // Create mod controls and tempo sync switches for delay parameters.
27 Output* free_frequency = createMonoModControl("delay_frequency");
28 Output* frequency = createTempoSyncSwitch("delay", free_frequency->owner, beats_per_second_, false);
29 Output* free_frequency_aux = createMonoModControl("delay_aux_frequency");
30 Output* frequency_aux = createTempoSyncSwitch("delay_aux", free_frequency_aux->owner, beats_per_second_, false);
31 Output* feedback = createMonoModControl("delay_feedback");
32 Output* wet = createMonoModControl("delay_dry_wet");
33
34 Output* filter_cutoff = createMonoModControl("delay_filter_cutoff");
35 Output* filter_spread = createMonoModControl("delay_filter_spread");
36
37 Value* style = createBaseControl("delay_style");
38
39 // Plug parameters into the StereoDelay processor.
41 delay_->plug(frequency_aux, StereoDelay::kFrequencyAux);
45 delay_->plug(filter_cutoff, StereoDelay::kFilterCutoff);
46 delay_->plug(filter_spread, StereoDelay::kFilterSpread);
47
49 }
50
51 void DelayModule::setSampleRate(int sample_rate) {
55 SynthModule::setSampleRate(sample_rate);
56 delay_->setSampleRate(sample_rate);
58 }
59
67
68 void DelayModule::processWithInput(const poly_float* audio_in, int num_samples) {
75 SynthModule::process(num_samples);
76 delay_->processWithInput(audio_in, num_samples);
77 }
78
79} // namespace vital
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
@ 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
@ 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
void setMaxSamples(int max_samples)
Sets the maximum number of samples for the delay.
Definition delay.cpp:57
virtual void setSampleRate(int sample_rate) override
Sets the sample rate for the delay. This ensures that time-based parameters remain accurate.
Definition delay_module.cpp:51
DelayModule(const Output *beats_per_second)
Constructs the DelayModule, linking it to a beats-per-second output for tempo synchronization.
Definition delay_module.cpp:8
virtual void processWithInput(const poly_float *audio_in, int num_samples) override
Processes audio input through the delay effect.
Definition delay_module.cpp:68
const Output * beats_per_second_
An output providing tempo information for syncing delay times.
Definition delay_module.h:90
static constexpr mono_float kMaxDelayTime
The maximum delay time in seconds.
Definition delay_module.h:19
StereoDelay * delay_
The underlying StereoDelay processor implementing the delay effect.
Definition delay_module.h:91
virtual ~DelayModule()
Destroys the DelayModule and releases associated resources.
Definition delay_module.cpp:15
virtual void init() override
Initializes the DelayModule, creating and linking parameters and setting up the StereoDelay processor...
Definition delay_module.cpp:17
virtual void setOversampleAmount(int oversample) override
Sets the oversample amount and updates internal delay buffer sizes accordingly.
Definition delay_module.cpp:60
virtual void setOversampleAmount(int oversample)
Sets the oversampling amount and updates the effective sample rate.
Definition processor.h:293
void useOutput(Output *output)
Uses an existing Output object as this Processor's first output.
Definition processor.cpp:138
force_inline int getSampleRate() const
Retrieves the current (effective) sample rate.
Definition processor.h:326
void plug(const Output *source)
Connects an external Output to this Processor's first input.
Definition processor.cpp:79
virtual void process(int num_samples)=0
Main processing function. Called by the ProcessorRouter.
force_inline Output * output(unsigned int index=0) const
Retrieves the Output pointer at a given index.
Definition processor.h:616
virtual void setSampleRate(int sample_rate)
Updates the sample rate of this Processor (scaled by oversampling).
Definition processor.h:285
virtual void init()
Called after constructor, used for any additional initialization. Subclasses can override....
Definition processor.h:258
virtual void addIdleProcessor(Processor *processor)
Adds a Processor that should remain idle (not processed) in the router.
Definition processor_router.cpp:146
A ProcessorRouter that encapsulates a cohesive unit of functionality in the synthesizer.
Definition synth_module.h:129
Value * createBaseControl(std::string name, bool audio_rate=false, bool smooth_value=false)
Creates a simple control processor for a given parameter name.
Definition synth_module.cpp:22
Output * createTempoSyncSwitch(std::string name, Processor *frequency, const Output *beats_per_second, bool poly, Input *midi=nullptr)
Creates a tempo sync switch that toggles between tempo-based frequency and free-running frequency.
Definition synth_module.cpp:289
Output * createMonoModControl(std::string name, bool audio_rate=false, bool smooth_value=false, Output *internal_modulation=nullptr)
Creates a monophonic mod control, including applying parameter scaling.
Definition synth_module.cpp:104
A Processor that maintains and outputs a constant poly_float value.
Definition value.h:24
Declares classes for time-domain memory storage and retrieval with cubic interpolation.
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
Holds and manages a buffer of samples (poly_float) for a Processor's output.
Definition processor.h:35
Processor * owner
Owning processor.
Definition processor.h:112
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600