/[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 287 by schoenebeck, Sat Oct 16 17:38:03 2004 UTC revision 368 by schoenebeck, Fri Feb 11 13:13:54 2005 UTC
# Line 22  Line 22 
22    
23  #include "EGADSR.h"  #include "EGADSR.h"
24  #include "Manipulator.h"  #include "Manipulator.h"
25    #include "../../common/Features.h"
26    #include "Synthesizer.h"
27    
28  #include "Voice.h"  #include "Voice.h"
29    
# Line 56  namespace LinuxSampler { namespace gig { Line 58  namespace LinuxSampler { namespace gig {
58          pLFO2  = NULL;          pLFO2  = NULL;
59          pLFO3  = NULL;          pLFO3  = NULL;
60          KeyGroup = 0;          KeyGroup = 0;
61            SynthesisMode = 0; // set all mode bits to 0 first
62            // select synthesis implementation (currently either pure C++ or MMX+SSE(1))
63            #if ARCH_X86
64            SYNTHESIS_MODE_SET_IMPLEMENTATION(SynthesisMode, Features::supportsMMX() && Features::supportsSSE());
65            #else
66            SYNTHESIS_MODE_SET_IMPLEMENTATION(SynthesisMode, false);
67            #endif
68            SYNTHESIS_MODE_SET_PROFILING(SynthesisMode, true);
69    
70            FilterLeft.Reset();
71            FilterRight.Reset();
72      }      }
73    
74      Voice::~Voice() {      Voice::~Voice() {
# Line 109  namespace LinuxSampler { namespace gig { Line 122  namespace LinuxSampler { namespace gig {
122       *  @param iLayer              - layer number this voice refers to (only if this is a layered sound of course)       *  @param iLayer              - layer number this voice refers to (only if this is a layered sound of course)
123       *  @param ReleaseTriggerVoice - if this new voice is a release trigger voice (optional, default = false)       *  @param ReleaseTriggerVoice - if this new voice is a release trigger voice (optional, default = false)
124       *  @param VoiceStealing       - wether the voice is allowed to steal voices for further subvoices       *  @param VoiceStealing       - wether the voice is allowed to steal voices for further subvoices
125       *  @returns 0 on success, a value < 0 if something failed       *  @returns 0 on success, a value < 0 if the voice wasn't triggered
126         *           (either due to an error or e.g. because no region is
127         *           defined for the given key)
128       */       */
129      int Voice::Trigger(Pool<Event>::Iterator& itNoteOnEvent, int PitchBend, ::gig::Instrument* pInstrument, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing) {      int Voice::Trigger(Pool<Event>::Iterator& itNoteOnEvent, int PitchBend, ::gig::Instrument* pInstrument, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing) {
130          if (!pInstrument) {          if (!pInstrument) {
131             dmsg(1,("voice::trigger: !pInstrument\n"));             dmsg(1,("voice::trigger: !pInstrument\n"));
132             exit(EXIT_FAILURE);             exit(EXIT_FAILURE);
133          }          }
134            if (itNoteOnEvent->FragmentPos() > pEngine->MaxSamplesPerCycle) { // FIXME: should be removed before the final release (purpose: just a sanity check for debugging)
135                dmsg(1,("Voice::Trigger(): ERROR, TriggerDelay > Totalsamples\n"));
136            }
137    
138          Type            = type_normal;          Type            = type_normal;
139          MIDIKey         = itNoteOnEvent->Param.Note.Key;          MIDIKey         = itNoteOnEvent->Param.Note.Key;
# Line 127  namespace LinuxSampler { namespace gig { Line 145  namespace LinuxSampler { namespace gig {
145          itChildVoice    = Pool<Voice>::Iterator();          itChildVoice    = Pool<Voice>::Iterator();
146    
147          if (!pRegion) {          if (!pRegion) {
148              std::cerr << "gig::Voice: No Region defined for MIDI key " << MIDIKey << std::endl << std::flush;              dmsg(4, ("gig::Voice: No Region defined for MIDI key %d\n", MIDIKey));
             KillImmediately();  
149              return -1;              return -1;
150          }          }
151    
# Line 136  namespace LinuxSampler { namespace gig { Line 153  namespace LinuxSampler { namespace gig {
153    
154          // get current dimension values to select the right dimension region          // get current dimension values to select the right dimension region
155          //FIXME: controller values for selecting the dimension region here are currently not sample accurate          //FIXME: controller values for selecting the dimension region here are currently not sample accurate
156          uint DimValues[5] = {0,0,0,0,0};          uint DimValues[8] = { 0 };
157          for (int i = pRegion->Dimensions - 1; i >= 0; i--) {          for (int i = pRegion->Dimensions - 1; i >= 0; i--) {
158              switch (pRegion->pDimensionDefinitions[i].dimension) {              switch (pRegion->pDimensionDefinitions[i].dimension) {
159                  case ::gig::dimension_samplechannel:                  case ::gig::dimension_samplechannel:
# Line 160  namespace LinuxSampler { namespace gig { Line 177  namespace LinuxSampler { namespace gig {
177                      DimValues[i] = (uint) ReleaseTriggerVoice;                      DimValues[i] = (uint) ReleaseTriggerVoice;
178                      break;                      break;
179                  case ::gig::dimension_keyboard:                  case ::gig::dimension_keyboard:
180                      DimValues[i] = (uint) itNoteOnEvent->Param.Note.Key;                      DimValues[i] = (uint) pEngine->CurrentKeyDimension;
181                      break;                      break;
182                  case ::gig::dimension_modwheel:                  case ::gig::dimension_modwheel:
183                      DimValues[i] = pEngine->ControllerTable[1];                      DimValues[i] = pEngine->ControllerTable[1];
# Line 238  namespace LinuxSampler { namespace gig { Line 255  namespace LinuxSampler { namespace gig {
255                      std::cerr << "gig::Voice::Trigger() Error: Unknown dimension\n" << std::flush;                      std::cerr << "gig::Voice::Trigger() Error: Unknown dimension\n" << std::flush;
256              }              }
257          }          }
258          pDimRgn = pRegion->GetDimensionRegionByValue(DimValues[4],DimValues[3],DimValues[2],DimValues[1],DimValues[0]);          pDimRgn = pRegion->GetDimensionRegionByValue(DimValues);
259    
260            pSample = pDimRgn->pSample; // sample won't change until the voice is finished
261            if (!pSample || !pSample->SamplesTotal) return -1; // no need to continue if sample is silent
262    
263            // select channel mode (mono or stereo)
264            SYNTHESIS_MODE_SET_CHANNELS(SynthesisMode, pSample->Channels == 2);
265    
266          // get starting crossfade volume level          // get starting crossfade volume level
267          switch (pDimRgn->AttenuationController.type) {          switch (pDimRgn->AttenuationController.type) {
# Line 259  namespace LinuxSampler { namespace gig { Line 282  namespace LinuxSampler { namespace gig {
282          PanLeft  = 1.0f - float(RTMath::Max(pDimRgn->Pan, 0)) /  63.0f;          PanLeft  = 1.0f - float(RTMath::Max(pDimRgn->Pan, 0)) /  63.0f;
283          PanRight = 1.0f - float(RTMath::Min(pDimRgn->Pan, 0)) / -64.0f;          PanRight = 1.0f - float(RTMath::Min(pDimRgn->Pan, 0)) / -64.0f;
284    
         pSample = pDimRgn->pSample; // sample won't change until the voice is finished  
   
285          Pos = pDimRgn->SampleStartOffset; // offset where we should start playback of sample (0 - 2000 sample points)          Pos = pDimRgn->SampleStartOffset; // offset where we should start playback of sample (0 - 2000 sample points)
286    
287          // 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
# Line 297  namespace LinuxSampler { namespace gig { Line 318  namespace LinuxSampler { namespace gig {
318    
319          // calculate initial pitch value          // calculate initial pitch value
320          {          {
321              double pitchbasecents = pDimRgn->FineTune * 10 + (int) pEngine->ScaleTuning[MIDIKey % 12];              double pitchbasecents = pDimRgn->FineTune + (int) pEngine->ScaleTuning[MIDIKey % 12];
322              if (pDimRgn->PitchTrack) pitchbasecents += (MIDIKey - (int) pDimRgn->UnityNote) * 100;              if (pDimRgn->PitchTrack) pitchbasecents += (MIDIKey - (int) pDimRgn->UnityNote) * 100;
323              this->PitchBase = RTMath::CentsToFreqRatio(pitchbasecents) * (double(pSample->SamplesPerSecond) / double(pEngine->pAudioOutputDevice->SampleRate()));              this->PitchBase = RTMath::CentsToFreqRatio(pitchbasecents) * (double(pSample->SamplesPerSecond) / double(pEngine->pAudioOutputDevice->SampleRate()));
324              this->PitchBend = RTMath::CentsToFreqRatio(((double) PitchBend / 8192.0) * 200.0); // pitchbend wheel +-2 semitones = 200 cents              this->PitchBend = RTMath::CentsToFreqRatio(((double) PitchBend / 8192.0) * 200.0); // pitchbend wheel +-2 semitones = 200 cents
325          }          }
326    
   
327          Volume = pDimRgn->GetVelocityAttenuation(itNoteOnEvent->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)          Volume = pDimRgn->GetVelocityAttenuation(itNoteOnEvent->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)
328    
   
329          // setup EG 1 (VCA EG)          // setup EG 1 (VCA EG)
330          {          {
331              // get current value of EG1 controller              // get current value of EG1 controller
# Line 345  namespace LinuxSampler { namespace gig { Line 364  namespace LinuxSampler { namespace gig {
364          }          }
365    
366    
     #if ENABLE_FILTER  
367          // setup EG 2 (VCF Cutoff EG)          // setup EG 2 (VCF Cutoff EG)
368          {          {
369              // get current value of EG2 controller              // get current value of EG2 controller
# Line 382  namespace LinuxSampler { namespace gig { Line 400  namespace LinuxSampler { namespace gig {
400                            pDimRgn->EG2Release + eg2release,                            pDimRgn->EG2Release + eg2release,
401                            Delay);                            Delay);
402          }          }
     #endif // ENABLE_FILTER  
403    
404    
405          // setup EG 3 (VCO EG)          // setup EG 3 (VCO EG)
# Line 429  namespace LinuxSampler { namespace gig { Line 446  namespace LinuxSampler { namespace gig {
446                            Delay);                            Delay);
447          }          }
448    
449      #if ENABLE_FILTER  
450          // setup LFO 2 (VCF Cutoff LFO)          // setup LFO 2 (VCF Cutoff LFO)
451          {          {
452              uint16_t lfo2_internal_depth;              uint16_t lfo2_internal_depth;
# Line 466  namespace LinuxSampler { namespace gig { Line 483  namespace LinuxSampler { namespace gig {
483                            pEngine->SampleRate,                            pEngine->SampleRate,
484                            Delay);                            Delay);
485          }          }
486      #endif // ENABLE_FILTER  
487    
488          // setup LFO 3 (VCO LFO)          // setup LFO 3 (VCO LFO)
489          {          {
# Line 505  namespace LinuxSampler { namespace gig { Line 522  namespace LinuxSampler { namespace gig {
522                            Delay);                            Delay);
523          }          }
524    
525      #if ENABLE_FILTER  
526          #if FORCE_FILTER_USAGE          #if FORCE_FILTER_USAGE
527          FilterLeft.Enabled = FilterRight.Enabled = true;          const bool bUseFilter = true;
528          #else // use filter only if instrument file told so          #else // use filter only if instrument file told so
529          FilterLeft.Enabled = FilterRight.Enabled = pDimRgn->VCFEnabled;          const bool bUseFilter = pDimRgn->VCFEnabled;
530          #endif // FORCE_FILTER_USAGE          #endif // FORCE_FILTER_USAGE
531          if (pDimRgn->VCFEnabled) {          SYNTHESIS_MODE_SET_FILTER(SynthesisMode, bUseFilter);
532            if (bUseFilter) {
533              #ifdef OVERRIDE_FILTER_CUTOFF_CTRL              #ifdef OVERRIDE_FILTER_CUTOFF_CTRL
534              VCFCutoffCtrl.controller = OVERRIDE_FILTER_CUTOFF_CTRL;              VCFCutoffCtrl.controller = OVERRIDE_FILTER_CUTOFF_CTRL;
535              #else // use the one defined in the instrument file              #else // use the one defined in the instrument file
# Line 599  namespace LinuxSampler { namespace gig { Line 617  namespace LinuxSampler { namespace gig {
617              VCFCutoffCtrl.fvalue    = cutoff - FILTER_CUTOFF_MIN;              VCFCutoffCtrl.fvalue    = cutoff - FILTER_CUTOFF_MIN;
618              VCFResonanceCtrl.fvalue = resonance;              VCFResonanceCtrl.fvalue = resonance;
619    
             FilterLeft.SetParameters(cutoff,  resonance, pEngine->SampleRate);  
             FilterRight.SetParameters(cutoff, resonance, pEngine->SampleRate);  
   
620              FilterUpdateCounter = -1;              FilterUpdateCounter = -1;
621          }          }
622          else {          else {
623              VCFCutoffCtrl.controller    = 0;              VCFCutoffCtrl.controller    = 0;
624              VCFResonanceCtrl.controller = 0;              VCFResonanceCtrl.controller = 0;
625          }          }
     #endif // ENABLE_FILTER  
