/[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 325 by senkov, Tue Dec 21 04:54:37 2004 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    
62            // select synthesis implementation (currently either pure C++ or MMX+SSE(1))
63            SYNTHESIS_MODE_SET_IMPLEMENTATION(SynthesisMode, Features::supportsMMX() && Features::supportsSSE());
64            SYNTHESIS_MODE_SET_PROFILING(SynthesisMode, true);
65      }      }
66    
67      Voice::~Voice() {      Voice::~Voice() {
# Line 116  namespace LinuxSampler { namespace gig { Line 122  namespace LinuxSampler { namespace gig {
122             dmsg(1,("voice::trigger: !pInstrument\n"));             dmsg(1,("voice::trigger: !pInstrument\n"));
123             exit(EXIT_FAILURE);             exit(EXIT_FAILURE);
124          }          }
125            if (itNoteOnEvent->FragmentPos() > pEngine->MaxSamplesPerCycle) { // FIXME: should be removed before the final release (purpose: just a sanity check for debugging)
126                dmsg(1,("Voice::Trigger(): ERROR, TriggerDelay > Totalsamples\n"));
127            }
128    
129          Type            = type_normal;          Type            = type_normal;
130          MIDIKey         = itNoteOnEvent->Param.Note.Key;          MIDIKey         = itNoteOnEvent->Param.Note.Key;
# Line 240  namespace LinuxSampler { namespace gig { Line 249  namespace LinuxSampler { namespace gig {
249          }          }
250          pDimRgn = pRegion->GetDimensionRegionByValue(DimValues[4],DimValues[3],DimValues[2],DimValues[1],DimValues[0]);          pDimRgn = pRegion->GetDimensionRegionByValue(DimValues[4],DimValues[3],DimValues[2],DimValues[1],DimValues[0]);
251    
252            pSample = pDimRgn->pSample; // sample won't change until the voice is finished
253    
254            // select channel mode (mono or stereo)
255            SYNTHESIS_MODE_SET_CHANNELS(SynthesisMode, pSample->Channels == 2);
256    
257          // get starting crossfade volume level          // get starting crossfade volume level
258          switch (pDimRgn->AttenuationController.type) {          switch (pDimRgn->AttenuationController.type) {
259              case ::gig::attenuation_ctrl_t::type_channelaftertouch:              case ::gig::attenuation_ctrl_t::type_channelaftertouch:
# Line 259  namespace LinuxSampler { namespace gig { Line 273  namespace LinuxSampler { namespace gig {
273          PanLeft  = 1.0f - float(RTMath::Max(pDimRgn->Pan, 0)) /  63.0f;          PanLeft  = 1.0f - float(RTMath::Max(pDimRgn->Pan, 0)) /  63.0f;
274          PanRight = 1.0f - float(RTMath::Min(pDimRgn->Pan, 0)) / -64.0f;          PanRight = 1.0f - float(RTMath::Min(pDimRgn->Pan, 0)) / -64.0f;
275    
         pSample = pDimRgn->pSample; // sample won't change until the voice is finished  
   
276          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)
277    
278          // 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 303  namespace LinuxSampler { namespace gig { Line 315  namespace LinuxSampler { namespace gig {
315              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
316          }          }
317    
   
318          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)
319    
   
320          // setup EG 1 (VCA EG)          // setup EG 1 (VCA EG)
321          {          {
322              // get current value of EG1 controller              // get current value of EG1 controller
# Line 345  namespace LinuxSampler { namespace gig { Line 355  namespace LinuxSampler { namespace gig {
355          }          }
356    
357    
     #if ENABLE_FILTER  
358          // setup EG 2 (VCF Cutoff EG)          // setup EG 2 (VCF Cutoff EG)
359          {          {
360              // get current value of EG2 controller              // get current value of EG2 controller
# Line 382  namespace LinuxSampler { namespace gig { Line 391  namespace LinuxSampler { namespace gig {
391                            pDimRgn->EG2Release + eg2release,                            pDimRgn->EG2Release + eg2release,
392                            Delay);                            Delay);
393          }          }
     #endif // ENABLE_FILTER  
