Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
dx7note.h
1/*
2 * Copyright 2016-2017 Pascal Gauthier.
3 * Copyright 2012 Google Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef SYNTH_DX7NOTE_H_
19#define SYNTH_DX7NOTE_H_
20
21// This is the logic to put together a note from the MIDI description
22// and run the low-level modules.
23
24// It will continue to evolve a bit, as note-stealing logic, scaling,
25// and real-time control of parameters live here.
26
27#include "env.h"
28#include "fm_core.h"
29#include "pitchenv.h"
30#include <memory>
31
33 uint32_t amp[6];
34 char ampStep[6];
35 char pitchStep;
36};
37
38class DxPatch {
39public:
40 DxPatch();
41
42 uint8_t params[156];
43 FmCore* core;
44 bool opSwitch(int op) const { return (params[155] >> op) & 1; }
45 void setOpSwitch(int op, bool on) { params[155] = (params[155] & ~(1 << op)) | (on ? 1 : 0) * (1 << op); }
46 uint8_t engineMode;
47
48 // extra parameters
49 int32_t random_detune;
50
51 // TODO: these should be per voice with MPE
52 // int amp_mod;
53 int pitch_mod;
54 int eg_mod;
55
56 uint32_t lfo_phase; // Q32
57 uint32_t lfo_delta;
58 uint32_t lfo_value;
59
60 // only needs to be called when rate (param 137) changes
61 void updateLfo();
62 void computeLfo(int n);
63
64 void setEngineMode(int mode, bool neon = true);
65 void updateEngineMode();
66};
67
68struct DxVoiceCtrl {
69 int32_t ampmod{};
70 int32_t velmod{}; // offset to the start velocity
71 int32_t ratemod{};
72
73 DxVoiceCtrl() = default;
74};
75
76class DxVoice {
77public:
78 DxVoice();
79 void init(DxPatch& p, int midinote, int velocity);
80 // Note: this _adds_ to the buffer. Interesting question whether it's
81 // worth it...
82 bool compute(int32_t* buf, int n, int pitch, const DxPatch* ctrls_patch, const DxVoiceCtrl* ctrls_voice);
83 int32_t getdelay(int n);
84
85 void keyup();
86
87 // TODO: some way of indicating end-of-note. Maybe should be a return
88 // value from the compute method? (Having a count return from keyup
89 // is also tempting, but if there's a dynamic parameter change after
90 // keyup, that won't work.
91
92 // PG:add the update
93 void update(DxPatch& p, int midinote);
94 void updateBasePitches(int logFreq);
95 void transferState(DxVoice& src);
96 void transferSignal(DxVoice& src);
97 void oscSync();
98 void oscUnSync();
99
100 int32_t osc_freq(int log_freq, int mode, int coarse, int fine, int detune, int random_detune);
101
102private:
103 Env env_[6];
104 PitchEnv pitchenv_;
105 int32_t phase[6];
106 int32_t gain_out[6];
107 int32_t basepitch_[6];
108 int32_t fb_buf_[2];
109
110 // for LFO
111 uint32_t delaystate_;
112 uint32_t delayinc_;
113 uint32_t delayinc2_;
114
115 int16_t detune_per_voice[6];
116
117 uint8_t* patch; // raw patch, same as p->currentPatch
118 int random_detune_scale;
119 uint8_t lastVelocity;
120
121 EnvParams& env_p(int op) { return *(EnvParams*)&patch[op * 21]; }
122 EnvParams& pitchenv_p() { return *(EnvParams*)&patch[126]; }
123
124public:
125 DxVoice* nextUnassigned;
126 bool preallocated;
127};
128
129#endif // SYNTH_DX7NOTE_H_
Definition dx7note.h:38
void transferState(DxVoice &src)
Definition dx7note.cpp:448
Definition env.h:26
Definition env.h:32
Definition fm_core.h:52
Definition pitchenv.h:23
Definition param.cpp:27
Definition dx7note.h:68
Definition dx7note.h:32