/[svn]/linuxsampler/trunk/src/engines/common/AbstractVoice.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/common/AbstractVoice.cpp

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

revision 2935 by schoenebeck, Sun Jul 10 14:24:13 2016 UTC revision 3214 by schoenebeck, Thu May 25 14:46:47 2017 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-2015 Christian Schoenebeck and Grigor Iliev        *   *   Copyright (C) 2009-2012 Christian Schoenebeck and Grigor Iliev        *
8     *   Copyright (C) 2013-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 128  namespace LinuxSampler { Line 129  namespace LinuxSampler {
129          AboutToTrigger();          AboutToTrigger();
130    
131          // calculate volume          // calculate volume
132          const double velocityAttenuation = GetVelocityAttenuation(itNoteOnEvent->Param.Note.Velocity);          const double velocityAttenuation = GetVelocityAttenuation(MIDIVelocity());
133          float volume = CalculateVolume(velocityAttenuation) * pKeyInfo->Volume;          float volume = CalculateVolume(velocityAttenuation) * pKeyInfo->Volume;
134          if (volume <= 0) return -1;          if (volume <= 0) return -1;
135    
# Line 138  namespace LinuxSampler { Line 139  namespace LinuxSampler {
139          SYNTHESIS_MODE_SET_BITDEPTH24(SynthesisMode, SmplInfo.BitDepth == 24);          SYNTHESIS_MODE_SET_BITDEPTH24(SynthesisMode, SmplInfo.BitDepth == 24);
140    
141          // get starting crossfade volume level          // get starting crossfade volume level
142          float crossfadeVolume = CalculateCrossfadeVolume(itNoteOnEvent->Param.Note.Velocity);          float crossfadeVolume = CalculateCrossfadeVolume(MIDIVelocity());
143    
144          VolumeLeft  = volume * pKeyInfo->PanLeft;          VolumeLeft  = volume * pKeyInfo->PanLeft;
145          VolumeRight = volume * pKeyInfo->PanRight;          VolumeRight = volume * pKeyInfo->PanRight;
146    
147          float subfragmentRate = GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE;          // this rate is used for rather mellow volume fades
148            const float subfragmentRate = GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE;
149            // this rate is used for very fast volume fades
150            const float quickRampRate = RTMath::Min(subfragmentRate, GetEngine()->SampleRate * 0.001f /* approx. 13ms */);
151          CrossfadeSmoother.trigger(crossfadeVolume, subfragmentRate);          CrossfadeSmoother.trigger(crossfadeVolume, subfragmentRate);
152    
153          VolumeSmoother.trigger(pEngineChannel->MidiVolume, subfragmentRate);          VolumeSmoother.trigger(pEngineChannel->MidiVolume, subfragmentRate);
154          NoteVolumeSmoother.trigger(pNote ? pNote->Override.Volume : 1.f, subfragmentRate);          NoteVolume.setCurrentValue(pNote ? pNote->Override.Volume : 1.f);
155            NoteVolume.setDefaultDuration(pNote ? pNote->Override.VolumeTime : DEFAULT_NOTE_VOLUME_TIME_S);
156    
157          // Check if the sample needs disk streaming or is too short for that          // Check if the sample needs disk streaming or is too short for that
158          long cachedsamples = GetSampleCacheSize() / SmplInfo.FrameSize;          long cachedsamples = GetSampleCacheSize() / SmplInfo.FrameSize;
# Line 186  namespace LinuxSampler { Line 192  namespace LinuxSampler {
192          }          }
193    
194          Pitch = CalculatePitchInfo(PitchBend);          Pitch = CalculatePitchInfo(PitchBend);
195          NotePitch = (pNote) ? pNote->Override.Pitch : 1.0f;          NotePitch.setCurrentValue(pNote ? pNote->Override.Pitch : 1.0f);
196            NotePitch.setDefaultDuration(pNote ? pNote->Override.PitchTime : DEFAULT_NOTE_PITCH_TIME_S);
197          NoteCutoff = (pNote) ? pNote->Override.Cutoff : 1.0f;          NoteCutoff = (pNote) ? pNote->Override.Cutoff : 1.0f;
198          NoteResonance = (pNote) ? pNote->Override.Resonance : 1.0f;          NoteResonance = (pNote) ? pNote->Override.Resonance : 1.0f;
199    
200          // the length of the decay and release curves are dependent on the velocity          // the length of the decay and release curves are dependent on the velocity
201          const double velrelease = 1 / GetVelocityRelease(itNoteOnEvent->Param.Note.Velocity);          const double velrelease = 1 / GetVelocityRelease(MIDIVelocity());
202    
203          if (pSignalUnitRack == NULL) { // setup EG 1 (VCA EG)          if (pSignalUnitRack == NULL) { // setup EG 1 (VCA EG)
204              // get current value of EG1 controller              // get current value of EG1 controller
205              double eg1controllervalue = GetEG1ControllerValue(itNoteOnEvent->Param.Note.Velocity);              double eg1controllervalue = GetEG1ControllerValue(MIDIVelocity());
206    
207              // calculate influence of EG1 controller on EG1's parameters              // calculate influence of EG1 controller on EG1's parameters
208              EGInfo egInfo = CalculateEG1ControllerInfluence(eg1controllervalue);              EGInfo egInfo = CalculateEG1ControllerInfluence(eg1controllervalue);
209    
210              TriggerEG1(egInfo, velrelease, velocityAttenuation, GetEngine()->SampleRate, itNoteOnEvent->Param.Note.Velocity);              if (pNote) {
211                    egInfo.Attack  *= pNote->Override.Attack;
212                    egInfo.Decay   *= pNote->Override.Decay;
213                    egInfo.Release *= pNote->Override.Release;
214                }
215    
216                TriggerEG1(egInfo, velrelease, velocityAttenuation, GetEngine()->SampleRate, MIDIVelocity());
217          } else {          } else {
218              pSignalUnitRack->Trigger();              pSignalUnitRack->Trigger();
219          }          }
# Line 210  namespace LinuxSampler { Line 223  namespace LinuxSampler {
223          NotePanRight = (pNote) ? AbstractEngine::PanCurveValueNorm(pNote->Override.Pan, 1 /*right*/) : 1.f;          NotePanRight = (pNote) ? AbstractEngine::PanCurveValueNorm(pNote->Override.Pan, 1 /*right*/) : 1.f;
224          PanLeftSmoother.trigger(          PanLeftSmoother.trigger(
225              AbstractEngine::PanCurve[128 - pan] * NotePanLeft,              AbstractEngine::PanCurve[128 - pan] * NotePanLeft,
226              subfragmentRate              quickRampRate //NOTE: maybe we should have 2 separate pan smoothers, one for MIDI CC10 (with slow rate) and one for instrument script change_pan() calls (with fast rate)
227          );          );
228          PanRightSmoother.trigger(          PanRightSmoother.trigger(
229              AbstractEngine::PanCurve[pan] * NotePanRight,              AbstractEngine::PanCurve[pan] * NotePanRight,
230              subfragmentRate              quickRampRate //NOTE: maybe we should have 2 separate pan smoothers, one for MIDI CC10 (with slow rate) and one for instrument script change_pan() calls (with fast rate)
231          );          );
232    
233  #ifdef CONFIG_INTERPOLATE_VOLUME  #ifdef CONFIG_INTERPOLATE_VOLUME
# Line 244  namespace LinuxSampler { Line 257  namespace LinuxSampler {
257              // setup EG 2 (VCF Cutoff EG)              // setup EG 2 (VCF Cutoff EG)
258              {              {
259                  // get current value of EG2 controller                  // get current value of EG2 controller
260                  double eg2controllervalue = GetEG2ControllerValue(itNoteOnEvent->Param.Note.Velocity);                  double eg2controllervalue = GetEG2ControllerValue(MIDIVelocity());
261    
262                  // calculate influence of EG2 controller on EG2's parameters                  // calculate influence of EG2 controller on EG2's parameters
263                  EGInfo egInfo = CalculateEG2ControllerInfluence(eg2controllervalue);                  EGInfo egInfo = CalculateEG2ControllerInfluence(eg2controllervalue);
264    
265                  TriggerEG2(egInfo, velrelease, velocityAttenuation, GetEngine()->SampleRate, itNoteOnEvent->Param.Note.Velocity);                  TriggerEG2(egInfo, velrelease, velocityAttenuation, GetEngine()->SampleRate, MIDIVelocity());
266              }              }
267    
268    
# Line 308  namespace LinuxSampler { Line 321  namespace LinuxSampler {
321              VCFResonanceCtrl.value = pEngineChannel->ControllerTable[VCFResonanceCtrl.controller];              VCFResonanceCtrl.value = pEngineChannel->ControllerTable[VCFResonanceCtrl.controller];
322    
323              // calculate cutoff frequency              // calculate cutoff frequency
324              CutoffBase = CalculateCutoffBase(itNoteOnEvent->Param.Note.Velocity);              CutoffBase = CalculateCutoffBase(MIDIVelocity());
325    
326              VCFCutoffCtrl.fvalue = CalculateFinalCutoff(CutoffBase);              VCFCutoffCtrl.fvalue = CalculateFinalCutoff(CutoffBase);
327    
# Line 409  namespace LinuxSampler { Line 422  namespace LinuxSampler {
422              }              }
423          }          }
424    
425          uint killPos;          uint killPos = 0;
426          if (itKillEvent) {          if (itKillEvent) {
427              int maxFadeOutPos = Samples - GetEngine()->GetMinFadeOutSamples();              int maxFadeOutPos = Samples - GetEngine()->GetMinFadeOutSamples();
428              if (maxFadeOutPos < 0) {              if (maxFadeOutPos < 0) {
# Line 445  namespace LinuxSampler { Line 458  namespace LinuxSampler {
458              PanLeftSmoother.update(AbstractEngine::PanCurve[128 - pan] * NotePanLeft);              PanLeftSmoother.update(AbstractEngine::PanCurve[128 - pan] * NotePanLeft);
459              PanRightSmoother.update(AbstractEngine::PanCurve[pan]      * NotePanRight);              PanRightSmoother.update(AbstractEngine::PanCurve[pan]      * NotePanRight);
460    
461              finalSynthesisParameters.fFinalPitch = Pitch.PitchBase * Pitch.PitchBend * NotePitch;              finalSynthesisParameters.fFinalPitch = Pitch.PitchBase * Pitch.PitchBend * NotePitch.render();
462    
463              float fFinalVolume = VolumeSmoother.render() * CrossfadeSmoother.render() * NoteVolumeSmoother.render();              float fFinalVolume = VolumeSmoother.render() * CrossfadeSmoother.render() * NoteVolume.render();
464  #ifdef CONFIG_PROCESS_MUTED_CHANNELS  #ifdef CONFIG_PROCESS_MUTED_CHANNELS
465              if (pChannel->GetMute()) fFinalVolume = 0;              if (pChannel->GetMute()) fFinalVolume = 0;
466  #endif  #endif
# Line 633  namespace LinuxSampler { Line 646  namespace LinuxSampler {
646       */       */
647      void AbstractVoice::processCCEvents(RTList<Event>::Iterator& itEvent, uint End) {      void AbstractVoice::processCCEvents(RTList<Event>::Iterator& itEvent, uint End) {
648          for (; itEvent && itEvent->FragmentPos() <= End; ++itEvent) {          for (; itEvent && itEvent->FragmentPos() <= End; ++itEvent) {
649              if (itEvent->Type == Event::type_control_change && itEvent->Param.CC.Controller) { // if (valid) MIDI control change event              if ((itEvent->Type == Event::type_control_change || itEvent->Type == Event::type_channel_pressure)
650                    && itEvent->Param.CC.Controller) // if (valid) MIDI control change event
651                {
652                  if (itEvent->Param.CC.Controller == VCFCutoffCtrl.controller) {                  if (itEvent->Param.CC.Controller == VCFCutoffCtrl.controller) {
653                      ProcessCutoffEvent(itEvent);                      ProcessCutoffEvent(itEvent);
654                  }                  }
655                  if (itEvent->Param.CC.Controller == VCFResonanceCtrl.controller) {                  if (itEvent->Param.CC.Controller == VCFResonanceCtrl.controller) {
656                      processResonanceEvent(itEvent);                      processResonanceEvent(itEvent);
657                  }                  }
658                    if (itEvent->Param.CC.Controller == CTRL_TABLE_IDX_AFTERTOUCH ||
659                        itEvent->Type == Event::type_channel_pressure)
660                    {
661                        ProcessChannelPressureEvent(itEvent);
662                    }
663                  if (pSignalUnitRack == NULL) {                  if (pSignalUnitRack == NULL) {
664                      if (itEvent->Param.CC.Controller == pLFO1->ExtController) {                      if (itEvent->Param.CC.Controller == pLFO1->ExtController) {
665                          pLFO1->update(itEvent->Param.CC.Value);                          pLFO1->updateByMIDICtrlValue(itEvent->Param.CC.Value);
666                      }                      }
667                      if (itEvent->Param.CC.Controller == pLFO2->ExtController) {                      if (itEvent->Param.CC.Controller == pLFO2->ExtController) {
668                          pLFO2->update(itEvent->Param.CC.Value);                          pLFO2->updateByMIDICtrlValue(itEvent->Param.CC.Value);
669                      }                      }
670                      if (itEvent->Param.CC.Controller == pLFO3->ExtController) {                      if (itEvent->Param.CC.Controller == pLFO3->ExtController) {
671                          pLFO3->update(itEvent->Param.CC.Value);                          pLFO3->updateByMIDICtrlValue(itEvent->Param.CC.Value);
672                      }                      }
673                  }                  }
674                  if (itEvent->Param.CC.Controller == 7) { // volume                  if (itEvent->Param.CC.Controller == 7) { // volume
# Line 658  namespace LinuxSampler { Line 678  namespace LinuxSampler {
678                  }                  }
679              } else if (itEvent->Type == Event::type_pitchbend) { // if pitch bend event              } else if (itEvent->Type == Event::type_pitchbend) { // if pitch bend event
680                  processPitchEvent(itEvent);                  processPitchEvent(itEvent);
             } else if (itEvent->Type == Event::type_channel_pressure) {  
                 ProcessChannelPressureEvent(itEvent);  
681              } else if (itEvent->Type == Event::type_note_pressure) {              } else if (itEvent->Type == Event::type_note_pressure) {
682                  ProcessPolyphonicKeyPressureEvent(itEvent);                  ProcessPolyphonicKeyPressureEvent(itEvent);
683              }              }
# Line 696  namespace LinuxSampler { Line 714  namespace LinuxSampler {
714          for (; itEvent && itEvent->FragmentPos() <= End; ++itEvent) {          for (; itEvent && itEvent->FragmentPos() <= End; ++itEvent) {
715              // some voice types ignore note off              // some voice types ignore note off
716              if (!(Type & (Voice::type_one_shot | Voice::type_release_trigger | Voice::type_controller_triggered))) {              if (!(Type & (Voice::type_one_shot | Voice::type_release_trigger | Voice::type_controller_triggered))) {
717                  if (itEvent->Type == Event::type_release) {                  if (itEvent->Type == Event::type_release_key) {
718                      EnterReleaseStage();                      EnterReleaseStage();
719                  } else if (itEvent->Type == Event::type_cancel_release) {                  } else if (itEvent->Type == Event::type_cancel_release_key) {
720                      if (pSignalUnitRack == NULL) {                      if (pSignalUnitRack == NULL) {
721                          pEG1->update(EG::event_cancel_release, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                          pEG1->update(EG::event_cancel_release, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
722                          pEG2->update(EG::event_cancel_release, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                          pEG2->update(EG::event_cancel_release, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
# Line 707  namespace LinuxSampler { Line 725  namespace LinuxSampler {
725                      }                      }
726                  }                  }
727              }              }
728                // process stop-note events (caused by built-in instrument script function note_off())
729                if (itEvent->Type == Event::type_release_note && pNote &&
730                    pEngineChannel->pEngine->NoteByID( itEvent->Param.Note.ID ) == pNote)
731                {
732                    EnterReleaseStage();
733                }
734                // process kill-note events (caused by built-in instrument script function fade_out())
735                if (itEvent->Type == Event::type_kill_note && pNote &&
736                    pEngineChannel->pEngine->NoteByID( itEvent->Param.Note.ID ) == pNote)
737                {
738                    Kill(itEvent);
739                }
740              // process synthesis parameter events (caused by built-in realt-time instrument script functions)              // process synthesis parameter events (caused by built-in realt-time instrument script functions)
741              if (itEvent->Type == Event::type_note_synth_param && pNote &&              if (itEvent->Type == Event::type_note_synth_param && pNote &&
742                  pEngineChannel->pEngine->NoteByID( itEvent->Param.NoteSynthParam.NoteID ) == pNote)                  pEngineChannel->pEngine->NoteByID( itEvent->Param.NoteSynthParam.NoteID ) == pNote)
743              {              {
744                  switch (itEvent->Param.NoteSynthParam.Type) {                  switch (itEvent->Param.NoteSynthParam.Type) {
745                      case Event::synth_param_volume:                      case Event::synth_param_volume:
746                          NoteVolumeSmoother.update(itEvent->Param.NoteSynthParam.AbsValue);                          NoteVolume.fadeTo(itEvent->Param.NoteSynthParam.AbsValue, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
747                            break;
748                        case Event::synth_param_volume_time:
749                            NoteVolume.setDefaultDuration(itEvent->Param.NoteSynthParam.AbsValue);
750                          break;                          break;
751                      case Event::synth_param_pitch:                      case Event::synth_param_pitch:
752                          NotePitch = itEvent->Param.NoteSynthParam.AbsValue;                          NotePitch.fadeTo(itEvent->Param.NoteSynthParam.AbsValue, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
753                            break;
754                        case Event::synth_param_pitch_time:
755                            NotePitch.setDefaultDuration(itEvent->Param.NoteSynthParam.AbsValue);
756                          break;                          break;
757                      case Event::synth_param_pan:                      case Event::synth_param_pan:
758                          NotePanLeft  = AbstractEngine::PanCurveValueNorm(itEvent->Param.NoteSynthParam.AbsValue, 0 /*left*/);                          NotePanLeft  = AbstractEngine::PanCurveValueNorm(itEvent->Param.NoteSynthParam.AbsValue, 0 /*left*/);
# Line 728  namespace LinuxSampler { Line 764  namespace LinuxSampler {
764                      case Event::synth_param_resonance:                      case Event::synth_param_resonance:
765                          NoteResonance = itEvent->Param.NoteSynthParam.AbsValue;                          NoteResonance = itEvent->Param.NoteSynthParam.AbsValue;
766                          break;                          break;
767                        case Event::synth_param_amp_lfo_depth:
768                            pLFO1->setScriptDepthFactor(itEvent->Param.NoteSynthParam.AbsValue);
769                            break;
770                        case Event::synth_param_amp_lfo_freq:
771                            pLFO1->setScriptFrequencyFactor(itEvent->Param.NoteSynthParam.AbsValue, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
772                            break;
773                        case Event::synth_param_pitch_lfo_depth:
774                            pLFO3->setScriptDepthFactor(itEvent->Param.NoteSynthParam.AbsValue);
775                            break;
776                        case Event::synth_param_pitch_lfo_freq:
777                            pLFO3->setScriptFrequencyFactor(itEvent->Param.NoteSynthParam.AbsValue, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
778                            break;
779    
780                        case Event::synth_param_attack:
781                        case Event::synth_param_decay:
782                        case Event::synth_param_release:
783                            break; // noop
784                  }                  }
785              }              }
786          }          }

Legend:
Removed from v.2935  
changed lines
  Added in v.3214

  ViewVC Help
Powered by ViewVC