Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
voice.h
1/*
2 * Copyright © 2014-2023 Synthstrom Audible Limited
3 *
4 * This file is part of The Synthstrom Audible Deluge Firmware.
5 *
6 * The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software Foundation,
8 * either version 3 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with this program.
15 * If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include "definitions_cxx.hpp"
21#include "dsp/filter/filter_set.h"
22#include "model/voice/voice_sample_playback_guide.h"
23#include "model/voice/voice_unison_part.h"
24#include "modulation/envelope.h"
25#include "modulation/lfo.h"
26#include "modulation/params/param.h"
27#include "modulation/patch/patcher.h"
28#include <bitset>
29#include <compare>
30#include <memory>
31
32class StereoSample;
34using namespace deluge;
35class Voice final {
36public:
37 Voice(Sound& sound);
38 ~Voice() { setAsUnassigned(nullptr); }
39 Patcher patcher;
40
41 // Stores all oscillator positions and stuff, for each Source within each Unison too
42 std::array<VoiceUnisonPart, kMaxNumVoicesUnison> unisonParts;
43
44 // Stores overall info on each Source (basically just sample memory bounds), for the play-through associated with
45 // this Voice right now.
46 std::array<VoiceSamplePlaybackGuide, kNumSources> guides;
47
48 Sound& sound; // This is a reference to the Sound that owns this Voice
49
53 std::array<int32_t, deluge::modulation::params::LOCAL_LAST> paramFinalValues;
54
55 // At the start of this list are local copies of the "global" ones. It's cheaper to copy them here than to pick and
56 // choose where the Patcher looks for them
57 std::array<int32_t, kNumPatchSources> sourceValues;
58
59 std::bitset<kNumExpressionDimensions> expressionSourcesCurrentlySmoothing;
60 std::bitset<kNumExpressionDimensions> expressionSourcesFinalValueChanged;
61 std::array<int32_t, kNumExpressionDimensions> localExpressionSourceValuesBeforeSmoothing;
62
63 std::array<Envelope, kNumEnvelopes> envelopes;
64 LFO lfo2;
65 LFO lfo4;
66
67 dsp::filter::FilterSet filterSet;
68
69 // Contains what used to be called noteCodeBeforeArpeggiation, and fromMIDIChannel
70 std::array<int32_t, 2> inputCharacteristics;
71 int32_t noteCodeAfterArpeggiation;
72
73 uint32_t portaEnvelopePos;
74 int32_t portaEnvelopeMaxAmplitude;
75
76 std::array<uint32_t, 2> lastSaturationTanHWorkingValue;
77
78 int32_t overallOscAmplitudeLastTime;
79 std::array<int32_t, kNumSources> sourceAmplitudesLastTime;
80 std::array<int32_t, kNumModulators> modulatorAmplitudeLastTime;
81 std::array<uint32_t, kNumSources> sourceWaveIndexesLastTime;
82
83 int32_t filterGainLastTime;
84
85 bool doneFirstRender;
86 bool previouslyIgnoredNoteOff;
87
88 uint32_t orderSounded;
89
90 int32_t overrideAmplitudeEnvelopeReleaseRate;
91
92 bool justCreated{false};
93
94 uint32_t getLocalLFOPhaseIncrement(LFO_ID lfoId, deluge::modulation::params::Local param);
95 void setAsUnassigned(ModelStackWithSoundFlags* modelStack, bool deletingSong = false);
96 bool render(ModelStackWithSoundFlags* modelStack, int32_t* soundBuffer, int32_t numSamples,
97 bool soundRenderingInStereo, bool applyingPanAtVoiceLevel, uint32_t sourcesChanged, bool doLPF,
98 bool doHPF, int32_t externalPitchAdjust);
99
100 void calculatePhaseIncrements(ModelStackWithSoundFlags* modelStack);
101 bool sampleZoneChanged(ModelStackWithSoundFlags* modelStack, int32_t s, MarkerType markerType);
102 bool noteOn(ModelStackWithSoundFlags* modelStack, int32_t newNoteCodeBeforeArpeggiation,
103 int32_t newNoteCodeAfterArpeggiation, uint8_t velocity, uint32_t newSampleSyncLength, int32_t ticksLate,
104 uint32_t samplesLate, bool resetEnvelopes, int32_t fromMIDIChannel, const int16_t* mpeValues);
105 void noteOff(ModelStackWithSoundFlags* modelStack, bool allowReleaseStage = true);
106
107 void randomizeOscPhases(const Sound& sound);
108 void changeNoteCode(ModelStackWithSoundFlags* modelStack, int32_t newNoteCodeBeforeArpeggiation,
109 int32_t newNoteCodeAfterArpeggiation, int32_t newInputMIDIChannel, const int16_t* newMPEValues);
110 bool hasReleaseStage();
111 void unassignStuff(bool deletingSong);
112 [[nodiscard]] uint32_t getPriorityRating() const;
113 void expressionEventImmediate(const Sound& sound, int32_t voiceLevelValue, int32_t s);
114 void expressionEventSmooth(int32_t newValue, int32_t s);
115
118 bool doFastRelease(uint32_t releaseIncrement = 4096);
119
122 bool doImmediateRelease();
123
124 bool forceNormalRelease();
125
126 bool speedUpRelease();
127
128 // This compares based on the priority of two voices
129 [[nodiscard]] std::strong_ordering operator<=>(const Voice& other) const {
130 return this->getPriorityRating() <=> other.getPriorityRating();
131 }
132
133private:
134 // inline int32_t doFM(uint32_t *carrierPhase, uint32_t* lastShiftedPhase, uint32_t carrierPhaseIncrement, uint32_t
135 // phaseShift);
136
137 void renderBasicSource(Sound& sound, ParamManagerForTimeline* paramManager, int32_t s, int32_t* oscBuffer,
138 int32_t numSamples, bool stereoBuffer, int32_t sourceAmplitude,
139 bool* unisonPartBecameInactive, int32_t overallPitchAdjust, bool doOscSync,
140 uint32_t* oscSyncPos, uint32_t* oscSyncPhaseIncrements, int32_t amplitudeIncrement,
141 uint32_t* getPhaseIncrements, bool getOutAfterPhaseIncrements, int32_t waveIndexIncrement);
142 static bool adjustPitch(uint32_t& phaseIncrement, int32_t adjustment);
143
144 void renderSineWaveWithFeedback(int32_t* thisSample, int32_t numSamples, uint32_t* phase, int32_t amplitude,
145 uint32_t phaseIncrement, int32_t feedbackAmount, int32_t* lastFeedbackValue,
146 bool add, int32_t amplitudeIncrement);
147 void renderFMWithFeedback(int32_t* thisSample, int32_t numSamples, int32_t* fmBuffer, uint32_t* phase,
148 int32_t amplitude, uint32_t phaseIncrement, int32_t feedbackAmount,
149 int32_t* lastFeedbackValue, int32_t amplitudeIncrement);
150 void renderFMWithFeedbackAdd(int32_t* thisSample, int32_t numSamples, int32_t* fmBuffer, uint32_t* phase,
151 int32_t amplitude, uint32_t phaseIncrement, int32_t feedbackAmount,
152 int32_t* lastFeedbackValue, int32_t amplitudeIncrement);
153 bool areAllUnisonPartsInactive(ModelStackWithSoundFlags& modelStack) const;
154 void setupPorta(const Sound& sound);
155 int32_t combineExpressionValues(const Sound& sound, int32_t expressionDimension) const;
156};
Definition lfo.h:35
Definition model_stack.h:287
Definition patcher.h:38
Definition sound.h:71
Definition voice.h:35
bool doImmediateRelease()
Definition voice.cpp:2490
std::array< int32_t, deluge::modulation::params::LOCAL_LAST > paramFinalValues
Definition voice.h:53
bool doFastRelease(uint32_t releaseIncrement=4096)
Definition voice.cpp:2440
Definition filter_set.h:44
Local
"Local" patched params, which apply to individual voices within the sound
Definition param.h:68
Definition stereo_sample.h:25