3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2009 Christian Schoenebeck * |
* Copyright (C) 2005 - 2008 Christian Schoenebeck * |
7 |
* Copyright (C) 2009 Grigor Iliev * |
* Copyright (C) 2009 - 2015 Christian Schoenebeck and Grigor Iliev * |
8 |
* * |
* * |
9 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
10 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
33 |
namespace LinuxSampler { namespace gig { |
namespace LinuxSampler { namespace gig { |
34 |
|
|
35 |
Voice::Voice() { |
Voice::Voice() { |
36 |
pEngine = NULL; |
pEngine = NULL; |
37 |
|
pEG1 = &EG1; |
38 |
|
pEG2 = &EG2; |
39 |
} |
} |
40 |
|
|
41 |
Voice::~Voice() { |
Voice::~Voice() { |
|
|
|
42 |
} |
} |
43 |
|
|
44 |
EngineChannel* Voice::GetGigEngineChannel() { |
EngineChannel* Voice::GetGigEngineChannel() { |
76 |
ri.Pan = pRegion->Pan; |
ri.Pan = pRegion->Pan; |
77 |
ri.SampleStartOffset = pRegion->SampleStartOffset; |
ri.SampleStartOffset = pRegion->SampleStartOffset; |
78 |
|
|
|
ri.EG1PreAttack = pRegion->EG1PreAttack; |
|
|
ri.EG1Attack = pRegion->EG1Attack; |
|
|
ri.EG1Hold = pRegion->EG1Hold; |
|
|
ri.EG1Decay1 = pRegion->EG1Decay1; |
|
|
ri.EG1Decay2 = pRegion->EG1Decay2; |
|
|
ri.EG1Sustain = pRegion->EG1Sustain; |
|
|
ri.EG1InfiniteSustain = pRegion->EG1InfiniteSustain; |
|
|
ri.EG1Release = pRegion->EG1Release; |
|
|
|
|
79 |
ri.EG2PreAttack = pRegion->EG2PreAttack; |
ri.EG2PreAttack = pRegion->EG2PreAttack; |
80 |
ri.EG2Attack = pRegion->EG2Attack; |
ri.EG2Attack = pRegion->EG2Attack; |
81 |
ri.EG2Decay1 = pRegion->EG2Decay1; |
ri.EG2Decay1 = pRegion->EG2Decay1; |
87 |
ri.EG3Attack = pRegion->EG3Attack; |
ri.EG3Attack = pRegion->EG3Attack; |
88 |
ri.EG3Depth = pRegion->EG3Depth; |
ri.EG3Depth = pRegion->EG3Depth; |
89 |
ri.VCFEnabled = pRegion->VCFEnabled; |
ri.VCFEnabled = pRegion->VCFEnabled; |
90 |
ri.VCFType = pRegion->VCFType; |
ri.VCFType = Filter::vcf_type_t(pRegion->VCFType); |
91 |
ri.VCFResonance = pRegion->VCFResonance; |
ri.VCFResonance = pRegion->VCFResonance; |
92 |
|
|
93 |
ri.ReleaseTriggerDecay = pRegion->ReleaseTriggerDecay; |
ri.ReleaseTriggerDecay = 0.01053 * (256 >> pRegion->ReleaseTriggerDecay); |
94 |
|
|
95 |
return ri; |
return ri; |
96 |
} |
} |
124 |
} |
} |
125 |
} |
} |
126 |
|
|
127 |
|
void Voice::ProcessChannelPressureEvent(RTList<Event>::Iterator& itEvent) { |
128 |
|
if (itEvent->Type == Event::type_channel_pressure) { // if (valid) MIDI channel pressure (aftertouch) event |
129 |
|
if (pRegion->AttenuationController.type == ::gig::attenuation_ctrl_t::type_channelaftertouch) { |
130 |
|
CrossfadeSmoother.update(AbstractEngine::CrossfadeCurve[CrossfadeAttenuation(itEvent->Param.ChannelPressure.Value)]); |
131 |
|
} |
132 |
|
} |
133 |
|
} |
134 |
|
|
135 |
|
void Voice::ProcessPolyphonicKeyPressureEvent(RTList<Event>::Iterator& itEvent) { |
136 |
|
// Not used so far |
137 |
|
} |
138 |
|
|
139 |
void Voice::ProcessCutoffEvent(RTList<Event>::Iterator& itEvent) { |
void Voice::ProcessCutoffEvent(RTList<Event>::Iterator& itEvent) { |
140 |
int ccvalue = itEvent->Param.CC.Value; |
int ccvalue = itEvent->Param.CC.Value; |
141 |
if (VCFCutoffCtrl.value == ccvalue) return; |
if (VCFCutoffCtrl.value == ccvalue) return; |
142 |
VCFCutoffCtrl.value == ccvalue; |
VCFCutoffCtrl.value = ccvalue; |
143 |
if (pRegion->VCFCutoffControllerInvert) ccvalue = 127 - ccvalue; |
if (pRegion->VCFCutoffControllerInvert) ccvalue = 127 - ccvalue; |
144 |
if (ccvalue < pRegion->VCFVelocityScale) ccvalue = pRegion->VCFVelocityScale; |
if (ccvalue < pRegion->VCFVelocityScale) ccvalue = pRegion->VCFVelocityScale; |
145 |
float cutoff = CutoffBase * float(ccvalue); |
float cutoff = CutoffBase * float(ccvalue); |
193 |
Voice::EGInfo Voice::CalculateEG1ControllerInfluence(double eg1ControllerValue) { |
Voice::EGInfo Voice::CalculateEG1ControllerInfluence(double eg1ControllerValue) { |
194 |
EGInfo eg; |
EGInfo eg; |
195 |
// (eg1attack is different from the others) |
// (eg1attack is different from the others) |
196 |
eg.Attack = (pRegion->EG1ControllerAttackInfluence) ? |
if (pRegion->EG1Attack < 1e-8 && // attack in gig == 0 |
197 |
1 + 0.031 * (double) (pRegion->EG1ControllerAttackInfluence == 1 ? |
(pRegion->EG1ControllerAttackInfluence == 0 || |
198 |
1 : 1 << pRegion->EG1ControllerAttackInfluence) * eg1ControllerValue : 1.0; |
eg1ControllerValue <= 10)) { // strange GSt special case |
199 |
|
eg.Attack = 0; // this will force the attack to be 0 in the call to EG1.trigger |
200 |
|
} else { |
201 |
|
eg.Attack = (pRegion->EG1ControllerAttackInfluence) ? |
202 |
|
1 + 0.031 * (double) (pRegion->EG1ControllerAttackInfluence == 1 ? |
203 |
|
1 : 1 << pRegion->EG1ControllerAttackInfluence) * eg1ControllerValue : 1.0; |
204 |
|
} |
205 |
eg.Decay = (pRegion->EG1ControllerDecayInfluence) ? 1 + 0.00775 * (double) (1 << pRegion->EG1ControllerDecayInfluence) * eg1ControllerValue : 1.0; |
eg.Decay = (pRegion->EG1ControllerDecayInfluence) ? 1 + 0.00775 * (double) (1 << pRegion->EG1ControllerDecayInfluence) * eg1ControllerValue : 1.0; |
206 |
eg.Release = (pRegion->EG1ControllerReleaseInfluence) ? 1 + 0.00775 * (double) (1 << pRegion->EG1ControllerReleaseInfluence) * eg1ControllerValue : 1.0; |
eg.Release = (pRegion->EG1ControllerReleaseInfluence) ? 1 + 0.00775 * (double) (1 << pRegion->EG1ControllerReleaseInfluence) * eg1ControllerValue : 1.0; |
207 |
|
|
341 |
break; |
break; |
342 |
case ::gig::lfo3_ctrl_aftertouch: |
case ::gig::lfo3_ctrl_aftertouch: |
343 |
lfo3_internal_depth = 0; |
lfo3_internal_depth = 0; |
344 |
pLFO3->ExtController = 128; |
pLFO3->ExtController = CTRL_TABLE_IDX_AFTERTOUCH; |
345 |
bLFO3Enabled = true; |
bLFO3Enabled = true; |
346 |
break; |
break; |
347 |
case ::gig::lfo3_ctrl_internal_modwheel: |
case ::gig::lfo3_ctrl_internal_modwheel: |
351 |
break; |
break; |
352 |
case ::gig::lfo3_ctrl_internal_aftertouch: |
case ::gig::lfo3_ctrl_internal_aftertouch: |
353 |
lfo3_internal_depth = pRegion->LFO3InternalDepth; |
lfo3_internal_depth = pRegion->LFO3InternalDepth; |
354 |
pLFO1->ExtController = 128; |
pLFO3->ExtController = CTRL_TABLE_IDX_AFTERTOUCH; |
355 |
bLFO3Enabled = (lfo3_internal_depth > 0 || pRegion->LFO3ControlDepth > 0); |
bLFO3Enabled = (lfo3_internal_depth > 0 || pRegion->LFO3ControlDepth > 0); |
356 |
break; |
break; |
357 |
default: |
default: |
369 |
pLFO3->update(pLFO3->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO3->ExtController] : 0); |
pLFO3->update(pLFO3->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO3->ExtController] : 0); |
370 |
} |
} |
371 |
} |
} |
372 |
|
|
373 |
float Voice::CalculateCutoffBase(uint8_t MIDIKeyVelocity) { |
float Voice::CalculateCutoffBase(uint8_t MIDIKeyVelocity) { |
374 |
float cutoff = pRegion->GetVelocityCutoff(MIDIKeyVelocity); |
float cutoff = pRegion->GetVelocityCutoff(MIDIKeyVelocity); |
375 |
if (pRegion->VCFKeyboardTracking) { |
if (pRegion->VCFKeyboardTracking) { |
376 |
cutoff *= exp((MIDIKeyVelocity - pRegion->VCFKeyboardTrackingBreakpoint) * 0.057762265f); // (ln(2) / 12) |
cutoff *= RTMath::CentsToFreqRatioUnlimited((MIDIKey() - pRegion->VCFKeyboardTrackingBreakpoint) * 100); |
377 |
} |
} |
378 |
return cutoff; |
return cutoff; |
379 |
} |
} |
426 |
ctrl = 83; |
ctrl = 83; |
427 |
break; |
break; |
428 |
case ::gig::vcf_cutoff_ctrl_aftertouch: |
case ::gig::vcf_cutoff_ctrl_aftertouch: |
429 |
ctrl = 128; |
ctrl = CTRL_TABLE_IDX_AFTERTOUCH; |
430 |
break; |
break; |
431 |
case ::gig::vcf_cutoff_ctrl_none: |
case ::gig::vcf_cutoff_ctrl_none: |
432 |
default: |
default: |
460 |
return ctrl; |
return ctrl; |
461 |
} |
} |
462 |
|
|
463 |
|
void Voice::TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) { |
464 |
|
EG1.trigger(pRegion->EG1PreAttack, |
465 |
|
RTMath::Max(pRegion->EG1Attack, 0.0316) * egInfo.Attack, |
466 |
|
pRegion->EG1Hold, |
467 |
|
pRegion->EG1Decay1 * egInfo.Decay * velrelease, |
468 |
|
pRegion->EG1Decay2 * egInfo.Decay * velrelease, |
469 |
|
pRegion->EG1InfiniteSustain, |
470 |
|
pRegion->EG1Sustain, |
471 |
|
RTMath::Max(pRegion->EG1Release * velrelease, 0.014) * egInfo.Release, |
472 |
|
velocityAttenuation, |
473 |
|
sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
474 |
|
} |
475 |
|
|
476 |
|
void Voice::TriggerEG2(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) { |
477 |
|
EG2.trigger(uint(RgnInfo.EG2PreAttack), |
478 |
|
RgnInfo.EG2Attack * egInfo.Attack, |
479 |
|
false, |
480 |
|
RgnInfo.EG2Decay1 * egInfo.Decay * velrelease, |
481 |
|
RgnInfo.EG2Decay2 * egInfo.Decay * velrelease, |
482 |
|
RgnInfo.EG2InfiniteSustain, |
483 |
|
uint(RgnInfo.EG2Sustain), |
484 |
|
RgnInfo.EG2Release * egInfo.Release * velrelease, |
485 |
|
velocityAttenuation, |
486 |
|
sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
487 |
|
} |
488 |
|
|
489 |
|
void Voice::ProcessGroupEvent(RTList<Event>::Iterator& itEvent) { |
490 |
|
dmsg(4,("Voice %p processGroupEvents event type=%d", (void*)this, itEvent->Type)); |
491 |
|
|
492 |
|
// TODO: The SustainPedal condition could be wrong, maybe the |
493 |
|
// check should be if this Voice is in release stage or is a |
494 |
|
// release sample instead. Need to test this in GSt. |
495 |
|
// -- Andreas |
496 |
|
// |
497 |
|
// Commented sustain pedal check out. I don't think voices of the same |
498 |
|
// note should be stopped at all, because it doesn't sound naturally |
499 |
|
// with a drumkit. |
500 |
|
// -- Christian, 2013-01-08 |
501 |
|
if (itEvent->Param.Note.Key != HostKey() /*|| |
502 |
|
!GetGigEngineChannel()->SustainPedal*/) { |
503 |
|
dmsg(4,("Voice %p - kill", (void*)this)); |
504 |
|
|
505 |
|
// kill the voice fast |
506 |
|
pEG1->enterFadeOutStage(); |
507 |
|
} |
508 |
|
} |
509 |
|
|
510 |
|
void Voice::CalculateFadeOutCoeff(float FadeOutTime, float SampleRate) { |
511 |
|
EG1.CalculateFadeOutCoeff(FadeOutTime, SampleRate); |
512 |
|
} |
513 |
|
|
514 |
|
int Voice::CalculatePan(uint8_t pan) { |
515 |
|
int p; |
516 |
|
// Gst behaviour: -64 and 63 are special cases |
517 |
|
if (RgnInfo.Pan == -64) p = pan * 2 - 127; |
518 |
|
else if (RgnInfo.Pan == 63) p = pan * 2; |
519 |
|
else p = pan + RgnInfo.Pan; |
520 |
|
|
521 |
|
if (p < 0) return 0; |
522 |
|
if (p > 127) return 127; |
523 |
|
return p; |
524 |
|
} |
525 |
|
|
526 |
}} // namespace LinuxSampler::gig |
}} // namespace LinuxSampler::gig |