FastLED 3.10.8
Loading...
Searching...
No Matches
synth.h
Go to the documentation of this file.
1#pragma once
2
43
44#include "fl/stl/stdint.h"
45#include "fl/stl/span.h"
46#include "fl/stl/shared_ptr.h"
47#include "fl/stl/noexcept.h"
48
49namespace fl {
50namespace audio {
51
52// Forward declarations
54class ISynthEngine;
57
59enum class SynthShape {
60 Sawtooth, // Classic sawtooth wave (reflect=1, peak=0, half=0, wait=0)
61 Square, // Classic square wave (reflect=1, peak=0, half=1, wait=0)
62 Triangle, // Classic triangle wave (reflect=1, peak=0.5, half=0, wait=0)
63 AlternatingSaw, // Alternating sawtooth (reflect=0, peak=0, half=0, wait=0)
64 Custom // User-defined parameters
65};
66
69 i32 reflect = 1;
70 float peakTime = 0.0f;
71 float halfHeight = 0.0f;
72 float zeroWait = 0.0f;
73
76
80
83};
84
91public:
96 static ISynthEnginePtr create(i32 width = 32, i32 oversample = 16) FL_NO_EXCEPT;
97
98 virtual ~ISynthEngine() FL_NO_EXCEPT = default;
99
101 virtual bool isValid() const FL_NO_EXCEPT = 0;
102
104 virtual i32 getWidth() const FL_NO_EXCEPT = 0;
105
107 virtual i32 getOversample() const FL_NO_EXCEPT = 0;
108};
109
118public:
123 static ISynthOscillatorPtr create(ISynthEnginePtr engine, const SynthParams& params) FL_NO_EXCEPT;
124
129 static ISynthOscillatorPtr create(ISynthEnginePtr engine, SynthShape shape = SynthShape::Sawtooth) FL_NO_EXCEPT;
130
131 virtual ~ISynthOscillator() FL_NO_EXCEPT = default;
132
137 virtual void generateSamples(float* output, i32 numSamples, float freq) FL_NO_EXCEPT = 0;
138
142 virtual void generateSamples(fl::span<float> output, float freq) FL_NO_EXCEPT = 0;
143
146 virtual void setShape(SynthShape shape) FL_NO_EXCEPT = 0;
147
150 virtual void setParams(const SynthParams& params) FL_NO_EXCEPT = 0;
151
153 virtual SynthParams getParams() const FL_NO_EXCEPT = 0;
154
156 virtual void reset() FL_NO_EXCEPT = 0;
157
159 virtual ISynthEnginePtr getEngine() const FL_NO_EXCEPT = 0;
160};
161
162} // namespace audio
163} // namespace fl
virtual ~ISynthEngine() FL_NO_EXCEPT=default
virtual i32 getOversample() const FL_NO_EXCEPT=0
Get the oversample setting.
virtual bool isValid() const FL_NO_EXCEPT=0
Check if engine was initialized successfully.
static ISynthEnginePtr create(i32 width=32, i32 oversample=16) FL_NO_EXCEPT
Factory function to create an engine with the specified quality settings.
Definition synth.cpp.hpp:98
virtual i32 getWidth() const FL_NO_EXCEPT=0
Get the width setting.
Interface for synth engine that holds BLEP/BLAMP tables.
Definition synth.h:90
virtual void setShape(SynthShape shape) FL_NO_EXCEPT=0
Change waveform shape (takes effect at next cycle boundary)
virtual ~ISynthOscillator() FL_NO_EXCEPT=default
virtual SynthParams getParams() const FL_NO_EXCEPT=0
Get current waveform parameters.
virtual void reset() FL_NO_EXCEPT=0
Reset oscillator to beginning of cycle.
virtual ISynthEnginePtr getEngine() const FL_NO_EXCEPT=0
Get the engine this oscillator uses.
virtual void generateSamples(float *output, i32 numSamples, float freq) FL_NO_EXCEPT=0
Generate audio samples.
virtual void setParams(const SynthParams &params) FL_NO_EXCEPT=0
Change waveform parameters (takes effect at next cycle boundary)
Interface class for synth oscillator.
Definition synth.h:117
SynthShape
Predefined waveform shapes for synth oscillator.
Definition synth.h:59
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
u8 width
Definition blur.h:186
Base definition for an LED controller.
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:577
static SynthParams fromShape(SynthShape shape) FL_NO_EXCEPT
Create parameters for a predefined shape.
Definition synth.cpp.hpp:78
float peakTime
Position of peak in cycle [0..1].
Definition synth.h:70
float halfHeight
Height at half-cycle point.
Definition synth.h:71
SynthParams() FL_NO_EXCEPT=default
Default constructor - sawtooth wave.
float zeroWait
Wait time at zero [0..1].
Definition synth.h:72
i32 reflect
Mirror second half of waveform (0 or 1)
Definition synth.h:69
Waveform parameters for custom waveforms.
Definition synth.h:68