--- linuxsampler/trunk/src/engines/gig/Voice.cpp 2012/03/10 16:16:14 2327 +++ linuxsampler/trunk/src/engines/gig/Voice.cpp 2017/04/21 13:33:03 3118 @@ -4,7 +4,8 @@ * * * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * * Copyright (C) 2005 - 2008 Christian Schoenebeck * - * Copyright (C) 2009 - 2012 Christian Schoenebeck and Grigor Iliev * + * Copyright (C) 2009 Christian Schoenebeck and Grigor Iliev * + * Copyright (C) 2010 - 2016 Christian Schoenebeck and Andreas Persson * * * * 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 * @@ -58,7 +59,7 @@ si.ChannelCount = pSample->Channels; si.FrameSize = pSample->FrameSize; si.BitDepth = pSample->BitDepth; - si.TotalFrameCount = pSample->SamplesTotal; + si.TotalFrameCount = (uint)pSample->SamplesTotal; si.HasLoops = pRegion->SampleLoops; si.LoopStart = (si.HasLoops) ? pRegion->pSampleLoops[0].LoopStart : 0; @@ -124,6 +125,18 @@ } } + void Voice::ProcessChannelPressureEvent(RTList::Iterator& itEvent) { + if (itEvent->Type == Event::type_channel_pressure) { // if (valid) MIDI channel pressure (aftertouch) event + if (pRegion->AttenuationController.type == ::gig::attenuation_ctrl_t::type_channelaftertouch) { + CrossfadeSmoother.update(AbstractEngine::CrossfadeCurve[CrossfadeAttenuation(itEvent->Param.ChannelPressure.Value)]); + } + } + } + + void Voice::ProcessPolyphonicKeyPressureEvent(RTList::Iterator& itEvent) { + // Not used so far + } + void Voice::ProcessCutoffEvent(RTList::Iterator& itEvent) { int ccvalue = itEvent->Param.CC.Value; if (VCFCutoffCtrl.value == ccvalue) return; @@ -181,9 +194,15 @@ Voice::EGInfo Voice::CalculateEG1ControllerInfluence(double eg1ControllerValue) { EGInfo eg; // (eg1attack is different from the others) - eg.Attack = (pRegion->EG1ControllerAttackInfluence) ? - 1 + 0.031 * (double) (pRegion->EG1ControllerAttackInfluence == 1 ? - 1 : 1 << pRegion->EG1ControllerAttackInfluence) * eg1ControllerValue : 1.0; + if (pRegion->EG1Attack < 1e-8 && // attack in gig == 0 + (pRegion->EG1ControllerAttackInfluence == 0 || + eg1ControllerValue <= 10)) { // strange GSt special case + eg.Attack = 0; // this will force the attack to be 0 in the call to EG1.trigger + } else { + eg.Attack = (pRegion->EG1ControllerAttackInfluence) ? + 1 + 0.031 * (double) (pRegion->EG1ControllerAttackInfluence == 1 ? + 1 : 1 << pRegion->EG1ControllerAttackInfluence) * eg1ControllerValue : 1.0; + } eg.Decay = (pRegion->EG1ControllerDecayInfluence) ? 1 + 0.00775 * (double) (1 << pRegion->EG1ControllerDecayInfluence) * eg1ControllerValue : 1.0; eg.Release = (pRegion->EG1ControllerReleaseInfluence) ? 1 + 0.00775 * (double) (1 << pRegion->EG1ControllerReleaseInfluence) * eg1ControllerValue : 1.0; @@ -260,7 +279,9 @@ pRegion->LFO1ControlDepth, pRegion->LFO1FlipPhase, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); - pLFO1->update(pLFO1->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO1->ExtController] : 0); + pLFO1->updateByMIDICtrlValue(pLFO1->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO1->ExtController] : 0); + pLFO1->setScriptDepthFactor(pNote->Override.AmpLFODepth); + pLFO1->setScriptFrequencyFactor(pNote->Override.AmpLFOFreq, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); } } @@ -304,7 +325,7 @@ pRegion->LFO2ControlDepth, pRegion->LFO2FlipPhase, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); - pLFO2->update(pLFO2->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO2->ExtController] : 0); + pLFO2->updateByMIDICtrlValue(pLFO2->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO2->ExtController] : 0); } } @@ -323,7 +344,7 @@ break; case ::gig::lfo3_ctrl_aftertouch: lfo3_internal_depth = 0; - pLFO3->ExtController = 128; + pLFO3->ExtController = CTRL_TABLE_IDX_AFTERTOUCH; bLFO3Enabled = true; break; case ::gig::lfo3_ctrl_internal_modwheel: @@ -333,7 +354,7 @@ break; case ::gig::lfo3_ctrl_internal_aftertouch: lfo3_internal_depth = pRegion->LFO3InternalDepth; - pLFO3->ExtController = 128; + pLFO3->ExtController = CTRL_TABLE_IDX_AFTERTOUCH; bLFO3Enabled = (lfo3_internal_depth > 0 || pRegion->LFO3ControlDepth > 0); break; default: @@ -348,14 +369,16 @@ pRegion->LFO3ControlDepth, false, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); - pLFO3->update(pLFO3->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO3->ExtController] : 0); + pLFO3->updateByMIDICtrlValue(pLFO3->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO3->ExtController] : 0); + pLFO3->setScriptDepthFactor(pNote->Override.PitchLFODepth); + pLFO3->setScriptFrequencyFactor(pNote->Override.PitchLFOFreq, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); } } float Voice::CalculateCutoffBase(uint8_t MIDIKeyVelocity) { float cutoff = pRegion->GetVelocityCutoff(MIDIKeyVelocity); if (pRegion->VCFKeyboardTracking) { - cutoff *= RTMath::CentsToFreqRatioUnlimited((MIDIKey - pRegion->VCFKeyboardTrackingBreakpoint) * 100); + cutoff *= RTMath::CentsToFreqRatioUnlimited((MIDIKey() - pRegion->VCFKeyboardTrackingBreakpoint) * 100); } return cutoff; } @@ -408,7 +431,7 @@ ctrl = 83; break; case ::gig::vcf_cutoff_ctrl_aftertouch: - ctrl = 128; + ctrl = CTRL_TABLE_IDX_AFTERTOUCH; break; case ::gig::vcf_cutoff_ctrl_none: default: @@ -444,13 +467,13 @@ void Voice::TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) { EG1.trigger(pRegion->EG1PreAttack, - pRegion->EG1Attack * egInfo.Attack, + RTMath::Max(pRegion->EG1Attack, 0.0316) * egInfo.Attack, pRegion->EG1Hold, pRegion->EG1Decay1 * egInfo.Decay * velrelease, pRegion->EG1Decay2 * egInfo.Decay * velrelease, pRegion->EG1InfiniteSustain, pRegion->EG1Sustain, - pRegion->EG1Release * egInfo.Release * velrelease, + RTMath::Max(pRegion->EG1Release * velrelease, 0.014) * egInfo.Release, velocityAttenuation, sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); } @@ -469,14 +492,20 @@ } void Voice::ProcessGroupEvent(RTList::Iterator& itEvent) { - dmsg(4,("Voice %x processGroupEvents event type=%d", this, itEvent->Type)); + dmsg(4,("Voice %p processGroupEvents event type=%d", (void*)this, itEvent->Type)); // 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) { - dmsg(4,("Voice %x - kill", this)); + // -- 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 != HostKey() /*|| + !GetGigEngineChannel()->SustainPedal*/) { + dmsg(4,("Voice %p - kill", (void*)this)); // kill the voice fast pEG1->enterFadeOutStage(); @@ -487,4 +516,16 @@ 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