/[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 2015 by iliev, Sun Oct 25 22:22:52 2009 UTC revision 2408 by persson, Sat Feb 2 08:22:49 2013 UTC
# Line 3  Line 3 
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 - 2013 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 33  Line 33 
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() {
# 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 = pRegion->ReleaseTriggerDecay;          ri.ReleaseTriggerDecay = 0.01053 * (256 >> pRegion->ReleaseTriggerDecay);
94    
95          return ri;          return ri;
96      }      }
# Line 135  namespace LinuxSampler { namespace gig { Line 127  namespace LinuxSampler { namespace gig {
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);
# Line 189  namespace LinuxSampler { namespace gig { Line 181  namespace LinuxSampler { namespace gig {
181      Voice::EGInfo Voice::CalculateEG1ControllerInfluence(double eg1ControllerValue) {      Voice::EGInfo Voice::CalculateEG1ControllerInfluence(double eg1ControllerValue) {
182          EGInfo eg;          EGInfo eg;
183          // (eg1attack is different from the others)          // (eg1attack is different from the others)
184          eg.Attack  = (pRegion->EG1ControllerAttackInfluence)  ?          if (pRegion->EG1Attack < 1e-8 && // attack in gig == 0
185              1 + 0.031 * (double) (pRegion->EG1ControllerAttackInfluence == 1 ?              (pRegion->EG1ControllerAttackInfluence == 0 ||
186                                    1 : 1 << pRegion->EG1ControllerAttackInfluence) * eg1ControllerValue : 1.0;               eg1ControllerValue <= 10)) { // strange GSt special case
187                eg.Attack = 0; // this will force the attack to be 0 in the call to EG1.trigger
188            } else {
189                eg.Attack  = (pRegion->EG1ControllerAttackInfluence)  ?
190                    1 + 0.031 * (double) (pRegion->EG1ControllerAttackInfluence == 1 ?
191                                          1 : 1 << pRegion->EG1ControllerAttackInfluence) * eg1ControllerValue : 1.0;
192            }
193          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;
194          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;
195    
# Line 341  namespace LinuxSampler { namespace gig { Line 339  namespace LinuxSampler { namespace gig {
339                  break;                  break;
340              case ::gig::lfo3_ctrl_internal_aftertouch:              case ::gig::lfo3_ctrl_internal_aftertouch:
341                  lfo3_internal_depth  = pRegion->LFO3InternalDepth;                  lfo3_internal_depth  = pRegion->LFO3InternalDepth;
342                  pLFO1->ExtController = 128;                  pLFO3->ExtController = 128;
343                  bLFO3Enabled         = (lfo3_internal_depth > 0 || pRegion->LFO3ControlDepth > 0);                  bLFO3Enabled         = (lfo3_internal_depth > 0 || pRegion->LFO3ControlDepth > 0);
344                  break;                  break;
345              default:              default:
# Line 359  namespace LinuxSampler { namespace gig { Line 357  namespace LinuxSampler { namespace gig {
357              pLFO3->update(pLFO3->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO3->ExtController] : 0);              pLFO3->update(pLFO3->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO3->ExtController] : 0);
358          }          }
359      }      }
360        
361      float Voice::CalculateCutoffBase(uint8_t MIDIKeyVelocity) {      float Voice::CalculateCutoffBase(uint8_t MIDIKeyVelocity) {
362          float cutoff = pRegion->GetVelocityCutoff(MIDIKeyVelocity);          float cutoff = pRegion->GetVelocityCutoff(MIDIKeyVelocity);
363          if (pRegion->VCFKeyboardTracking) {          if (pRegion->VCFKeyboardTracking) {
364              cutoff *= exp((MIDIKeyVelocity - pRegion->VCFKeyboardTrackingBreakpoint) * 0.057762265f); // (ln(2) / 12)              cutoff *= RTMath::CentsToFreqRatioUnlimited((MIDIKey - pRegion->VCFKeyboardTrackingBreakpoint) * 100);
365          }          }
366          return cutoff;          return cutoff;
367      }      }
# Line 450  namespace LinuxSampler { namespace gig { Line 448  namespace LinuxSampler { namespace gig {
448          return ctrl;          return ctrl;
449      }      }
450    
451        void Voice::TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) {
452            EG1.trigger(pRegion->EG1PreAttack,
453                        RTMath::Max(pRegion->EG1Attack, 0.0316) * egInfo.Attack,
454                        pRegion->EG1Hold,
455                        pRegion->EG1Decay1 * egInfo.Decay * velrelease,
456                        pRegion->EG1Decay2 * egInfo.Decay * velrelease,
457                        pRegion->EG1InfiniteSustain,
458                        pRegion->EG1Sustain,
459                        RTMath::Max(pRegion->EG1Release * velrelease, 0.014) * egInfo.Release,
460                        velocityAttenuation,
461                        sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
462        }
463    
464        void Voice::TriggerEG2(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) {
465            EG2.trigger(uint(RgnInfo.EG2PreAttack),
466                        RgnInfo.EG2Attack * egInfo.Attack,
467                        false,
468                        RgnInfo.EG2Decay1 * egInfo.Decay * velrelease,
469                        RgnInfo.EG2Decay2 * egInfo.Decay * velrelease,
470                        RgnInfo.EG2InfiniteSustain,
471                        uint(RgnInfo.EG2Sustain),
472                        RgnInfo.EG2Release * egInfo.Release * velrelease,
473                        velocityAttenuation,
474                        sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
475        }
476    
477        void Voice::ProcessGroupEvent(RTList<Event>::Iterator& itEvent) {
478            dmsg(4,("Voice %x processGroupEvents event type=%d", this, itEvent->Type));
479    
480            // TODO: The SustainPedal condition could be wrong, maybe the
481            // check should be if this Voice is in release stage or is a
482            // release sample instead. Need to test this in GSt.
483            // -- Andreas
484            //
485            // Commented sustain pedal check out. I don't think voices of the same
486            // note should be stopped at all, because it doesn't sound naturally
487            // with a drumkit.
488            // -- Christian, 2013-01-08
489            if (itEvent->Param.Note.Key != MIDIKey /*||
490                !GetGigEngineChannel()->SustainPedal*/) {
491                dmsg(4,("Voice %x - kill", this));
492    
493                // kill the voice fast
494                pEG1->enterFadeOutStage();
495            }
496        }
497    
498        void Voice::CalculateFadeOutCoeff(float FadeOutTime, float SampleRate) {
499            EG1.CalculateFadeOutCoeff(FadeOutTime, SampleRate);
500        }
501    
502        int Voice::CalculatePan(uint8_t pan) {
503            int p;
504            // Gst behaviour: -64 and 63 are special cases
505            if (RgnInfo.Pan == -64)     p = pan * 2 - 127;
506            else if (RgnInfo.Pan == 63) p = pan * 2;
507            else                        p = pan + RgnInfo.Pan;
508    
509            if (p < 0) return 0;
510            if (p > 127) return 127;
511            return p;
512        }
513    
514  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig

Legend:
Removed from v.2015  
changed lines
  Added in v.2408

  ViewVC Help
Powered by ViewVC