394    
395    
396          // setup EG 3 (VCO EG)          // setup EG 3 (VCO EG)
# Line 429  namespace LinuxSampler { namespace gig { Line 437  namespace LinuxSampler { namespace gig {
437                            Delay);                            Delay);
438          }          }
439    
440      #if ENABLE_FILTER  
441          // setup LFO 2 (VCF Cutoff LFO)          // setup LFO 2 (VCF Cutoff LFO)
442          {          {
443              uint16_t lfo2_internal_depth;              uint16_t lfo2_internal_depth;
# Line 466  namespace LinuxSampler { namespace gig { Line 474  namespace LinuxSampler { namespace gig {
474                            pEngine->SampleRate,                            pEngine->SampleRate,
475                            Delay);                            Delay);
476          }          }
477      #endif // ENABLE_FILTER  
478    
479          // setup LFO 3 (VCO LFO)          // setup LFO 3 (VCO LFO)
480          {          {
# Line 505  namespace LinuxSampler { namespace gig { Line 513  namespace LinuxSampler { namespace gig {
513                            Delay);                            Delay);
514          }          }
515    
516      #if ENABLE_FILTER  
517          #if FORCE_FILTER_USAGE          #if FORCE_FILTER_USAGE
518          FilterLeft.Enabled = FilterRight.Enabled = true;          SYNTHESIS_MODE_SET_FILTER(SynthesisMode, true);
519          #else // use filter only if instrument file told so          #else // use filter only if instrument file told so
520          FilterLeft.Enabled = FilterRight.Enabled = pDimRgn->VCFEnabled;          SYNTHESIS_MODE_SET_FILTER(SynthesisMode, pDimRgn->VCFEnabled);
521          #endif // FORCE_FILTER_USAGE          #endif // FORCE_FILTER_USAGE
522          if (pDimRgn->VCFEnabled) {          if (pDimRgn->VCFEnabled) {
523              #ifdef OVERRIDE_FILTER_CUTOFF_CTRL              #ifdef OVERRIDE_FILTER_CUTOFF_CTRL
# Line 599  namespace LinuxSampler { namespace gig { Line 607  namespace LinuxSampler { namespace gig {
607              VCFCutoffCtrl.fvalue    = cutoff - FILTER_CUTOFF_MIN;              VCFCutoffCtrl.fvalue    = cutoff - FILTER_CUTOFF_MIN;
608              VCFResonanceCtrl.fvalue = resonance;              VCFResonanceCtrl.fvalue = resonance;
609    
             FilterLeft.SetParameters(cutoff,  resonance, pEngine->SampleRate);  
             FilterRight.SetParameters(cutoff, resonance, pEngine->SampleRate);  
   
610              FilterUpdateCounter = -1;              FilterUpdateCounter = -1;
611          }          }
612          else {          else {
613              VCFCutoffCtrl.controller    = 0;              VCFCutoffCtrl.controller    = 0;
614              VCFResonanceCtrl.controller = 0;              VCFResonanceCtrl.controller = 0;
615          }          }
     #endif // ENABLE_FILTER  
