/[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 2027 by iliev, Tue Nov 3 19:27:42 2009 UTC revision 2205 by iliev, Mon Jul 11 17:52:01 2011 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
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 - 2009 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2008 Christian Schoenebeck                       *
7   *   Copyright (C) 2009 Grigor Iliev                                       *   *   Copyright (C) 2009 - 2011 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() {      Voice::Voice(): SignalRack(this) {
33          pEngine     = NULL;          pEngine = NULL;
34            pEG1 = &EG1;
35            pEG2 = &EG2;
36      }      }
37    
38      Voice::~Voice() {      Voice::~Voice() {
39    
40      }      }
41    
42        void Voice::AboutToTrigger() {
43            
44        }
45    
46      EngineChannel* Voice::GetSf2EngineChannel() {      EngineChannel* Voice::GetSf2EngineChannel() {
47          return static_cast<EngineChannel*>(pEngineChannel);          return static_cast<EngineChannel*>(pEngineChannel);
48      }      }
# Line 70  namespace LinuxSampler { namespace sf2 { Line 76  namespace LinuxSampler { namespace sf2 {
76          ::sf2::Preset* preset = GetSf2EngineChannel()->pInstrument;          ::sf2::Preset* preset = GetSf2EngineChannel()->pInstrument;
77          for (int i = 0; i < preset->GetRegionCount(); i++) { // TODO: some optimization?          for (int i = 0; i < preset->GetRegionCount(); i++) { // TODO: some optimization?
78              if (preset->GetRegion(i)->pInstrument == pRegion->GetParentInstrument()) {              if (preset->GetRegion(i)->pInstrument == pRegion->GetParentInstrument()) {
79                  reg = preset->GetRegion(i); // TODO: Can the instrument belongs to more than one preset regions?                  reg = preset->GetRegion(i); // TODO: Can the instrument belong to more than one preset region?
80                  break;                  break;
81              }              }
82          }          }
83                    pPresetRegion = reg;
84    
85          RegionInfo ri;          RegionInfo ri;
86          ri.UnityNote = pRegion->GetUnityNote();          ri.UnityNote = pRegion->GetUnityNote();
87          ri.FineTune  = pRegion->GetFineTune(reg) + (pRegion->GetCoarseTune(reg) * 100);          ri.FineTune  = pRegion->GetFineTune(reg) + (pRegion->GetCoarseTune(reg) * 100);
88          ri.Pan       = pRegion->GetPan(reg);          ri.Pan       = pRegion->GetPan(reg);
89          ri.SampleStartOffset = pRegion->startAddrsOffset + pRegion->startAddrsCoarseOffset;          ri.SampleStartOffset = pRegion->startAddrsOffset + pRegion->startAddrsCoarseOffset;
90    
         // sample amplitude  
         ri.EG1PreAttack        = 1000;  
         ri.EG1Attack           = pRegion->GetEG1Attack(reg);  
         ri.EG1Hold             = pRegion->GetEG1Hold(reg);  
         ri.EG1Decay1           = pRegion->GetEG1Decay(reg);  
         ri.EG1Decay2           = pRegion->GetEG1Decay(reg);  
         ri.EG1Sustain          = pRegion->GetEG1Sustain(reg);  
         ri.EG1InfiniteSustain  = true;  
         ri.EG1Release          = pRegion->GetEG1Release(reg);  
   
