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 - 2008 Christian Schoenebeck * |
* Copyright (C) 2005 - 2008 Christian Schoenebeck * |
7 |
* Copyright (C) 2009 - 2010 Christian Schoenebeck and Grigor Iliev * |
* Copyright (C) 2009 - 2012 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 * |
35 |
Voice::Voice() { |
Voice::Voice() { |
36 |
pEngine = NULL; |
pEngine = NULL; |
37 |
pEG1 = &EG1; |
pEG1 = &EG1; |
38 |
|
pEG2 = &EG2; |
39 |
} |
} |
40 |
|
|
41 |
Voice::~Voice() { |
Voice::~Voice() { |
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 = 0.01053 * (256 >> pRegion->ReleaseTriggerDecay); |
ri.ReleaseTriggerDecay = 0.01053 * (256 >> pRegion->ReleaseTriggerDecay); |
127 |
void Voice::ProcessCutoffEvent(RTList<Event>::Iterator& itEvent) { |
void Voice::ProcessCutoffEvent(RTList<Event>::Iterator& itEvent) { |
128 |
int ccvalue = itEvent->Param.CC.Value; |
int ccvalue = itEvent->Param.CC.Value; |
129 |
if (VCFCutoffCtrl.value == ccvalue) return; |
if (VCFCutoffCtrl.value == ccvalue) return; |
130 |
VCFCutoffCtrl.value == ccvalue; |
VCFCutoffCtrl.value = ccvalue; |
131 |
if (pRegion->VCFCutoffControllerInvert) ccvalue = 127 - ccvalue; |
if (pRegion->VCFCutoffControllerInvert) ccvalue = 127 - ccvalue; |
132 |
if (ccvalue < pRegion->VCFVelocityScale) ccvalue = pRegion->VCFVelocityScale; |
if (ccvalue < pRegion->VCFVelocityScale) ccvalue = pRegion->VCFVelocityScale; |
133 |
float cutoff = CutoffBase * float(ccvalue); |
float cutoff = CutoffBase * float(ccvalue); |
333 |
break; |
break; |
334 |
case ::gig::lfo3_ctrl_internal_aftertouch: |
case ::gig::lfo3_ctrl_internal_aftertouch: |
335 |
lfo3_internal_depth = pRegion->LFO3InternalDepth; |
lfo3_internal_depth = pRegion->LFO3InternalDepth; |
336 |
pLFO1->ExtController = 128; |
pLFO3->ExtController = 128; |
337 |
bLFO3Enabled = (lfo3_internal_depth > 0 || pRegion->LFO3ControlDepth > 0); |
bLFO3Enabled = (lfo3_internal_depth > 0 || pRegion->LFO3ControlDepth > 0); |
338 |
break; |
break; |
339 |
default: |
default: |
355 |
float Voice::CalculateCutoffBase(uint8_t MIDIKeyVelocity) { |
float Voice::CalculateCutoffBase(uint8_t MIDIKeyVelocity) { |
356 |
float cutoff = pRegion->GetVelocityCutoff(MIDIKeyVelocity); |
float cutoff = pRegion->GetVelocityCutoff(MIDIKeyVelocity); |
357 |
if (pRegion->VCFKeyboardTracking) { |
if (pRegion->VCFKeyboardTracking) { |
358 |
cutoff *= exp((MIDIKeyVelocity - pRegion->VCFKeyboardTrackingBreakpoint) * 0.057762265f); // (ln(2) / 12) |
cutoff *= RTMath::CentsToFreqRatioUnlimited((MIDIKey - pRegion->VCFKeyboardTrackingBreakpoint) * 100); |
359 |
} |
} |
360 |
return cutoff; |
return cutoff; |
361 |
} |
} |
443 |
} |
} |
444 |
|
|
445 |
void Voice::TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) { |
void Voice::TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) { |
446 |
EG1.trigger(uint(RgnInfo.EG1PreAttack), |
EG1.trigger(pRegion->EG1PreAttack, |
447 |
RgnInfo.EG1Attack * egInfo.Attack, |
pRegion->EG1Attack * egInfo.Attack, |
448 |
RgnInfo.EG1Hold, |
pRegion->EG1Hold, |
449 |
RgnInfo.EG1Decay1 * egInfo.Decay * velrelease, |
pRegion->EG1Decay1 * egInfo.Decay * velrelease, |
450 |
RgnInfo.EG1Decay2 * egInfo.Decay * velrelease, |
pRegion->EG1Decay2 * egInfo.Decay * velrelease, |
451 |
RgnInfo.EG1InfiniteSustain, |
pRegion->EG1InfiniteSustain, |
452 |
uint(RgnInfo.EG1Sustain), |
pRegion->EG1Sustain, |
453 |
RgnInfo.EG1Release * egInfo.Release * velrelease, |
pRegion->EG1Release * egInfo.Release * velrelease, |
454 |
velocityAttenuation, |
velocityAttenuation, |
455 |
sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
456 |
} |
} |
457 |
|
|
458 |
|
void Voice::TriggerEG2(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) { |
459 |
|
EG2.trigger(uint(RgnInfo.EG2PreAttack), |
460 |
|
RgnInfo.EG2Attack * egInfo.Attack, |
461 |
|
false, |
462 |
|
RgnInfo.EG2Decay1 * egInfo.Decay * velrelease, |
463 |
|
RgnInfo.EG2Decay2 * egInfo.Decay * velrelease, |
464 |
|
RgnInfo.EG2InfiniteSustain, |
465 |
|
uint(RgnInfo.EG2Sustain), |
466 |
|
RgnInfo.EG2Release * egInfo.Release * velrelease, |
467 |
|
velocityAttenuation, |
468 |
|
sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
469 |
|
} |
470 |
|
|
471 |
|
void Voice::ProcessGroupEvent(RTList<Event>::Iterator& itEvent) { |
472 |
|
dmsg(4,("Voice %x processGroupEvents event type=%d", this, itEvent->Type)); |
473 |
|
|
474 |
|
// TODO: The SustainPedal condition could be wrong, maybe the |
475 |
|
// check should be if this Voice is in release stage or is a |
476 |
|
// release sample instead. Need to test this in GSt. |
477 |
|
// -- Andreas |
478 |
|
// |
479 |
|
// Commented sustain pedal check out. I don't think voices of the same |
480 |
|
// note should be stopped at all, because it doesn't sound naturally |
481 |
|
// with a drumkit. |
482 |
|
// -- Christian, 2013-01-08 |
483 |
|
if (itEvent->Param.Note.Key != MIDIKey /*|| |
484 |
|
!GetGigEngineChannel()->SustainPedal*/) { |
485 |
|
dmsg(4,("Voice %x - kill", this)); |
486 |
|
|
487 |
|
// kill the voice fast |
488 |
|
pEG1->enterFadeOutStage(); |
489 |
|
} |
490 |
|
} |
491 |
|
|
492 |
|
void Voice::CalculateFadeOutCoeff(float FadeOutTime, float SampleRate) { |
493 |
|
EG1.CalculateFadeOutCoeff(FadeOutTime, SampleRate); |
494 |
|
} |
495 |
|
|
496 |
|
int Voice::CalculatePan(uint8_t pan) { |
497 |
|
int p; |
498 |
|
// Gst behaviour: -64 and 63 are special cases |
499 |
|
if (RgnInfo.Pan == -64) p = pan * 2 - 127; |
500 |
|
else if (RgnInfo.Pan == 63) p = pan * 2; |
501 |
|
else p = pan + RgnInfo.Pan; |
502 |
|
|
503 |
|
if (p < 0) return 0; |
504 |
|
if (p > 127) return 127; |
505 |
|
return p; |
506 |
|
} |
507 |
|
|
508 |
}} // namespace LinuxSampler::gig |
}} // namespace LinuxSampler::gig |