616    
617          return 0; // success          return 0; // success
618      }      }
# Line 626  namespace LinuxSampler { namespace gig { Line 630  namespace LinuxSampler { namespace gig {
630       */       */
631      void Voice::Render(uint Samples) {      void Voice::Render(uint Samples) {
632    
633            // select default values for synthesis mode bits
634            SYNTHESIS_MODE_SET_INTERPOLATE(SynthesisMode, (PitchBase * PitchBend) != 1.0f);
635            SYNTHESIS_MODE_SET_CONSTPITCH(SynthesisMode, true);
636            SYNTHESIS_MODE_SET_LOOP(SynthesisMode, false);
637    
638          // Reset the synthesis parameter matrix          // Reset the synthesis parameter matrix
639    
640          pEngine->ResetSynthesisParameters(Event::destination_vca, this->Volume * this->CrossfadeVolume * pEngine->GlobalVolume);          pEngine->ResetSynthesisParameters(Event::destination_vca, this->Volume * this->CrossfadeVolume * pEngine->GlobalVolume);
641          pEngine->ResetSynthesisParameters(Event::destination_vco, this->PitchBase);          pEngine->ResetSynthesisParameters(Event::destination_vco, this->PitchBase);
     #if ENABLE_FILTER  
642          pEngine->ResetSynthesisParameters(Event::destination_vcfc, VCFCutoffCtrl.fvalue);          pEngine->ResetSynthesisParameters(Event::destination_vcfc, VCFCutoffCtrl.fvalue);
643          pEngine->ResetSynthesisParameters(Event::destination_vcfr, VCFResonanceCtrl.fvalue);          pEngine->ResetSynthesisParameters(Event::destination_vcfr, VCFResonanceCtrl.fvalue);
     #endif // ENABLE_FILTER  
   
644    
645          // Apply events to the synthesis parameter matrix          // Apply events to the synthesis parameter matrix
646          ProcessEvents(Samples);          ProcessEvents(Samples);
647    
   
648          // 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
649          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  
650          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);
651      #endif // ENABLE_FILTER          if (pEG3->Process(Samples)) { // if pitch EG is active
652          pEG3->Process(Samples);              SYNTHESIS_MODE_SET_INTERPOLATE(SynthesisMode, true);
653                SYNTHESIS_MODE_SET_CONSTPITCH(SynthesisMode, false);
654            }
655          pLFO1->Process(Samples);          pLFO1->Process(Samples);
     #if ENABLE_FILTER  
656          pLFO2->Process(Samples);          pLFO2->Process(Samples);
657      #endif // ENABLE_FILTER          if (pLFO3->Process(Samples)) { // if pitch LFO modulation is active
658          pLFO3->Process(Samples);              SYNTHESIS_MODE_SET_INTERPOLATE(SynthesisMode, true);
659                SYNTHESIS_MODE_SET_CONSTPITCH(SynthesisMode, false);
660            }
     #if ENABLE_FILTER  
         CalculateBiquadParameters(Samples); // calculate the final biquad filter parameters  
     #endif // ENABLE_FILTER  
661    
662            if (SYNTHESIS_MODE_GET_FILTER(SynthesisMode))
663                    CalculateBiquadParameters(Samples); // calculate the final biquad filter parameters
664    
665          switch (this->PlaybackState) {          switch (this->PlaybackState) {
666    
667              case playback_state_ram: {              case playback_state_ram: {
668                      if (RAMLoop) InterpolateAndLoop(Samples, (sample_t*) pSample->GetCache().pStart, Delay);                      if (RAMLoop) SYNTHESIS_MODE_SET_LOOP(SynthesisMode, true); // enable looping
669                      else         InterpolateNoLoop(Samples, (sample_t*) pSample->GetCache().pStart, Delay);  
670                        // render current fragment
671                        Synthesize(Samples, (sample_t*) pSample->GetCache().pStart, Delay);
672    
673                      if (DiskVoice) {                      if (DiskVoice) {
674                          // check if we reached the allowed limit of the sample RAM cache                          // check if we reached the allowed limit of the sample RAM cache
675                          if (Pos > MaxRAMPos) {                          if (Pos > MaxRAMPos) {
# Line 684  namespace LinuxSampler { namespace gig { Line 692  namespace LinuxSampler { namespace gig {
692                              KillImmediately();                              KillImmediately();
693                              return;                              return;
694                          }                          }
695                          DiskStreamRef.pStream->IncrementReadPos(pSample->Channels * (RTMath::DoubleToInt(Pos) - MaxRAMPos));                          DiskStreamRef.pStream->IncrementReadPos(pSample->Channels * (int(Pos) - MaxRAMPos));
696                          Pos -= RTMath::DoubleToInt(Pos);                          Pos -= int(Pos);
697                      }                      }
698    
699                        const int sampleWordsLeftToRead = DiskStreamRef.pStream->GetReadSpace();
700    
701                      // 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)
702                      if (DiskStreamRef.State == Stream::state_end && DiskStreamRef.pStream->GetReadSpace() < (pEngine->MaxSamplesPerCycle << MAX_PITCH) / pSample->Channels) {                      if (DiskStreamRef.State == Stream::state_end) {
703                          DiskStreamRef.pStream->WriteSilence((pEngine->MaxSamplesPerCycle << MAX_PITCH) / pSample->Channels);                          const int maxSampleWordsPerCycle = (pEngine->MaxSamplesPerCycle << MAX_PITCH) * pSample->Channels + 6; // +6 for the interpolator algorithm
704                          this->PlaybackState = playback_state_end;                          if (sampleWordsLeftToRead <= maxSampleWordsPerCycle) {
705                                DiskStreamRef.pStream->WriteSilence(maxSampleWordsPerCycle - sampleWordsLeftToRead);
706                            }
707                      }                      }
708    
709                      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
710                      InterpolateNoLoop(Samples, ptr, Delay);  
711                      DiskStreamRef.pStream->IncrementReadPos(RTMath::DoubleToInt(Pos) * pSample->Channels);                      // render current audio fragment
712                      Pos -= RTMath::DoubleToInt(Pos);                      Synthesize(Samples, ptr, Delay);
713    
714                        const int iPos = (int) Pos;
715                        const int readSampleWords = iPos * pSample->Channels; // amount of sample words actually been read
716                        DiskStreamRef.pStream->IncrementReadPos(readSampleWords);
717                        Pos -= iPos; // just keep fractional part of Pos
718    
719                        // change state of voice to 'end' if we really reached the end of the sample data
720                        if (DiskStreamRef.State == Stream::state_end && readSampleWords >= sampleWordsLeftToRead) this->PlaybackState = playback_state_end;
721                  }                  }
722                  break;                  break;
723    
# Line 706  namespace LinuxSampler { namespace gig { Line 726  namespace LinuxSampler { namespace gig {
726                  break;                  break;
727          }          }
728    
   