626    
627          return 0; // success          return 0; // success
628      }      }
# Line 626  namespace LinuxSampler { namespace gig { Line 640  namespace LinuxSampler { namespace gig {
640       */       */
641      void Voice::Render(uint Samples) {      void Voice::Render(uint Samples) {
642    
643            // select default values for synthesis mode bits
644            SYNTHESIS_MODE_SET_INTERPOLATE(SynthesisMode, (PitchBase * PitchBend) != 1.0f);
645            SYNTHESIS_MODE_SET_CONSTPITCH(SynthesisMode, true);
646            SYNTHESIS_MODE_SET_LOOP(SynthesisMode, false);
647    
648          // Reset the synthesis parameter matrix          // Reset the synthesis parameter matrix
649    
650          pEngine->ResetSynthesisParameters(Event::destination_vca, this->Volume * this->CrossfadeVolume * pEngine->GlobalVolume);          pEngine->ResetSynthesisParameters(Event::destination_vca, this->Volume * this->CrossfadeVolume * pEngine->GlobalVolume);
651          pEngine->ResetSynthesisParameters(Event::destination_vco, this->PitchBase);          pEngine->ResetSynthesisParameters(Event::destination_vco, this->PitchBase);
     #if ENABLE_FILTER  
652          pEngine->ResetSynthesisParameters(Event::destination_vcfc, VCFCutoffCtrl.fvalue);          pEngine->ResetSynthesisParameters(Event::destination_vcfc, VCFCutoffCtrl.fvalue);
653          pEngine->ResetSynthesisParameters(Event::destination_vcfr, VCFResonanceCtrl.fvalue);          pEngine->ResetSynthesisParameters(Event::destination_vcfr, VCFResonanceCtrl.fvalue);
     #endif // ENABLE_FILTER  
   
654    
655          // Apply events to the synthesis parameter matrix          // Apply events to the synthesis parameter matrix
656          ProcessEvents(Samples);          ProcessEvents(Samples);
657    
   
658          // Let all modulators write their parameter changes to the synthesis parameter matrix for the current audio fragment          // Let all modulators write their parameter changes to the synthesis parameter matrix for the current audio fragment
659          pEG1->Process(Samples, pEngine->pMIDIKeyInfo[MIDIKey].pEvents, itTriggerEvent, this->Pos, this->PitchBase * this->PitchBend, itKillEvent);          pEG1->Process(Samples, pEngine->pMIDIKeyInfo[MIDIKey].pEvents, itTriggerEvent, this->Pos, this->PitchBase * this->PitchBend, itKillEvent);
     #if ENABLE_FILTER  
660          pEG2->Process(Samples, pEngine->pMIDIKeyInfo[MIDIKey].pEvents, itTriggerEvent, this->Pos, this->PitchBase * this->PitchBend);          pEG2->Process(Samples, pEngine->pMIDIKeyInfo[MIDIKey].pEvents, itTriggerEvent, this->Pos, this->PitchBase * this->PitchBend);
661      #endif // ENABLE_FILTER          if (pEG3->Process(Samples)) { // if pitch EG is active
662          pEG3->Process(Samples);              SYNTHESIS_MODE_SET_INTERPOLATE(SynthesisMode, true);
663                SYNTHESIS_MODE_SET_CONSTPITCH(SynthesisMode, false);
664            }
665          pLFO1->Process(Samples);          pLFO1->Process(Samples);
     #if ENABLE_FILTER  
666          pLFO2->Process(Samples);          pLFO2->Process(Samples);
667      #endif // ENABLE_FILTER          if (pLFO3->Process(Samples)) { // if pitch LFO modulation is active
668          pLFO3->Process(Samples);              SYNTHESIS_MODE_SET_INTERPOLATE(SynthesisMode, true);
669                SYNTHESIS_MODE_SET_CONSTPITCH(SynthesisMode, false);
670            }
     #if ENABLE_FILTER  
         CalculateBiquadParameters(Samples); // calculate the final biquad filter parameters  
     #endif // ENABLE_FILTER  
