/[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 245 by schoenebeck, Sat Sep 18 14:12:36 2004 UTC revision 247 by senkov, Sun Sep 19 23:44:23 2004 UTC
# Line 118  namespace LinuxSampler { namespace gig { Line 118  namespace LinuxSampler { namespace gig {
118    
119          Type            = type_normal;          Type            = type_normal;
120          Active          = true;          Active          = true;
121          MIDIKey         = pNoteOnEvent->Key;          MIDIKey         = pNoteOnEvent->Param.Note.Key;
122          pRegion         = pInstrument->GetRegion(MIDIKey);          pRegion         = pInstrument->GetRegion(MIDIKey);
123          PlaybackState   = playback_state_ram; // we always start playback from RAM cache and switch then to disk if needed          PlaybackState   = playback_state_ram; // we always start playback from RAM cache and switch then to disk if needed
124          Delay           = pNoteOnEvent->FragmentPos();          Delay           = pNoteOnEvent->FragmentPos();
# Line 149  namespace LinuxSampler { namespace gig { Line 149  namespace LinuxSampler { namespace gig {
149                              pEngine->LaunchVoice(pNoteOnEvent, iNewLayer, ReleaseTriggerVoice);                              pEngine->LaunchVoice(pNoteOnEvent, iNewLayer, ReleaseTriggerVoice);
150                      break;                      break;
151                  case ::gig::dimension_velocity:                  case ::gig::dimension_velocity:
152                      DimValues[i] = pNoteOnEvent->Velocity;                      DimValues[i] = pNoteOnEvent->Param.Note.Velocity;
153                      break;                      break;
154                  case ::gig::dimension_channelaftertouch:                  case ::gig::dimension_channelaftertouch:
155                      DimValues[i] = 0; //TODO: we currently ignore this dimension                      DimValues[i] = 0; //TODO: we currently ignore this dimension
# Line 159  namespace LinuxSampler { namespace gig { Line 159  namespace LinuxSampler { namespace gig {
159                      DimValues[i] = (uint) ReleaseTriggerVoice;                      DimValues[i] = (uint) ReleaseTriggerVoice;
160                      break;                      break;
161                  case ::gig::dimension_keyboard:                  case ::gig::dimension_keyboard:
162                      DimValues[i] = (uint) pNoteOnEvent->Key;                      DimValues[i] = (uint) pNoteOnEvent->Param.Note.Key;
163                      break;                      break;
164                  case ::gig::dimension_modwheel:                  case ::gig::dimension_modwheel:
165                      DimValues[i] = pEngine->ControllerTable[1];                      DimValues[i] = pEngine->ControllerTable[1];
# Line 245  namespace LinuxSampler { namespace gig { Line 245  namespace LinuxSampler { namespace gig {
245                  CrossfadeVolume = 1.0f; //TODO: aftertouch not supported yet                  CrossfadeVolume = 1.0f; //TODO: aftertouch not supported yet
246                  break;                  break;
247              case ::gig::attenuation_ctrl_t::type_velocity:              case ::gig::attenuation_ctrl_t::type_velocity:
248                  CrossfadeVolume = CrossfadeAttenuation(pNoteOnEvent->Velocity);                  CrossfadeVolume = CrossfadeAttenuation(pNoteOnEvent->Param.Note.Velocity);
249                  break;                  break;
250              case ::gig::attenuation_ctrl_t::type_controlchange: //FIXME: currently not sample accurate              case ::gig::attenuation_ctrl_t::type_controlchange: //FIXME: currently not sample accurate
251                  CrossfadeVolume = CrossfadeAttenuation(pEngine->ControllerTable[pDimRgn->AttenuationController.controller_number]);                  CrossfadeVolume = CrossfadeAttenuation(pEngine->ControllerTable[pDimRgn->AttenuationController.controller_number]);
# Line 255  namespace LinuxSampler { namespace gig { Line 255  namespace LinuxSampler { namespace gig {
255                  CrossfadeVolume = 1.0f;                  CrossfadeVolume = 1.0f;
256          }          }
257    
258          PanLeft  = float(RTMath::Max(pDimRgn->Pan, 0)) / -64.0f;          const float fpan = float(RTMath::Max(RTMath::Min(pDimRgn->Pan, 63), -64)) / 64.0f;
259          PanRight = float(RTMath::Min(pDimRgn->Pan, 0)) /  63.0f;          PanLeft  = 1.0f - fpan;
260            PanRight = 1.0f + fpan;
261    
262          pSample = pDimRgn->pSample; // sample won't change until the voice is finished          pSample = pDimRgn->pSample; // sample won't change until the voice is finished
263    
# Line 303  namespace LinuxSampler { namespace gig { Line 304  namespace LinuxSampler { namespace gig {
304          }          }
305    
306    
307          Volume = pDimRgn->GetVelocityAttenuation(pNoteOnEvent->Velocity) / 32768.0f; // we downscale by 32768 to convert from int16 value range to DSP value range (which is -1.0..1.0)          Volume = pDimRgn->GetVelocityAttenuation(pNoteOnEvent->Param.Note.Velocity) / 32768.0f; // we downscale by 32768 to convert from int16 value range to DSP value range (which is -1.0..1.0)
308    
309    
310          // setup EG 1 (VCA EG)          // setup EG 1 (VCA EG)
# Line 318  namespace LinuxSampler { namespace gig { Line 319  namespace LinuxSampler { namespace gig {
319                      eg1controllervalue = 0; // TODO: aftertouch not yet supported                      eg1controllervalue = 0; // TODO: aftertouch not yet supported
320                      break;                      break;
321                  case ::gig::eg1_ctrl_t::type_velocity:                  case ::gig::eg1_ctrl_t::type_velocity:
322                      eg1controllervalue = pNoteOnEvent->Velocity;                      eg1controllervalue = pNoteOnEvent->Param.Note.Velocity;
323                      break;                      break;
324                  case ::gig::eg1_ctrl_t::type_controlchange: // MIDI control change controller                  case ::gig::eg1_ctrl_t::type_controlchange: // MIDI control change controller
325                      eg1controllervalue = pEngine->ControllerTable[pDimRgn->EG1Controller.controller_number];                      eg1controllervalue = pEngine->ControllerTable[pDimRgn->EG1Controller.controller_number];
# Line 357  namespace LinuxSampler { namespace gig { Line 358  namespace LinuxSampler { namespace gig {
358                      eg2controllervalue = 0; // TODO: aftertouch not yet supported                      eg2controllervalue = 0; // TODO: aftertouch not yet supported
359                      break;                      break;
360                  case ::gig::eg2_ctrl_t::type_velocity:                  case ::gig::eg2_ctrl_t::type_velocity:
361                      eg2controllervalue = pNoteOnEvent->Velocity;                      eg2controllervalue = pNoteOnEvent->Param.Note.Velocity;
362                      break;                      break;
363                  case ::gig::eg2_ctrl_t::type_controlchange: // MIDI control change controller                  case ::gig::eg2_ctrl_t::type_controlchange: // MIDI control change controller
364                      eg2controllervalue = pEngine->ControllerTable[pDimRgn->EG2Controller.controller_number];                      eg2controllervalue = pEngine->ControllerTable[pDimRgn->EG2Controller.controller_number];
# Line 585  namespace LinuxSampler { namespace gig { Line 586  namespace LinuxSampler { namespace gig {
586    
587              // calculate cutoff frequency              // calculate cutoff frequency
588              float cutoff = (!VCFCutoffCtrl.controller)              float cutoff = (!VCFCutoffCtrl.controller)
589                  ? exp((float) (127 - pNoteOnEvent->Velocity) * (float) pDimRgn->VCFVelocityScale * 6.2E-5f * FILTER_CUTOFF_COEFF) * FILTER_CUTOFF_MAX                  ? exp((float) (127 - pNoteOnEvent->Param.Note.Velocity) * (float) pDimRgn->VCFVelocityScale * 6.2E-5f * FILTER_CUTOFF_COEFF) * FILTER_CUTOFF_MAX
590                  : exp((float) VCFCutoffCtrl.value * 0.00787402f * FILTER_CUTOFF_COEFF) * FILTER_CUTOFF_MAX;                  : exp((float) VCFCutoffCtrl.value * 0.00787402f * FILTER_CUTOFF_COEFF) * FILTER_CUTOFF_MAX;
591    
592              // calculate resonance              // calculate resonance
593              float resonance = (float) VCFResonanceCtrl.value * 0.00787f;   // 0.0..1.0              float resonance = (float) VCFResonanceCtrl.value * 0.00787f;   // 0.0..1.0
594              if (pDimRgn->VCFKeyboardTracking) {              if (pDimRgn->VCFKeyboardTracking) {
595                  resonance += (float) (pNoteOnEvent->Key - pDimRgn->VCFKeyboardTrackingBreakpoint) * 0.00787f;                  resonance += (float) (pNoteOnEvent->Param.Note.Key - pDimRgn->VCFKeyboardTrackingBreakpoint) * 0.00787f;
596              }              }
597              Constrain(resonance, 0.0, 1.0); // correct resonance if outside allowed value range (0.0..1.0)              Constrain(resonance, 0.0, 1.0); // correct resonance if outside allowed value range (0.0..1.0)
598    
# Line 752  namespace LinuxSampler { namespace gig { Line 753  namespace LinuxSampler { namespace gig {
753              while (pCCEvent && pCCEvent->FragmentPos() <= Delay) pCCEvent = pEngine->pCCEvents->next();              while (pCCEvent && pCCEvent->FragmentPos() <= Delay) pCCEvent = pEngine->pCCEvents->next();
754          }          }
755          while (pCCEvent) {          while (pCCEvent) {
756              if (pCCEvent->Controller) { // if valid MIDI controller              if (pCCEvent->Param.CC.Controller) { // if valid MIDI controller
757                  #if ENABLE_FILTER                  #if ENABLE_FILTER
758                  if (pCCEvent->Controller == VCFCutoffCtrl.controller) {                  if (pCCEvent->Param.CC.Controller == VCFCutoffCtrl.controller) {
759                      pEngine->pSynthesisEvents[Event::destination_vcfc]->alloc_assign(*pCCEvent);                      pEngine->pSynthesisEvents[Event::destination_vcfc]->alloc_assign(*pCCEvent);
760                  }                  }
761                  if (pCCEvent->Controller == VCFResonanceCtrl.controller) {                  if (pCCEvent->Param.CC.Controller == VCFResonanceCtrl.controller) {
762                      pEngine->pSynthesisEvents[Event::destination_vcfr]->alloc_assign(*pCCEvent);                      pEngine->pSynthesisEvents[Event::destination_vcfr]->alloc_assign(*pCCEvent);
763                  }                  }
764                  #endif // ENABLE_FILTER                  #endif // ENABLE_FILTER
765                  if (pCCEvent->Controller == pLFO1->ExtController) {                  if (pCCEvent->Param.CC.Controller == pLFO1->ExtController) {
766                      pLFO1->SendEvent(pCCEvent);                      pLFO1->SendEvent(pCCEvent);
767                  }                  }
768                  #if ENABLE_FILTER                  #if ENABLE_FILTER
769                  if (pCCEvent->Controller == pLFO2->ExtController) {                  if (pCCEvent->Param.CC.Controller == pLFO2->ExtController) {
770                      pLFO2->SendEvent(pCCEvent);                      pLFO2->SendEvent(pCCEvent);
771                  }                  }
772                  #endif // ENABLE_FILTER                  #endif // ENABLE_FILTER
773                  if (pCCEvent->Controller == pLFO3->ExtController) {                  if (pCCEvent->Param.CC.Controller == pLFO3->ExtController) {
774                      pLFO3->SendEvent(pCCEvent);                      pLFO3->SendEvent(pCCEvent);
775                  }                  }
776                  if (pDimRgn->AttenuationController.type == ::gig::attenuation_ctrl_t::type_controlchange &&                  if (pDimRgn->AttenuationController.type == ::gig::attenuation_ctrl_t::type_controlchange &&
777                      pCCEvent->Controller == pDimRgn->AttenuationController.controller_number) { // if crossfade event                      pCCEvent->Param.CC.Controller == pDimRgn->AttenuationController.controller_number) { // if crossfade event
778                      pEngine->pSynthesisEvents[Event::destination_vca]->alloc_assign(*pCCEvent);                      pEngine->pSynthesisEvents[Event::destination_vca]->alloc_assign(*pCCEvent);
779                  }                  }
780              }              }
# Line 803  namespace LinuxSampler { namespace gig { Line 804  namespace LinuxSampler { namespace gig {
804                  // calculate the influence length of this event (in sample points)                  // calculate the influence length of this event (in sample points)
805                  uint end = (pNextVCOEvent) ? pNextVCOEvent->FragmentPos() : Samples;                  uint end = (pNextVCOEvent) ? pNextVCOEvent->FragmentPos() : Samples;
806    
807                  pitch = RTMath::CentsToFreqRatio(((double) pVCOEvent->Pitch / 8192.0) * 200.0); // +-two semitones = +-200 cents                  pitch = RTMath::CentsToFreqRatio(((double) pVCOEvent->Param.Pitch.Pitch / 8192.0) * 200.0); // +-two semitones = +-200 cents
808    
809                  // apply pitch value to the pitch parameter sequence                  // apply pitch value to the pitch parameter sequence
810                  for (uint i = pVCOEvent->FragmentPos(); i < end; i++) {                  for (uint i = pVCOEvent->FragmentPos(); i < end; i++) {
# Line 829  namespace LinuxSampler { namespace gig { Line 830  namespace LinuxSampler { namespace gig {
830                  // calculate the influence length of this event (in sample points)                  // calculate the influence length of this event (in sample points)
831                  uint end = (pNextVCAEvent) ? pNextVCAEvent->FragmentPos() : Samples;                  uint end = (pNextVCAEvent) ? pNextVCAEvent->FragmentPos() : Samples;
832    
833                  crossfadevolume = CrossfadeAttenuation(pVCAEvent->Value);                  crossfadevolume = CrossfadeAttenuation(pVCAEvent->Param.CC.Value);
834    
835                  float effective_volume = crossfadevolume * this->Volume * pEngine->GlobalVolume;                  float effective_volume = crossfadevolume * this->Volume * pEngine->GlobalVolume;
836    
# Line 858  namespace LinuxSampler { namespace gig { Line 859  namespace LinuxSampler { namespace gig {
859                  // calculate the influence length of this event (in sample points)                  // calculate the influence length of this event (in sample points)
860                  uint end = (pNextCutoffEvent) ? pNextCutoffEvent->FragmentPos() : Samples;                  uint end = (pNextCutoffEvent) ? pNextCutoffEvent->FragmentPos() : Samples;
861    
862                  cutoff = exp((float) pCutoffEvent->Value * 0.00787402f * FILTER_CUTOFF_COEFF) * FILTER_CUTOFF_MAX - FILTER_CUTOFF_MIN;                  cutoff = exp((float) pCutoffEvent->Param.CC.Value * 0.00787402f * FILTER_CUTOFF_COEFF) * FILTER_CUTOFF_MAX - FILTER_CUTOFF_MIN;
863    
864                  // apply cutoff frequency to the cutoff parameter sequence                  // apply cutoff frequency to the cutoff parameter sequence
865                  for (uint i = pCutoffEvent->FragmentPos(); i < end; i++) {                  for (uint i = pCutoffEvent->FragmentPos(); i < end; i++) {
# Line 884  namespace LinuxSampler { namespace gig { Line 885  namespace LinuxSampler { namespace gig {
885                  uint end = (pNextResonanceEvent) ? pNextResonanceEvent->FragmentPos() : Samples;                  uint end = (pNextResonanceEvent) ? pNextResonanceEvent->FragmentPos() : Samples;
886    
887                  // convert absolute controller value to differential                  // convert absolute controller value to differential
888                  int ctrldelta = pResonanceEvent->Value - VCFResonanceCtrl.value;                  int ctrldelta = pResonanceEvent->Param.CC.Value - VCFResonanceCtrl.value;
889                  VCFResonanceCtrl.value = pResonanceEvent->Value;                  VCFResonanceCtrl.value = pResonanceEvent->Param.CC.Value;
890    
891                  float resonancedelta = (float) ctrldelta * 0.00787f; // 0.0..1.0                  float resonancedelta = (float) ctrldelta * 0.00787f; // 0.0..1.0
892    
# Line 896  namespace LinuxSampler { namespace gig { Line 897  namespace LinuxSampler { namespace gig {
897    
898                  pResonanceEvent = pNextResonanceEvent;                  pResonanceEvent = pNextResonanceEvent;
899              }              }
900              if (pResonanceEventList->last()) VCFResonanceCtrl.fvalue = pResonanceEventList->last()->Value * 0.00787f; // needed for initialization of parameter matrix next time              if (pResonanceEventList->last()) VCFResonanceCtrl.fvalue = pResonanceEventList->last()->Param.CC.Value * 0.00787f; // needed for initialization of parameter matrix next time
901          }          }
902      #endif // ENABLE_FILTER      #endif // ENABLE_FILTER
903      }      }

Legend:
Removed from v.245  
changed lines
  Added in v.247

  ViewVC Help
Powered by ViewVC