fsh::stk
fantastic spatial holophonic synthesis toolkit
Loading...
Searching...
No Matches
Voice.h
1/***************************************************************************************************
2 ██████ █████ █████ █████
3 ███░░███ ░░███ ░░███ ░░███
4 ░███ ░░░ █████ ░███████ ██ ██ █████ ███████ ░███ █████
5 ███████ ███░░ ░███░░███ ░░ ░░ ███░░ ░░░███░ ░███░░███
6 ░░░███░ ░░█████ ░███ ░███ ░░█████ ░███ ░██████░
7 ░███ ░░░░███ ░███ ░███ ░░░░███ ░███ ███ ░███░░███
8 █████ ██████ ████ █████ ██ ██ ██████ ░░█████ ████ █████
9 ░░░░░ ░░░░░░ ░░░░ ░░░░░ ░░ ░░ ░░░░░░ ░░░░░ ░░░░ ░░░░░
10
11 fantastic spatial holophonic synthesis tool kit
12
13 copyright (c) fabian hummel
14 www.github.com/fshstk
15 www.fshstk.com
16
17 this file is part of the fantastic spatial holophonic synthesis toolkit (fsh::stk)
18 fsh::stk is free software: it is provided under the terms of the gnu general public license v3.0
19 www.gnu.org/licenses/gpl-3.0
20***************************************************************************************************/
21
22#pragma once
23#include "ADSR.h"
24#include "AmbisonicEncoder.h"
25#include "Distortion.h"
26#include "MoogVCF.h"
27#include "Oscillator.h"
28#include <cstdint>
29#include <juce_audio_basics/juce_audio_basics.h>
30#include <stdint.h>
31
32namespace fsh::synth
33{
46class Voice
47{
48public:
65
67 void setSampleRate(double sampleRate);
68
70 void setParams(const Params&);
71
73 void noteOn(uint8_t noteVal, uint8_t velocity);
74
76 void noteOff(uint8_t noteVal, uint8_t velocity);
77
79 void pitchBend(uint16_t bendVal);
80
85 void render(juce::AudioBuffer<float>& audio, size_t numSamples, size_t bufferOffset);
86
88 auto getNoteVal() const -> uint8_t;
89
91 auto isActive() const -> bool;
92
94 void reset();
95
96private:
97 auto nextSample() -> float;
98
99 Params _params;
100 uint8_t _noteVal;
101 double _bendValSemitones;
102 uint8_t _velocity;
103 ADSR _ampEnv;
104 ADSR _filtEnv;
105 fx::AmbisonicEncoder _encoder;
106 Oscillator _oscA;
107 Oscillator _oscB;
108 Oscillator _oscC;
109 fx::MoogVCF _filter;
110 fx::Distortion _drive;
111};
112} // namespace fsh::synth
ADSR envelope.
Definition ADSR.h:40
Represents a single band-limited oscillator with multiple waveforms.
Definition Oscillator.h:42
Represents a single voice of a polyphonic synthesizer.
Definition Voice.h:47
void reset()
Reset the voice's state.
Definition Voice.cpp:69
void setSampleRate(double sampleRate)
Set the sample rate in Hz.
Definition Voice.cpp:158
auto getNoteVal() const -> uint8_t
Returns the MIDI value of the currently playing note, or 0 if no note is playing.
Definition Voice.cpp:195
void noteOn(uint8_t noteVal, uint8_t velocity)
Start a note with the given note value and velocity.
Definition Voice.cpp:82
void render(juce::AudioBuffer< float > &audio, size_t numSamples, size_t bufferOffset)
Compute the next block of audio samples.
Definition Voice.cpp:111
void setParams(const Params &)
Set the voice's parameters.
Definition Voice.cpp:169
auto isActive() const -> bool
Returns true if a note is currently being played.
Definition Voice.cpp:200
void pitchBend(uint16_t bendVal)
Set the pitch bend value using MIDI pitchbend data (14 bytes)
Definition Voice.cpp:104
void noteOff(uint8_t noteVal, uint8_t velocity)
Stop a note with the given note value. (Velocity is ignored for now.)
Definition Voice.cpp:94
Envelope parameters.
Definition ADSR.h:44
Oscillator parameters.
Definition Oscillator.h:60
Voice parameters.
Definition Voice.h:51
Oscillator::Params oscA
Oscillator A parameters.
Definition Voice.h:53
double aziRange
Spread MIDI range around aziCenter +/- aziRange/2.
Definition Voice.h:60
float filtModAmt
How much the filter env should modulate the filter.
Definition Voice.h:58
float filterCutoff
Filter cutoff as a multiplier of oscillator frequency.
Definition Voice.h:61
double aziCenter
Anchor middle of MIDI note range to this azimuth in degrees.
Definition Voice.h:59
float drive
Distortion drive (dB)
Definition Voice.h:63
ADSR::Params filtEnv
Amplitude envelope parameters.
Definition Voice.h:57
Oscillator::Params oscB
Oscillator A parameters.
Definition Voice.h:54
float masterLevel
Master level.
Definition Voice.h:52
Oscillator::Params oscC
Oscillator A parameters.
Definition Voice.h:55
float filterResonance
Filter resonance.
Definition Voice.h:62
ADSR::Params ampEnv
Amplitude envelope parameters.
Definition Voice.h:56