/[svn]/linuxsampler/trunk/src/voice.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/voice.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 37 by schoenebeck, Wed Mar 10 22:01:36 2004 UTC revision 38 by schoenebeck, Tue Mar 16 13:25:39 2004 UTC
# Line 147  int Voice::Trigger(ModulationSystem::Eve Line 147  int Voice::Trigger(ModulationSystem::Eve
147                  pDimRgn->EG1Release + eg1release,                  pDimRgn->EG1Release + eg1release,
148                  Delay);                  Delay);
149    
150    #if ENABLE_FILTER
151        #if FORCE_FILTER_USAGE
152        FilterLeft.Enabled = FilterRight.Enabled = true;
153        #else // use filter only if instrument file told so
154        FilterLeft.Enabled = FilterRight.Enabled = pDimRgn->VCFEnabled;
155        #endif // FORCE_FILTER_USAGE
156        if (pDimRgn->VCFEnabled) {
157            #ifdef OVERRIDE_FILTER_CUTOFF_CTRL
158            VCFCutoffCtrl.controller = OVERRIDE_FILTER_CUTOFF_CTRL;
159            #else // use the one defined in the instrument file
160            switch (pDimRgn->VCFCutoffController) {            
161                case gig::vcf_cutoff_ctrl_modwheel:
162                    VCFCutoffCtrl.controller = 1;
163                    break;
164                case gig::vcf_cutoff_ctrl_effect1:
165                    VCFCutoffCtrl.controller = 12;
166                    break;
167                case gig::vcf_cutoff_ctrl_effect2:
168                    VCFCutoffCtrl.controller = 13;
169                    break;
170                case gig::vcf_cutoff_ctrl_breath:
171                    VCFCutoffCtrl.controller = 2;
172                    break;
173                case gig::vcf_cutoff_ctrl_foot:
174                    VCFCutoffCtrl.controller = 4;
175                    break;
176                case gig::vcf_cutoff_ctrl_sustainpedal:
177                    VCFCutoffCtrl.controller = 64;
178                    break;
179                case gig::vcf_cutoff_ctrl_softpedal:
180                    VCFCutoffCtrl.controller = 67;
181                    break;
182                case gig::vcf_cutoff_ctrl_genpurpose7:
183                    VCFCutoffCtrl.controller = 82;
184                    break;
185                case gig::vcf_cutoff_ctrl_genpurpose8:
186                    VCFCutoffCtrl.controller = 83;
187                    break;
188                case gig::vcf_cutoff_ctrl_aftertouch: //TODO: not implemented yet
189                case gig::vcf_cutoff_ctrl_none:
190                default:
191                    VCFCutoffCtrl.controller = 0;
192                    break;
193            }
194            #endif // OVERRIDE_FILTER_CUTOFF_CTRL
195            
196            #ifdef OVERRIDE_FILTER_RES_CTRL
197            VCFResonanceCtrl.controller = OVERRIDE_FILTER_RES_CTRL;
198            #else // use the one defined in the instrument file
199            switch (pDimRgn->VCFResonanceController) {
200                case gig::vcf_res_ctrl_genpurpose3:
201                    VCFResonanceCtrl.controller = 18;
202                    break;
203                case gig::vcf_res_ctrl_genpurpose4:
204                    VCFResonanceCtrl.controller = 19;
205                    break;
206                case gig::vcf_res_ctrl_genpurpose5:
207                    VCFResonanceCtrl.controller = 80;
208                    break;
209                case gig::vcf_res_ctrl_genpurpose6:
210                    VCFResonanceCtrl.controller = 81;
211                    break;
212                case gig::vcf_res_ctrl_none:
213                default:
214                    VCFResonanceCtrl.controller = 0;
215            }
216            #endif // OVERRIDE_FILTER_RES_CTRL
217            
218            #ifndef OVERRIDE_FILTER_TYPE
219            FilterLeft.SetType(pDimRgn->VCFType);
220            FilterRight.SetType(pDimRgn->VCFType);
221            #else // override filter type
222            FilterLeft.SetType(OVERRIDE_FILTER_TYPE);
223            FilterRight.SetType(OVERRIDE_FILTER_TYPE);
224            #endif // OVERRIDE_FILTER_TYPE
225            
226            VCFCutoffCtrl.value    = pEngine->ControllerTable[VCFCutoffCtrl.controller];
227            VCFResonanceCtrl.value = pEngine->ControllerTable[VCFResonanceCtrl.controller];
228            
229            // calculate cutoff frequency
230            float cutoff = (!VCFCutoffCtrl.controller && pDimRgn->VCFVelocityScale)
231                ? (float) pNoteOnEvent->Velocity * pDimRgn->VCFVelocityScale * 0.31f + 20.0f // 20Hz..5kHz
232                : (float) (127 - VCFCutoffCtrl.value) * 39.4f + 20.0f;                       // 20Hz..5kHz (inverted)
233            
234            // calculate resonance
235            float resonance = (float) VCFResonanceCtrl.value * 0.00787f;   // 0.0..1.0
236            if (pDimRgn->VCFKeyboardTracking) {
237                resonance += (float) (pNoteOnEvent->Key - pDimRgn->VCFKeyboardTrackingBreakpoint) * 0.00787f;
238            }
239            Constrain(resonance, 0.0, 1.0); // correct resonance if outside allowed value range (0.0..1.0)
240            
241            FilterLeft.SetParameters(cutoff,  resonance, ModulationSystem::SampleRate());
242            FilterRight.SetParameters(cutoff, resonance, ModulationSystem::SampleRate());
243        }
244        else {
245            VCFCutoffCtrl.controller    = 0;
246            VCFResonanceCtrl.controller = 0;
247        }
248    #endif // ENABLE_FILTER
249    
250      // ************************************************      // ************************************************
251      // TODO: ARTICULATION DATA HANDLING IS MISSING HERE      // TODO: ARTICULATION DATA HANDLING IS MISSING HERE
252      // ************************************************      // ************************************************
# Line 170  void Voice::Render(uint Samples) { Line 270  void Voice::Render(uint Samples) {
270      // Reset the synthesis parameter matrix      // Reset the synthesis parameter matrix
271      ModulationSystem::ResetDestinationParameter(ModulationSystem::destination_vca, this->Volume);      ModulationSystem::ResetDestinationParameter(ModulationSystem::destination_vca, this->Volume);
272      ModulationSystem::ResetDestinationParameter(ModulationSystem::destination_vco, this->Pitch);      ModulationSystem::ResetDestinationParameter(ModulationSystem::destination_vco, this->Pitch);
273    #if ENABLE_FILTER    
274        ModulationSystem::ResetDestinationParameter(ModulationSystem::destination_vcfc, FilterLeft.Cutoff());    // intialize with last cutoff value from previous render cycle
275        ModulationSystem::ResetDestinationParameter(ModulationSystem::destination_vcfr, FilterLeft.Resonance()); // intialize with last resonance value from previous render cycle
276        
277        
278        // Reset synthesis event lists (except VCO, as VCO events apply channel wide currently)
279        pEngine->pSynthesisEvents[ModulationSystem::destination_vcfc]->clear();
280        pEngine->pSynthesisEvents[ModulationSystem::destination_vcfr]->clear();
281    #endif // ENABLE_FILTER    
282    
283    
284      // Apply events to the synthesis parameter matrix      // Apply events to the synthesis parameter matrix
285      ProcessEvents(Samples);      ProcessEvents(Samples);
286    
287    
288      // Let all modulators throw their parameter changes for the current audio fragment      // Let all modulators write their parameter changes to the synthesis parameter matrix for the current audio fragment
289      EG1.Process(Samples, pEngine->pMIDIKeyInfo[MIDIKey].pEvents, pTriggerEvent, this->Pos, this->Pitch);      EG1.Process(Samples, pEngine->pMIDIKeyInfo[MIDIKey].pEvents, pTriggerEvent, this->Pos, this->Pitch);    
290    
291    
292      switch (this->PlaybackState) {      switch (this->PlaybackState) {
# Line 259  void Voice::Reset() { Line 368  void Voice::Reset() {
368   *  @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
369   */   */
370  void Voice::ProcessEvents(uint Samples) {  void Voice::ProcessEvents(uint Samples) {
371    #if ENABLE_FILTER
372        // dispatch control change events
373        ModulationSystem::Event* pCCEvent = pEngine->pCCEvents->first();
374        while (pCCEvent) {
375            if (pCCEvent->Controller == VCFCutoffCtrl.controller) {
376                pEngine->pSynthesisEvents[ModulationSystem::destination_vcfc]->alloc_assign(*pCCEvent);
377            }
378            if (pCCEvent->Controller == VCFResonanceCtrl.controller) {
379                pEngine->pSynthesisEvents[ModulationSystem::destination_vcfr]->alloc_assign(*pCCEvent);
380            }
381    
382            pCCEvent = pEngine->pCCEvents->next();
383        }
384    #endif // ENABLE_FILTER
385    
386      // process pitch events      // process pitch events
387      RTEList<ModulationSystem::Event>* pEventList = pEngine->pSynthesisEvents[ModulationSystem::destination_vco];      RTEList<ModulationSystem::Event>* pVCOEventList = pEngine->pSynthesisEvents[ModulationSystem::destination_vco];
388      ModulationSystem::Event* pEvent = pEventList->first();;      ModulationSystem::Event* pVCOEvent = pVCOEventList->first();
389      while (pEvent) {      while (pVCOEvent) {
390          ModulationSystem::Event* pNextEvent = pEventList->next();          ModulationSystem::Event* pNextVCOEvent = pVCOEventList->next();
391    
392          // calculate the influence length of this event (in sample points)          // calculate the influence length of this event (in sample points)
393          uint duration = (pNextEvent) ? pNextEvent->FragmentPos() - pEvent->FragmentPos()          uint end = (pNextVCOEvent) ? pNextVCOEvent->FragmentPos() : Samples;
394                                       : Samples                   - pEvent->FragmentPos();                                          
395            this->Pitch += ((double) pVCOEvent->Pitch / 8192.0) / 12.0; // +- one semitone
         // calculate actual pitch value  
         switch (pEvent->Type) {  
             case ModulationSystem::event_type_pitchbend:  
                 this->Pitch += ((double) pEvent->Pitch / 8192.0) / 12.0; // +- one semitone  
                 break;  
         }  
396    
397          // apply pitch value to the pitch parameter sequence          // apply pitch value to the pitch parameter sequence
398          for (uint i = pEvent->FragmentPos(); i < duration; i++) {          for (uint i = pVCOEvent->FragmentPos(); i < end; i++) {
399              ModulationSystem::pDestinationParameter[ModulationSystem::destination_vco][i] = this->Pitch;              ModulationSystem::pDestinationParameter[ModulationSystem::destination_vco][i] = this->Pitch;
400          }          }
401    
402          pEvent = pNextEvent;          pVCOEvent = pNextVCOEvent;
403      }      }
404    
405    #if ENABLE_FILTER
406        // process filter cutoff events
407        RTEList<ModulationSystem::Event>* pCutoffEventList = pEngine->pSynthesisEvents[ModulationSystem::destination_vcfc];
408        ModulationSystem::Event* pCutoffEvent = pCutoffEventList->first();
409        while (pCutoffEvent) {
410            ModulationSystem::Event* pNextCutoffEvent = pCutoffEventList->next();
411    
412            // calculate the influence length of this event (in sample points)
413            uint end = (pNextCutoffEvent) ? pNextCutoffEvent->FragmentPos() : Samples;
414    
415            // convert absolute controller value to differential
416            int ctrldelta = pCutoffEvent->Value - VCFCutoffCtrl.value;
417            VCFCutoffCtrl.value = pCutoffEvent->Value;
418            
419            float cutoffdelta = (float) ctrldelta * -39.4f; // (20Hz)..5kHz (inverted)
420            
421            // apply cutoff frequency to the cutoff parameter sequence
422            for (uint i = pCutoffEvent->FragmentPos(); i < end; i++) {
423                ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfc][i] += cutoffdelta;
424            }
425    
426            pCutoffEvent = pNextCutoffEvent;
427        }
428        
429        // process filter resonance events
430        RTEList<ModulationSystem::Event>* pResonanceEventList = pEngine->pSynthesisEvents[ModulationSystem::destination_vcfr];
431        ModulationSystem::Event* pResonanceEvent = pResonanceEventList->first();
432        while (pResonanceEvent) {
433            ModulationSystem::Event* pNextResonanceEvent = pResonanceEventList->next();
434    
435            // calculate the influence length of this event (in sample points)
436            uint end = (pNextResonanceEvent) ? pNextResonanceEvent->FragmentPos() : Samples;
437            
438            // convert absolute controller value to differential
439            int ctrldelta = pResonanceEvent->Value - VCFResonanceCtrl.value;
440            VCFResonanceCtrl.value = pResonanceEvent->Value;
441    
442            float resonancedelta = (float) ctrldelta * 0.00787f; // 0.0..1.0
443            
444            // apply cutoff frequency to the cutoff parameter sequence
445            for (uint i = pResonanceEvent->FragmentPos(); i < end; i++) {
446                ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfr][i] += resonancedelta;
447            }
448    
449            pResonanceEvent = pNextResonanceEvent;
450        }
451    #endif // ENABLE_FILTER
452  }  }
453    
454  /**  /**
# Line 301  void Voice::Interpolate(uint Samples, sa Line 467  void Voice::Interpolate(uint Samples, sa
467          while (i < Samples) {          while (i < Samples) {
468              InterpolateOneStep_Stereo(pSrc, i,              InterpolateOneStep_Stereo(pSrc, i,
469                                        ModulationSystem::pDestinationParameter[ModulationSystem::destination_vca][i],                                        ModulationSystem::pDestinationParameter[ModulationSystem::destination_vca][i],
470                                        ModulationSystem::pDestinationParameter[ModulationSystem::destination_vco][i]);                                        ModulationSystem::pDestinationParameter[ModulationSystem::destination_vco][i],
471                                          ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfc][i],
472                                          ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfr][i]);
473          }          }
474            
475    #if ENABLE_FILTER        
476            // to save the last filter setting for the next render cycle (only needed when we update the filter not-sample-accurate)
477            ForceUpdateFilter_Stereo(ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfc][Samples - 1],
478                                     ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfr][Samples - 1]);
479    #endif // ENABLE_FILTER
480      }      }
481      else { // Mono Sample      else { // Mono Sample
482          while (i < Samples) {          while (i < Samples) {
483              InterpolateOneStep_Mono(pSrc, i,              InterpolateOneStep_Mono(pSrc, i,
484                                      ModulationSystem::pDestinationParameter[ModulationSystem::destination_vca][i],                                      ModulationSystem::pDestinationParameter[ModulationSystem::destination_vca][i],
485                                      ModulationSystem::pDestinationParameter[ModulationSystem::destination_vco][i]);                                      ModulationSystem::pDestinationParameter[ModulationSystem::destination_vco][i],
486                                        ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfc][i],
487                                        ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfr][i]);
488          }          }
489      }          
490    #if ENABLE_FILTER        
491            // to save the last filter setting for the next render cycle (only needed when we update the filter not-sample-accurate)
492            ForceUpdateFilter_Mono(ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfc][Samples - 1],
493                                   ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfr][Samples - 1]);
494    #endif // ENABLE_FILTER
495        }        
496  }  }
497    
498  /**  /**
# Line 331  void Voice::InterpolateAndLoop(uint Samp Line 513  void Voice::InterpolateAndLoop(uint Samp
513              while (i < Samples && LoopCyclesLeft) {              while (i < Samples && LoopCyclesLeft) {
514                  InterpolateOneStep_Stereo(pSrc, i,                  InterpolateOneStep_Stereo(pSrc, i,
515                                            ModulationSystem::pDestinationParameter[ModulationSystem::destination_vca][i],                                            ModulationSystem::pDestinationParameter[ModulationSystem::destination_vca][i],
516                                            ModulationSystem::pDestinationParameter[ModulationSystem::destination_vco][i]);                                            ModulationSystem::pDestinationParameter[ModulationSystem::destination_vco][i],
517                                              ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfc][i],
518                                              ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfr][i]);
519                  if (Pos > pSample->LoopEnd) {                  if (Pos > pSample->LoopEnd) {
520                      Pos = pSample->LoopStart + fmod(Pos - pSample->LoopEnd, pSample->LoopSize);;                      Pos = pSample->LoopStart + fmod(Pos - pSample->LoopEnd, pSample->LoopSize);;
521                      LoopCyclesLeft--;                      LoopCyclesLeft--;
# Line 341  void Voice::InterpolateAndLoop(uint Samp Line 525  void Voice::InterpolateAndLoop(uint Samp
525              while (i < Samples) {              while (i < Samples) {
526                  InterpolateOneStep_Stereo(pSrc, i,                  InterpolateOneStep_Stereo(pSrc, i,
527                                            ModulationSystem::pDestinationParameter[ModulationSystem::destination_vca][i],                                            ModulationSystem::pDestinationParameter[ModulationSystem::destination_vca][i],
528                                            ModulationSystem::pDestinationParameter[ModulationSystem::destination_vco][i]);                                            ModulationSystem::pDestinationParameter[ModulationSystem::destination_vco][i],
529                                              ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfc][i],
530                                              ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfr][i]);
531              }              }
532          }          }
533          else { // render loop (endless loop)          else { // render loop (endless loop)
534              while (i < Samples) {              while (i < Samples) {
535                  InterpolateOneStep_Stereo(pSrc, i,                  InterpolateOneStep_Stereo(pSrc, i,
536                                            ModulationSystem::pDestinationParameter[ModulationSystem::destination_vca][i],                                            ModulationSystem::pDestinationParameter[ModulationSystem::destination_vca][i],
537                                            ModulationSystem::pDestinationParameter[ModulationSystem::destination_vco][i]);                                            ModulationSystem::pDestinationParameter[ModulationSystem::destination_vco][i],
538                                              ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfc][i],
539                                              ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfr][i]);
540                  if (Pos > pSample->LoopEnd) {                  if (Pos > pSample->LoopEnd) {
541                      Pos = pSample->LoopStart + fmod(Pos - pSample->LoopEnd, pSample->LoopSize);                      Pos = pSample->LoopStart + fmod(Pos - pSample->LoopEnd, pSample->LoopSize);
542                  }                  }
543              }              }
544          }          }
545    #if ENABLE_FILTER        
546            // to save the last filter setting for the next render cycle (only needed when we update the filter not-sample-accurate)
547            ForceUpdateFilter_Stereo(ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfc][Samples - 1],
548                                     ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfr][Samples - 1]);
549    #endif // ENABLE_FILTER                                
550      }      }
551      else { // Mono Sample      else { // Mono Sample
552          if (pSample->LoopPlayCount) {          if (pSample->LoopPlayCount) {
# Line 361  void Voice::InterpolateAndLoop(uint Samp Line 554  void Voice::InterpolateAndLoop(uint Samp
554              while (i < Samples && LoopCyclesLeft) {              while (i < Samples && LoopCyclesLeft) {
555                  InterpolateOneStep_Mono(pSrc, i,                  InterpolateOneStep_Mono(pSrc, i,
556                                          ModulationSystem::pDestinationParameter[ModulationSystem::destination_vca][i],                                          ModulationSystem::pDestinationParameter[ModulationSystem::destination_vca][i],
557                                          ModulationSystem::pDestinationParameter[ModulationSystem::destination_vco][i]);                                          ModulationSystem::pDestinationParameter[ModulationSystem::destination_vco][i],
558                                            ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfc][i],
559                                            ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfr][i]);
560                  if (Pos > pSample->LoopEnd) {                  if (Pos > pSample->LoopEnd) {
561                      Pos = pSample->LoopStart + fmod(Pos - pSample->LoopEnd, pSample->LoopSize);;                      Pos = pSample->LoopStart + fmod(Pos - pSample->LoopEnd, pSample->LoopSize);;
562                      LoopCyclesLeft--;                      LoopCyclesLeft--;
# Line 371  void Voice::InterpolateAndLoop(uint Samp Line 566  void Voice::InterpolateAndLoop(uint Samp
566              while (i < Samples) {              while (i < Samples) {
567                  InterpolateOneStep_Mono(pSrc, i,                  InterpolateOneStep_Mono(pSrc, i,
568                                          ModulationSystem::pDestinationParameter[ModulationSystem::destination_vca][i],                                          ModulationSystem::pDestinationParameter[ModulationSystem::destination_vca][i],
569                                          ModulationSystem::pDestinationParameter[ModulationSystem::destination_vco][i]);                                          ModulationSystem::pDestinationParameter[ModulationSystem::destination_vco][i],
570                                            ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfc][i],
571                                            ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfr][i]);
572              }              }
573          }          }
574          else { // render loop (endless loop)          else { // render loop (endless loop)
575              while (i < Samples) {              while (i < Samples) {
576                  InterpolateOneStep_Mono(pSrc, i,                  InterpolateOneStep_Mono(pSrc, i,
577                                          ModulationSystem::pDestinationParameter[ModulationSystem::destination_vca][i],                                          ModulationSystem::pDestinationParameter[ModulationSystem::destination_vca][i],
578                                          ModulationSystem::pDestinationParameter[ModulationSystem::destination_vco][i]);                                          ModulationSystem::pDestinationParameter[ModulationSystem::destination_vco][i],
579                                            ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfc][i],
580                                            ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfr][i]);
581                  if (Pos > pSample->LoopEnd) {                  if (Pos > pSample->LoopEnd) {
582                      Pos = pSample->LoopStart + fmod(Pos - pSample->LoopEnd, pSample->LoopSize);;                      Pos = pSample->LoopStart + fmod(Pos - pSample->LoopEnd, pSample->LoopSize);;
583                  }                  }
584              }              }
585          }          }
586      }  #if ENABLE_FILTER        
587            // to save the last filter setting for the next render cycle (only needed when we update the filter not-sample-accurate)
588            ForceUpdateFilter_Mono(ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfc][Samples - 1],
589                                   ModulationSystem::pDestinationParameter[ModulationSystem::destination_vcfr][Samples - 1]);
590    #endif // ENABLE_FILTER                              
591        }    
592  }  }
593    
594  /**  /**

Legend:
Removed from v.37  
changed lines
  Added in v.38

  ViewVC Help
Powered by ViewVC