Deluge Firmware 1.3.0
Build date: 2025.10.15
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
33using namespace deluge;
34class Voice final {
35public:
36 Voice(Sound& sound);
37 ~Voice() { setAsUnassigned(nullptr); }
38 Patcher patcher;
39
40 // Stores all oscillator positions and stuff, for each Source within each Unison too
41 std::array<VoiceUnisonPart, kMaxNumVoicesUnison> unisonParts;
42
43 // Stores overall info on each Source (basically just sample memory bounds), for the play-through associated with
44 // this Voice right now.
45 std::array<VoiceSamplePlaybackGuide, kNumSources> guides;
46
47 Sound& sound; // This is a reference to the Sound that owns this Voice
48
52 std::array<int32_t, deluge::modulation::params::LOCAL_LAST> paramFinalValues;
53
54 // At the start of this list are local copies of the "global" ones. It's cheaper to copy them here than to pick and
55 // choose where the Patcher looks for them
56 std::array<int32_t, kNumPatchSources> sourceValues;
57
58 std::bitset<kNumExpressionDimensions> expressionSourcesCurrentlySmoothing;
59 std::bitset<kNumExpressionDimensions> expressionSourcesFinalValueChanged;
60 std::array<int32_t, kNumExpressionDimensions> localExpressionSourceValuesBeforeSmoothing;
61
62 std::array<Envelope, kNumEnvelopes> envelopes;
63 LFO lfo2;
64 LFO lfo4;
65
66 dsp::filter::FilterSet filterSet;
67
68 // Contains what used to be called noteCodeBeforeArpeggiation, and fromMIDIChannel
69 std::array<int32_t, 2> inputCharacteristics;
70 int32_t noteCodeAfterArpeggiation;
71
72 uint32_t portaEnvelopePos;
73 int32_t portaEnvelopeMaxAmplitude;
74
75 std::array<uint32_t, 2> lastSaturationTanHWorkingValue;
76
77 int32_t overallOscAmplitudeLastTime;
78 std::array<int32_t, kNumSources> sourceAmplitudesLastTime;
79 std::array<int32_t, kNumModulators> modulatorAmplitudeLastTime;
80 std::array<uint32_t, kNumSources> sourceWaveIndexesLastTime;
81
82 int32_t filterGainLastTime;
83 bool doneFirstRender;
84 bool previouslyIgnoredNoteOff;
85
86 uint32_t orderSounded;
87
88 int32_t overrideAmplitudeEnvelopeReleaseRate;
89
90 bool justCreated{false};
91
92 uint32_t getLocalLFOPhaseIncrement(LFO_ID lfoId, deluge::modulation::params::Local param);
93 void setAsUnassigned(ModelStackWithSoundFlags* modelStack, bool deletingSong = false);
94 bool render(ModelStackWithSoundFlags* modelStack, int32_t* soundBuffer, int32_t numSamples,
95 bool soundRenderingInStereo, bool applyingPanAtVoiceLevel, uint32_t sourcesChanged, bool doLPF,
96 bool doHPF, int32_t externalPitchAdjust);
97
98 void calculatePhaseIncrements(ModelStackWithSoundFlags* modelStack);
99 bool sampleZoneChanged(ModelStackWithSoundFlags* modelStack, int32_t s, MarkerType markerType);
100 bool noteOn(ModelStackWithSoundFlags* modelStack, int32_t newNoteCodeBeforeArpeggiation,
101 int32_t newNoteCodeAfterArpeggiation, uint8_t velocity, uint32_t newSampleSyncLength, int32_t ticksLate,
102 uint32_t samplesLate, bool resetEnvelopes, int32_t fromMIDIChannel, const int16_t* mpeValues);
103 void noteOff(ModelStackWithSoundFlags* modelStack, bool allowReleaseStage = true);
104
105 void randomizeOscPhases(const Sound& sound);
106 void changeNoteCode(ModelStackWithSoundFlags* modelStack, int32_t newNoteCodeBeforeArpeggiation,
107 int32_t newNoteCodeAfterArpeggiation, int32_t newInputMIDIChannel, const int16_t* newMPEValues);
108 bool hasReleaseStage();
109 void unassignStuff(bool deletingSong);
110 [[nodiscard]] uint32_t getPriorityRating() const;
111 void expressionEventImmediate(const Sound& sound, int32_t voiceLevelValue, int32_t s);
112 void expressionEventSmooth(int32_t newValue, int32_t s);
113
116 bool doFastRelease(uint32_t releaseIncrement);
117
120 bool doImmediateRelease();
121
122 bool forceNormalRelease();
123
124 bool speedUpRelease();
125 bool shouldBeDeleted() { return delete_this_voice_; }
126
127 // This compares based on the priority of two voices
128 [[nodiscard]] std::strong_ordering operator<=>(const Voice& other) const {
129 return this->getPriorityRating() <=> other.getPriorityRating();
130 }
131
132private:
133 // inline int32_t doFM(uint32_t *carrierPhase, uint32_t* lastShiftedPhase, uint32_t carrierPhaseIncrement, uint32_t
134 // phaseShift);
135 bool delete_this_voice_{false};
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 void makeUnisonPartsInactive(const Sound& sound, int32_t source_index);
157 void calculatePhaseIncrementForSource(Sound& sound, int32_t source_index);
158 void calculatePhaseIncrementForFmMod(Sound& sound, int32_t mod_index);
159};
Definition lfo.h:35
Definition model_stack.h:287
Definition patcher.h:38
Definition sound.h:71
bool doImmediateRelease()
Definition voice.cpp:2502
bool doFastRelease(uint32_t releaseIncrement)
Definition voice.cpp:2452
std::array< int32_t, deluge::modulation::params::LOCAL_LAST > paramFinalValues
Definition voice.h:52
Definition filter_set.h:44
Local
"Local" patched params, which apply to individual voices within the sound
Definition param.h:68