729          // 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)
730          pEngine->pSynthesisEvents[Event::destination_vca]->clear();          pEngine->pSynthesisEvents[Event::destination_vca]->clear();
     #if ENABLE_FILTER  
731          pEngine->pSynthesisEvents[Event::destination_vcfc]->clear();          pEngine->pSynthesisEvents[Event::destination_vcfc]->clear();
732          pEngine->pSynthesisEvents[Event::destination_vcfr]->clear();          pEngine->pSynthesisEvents[Event::destination_vcfr]->clear();
     #endif // ENABLE_FILTER  
733    
734          // Reset delay          // Reset delay
735          Delay = 0;          Delay = 0;
# Line 731  namespace LinuxSampler { namespace gig { Line 748  namespace LinuxSampler { namespace gig {
748          pLFO1->Reset();          pLFO1->Reset();
749          pLFO2->Reset();          pLFO2->Reset();
750          pLFO3->Reset();          pLFO3->Reset();
751            FilterLeft.Reset();
752            FilterRight.Reset();
753          DiskStreamRef.pStream = NULL;          DiskStreamRef.pStream = NULL;
754          DiskStreamRef.hStream = 0;          DiskStreamRef.hStream = 0;
755          DiskStreamRef.State   = Stream::state_unused;          DiskStreamRef.State   = Stream::state_unused;
# Line 756  namespace LinuxSampler { namespace gig { Line 775  namespace LinuxSampler { namespace gig {
775          }          }
776          while (itCCEvent) {          while (itCCEvent) {
777              if (itCCEvent->Param.CC.Controller) { // if valid MIDI controller              if (itCCEvent->Param.CC.Controller) { // if valid MIDI controller
                 #if ENABLE_FILTER  
778                  if (itCCEvent->Param.CC.Controller == VCFCutoffCtrl.controller) {                  if (itCCEvent->Param.CC.Controller == VCFCutoffCtrl.controller) {
779                      *pEngine->pSynthesisEvents[Event::destination_vcfc]->allocAppend() = *itCCEvent;                      *pEngine->pSynthesisEvents[Event::destination_vcfc]->allocAppend() = *itCCEvent;
780                  }                  }
781                  if (itCCEvent->Param.CC.Controller == VCFResonanceCtrl.controller) {                  if (itCCEvent->Param.CC.Controller == VCFResonanceCtrl.controller) {
782                      *pEngine->pSynthesisEvents[Event::destination_vcfr]->allocAppend() = *itCCEvent;                      *pEngine->pSynthesisEvents[Event::destination_vcfr]->allocAppend() = *itCCEvent;
783                  }                  }
                 #endif // ENABLE_FILTER  
784                  if (itCCEvent->Param.CC.Controller == pLFO1->ExtController) {                  if (itCCEvent->Param.CC.Controller == pLFO1->ExtController) {
785                      pLFO1->SendEvent(itCCEvent);                      pLFO1->SendEvent(itCCEvent);
786                  }                  }
                 #if ENABLE_FILTER  
787                  if (itCCEvent->Param.CC.Controller == pLFO2->ExtController) {                  if (itCCEvent->Param.CC.Controller == pLFO2->ExtController) {
788                      pLFO2->SendEvent(itCCEvent);                      pLFO2->SendEvent(itCCEvent);
789                  }                  }
                 #endif // ENABLE_FILTER  
790                  if (itCCEvent->Param.CC.Controller == pLFO3->ExtController) {                  if (itCCEvent->Param.CC.Controller == pLFO3->ExtController) {
791                      pLFO3->SendEvent(itCCEvent);                      pLFO3->SendEvent(itCCEvent);
792                  }                  }
# Line 816  namespace LinuxSampler { namespace gig { Line 831  namespace LinuxSampler { namespace gig {
831    
832                  itVCOEvent = itNextVCOEvent;                  itVCOEvent = itNextVCOEvent;
833              }              }
834              if (!pVCOEventList->isEmpty()) this->PitchBend = pitch;              if (!pVCOEventList->isEmpty()) {
835                    this->PitchBend = pitch;
836                    SYNTHESIS_MODE_SET_INTERPOLATE(SynthesisMode, true);
837                    SYNTHESIS_MODE_SET_CONSTPITCH(SynthesisMode, false);
838                }
839          }          }
840    
841          // 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 867  namespace LinuxSampler { namespace gig {
867              if (!pVCAEventList->isEmpty()) this->CrossfadeVolume = crossfadevolume;              if (!pVCAEventList->isEmpty()) this->CrossfadeVolume = crossfadevolume;
868          }          }
869    
     #if ENABLE_FILTER  
