/[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 2175 by persson, Mon Apr 25 08:12:36 2011 UTC revision 3054 by schoenebeck, Thu Dec 15 12:47:45 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 - 2011 Christian Schoenebeck and Grigor Iliev      *   *   Copyright (C) 2009 Christian Schoenebeck and Grigor Iliev             *
8     *   Copyright (C) 2010 - 2016 Christian Schoenebeck and Andreas Persson   *
9   *                                                                         *   *                                                                         *
10   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
11   *   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 58  namespace LinuxSampler { namespace gig { Line 59  namespace LinuxSampler { namespace gig {
59          si.ChannelCount     = pSample->Channels;          si.ChannelCount     = pSample->Channels;
60          si.FrameSize        = pSample->FrameSize;          si.FrameSize        = pSample->FrameSize;
61          si.BitDepth         = pSample->BitDepth;          si.BitDepth         = pSample->BitDepth;
62          si.TotalFrameCount  = pSample->SamplesTotal;          si.TotalFrameCount  = (uint)pSample->SamplesTotal;
63    
64          si.HasLoops       = pRegion->SampleLoops;          si.HasLoops       = pRegion->SampleLoops;
65          si.LoopStart      = (si.HasLoops) ? pRegion->pSampleLoops[0].LoopStart  : 0;          si.LoopStart      = (si.HasLoops) ? pRegion->pSampleLoops[0].LoopStart  : 0;
# Line 76  namespace LinuxSampler { namespace gig { Line 77  namespace LinuxSampler { namespace gig {
77          ri.Pan       = pRegion->Pan;          ri.Pan       = pRegion->Pan;
78          ri.SampleStartOffset = pRegion->SampleStartOffset;          ri.SampleStartOffset = pRegion->SampleStartOffset;
79    
         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;  
   
80          ri.EG2PreAttack        = pRegion->EG2PreAttack;          ri.EG2PreAttack        = pRegion->EG2PreAttack;
81          ri.EG2Attack           = pRegion->EG2Attack;          ri.EG2Attack           = pRegion->EG2Attack;
82          ri.EG2Decay1           = pRegion->EG2Decay1;          ri.EG2Decay1           = pRegion->EG2Decay1;
# Line 133  namespace LinuxSampler { namespace gig { Line 125  namespace LinuxSampler { namespace gig {
125          }          }
126      }      }
127    
128        void Voice::ProcessChannelPressureEvent(RTList<Event>::Iterator& itEvent) {
129            if (itEvent->Type == Event::type_channel_pressure) { // if (valid) MIDI channel pressure (aftertouch) event
130                if (pRegion->AttenuationController.type == ::gig::attenuation_ctrl_t::type_channelaftertouch) {
131                    CrossfadeSmoother.update(AbstractEngine::CrossfadeCurve[CrossfadeAttenuation(itEvent->Param.ChannelPressure.Value)]);
132                }
133            }
134        }
135    
136        void Voice::ProcessPolyphonicKeyPressureEvent(RTList<Event>::Iterator& itEvent) {
137            // Not used so far
138        }
139    
140      void Voice::ProcessCutoffEvent(RTList<Event>::Iterator& itEvent) {      void Voice::ProcessCutoffEvent(RTList<Event>::Iterator& itEvent) {
141          int ccvalue = itEvent->Param.CC.Value;          int ccvalue = itEvent->Param.CC.Value;
142          if (VCFCutoffCtrl.value == ccvalue) return;          if (VCFCutoffCtrl.value == ccvalue) return;
# Line 190  namespace LinuxSampler { namespace gig { Line 194  namespace LinuxSampler { namespace gig {
194      Voice::EGInfo Voice::CalculateEG1ControllerInfluence(double eg1ControllerValue) {      Voice::EGInfo Voice::CalculateEG1ControllerInfluence(double eg1ControllerValue) {
195          EGInfo eg;          EGInfo eg;
196          // (eg1attack is different from the others)          // (eg1attack is different from the others)
197          eg.Attack  = (pRegion->EG1ControllerAttackInfluence)  ?          if (pRegion->EG1Attack < 1e-8 && // attack in gig == 0
198              1 + 0.031 * (double) (pRegion->EG1ControllerAttackInfluence == 1 ?              (pRegion->EG1ControllerAttackInfluence == 0 ||
199                                    1 : 1 << pRegion->EG1ControllerAttackInfluence) * eg1ControllerValue : 1.0;               eg1ControllerValue <= 10)) { // strange GSt special case
200                eg.Attack = 0; // this will force the attack to be 0 in the call to EG1.trigger
201            } else {
202                eg.Attack  = (pRegion->EG1ControllerAttackInfluence)  ?
203                    1 + 0.031 * (double) (pRegion->EG1ControllerAttackInfluence == 1 ?
204                                          1 : 1 << pRegion->EG1ControllerAttackInfluence) * eg1ControllerValue : 1.0;
205            }
206          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;
207          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;
208    
# Line 332  namespace LinuxSampler { namespace gig { Line 342  namespace LinuxSampler { namespace gig {
342                  break;                  break;
343              case ::gig::lfo3_ctrl_aftertouch:              case ::gig::lfo3_ctrl_aftertouch:
344                  lfo3_internal_depth  = 0;                  lfo3_internal_depth  = 0;
345                  pLFO3->ExtController = 128;                  pLFO3->ExtController = CTRL_TABLE_IDX_AFTERTOUCH;
346                  bLFO3Enabled         = true;                  bLFO3Enabled         = true;
347                  break;                  break;
348              case ::gig::lfo3_ctrl_internal_modwheel:              case ::gig::lfo3_ctrl_internal_modwheel:
# Line 342  namespace LinuxSampler { namespace gig { Line 352  namespace LinuxSampler { namespace gig {
352                  break;                  break;
353              case ::gig::lfo3_ctrl_internal_aftertouch:              case ::gig::lfo3_ctrl_internal_aftertouch:
354                  lfo3_internal_depth  = pRegion->LFO3InternalDepth;                  lfo3_internal_depth  = pRegion->LFO3InternalDepth;
355                  pLFO3->ExtController = 128;                  pLFO3->ExtController = CTRL_TABLE_IDX_AFTERTOUCH;
356                  bLFO3Enabled         = (lfo3_internal_depth > 0 || pRegion->LFO3ControlDepth > 0);                  bLFO3Enabled         = (lfo3_internal_depth > 0 || pRegion->LFO3ControlDepth > 0);
357                  break;                  break;
358              default:              default:
# Line 364  namespace LinuxSampler { namespace gig { Line 374  namespace LinuxSampler { namespace gig {
374      float Voice::CalculateCutoffBase(uint8_t MIDIKeyVelocity) {      float Voice::CalculateCutoffBase(uint8_t MIDIKeyVelocity) {
375          float cutoff = pRegion->GetVelocityCutoff(MIDIKeyVelocity);          float cutoff = pRegion->GetVelocityCutoff(MIDIKeyVelocity);
376          if (pRegion->VCFKeyboardTracking) {          if (pRegion->VCFKeyboardTracking) {
377              cutoff *= RTMath::CentsToFreqRatioUnlimited((MIDIKey - pRegion->VCFKeyboardTrackingBreakpoint) * 100);              cutoff *= RTMath::CentsToFreqRatioUnlimited((MIDIKey() - pRegion->VCFKeyboardTrackingBreakpoint) * 100);
378          }          }
379          return cutoff;          return cutoff;
380      }      }
# Line 417  namespace LinuxSampler { namespace gig { Line 427  namespace LinuxSampler { namespace gig {
427                  ctrl = 83;                  ctrl = 83;
428                  break;                  break;
429              case ::gig::vcf_cutoff_ctrl_aftertouch:              case ::gig::vcf_cutoff_ctrl_aftertouch:
430                  ctrl = 128;                  ctrl = CTRL_TABLE_IDX_AFTERTOUCH;
431                  break;                  break;
432              case ::gig::vcf_cutoff_ctrl_none:              case ::gig::vcf_cutoff_ctrl_none:
433              default:              default:
# Line 452  namespace LinuxSampler { namespace gig { Line 462  namespace LinuxSampler { namespace gig {
462      }      }
463    
464      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) {
465          EG1.trigger(uint(RgnInfo.EG1PreAttack),          EG1.trigger(pRegion->EG1PreAttack,
466                      RgnInfo.EG1Attack * egInfo.Attack,                      RTMath::Max(pRegion->EG1Attack, 0.0316) * egInfo.Attack,
467                      RgnInfo.EG1Hold,                      pRegion->EG1Hold,
468                      RgnInfo.EG1Decay1 * egInfo.Decay * velrelease,                      pRegion->EG1Decay1 * egInfo.Decay * velrelease,
469                      RgnInfo.EG1Decay2 * egInfo.Decay * velrelease,                      pRegion->EG1Decay2 * egInfo.Decay * velrelease,
470                      RgnInfo.EG1InfiniteSustain,                      pRegion->EG1InfiniteSustain,
471                      uint(RgnInfo.EG1Sustain),                      pRegion->EG1Sustain,
472                      RgnInfo.EG1Release * egInfo.Release * velrelease,                      RTMath::Max(pRegion->EG1Release * velrelease, 0.014) * egInfo.Release,
473                      velocityAttenuation,                      velocityAttenuation,
474                      sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                      sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
475      }      }
# Line 478  namespace LinuxSampler { namespace gig { Line 488  namespace LinuxSampler { namespace gig {
488      }      }
489    
490      void Voice::ProcessGroupEvent(RTList<Event>::Iterator& itEvent) {      void Voice::ProcessGroupEvent(RTList<Event>::Iterator& itEvent) {
491          dmsg(4,("Voice %x processGroupEvents event type=%d", this, itEvent->Type));          dmsg(4,("Voice %p processGroupEvents event type=%d", (void*)this, itEvent->Type));
492    
493          // TODO: The SustainPedal condition could be wrong, maybe the          // TODO: The SustainPedal condition could be wrong, maybe the
494          // check should be if this Voice is in release stage or is a          // check should be if this Voice is in release stage or is a
495          // release sample instead. Need to test this in GSt.          // release sample instead. Need to test this in GSt.
496          if (itEvent->Param.Note.Key != MIDIKey ||          // -- Andreas
497              !GetGigEngineChannel()->SustainPedal) {          //
498              dmsg(4,("Voice %x - kill", this));          // Commented sustain pedal check out. I don't think voices of the same
499            // note should be stopped at all, because it doesn't sound naturally
500            // with a drumkit.
501            // -- Christian, 2013-01-08
502            if (itEvent->Param.Note.Key != HostKey() /*||
503                !GetGigEngineChannel()->SustainPedal*/) {
504                dmsg(4,("Voice %p - kill", (void*)this));
505    
506              // kill the voice fast              // kill the voice fast
507              pEG1->enterFadeOutStage();              pEG1->enterFadeOutStage();
508          }          }
509      }      }
510    
511        void Voice::CalculateFadeOutCoeff(float FadeOutTime, float SampleRate) {
512            EG1.CalculateFadeOutCoeff(FadeOutTime, SampleRate);
513        }
514    
515        int Voice::CalculatePan(uint8_t pan) {
516            int p;
517            // Gst behaviour: -64 and 63 are special cases
518            if (RgnInfo.Pan == -64)     p = pan * 2 - 127;
519            else if (RgnInfo.Pan == 63) p = pan * 2;
520            else                        p = pan + RgnInfo.Pan;
521    
522            if (p < 0) return 0;
523            if (p > 127) return 127;
524            return p;
525        }
526    
527  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig

Legend:
Removed from v.2175  
changed lines
  Added in v.3054

  ViewVC Help
Powered by ViewVC