671    
672            if (SYNTHESIS_MODE_GET_FILTER(SynthesisMode))
673                    CalculateBiquadParameters(Samples); // calculate the final biquad filter parameters
674    
675          switch (this->PlaybackState) {          switch (this->PlaybackState) {
676    
677              case playback_state_ram: {              case playback_state_ram: {
678                      if (RAMLoop) InterpolateAndLoop(Samples, (sample_t*) pSample->GetCache().pStart, Delay);                      if (RAMLoop) SYNTHESIS_MODE_SET_LOOP(SynthesisMode, true); // enable looping
679                      else         InterpolateNoLoop(Samples, (sample_t*) pSample->GetCache().pStart, Delay);  
680                        // render current fragment
681                        Synthesize(Samples, (sample_t*) pSample->GetCache().pStart, Delay);
682    
683                      if (DiskVoice) {                      if (DiskVoice) {
684                          // check if we reached the allowed limit of the sample RAM cache                          // check if we reached the allowed limit of the sample RAM cache
685                          if (Pos > MaxRAMPos) {                          if (Pos > MaxRAMPos) {
# Line 684  namespace LinuxSampler { namespace gig { Line 702  namespace LinuxSampler { namespace gig {
702                              KillImmediately();                              KillImmediately();
703                              return;                              return;
704                          }                          }
705                          DiskStreamRef.pStream->IncrementReadPos(pSample->Channels * (RTMath::DoubleToInt(Pos) - MaxRAMPos));                          DiskStreamRef.pStream->IncrementReadPos(pSample->Channels * (int(Pos) - MaxRAMPos));
706                          Pos -= RTMath::DoubleToInt(Pos);                          Pos -= int(Pos);
707                            RealSampleWordsLeftToRead = -1; // -1 means no silence has been added yet
708                      }                      }
709    
710                        const int sampleWordsLeftToRead = DiskStreamRef.pStream->GetReadSpace();
711    
712                      // add silence sample at the end if we reached the end of the stream (for the interpolator)                      // add silence sample at the end if we reached the end of the stream (for the interpolator)
713                      if (DiskStreamRef.State == Stream::state_end && DiskStreamRef.pStream->GetReadSpace() < (pEngine->MaxSamplesPerCycle << MAX_PITCH) / pSample->Channels) {                      if (DiskStreamRef.State == Stream::state_end) {
714                          DiskStreamRef.pStream->WriteSilence((pEngine->MaxSamplesPerCycle << MAX_PITCH) / pSample->Channels);                          const int maxSampleWordsPerCycle = (pEngine->MaxSamplesPerCycle << MAX_PITCH) * pSample->Channels + 6; // +6 for the interpolator algorithm
715                          this->PlaybackState = playback_state_end;                          if (sampleWordsLeftToRead <= maxSampleWordsPerCycle) {
716                                // remember how many sample words there are before any silence has been added
717                                if (RealSampleWordsLeftToRead < 0) RealSampleWordsLeftToRead = sampleWordsLeftToRead;
718                                DiskStreamRef.pStream->WriteSilence(maxSampleWordsPerCycle - sampleWordsLeftToRead);
719                            }
720                      }                      }
721    
722                      sample_t* ptr = DiskStreamRef.pStream->GetReadPtr(); // get the current read_ptr within the ringbuffer where we read the samples from                      sample_t* ptr = DiskStreamRef.pStream->GetReadPtr(); // get the current read_ptr within the ringbuffer where we read the samples from
723                      InterpolateNoLoop(Samples, ptr, Delay);  
724                      DiskStreamRef.pStream->IncrementReadPos(RTMath::DoubleToInt(Pos) * pSample->Channels);                      // render current audio fragment
725                      Pos -= RTMath::DoubleToInt(Pos);                      Synthesize(Samples, ptr, Delay);
726    
727                        const int iPos = (int) Pos;
728                        const int readSampleWords = iPos * pSample->Channels; // amount of sample words actually been read
729                        DiskStreamRef.pStream->IncrementReadPos(readSampleWords);
730                        Pos -= iPos; // just keep fractional part of Pos
731    
732                        // change state of voice to 'end' if we really reached the end of the sample data
733                        if (RealSampleWordsLeftToRead >= 0) {
734                            RealSampleWordsLeftToRead -= readSampleWords;
735                            if (RealSampleWordsLeftToRead <= 0) this->PlaybackState = playback_state_end;
736                        }
737                  }                  }
738                  break;                  break;
739    
# Line 706  namespace LinuxSampler { namespace gig { Line 742  namespace LinuxSampler { namespace gig {
742                  break;                  break;
743          }          }
744    
   
