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

Annotation of /linuxsampler/trunk/src/engines/sfz/Voice.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2218 - (hide annotations) (download)
Thu Jul 28 08:05:57 2011 UTC (12 years, 9 months ago) by iliev
File size: 23666 byte(s)
* sfz engine: use the newly introduced signal units model

1 iliev 2012 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 persson 2055 * Copyright (C) 2005 - 2008 Christian Schoenebeck *
7 persson 2175 * Copyright (C) 2009 - 2011 Christian Schoenebeck and Grigor Iliev *
8 iliev 2012 * *
9     * 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 *
11     * the Free Software Foundation; either version 2 of the License, or *
12     * (at your option) any later version. *
13     * *
14     * This program is distributed in the hope that it will be useful, *
15     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17     * GNU General Public License for more details. *
18     * *
19     * You should have received a copy of the GNU General Public License *
20     * along with this program; if not, write to the Free Software *
21     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
22     * MA 02111-1307 USA *
23     ***************************************************************************/
24    
25 iliev 2015 #include "Voice.h"
26    
27 iliev 2012 #include "Engine.h"
28     #include "EngineChannel.h"
29    
30 persson 2072 #define LN_10_DIV_20 0.115129254649702
31    
32 iliev 2012 namespace LinuxSampler { namespace sfz {
33    
34 iliev 2218 typedef LinuxSampler::VoiceBase<EngineChannel, ::sfz::Region, Sample, DiskThread> SfzVoice;
35     Voice::Voice(): SignalRack(this), SfzVoice(&SignalRack) {
36 iliev 2012 pEngine = NULL;
37     }
38    
39     Voice::~Voice() {
40 iliev 2015
41 iliev 2012 }
42    
43 iliev 2015 EngineChannel* Voice::GetSfzEngineChannel() {
44     return static_cast<EngineChannel*>(pEngineChannel);
45     }
46    
47 iliev 2012 void Voice::SetEngine(LinuxSampler::Engine* pEngine) {
48     Engine* engine = static_cast<Engine*>(pEngine);
49     this->pEngine = engine;
50     this->pDiskThread = engine->pDiskThread;
51     dmsg(6,("Voice::SetEngine()\n"));
52     }
53    
54 iliev 2015 Voice::SampleInfo Voice::GetSampleInfo() {
55     SampleInfo si;
56     si.SampleRate = pSample->GetSampleRate();
57     si.ChannelCount = pSample->GetChannelCount();
58     si.FrameSize = pSample->GetFrameSize();
59     si.BitDepth = (pSample->GetFrameSize() / pSample->GetChannelCount()) * 8;
60     si.TotalFrameCount = pSample->GetTotalFrameCount();
61 iliev 2012
62 iliev 2021 si.HasLoops = pRegion->HasLoop();
63     si.LoopStart = pRegion->GetLoopStart();
64     si.LoopLength = pRegion->GetLoopEnd() - pRegion->GetLoopStart();
65     si.LoopPlayCount = pRegion->GetLoopCount();
66     si.Unpitched = pRegion->pitch_keytrack == 0;
67 iliev 2015 return si;
68     }
69 iliev 2012
70 iliev 2015 Voice::RegionInfo Voice::GetRegionInfo() {
71     RegionInfo ri;
72 iliev 2018 ri.UnityNote = pRegion->pitch_keycenter;
73 persson 2086 ri.FineTune = pRegion->tune + pRegion->transpose * 100;
74 persson 2045 ri.Pan = int(pRegion->pan * 0.63); // convert from -100..100 to -64..63
75 iliev 2216 ri.SampleStartOffset = pRegion->offset ? *(pRegion->offset) : 0;
76 iliev 2012
77 persson 2055 ri.EG2PreAttack = pRegion->fileg_start * 10;
78 iliev 2018 ri.EG2Attack = pRegion->fileg_attack;
79     //ri.EG2Hold = pRegion->fileg_hold; // TODO:
80     ri.EG2Decay1 = pRegion->fileg_decay;
81     ri.EG2Decay2 = pRegion->fileg_decay;
82 persson 2055 ri.EG2Sustain = pRegion->fileg_sustain * 10;
83 iliev 2015 ri.EG2InfiniteSustain = true;
84 iliev 2018 ri.EG2Release = pRegion->fileg_release;
85 iliev 2012
86 iliev 2018 ri.EG3Attack = pRegion->pitcheg_attack;
87 iliev 2015 ri.EG3Depth = 0; // TODO:
88 persson 2175 ri.VCFEnabled = pRegion->cutoff;
89     switch (pRegion->fil_type) {
90     case ::sfz::LPF_1P:
91     ri.VCFType = Filter::vcf_type_1p_lowpass;
92     break;
93     case ::sfz::LPF_2P:
94     ri.VCFType = Filter::vcf_type_2p_lowpass;
95     break;
96     case ::sfz::LPF_4P:
97     ri.VCFType = Filter::vcf_type_4p_lowpass;
98     break;
99     case ::sfz::LPF_6P:
100     ri.VCFType = Filter::vcf_type_6p_lowpass;
101     break;
102     case ::sfz::HPF_1P:
103     ri.VCFType = Filter::vcf_type_1p_highpass;
104     break;
105     case ::sfz::HPF_2P:
106     ri.VCFType = Filter::vcf_type_2p_highpass;
107     break;
108     case ::sfz::HPF_4P:
109     ri.VCFType = Filter::vcf_type_4p_highpass;
110     break;
111     case ::sfz::HPF_6P:
112     ri.VCFType = Filter::vcf_type_6p_highpass;
113     break;
114     case ::sfz::BPF_1P:
115     case ::sfz::BPF_2P:
116     ri.VCFType = Filter::vcf_type_2p_bandpass;
117     break;
118     case ::sfz::BRF_1P:
119     case ::sfz::BRF_2P:
120     ri.VCFType = Filter::vcf_type_2p_bandreject;
121     break;
122     case ::sfz::APF_1P:
123     case ::sfz::PKF_2P:
124     default:
125     ri.VCFEnabled = false;
126     break;
127     }
128 iliev 2012
129 persson 2175 ri.VCFResonance = pRegion->resonance;
130    
131 persson 2061 // rt_decay is in dB. Precalculate a suitable value for exp in
132     // GetReleaseTriggerAttenuation: -ln(10) / 20 * rt_decay
133 persson 2072 ri.ReleaseTriggerDecay = -LN_10_DIV_20 * pRegion->rt_decay;
134 iliev 2012
135 iliev 2015 return ri;
136     }
137 iliev 2012
138 iliev 2015 Voice::InstrumentInfo Voice::GetInstrumentInfo() {
139     InstrumentInfo ii;
140     ii.FineTune = 0; // TODO:
141     ii.PitchbendRange = 2; // TODO:
142    
143     return ii;
144     }
145    
146     double Voice::GetSampleAttenuation() {
147 persson 2072 return exp(LN_10_DIV_20 * pRegion->volume);
148 iliev 2015 }
149    
150     double Voice::GetVelocityAttenuation(uint8_t MIDIKeyVelocity) {
151 persson 2082 return pRegion->amp_velcurve[MIDIKeyVelocity];
152 iliev 2015 }
153    
154     double Voice::GetVelocityRelease(uint8_t MIDIKeyVelocity) {
155 persson 2176 return 127.0 / MIDIKeyVelocity;
156 iliev 2015 }
157    
158     void Voice::ProcessCCEvent(RTList<Event>::Iterator& itEvent) {
159     /*if (itEvent->Type == Event::type_control_change && itEvent->Param.CC.Controller) { // if (valid) MIDI control change event
160     if (pRegion->AttenuationController.type == ::gig::attenuation_ctrl_t::type_controlchange &&
161     itEvent->Param.CC.Controller == pRegion->AttenuationController.controller_number) {
162     CrossfadeSmoother.update(AbstractEngine::CrossfadeCurve[CrossfadeAttenuation(itEvent->Param.CC.Value)]);
163     }
164     }*/ // TODO: ^^^
165     }
166    
167     void Voice::ProcessCutoffEvent(RTList<Event>::Iterator& itEvent) {
168 persson 2175 int ccvalue = itEvent->Param.CC.Value;
169 iliev 2015 if (VCFCutoffCtrl.value == ccvalue) return;
170 persson 2175 VCFCutoffCtrl.value = ccvalue;
171 iliev 2015
172 persson 2175 float cutoff = CutoffBase * RTMath::CentsToFreqRatioUnlimited(
173     ccvalue / 127.0f * pRegion->cutoff_oncc[VCFCutoffCtrl.controller]);
174     if (cutoff > 0.49 * pEngine->SampleRate) cutoff = 0.49 * pEngine->SampleRate;
175    
176 iliev 2015 VCFCutoffCtrl.fvalue = cutoff; // needed for initialization of fFinalCutoff next time
177 persson 2175 fFinalCutoff = cutoff;
178 iliev 2015 }
179    
180     double Voice::CalculateCrossfadeVolume(uint8_t MIDIKeyVelocity) {
181 iliev 2012 /*float crossfadeVolume;
182     switch (pRegion->AttenuationController.type) {
183     case ::gig::attenuation_ctrl_t::type_channelaftertouch:
184 iliev 2015 crossfadeVolume = Engine::CrossfadeCurve[CrossfadeAttenuation(GetSfzEngineChannel()->ControllerTable[128])];
185 iliev 2012 break;
186     case ::gig::attenuation_ctrl_t::type_velocity:
187 iliev 2015 crossfadeVolume = Engine::CrossfadeCurve[CrossfadeAttenuation(MIDIKeyVelocity)];
188 iliev 2012 break;
189     case ::gig::attenuation_ctrl_t::type_controlchange: //FIXME: currently not sample accurate
190 iliev 2015 crossfadeVolume = Engine::CrossfadeCurve[CrossfadeAttenuation(GetSfzEngineChannel()->ControllerTable[pRegion->AttenuationController.controller_number])];
191 iliev 2012 break;
192     case ::gig::attenuation_ctrl_t::type_none: // no crossfade defined
193     default:
194     crossfadeVolume = 1.0f;
195     }
196    
197 iliev 2015 return crossfadeVolume;*/ // TODO: ^^^
198     return 1.0f;
199     }
200 iliev 2012
201 iliev 2015 double Voice::GetEG1ControllerValue(uint8_t MIDIKeyVelocity) {
202     /*double eg1controllervalue = 0;
203     switch (pRegion->EG1Controller.type) {
204     case ::gig::eg1_ctrl_t::type_none: // no controller defined
205     eg1controllervalue = 0;
206     break;
207     case ::gig::eg1_ctrl_t::type_channelaftertouch:
208     eg1controllervalue = GetSfzEngineChannel()->ControllerTable[128];
209     break;
210     case ::gig::eg1_ctrl_t::type_velocity:
211     eg1controllervalue = MIDIKeyVelocity;
212     break;
213     case ::gig::eg1_ctrl_t::type_controlchange: // MIDI control change controller
214     eg1controllervalue = GetSfzEngineChannel()->ControllerTable[pRegion->EG1Controller.controller_number];
215     break;
216 iliev 2012 }
217 iliev 2015 if (pRegion->EG1ControllerInvert) eg1controllervalue = 127 - eg1controllervalue;
218 iliev 2012
219 iliev 2015 return eg1controllervalue;*/ // TODO: ^^^
220     return 0;
221     }
222 iliev 2012
223 iliev 2015 Voice::EGInfo Voice::CalculateEG1ControllerInfluence(double eg1ControllerValue) {
224     /*EGInfo eg;
225     // (eg1attack is different from the others)
226     eg.Attack = (pRegion->EG1ControllerAttackInfluence) ?
227     1 + 0.031 * (double) (pRegion->EG1ControllerAttackInfluence == 1 ?
228     1 : 1 << pRegion->EG1ControllerAttackInfluence) * eg1ControllerValue : 1.0;
229     eg.Decay = (pRegion->EG1ControllerDecayInfluence) ? 1 + 0.00775 * (double) (1 << pRegion->EG1ControllerDecayInfluence) * eg1ControllerValue : 1.0;
230     eg.Release = (pRegion->EG1ControllerReleaseInfluence) ? 1 + 0.00775 * (double) (1 << pRegion->EG1ControllerReleaseInfluence) * eg1ControllerValue : 1.0;
231 iliev 2012
232 iliev 2015 return eg;*/ // TODO: ^^^
233     EGInfo eg;
234     eg.Attack = 1.0;
235     eg.Decay = 1.0;
236     eg.Release = 1.0;
237     return eg;
238     }
239 iliev 2012
240 persson 2055 void Voice::TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) {
241    
242     // TODO: controller modulation
243    
244     // first check if there is a v2 EG for amplitude
245     for (int i = 0 ; i < pRegion->eg.size() ; i++) {
246     if (pRegion->eg[i].amplitude > 0) {
247     // TODO: actually use the value of the amplitude parameter
248     pEG1 = &EG1;
249     EG1.trigger(pRegion->eg[i], sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE, velocity);
250     return;
251     }
252     }
253    
254     // otherwise use the v1 EGADSR
255     pEG1 = &EGADSR1;
256 persson 2203 EGADSR1.trigger(uint(pRegion->ampeg_start * 10),
257     std::max(0.0, pRegion->ampeg_attack + pRegion->ampeg_vel2attack * velrelease),
258     std::max(0.0, pRegion->ampeg_hold + pRegion->ampeg_vel2hold * velrelease),
259     std::max(0.0, pRegion->ampeg_decay + pRegion->ampeg_vel2decay * velrelease),
260     uint(std::min(std::max(0.0, 10 * (pRegion->ampeg_sustain + pRegion->ampeg_vel2sustain * velrelease)), 1000.0)),
261     std::max(0.0, pRegion->ampeg_release + pRegion->ampeg_vel2release * velrelease),
262 persson 2055 sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
263 persson 2176 }
264 persson 2055
265 persson 2176 double Voice::GetEG2ControllerValue(uint8_t MIDIKeyVelocity) {
266 iliev 2015 /*double eg2controllervalue = 0;
267     switch (pRegion->EG2Controller.type) {
268     case ::gig::eg2_ctrl_t::type_none: // no controller defined
269     eg2controllervalue = 0;
270     break;
271     case ::gig::eg2_ctrl_t::type_channelaftertouch:
272     eg2controllervalue = GetSfzEngineChannel()->ControllerTable[128];
273     break;
274     case ::gig::eg2_ctrl_t::type_velocity:
275     eg2controllervalue = MIDIKeyVelocity;
276     break;
277     case ::gig::eg2_ctrl_t::type_controlchange: // MIDI control change controller
278     eg2controllervalue = GetSfzEngineChannel()->ControllerTable[pRegion->EG2Controller.controller_number];
279     break;
280 iliev 2012 }
281 iliev 2015 if (pRegion->EG2ControllerInvert) eg2controllervalue = 127 - eg2controllervalue;
282 iliev 2012
283 iliev 2015 return eg2controllervalue;*/ // TODO: ^^^
284     return 0;
285     }
286 iliev 2012
287 iliev 2015 Voice::EGInfo Voice::CalculateEG2ControllerInfluence(double eg2ControllerValue) {
288     /*EGInfo eg;
289     eg.Attack = (pRegion->EG2ControllerAttackInfluence) ? 1 + 0.00775 * (double) (1 << pRegion->EG2ControllerAttackInfluence) * eg2ControllerValue : 1.0;
290     eg.Decay = (pRegion->EG2ControllerDecayInfluence) ? 1 + 0.00775 * (double) (1 << pRegion->EG2ControllerDecayInfluence) * eg2ControllerValue : 1.0;
291     eg.Release = (pRegion->EG2ControllerReleaseInfluence) ? 1 + 0.00775 * (double) (1 << pRegion->EG2ControllerReleaseInfluence) * eg2ControllerValue : 1.0;
292 iliev 2012
293 iliev 2015 return eg;*/ // TODO: ^^^
294     EGInfo eg;
295     eg.Attack = 1.0;
296     eg.Decay = 1.0;
297     eg.Release = 1.0;
298     return eg;
299     }
300 iliev 2012
301 persson 2175 void Voice::TriggerEG2(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) {
302    
303     // TODO: the sfz filter EG should modulate cents, not hertz,
304     // so we can't use the EG or EGADSR as it is. Disable for now.
305    
306     pEG2 = &EGADSR2;
307     EGADSR2.trigger(0,
308     0,
309     false,
310     0,
311     1000,
312     0,
313     sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
314     }
315    
316 iliev 2015 void Voice::InitLFO1() {
317     /*uint16_t lfo1_internal_depth;
318     switch (pRegion->LFO1Controller) {
319     case ::gig::lfo1_ctrl_internal:
320     lfo1_internal_depth = pRegion->LFO1InternalDepth;
321     pLFO1->ExtController = 0; // no external controller
322     bLFO1Enabled = (lfo1_internal_depth > 0);
323     break;
324     case ::gig::lfo1_ctrl_modwheel:
325     lfo1_internal_depth = 0;
326     pLFO1->ExtController = 1; // MIDI controller 1
327     bLFO1Enabled = (pRegion->LFO1ControlDepth > 0);
328     break;
329     case ::gig::lfo1_ctrl_breath:
330     lfo1_internal_depth = 0;
331     pLFO1->ExtController = 2; // MIDI controller 2
332     bLFO1Enabled = (pRegion->LFO1ControlDepth > 0);
333     break;
334     case ::gig::lfo1_ctrl_internal_modwheel:
335     lfo1_internal_depth = pRegion->LFO1InternalDepth;
336     pLFO1->ExtController = 1; // MIDI controller 1
337     bLFO1Enabled = (lfo1_internal_depth > 0 || pRegion->LFO1ControlDepth > 0);
338     break;
339     case ::gig::lfo1_ctrl_internal_breath:
340     lfo1_internal_depth = pRegion->LFO1InternalDepth;
341     pLFO1->ExtController = 2; // MIDI controller 2
342     bLFO1Enabled = (lfo1_internal_depth > 0 || pRegion->LFO1ControlDepth > 0);
343     break;
344     default:
345     lfo1_internal_depth = 0;
346     pLFO1->ExtController = 0; // no external controller
347     bLFO1Enabled = false;
348 iliev 2012 }
349 iliev 2015 if (bLFO1Enabled) {
350     pLFO1->trigger(pRegion->LFO1Frequency,
351     start_level_min,
352     lfo1_internal_depth,
353     pRegion->LFO1ControlDepth,
354     pRegion->LFO1FlipPhase,
355     pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
356     pLFO1->update(pLFO1->ExtController ? GetSfzEngineChannel()->ControllerTable[pLFO1->ExtController] : 0);
357 iliev 2012 }*/ // TODO: ^^^
358 iliev 2015 bLFO1Enabled = false;
359     }
360 iliev 2012
361 iliev 2015 void Voice::InitLFO2() {
362     /*uint16_t lfo2_internal_depth;
363     switch (pRegion->LFO2Controller) {
364     case ::gig::lfo2_ctrl_internal:
365     lfo2_internal_depth = pRegion->LFO2InternalDepth;
366     pLFO2->ExtController = 0; // no external controller
367     bLFO2Enabled = (lfo2_internal_depth > 0);
368     break;
369     case ::gig::lfo2_ctrl_modwheel:
370     lfo2_internal_depth = 0;
371     pLFO2->ExtController = 1; // MIDI controller 1
372     bLFO2Enabled = (pRegion->LFO2ControlDepth > 0);
373     break;
374     case ::gig::lfo2_ctrl_foot:
375     lfo2_internal_depth = 0;
376     pLFO2->ExtController = 4; // MIDI controller 4
377     bLFO2Enabled = (pRegion->LFO2ControlDepth > 0);
378     break;
379     case ::gig::lfo2_ctrl_internal_modwheel:
380     lfo2_internal_depth = pRegion->LFO2InternalDepth;
381     pLFO2->ExtController = 1; // MIDI controller 1
382     bLFO2Enabled = (lfo2_internal_depth > 0 || pRegion->LFO2ControlDepth > 0);
383     break;
384     case ::gig::lfo2_ctrl_internal_foot:
385     lfo2_internal_depth = pRegion->LFO2InternalDepth;
386     pLFO2->ExtController = 4; // MIDI controller 4
387     bLFO2Enabled = (lfo2_internal_depth > 0 || pRegion->LFO2ControlDepth > 0);
388     break;
389     default:
390     lfo2_internal_depth = 0;
391     pLFO2->ExtController = 0; // no external controller
392     bLFO2Enabled = false;
393 iliev 2012 }
394 iliev 2015 if (bLFO2Enabled) {
395     pLFO2->trigger(pRegion->LFO2Frequency,
396     start_level_max,
397     lfo2_internal_depth,
398     pRegion->LFO2ControlDepth,
399     pRegion->LFO2FlipPhase,
400     pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
401     pLFO2->update(pLFO2->ExtController ? GetSfzEngineChannel()->ControllerTable[pLFO2->ExtController] : 0);
402 iliev 2012 }*/ // TODO: ^^^
403 iliev 2015 bLFO2Enabled = false;
404 iliev 2012 }
405    
406 iliev 2015 void Voice::InitLFO3() {
407     /*uint16_t lfo3_internal_depth;
408     switch (pRegion->LFO3Controller) {
409     case ::gig::lfo3_ctrl_internal:
410     lfo3_internal_depth = pRegion->LFO3InternalDepth;
411     pLFO3->ExtController = 0; // no external controller
412     bLFO3Enabled = (lfo3_internal_depth > 0);
413 iliev 2012 break;
414 iliev 2015 case ::gig::lfo3_ctrl_modwheel:
415     lfo3_internal_depth = 0;
416     pLFO3->ExtController = 1; // MIDI controller 1
417     bLFO3Enabled = (pRegion->LFO3ControlDepth > 0);
418 iliev 2012 break;
419 iliev 2015 case ::gig::lfo3_ctrl_aftertouch:
420     lfo3_internal_depth = 0;
421     pLFO3->ExtController = 128;
422     bLFO3Enabled = true;
423 iliev 2012 break;
424 iliev 2015 case ::gig::lfo3_ctrl_internal_modwheel:
425     lfo3_internal_depth = pRegion->LFO3InternalDepth;
426     pLFO3->ExtController = 1; // MIDI controller 1
427     bLFO3Enabled = (lfo3_internal_depth > 0 || pRegion->LFO3ControlDepth > 0);
428     break;
429     case ::gig::lfo3_ctrl_internal_aftertouch:
430     lfo3_internal_depth = pRegion->LFO3InternalDepth;
431     pLFO1->ExtController = 128;
432     bLFO3Enabled = (lfo3_internal_depth > 0 || pRegion->LFO3ControlDepth > 0);
433     break;
434     default:
435     lfo3_internal_depth = 0;
436     pLFO3->ExtController = 0; // no external controller
437     bLFO3Enabled = false;
438 iliev 2012 }
439 iliev 2015 if (bLFO3Enabled) {
440     pLFO3->trigger(pRegion->LFO3Frequency,
441     start_level_mid,
442     lfo3_internal_depth,
443     pRegion->LFO3ControlDepth,
444     false,
445     pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE);
446     pLFO3->update(pLFO3->ExtController ? GetSfzEngineChannel()->ControllerTable[pLFO3->ExtController] : 0);
447     }*/ // TODO: ^^^
448     bLFO3Enabled = false;
449 iliev 2012 }
450    
451 iliev 2015 float Voice::CalculateCutoffBase(uint8_t MIDIKeyVelocity) {
452 persson 2175 float cutoff = *pRegion->cutoff;
453     cutoff *= RTMath::CentsToFreqRatioUnlimited(
454     MIDIKeyVelocity / 127.0f * pRegion->fil_veltrack +
455     (MIDIKey - pRegion->fil_keycenter) * pRegion->fil_keytrack);
456     return cutoff;
457 iliev 2012 }
458    
459 iliev 2015 float Voice::CalculateFinalCutoff(float cutoffBase) {
460 persson 2175 float cutoff;
461 iliev 2015 if (VCFCutoffCtrl.controller) {
462 persson 2175 int ccvalue = GetSfzEngineChannel()->ControllerTable[VCFCutoffCtrl.controller];
463     cutoff = CutoffBase * RTMath::CentsToFreqRatioUnlimited(
464     ccvalue / 127.0f * pRegion->cutoff_oncc[VCFCutoffCtrl.controller]);
465     } else {
466     cutoff = cutoffBase;
467 iliev 2012 }
468 persson 2175 if (cutoff > 0.49 * pEngine->SampleRate) cutoff = 0.49 * pEngine->SampleRate;
469     return cutoff;
470 iliev 2012 }
471    
472 iliev 2015 uint8_t Voice::GetVCFCutoffCtrl() {
473 persson 2175 // TODO: the sfz format allows several CC for the same
474     // modulation destination. The Voice interface needs to be
475     // changed to support that.
476     if (pRegion->cutoff_cc) return pRegion->cutoff_cc;
477     else if (pRegion->cutoff_chanaft) return 128;
478 iliev 2015 return 0;
479 iliev 2012 }
480    
481 iliev 2015 uint8_t Voice::GetVCFResonanceCtrl() {
482     /*uint8_t ctrl;
483     switch (pRegion->VCFResonanceController) {
484     case ::gig::vcf_res_ctrl_genpurpose3:
485     ctrl = 18;
486     break;
487     case ::gig::vcf_res_ctrl_genpurpose4:
488     ctrl = 19;
489     break;
490     case ::gig::vcf_res_ctrl_genpurpose5:
491     ctrl = 80;
492     break;
493     case ::gig::vcf_res_ctrl_genpurpose6:
494     ctrl = 81;
495     break;
496     case ::gig::vcf_res_ctrl_none:
497     default:
498     ctrl = 0;
499 iliev 2012 }
500    
501 iliev 2015 return ctrl;*/ // TODO: ^^^
502     return 0;
503 iliev 2012 }
504    
505 persson 2061 float Voice::GetReleaseTriggerAttenuation(float noteLength) {
506     // pow(10, -rt_decay * noteLength / 20):
507     return expf(RgnInfo.ReleaseTriggerDecay * noteLength);
508     }
509    
510 persson 2114 void Voice::ProcessGroupEvent(RTList<Event>::Iterator& itEvent) {
511     dmsg(4,("Voice %x processGroupEvents event type=%d", this, itEvent->Type));
512 persson 2115 if (itEvent->Type == Event::type_control_change ||
513     (Type & Voice::type_controller_triggered) ||
514     itEvent->Param.Note.Key != MIDIKey) {
515 persson 2114 dmsg(4,("Voice %x - kill", this));
516     if (pRegion->off_mode == ::sfz::OFF_NORMAL) {
517     // turn off the voice by entering release envelope stage
518     EnterReleaseStage();
519     } else {
520     // kill the voice fast
521 iliev 2218 SignalRack.EnterFadeOutStage();
522 persson 2114 }
523     }
524     }
525 iliev 2216
526     void Voice::SetSampleStartOffset() {
527     if (DiskVoice && RgnInfo.SampleStartOffset > pSample->MaxOffset) {
528     // The offset is applied to the RAM buffer
529     finalSynthesisParameters.dPos = 0;
530     Pos = 0;
531     } else {
532     finalSynthesisParameters.dPos = RgnInfo.SampleStartOffset; // offset where we should start playback of sample
533     Pos = RgnInfo.SampleStartOffset;
534     }
535     }
536 persson 2114
537 iliev 2012 }} // namespace LinuxSampler::sfz

  ViewVC Help
Powered by ViewVC