870          // process filter cutoff events          // process filter cutoff events
871          {          {
872              RTList<Event>* pCutoffEventList = pEngine->pSynthesisEvents[Event::destination_vcfc];              RTList<Event>* pCutoffEventList = pEngine->pSynthesisEvents[Event::destination_vcfc];
# Line 905  namespace LinuxSampler { namespace gig { Line 923  namespace LinuxSampler { namespace gig {
923              }              }
924              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
925          }          }
     #endif // ENABLE_FILTER  
926      }      }
927    
     #if ENABLE_FILTER  
928      /**      /**
929       * Calculate all necessary, final biquad filter parameters.       * Calculate all necessary, final biquad filter parameters.
930       *       *
931       * @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
932       */       */
933      void Voice::CalculateBiquadParameters(uint Samples) {      void Voice::CalculateBiquadParameters(uint Samples) {
         if (!FilterLeft.Enabled) return;  
   
934          biquad_param_t bqbase;          biquad_param_t bqbase;
935          biquad_param_t bqmain;          biquad_param_t bqmain;
936          float prev_cutoff = pEngine->pSynthesisParameters[Event::destination_vcfc][0];          float prev_cutoff = pEngine->pSynthesisParameters[Event::destination_vcfc][0];
937          float prev_res    = pEngine->pSynthesisParameters[Event::destination_vcfr][0];          float prev_res    = pEngine->pSynthesisParameters[Event::destination_vcfr][0];
938          FilterLeft.SetParameters(&bqbase, &bqmain, prev_cutoff, prev_res, pEngine->SampleRate);          FilterLeft.SetParameters(&bqbase, &bqmain, prev_cutoff, prev_res, pEngine->SampleRate);
939            FilterRight.SetParameters(&bqbase, &bqmain, prev_cutoff, prev_res, pEngine->SampleRate);
940          pEngine->pBasicFilterParameters[0] = bqbase;          pEngine->pBasicFilterParameters[0] = bqbase;
941          pEngine->pMainFilterParameters[0]  = bqmain;          pEngine->pMainFilterParameters[0]  = bqmain;
942    
943          float* bq;          float* bq;
944          for (int i = 1; i < Samples; i++) {          for (int i = 1; i < Samples; i++) {
945              // recalculate biquad parameters if cutoff or resonance differ from previous sample point              // recalculate biquad parameters if cutoff or resonance differ from previous sample point
946              if (!(i & FILTER_UPDATE_MASK)) if (pEngine->pSynthesisParameters[Event::destination_vcfr][i] != prev_res ||              if (!(i & FILTER_UPDATE_MASK)) {
947                                                 pEngine->pSynthesisParameters[Event::destination_vcfc][i] != prev_cutoff) {                  if (pEngine->pSynthesisParameters[Event::destination_vcfr][i] != prev_res ||
948                  prev_cutoff = pEngine->pSynthesisParameters[Event::destination_vcfc][i];                      pEngine->pSynthesisParameters[Event::destination_vcfc][i] != prev_cutoff)
949                  prev_res    = pEngine->pSynthesisParameters[Event::destination_vcfr][i];                  {
950                  FilterLeft.SetParameters(&bqbase, &bqmain, prev_cutoff, prev_res, pEngine->SampleRate);                      prev_cutoff = pEngine->pSynthesisParameters[Event::destination_vcfc][i];
951                        prev_res    = pEngine->pSynthesisParameters[Event::destination_vcfr][i];
952                        FilterLeft.SetParameters(&bqbase, &bqmain, prev_cutoff, prev_res, pEngine->SampleRate);
953                        FilterRight.SetParameters(&bqbase, &bqmain, prev_cutoff, prev_res, pEngine->SampleRate);
954                    }
955              }              }
956    
957              //same as 'pEngine->pBasicFilterParameters[i] = bqbase;'              //same as 'pEngine->pBasicFilterParameters[i] = bqbase;'
958              bq    = (float*) &pEngine->pBasicFilterParameters[i];              bq    = (float*) &pEngine->pBasicFilterParameters[i];
959              bq[0] = bqbase.a1;              bq[0] = bqbase.b0;
960              bq[1] = bqbase.a2;              bq[1] = bqbase.b1;
961              bq[2] = bqbase.b0;              bq[2] = bqbase.b2;
962              bq[3] = bqbase.b1;              bq[3] = bqbase.a1;
963              bq[4] = bqbase.b2;              bq[4] = bqbase.a2;
964    
965              // same as 'pEngine->pMainFilterParameters[i] = bqmain;'              // same as 'pEngine->pMainFilterParameters[i] = bqmain;'
966              bq    = (float*) &pEngine->pMainFilterParameters[i];              bq    = (float*) &pEngine->pMainFilterParameters[i];
967              bq[0] = bqmain.a1;              bq[0] = bqmain.b0;
968              bq[1] = bqmain.a2;              bq[1] = bqmain.b1;
969              bq[2] = bqmain.b0;              bq[2] = bqmain.b2;
970              bq[3] = bqmain.b1;              bq[3] = bqmain.a1;
971              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);  
972          }          }
973      }      }
974    
975      /**      /**
976       *  Interpolates the input audio data, this method honors looping.       *  Synthesizes the current audio fragment for this voice.
977       *       *
978       *  @param Samples - number of sample points to be rendered in this audio       *  @param Samples - number of sample points to be rendered in this audio
979       *                   fragment cycle       *                   fragment cycle
980       *  @param pSrc    - pointer to input sample data       *  @param pSrc    - pointer to input sample data
981       *  @param Skip    - number of sample points to skip in output buffer       *  @param Skip    - number of sample points to skip in output buffer
982       */       */
983      void Voice::InterpolateAndLoop(uint Samples, sample_t* pSrc, uint Skip) {      void Voice::Synthesize(uint Samples, sample_t* pSrc, uint Skip) {
984          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);;  
                     }  
                 }  
             }  
         }  
985      }      }
986    
987      /**      /**

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

  ViewVC Help
Powered by ViewVC