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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2061 by persson, Tue Feb 23 18:32:31 2010 UTC revision 3017 by schoenebeck, Wed Oct 19 12:28:40 2016 UTC
# Line 4  Line 4 
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 - 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  *
# Line 35  namespace LinuxSampler { namespace gig { Line 35  namespace LinuxSampler { namespace gig {
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() {
# Line 75  namespace LinuxSampler { namespace gig { Line 76  namespace LinuxSampler { namespace gig {
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;
# Line 95  namespace LinuxSampler { namespace gig { Line 87  namespace LinuxSampler { namespace gig {
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);
# Line 132  namespace LinuxSampler { namespace gig { Line 124  namespace LinuxSampler { namespace gig {
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);
# Line 189  namespace LinuxSampler { namespace gig { Line 193  namespace LinuxSampler { namespace gig {
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    
# Line 331  namespace LinuxSampler { namespace gig { Line 341  namespace LinuxSampler { namespace gig {
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:
# Line 341  namespace LinuxSampler { namespace gig { Line 351  namespace LinuxSampler { namespace gig {
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:
# Line 363  namespace LinuxSampler { namespace gig { Line 373  namespace LinuxSampler { namespace gig {
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      }      }
# Line 416  namespace LinuxSampler { namespace gig { Line 426  namespace LinuxSampler { namespace gig {
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:
# Line 451  namespace LinuxSampler { namespace gig { Line 461  namespace LinuxSampler { namespace gig {
461      }      }
462    
463      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) {
464          EG1.trigger(uint(RgnInfo.EG1PreAttack),          EG1.trigger(pRegion->EG1PreAttack,
465                      RgnInfo.EG1Attack * egInfo.Attack,                      RTMath::Max(pRegion->EG1Attack, 0.0316) * egInfo.Attack,
466                      RgnInfo.EG1Hold,                      pRegion->EG1Hold,
467                      RgnInfo.EG1Decay1 * egInfo.Decay * velrelease,                      pRegion->EG1Decay1 * egInfo.Decay * velrelease,
468                      RgnInfo.EG1Decay2 * egInfo.Decay * velrelease,                      pRegion->EG1Decay2 * egInfo.Decay * velrelease,
469                      RgnInfo.EG1InfiniteSustain,                      pRegion->EG1InfiniteSustain,
470                      uint(RgnInfo.EG1Sustain),                      pRegion->EG1Sustain,
471                      RgnInfo.EG1Release * egInfo.Release * velrelease,                      RTMath::Max(pRegion->EG1Release * velrelease, 0.014) * egInfo.Release,
472                      velocityAttenuation,                      velocityAttenuation,
473                      sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                      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

Legend:
Removed from v.2061  
changed lines
  Added in v.3017

  ViewVC Help
Powered by ViewVC