91          // filter cutoff frequency          // filter cutoff frequency
92          ri.EG2PreAttack        = 1000;          ri.EG2PreAttack        = 1000;
93          ri.EG2Attack           = pRegion->GetEG2Attack(reg);          ri.EG2Attack           = pRegion->GetEG2Attack(reg);
# Line 105  namespace LinuxSampler { namespace sf2 { Line 102  namespace LinuxSampler { namespace sf2 {
102          ri.EG3Attack     = 0; // TODO:          ri.EG3Attack     = 0; // TODO:
103          ri.EG3Depth      = 0; // TODO:          ri.EG3Depth      = 0; // TODO:
104          ri.VCFEnabled    = false; // TODO:          ri.VCFEnabled    = false; // TODO:
105          ri.VCFType       = ::gig::vcf_type_lowpass; // TODO:          ri.VCFType       = Filter::vcf_type_2p_lowpass; // TODO:
106          ri.VCFResonance  = 0; // TODO:          ri.VCFResonance  = 0; // TODO:
107    
108          ri.ReleaseTriggerDecay = 0; // TODO:          ri.ReleaseTriggerDecay = 0; // TODO:
# Line 215  namespace LinuxSampler { namespace sf2 { Line 212  namespace LinuxSampler { namespace sf2 {
212          return eg;          return eg;
213      }      }
214    
215        void Voice::TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) {
216            EG1.trigger(0,
217                        pRegion->GetEG1Attack(pPresetRegion),
218                        pRegion->GetEG1Hold(pPresetRegion),
219                        pRegion->GetEG1Decay(pPresetRegion),
220                        uint(pRegion->GetEG1Sustain(pPresetRegion)),
221                        pRegion->GetEG1Release(pPresetRegion),
222                        sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
223        }
224    
225      double Voice::GetEG2ControllerValue(uint8_t MIDIKeyVelocity) {      double Voice::GetEG2ControllerValue(uint8_t MIDIKeyVelocity) {
226          /*double eg2controllervalue = 0;          /*double eg2controllervalue = 0;
227          switch (pRegion->EG2Controller.type) {          switch (pRegion->EG2Controller.type) {
# Line 251  namespace LinuxSampler { namespace sf2 { Line 258  namespace LinuxSampler { namespace sf2 {
258          return eg;          return eg;
259      }      }
260    
261        void Voice::TriggerEG2(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) {
262            EG2.trigger(uint(RgnInfo.EG2PreAttack),
263                        RgnInfo.EG2Attack * egInfo.Attack,
264                        false,
265                        RgnInfo.EG2Decay1 * egInfo.Decay * velrelease,
266                        RgnInfo.EG2Decay2 * egInfo.Decay * velrelease,
267                        RgnInfo.EG2InfiniteSustain,
268                        uint(RgnInfo.EG2Sustain),
269                        RgnInfo.EG2Release * egInfo.Release * velrelease,
270                        velocityAttenuation,
271                        sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
272        }
273    
274      void Voice::InitLFO1() {      void Voice::InitLFO1() {
275          /*uint16_t lfo1_internal_depth;          /*uint16_t lfo1_internal_depth;
276          switch (pRegion->LFO1Controller) {          switch (pRegion->LFO1Controller) {
# Line 385  namespace LinuxSampler { namespace sf2 { Line 405  namespace LinuxSampler { namespace sf2 {
405          }*/ // TODO: ^^^          }*/ // TODO: ^^^
406           bLFO3Enabled = false;           bLFO3Enabled = false;
407      }      }
408        
409        SignalUnitRack* Voice::GetSignalUnitRack() {
410            return static_cast<SignalUnitRack*> (&SignalRack);
411        }
412    
413      float Voice::CalculateCutoffBase(uint8_t MIDIKeyVelocity) {      float Voice::CalculateCutoffBase(uint8_t MIDIKeyVelocity) {
414          /*float cutoff = pRegion->GetVelocityCutoff(MIDIKeyVelocity);          /*float cutoff = pRegion->GetVelocityCutoff(MIDIKeyVelocity);
415          if (pRegion->VCFKeyboardTracking) {          if (pRegion->VCFKeyboardTracking) {
416              cutoff *= exp((MIDIKeyVelocity - pRegion->VCFKeyboardTrackingBreakpoint) * 0.057762265f); // (ln(2) / 12)              cutoff *= RTMath::CentsToFreqRatioUnlimited((MIDIKey - pRegion->VCFKeyboardTrackingBreakpoint) * 100);
417          }          }
418          return cutoff;*/ // TODO: ^^^          return cutoff;*/ // TODO: ^^^
419          return 1.0f;          return 1.0f;
# Line 480  namespace LinuxSampler { namespace sf2 { Line 504  namespace LinuxSampler { namespace sf2 {
504          return 0;          return 0;
505      }      }
506    
507        void Voice::ProcessGroupEvent(RTList<Event>::Iterator& itEvent) {
508            if (itEvent->Param.Note.Key != MIDIKey) {
509                // kill the voice fast
510                pEG1->enterFadeOutStage();
511            }
512        }
513    
514  }} // namespace LinuxSampler::sf2  }} // namespace LinuxSampler::sf2

Legend:
Removed from v.2027  
changed lines
  Added in v.2205

  ViewVC Help
Powered by ViewVC