745          // Reset synthesis event lists (except VCO, as VCO events apply channel wide currently)          // Reset synthesis event lists (except VCO, as VCO events apply channel wide currently)
746          pEngine->pSynthesisEvents[Event::destination_vca]->clear();          pEngine->pSynthesisEvents[Event::destination_vca]->clear();
     #if ENABLE_FILTER  
747          pEngine->pSynthesisEvents[Event::destination_vcfc]->clear();          pEngine->pSynthesisEvents[Event::destination_vcfc]->clear();
748          pEngine->pSynthesisEvents[Event::destination_vcfr]->clear();          pEngine->pSynthesisEvents[Event::destination_vcfr]->clear();
     #endif // ENABLE_FILTER  
749    
750          // Reset delay          // Reset delay
751          Delay = 0;          Delay = 0;
# Line 731  namespace LinuxSampler { namespace gig { Line 764  namespace LinuxSampler { namespace gig {
764          pLFO1->Reset();          pLFO1->Reset();
765          pLFO2->Reset();          pLFO2->Reset();
766          pLFO3->Reset();          pLFO3->Reset();
767            FilterLeft.Reset();
768            FilterRight.Reset();
769          DiskStreamRef.pStream = NULL;          DiskStreamRef.pStream = NULL;
770          DiskStreamRef.hStream = 0;          DiskStreamRef.hStream = 0;
771          DiskStreamRef.State   = Stream::state_unused;          DiskStreamRef.State   = Stream::state_unused;
# Line 756  namespace LinuxSampler { namespace gig { Line 791  namespace LinuxSampler { namespace gig {
791          }          }
792          while (itCCEvent) {          while (itCCEvent) {
793              if (itCCEvent->Param.CC.Controller) { // if valid MIDI controller              if (itCCEvent->Param.CC.Controller) { // if valid MIDI controller
                 #if ENABLE_FILTER  
794                  if (itCCEvent->Param.CC.Controller == VCFCutoffCtrl.controller) {                  if (itCCEvent->Param.CC.Controller == VCFCutoffCtrl.controller) {
795                      *pEngine->pSynthesisEvents[Event::destination_vcfc]->allocAppend() = *itCCEvent;                      *pEngine->pSynthesisEvents[Event::destination_vcfc]->allocAppend() = *itCCEvent;
796                  }                  }
797                  if (itCCEvent->Param.CC.Controller == VCFResonanceCtrl.controller) {                  if (itCCEvent->Param.CC.Controller == VCFResonanceCtrl.controller) {
798                      *pEngine->pSynthesisEvents[Event::destination_vcfr]->allocAppend() = *itCCEvent;                      *pEngine->pSynthesisEvents[Event::destination_vcfr]->allocAppend() = *itCCEvent;
799                  }                  }
                 #endif // ENABLE_FILTER  
800                  if (itCCEvent->Param.CC.Controller == pLFO1->ExtController) {                  if (itCCEvent->Param.CC.Controller == pLFO1->ExtController) {
801                      pLFO1->SendEvent(itCCEvent);                      pLFO1->SendEvent(itCCEvent);
802                  }                  }
                 #if ENABLE_FILTER  
803                  if (itCCEvent->Param.CC.Controller == pLFO2->ExtController) {                  if (itCCEvent->Param.CC.Controller == pLFO2->ExtController) {
804                      pLFO2->SendEvent(itCCEvent);                      pLFO2->SendEvent(itCCEvent);
805                  }                  }
                 #endif // ENABLE_FILTER  
806                  if (itCCEvent->Param.CC.Controller == pLFO3->ExtController) {                  if (itCCEvent->Param.CC.Controller == pLFO3->ExtController) {
807                      pLFO3->SendEvent(itCCEvent);                      pLFO3->SendEvent(itCCEvent);
808                  }                  }
# Line 816  namespace LinuxSampler { namespace gig { Line 847  namespace LinuxSampler { namespace gig {
847    
848                  itVCOEvent = itNextVCOEvent;                  itVCOEvent = itNextVCOEvent;
849              }              }
850              if (!pVCOEventList->isEmpty()) this->PitchBend = pitch;              if (!pVCOEventList->isEmpty()) {
851                    this->PitchBend = pitch;
852                    SYNTHESIS_MODE_SET_INTERPOLATE(SynthesisMode, true);
853                    SYNTHESIS_MODE_SET_CONSTPITCH(SynthesisMode, false);
854                }
855          }          }
856    
857          // process volume / attenuation events (TODO: we only handle and _expect_ crossfade events here ATM !)          // process volume / attenuation events (TODO: we only handle and _expect_ crossfade events here ATM !)
# Line 848  namespace LinuxSampler { namespace gig { Line 883  namespace LinuxSampler { namespace gig {
883              if (!pVCAEventList->isEmpty()) this->CrossfadeVolume = crossfadevolume;              if (!pVCAEventList->isEmpty()) this->CrossfadeVolume = crossfadevolume;
884          }          }
885    
     #if ENABLE_FILTER  
