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

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

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

revision 2205 by iliev, Mon Jul 11 17:52:01 2011 UTC revision 3316 by schoenebeck, Thu Jul 20 12:05:53 2017 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2011 Grigor Iliev                                       *   *   Copyright (C) 2011 - 2012 Grigor Iliev                                *
6   *                                                                         *   *                                                                         *
7   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
8   *   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 25  Line 25 
25    
26  namespace LinuxSampler { namespace sf2 {  namespace LinuxSampler { namespace sf2 {
27            
28        SFSignalUnit::SFSignalUnit(SF2SignalUnitRack* rack): SignalUnit(rack), pVoice(NULL) {
29            
30        }
31        
32      void EGUnit::EnterReleaseStage() {      void EGUnit::EnterReleaseStage() {
33          update(EG::event_release, pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);          update(EG::event_release, pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
34      }      }
35            
36      void EGUnit::CancelRelease() {      void EGUnit::CancelRelease() {
37          update(EG::event_cancel_release, pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);          update(EG::event_cancel_release, pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
38      }      }
39    
40            
41      void VolEGUnit::Trigger() {      void VolEGUnit::Trigger() {
42          // set the delay trigger          // set the delay trigger
43          double d = pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE;          double d = pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE;
44          uiDelayTrigger = pOwner->pRegion->GetEG1PreAttackDelay(pOwner->pPresetRegion) * d;          uiDelayTrigger = pVoice->pRegion->GetEG1PreAttackDelay(pVoice->pPresetRegion) * d;
45          ////////////          ////////////
46                
47            // GetEG1Sustain gets the decrease in level in centibels
48            uint sustain = ::sf2::ToRatio(-1 * pVoice->pRegion->GetEG1Sustain(pVoice->pPresetRegion)) * 1000; // in permille
49            if (pVoice->pNote)
50                sustain *= pVoice->pNote->Override.Sustain;
51    
52          trigger (          trigger (
53              0, // should be in permille              0, // should be in permille
54              pOwner->pRegion->GetEG1Attack(pOwner->pPresetRegion),              pVoice->pRegion->GetEG1Attack(pVoice->pPresetRegion),
55              pOwner->pRegion->GetEG1Hold(pOwner->pPresetRegion),              pVoice->pRegion->GetEG1Hold(pVoice->pPresetRegion),
56              pOwner->pRegion->GetEG1Decay(pOwner->pPresetRegion),              pVoice->pRegion->GetEG1Decay(pVoice->pPresetRegion),
57              uint(pOwner->pRegion->GetEG1Sustain(pOwner->pPresetRegion)),              sustain,
58              pOwner->pRegion->GetEG1Release(pOwner->pPresetRegion),              pVoice->pRegion->GetEG1Release(pVoice->pPresetRegion),
59              pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE              pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE,
60                false
61          );          );
62      }      }
63            
# Line 75  namespace LinuxSampler { namespace sf2 { Line 85  namespace LinuxSampler { namespace sf2 {
85          if (active()) {          if (active()) {
86    
87              // 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
88              /*if (pOwner->SmplInfo.HasLoops && pOwner->Pos <= pOwner->SmplInfo.LoopStart && pOwner->SmplInfo.LoopStart < newPos) {              /*if (pVoice->SmplInfo.HasLoops && pVoice->Pos <= pVoice->SmplInfo.LoopStart && pVoice->SmplInfo.LoopStart < newPos) {
89                  update(EG::event_hold_end, pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);                  update(EG::event_hold_end, pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
90              }*/              }*/
91              // TODO: ^^^              // TODO: ^^^
92    
93              increment(1);              increment(1);
94              if (!toStageEndLeft()) update(EG::event_stage_end, pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);              if (!toStageEndLeft()) update(EG::event_stage_end, pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
95           }           }
96      }      }
97            
98      void ModEGUnit::Trigger() {      void ModEGUnit::Trigger() {
99          double d = pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE;          double d = pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE;
100          uiDelayTrigger = pOwner->pRegion->GetEG2PreAttackDelay(pOwner->pPresetRegion) * d;          uiDelayTrigger = pVoice->pRegion->GetEG2PreAttackDelay(pVoice->pPresetRegion) * d;
101    
102          trigger (          trigger (
103              0, // should be in permille              0, // should be in permille
104              pOwner->pRegion->GetEG2Attack(pOwner->pPresetRegion),              pVoice->pRegion->GetEG2Attack(pVoice->pPresetRegion),
105              pOwner->pRegion->GetEG2Hold(pOwner->pPresetRegion),              pVoice->pRegion->GetEG2Hold(pVoice->pPresetRegion),
106              pOwner->pRegion->GetEG2Decay(pOwner->pPresetRegion),              pVoice->pRegion->GetEG2Decay(pVoice->pPresetRegion),
107              uint(pOwner->pRegion->GetEG2Sustain(pOwner->pPresetRegion)),              uint(1000 - pVoice->pRegion->GetEG2Sustain(pVoice->pPresetRegion)),
108              pOwner->pRegion->GetEG2Release(pOwner->pPresetRegion),              pVoice->pRegion->GetEG2Release(pVoice->pPresetRegion),
109              pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE              pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE,
110                true
111          );          );
112      }      }
113            
# Line 123  namespace LinuxSampler { namespace sf2 { Line 134  namespace LinuxSampler { namespace sf2 {
134                    
135          if (active()) {          if (active()) {
136              increment(1);              increment(1);
137              if (!toStageEndLeft()) update(EG::event_stage_end, pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);              if (!toStageEndLeft()) update(EG::event_stage_end, pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
138           }          }
139        }
140    
141    
142        void ModLfoUnit::Trigger() {
143            //reset
144            Level = 0;
145            
146            // set the delay trigger
147            double samplerate = pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE;
148            uiDelayTrigger = pVoice->pRegion->GetDelayModLfo(pVoice->pPresetRegion) * samplerate;
149            ////////////
150                
151            trigger (
152                pVoice->pRegion->GetFreqModLfo(pVoice->pPresetRegion),
153                start_level_min,
154                1, 0, false, samplerate
155            );
156            updateByMIDICtrlValue(0);
157        }
158    
159        void ModLfoUnit::Increment() {
160            if (DelayStage()) return;
161            
162            SignalUnit::Increment();
163            
164            Level = render();
165      }      }
166    
167    
168      void VibLfoUnit::Trigger() {      void VibLfoUnit::Trigger() {
169            //reset
170            Level = 0;
171    
172          // set the delay trigger          // set the delay trigger
173          double samplerate = pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE;          double samplerate = pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE;
174          uiDelayTrigger = pOwner->pRegion->GetDelayVibLfo(pOwner->pPresetRegion) * samplerate;          uiDelayTrigger = pVoice->pRegion->GetDelayVibLfo(pVoice->pPresetRegion) * samplerate;
175          ////////////          ////////////
176                            
177          trigger (          trigger (
178              pOwner->pRegion->GetFreqVibLfo(pOwner->pPresetRegion),              pVoice->pRegion->GetFreqVibLfo(pVoice->pPresetRegion),
179              start_level_min,              start_level_min,
180              pOwner->pRegion->GetVibLfoToPitch(pOwner->pPresetRegion),              pVoice->pRegion->GetVibLfoToPitch(pVoice->pPresetRegion),
181              0, false, samplerate              0, false, samplerate
182          );          );
183          update(0);          updateByMIDICtrlValue(0);
184      }      }
185    
186      void VibLfoUnit::Increment() {      void VibLfoUnit::Increment() {
187          if (DelayStage()) return;          if (DelayStage()) return;
188                    
189          SignalUnitBase<Voice>::Increment();          SignalUnit::Increment();
190                    
191          Level = render();          Level = render();
192      }      }
       
193    
194      void EndpointUnit::Trigger() {  
195        EndpointUnit::EndpointUnit(SF2SignalUnitRack* rack): EndpointSignalUnit(rack) {
196                    
197      }      }
198    
199        void EndpointUnit::Trigger() {
200            prmModEgPitch->Coeff = pVoice->pRegion->GetModEnvToPitch(pVoice->pPresetRegion);
201            if (prmModEgPitch->Coeff == ::sf2::NONE) prmModEgPitch->Coeff = 0;
202    
203            prmModEgCutoff->Coeff = pVoice->pRegion->GetModEnvToFilterFc(pVoice->pPresetRegion); // cents
204            if (prmModEgCutoff->Coeff == ::sf2::NONE) prmModEgCutoff->Coeff = 0;
205    
206            prmModLfoVol->Coeff = pVoice->pRegion->GetModLfoToVolume(pVoice->pPresetRegion); // centibels
207            if (prmModLfoVol->Coeff == ::sf2::NONE) prmModLfoVol->Coeff = 0;
208    
209            prmModLfoCutoff->Coeff = pVoice->pRegion->GetModLfoToFilterFc(pVoice->pPresetRegion);
210            if (prmModLfoCutoff->Coeff == ::sf2::NONE) prmModLfoCutoff->Coeff = 0;
211    
212            prmModLfoPitch->Coeff = pVoice->pRegion->GetModLfoToPitch(pVoice->pPresetRegion);
213            if (prmModLfoPitch->Coeff == ::sf2::NONE) prmModLfoPitch->Coeff = 0;
214        }
215            
216      bool EndpointUnit::Active() {      bool EndpointUnit::Active() {
217          if (Params.size() < 1) return false;          return prmVolEg->pUnit->Active(); // volEGUnit
         return Params[0].pUnit->Active(); // volEGUnit  
218      }      }
219            
220      float EndpointUnit::GetVolume() {      float EndpointUnit::GetVolume() {
221          if (Params.size() < 1) return 0;          if (!prmVolEg->pUnit->Active()) return 0;
222          return Params[0].pUnit->Active() ? Params[0].GetFinalValue() : 0;          return prmVolEg->GetValue() *
223                   ::sf2::ToRatio(prmModLfoVol->GetValue() /*logarithmically modified */);
224      }      }
225            
226      float EndpointUnit::GetFilterCutoff() {      float EndpointUnit::GetFilterCutoff() {
227          return 1;          double modEg, modLfo;
228            modEg = prmModEgCutoff->pUnit->Active() ? prmModEgCutoff->GetValue() : 0;
229            modEg = RTMath::CentsToFreqRatioUnlimited(modEg);
230            
231            modLfo = prmModLfoCutoff->pUnit->Active() ? prmModLfoCutoff->GetValue() : 0;
232            modLfo = RTMath::CentsToFreqRatioUnlimited(modLfo);
233            
234            return modEg * modLfo;
235      }      }
236            
237      float EndpointUnit::GetPitch() {      float EndpointUnit::GetPitch() {
238          if (Params.size() < 3) return 0;          double modEg, modLfo, vibLfo;
239          double eg  = Params[1].pUnit->Active() ? RTMath::CentsToFreqRatio(Params[1].GetFinalValue()) : 1;          modEg  = prmModEgPitch->pUnit->Active() ? RTMath::CentsToFreqRatioUnlimited(prmModEgPitch->GetValue()) : 1;
240          double lfo = Params[2].pUnit->Active() ? RTMath::CentsToFreqRatio(Params[2].GetFinalValue()) : 1;          modLfo = prmModLfoPitch->pUnit->Active() ? RTMath::CentsToFreqRatioUnlimited(prmModLfoPitch->GetValue()) : 1;
241            vibLfo = prmVibLfo->pUnit->Active() ? RTMath::CentsToFreqRatioUnlimited(prmVibLfo->GetValue()) : 1;
242                    
243          return eg * lfo;          return modEg * modLfo * vibLfo;
244      }      }
245            
246      float EndpointUnit::GetResonance() {      float EndpointUnit::GetResonance() {
247          return 1;          return 1;
248      }      }
249            
250      SF2SignalUnitRack::SF2SignalUnitRack(Voice* pVoice): SignalUnitRackBase<Voice>(pVoice) {      SF2SignalUnitRack::SF2SignalUnitRack(Voice* voice)
251            : SignalUnitRack(MaxUnitCount), suVolEG(this), suModEG(this), suModLfo(this), suVibLfo(this), suEndpoint(this), pVoice(voice) {
252    
253            suVolEG.pVoice = suModEG.pVoice = suModLfo.pVoice = suVibLfo.pVoice = suEndpoint.pVoice = voice;
254          Units.add(&suVolEG);          Units.add(&suVolEG);
255          Units.add(&suModEG);          Units.add(&suModEG);
256            Units.add(&suModLfo);
257          Units.add(&suVibLfo);          Units.add(&suVibLfo);
258          Units.add(&suEndpoint);          Units.add(&suEndpoint);
259                    
260          // Volume envelope          // Volume envelope
261          suEndpoint.Params.add(SignalUnit::Parameter(&suVolEG));          suEndpoint.Params.add(SignalUnit::Parameter(&suVolEG)); // Volume
262          // Modulation envelope          // Modulation envelope
263          suEndpoint.Params.add(SignalUnit::Parameter(&suModEG));          suEndpoint.Params.add(SignalUnit::Parameter(&suModEG)); // Pitch
264            suEndpoint.Params.add(SignalUnit::Parameter(&suModEG)); // Filter cutoff
265            // Modulation LFO
266            suEndpoint.Params.add(SignalUnit::Parameter(&suModLfo)); // Volume
267            suEndpoint.Params.add(SignalUnit::Parameter(&suModLfo)); // Pitch
268            suEndpoint.Params.add(SignalUnit::Parameter(&suModLfo)); // Filter cutoff
269          // Vibrato LFO          // Vibrato LFO
270          suEndpoint.Params.add(SignalUnit::Parameter(&suVibLfo));          suEndpoint.Params.add(SignalUnit::Parameter(&suVibLfo)); // Pitch
     }  
       
     void SF2SignalUnitRack::Trigger() {  
         // The region settings are available after the voice is triggered  
   
         // Modulation envelope  
         int pitch = pOwner->pRegion->GetModEnvToPitch(pOwner->pPresetRegion);  
         suEndpoint.Params[1].Coeff = pitch;  
         ///////  
271    
272          SignalUnitRackBase<Voice>::Trigger();          /* This should be done at the end because when a parameter is added to
273               ArrayList a new copy is made for all parameters */
274            suEndpoint.prmVolEg = &suEndpoint.Params[0];
275            suEndpoint.prmModEgPitch = &suEndpoint.Params[1];
276            suEndpoint.prmModEgCutoff = &suEndpoint.Params[2];
277            suEndpoint.prmModLfoVol = &suEndpoint.Params[3];
278            suEndpoint.prmModLfoPitch = &suEndpoint.Params[4];
279            suEndpoint.prmModLfoCutoff = &suEndpoint.Params[5];
280            suEndpoint.prmVibLfo = &suEndpoint.Params[6];
281      }      }
282            
283      EndpointSignalUnit* SF2SignalUnitRack::GetEndpointUnit() {      EndpointSignalUnit* SF2SignalUnitRack::GetEndpointUnit() {
284          return static_cast<EndpointSignalUnit*> (&suEndpoint);          return static_cast<EndpointSignalUnit*> (&suEndpoint);
285      }      }
286            
287        void SF2SignalUnitRack::EnterFadeOutStage() {
288            suVolEG.enterFadeOutStage();
289        }
290    
291        void SF2SignalUnitRack::EnterFadeOutStage(int maxFadeOutSteps) {
292            suVolEG.enterFadeOutStage(maxFadeOutSteps);
293        }
294    
295        void SF2SignalUnitRack::CalculateFadeOutCoeff(float FadeOutTime, float SampleRate) {
296            suVolEG.CalculateFadeOutCoeff(FadeOutTime, SampleRate);
297        }
298  }} // namespace LinuxSampler::sf2  }} // namespace LinuxSampler::sf2

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

  ViewVC Help
Powered by ViewVC