/[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 2217 by iliev, Tue Jul 26 15:51:30 2011 UTC revision 2297 by iliev, Fri Dec 9 15:04:55 2011 UTC
# Line 99  namespace LinuxSampler { Line 99  namespace LinuxSampler {
99    
100          Type            = VoiceType;          Type            = VoiceType;
101          MIDIKey         = itNoteOnEvent->Param.Note.Key;          MIDIKey         = itNoteOnEvent->Param.Note.Key;
102            MIDIVelocity    = itNoteOnEvent->Param.Note.Velocity;
103            MIDIPan         = pEngineChannel->ControllerTable[10];
104            if (MIDIPan == 0 && pEngineChannel->GlobalPanRight == 1) MIDIPan = 64; // workaround used to determine whether the MIDI pan has not been set
105          PlaybackState   = playback_state_init; // mark voice as triggered, but no audio rendered yet          PlaybackState   = playback_state_init; // mark voice as triggered, but no audio rendered yet
106          Delay           = itNoteOnEvent->FragmentPos();          Delay           = itNoteOnEvent->FragmentPos();
107          itTriggerEvent  = itNoteOnEvent;          itTriggerEvent  = itNoteOnEvent;
# Line 309  namespace LinuxSampler { Line 312  namespace LinuxSampler {
312       *  @param Skip    - number of sample points to skip in output buffer       *  @param Skip    - number of sample points to skip in output buffer
313       */       */
314      void AbstractVoice::Synthesize(uint Samples, sample_t* pSrc, uint Skip) {      void AbstractVoice::Synthesize(uint Samples, sample_t* pSrc, uint Skip) {
315            bool delay = false; // Whether the voice playback should be delayed for this call
316            
317            if (pSignalUnitRack != NULL) {
318                uint delaySteps = pSignalUnitRack->GetEndpointUnit()->DelayTrigger();
319                if (delaySteps > 0) { // delay on the endpoint unit means delay of the voice playback
320                    if (delaySteps >= Samples) {
321                        pSignalUnitRack->GetEndpointUnit()->DecreaseDelay(Samples);
322                        delay = true;
323                    } else {
324                        pSignalUnitRack->GetEndpointUnit()->DecreaseDelay(delaySteps);
325                        Samples -= delaySteps;
326                        Skip += delaySteps;
327                    }
328                }
329            }
330            
331          AbstractEngineChannel* pChannel = pEngineChannel;          AbstractEngineChannel* pChannel = pEngineChannel;
332          MidiKeyBase* pMidiKeyInfo = GetMidiKeyInfo(MIDIKey);          MidiKeyBase* pMidiKeyInfo = GetMidiKeyInfo(MIDIKey);
333    
334          const bool bVoiceRequiresDedicatedRouting =          const bool bVoiceRequiresDedicatedRouting =
335              pEngineChannel->GetFxSendCount() > 0 &&              pEngineChannel->GetFxSendCount() > 0 &&
336              (pMidiKeyInfo->ReverbSend || pMidiKeyInfo->ChorusSend);              (pMidiKeyInfo->ReverbSend || pMidiKeyInfo->ChorusSend);
337            
338            const bool bEq =
339                pSignalUnitRack != NULL && pSignalUnitRack->HasEq() && GetEngine()->pEq->HasSupport();
340    
341          if (bVoiceRequiresDedicatedRouting) {          if (bEq) {
342                GetEngine()->pEq->GetInChannelLeft()->Clear();
343                GetEngine()->pEq->GetInChannelRight()->Clear();
344                finalSynthesisParameters.pOutLeft  = &GetEngine()->pEq->GetInChannelLeft()->Buffer()[Skip];
345                finalSynthesisParameters.pOutRight = &GetEngine()->pEq->GetInChannelRight()->Buffer()[Skip];
346                pSignalUnitRack->UpdateEqSettings(GetEngine()->pEq);
347            } else if (bVoiceRequiresDedicatedRouting) {
348              finalSynthesisParameters.pOutLeft  = &GetEngine()->pDedicatedVoiceChannelLeft->Buffer()[Skip];              finalSynthesisParameters.pOutLeft  = &GetEngine()->pDedicatedVoiceChannelLeft->Buffer()[Skip];
349              finalSynthesisParameters.pOutRight = &GetEngine()->pDedicatedVoiceChannelRight->Buffer()[Skip];              finalSynthesisParameters.pOutRight = &GetEngine()->pDedicatedVoiceChannelRight->Buffer()[Skip];
350          } else {          } else {
# Line 377  namespace LinuxSampler { Line 405  namespace LinuxSampler {
405    
406              // process MIDI control change and pitchbend events for this subfragment              // process MIDI control change and pitchbend events for this subfragment
407              processCCEvents(itCCEvent, iSubFragmentEnd);              processCCEvents(itCCEvent, iSubFragmentEnd);
408                uint8_t pan = MIDIPan;
409                if (pSignalUnitRack != NULL) pan = pSignalUnitRack->GetEndpointUnit()->CaluclatePan(pan);
410                
411                PanLeftSmoother.update(AbstractEngine::PanCurve[128 - pan]);
412                PanRightSmoother.update(AbstractEngine::PanCurve[pan]);
413    
414              finalSynthesisParameters.fFinalPitch = Pitch.PitchBase * Pitch.PitchBend;              finalSynthesisParameters.fFinalPitch = Pitch.PitchBase * Pitch.PitchBend;
415              float fFinalVolume = VolumeSmoother.render() * CrossfadeSmoother.render();              float fFinalVolume = VolumeSmoother.render() * CrossfadeSmoother.render();
# Line 387  namespace LinuxSampler { Line 420  namespace LinuxSampler {
420              // process transition events (note on, note off & sustain pedal)              // process transition events (note on, note off & sustain pedal)
421              processTransitionEvents(itNoteEvent, iSubFragmentEnd);              processTransitionEvents(itNoteEvent, iSubFragmentEnd);
422              processGroupEvents(itGroupEvent, iSubFragmentEnd);              processGroupEvents(itGroupEvent, iSubFragmentEnd);
423                
424              if (pSignalUnitRack == NULL) {              if (pSignalUnitRack == NULL) {
425                  // if the voice was killed in this subfragment, or if the                  // if the voice was killed in this subfragment, or if the
426                  // filter EG is finished, switch EG1 to fade out stage                  // filter EG is finished, switch EG1 to fade out stage
# Line 485  namespace LinuxSampler { Line 518  namespace LinuxSampler {
518                  fFinalVolume * VolumeRight * PanRightSmoother.render();                  fFinalVolume * VolumeRight * PanRightSmoother.render();
519  #endif  #endif
520              // render audio for one subfragment              // render audio for one subfragment
521              RunSynthesisFunction(SynthesisMode, &finalSynthesisParameters, &loop);              if (!delay) RunSynthesisFunction(SynthesisMode, &finalSynthesisParameters, &loop);
522    
523              if (pSignalUnitRack == NULL) {              if (pSignalUnitRack == NULL) {
524                  // stop the rendering if volume EG is finished                  // stop the rendering if volume EG is finished
# Line 522  namespace LinuxSampler { Line 555  namespace LinuxSampler {
555                      }*/                      }*/
556                  // TODO: ^^^                  // TODO: ^^^
557                                    
558                  pSignalUnitRack->Increment();                  if (!delay) pSignalUnitRack->Increment();
559              }              }
560    
561              Pos = newPos;              Pos = newPos;
562              i = iSubFragmentEnd;              i = iSubFragmentEnd;
563          }          }
564            
565            if (delay) return;
566    
567          if (bVoiceRequiresDedicatedRouting) {          if (bVoiceRequiresDedicatedRouting) {
568                if (bEq) {
569                    GetEngine()->pEq->RenderAudio(Samples);
570                    GetEngine()->pEq->GetOutChannelLeft()->CopyTo(GetEngine()->pDedicatedVoiceChannelLeft, Samples);
571                    GetEngine()->pEq->GetOutChannelRight()->CopyTo(GetEngine()->pDedicatedVoiceChannelRight, Samples);
572                }
573              optional<float> effectSendLevels[2] = {              optional<float> effectSendLevels[2] = {
574                  pMidiKeyInfo->ReverbSend,                  pMidiKeyInfo->ReverbSend,
575                  pMidiKeyInfo->ChorusSend                  pMidiKeyInfo->ChorusSend
576              };              };
577              GetEngine()->RouteDedicatedVoiceChannels(pEngineChannel, effectSendLevels, Samples);              GetEngine()->RouteDedicatedVoiceChannels(pEngineChannel, effectSendLevels, Samples);
578            } else if (bEq) {
579                GetEngine()->pEq->RenderAudio(Samples);
580                GetEngine()->pEq->GetOutChannelLeft()->CopyTo(pChannel->pChannelLeft, Samples);
581                GetEngine()->pEq->GetOutChannelRight()->CopyTo(pChannel->pChannelRight, Samples);
582          }          }
583      }      }
584    
# Line 568  namespace LinuxSampler { Line 612  namespace LinuxSampler {
612                  if (itEvent->Param.CC.Controller == 7) { // volume                  if (itEvent->Param.CC.Controller == 7) { // volume
613                      VolumeSmoother.update(AbstractEngine::VolumeCurve[itEvent->Param.CC.Value]);                      VolumeSmoother.update(AbstractEngine::VolumeCurve[itEvent->Param.CC.Value]);
614                  } else if (itEvent->Param.CC.Controller == 10) { // panpot                  } else if (itEvent->Param.CC.Controller == 10) { // panpot
615                      PanLeftSmoother.update(AbstractEngine::PanCurve[128 - itEvent->Param.CC.Value]);                      MIDIPan = itEvent->Param.CC.Value;
                     PanRightSmoother.update(AbstractEngine::PanCurve[itEvent->Param.CC.Value]);  
616                  }                  }
617              } else if (itEvent->Type == Event::type_pitchbend) { // if pitch bend event              } else if (itEvent->Type == Event::type_pitchbend) { // if pitch bend event
618                  processPitchEvent(itEvent);                  processPitchEvent(itEvent);

Legend:
Removed from v.2217  
changed lines
  Added in v.2297

  ViewVC Help
Powered by ViewVC