/[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 319 by schoenebeck, Mon Dec 13 00:46:42 2004 UTC revision 361 by schoenebeck, Wed Feb 9 01:22:18 2005 UTC
# Line 58  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))          // 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());          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    
71      Voice::~Voice() {      Voice::~Voice() {
# Line 114  namespace LinuxSampler { namespace gig { Line 119  namespace LinuxSampler { namespace gig {
119       *  @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)
120       *  @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)
121       *  @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
122       *  @returns 0 on success, a value < 0 if something failed       *  @returns 0 on success, a value < 0 if the voice wasn't triggered
123         *           (either due to an error or e.g. because no region is
124         *           defined for the given key)
125       */       */
126      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) {
127          if (!pInstrument) {          if (!pInstrument) {
# Line 135  namespace LinuxSampler { namespace gig { Line 142  namespace LinuxSampler { namespace gig {
142          itChildVoice    = Pool<Voice>::Iterator();          itChildVoice    = Pool<Voice>::Iterator();
143    
144          if (!pRegion) {          if (!pRegion) {
145              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();  
146              return -1;              return -1;
147          }          }
148    
# Line 144  namespace LinuxSampler { namespace gig { Line 150  namespace LinuxSampler { namespace gig {
150    
151          // get current dimension values to select the right dimension region          // get current dimension values to select the right dimension region
152          //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
153          uint DimValues[5] = {0,0,0,0,0};          uint DimValues[8] = { 0 };
154          for (int i = pRegion->Dimensions - 1; i >= 0; i--) {          for (int i = pRegion->Dimensions - 1; i >= 0; i--) {
155              switch (pRegion->pDimensionDefinitions[i].dimension) {              switch (pRegion->pDimensionDefinitions[i].dimension) {
156                  case ::gig::dimension_samplechannel:                  case ::gig::dimension_samplechannel:
# Line 168  namespace LinuxSampler { namespace gig { Line 174  namespace LinuxSampler { namespace gig {
174                      DimValues[i] = (uint) ReleaseTriggerVoice;                      DimValues[i] = (uint) ReleaseTriggerVoice;
175                      break;                      break;
176                  case ::gig::dimension_keyboard:                  case ::gig::dimension_keyboard:
177                      DimValues[i] = (uint) itNoteOnEvent->Param.Note.Key;                      DimValues[i] = (uint) pEngine->CurrentKeyDimension;
178                      break;                      break;
179                  case ::gig::dimension_modwheel:                  case ::gig::dimension_modwheel:
180                      DimValues[i] = pEngine->ControllerTable[1];                      DimValues[i] = pEngine->ControllerTable[1];
# Line 246  namespace LinuxSampler { namespace gig { Line 252  namespace LinuxSampler { namespace gig {
252                      std::cerr << "gig::Voice::Trigger() Error: Unknown dimension\n" << std::flush;                      std::cerr << "gig::Voice::Trigger() Error: Unknown dimension\n" << std::flush;
253              }              }
254          }          }
255          pDimRgn = pRegion->GetDimensionRegionByValue(DimValues[4],DimValues[3],DimValues[2],DimValues[1],DimValues[0]);          pDimRgn = pRegion->GetDimensionRegionByValue(DimValues);
256    
257          pSample = pDimRgn->pSample; // sample won't change until the voice is finished          pSample = pDimRgn->pSample; // sample won't change until the voice is finished
258            if (!pSample || !pSample->SamplesTotal) return -1; // no need to continue if sample is silent
259    
260          // select channel mode (mono or stereo)          // select channel mode (mono or stereo)
261          SYNTHESIS_MODE_SET_CHANNELS(SynthesisMode, pSample->Channels == 2);          SYNTHESIS_MODE_SET_CHANNELS(SynthesisMode, pSample->Channels == 2);
# Line 308  namespace LinuxSampler { namespace gig { Line 315  namespace LinuxSampler { namespace gig {
315    
316          // calculate initial pitch value          // calculate initial pitch value
317          {          {
318              double pitchbasecents = pDimRgn->FineTune * 10 + (int) pEngine->ScaleTuning[MIDIKey % 12];              double pitchbasecents = pDimRgn->FineTune + (int) pEngine->ScaleTuning[MIDIKey % 12];
319              if (pDimRgn->PitchTrack) pitchbasecents += (MIDIKey - (int) pDimRgn->UnityNote) * 100;              if (pDimRgn->PitchTrack) pitchbasecents += (MIDIKey - (int) pDimRgn->UnityNote) * 100;
320              this->PitchBase = RTMath::CentsToFreqRatio(pitchbasecents) * (double(pSample->SamplesPerSecond) / double(pEngine->pAudioOutputDevice->SampleRate()));              this->PitchBase = RTMath::CentsToFreqRatio(pitchbasecents) * (double(pSample->SamplesPerSecond) / double(pEngine->pAudioOutputDevice->SampleRate()));
321              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
# Line 693  namespace LinuxSampler { namespace gig { Line 700  namespace LinuxSampler { namespace gig {
700                          }                          }
701                          DiskStreamRef.pStream->IncrementReadPos(pSample->Channels * (int(Pos) - MaxRAMPos));                          DiskStreamRef.pStream->IncrementReadPos(pSample->Channels * (int(Pos) - MaxRAMPos));
702                          Pos -= int(Pos);                          Pos -= int(Pos);
703                            RealSampleWordsLeftToRead = -1; // -1 means no silence has been added yet
704                      }                      }
705    
706                        const int sampleWordsLeftToRead = DiskStreamRef.pStream->GetReadSpace();
707    
708                      // 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)
709                      if (DiskStreamRef.State == Stream::state_end && DiskStreamRef.pStream->GetReadSpace() < (pEngine->MaxSamplesPerCycle << MAX_PITCH) / pSample->Channels) {                      if (DiskStreamRef.State == Stream::state_end) {
710                          DiskStreamRef.pStream->WriteSilence((pEngine->MaxSamplesPerCycle << MAX_PITCH) / pSample->Channels);                          const int maxSampleWordsPerCycle = (pEngine->MaxSamplesPerCycle << MAX_PITCH) * pSample->Channels + 6; // +6 for the interpolator algorithm
711                          this->PlaybackState = playback_state_end;                          if (sampleWordsLeftToRead <= maxSampleWordsPerCycle) {
712                                // remember how many sample words there are before any silence has been added
713                                if (RealSampleWordsLeftToRead < 0) RealSampleWordsLeftToRead = sampleWordsLeftToRead;
714                                DiskStreamRef.pStream->WriteSilence(maxSampleWordsPerCycle - sampleWordsLeftToRead);
715                            }
716                      }                      }
717    
718                      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
# Line 706  namespace LinuxSampler { namespace gig { Line 720  namespace LinuxSampler { namespace gig {
720                      // render current audio fragment                      // render current audio fragment
721                      Synthesize(Samples, ptr, Delay);                      Synthesize(Samples, ptr, Delay);
722    
723                      DiskStreamRef.pStream->IncrementReadPos(int(Pos) * pSample->Channels);                      const int iPos = (int) Pos;
724                      Pos -= int(Pos);                      const int readSampleWords = iPos * pSample->Channels; // amount of sample words actually been read
725                        DiskStreamRef.pStream->IncrementReadPos(readSampleWords);
726                        Pos -= iPos; // just keep fractional part of Pos
727    
728                        // change state of voice to 'end' if we really reached the end of the sample data
729                        if (RealSampleWordsLeftToRead >= 0) {
730                            RealSampleWordsLeftToRead -= readSampleWords;
731                            if (RealSampleWordsLeftToRead <= 0) this->PlaybackState = playback_state_end;
732                        }
733                  }                  }
734                  break;                  break;
735    
# Line 926  namespace LinuxSampler { namespace gig { Line 948  namespace LinuxSampler { namespace gig {
948          float prev_cutoff = pEngine->pSynthesisParameters[Event::destination_vcfc][0];          float prev_cutoff = pEngine->pSynthesisParameters[Event::destination_vcfc][0];
949          float prev_res    = pEngine->pSynthesisParameters[Event::destination_vcfr][0];          float prev_res    = pEngine->pSynthesisParameters[Event::destination_vcfr][0];
950          FilterLeft.SetParameters(&bqbase, &bqmain, prev_cutoff, prev_res, pEngine->SampleRate);          FilterLeft.SetParameters(&bqbase, &bqmain, prev_cutoff, prev_res, pEngine->SampleRate);
951            FilterRight.SetParameters(&bqbase, &bqmain, prev_cutoff, prev_res, pEngine->SampleRate);
952          pEngine->pBasicFilterParameters[0] = bqbase;          pEngine->pBasicFilterParameters[0] = bqbase;
953          pEngine->pMainFilterParameters[0]  = bqmain;          pEngine->pMainFilterParameters[0]  = bqmain;
954    
# Line 939  namespace LinuxSampler { namespace gig { Line 962  namespace LinuxSampler { namespace gig {
962                      prev_cutoff = pEngine->pSynthesisParameters[Event::destination_vcfc][i];                      prev_cutoff = pEngine->pSynthesisParameters[Event::destination_vcfc][i];
963                      prev_res    = pEngine->pSynthesisParameters[Event::destination_vcfr][i];                      prev_res    = pEngine->pSynthesisParameters[Event::destination_vcfr][i];
964                      FilterLeft.SetParameters(&bqbase, &bqmain, prev_cutoff, prev_res, pEngine->SampleRate);                      FilterLeft.SetParameters(&bqbase, &bqmain, prev_cutoff, prev_res, pEngine->SampleRate);
965                        FilterRight.SetParameters(&bqbase, &bqmain, prev_cutoff, prev_res, pEngine->SampleRate);
966                  }                  }
967              }              }
968    
969              //same as 'pEngine->pBasicFilterParameters[i] = bqbase;'              //same as 'pEngine->pBasicFilterParameters[i] = bqbase;'
970              bq    = (float*) &pEngine->pBasicFilterParameters[i];              bq    = (float*) &pEngine->pBasicFilterParameters[i];
971              bq[0] = bqbase.a1;              bq[0] = bqbase.b0;
972              bq[1] = bqbase.a2;              bq[1] = bqbase.b1;
973              bq[2] = bqbase.b0;              bq[2] = bqbase.b2;
974              bq[3] = bqbase.b1;              bq[3] = bqbase.a1;
975              bq[4] = bqbase.b2;              bq[4] = bqbase.a2;
976    
977              // same as 'pEngine->pMainFilterParameters[i] = bqmain;'              // same as 'pEngine->pMainFilterParameters[i] = bqmain;'
978              bq    = (float*) &pEngine->pMainFilterParameters[i];              bq    = (float*) &pEngine->pMainFilterParameters[i];
979              bq[0] = bqmain.a1;              bq[0] = bqmain.b0;
980              bq[1] = bqmain.a2;              bq[1] = bqmain.b1;
981              bq[2] = bqmain.b0;              bq[2] = bqmain.b2;
982              bq[3] = bqmain.b1;              bq[3] = bqmain.a1;
983              bq[4] = bqmain.b2;              bq[4] = bqmain.a2;
984          }          }
985      }      }
986    
# Line 968  namespace LinuxSampler { namespace gig { Line 992  namespace LinuxSampler { namespace gig {
992       *  @param pSrc    - pointer to input sample data       *  @param pSrc    - pointer to input sample data
993       *  @param Skip    - number of sample points to skip in output buffer       *  @param Skip    - number of sample points to skip in output buffer
994       */       */
995      void Voice::Synthesize(uint Samples, sample_t* pSrc, int Skip) {      void Voice::Synthesize(uint Samples, sample_t* pSrc, uint Skip) {
996          UpdateSynthesisMode();          RunSynthesisFunction(SynthesisMode, *this, Samples, pSrc, Skip);
         SynthesizeFragment_Fn* f = (SynthesizeFragment_Fn*) SynthesizeFragmentFnPtr;  
         f(*this, Samples, pSrc, Skip);  
     }  
   
     /**  
      *  Determine the respective synthesis function for the given synthesis  
      *  mode.  
      */  
     void Voice::UpdateSynthesisMode() {  
         SynthesizeFragmentFnPtr = GetSynthesisFunction(SynthesisMode);  
997      }      }
998    
999      /**      /**

Legend:
Removed from v.319  
changed lines
  Added in v.361

  ViewVC Help
Powered by ViewVC