/[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 2015 by iliev, Sun Oct 25 22:22:52 2009 UTC revision 2327 by persson, Sat Mar 10 16:16:14 2012 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 - 2012 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> SF2Voice;
33          pEngine     = NULL;      Voice::Voice(): SignalRack(this), SF2Voice(&SignalRack) {
34            pEngine = NULL;
35            pEG1 = NULL;
36            pEG2 = NULL;
37      }      }
38    
39      Voice::~Voice() {      Voice::~Voice() {
40    
41      }      }
42    
43        void Voice::AboutToTrigger() {
44            
45        }
46    
47      EngineChannel* Voice::GetSf2EngineChannel() {      EngineChannel* Voice::GetSf2EngineChannel() {
48          return static_cast<EngineChannel*>(pEngineChannel);          return static_cast<EngineChannel*>(pEngineChannel);
49      }      }
# Line 56  namespace LinuxSampler { namespace sf2 { Line 63  namespace LinuxSampler { namespace sf2 {
63          si.BitDepth         = (pSample->GetFrameSize() / pSample->GetChannelCount()) * 8;          si.BitDepth         = (pSample->GetFrameSize() / pSample->GetChannelCount()) * 8;
64          si.TotalFrameCount  = pSample->GetTotalFrameCount();          si.TotalFrameCount  = pSample->GetTotalFrameCount();
65    
66          si.HasLoops       = pSample->HasLoops();          si.HasLoops       = pRegion->HasLoop;
67          si.LoopStart      = (si.HasLoops) ? pSample->StartLoop : 0; // TODO: region loop offsets          si.LoopStart      = (si.HasLoops) ? pRegion->LoopStart : 0;
68          si.LoopLength     = (si.HasLoops) ? pSample->EndLoop   : 0; // TODO: region loop offsets          si.LoopLength     = (si.HasLoops) ? ((pRegion->LoopEnd) - pRegion->LoopStart): 0;
69          si.LoopPlayCount  = 0; // TODO:          si.LoopPlayCount  = 0; // TODO:
70          si.Unpitched      = pSample->IsUnpitched();          si.Unpitched      = pSample->IsUnpitched();
71    
# Line 66  namespace LinuxSampler { namespace sf2 { Line 73  namespace LinuxSampler { namespace sf2 {
73      }      }
74    
75      Voice::RegionInfo Voice::GetRegionInfo() {      Voice::RegionInfo Voice::GetRegionInfo() {
76            ::sf2::Region* reg = NULL;
77            ::sf2::Preset* preset = GetSf2EngineChannel()->pInstrument;
78            for (int i = 0; i < preset->GetRegionCount(); i++) { // TODO: some optimization?
79                if (preset->GetRegion(i)->pInstrument == pRegion->GetParentInstrument()) {
80                    reg = preset->GetRegion(i); // TODO: Can the instrument belong to more than one preset region?
81                    break;
82                }
83            }
84            pPresetRegion = reg;
85    
86          RegionInfo ri;          RegionInfo ri;
87          ri.UnityNote = pSample->OriginalPitch;          ri.UnityNote = pRegion->GetUnityNote();
88          ri.FineTune  = pRegion->fineTune;          ri.FineTune  = pRegion->GetFineTune(reg) + (pRegion->GetCoarseTune(reg) * 100);
89          ri.Pan       = pRegion->pan;          ri.Pan       = pRegion->GetPan(reg);
90          ri.SampleStartOffset = pRegion->startAddrsOffset + pRegion->startAddrsCoarseOffset;          ri.SampleStartOffset = pRegion->startAddrsOffset + pRegion->startAddrsCoarseOffset;
91    
92          ri.EG1PreAttack        = 1000;          // sample pitch
93          ri.EG1Attack           = pRegion->EG1Attack;          ri.VCFEnabled    = true; // TODO:
94          ri.EG1Hold             = pRegion->EG1Hold;          ri.VCFType       = Filter::vcf_type_2p_lowpass; // TODO:
         ri.EG1Decay1           = pRegion->EG1Decay;  
         ri.EG1Decay2           = pRegion->EG1Decay;  
         ri.EG1Sustain          = pRegion->EG1Sustain;  
         ri.EG1InfiniteSustain  = true;  
         ri.EG1Release          = pRegion->EG1Release;  
   
         ri.EG2PreAttack        = 1000;  
         ri.EG2Attack           = pRegion->EG2Attack;  
         //ri.EG2Hold             = pRegion->EG2Hold; // TODO:  
         ri.EG2Decay1           = pRegion->EG2Decay;  
         ri.EG2Decay2           = pRegion->EG2Decay;  
         ri.EG2Sustain          = pRegion->EG2Sustain;  
         ri.EG2InfiniteSustain  = true;  
         ri.EG2Release          = pRegion->EG2Release;  
   
         ri.EG3Attack     = 0; // TODO:  
         ri.EG3Depth      = 0; // TODO:  
         ri.VCFEnabled    = false; // TODO:  
         ri.VCFType       = ::gig::vcf_type_lowpass; // TODO:  
95          ri.VCFResonance  = 0; // TODO:          ri.VCFResonance  = 0; // TODO:
96    
97          ri.ReleaseTriggerDecay = 0; // TODO:          ri.ReleaseTriggerDecay = 0; // TODO:
# Line 239  namespace LinuxSampler { namespace sf2 { Line 237  namespace LinuxSampler { namespace sf2 {
237          return eg;          return eg;
238      }      }
239    
240      void Voice::InitLFO1() {      float Voice::CalculateCutoffBase(uint8_t MIDIKeyVelocity) {
241          /*uint16_t lfo1_internal_depth;          float cutoff = pRegion->GetInitialFilterFc(pPresetRegion);
242          switch (pRegion->LFO1Controller) {          if (MIDIKeyVelocity == 0) return cutoff;
             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;  
     }  
243    
244      void Voice::InitLFO3() {          cutoff *= RTMath::CentsToFreqRatioUnlimited (
245          /*uint16_t lfo3_internal_depth;              ((127 - MIDIKeyVelocity) / 127.0) * -2400 // 8.4.2 MIDI Note-On Velocity to Filter Cutoff
246          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;  
     }  
247    
248      float Voice::CalculateCutoffBase(uint8_t MIDIKeyVelocity) {          return cutoff;
         /*float cutoff = pRegion->GetVelocityCutoff(MIDIKeyVelocity);  
         if (pRegion->VCFKeyboardTracking) {  
             cutoff *= exp((MIDIKeyVelocity - pRegion->VCFKeyboardTrackingBreakpoint) * 0.057762265f); // (ln(2) / 12)  
         }  
         return cutoff;*/ // TODO: ^^^  
         return 1.0f;  
249      }      }
250    
251      float Voice::CalculateFinalCutoff(float cutoffBase) {      float Voice::CalculateFinalCutoff(float cutoffBase) {
# Line 398  namespace LinuxSampler { namespace sf2 { Line 263  namespace LinuxSampler { namespace sf2 {
263          if (fco > 127.0f) fco = 127.0f;          if (fco > 127.0f) fco = 127.0f;
264    
265          return fco;*/ // TODO: ^^^          return fco;*/ // TODO: ^^^
266          return 0.0f;          return cutoffBase;
267      }      }
268    
269      uint8_t Voice::GetVCFCutoffCtrl() {      uint8_t Voice::GetVCFCutoffCtrl() {
# Line 468  namespace LinuxSampler { namespace sf2 { Line 333  namespace LinuxSampler { namespace sf2 {
333          return 0;          return 0;
334      }      }
335    
336        void Voice::ProcessGroupEvent(RTList<Event>::Iterator& itEvent) {
337            if (itEvent->Param.Note.Key != MIDIKey) {
338                // kill the voice fast
339                SignalRack.EnterFadeOutStage();
340            }
341        }
342    
343        void Voice::CalculateFadeOutCoeff(float FadeOutTime, float SampleRate) {
344            SignalRack.CalculateFadeOutCoeff(FadeOutTime, SampleRate);
345        }
346    
347  }} // namespace LinuxSampler::sf2  }} // namespace LinuxSampler::sf2

Legend:
Removed from v.2015  
changed lines
  Added in v.2327

  ViewVC Help
Powered by ViewVC