/[svn]/linuxsampler/trunk/src/engines/gig/Voice.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/engines/gig/Voice.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3626 - (show annotations) (download)
Thu Oct 3 14:40:17 2019 UTC (10 months ago) by schoenebeck
File size: 29096 byte(s)
Just added some compile-time sanity checks
(for enum ::gig::lfo_wave_t to match enum LFO::wave_t).

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 - 2008 Christian Schoenebeck *
7 * Copyright (C) 2009 Christian Schoenebeck and Grigor Iliev *
8 * Copyright (C) 2010 - 2017 Christian Schoenebeck and Andreas Persson *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the Free Software *
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
23 * MA 02111-1307 USA *
24 ***************************************************************************/
25
26 #include "../../common/Features.h"
27 #include "Synthesizer.h"
28 #include "Profiler.h"
29 #include "Engine.h"
30 #include "EngineChannel.h"
31
32 #include "Voice.h"
33
34 namespace LinuxSampler { namespace gig {
35
36 // sanity checks: fromGigLfoWave() assumes equally mapped enums
37 static_assert(::gig::lfo_wave_sine == LFO::wave_sine);
38 static_assert(::gig::lfo_wave_triangle == LFO::wave_triangle);
39 static_assert(::gig::lfo_wave_saw == LFO::wave_saw);
40 static_assert(::gig::lfo_wave_square == LFO::wave_square);
41
42 // converts ::gig::lfo_wave_t (libgig) -> LFO::wave_t (LinuxSampler)
43 inline LFO::wave_t fromGigLfoWave(::gig::lfo_wave_t wave) {
44 // simply assuming equally mapped enums on both sides
45 return static_cast<LFO::wave_t>(wave);
46 }
47
48 Voice::Voice() {
49 pEngine = NULL;
50 pEG1 = &EG1;
51 pEG2 = &EG2;
52 }
53
54 Voice::~Voice() {
55 }
56
57 EngineChannel* Voice::GetGigEngineChannel() {
58 return static_cast<EngineChannel*>(pEngineChannel);
59 }
60
61 void Voice::SetEngine(LinuxSampler::Engine* pEngine) {
62 Engine* engine = static_cast<Engine*>(pEngine);
63 this->pEngine = engine;
64 this->pDiskThread = engine->pDiskThread;
65 dmsg(6,("Voice::SetEngine()\n"));
66 }
67
68 Voice::SampleInfo Voice::GetSampleInfo() {
69 SampleInfo si;
70 si.SampleRate = pSample->SamplesPerSecond;
71 si.ChannelCount = pSample->Channels;
72 si.FrameSize = pSample->FrameSize;
73 si.BitDepth = pSample->BitDepth;
74 si.TotalFrameCount = (uint)pSample->SamplesTotal;
75
76 si.HasLoops = pRegion->SampleLoops;
77 si.LoopStart = (si.HasLoops) ? pRegion->pSampleLoops[0].LoopStart : 0;
78 si.LoopLength = (si.HasLoops) ? pRegion->pSampleLoops[0].LoopLength : 0;
79 si.LoopPlayCount = pSample->LoopPlayCount;
80 si.Unpitched = !pRegion->PitchTrack;
81
82 return si;
83 }
84
85 Voice::RegionInfo Voice::GetRegionInfo() {
86 RegionInfo ri;
87 ri.UnityNote = pRegion->UnityNote;
88 ri.FineTune = pRegion->FineTune;
89 ri.Pan = pRegion->Pan;
90 ri.SampleStartOffset = pRegion->SampleStartOffset;
91
92 ri.EG2PreAttack = pRegion->EG2PreAttack;
93 ri.EG2Attack = pRegion->EG2Attack;
94 ri.EG2Decay1 = pRegion->EG2Decay1;
95 ri.EG2Decay2 = pRegion->EG2Decay2;
96 ri.EG2Sustain = pRegion->EG2Sustain;
97 ri.EG2InfiniteSustain = pRegion->EG2InfiniteSustain;
98 ri.EG2Release = pRegion->EG2Release;
99
100 ri.EG3Attack = pRegion->EG3Attack;
101 ri.EG3Depth = pRegion->EG3Depth;
102 ri.VCFEnabled = pRegion->VCFEnabled;
103 ri.VCFType = Filter::vcf_type_t(pRegion->VCFType);
104 ri.VCFResonance = pRegion->VCFResonance;
105
106 ri.ReleaseTriggerDecay = 0.01053 * (256 >> pRegion->ReleaseTriggerDecay);
107
108 return ri;
109 }
110
111 Voice::InstrumentInfo Voice::GetInstrumentInfo() {
112 InstrumentInfo ii;
113 ii.FineTune = GetGigEngineChannel()->pInstrument->FineTune;
114 ii.PitchbendRange = GetGigEngineChannel()->pInstrument->PitchbendRange;
115
116 return ii;
117 }
118
119 double Voice::GetSampleAttenuation() {
120 return pRegion->SampleAttenuation;
121 }
122
123 double Voice::GetVelocityAttenuation(uint8_t MIDIKeyVelocity) {
124 return pRegion->GetVelocityAttenuation(MIDIKeyVelocity);
125 }
126
127 double Voice::GetVelocityRelease(uint8_t MIDIKeyVelocity) {
128 return pRegion->GetVelocityRelease(MIDIKeyVelocity);
129 }
130
131 void Voice::ProcessCCEvent(RTList<Event>::Iterator& itEvent) {
132 if (itEvent->Type == Event::type_control_change && itEvent->Param.CC.Controller) { // if (valid) MIDI control change event
133 if (pRegion->AttenuationController.type == ::gig::attenuation_ctrl_t::type_controlchange &&
134 itEvent->Param.CC.Controller == pRegion->AttenuationController.controller_number) {
135 CrossfadeSmoother.update(AbstractEngine::CrossfadeCurve[CrossfadeAttenuation(itEvent->Param.CC.Value)]);
136 }
137 }
138 }
139
140 void Voice::ProcessChannelPressureEvent(RTList<Event>::Iterator& itEvent) {
141 if (itEvent->Type == Event::type_channel_pressure) { // if (valid) MIDI channel pressure (aftertouch) event
142 if (pRegion->AttenuationController.type == ::gig::attenuation_ctrl_t::type_channelaftertouch) {
143 CrossfadeSmoother.update(AbstractEngine::CrossfadeCurve[CrossfadeAttenuation(itEvent->Param.ChannelPressure.Value)]);
144 }
145 }
146 }
147
148 void Voice::ProcessPolyphonicKeyPressureEvent(RTList<Event>::Iterator& itEvent) {
149 // Not used so far
150 }
151
152 void Voice::ProcessCutoffEvent(RTList<Event>::Iterator& itEvent) {
153 int ccvalue = itEvent->Param.CC.Value;
154 if (VCFCutoffCtrl.value == ccvalue) return;
155 VCFCutoffCtrl.value = ccvalue;
156 if (pRegion->VCFCutoffControllerInvert) ccvalue = 127 - ccvalue;
157 if (ccvalue < pRegion->VCFVelocityScale) ccvalue = pRegion->VCFVelocityScale;
158 float cutoff = CutoffBase * float(ccvalue);
159 if (cutoff > 127.0f) cutoff = 127.0f;
160
161 VCFCutoffCtrl.fvalue = cutoff; // needed for initialization of fFinalCutoff next time
162 fFinalCutoff = cutoff;
163 }
164
165 double Voice::CalculateCrossfadeVolume(uint8_t MIDIKeyVelocity) {
166 float crossfadeVolume;
167 switch (pRegion->AttenuationController.type) {
168 case ::gig::attenuation_ctrl_t::type_channelaftertouch:
169 crossfadeVolume = Engine::CrossfadeCurve[CrossfadeAttenuation(GetGigEngineChannel()->ControllerTable[128])];
170 break;
171 case ::gig::attenuation_ctrl_t::type_velocity:
172 crossfadeVolume = Engine::CrossfadeCurve[CrossfadeAttenuation(MIDIKeyVelocity)];
173 break;
174 case ::gig::attenuation_ctrl_t::type_controlchange: //FIXME: currently not sample accurate
175 crossfadeVolume = Engine::CrossfadeCurve[CrossfadeAttenuation(GetGigEngineChannel()->ControllerTable[pRegion->AttenuationController.controller_number])];
176 break;
177 case ::gig::attenuation_ctrl_t::type_none: // no crossfade defined
178 default:
179 crossfadeVolume = 1.0f;
180 }
181
182 return crossfadeVolume;
183 }
184
185 double Voice::GetEG1ControllerValue(uint8_t MIDIKeyVelocity) {
186 double eg1controllervalue = 0;
187 switch (pRegion->EG1Controller.type) {
188 case ::gig::eg1_ctrl_t::type_none: // no controller defined
189 eg1controllervalue = 0;
190 break;
191 case ::gig::eg1_ctrl_t::type_channelaftertouch:
192 eg1controllervalue = GetGigEngineChannel()->ControllerTable[128];
193 break;
194 case ::gig::eg1_ctrl_t::type_velocity:
195 eg1controllervalue = MIDIKeyVelocity;
196 break;
197 case ::gig::eg1_ctrl_t::type_controlchange: // MIDI control change controller
198 eg1controllervalue = GetGigEngineChannel()->ControllerTable[pRegion->EG1Controller.controller_number];
199 break;
200 }
201 if (pRegion->EG1ControllerInvert) eg1controllervalue = 127 - eg1controllervalue;
202
203 return eg1controllervalue;
204 }
205
206 Voice::EGInfo Voice::CalculateEG1ControllerInfluence(double eg1ControllerValue) {
207 EGInfo eg;
208 // (eg1attack is different from the others)
209 if (pRegion->EG1Attack < 1e-8 && // attack in gig == 0
210 (pRegion->EG1ControllerAttackInfluence == 0 ||
211 eg1ControllerValue <= 10)) { // strange GSt special case
212 eg.Attack = 0; // this will force the attack to be 0 in the call to EG1.trigger
213 } else {
214 eg.Attack = (pRegion->EG1ControllerAttackInfluence) ?
215 1 + 0.031 * (double) (pRegion->EG1ControllerAttackInfluence == 1 ?
216 1 : 1 << pRegion->EG1ControllerAttackInfluence) * eg1ControllerValue : 1.0;
217 }
218 eg.Decay = (pRegion->EG1ControllerDecayInfluence) ? 1 + 0.00775 * (double) (1 << pRegion->EG1ControllerDecayInfluence) * eg1ControllerValue : 1.0;
219 eg.Release = (pRegion->EG1ControllerReleaseInfluence) ? 1 + 0.00775 * (double) (1 << pRegion->EG1ControllerReleaseInfluence) * eg1ControllerValue : 1.0;
220
221 return eg;
222 }
223
224 double Voice::GetEG2ControllerValue(uint8_t MIDIKeyVelocity) {
225 double eg2controllervalue = 0;
226 switch (pRegion->EG2Controller.type) {
227 case ::gig::eg2_ctrl_t::type_none: // no controller defined
228 eg2controllervalue = 0;
229 break;
230 case ::gig::eg2_ctrl_t::type_channelaftertouch:
231 eg2controllervalue = GetGigEngineChannel()->ControllerTable[128];
232 break;
233 case ::gig::eg2_ctrl_t::type_velocity:
234 eg2controllervalue = MIDIKeyVelocity;
235 break;
236 case ::gig::eg2_ctrl_t::type_controlchange: // MIDI control change controller
237 eg2controllervalue = GetGigEngineChannel()->ControllerTable[pRegion->EG2Controller.controller_number];
238 break;
239 }
240 if (pRegion->EG2ControllerInvert) eg2controllervalue = 127 - eg2controllervalue;
241
242 return eg2controllervalue;
243 }
244
245 Voice::EGInfo Voice::CalculateEG2ControllerInfluence(double eg2ControllerValue) {
246 EGInfo eg;
247 eg.Attack = (pRegion->EG2ControllerAttackInfluence) ? 1 + 0.00775 * (double) (1 << pRegion->EG2ControllerAttackInfluence) * eg2ControllerValue : 1.0;
248 eg.Decay = (pRegion->EG2ControllerDecayInfluence) ? 1 + 0.00775 * (double) (1 << pRegion->EG2ControllerDecayInfluence) * eg2ControllerValue : 1.0;
249 eg.Release = (pRegion->EG2ControllerReleaseInfluence) ? 1 + 0.00775 * (double) (1 << pRegion->EG2ControllerReleaseInfluence) * eg2ControllerValue : 1.0;
250
251 return eg;
252 }
253
254 void Voice::InitLFO1() {
255 uint16_t lfo1_internal_depth;
256 switch (pRegion->LFO1Controller) {
257 case ::gig::lfo1_ctrl_internal:
258 lfo1_internal_depth = pRegion->LFO1InternalDepth;
259 pLFO1->ExtController = 0; // no external controller
260 bLFO1Enabled = (lfo1_internal_depth > 0);
261 break;
262 case ::gig::lfo1_ctrl_modwheel:
263 lfo1_internal_depth = 0;
264 pLFO1->ExtController = 1; // MIDI controller 1
265 bLFO1Enabled = (pRegion->LFO1ControlDepth > 0);
266 break;
267 case ::gig::lfo1_ctrl_breath:
268 lfo1_internal_depth = 0;
269 pLFO1->ExtController = 2; // MIDI controller 2
270 bLFO1Enabled = (pRegion->LFO1ControlDepth > 0);
271 break;
272 case ::gig::lfo1_ctrl_internal_modwheel:
273 lfo1_internal_depth = pRegion->LFO1InternalDepth;
274 pLFO1->ExtController = 1; // MIDI controller 1
275 bLFO1Enabled = (lfo1_internal_depth > 0 || pRegion->LFO1ControlDepth > 0);
276 break;
277 case ::gig::lfo1_ctrl_internal_breath:
278 lfo1_internal_depth = pRegion->LFO1InternalDepth;
279 pLFO1->ExtController = 2; // MIDI controller 2
280 bLFO1Enabled = (lfo1_internal_depth > 0 || pRegion->LFO1ControlDepth > 0);
281 break;
282 default:
283 lfo1_internal_depth = 0;
284 pLFO1->ExtController = 0; // no external controller
285 bLFO1Enabled = false;
286 }
287 if (bLFO1Enabled) {
288 pLFO1->trigger(fromGigLfoWave(pRegion->LFO1WaveForm),
289 pRegion->LFO1Frequency,
290 pRegion->LFO1Phase,
291 LFO::start_level_mid, // see https://sourceforge.net/p/linuxsampler/mailman/linuxsampler-devel/thread/2189307.cNP0Xbctxq%40silver/#msg36774029
292 lfo1_internal_depth,
293 pRegion->LFO1ControlDepth,
294 pRegion->LFO1FlipPhase,
295 pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
296 pLFO1->updateByMIDICtrlValue(pLFO1->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO1->ExtController] : 0);
297 pLFO1->setScriptDepthFactor(
298 pNote->Override.AmpLFODepth.Value,
299 pNote->Override.AmpLFODepth.Final
300 );
301 if (pNote->Override.AmpLFOFreq.isFinal())
302 pLFO1->setScriptFrequencyFinal(
303 pNote->Override.AmpLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE
304 );
305 else
306 pLFO1->setScriptFrequencyFactor(
307 pNote->Override.AmpLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE
308 );
309 }
310 }
311
312 void Voice::InitLFO2() {
313 uint16_t lfo2_internal_depth;
314 switch (pRegion->LFO2Controller) {
315 case ::gig::lfo2_ctrl_internal:
316 lfo2_internal_depth = pRegion->LFO2InternalDepth;
317 pLFO2->ExtController = 0; // no external controller
318 bLFO2Enabled = (lfo2_internal_depth > 0);
319 break;
320 case ::gig::lfo2_ctrl_modwheel:
321 lfo2_internal_depth = 0;
322 pLFO2->ExtController = 1; // MIDI controller 1
323 bLFO2Enabled = (pRegion->LFO2ControlDepth > 0);
324 break;
325 case ::gig::lfo2_ctrl_foot:
326 lfo2_internal_depth = 0;
327 pLFO2->ExtController = 4; // MIDI controller 4
328 bLFO2Enabled = (pRegion->LFO2ControlDepth > 0);
329 break;
330 case ::gig::lfo2_ctrl_internal_modwheel:
331 lfo2_internal_depth = pRegion->LFO2InternalDepth;
332 pLFO2->ExtController = 1; // MIDI controller 1
333 bLFO2Enabled = (lfo2_internal_depth > 0 || pRegion->LFO2ControlDepth > 0);
334 break;
335 case ::gig::lfo2_ctrl_internal_foot:
336 lfo2_internal_depth = pRegion->LFO2InternalDepth;
337 pLFO2->ExtController = 4; // MIDI controller 4
338 bLFO2Enabled = (lfo2_internal_depth > 0 || pRegion->LFO2ControlDepth > 0);
339 break;
340 default:
341 lfo2_internal_depth = 0;
342 pLFO2->ExtController = 0; // no external controller
343 bLFO2Enabled = false;
344 }
345 if (bLFO2Enabled) {
346 pLFO2->trigger(fromGigLfoWave(pRegion->LFO2WaveForm),
347 pRegion->LFO2Frequency,
348 pRegion->LFO2Phase,
349 LFO::start_level_mid, // see https://sourceforge.net/p/linuxsampler/mailman/linuxsampler-devel/thread/2189307.cNP0Xbctxq%40silver/#msg36774029
350 lfo2_internal_depth,
351 pRegion->LFO2ControlDepth,
352 pRegion->LFO2FlipPhase,
353 pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
354 pLFO2->updateByMIDICtrlValue(pLFO2->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO2->ExtController] : 0);
355 pLFO2->setScriptDepthFactor(
356 pNote->Override.CutoffLFODepth.Value,
357 pNote->Override.CutoffLFODepth.Final
358 );
359 if (pNote->Override.CutoffLFOFreq.isFinal())
360 pLFO2->setScriptFrequencyFinal(pNote->Override.CutoffLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
361 else
362 pLFO2->setScriptFrequencyFactor(pNote->Override.CutoffLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
363 }
364 }
365
366 void Voice::InitLFO3() {
367 uint16_t lfo3_internal_depth;
368 switch (pRegion->LFO3Controller) {
369 case ::gig::lfo3_ctrl_internal:
370 lfo3_internal_depth = pRegion->LFO3InternalDepth;
371 pLFO3->ExtController = 0; // no external controller
372 bLFO3Enabled = (lfo3_internal_depth > 0);
373 break;
374 case ::gig::lfo3_ctrl_modwheel:
375 lfo3_internal_depth = 0;
376 pLFO3->ExtController = 1; // MIDI controller 1
377 bLFO3Enabled = (pRegion->LFO3ControlDepth > 0);
378 break;
379 case ::gig::lfo3_ctrl_aftertouch:
380 lfo3_internal_depth = 0;
381 pLFO3->ExtController = CTRL_TABLE_IDX_AFTERTOUCH;
382 bLFO3Enabled = true;
383 break;
384 case ::gig::lfo3_ctrl_internal_modwheel:
385 lfo3_internal_depth = pRegion->LFO3InternalDepth;
386 pLFO3->ExtController = 1; // MIDI controller 1
387 bLFO3Enabled = (lfo3_internal_depth > 0 || pRegion->LFO3ControlDepth > 0);
388 break;
389 case ::gig::lfo3_ctrl_internal_aftertouch:
390 lfo3_internal_depth = pRegion->LFO3InternalDepth;
391 pLFO3->ExtController = CTRL_TABLE_IDX_AFTERTOUCH;
392 bLFO3Enabled = (lfo3_internal_depth > 0 || pRegion->LFO3ControlDepth > 0);
393 break;
394 default:
395 lfo3_internal_depth = 0;
396 pLFO3->ExtController = 0; // no external controller
397 bLFO3Enabled = false;
398 }
399 if (bLFO3Enabled) {
400 pLFO3->trigger(fromGigLfoWave(pRegion->LFO3WaveForm),
401 pRegion->LFO3Frequency,
402 pRegion->LFO3Phase,
403 LFO::start_level_max, // see https://sourceforge.net/p/linuxsampler/mailman/linuxsampler-devel/thread/2189307.cNP0Xbctxq%40silver/#msg36774029
404 lfo3_internal_depth,
405 pRegion->LFO3ControlDepth,
406 pRegion->LFO3FlipPhase,
407 pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
408 pLFO3->updateByMIDICtrlValue(pLFO3->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO3->ExtController] : 0);
409 pLFO3->setScriptDepthFactor(
410 pNote->Override.PitchLFODepth.Value,
411 pNote->Override.PitchLFODepth.Final
412 );
413 if (pNote->Override.PitchLFOFreq.isFinal())
414 pLFO3->setScriptFrequencyFinal(pNote->Override.PitchLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
415 else
416 pLFO3->setScriptFrequencyFactor(pNote->Override.PitchLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
417 }
418 }
419
420 float Voice::CalculateCutoffBase(uint8_t MIDIKeyVelocity) {
421 float cutoff = pRegion->GetVelocityCutoff(MIDIKeyVelocity);
422 if (pRegion->VCFKeyboardTracking) {
423 cutoff *= RTMath::CentsToFreqRatioUnlimited((MIDIKey() - pRegion->VCFKeyboardTrackingBreakpoint) * 100);
424 }
425 return cutoff;
426 }
427
428 float Voice::CalculateFinalCutoff(float cutoffBase) {
429 int cvalue;
430 if (VCFCutoffCtrl.controller) {
431 cvalue = GetGigEngineChannel()->ControllerTable[VCFCutoffCtrl.controller];
432 if (pRegion->VCFCutoffControllerInvert) cvalue = 127 - cvalue;
433 // VCFVelocityScale in this case means Minimum cutoff
434 if (cvalue < pRegion->VCFVelocityScale) cvalue = pRegion->VCFVelocityScale;
435 }
436 else {
437 cvalue = pRegion->VCFCutoff;
438 }
439 float fco = cutoffBase * float(cvalue);
440 if (fco > 127.0f) fco = 127.0f;
441
442 return fco;
443 }
444
445 uint8_t Voice::GetVCFCutoffCtrl() {
446 uint8_t ctrl;
447 switch (pRegion->VCFCutoffController) {
448 case ::gig::vcf_cutoff_ctrl_modwheel:
449 ctrl = 1;
450 break;
451 case ::gig::vcf_cutoff_ctrl_effect1:
452 ctrl = 12;
453 break;
454 case ::gig::vcf_cutoff_ctrl_effect2:
455 ctrl = 13;
456 break;
457 case ::gig::vcf_cutoff_ctrl_breath:
458 ctrl = 2;
459 break;
460 case ::gig::vcf_cutoff_ctrl_foot:
461 ctrl = 4;
462 break;
463 case ::gig::vcf_cutoff_ctrl_sustainpedal:
464 ctrl = 64;
465 break;
466 case ::gig::vcf_cutoff_ctrl_softpedal:
467 ctrl = 67;
468 break;
469 case ::gig::vcf_cutoff_ctrl_genpurpose7:
470 ctrl = 82;
471 break;
472 case ::gig::vcf_cutoff_ctrl_genpurpose8:
473 ctrl = 83;
474 break;
475 case ::gig::vcf_cutoff_ctrl_aftertouch:
476 ctrl = CTRL_TABLE_IDX_AFTERTOUCH;
477 break;
478 case ::gig::vcf_cutoff_ctrl_none:
479 default:
480 ctrl = 0;
481 break;
482 }
483
484 return ctrl;
485 }
486
487 uint8_t Voice::GetVCFResonanceCtrl() {
488 uint8_t ctrl;
489 switch (pRegion->VCFResonanceController) {
490 case ::gig::vcf_res_ctrl_genpurpose3:
491 ctrl = 18;
492 break;
493 case ::gig::vcf_res_ctrl_genpurpose4:
494 ctrl = 19;
495 break;
496 case ::gig::vcf_res_ctrl_genpurpose5:
497 ctrl = 80;
498 break;
499 case ::gig::vcf_res_ctrl_genpurpose6:
500 ctrl = 81;
501 break;
502 case ::gig::vcf_res_ctrl_none:
503 default:
504 ctrl = 0;
505 }
506
507 return ctrl;
508 }
509
510 void Voice::TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) {
511 EG1.setStateOptions(
512 pRegion->EG1Options.AttackCancel,
513 pRegion->EG1Options.AttackHoldCancel,
514 pRegion->EG1Options.Decay1Cancel,
515 pRegion->EG1Options.Decay2Cancel,
516 pRegion->EG1Options.ReleaseCancel
517 );
518 EG1.trigger(pRegion->EG1PreAttack,
519 (pNote && pNote->Override.Attack.isFinal()) ?
520 pNote->Override.Attack.Value :
521 RTMath::Max(pRegion->EG1Attack, 0.0316) * egInfo.Attack,
522 pRegion->EG1Hold,
523 (pNote && pNote->Override.Decay.isFinal()) ?
524 pNote->Override.Decay.Value :
525 pRegion->EG1Decay1 * egInfo.Decay * velrelease,
526 (pNote && pNote->Override.Decay.isFinal()) ?
527 pNote->Override.Decay.Value :
528 pRegion->EG1Decay2 * egInfo.Decay * velrelease,
529 pRegion->EG1InfiniteSustain,
530 (pNote && pNote->Override.Sustain.Final) ?
531 uint(pNote->Override.Sustain.Value * 1000.f) :
532 pRegion->EG1Sustain * (pNote ? pNote->Override.Sustain.Value : 1.f),
533 (pNote && pNote->Override.Release.isFinal()) ?
534 pNote->Override.Release.Value :
535 RTMath::Max(pRegion->EG1Release * velrelease, 0.014) * egInfo.Release,
536 velocityAttenuation,
537 sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
538 }
539
540 void Voice::TriggerEG2(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) {
541 EG2.setStateOptions(
542 pRegion->EG2Options.AttackCancel,
543 pRegion->EG2Options.AttackHoldCancel,
544 pRegion->EG2Options.Decay1Cancel,
545 pRegion->EG2Options.Decay2Cancel,
546 pRegion->EG2Options.ReleaseCancel
547 );
548 EG2.trigger(uint(RgnInfo.EG2PreAttack),
549 (pNote && pNote->Override.CutoffAttack.isFinal()) ?
550 pNote->Override.CutoffAttack.Value :
551 RgnInfo.EG2Attack * egInfo.Attack,
552 false,
553 (pNote && pNote->Override.CutoffDecay.isFinal()) ?
554 pNote->Override.CutoffDecay.Value :
555 RgnInfo.EG2Decay1 * egInfo.Decay * velrelease,
556 (pNote && pNote->Override.CutoffDecay.isFinal()) ?
557 pNote->Override.CutoffDecay.Value :
558 RgnInfo.EG2Decay2 * egInfo.Decay * velrelease,
559 RgnInfo.EG2InfiniteSustain,
560 (pNote && pNote->Override.CutoffSustain.Final) ?
561 uint(pNote->Override.CutoffSustain.Value * 1000.f) :
562 uint(RgnInfo.EG2Sustain),
563 (pNote && pNote->Override.CutoffRelease.isFinal()) ?
564 pNote->Override.CutoffRelease.Value :
565 RgnInfo.EG2Release * egInfo.Release * velrelease,
566 velocityAttenuation,
567 sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
568 }
569
570 void Voice::ProcessGroupEvent(RTList<Event>::Iterator& itEvent) {
571 dmsg(4,("Voice %p processGroupEvents event type=%d", (void*)this, itEvent->Type));
572
573 // TODO: The SustainPedal condition could be wrong, maybe the
574 // check should be if this Voice is in release stage or is a
575 // release sample instead. Need to test this in GSt.
576 // -- Andreas
577 //
578 // Commented sustain pedal check out. I don't think voices of the same
579 // note should be stopped at all, because it doesn't sound naturally
580 // with a drumkit.
581 // -- Christian, 2013-01-08
582 if (itEvent->Param.Note.Key != HostKey() /*||
583 !GetGigEngineChannel()->SustainPedal*/) {
584 dmsg(4,("Voice %p - kill", (void*)this));
585
586 // kill the voice fast
587 pEG1->enterFadeOutStage();
588 }
589 }
590
591 void Voice::CalculateFadeOutCoeff(float FadeOutTime, float SampleRate) {
592 EG1.CalculateFadeOutCoeff(FadeOutTime, SampleRate);
593 }
594
595 int Voice::CalculatePan(uint8_t pan) {
596 int p;
597 // Gst behaviour: -64 and 63 are special cases
598 if (RgnInfo.Pan == -64) p = pan * 2 - 127;
599 else if (RgnInfo.Pan == 63) p = pan * 2;
600 else p = pan + RgnInfo.Pan;
601
602 if (p < 0) return 0;
603 if (p > 127) return 127;
604 return p;
605 }
606
607 release_trigger_t Voice::GetReleaseTriggerFlags() {
608 release_trigger_t flags =
609 (pRegion->NoNoteOffReleaseTrigger) ?
610 release_trigger_none : release_trigger_noteoff; //HACK: currently this method is actually only called by EngineBase if it already knows that this voice requires release trigger, so I took the short way instead of checking (again) the existence of a ::gig::dimension_releasetrigger
611 switch (pRegion->SustainReleaseTrigger) {
612 case ::gig::sust_rel_trg_none:
613 break;
614 case ::gig::sust_rel_trg_maxvelocity:
615 flags |= release_trigger_sustain_maxvelocity;
616 break;
617 case ::gig::sust_rel_trg_keyvelocity:
618 flags |= release_trigger_sustain_keyvelocity;
619 break;
620 }
621 return flags;
622 }
623
624 }} // namespace LinuxSampler::gig

  ViewVC Help
Powered by ViewVC