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 - 2008 Christian Schoenebeck * |
* Copyright (C) 2005 - 2008 Christian Schoenebeck * |
7 |
* Copyright (C) 2009 - 2010 Christian Schoenebeck and 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 * |
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 |
|
Voice::Voice(): SignalRack(this), SF2Voice(&SignalRack) { |
34 |
pEngine = NULL; |
pEngine = NULL; |
35 |
pEG1 = &EG1; |
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 |
} |
} |
77 |
::sf2::Preset* preset = GetSf2EngineChannel()->pInstrument; |
::sf2::Preset* preset = GetSf2EngineChannel()->pInstrument; |
78 |
for (int i = 0; i < preset->GetRegionCount(); i++) { // TODO: some optimization? |
for (int i = 0; i < preset->GetRegionCount(); i++) { // TODO: some optimization? |
79 |
if (preset->GetRegion(i)->pInstrument == pRegion->GetParentInstrument()) { |
if (preset->GetRegion(i)->pInstrument == pRegion->GetParentInstrument()) { |
80 |
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? |
81 |
break; |
break; |
82 |
} |
} |
83 |
} |
} |
84 |
|
pPresetRegion = reg; |
85 |
|
|
86 |
RegionInfo ri; |
RegionInfo ri; |
87 |
ri.UnityNote = pRegion->GetUnityNote(); |
ri.UnityNote = pRegion->GetUnityNote(); |
88 |
ri.FineTune = pRegion->GetFineTune(reg) + (pRegion->GetCoarseTune(reg) * 100); |
ri.FineTune = pRegion->GetFineTune(reg) + (pRegion->GetCoarseTune(reg) * 100); |
89 |
ri.Pan = pRegion->GetPan(reg); |
ri.Pan = pRegion->GetPan(reg); |
90 |
ri.SampleStartOffset = pRegion->startAddrsOffset + pRegion->startAddrsCoarseOffset; |
ri.SampleStartOffset = pRegion->startAddrsOffset + pRegion->startAddrsCoarseOffset; |
91 |
|
|
|
// 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); |
|
|
|
|
|
// filter cutoff frequency |
|
|
ri.EG2PreAttack = 1000; |
|
|
ri.EG2Attack = pRegion->GetEG2Attack(reg); |
|
|
//ri.EG2Hold = pRegion->EG2Hold; // TODO: |
|
|
ri.EG2Decay1 = pRegion->GetEG2Decay(reg); |
|
|
ri.EG2Decay2 = pRegion->GetEG2Decay(reg); |
|
|
ri.EG2Sustain = pRegion->GetEG2Sustain(reg); |
|
|
ri.EG2InfiniteSustain = true; |
|
|
ri.EG2Release = pRegion->GetEG2Release(reg); |
|
|
|
|
92 |
// sample pitch |
// sample pitch |
93 |
ri.EG3Attack = 0; // TODO: |
ri.VCFEnabled = true; // TODO: |
94 |
ri.EG3Depth = 0; // TODO: |
ri.VCFType = Filter::vcf_type_2p_lowpass; // 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: |
201 |
return eg; |
return eg; |
202 |
} |
} |
203 |
|
|
|
void Voice::TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) { |
|
|
EG1.trigger(uint(RgnInfo.EG1PreAttack), |
|
|
RgnInfo.EG1Attack * egInfo.Attack, |
|
|
RgnInfo.EG1Hold, |
|
|
RgnInfo.EG1Decay1 * egInfo.Decay * velrelease, |
|
|
RgnInfo.EG1Decay2 * egInfo.Decay * velrelease, |
|
|
RgnInfo.EG1InfiniteSustain, |
|
|
uint(RgnInfo.EG1Sustain), |
|
|
RgnInfo.EG1Release * egInfo.Release * velrelease, |
|
|
velocityAttenuation, |
|
|
sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
|
|
} |
|
|
|
|
204 |
double Voice::GetEG2ControllerValue(uint8_t MIDIKeyVelocity) { |
double Voice::GetEG2ControllerValue(uint8_t MIDIKeyVelocity) { |
205 |
/*double eg2controllervalue = 0; |
/*double eg2controllervalue = 0; |
206 |
switch (pRegion->EG2Controller.type) { |
switch (pRegion->EG2Controller.type) { |
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) { |
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() { |
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 |