Vital
Loading...
Searching...
No Matches
random_lfo.h
Go to the documentation of this file.
1#pragma once
2
3#include "processor.h"
4#include "utils.h"
5
6namespace vital {
7
16 class RandomLfo : public Processor {
17 public:
24 struct RandomState {
26 offset = 0.0f;
27 last_random_value = 0.0f;
28 next_random_value = 0.0f;
29 state1 = 0.1f;
30 state2 = 0.0f;
31 state3 = 0.0f;
32 }
33
37
38 // Used by certain random types (like Lorenz attractor) to store state variables.
40 };
41
53 enum {
62 };
63
79
83 RandomLfo();
84
89 virtual Processor* clone() const override { return new RandomLfo(*this); }
90
99 void process(int num_samples) override;
100
110 void process(RandomState* state, int num_samples);
111
121 void processSampleAndHold(RandomState* state, int num_samples);
122
132 void processLorenzAttractor(RandomState* state, int num_samples);
133
139 void correctToTime(double seconds);
140
141 protected:
149 void doReset(RandomState* state, bool mono, poly_float frequency);
150
161 poly_int updatePhase(RandomState* state, int num_samples);
162
164 std::shared_ptr<RandomState> shared_state_;
165
168
169 std::shared_ptr<double> sync_seconds_;
170 std::shared_ptr<double> last_sync_;
171
172 JUCE_LEAK_DETECTOR(RandomLfo)
173 };
174} // namespace vital
Base class for all signal-processing units in Vital.
Definition processor.h:212
A Low-Frequency Oscillator (LFO) that generates random modulation signals.
Definition random_lfo.h:16
RandomLfo()
Constructs a RandomLfo processor with default parameters.
Definition random_lfo.cpp:22
std::shared_ptr< double > sync_seconds_
A shared double holding the sync reference time in seconds.
Definition random_lfo.h:169
std::shared_ptr< double > last_sync_
A shared double holding the last sync time for comparison.
Definition random_lfo.h:170
utils::RandomGenerator random_generator_
A random generator to produce random values for the LFO.
Definition random_lfo.h:166
std::shared_ptr< RandomState > shared_state_
A shared RandomState (used when syncing across instances).
Definition random_lfo.h:164
virtual Processor * clone() const override
Clones the RandomLfo, creating an identical instance.
Definition random_lfo.h:89
void process(int num_samples) override
Processes a block of samples.
Definition random_lfo.cpp:109
RandomType
The types of random waveforms supported by RandomLfo.
Definition random_lfo.h:72
@ kSampleAndHold
Definition random_lfo.h:74
@ kNumStyles
Definition random_lfo.h:77
@ kSinInterpolate
Definition random_lfo.h:75
@ kLorenzAttractor
Definition random_lfo.h:76
@ kPerlin
Definition random_lfo.h:73
void processSampleAndHold(RandomState *state, int num_samples)
Processes the LFO in Sample-And-Hold mode.
Definition random_lfo.cpp:191
void correctToTime(double seconds)
Adjusts the LFO to match a specific time reference (in seconds), for synchronization.
Definition random_lfo.cpp:283
poly_int updatePhase(RandomState *state, int num_samples)
Updates the LFO phase and determines if a new random value is needed.
Definition random_lfo.cpp:62
poly_float last_value_
The last output value of the LFO.
Definition random_lfo.h:167
@ kStereo
Definition random_lfo.h:60
@ kReset
Definition random_lfo.h:56
@ kRandomType
Definition random_lfo.h:59
@ kStyle
Definition random_lfo.h:58
@ kFrequency
Definition random_lfo.h:54
@ kSync
Definition random_lfo.h:57
@ kAmplitude
Definition random_lfo.h:55
@ kNumInputs
Definition random_lfo.h:61
void processLorenzAttractor(RandomState *state, int num_samples)
Processes the LFO using a Lorenz attractor model.
Definition random_lfo.cpp:215
void doReset(RandomState *state, bool mono, poly_float frequency)
Resets the LFO phase and random values if a reset trigger occurs.
Definition random_lfo.cpp:29
RandomState state_
The main internal RandomState for this LFO instance.
Definition random_lfo.h:163
A basic random number generator for producing uniform distributions of floats.
Definition utils.h:61
Contains classes and functions used within the Vital synthesizer framework.
Declares the Processor class and related structures for handling audio processing in a polyphonic con...
Holds the internal state of the RandomLfo for a given voice or channel.
Definition random_lfo.h:24
poly_float state1
Definition random_lfo.h:39
RandomState()
Definition random_lfo.h:25
poly_float last_random_value
The previously generated random value.
Definition random_lfo.h:35
poly_float state2
Definition random_lfo.h:39
poly_float next_random_value
The next target random value for interpolation.
Definition random_lfo.h:36
poly_float state3
Definition random_lfo.h:39
poly_float offset
Current offset (phase) in the LFO cycle.
Definition random_lfo.h:34
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600
Represents a vector of integer values using SIMD instructions.
Definition poly_values.h:56
Provides various utility functions, classes, and constants for audio, math, and general-purpose opera...