/[svn]/linuxsampler/trunk/src/engines/sf2/Voice.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/sf2/Voice.cpp

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

revision 2203 by persson, Sat Jul 9 16:44:27 2011 UTC revision 3444 by schoenebeck, Sun Dec 23 19:32:11 2018 UTC
# Line 4  Line 4 
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005 - 2008 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2008 Christian Schoenebeck                       *
7   *   Copyright (C) 2009 - 2011 Christian Schoenebeck and Grigor Iliev      *   *   Copyright (C) 2009 - 2016 Christian Schoenebeck and Grigor Iliev      *
8   *                                                                         *   *                                                                         *
9   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
10   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 29  Line 29 
29    
30  namespace LinuxSampler { namespace sf2 {  namespace LinuxSampler { namespace sf2 {
31    
32      Voice::Voice() {      typedef LinuxSampler::VoiceBase<EngineChannel, ::sf2::Region, ::sf2::Sample, DiskThread> SF2VoiceBase;
33    
34        Voice::Voice(): SF2VoiceBase(&SignalRack), SignalRack(this) {
35          pEngine = NULL;          pEngine = NULL;
36          pEG1 = &EG1;          pEG1 = NULL;
37          pEG2 = &EG2;          pEG2 = NULL;
38      }      }
39    
40      Voice::~Voice() {      Voice::~Voice() {
41    
42      }      }
43    
44        void Voice::AboutToTrigger() {
45            
46        }
47    
48      EngineChannel* Voice::GetSf2EngineChannel() {      EngineChannel* Voice::GetSf2EngineChannel() {
49          return static_cast<EngineChannel*>(pEngineChannel);          return static_cast<EngineChannel*>(pEngineChannel);
50      }      }
# Line 56  namespace LinuxSampler { namespace sf2 { Line 62  namespace LinuxSampler { namespace sf2 {
62          si.ChannelCount     = pSample->GetChannelCount();          si.ChannelCount     = pSample->GetChannelCount();
63          si.FrameSize        = pSample->GetFrameSize();          si.FrameSize        = pSample->GetFrameSize();
64          si.BitDepth         = (pSample->GetFrameSize() / pSample->GetChannelCount()) * 8;          si.BitDepth         = (pSample->GetFrameSize() / pSample->GetChannelCount()) * 8;
65          si.TotalFrameCount  = pSample->GetTotalFrameCount();          si.TotalFrameCount  = (uint)pSample->GetTotalFrameCount();
66    
67          si.HasLoops       = pRegion->HasLoop;          si.HasLoops       = pRegion->HasLoop;
68          si.LoopStart      = (si.HasLoops) ? pRegion->LoopStart : 0;          si.LoopStart      = (si.HasLoops) ? pRegion->LoopStart : 0;
# Line 84  namespace LinuxSampler { namespace sf2 { Line 90  namespace LinuxSampler { namespace sf2 {
90          ri.Pan       = pRegion->GetPan(reg);          ri.Pan       = pRegion->GetPan(reg);
91          ri.SampleStartOffset = pRegion->startAddrsOffset + pRegion->startAddrsCoarseOffset;          ri.SampleStartOffset = pRegion->startAddrsOffset + pRegion->startAddrsCoarseOffset;
92    
         // filter cutoff frequency  
         ri.EG2PreAttack        = 1000;  
         ri.EG2Attack           = pRegion->GetEG2Attack(reg);  
         //ri.EG2Hold             = pRegion->EG2Hold; // TODO:  
         ri.EG2Decay1           = pRegion->GetEG2Decay(reg);  
         ri.EG2Decay2           = pRegion->GetEG2Decay(reg);  
         ri.EG2Sustain          = pRegion->GetEG2Sustain(reg);  
         ri.EG2InfiniteSustain  = true;  
         ri.EG2Release          = pRegion->GetEG2Release(reg);  
   
93          // sample pitch          // sample pitch
94          ri.EG3Attack     = 0; // TODO:          ri.VCFEnabled    = true; // TODO:
         ri.EG3Depth      = 0; // TODO:  
         ri.VCFEnabled    = false; // TODO:  
95          ri.VCFType       = Filter::vcf_type_2p_lowpass; // TODO:          ri.VCFType       = Filter::vcf_type_2p_lowpass; // TODO:
96          ri.VCFResonance  = 0; // TODO:          ri.VCFResonance  = 0; // TODO:
97    
# Line 134  namespace LinuxSampler { namespace sf2 { Line 128  namespace LinuxSampler { namespace sf2 {
128              }              }
129          }*/ // TODO: ^^^          }*/ // TODO: ^^^
130      }      }
131        
132        void Voice::ProcessChannelPressureEvent(RTList<Event>::Iterator& itEvent) {
133            //TODO: ...
134        }
135        
136        void Voice::ProcessPolyphonicKeyPressureEvent(RTList<Event>::Iterator& itEvent) {
137            //TODO: ...
138        }
139    
140      void Voice::ProcessCutoffEvent(RTList<Event>::Iterator& itEvent) {      void Voice::ProcessCutoffEvent(RTList<Event>::Iterator& itEvent) {
141          /*int ccvalue = itEvent->Param.CC.Value;          /*int ccvalue = itEvent->Param.CC.Value;
# Line 208  namespace LinuxSampler { namespace sf2 { Line 210  namespace LinuxSampler { namespace sf2 {
210          return eg;          return eg;
211      }      }
212    
     void Voice::TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) {  
         EG1.trigger(0,  
                     pRegion->GetEG1Attack(pPresetRegion),  
                     pRegion->GetEG1Hold(pPresetRegion),  
                     pRegion->GetEG1Decay(pPresetRegion),  
                     uint(pRegion->GetEG1Sustain(pPresetRegion)),  
                     pRegion->GetEG1Release(pPresetRegion),  
                     sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);  
     }  
   
213      double Voice::GetEG2ControllerValue(uint8_t MIDIKeyVelocity) {      double Voice::GetEG2ControllerValue(uint8_t MIDIKeyVelocity) {
214          /*double eg2controllervalue = 0;          /*double eg2controllervalue = 0;
215          switch (pRegion->EG2Controller.type) {          switch (pRegion->EG2Controller.type) {
# Line 254  namespace LinuxSampler { namespace sf2 { Line 246  namespace LinuxSampler { namespace sf2 {
246          return eg;          return eg;
247      }      }
248    
249      void Voice::TriggerEG2(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) {      float Voice::CalculateCutoffBase(uint8_t MIDIKeyVelocity) {
250          EG2.trigger(uint(RgnInfo.EG2PreAttack),          float cutoff = pRegion->GetInitialFilterFc(pPresetRegion);
251                      RgnInfo.EG2Attack * egInfo.Attack,          if (MIDIKeyVelocity == 0) return cutoff;
                     false,  
                     RgnInfo.EG2Decay1 * egInfo.Decay * velrelease,  
                     RgnInfo.EG2Decay2 * egInfo.Decay * velrelease,  
                     RgnInfo.EG2InfiniteSustain,  
                     uint(RgnInfo.EG2Sustain),  
                     RgnInfo.EG2Release * egInfo.Release * velrelease,  
                     velocityAttenuation,  
                     sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);  
     }  
   
     void Voice::InitLFO1() {  
         /*uint16_t lfo1_internal_depth;  
         switch (pRegion->LFO1Controller) {  
             case ::gig::lfo1_ctrl_internal:  
                 lfo1_internal_depth  = pRegion->LFO1InternalDepth;  
                 pLFO1->ExtController = 0; // no external controller  
                 bLFO1Enabled         = (lfo1_internal_depth > 0);  
                 break;  
             case ::gig::lfo1_ctrl_modwheel:  
                 lfo1_internal_depth  = 0;  
                 pLFO1->ExtController = 1; // MIDI controller 1  
                 bLFO1Enabled         = (pRegion->LFO1ControlDepth > 0);  
                 break;  
             case ::gig::lfo1_ctrl_breath:  
                 lfo1_internal_depth  = 0;  
                 pLFO1->ExtController = 2; // MIDI controller 2  
                 bLFO1Enabled         = (pRegion->LFO1ControlDepth > 0);  
                 break;  
             case ::gig::lfo1_ctrl_internal_modwheel:  
                 lfo1_internal_depth  = pRegion->LFO1InternalDepth;  
                 pLFO1->ExtController = 1; // MIDI controller 1  
                 bLFO1Enabled         = (lfo1_internal_depth > 0 || pRegion->LFO1ControlDepth > 0);  
                 break;  
             case ::gig::lfo1_ctrl_internal_breath:  
                 lfo1_internal_depth  = pRegion->LFO1InternalDepth;  
                 pLFO1->ExtController = 2; // MIDI controller 2  
                 bLFO1Enabled         = (lfo1_internal_depth > 0 || pRegion->LFO1ControlDepth > 0);  
                 break;  
             default:  
                 lfo1_internal_depth  = 0;  
                 pLFO1->ExtController = 0; // no external controller  
                 bLFO1Enabled         = false;  
         }  
         if (bLFO1Enabled) {  
             pLFO1->trigger(pRegion->LFO1Frequency,  
                            start_level_min,  
                            lfo1_internal_depth,  
                            pRegion->LFO1ControlDepth,  
                            pRegion->LFO1FlipPhase,  
                            pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);  
             pLFO1->update(pLFO1->ExtController ? GetSf2EngineChannel()->ControllerTable[pLFO1->ExtController] : 0);  
         }*/ // TODO: ^^^  
         bLFO1Enabled = false;  
     }  
   
     void Voice::InitLFO2() {  
         /*uint16_t lfo2_internal_depth;  
         switch (pRegion->LFO2Controller) {  
             case ::gig::lfo2_ctrl_internal:  
                 lfo2_internal_depth  = pRegion->LFO2InternalDepth;  
                 pLFO2->ExtController = 0; // no external controller  
                 bLFO2Enabled         = (lfo2_internal_depth > 0);  
                 break;  
             case ::gig::lfo2_ctrl_modwheel:  
                 lfo2_internal_depth  = 0;  
                 pLFO2->ExtController = 1; // MIDI controller 1  
                 bLFO2Enabled         = (pRegion->LFO2ControlDepth > 0);  
                 break;  
             case ::gig::lfo2_ctrl_foot:  
                 lfo2_internal_depth  = 0;  
                 pLFO2->ExtController = 4; // MIDI controller 4  
                 bLFO2Enabled         = (pRegion->LFO2ControlDepth > 0);  
                 break;  
             case ::gig::lfo2_ctrl_internal_modwheel:  
                 lfo2_internal_depth  = pRegion->LFO2InternalDepth;  
                 pLFO2->ExtController = 1; // MIDI controller 1  
                 bLFO2Enabled         = (lfo2_internal_depth > 0 || pRegion->LFO2ControlDepth > 0);  
                 break;  
             case ::gig::lfo2_ctrl_internal_foot:  
                 lfo2_internal_depth  = pRegion->LFO2InternalDepth;  
                 pLFO2->ExtController = 4; // MIDI controller 4  
                 bLFO2Enabled         = (lfo2_internal_depth > 0 || pRegion->LFO2ControlDepth > 0);  
                 break;  
             default:  
                 lfo2_internal_depth  = 0;  
                 pLFO2->ExtController = 0; // no external controller  
                 bLFO2Enabled         = false;  
         }  
         if (bLFO2Enabled) {  
             pLFO2->trigger(pRegion->LFO2Frequency,  
                            start_level_max,  
                            lfo2_internal_depth,  
                            pRegion->LFO2ControlDepth,  
                            pRegion->LFO2FlipPhase,  
                            pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);  
             pLFO2->update(pLFO2->ExtController ? GetSf2EngineChannel()->ControllerTable[pLFO2->ExtController] : 0);  
         }*/ // TODO: ^^^  
          bLFO2Enabled = false;  
     }  
252    
253      void Voice::InitLFO3() {          cutoff *= RTMath::CentsToFreqRatioUnlimited (
254          /*uint16_t lfo3_internal_depth;              ((127 - MIDIKeyVelocity) / 127.0) * -2400 // 8.4.2 MIDI Note-On Velocity to Filter Cutoff
255          switch (pRegion->LFO3Controller) {          );
             case ::gig::lfo3_ctrl_internal:  
                 lfo3_internal_depth  = pRegion->LFO3InternalDepth;  
                 pLFO3->ExtController = 0; // no external controller  
                 bLFO3Enabled         = (lfo3_internal_depth > 0);  
                 break;  
             case ::gig::lfo3_ctrl_modwheel:  
                 lfo3_internal_depth  = 0;  
                 pLFO3->ExtController = 1; // MIDI controller 1  
                 bLFO3Enabled         = (pRegion->LFO3ControlDepth > 0);  
                 break;  
             case ::gig::lfo3_ctrl_aftertouch:  
                 lfo3_internal_depth  = 0;  
                 pLFO3->ExtController = 128;  
                 bLFO3Enabled         = true;  
                 break;  
             case ::gig::lfo3_ctrl_internal_modwheel:  
                 lfo3_internal_depth  = pRegion->LFO3InternalDepth;  
                 pLFO3->ExtController = 1; // MIDI controller 1  
                 bLFO3Enabled         = (lfo3_internal_depth > 0 || pRegion->LFO3ControlDepth > 0);  
                 break;  
             case ::gig::lfo3_ctrl_internal_aftertouch:  
                 lfo3_internal_depth  = pRegion->LFO3InternalDepth;  
                 pLFO1->ExtController = 128;  
                 bLFO3Enabled         = (lfo3_internal_depth > 0 || pRegion->LFO3ControlDepth > 0);  
                 break;  
             default:  
                 lfo3_internal_depth  = 0;  
                 pLFO3->ExtController = 0; // no external controller  
                 bLFO3Enabled         = false;  
         }  
         if (bLFO3Enabled) {  
             pLFO3->trigger(pRegion->LFO3Frequency,  
                            start_level_mid,  
                            lfo3_internal_depth,  
                            pRegion->LFO3ControlDepth,  
                            false,  
                            pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);  
             pLFO3->update(pLFO3->ExtController ? GetSf2EngineChannel()->ControllerTable[pLFO3->ExtController] : 0);  
         }*/ // TODO: ^^^  
          bLFO3Enabled = false;  
     }  
256    
257      float Voice::CalculateCutoffBase(uint8_t MIDIKeyVelocity) {          return cutoff;
         /*float cutoff = pRegion->GetVelocityCutoff(MIDIKeyVelocity);  
         if (pRegion->VCFKeyboardTracking) {  
             cutoff *= RTMath::CentsToFreqRatioUnlimited((MIDIKey - pRegion->VCFKeyboardTrackingBreakpoint) * 100);  
         }  
         return cutoff;*/ // TODO: ^^^  
         return 1.0f;  
258      }      }
259    
260      float Voice::CalculateFinalCutoff(float cutoffBase) {      float Voice::CalculateFinalCutoff(float cutoffBase) {
# Line 426  namespace LinuxSampler { namespace sf2 { Line 272  namespace LinuxSampler { namespace sf2 {
272          if (fco > 127.0f) fco = 127.0f;          if (fco > 127.0f) fco = 127.0f;
273    
274          return fco;*/ // TODO: ^^^          return fco;*/ // TODO: ^^^
275          return 0.0f;          return cutoffBase;
276      }      }
277    
278      uint8_t Voice::GetVCFCutoffCtrl() {      uint8_t Voice::GetVCFCutoffCtrl() {
# Line 460  namespace LinuxSampler { namespace sf2 { Line 306  namespace LinuxSampler { namespace sf2 {
306                  ctrl = 83;                  ctrl = 83;
307                  break;                  break;
308              case ::gig::vcf_cutoff_ctrl_aftertouch:              case ::gig::vcf_cutoff_ctrl_aftertouch:
309                  ctrl = 128;                  ctrl = CTRL_TABLE_IDX_AFTERTOUCH;
310                  break;                  break;
311              case ::gig::vcf_cutoff_ctrl_none:              case ::gig::vcf_cutoff_ctrl_none:
312              default:              default:
# Line 497  namespace LinuxSampler { namespace sf2 { Line 343  namespace LinuxSampler { namespace sf2 {
343      }      }
344    
345      void Voice::ProcessGroupEvent(RTList<Event>::Iterator& itEvent) {      void Voice::ProcessGroupEvent(RTList<Event>::Iterator& itEvent) {
346          if (itEvent->Param.Note.Key != MIDIKey) {          if (itEvent->Param.Note.Key != HostKey()) {
347              // kill the voice fast              // kill the voice fast
348              pEG1->enterFadeOutStage();              SignalRack.EnterFadeOutStage();
349          }          }
350      }      }
351    
352        void Voice::CalculateFadeOutCoeff(float FadeOutTime, float SampleRate) {
353            SignalRack.CalculateFadeOutCoeff(FadeOutTime, SampleRate);
354        }
355    
356        int Voice::CalculatePan(uint8_t pan) {
357            int p = pan + RgnInfo.Pan;
358    
359            if (p < 0) return 0;
360            if (p > 127) return 127;
361            return p;
362        }
363    
364        release_trigger_t Voice::GetReleaseTriggerFlags() {
365            return release_trigger_none;
366        }
367    
368  }} // namespace LinuxSampler::sf2  }} // namespace LinuxSampler::sf2

Legend:
Removed from v.2203  
changed lines
  Added in v.3444

  ViewVC Help
Powered by ViewVC