-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImpulseSynth.h
More file actions
106 lines (91 loc) · 2.5 KB
/
ImpulseSynth.h
File metadata and controls
106 lines (91 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
VocoderSynth is a DSP plugin.
Copyright 2024-2025 Tim Krause
This file is part of VocoderSynth
VocoderSynth is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
VocoderSynth is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with VocoderSynth. If not, see
<https://www.gnu.org/licenses/>.
Contact: tim.krause@twkrause.ca
*/
#pragma once
#include <cstdint>
#include <list>
#include <memory>
#include <lv2/atom/atom.h>
#include <lv2/urid/urid.h>
#include <lv2/midi/midi.h>
#include <lv2/core/lv2_util.h>
#include <lv2/atom/util.h>
#include "ImpulseGen.h"
#define N_VOICES 16
class ImpulseSynth;
class VocoderSynth;
enum EnvState
{
ENV_ATTACK,
ENV_DECAY,
ENV_SUSTAIN,
ENV_RELEASE
};
struct Voice
{
uint8_t note;
uint8_t vel;
EnvState state;
float envelope;
float denvelope;
float attack; // Attack time in seconds. Can be zero.
float decay;
float sustain;
float release;
double sample_rate;
float freq0;
ImpulseSynth &synth;
std::list<Voice*>::iterator active_pos;
ImpulseGen gen;
Voice(double sample_rate, ImpulseSynth &synth);
void NoteOn(uint8_t note, uint8_t vel);
void NoteOff(uint8_t vel);
float dEnvelope(float t);
float Evaluate(void);
};
struct Key
{
Voice* voice;
bool pressed;
};
class ImpulseSynth
{
private:
std::list<Voice*> avail_voices;
std::list<Voice*> active_voices;
std::unique_ptr<Voice> alloc_voices[N_VOICES];
Key keys[128];
const LV2_Atom_Sequence *sequence;
LV2_Atom_Event* event;
void NextEvent(void);
void ProcessEvent(void);
uint32_t frame;
LV2_URID MidiEvent_URID;
double sample_rate;
public:
VocoderSynth &plugin;
float pitch_bend;
ImpulseSynth(double sample_rate, const LV2_Feature *const *features, VocoderSynth &plugin);
Voice* ActivateVoice(void);
void DeactivateVoice(Voice *voice);
void NoteOn(uint8_t note, uint8_t vel);
void NoteOff(uint8_t note, uint8_t vel);
void AllNotesOff(void);
void Bender(uint8_t lsb, uint8_t msb);
void EvaluateStart(const LV2_Atom_Sequence *sequence);
float Evaluate(void);
};