886          // process filter cutoff events          // process filter cutoff events
887          {          {
888              RTList<Event>* pCutoffEventList = pEngine->pSynthesisEvents[Event::destination_vcfc];              RTList<Event>* pCutoffEventList = pEngine->pSynthesisEvents[Event::destination_vcfc];
# Line 905  namespace LinuxSampler { namespace gig { Line 939  namespace LinuxSampler { namespace gig {
939              }              }
940              if (!pResonanceEventList->isEmpty()) VCFResonanceCtrl.fvalue = pResonanceEventList->last()->Param.CC.Value * 0.00787f; // needed for initialization of parameter matrix next time              if (!pResonanceEventList->isEmpty()) VCFResonanceCtrl.fvalue = pResonanceEventList->last()->Param.CC.Value * 0.00787f; // needed for initialization of parameter matrix next time
941          }          }
     #endif // ENABLE_FILTER  
942      }      }
943    
     #if ENABLE_FILTER  
944      /**      /**
945       * Calculate all necessary, final biquad filter parameters.       * Calculate all necessary, final biquad filter parameters.
946       *       *
947       * @param Samples - number of samples to be rendered in this audio fragment cycle       * @param Samples - number of samples to be rendered in this audio fragment cycle
948       */       */
949      void Voice::CalculateBiquadParameters(uint Samples) {      void Voice::CalculateBiquadParameters(uint Samples) {
         if (!FilterLeft.Enabled) return;  
   
950          biquad_param_t bqbase;          biquad_param_t bqbase;
951          biquad_param_t bqmain;          biquad_param_t bqmain;
952          float prev_cutoff = pEngine->pSynthesisParameters[Event::destination_vcfc][0];          float prev_cutoff = pEngine->pSynthesisParameters[Event::destination_vcfc][0];
953          float prev_res    = pEngine->pSynthesisParameters[Event::destination_vcfr][0];          float prev_res    = pEngine->pSynthesisParameters[Event::destination_vcfr][0];
954          FilterLeft.SetParameters(&bqbase, &bqmain, prev_cutoff, prev_res, pEngine->SampleRate);          FilterLeft.SetParameters( &bqbase, &bqmain, prev_cutoff + FILTER_CUTOFF_MIN, prev_res, pEngine->SampleRate);
955            FilterRight.SetParameters(&bqbase, &bqmain, prev_cutoff + FILTER_CUTOFF_MIN, prev_res, pEngine->SampleRate);
956          pEngine->pBasicFilterParameters[0] = bqbase;          pEngine->pBasicFilterParameters[0] = bqbase;
957          pEngine->pMainFilterParameters[0]  = bqmain;          pEngine->pMainFilterParameters[0]  = bqmain;
958    
959          float* bq;          float* bq;
960          for (int i = 1; i < Samples; i++) {          for (int i = 1; i < Samples; i++) {
961              // recalculate biquad parameters if cutoff or resonance differ from previous sample point              // recalculate biquad parameters if cutoff or resonance differ from previous sample point
962              if (!(i & FILTER_UPDATE_MASK)) if (pEngine->pSynthesisParameters[Event::destination_vcfr][i] != prev_res ||              if (!(i & FILTER_UPDATE_MASK)) {
963                                                 pEngine->pSynthesisParameters[Event::destination_vcfc][i] != prev_cutoff) {                  if (pEngine->pSynthesisParameters[Event::destination_vcfr][i] != prev_res ||
964                  prev_cutoff = pEngine->pSynthesisParameters[Event::destination_vcfc][i];                      pEngine->pSynthesisParameters[Event::destination_vcfc][i] != prev_cutoff)
965                  prev_res    = pEngine->pSynthesisParameters[Event::destination_vcfr][i];                  {
966                  FilterLeft.SetParameters(&bqbase, &bqmain, prev_cutoff, prev_res, pEngine->SampleRate);                      prev_cutoff = pEngine->pSynthesisParameters[Event::destination_vcfc][i];
967                        prev_res    = pEngine->pSynthesisParameters[Event::destination_vcfr][i];
968                        FilterLeft.SetParameters( &bqbase, &bqmain, prev_cutoff + FILTER_CUTOFF_MIN, prev_res, pEngine->SampleRate);
969                        FilterRight.SetParameters(&bqbase, &bqmain, prev_cutoff + FILTER_CUTOFF_MIN, prev_res, pEngine->SampleRate);
970                    }
971              }              }
972    
973              //same as 'pEngine->pBasicFilterParameters[i] = bqbase;'              //same as 'pEngine->pBasicFilterParameters[i] = bqbase;'
974              bq    = (float*) &pEngine->pBasicFilterParameters[i];              bq    = (float*) &pEngine->pBasicFilterParameters[i];
975              bq[0] = bqbase.a1;              bq[0] = bqbase.b0;
976              bq[1] = bqbase.a2;              bq[1] = bqbase.b1;
977              bq[2] = bqbase.b0;              bq[2] = bqbase.b2;
978              bq[3] = bqbase.b1;              bq[3] = bqbase.a1;
979              bq[4] = bqbase.b2;              bq[4] = bqbase.a2;
980    
981              // same as 'pEngine->pMainFilterParameters[i] = bqmain;'              // same as 'pEngine->pMainFilterParameters[i] = bqmain;'
982              bq    = (float*) &pEngine->pMainFilterParameters[i];              bq    = (float*) &pEngine->pMainFilterParameters[i];
983              bq[0] = bqmain.a1;              bq[0] = bqmain.b0;
984              bq[1] = bqmain.a2;              bq[1] = bqmain.b1;
985              bq[2] = bqmain.b0;              bq[2] = bqmain.b2;
986              bq[3] = bqmain.b1;              bq[3] = bqmain.a1;
987              bq[4] = bqmain.b2;              bq[4] = bqmain.a2;
         }  
     }  
     #endif // ENABLE_FILTER  
   
     /**  
      *  Interpolates the input audio data (without looping).  
      *  
      *  @param Samples - number of sample points to be rendered in this audio  
      *                   fragment cycle  
      *  @param pSrc    - pointer to input sample data  
      *  @param Skip    - number of sample points to skip in output buffer  
      */  
     void Voice::InterpolateNoLoop(uint Samples, sample_t* pSrc, uint Skip) {  
         int i = Skip;  
   
         // FIXME: assuming either mono or stereo  
         if (this->pSample->Channels == 2) { // Stereo Sample  
             while (i < Samples) InterpolateStereo(pSrc, i);  
         }  
         else { // Mono Sample  
             while (i < Samples) InterpolateMono(pSrc, i);  
988          }          }
989      }      }
990    
991      /**      /**
992       *  Interpolates the input audio data, this method honors looping.       *  Synthesizes the current audio fragment for this voice.
993       *       *
994       *  @param Samples - number of sample points to be rendered in this audio       *  @param Samples - number of sample points to be rendered in this audio
995       *                   fragment cycle       *                   fragment cycle
996       *  @param pSrc    - pointer to input sample data       *  @param pSrc    - pointer to input sample data
997       *  @param Skip    - number of sample points to skip in output buffer       *  @param Skip    - number of sample points to skip in output buffer
998       */       */
999      void Voice::InterpolateAndLoop(uint Samples, sample_t* pSrc, uint Skip) {      void Voice::Synthesize(uint Samples, sample_t* pSrc, uint Skip) {
1000          int i = Skip;          RunSynthesisFunction(SynthesisMode, *this, Samples, pSrc, Skip);
   
         // FIXME: assuming either mono or stereo  
         if (pSample->Channels == 2) { // Stereo Sample  
             if (pSample->LoopPlayCount) {  
                 // render loop (loop count limited)  
                 while (i < Samples && LoopCyclesLeft) {  
                     InterpolateStereo(pSrc, i);  
                     if (Pos > pSample->LoopEnd) {  
                         Pos = pSample->LoopStart + fmod(Pos - pSample->LoopEnd, pSample->LoopSize);;  
                         LoopCyclesLeft--;  
                     }  
                 }  
                 // render on without loop  
                 while (i < Samples) InterpolateStereo(pSrc, i);  
             }  
             else { // render loop (endless loop)  
                 while (i < Samples) {  
                     InterpolateStereo(pSrc, i);  
                     if (Pos > pSample->LoopEnd) {  
                         Pos = pSample->LoopStart + fmod(Pos - pSample->LoopEnd, pSample->LoopSize);  
                     }  
                 }  
             }  
         }  
         else { // Mono Sample  
             if (pSample->LoopPlayCount) {  
                 // render loop (loop count limited)  
                 while (i < Samples && LoopCyclesLeft) {  
                     InterpolateMono(pSrc, i);  
                     if (Pos > pSample->LoopEnd) {  
                         Pos = pSample->LoopStart + fmod(Pos - pSample->LoopEnd, pSample->LoopSize);;  
                         LoopCyclesLeft--;  
                     }  
                 }  
                 // render on without loop  
                 while (i < Samples) InterpolateMono(pSrc, i);  
             }  
             else { // render loop (endless loop)  
                 while (i < Samples) {  
                     InterpolateMono(pSrc, i);  
                     if (Pos > pSample->LoopEnd) {  
                         Pos = pSample->LoopStart + fmod(Pos - pSample->LoopEnd, pSample->LoopSize);;  
                     }  
                 }  
             }  
         }  
1001      }      }
1002    
1003      /**      /**

Legend:
Removed from v.287  
changed lines
  Added in v.368

  ViewVC Help
Powered by ViewVC