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 * |
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 |
} |
} |
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); |
101 |
// sample pitch |
// sample pitch |
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 = true; // 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: |
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) { |
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) { |
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->GetInitialFilterFc(pPresetRegion); |
415 |
if (pRegion->VCFKeyboardTracking) { |
if (MIDIKeyVelocity == 0) return cutoff; |
416 |
cutoff *= exp((MIDIKeyVelocity - pRegion->VCFKeyboardTrackingBreakpoint) * 0.057762265f); // (ln(2) / 12) |
|
417 |
} |
cutoff *= RTMath::CentsToFreqRatioUnlimited ( |
418 |
return cutoff;*/ // TODO: ^^^ |
((127 - MIDIKeyVelocity) / 127.0) * -2400 // 8.4.2 MIDI Note-On Velocity to Filter Cutoff |
419 |
return 1.0f; |
); |
420 |
|
|
421 |
|
return cutoff; |
422 |
} |
} |
423 |
|
|
424 |
float Voice::CalculateFinalCutoff(float cutoffBase) { |
float Voice::CalculateFinalCutoff(float cutoffBase) { |
436 |
if (fco > 127.0f) fco = 127.0f; |
if (fco > 127.0f) fco = 127.0f; |
437 |
|
|
438 |
return fco;*/ // TODO: ^^^ |
return fco;*/ // TODO: ^^^ |
439 |
return 0.0f; |
return cutoffBase; |
440 |
} |
} |
441 |
|
|
442 |
uint8_t Voice::GetVCFCutoffCtrl() { |
uint8_t Voice::GetVCFCutoffCtrl() { |
506 |
return 0; |
return 0; |
507 |
} |
} |
508 |
|
|
509 |
|
void Voice::ProcessGroupEvent(RTList<Event>::Iterator& itEvent) { |
510 |
|
if (itEvent->Param.Note.Key != MIDIKey) { |
511 |
|
// kill the voice fast |
512 |
|
pEG1->enterFadeOutStage(); |
513 |
|
} |
514 |
|
} |
515 |
|
|
516 |
}} // namespace LinuxSampler::sf2 |
}} // namespace LinuxSampler::sf2 |