FastLED 3.9.15
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
82 static SynthParams fromShape(SynthShape shape);
83};
84
91public:
96 static ISynthEnginePtr create(i32 width = 32, i32 oversample = 16);
97
98 virtual ~ISynthEngine() FL_NOEXCEPT = default;
99
101 virtual bool isValid() const = 0;
102
104 virtual i32 getWidth() const = 0;
105
107 virtual i32 getOversample() const = 0;
108};
109
118public:
123 static ISynthOscillatorPtr create(ISynthEnginePtr engine, const SynthParams& params);
124
129 static ISynthOscillatorPtr create(ISynthEnginePtr engine, SynthShape shape = SynthShape::Sawtooth);
130
131 virtual ~ISynthOscillator() FL_NOEXCEPT = default;
132
137 virtual void generateSamples(float* output, i32 numSamples, float freq) = 0;
138
142 virtual void generateSamples(fl::span<float> output, float freq) = 0;
143
146 virtual void setShape(SynthShape shape) = 0;
147
150 virtual void setParams(const SynthParams& params) = 0;
151
153 virtual SynthParams getParams() const = 0;
154
156 virtual void reset() = 0;
157
159 virtual ISynthEnginePtr getEngine() const = 0;
160};
161
162} // namespace audio
163} // namespace fl
virtual ~ISynthEngine() FL_NOEXCEPT=default
static ISynthEnginePtr create(i32 width=32, i32 oversample=16)
Factory function to create an engine with the specified quality settings.
Definition synth.cpp.hpp:98
virtual i32 getOversample() const =0
Get the oversample setting.
virtual bool isValid() const =0
Check if engine was initialized successfully.
virtual i32 getWidth() const =0
Get the width setting.
Interface for synth engine that holds BLEP/BLAMP tables.
Definition synth.h:90
virtual void reset()=0
Reset oscillator to beginning of cycle.
virtual ISynthEnginePtr getEngine() const =0
Get the engine this oscillator uses.
virtual void setParams(const SynthParams &params)=0
Change waveform parameters (takes effect at next cycle boundary)
virtual SynthParams getParams() const =0
Get current waveform parameters.
virtual void setShape(SynthShape shape)=0
Change waveform shape (takes effect at next cycle boundary)
virtual void generateSamples(float *output, i32 numSamples, float freq)=0
Generate audio samples.
virtual ~ISynthOscillator() FL_NOEXCEPT=default
Interface class for synth oscillator.
Definition synth.h:117
SynthShape
Predefined waveform shapes for synth oscillator.
Definition synth.h:59
u8 width
Definition blur.h:186
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:535
float peakTime
Position of peak in cycle [0..1].
Definition synth.h:70
SynthParams() FL_NOEXCEPT=default
Default constructor - sawtooth wave.
float halfHeight
Height at half-cycle point.
Definition synth.h:71
static SynthParams fromShape(SynthShape shape)
Create parameters for a predefined shape.
Definition synth.cpp.hpp:78
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