/[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 111 by schoenebeck, Sat Jun 5 20:55:50 2004 UTC revision 230 by schoenebeck, Thu Sep 2 21:52:29 2004 UTC
# Line 71  namespace LinuxSampler { namespace gig { Line 71  namespace LinuxSampler { namespace gig {
71          if (pVCOManipulator)  delete pVCOManipulator;          if (pVCOManipulator)  delete pVCOManipulator;
72      }      }
73    
     void Voice::SetOutput(AudioOutputDevice* pAudioOutputDevice) {  
         this->pOutputLeft        = pAudioOutputDevice->Channel(0)->Buffer();  
         this->pOutputRight       = pAudioOutputDevice->Channel(1)->Buffer();  
         this->MaxSamplesPerCycle = pAudioOutputDevice->MaxSamplesPerCycle();  
         this->SampleRate         = pAudioOutputDevice->SampleRate();  
     }  
   
74      void Voice::SetEngine(Engine* pEngine) {      void Voice::SetEngine(Engine* pEngine) {
75          this->pEngine = pEngine;          this->pEngine = pEngine;
76    
# Line 131  namespace LinuxSampler { namespace gig { Line 124  namespace LinuxSampler { namespace gig {
124          pTriggerEvent   = pNoteOnEvent;          pTriggerEvent   = pNoteOnEvent;
125    
126          if (!pRegion) {          if (!pRegion) {
127              std::cerr << "Audio Thread: No Region defined for MIDI key " << MIDIKey << std::endl << std::flush;              std::cerr << "gig::Voice: No Region defined for MIDI key " << MIDIKey << std::endl << std::flush;
128              Kill();              Kill();
129              return -1;              return -1;
130          }          }
131    
132          //TODO: current MIDI controller values are not taken into account yet          // get current dimension values to select the right dimension region
133          ::gig::DimensionRegion* pDimRgn = NULL;          //FIXME: controller values for selecting the dimension region here are currently not sample accurate
134          for (int i = pRegion->Dimensions - 1; i >= 0; i--) { // Check if instrument has a velocity split          uint DimValues[5] = {0,0,0,0,0};
135              if (pRegion->pDimensionDefinitions[i].dimension == ::gig::dimension_velocity) {          for (int i = pRegion->Dimensions - 1; i >= 0; i--) {
136                  uint DimValues[5] = {0,0,0,0,0};              switch (pRegion->pDimensionDefinitions[i].dimension) {
137                    case ::gig::dimension_samplechannel:
138                        DimValues[i] = 0; //TODO: we currently ignore this dimension
139                        break;
140                    case ::gig::dimension_layer:
141                        DimValues[i] = 0; //TODO: we currently ignore this dimension
142                        break;
143                    case ::gig::dimension_velocity:
144                      DimValues[i] = pNoteOnEvent->Velocity;                      DimValues[i] = pNoteOnEvent->Velocity;
145                  pDimRgn = pRegion->GetDimensionRegionByValue(DimValues[4],DimValues[3],DimValues[2],DimValues[1],DimValues[0]);                      break;
146                  break;                  case ::gig::dimension_channelaftertouch:
147                        DimValues[i] = 0; //TODO: we currently ignore this dimension
148                        break;
149                    case ::gig::dimension_releasetrigger:
150                        DimValues[i] = 0; //TODO: we currently ignore this dimension
151                        break;
152                    case ::gig::dimension_keyboard:
153                        DimValues[i] = (uint) pNoteOnEvent->Key;
154                        break;
155                    case ::gig::dimension_modwheel:
156                        DimValues[i] = pEngine->ControllerTable[1];
157                        break;
158                    case ::gig::dimension_breath:
159                        DimValues[i] = pEngine->ControllerTable[2];
160                        break;
161                    case ::gig::dimension_foot:
162                        DimValues[i] = pEngine->ControllerTable[4];
163                        break;
164                    case ::gig::dimension_portamentotime:
165                        DimValues[i] = pEngine->ControllerTable[5];
166                        break;
167                    case ::gig::dimension_effect1:
168                        DimValues[i] = pEngine->ControllerTable[12];
169                        break;
170                    case ::gig::dimension_effect2:
171                        DimValues[i] = pEngine->ControllerTable[13];
172                        break;
173                    case ::gig::dimension_genpurpose1:
174                        DimValues[i] = pEngine->ControllerTable[16];
175                        break;
176                    case ::gig::dimension_genpurpose2:
177                        DimValues[i] = pEngine->ControllerTable[17];
178                        break;
179                    case ::gig::dimension_genpurpose3:
180                        DimValues[i] = pEngine->ControllerTable[18];
181                        break;
182                    case ::gig::dimension_genpurpose4:
183                        DimValues[i] = pEngine->ControllerTable[19];
184                        break;
185                    case ::gig::dimension_sustainpedal:
186                        DimValues[i] = pEngine->ControllerTable[64];
187                        break;
188                    case ::gig::dimension_portamento:
189                        DimValues[i] = pEngine->ControllerTable[65];
190                        break;
191                    case ::gig::dimension_sostenutopedal:
192                        DimValues[i] = pEngine->ControllerTable[66];
193                        break;
194                    case ::gig::dimension_softpedal:
195                        DimValues[i] = pEngine->ControllerTable[67];
196                        break;
197                    case ::gig::dimension_genpurpose5:
198                        DimValues[i] = pEngine->ControllerTable[80];
199                        break;
200                    case ::gig::dimension_genpurpose6:
201                        DimValues[i] = pEngine->ControllerTable[81];
202                        break;
203                    case ::gig::dimension_genpurpose7:
204                        DimValues[i] = pEngine->ControllerTable[82];
205                        break;
206                    case ::gig::dimension_genpurpose8:
207                        DimValues[i] = pEngine->ControllerTable[83];
208                        break;
209                    case ::gig::dimension_effect1depth:
210                        DimValues[i] = pEngine->ControllerTable[91];
211                        break;
212                    case ::gig::dimension_effect2depth:
213                        DimValues[i] = pEngine->ControllerTable[92];
214                        break;
215                    case ::gig::dimension_effect3depth:
216                        DimValues[i] = pEngine->ControllerTable[93];
217                        break;
218                    case ::gig::dimension_effect4depth:
219                        DimValues[i] = pEngine->ControllerTable[94];
220                        break;
221                    case ::gig::dimension_effect5depth:
222                        DimValues[i] = pEngine->ControllerTable[95];
223                        break;
224                    case ::gig::dimension_none:
225                        std::cerr << "gig::Voice::Trigger() Error: dimension=none\n" << std::flush;
226                        break;
227                    default:
228                        std::cerr << "gig::Voice::Trigger() Error: Unknown dimension\n" << std::flush;
229              }              }
230          }          }
231          if (!pDimRgn) { // if there was no velocity split          ::gig::DimensionRegion* pDimRgn = pRegion->GetDimensionRegionByValue(DimValues[4],DimValues[3],DimValues[2],DimValues[1],DimValues[0]);
             pDimRgn = pRegion->GetDimensionRegionByValue(0,0,0,0,0);  
         }  
232    
233          pSample = pDimRgn->pSample; // sample won't change until the voice is finished          pSample = pDimRgn->pSample; // sample won't change until the voice is finished
234    
# Line 157  namespace LinuxSampler { namespace gig { Line 237  namespace LinuxSampler { namespace gig {
237          DiskVoice          = cachedsamples < pSample->SamplesTotal;          DiskVoice          = cachedsamples < pSample->SamplesTotal;
238    
239          if (DiskVoice) { // voice to be streamed from disk          if (DiskVoice) { // voice to be streamed from disk
240              MaxRAMPos = cachedsamples - (MaxSamplesPerCycle << MAX_PITCH) / pSample->Channels; //TODO: this calculation is too pessimistic and may better be moved to Render() method, so it calculates MaxRAMPos dependent to the current demand of sample points to be rendered (e.g. in case of JACK)              MaxRAMPos = cachedsamples - (pEngine->MaxSamplesPerCycle << MAX_PITCH) / pSample->Channels; //TODO: this calculation is too pessimistic and may better be moved to Render() method, so it calculates MaxRAMPos dependent to the current demand of sample points to be rendered (e.g. in case of JACK)
241    
242              // check if there's a loop defined which completely fits into the cached (RAM) part of the sample              // check if there's a loop defined which completely fits into the cached (RAM) part of the sample
243              if (pSample->Loops && pSample->LoopEnd <= MaxRAMPos) {              if (pSample->Loops && pSample->LoopEnd <= MaxRAMPos) {
# Line 314  namespace LinuxSampler { namespace gig { Line 394  namespace LinuxSampler { namespace gig {
394                            pDimRgn->LFO1ControlDepth,                            pDimRgn->LFO1ControlDepth,
395                            pEngine->ControllerTable[pLFO1->ExtController],                            pEngine->ControllerTable[pLFO1->ExtController],
396                            pDimRgn->LFO1FlipPhase,                            pDimRgn->LFO1FlipPhase,
397                            this->SampleRate,                            pEngine->SampleRate,
398                            Delay);                            Delay);
399          }          }
400    
# Line 352  namespace LinuxSampler { namespace gig { Line 432  namespace LinuxSampler { namespace gig {
432                            pDimRgn->LFO2ControlDepth,                            pDimRgn->LFO2ControlDepth,
433                            pEngine->ControllerTable[pLFO2->ExtController],                            pEngine->ControllerTable[pLFO2->ExtController],
434                            pDimRgn->LFO2FlipPhase,                            pDimRgn->LFO2FlipPhase,
435                            this->SampleRate,                            pEngine->SampleRate,
436                            Delay);                            Delay);
437          }          }
438      #endif // ENABLE_FILTER      #endif // ENABLE_FILTER
# Line 390  namespace LinuxSampler { namespace gig { Line 470  namespace LinuxSampler { namespace gig {
470                            pDimRgn->LFO3ControlDepth,                            pDimRgn->LFO3ControlDepth,
471                            pEngine->ControllerTable[pLFO3->ExtController],                            pEngine->ControllerTable[pLFO3->ExtController],
472                            false,                            false,
473                            this->SampleRate,                            pEngine->SampleRate,
474                            Delay);                            Delay);
475          }          }
476    
# Line 488  namespace LinuxSampler { namespace gig { Line 568  namespace LinuxSampler { namespace gig {
568              VCFCutoffCtrl.fvalue    = cutoff - FILTER_CUTOFF_MIN;              VCFCutoffCtrl.fvalue    = cutoff - FILTER_CUTOFF_MIN;
569              VCFResonanceCtrl.fvalue = resonance;              VCFResonanceCtrl.fvalue = resonance;
570    
571              FilterLeft.SetParameters(cutoff,  resonance, SampleRate);              FilterLeft.SetParameters(cutoff,  resonance, pEngine->SampleRate);
572              FilterRight.SetParameters(cutoff, resonance, SampleRate);              FilterRight.SetParameters(cutoff, resonance, pEngine->SampleRate);
573    
574              FilterUpdateCounter = -1;              FilterUpdateCounter = -1;
575          }          }
# Line 582  namespace LinuxSampler { namespace gig { Line 662  namespace LinuxSampler { namespace gig {
662                      }                      }
663    
664                      // 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)
665                      if (DiskStreamRef.State == Stream::state_end && DiskStreamRef.pStream->GetReadSpace() < (MaxSamplesPerCycle << MAX_PITCH) / pSample->Channels) {                      if (DiskStreamRef.State == Stream::state_end && DiskStreamRef.pStream->GetReadSpace() < (pEngine->MaxSamplesPerCycle << MAX_PITCH) / pSample->Channels) {
666                          DiskStreamRef.pStream->WriteSilence((MaxSamplesPerCycle << MAX_PITCH) / pSample->Channels);                          DiskStreamRef.pStream->WriteSilence((pEngine->MaxSamplesPerCycle << MAX_PITCH) / pSample->Channels);
667                          this->PlaybackState = playback_state_end;                          this->PlaybackState = playback_state_end;
668                      }                      }
669    
# Line 776  namespace LinuxSampler { namespace gig { Line 856  namespace LinuxSampler { namespace gig {
856          biquad_param_t bqmain;          biquad_param_t bqmain;
857          float prev_cutoff = pEngine->pSynthesisParameters[Event::destination_vcfc][0];          float prev_cutoff = pEngine->pSynthesisParameters[Event::destination_vcfc][0];
858          float prev_res    = pEngine->pSynthesisParameters[Event::destination_vcfr][0];          float prev_res    = pEngine->pSynthesisParameters[Event::destination_vcfr][0];
859          FilterLeft.SetParameters(&bqbase, &bqmain, prev_cutoff, prev_res, SampleRate);          FilterLeft.SetParameters(&bqbase, &bqmain, prev_cutoff, prev_res, pEngine->SampleRate);
860          pEngine->pBasicFilterParameters[0] = bqbase;          pEngine->pBasicFilterParameters[0] = bqbase;
861          pEngine->pMainFilterParameters[0]  = bqmain;          pEngine->pMainFilterParameters[0]  = bqmain;
862    
# Line 787  namespace LinuxSampler { namespace gig { Line 867  namespace LinuxSampler { namespace gig {
867                                                 pEngine->pSynthesisParameters[Event::destination_vcfc][i] != prev_cutoff) {                                                 pEngine->pSynthesisParameters[Event::destination_vcfc][i] != prev_cutoff) {
868                  prev_cutoff = pEngine->pSynthesisParameters[Event::destination_vcfc][i];                  prev_cutoff = pEngine->pSynthesisParameters[Event::destination_vcfc][i];
869                  prev_res    = pEngine->pSynthesisParameters[Event::destination_vcfr][i];                  prev_res    = pEngine->pSynthesisParameters[Event::destination_vcfr][i];
870                  FilterLeft.SetParameters(&bqbase, &bqmain, prev_cutoff, prev_res, SampleRate);                  FilterLeft.SetParameters(&bqbase, &bqmain, prev_cutoff, prev_res, pEngine->SampleRate);
871              }              }
872    
873              //same as 'pEngine->pBasicFilterParameters[i] = bqbase;'              //same as 'pEngine->pBasicFilterParameters[i] = bqbase;'

Legend:
Removed from v.111  
changed lines
  Added in v.230

  ViewVC Help
Powered by ViewVC