/[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 832 by persson, Sun Feb 5 10:24:05 2006 UTC revision 877 by persson, Sun Jun 25 13:54:17 2006 UTC
# Line 29  Line 29 
29    
30  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
31    
     const float Voice::FILTER_CUTOFF_COEFF(CalculateFilterCutoffCoeff());  
   
     float Voice::CalculateFilterCutoffCoeff() {  
         return log(CONFIG_FILTER_CUTOFF_MAX / CONFIG_FILTER_CUTOFF_MIN);  
     }  
   
32      Voice::Voice() {      Voice::Voice() {
33          pEngine     = NULL;          pEngine     = NULL;
34          pDiskThread = NULL;          pDiskThread = NULL;
# Line 153  namespace LinuxSampler { namespace gig { Line 147  namespace LinuxSampler { namespace gig {
147          long cachedsamples = pSample->GetCache().Size / pSample->FrameSize;          long cachedsamples = pSample->GetCache().Size / pSample->FrameSize;
148          DiskVoice          = cachedsamples < pSample->SamplesTotal;          DiskVoice          = cachedsamples < pSample->SamplesTotal;
149    
150            const DLS::sample_loop_t& loopinfo = pDimRgn->pSampleLoops[0];
151    
152          if (DiskVoice) { // voice to be streamed from disk          if (DiskVoice) { // voice to be streamed from disk
153              MaxRAMPos = cachedsamples - (pEngine->MaxSamplesPerCycle << CONFIG_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 << CONFIG_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)
154    
155              // 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
156              RAMLoop = (pSample->Loops && pSample->LoopEnd <= MaxRAMPos);              RAMLoop = (pDimRgn->SampleLoops && (loopinfo.LoopStart + loopinfo.LoopLength) <= MaxRAMPos);
157    
158              if (pDiskThread->OrderNewStream(&DiskStreamRef, pSample, MaxRAMPos, !RAMLoop) < 0) {              if (pDiskThread->OrderNewStream(&DiskStreamRef, pDimRgn, MaxRAMPos, !RAMLoop) < 0) {
159                  dmsg(1,("Disk stream order failed!\n"));                  dmsg(1,("Disk stream order failed!\n"));
160                  KillImmediately();                  KillImmediately();
161                  return -1;                  return -1;
# Line 168  namespace LinuxSampler { namespace gig { Line 164  namespace LinuxSampler { namespace gig {
164          }          }
165          else { // RAM only voice          else { // RAM only voice
166              MaxRAMPos = cachedsamples;              MaxRAMPos = cachedsamples;
167              RAMLoop = (pSample->Loops != 0);              RAMLoop = (pDimRgn->SampleLoops != 0);
168              dmsg(4,("RAM only voice launched (Looping: %s)\n", (RAMLoop) ? "yes" : "no"));              dmsg(4,("RAM only voice launched (Looping: %s)\n", (RAMLoop) ? "yes" : "no"));
169          }          }
170          if (RAMLoop) {          if (RAMLoop) {
171              loop.uiTotalCycles = pSample->LoopPlayCount;              loop.uiTotalCycles = pSample->LoopPlayCount;
172              loop.uiCyclesLeft  = pSample->LoopPlayCount;              loop.uiCyclesLeft  = pSample->LoopPlayCount;
173              loop.uiStart       = pSample->LoopStart;              loop.uiStart       = loopinfo.LoopStart;
174              loop.uiEnd         = pSample->LoopEnd;              loop.uiEnd         = loopinfo.LoopStart + loopinfo.LoopLength;
175              loop.uiSize        = pSample->LoopSize;              loop.uiSize        = loopinfo.LoopLength;
176          }          }
177    
178          // calculate initial pitch value          // calculate initial pitch value
# Line 335  namespace LinuxSampler { namespace gig { Line 331  namespace LinuxSampler { namespace gig {
331                      pLFO1->ExtController = 0; // no external controller                      pLFO1->ExtController = 0; // no external controller
332                      bLFO1Enabled         = false;                      bLFO1Enabled         = false;
333              }              }
334              if (bLFO1Enabled) pLFO1->trigger(pDimRgn->LFO1Frequency,              if (bLFO1Enabled) {
335                                               start_level_max,                  pLFO1->trigger(pDimRgn->LFO1Frequency,
336                                               lfo1_internal_depth,                                 start_level_max,
337                                               pDimRgn->LFO1ControlDepth,                                 lfo1_internal_depth,
338                                               pDimRgn->LFO1FlipPhase,                                 pDimRgn->LFO1ControlDepth,
339                                               pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                                 pDimRgn->LFO1FlipPhase,
340                                   pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
341                    pLFO1->update(pLFO1->ExtController ? pEngineChannel->ControllerTable[pLFO1->ExtController] : 0);
342                }
343          }          }
344    
345    
# Line 378  namespace LinuxSampler { namespace gig { Line 377  namespace LinuxSampler { namespace gig {
377                      pLFO2->ExtController = 0; // no external controller                      pLFO2->ExtController = 0; // no external controller
378                      bLFO2Enabled         = false;                      bLFO2Enabled         = false;
379              }              }
380              if (bLFO2Enabled) pLFO2->trigger(pDimRgn->LFO2Frequency,              if (bLFO2Enabled) {
381                                               start_level_max,                  pLFO2->trigger(pDimRgn->LFO2Frequency,
382                                               lfo2_internal_depth,                                 start_level_max,
383                                               pDimRgn->LFO2ControlDepth,                                 lfo2_internal_depth,
384                                               pDimRgn->LFO2FlipPhase,                                 pDimRgn->LFO2ControlDepth,
385                                               pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                                 pDimRgn->LFO2FlipPhase,
386                                   pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
387                    pLFO2->update(pLFO2->ExtController ? pEngineChannel->ControllerTable[pLFO2->ExtController] : 0);
388                }
389          }          }
390    
391    
# Line 421  namespace LinuxSampler { namespace gig { Line 423  namespace LinuxSampler { namespace gig {
423                      pLFO3->ExtController = 0; // no external controller                      pLFO3->ExtController = 0; // no external controller
424                      bLFO3Enabled         = false;                      bLFO3Enabled         = false;
425              }              }
426              if (bLFO3Enabled) pLFO3->trigger(pDimRgn->LFO3Frequency,              if (bLFO3Enabled) {
427                                               start_level_mid,                  pLFO3->trigger(pDimRgn->LFO3Frequency,
428                                               lfo3_internal_depth,                                 start_level_mid,
429                                               pDimRgn->LFO3ControlDepth,                                 lfo3_internal_depth,
430                                               false,                                 pDimRgn->LFO3ControlDepth,
431                                               pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                                 false,
432                                   pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
433                    pLFO3->update(pLFO3->ExtController ? pEngineChannel->ControllerTable[pLFO3->ExtController] : 0);
434                }
435          }          }
436    
437    
# Line 526  namespace LinuxSampler { namespace gig { Line 531  namespace LinuxSampler { namespace gig {
531              else {              else {
532                  cvalue = pDimRgn->VCFCutoff;                  cvalue = pDimRgn->VCFCutoff;
533              }              }
534              cutoff *= float(cvalue) * 0.00787402f; // (1 / 127)              cutoff *= float(cvalue);
535              if (cutoff > 1.0) cutoff = 1.0;              if (cutoff > 127.0f) cutoff = 127.0f;
             cutoff = (cutoff < 0.5 ? cutoff * 4826 - 1 : cutoff * 5715 - 449);  
             if (cutoff < 1.0) cutoff = 1.0;  
