/[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 2203 by persson, Sat Jul 9 16:44:27 2011 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 - 2011 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 124  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;
# Line 181  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 323  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 333  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                  pLFO3->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 355  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 *= RTMath::CentsToFreqRatioUnlimited((MIDIKey - pRegion->VCFKeyboardTrackingBreakpoint) * 100);              cutoff *= RTMath::CentsToFreqRatioUnlimited((MIDIKey() - pRegion->VCFKeyboardTrackingBreakpoint) * 100);
377          }          }
378          return cutoff;          return cutoff;
379      }      }
# Line 408  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 444  namespace LinuxSampler { namespace gig { Line 462  namespace LinuxSampler { namespace gig {
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(pRegion->EG1PreAttack,          EG1.trigger(pRegion->EG1PreAttack,
465                      pRegion->EG1Attack * egInfo.Attack,                      RTMath::Max(pRegion->EG1Attack, 0.0316) * egInfo.Attack,
466                      pRegion->EG1Hold,                      pRegion->EG1Hold,
467                      pRegion->EG1Decay1 * egInfo.Decay * velrelease,                      pRegion->EG1Decay1 * egInfo.Decay * velrelease,
468                      pRegion->EG1Decay2 * egInfo.Decay * velrelease,                      pRegion->EG1Decay2 * egInfo.Decay * velrelease,
469                      pRegion->EG1InfiniteSustain,                      pRegion->EG1InfiniteSustain,
470                      pRegion->EG1Sustain,                      pRegion->EG1Sustain,
471                      pRegion->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      }      }
# Line 469  namespace LinuxSampler { namespace gig { Line 487  namespace LinuxSampler { namespace gig {
487      }      }
488    
489      void Voice::ProcessGroupEvent(RTList<Event>::Iterator& itEvent) {      void Voice::ProcessGroupEvent(RTList<Event>::Iterator& itEvent) {
490          dmsg(4,("Voice %x processGroupEvents event type=%d", this, itEvent->Type));          dmsg(4,("Voice %p processGroupEvents event type=%d", (void*)this, itEvent->Type));
491    
492          // TODO: The SustainPedal condition could be wrong, maybe the          // TODO: The SustainPedal condition could be wrong, maybe the
493          // 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
494          // release sample instead. Need to test this in GSt.          // release sample instead. Need to test this in GSt.
495          if (itEvent->Param.Note.Key != MIDIKey ||          // -- Andreas
496              !GetGigEngineChannel()->SustainPedal) {          //
497              dmsg(4,("Voice %x - kill", this));          // 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              // kill the voice fast
506              pEG1->enterFadeOutStage();              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.2203  
changed lines
  Added in v.3017

  ViewVC Help
Powered by ViewVC