--- linuxsampler/trunk/src/engines/gig/Voice.cpp 2010/08/10 12:05:19 2114 +++ linuxsampler/trunk/src/engines/gig/Voice.cpp 2013/01/08 12:00:45 2396 @@ -4,7 +4,7 @@ * * * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * * Copyright (C) 2005 - 2008 Christian Schoenebeck * - * Copyright (C) 2009 - 2010 Christian Schoenebeck and Grigor Iliev * + * Copyright (C) 2009 - 2012 Christian Schoenebeck and Grigor Iliev * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -35,6 +35,7 @@ Voice::Voice() { pEngine = NULL; pEG1 = &EG1; + pEG2 = &EG2; } Voice::~Voice() { @@ -75,15 +76,6 @@ ri.Pan = pRegion->Pan; ri.SampleStartOffset = pRegion->SampleStartOffset; - 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; - ri.EG2PreAttack = pRegion->EG2PreAttack; ri.EG2Attack = pRegion->EG2Attack; ri.EG2Decay1 = pRegion->EG2Decay1; @@ -95,7 +87,7 @@ ri.EG3Attack = pRegion->EG3Attack; ri.EG3Depth = pRegion->EG3Depth; ri.VCFEnabled = pRegion->VCFEnabled; - ri.VCFType = pRegion->VCFType; + ri.VCFType = Filter::vcf_type_t(pRegion->VCFType); ri.VCFResonance = pRegion->VCFResonance; ri.ReleaseTriggerDecay = 0.01053 * (256 >> pRegion->ReleaseTriggerDecay); @@ -135,7 +127,7 @@ void Voice::ProcessCutoffEvent(RTList::Iterator& itEvent) { int ccvalue = itEvent->Param.CC.Value; if (VCFCutoffCtrl.value == ccvalue) return; - VCFCutoffCtrl.value == ccvalue; + VCFCutoffCtrl.value = ccvalue; if (pRegion->VCFCutoffControllerInvert) ccvalue = 127 - ccvalue; if (ccvalue < pRegion->VCFVelocityScale) ccvalue = pRegion->VCFVelocityScale; float cutoff = CutoffBase * float(ccvalue); @@ -341,7 +333,7 @@ break; case ::gig::lfo3_ctrl_internal_aftertouch: lfo3_internal_depth = pRegion->LFO3InternalDepth; - pLFO1->ExtController = 128; + pLFO3->ExtController = 128; bLFO3Enabled = (lfo3_internal_depth > 0 || pRegion->LFO3ControlDepth > 0); break; default: @@ -363,7 +355,7 @@ float Voice::CalculateCutoffBase(uint8_t MIDIKeyVelocity) { float cutoff = pRegion->GetVelocityCutoff(MIDIKeyVelocity); if (pRegion->VCFKeyboardTracking) { - cutoff *= exp((MIDIKeyVelocity - pRegion->VCFKeyboardTrackingBreakpoint) * 0.057762265f); // (ln(2) / 12) + cutoff *= RTMath::CentsToFreqRatioUnlimited((MIDIKey - pRegion->VCFKeyboardTrackingBreakpoint) * 100); } return cutoff; } @@ -451,14 +443,27 @@ } void Voice::TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) { - EG1.trigger(uint(RgnInfo.EG1PreAttack), - RgnInfo.EG1Attack * egInfo.Attack, - RgnInfo.EG1Hold, - RgnInfo.EG1Decay1 * egInfo.Decay * velrelease, - RgnInfo.EG1Decay2 * egInfo.Decay * velrelease, - RgnInfo.EG1InfiniteSustain, - uint(RgnInfo.EG1Sustain), - RgnInfo.EG1Release * egInfo.Release * velrelease, + EG1.trigger(pRegion->EG1PreAttack, + pRegion->EG1Attack * egInfo.Attack, + pRegion->EG1Hold, + pRegion->EG1Decay1 * egInfo.Decay * velrelease, + pRegion->EG1Decay2 * egInfo.Decay * velrelease, + pRegion->EG1InfiniteSustain, + pRegion->EG1Sustain, + pRegion->EG1Release * egInfo.Release * velrelease, + velocityAttenuation, + sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); + } + + void Voice::TriggerEG2(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) { + EG2.trigger(uint(RgnInfo.EG2PreAttack), + RgnInfo.EG2Attack * egInfo.Attack, + false, + RgnInfo.EG2Decay1 * egInfo.Decay * velrelease, + RgnInfo.EG2Decay2 * egInfo.Decay * velrelease, + RgnInfo.EG2InfiniteSustain, + uint(RgnInfo.EG2Sustain), + RgnInfo.EG2Release * egInfo.Release * velrelease, velocityAttenuation, sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); } @@ -469,8 +474,14 @@ // TODO: The SustainPedal condition could be wrong, maybe the // check should be if this Voice is in release stage or is a // release sample instead. Need to test this in GSt. - if (itEvent->Param.Note.Key != MIDIKey || - !GetGigEngineChannel()->SustainPedal) { + // -- Andreas + // + // Commented sustain pedal check out. I don't think voices of the same + // note should be stopped at all, because it doesn't sound naturally + // with a drumkit. + // -- Christian, 2013-01-08 + if (itEvent->Param.Note.Key != MIDIKey /*|| + !GetGigEngineChannel()->SustainPedal*/) { dmsg(4,("Voice %x - kill", this)); // kill the voice fast @@ -478,4 +489,20 @@ } } + void Voice::CalculateFadeOutCoeff(float FadeOutTime, float SampleRate) { + EG1.CalculateFadeOutCoeff(FadeOutTime, SampleRate); + } + + int Voice::CalculatePan(uint8_t pan) { + int p; + // Gst behaviour: -64 and 63 are special cases + if (RgnInfo.Pan == -64) p = pan * 2 - 127; + else if (RgnInfo.Pan == 63) p = pan * 2; + else p = pan + RgnInfo.Pan; + + if (p < 0) return 0; + if (p > 127) return 127; + return p; + } + }} // namespace LinuxSampler::gig