536    
537              // calculate resonance              // calculate resonance
538              float resonance = (float) (VCFResonanceCtrl.controller ? VCFResonanceCtrl.value : pDimRgn->VCFResonance) * 0.00787f; // 0.0..1.0              float resonance = (float) (VCFResonanceCtrl.controller ? VCFResonanceCtrl.value : pDimRgn->VCFResonance);
539    
540              VCFCutoffCtrl.fvalue    = cutoff - 1.0;              VCFCutoffCtrl.fvalue    = cutoff;
541              VCFResonanceCtrl.fvalue = resonance;              VCFResonanceCtrl.fvalue = resonance;
542          }          }
543          else {          else {
# Line 732  namespace LinuxSampler { namespace gig { Line 735  namespace LinuxSampler { namespace gig {
735          VCFCutoffCtrl.value == ccvalue;          VCFCutoffCtrl.value == ccvalue;
736          if (pDimRgn->VCFCutoffControllerInvert)  ccvalue = 127 - ccvalue;          if (pDimRgn->VCFCutoffControllerInvert)  ccvalue = 127 - ccvalue;
737          if (ccvalue < pDimRgn->VCFVelocityScale) ccvalue = pDimRgn->VCFVelocityScale;          if (ccvalue < pDimRgn->VCFVelocityScale) ccvalue = pDimRgn->VCFVelocityScale;
738          float cutoff = CutoffBase * float(ccvalue) * 0.00787402f; // (1 / 127)          float cutoff = CutoffBase * float(ccvalue);
739          if (cutoff > 1.0) cutoff = 1.0;          if (cutoff > 127.0f) cutoff = 127.0f;
         cutoff = (cutoff < 0.5 ? cutoff * 4826 - 1 : cutoff * 5715 - 449);  
         if (cutoff < 1.0) cutoff = 1.0;  
740    
741          VCFCutoffCtrl.fvalue = cutoff - 1.0; // needed for initialization of fFinalCutoff next time          VCFCutoffCtrl.fvalue = cutoff; // needed for initialization of fFinalCutoff next time
742          fFinalCutoff = cutoff;          fFinalCutoff = cutoff;
743      }      }
744    
# Line 745  namespace LinuxSampler { namespace gig { Line 746  namespace LinuxSampler { namespace gig {
746          // convert absolute controller value to differential          // convert absolute controller value to differential
747          const int ctrldelta = itEvent->Param.CC.Value - VCFResonanceCtrl.value;          const int ctrldelta = itEvent->Param.CC.Value - VCFResonanceCtrl.value;
748          VCFResonanceCtrl.value = itEvent->Param.CC.Value;          VCFResonanceCtrl.value = itEvent->Param.CC.Value;
749          const float resonancedelta = (float) ctrldelta * 0.00787f; // 0.0..1.0          const float resonancedelta = (float) ctrldelta;
750          fFinalResonance += resonancedelta;          fFinalResonance += resonancedelta;
751          // needed for initialization of parameter          // needed for initialization of parameter
752          VCFResonanceCtrl.fvalue = itEvent->Param.CC.Value * 0.00787f;          VCFResonanceCtrl.fvalue = itEvent->Param.CC.Value;
753      }      }
754    
755      /**      /**
# Line 833  namespace LinuxSampler { namespace gig { Line 834  namespace LinuxSampler { namespace gig {
834    
835              // if filter enabled then update filter coefficients              // if filter enabled then update filter coefficients
836              if (SYNTHESIS_MODE_GET_FILTER(SynthesisMode)) {              if (SYNTHESIS_MODE_GET_FILTER(SynthesisMode)) {
837                  finalSynthesisParameters.filterLeft.SetParameters(fFinalCutoff + 1.0, fFinalResonance, pEngine->SampleRate);                  finalSynthesisParameters.filterLeft.SetParameters(fFinalCutoff, fFinalResonance, pEngine->SampleRate);
838                  finalSynthesisParameters.filterRight.SetParameters(fFinalCutoff + 1.0, fFinalResonance, pEngine->SampleRate);                  finalSynthesisParameters.filterRight.SetParameters(fFinalCutoff, fFinalResonance, pEngine->SampleRate);
839              }              }
840    
841              // do we need resampling?              // do we need resampling?
# Line 871  namespace LinuxSampler { namespace gig { Line 872  namespace LinuxSampler { namespace gig {
872              if (EG1.active()) {              if (EG1.active()) {
873    
874                  // if sample has a loop and loop start has been reached in this subfragment, send a special event to EG1 to let it finish the attack hold stage                  // if sample has a loop and loop start has been reached in this subfragment, send a special event to EG1 to let it finish the attack hold stage
875                  if (pSample->Loops && Pos <= pSample->LoopStart && pSample->LoopStart < newPos) {                  if (pDimRgn->SampleLoops && Pos <= pDimRgn->pSampleLoops[0].LoopStart && pDimRgn->pSampleLoops[0].LoopStart < newPos) {
876                      EG1.update(EGADSR::event_hold_end, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                      EG1.update(EGADSR::event_hold_end, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
877                  }                  }
878    

Legend:
Removed from v.832  
changed lines
  Added in v.877

  ViewVC Help
Powered by ViewVC