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 - 2010 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 * |
30 |
namespace LinuxSampler { namespace sf2 { |
namespace LinuxSampler { namespace sf2 { |
31 |
|
|
32 |
Voice::Voice() { |
Voice::Voice() { |
33 |
pEngine = NULL; |
pEngine = NULL; |
34 |
|
pEG1 = &EG1; |
35 |
} |
} |
36 |
|
|
37 |
Voice::~Voice() { |
Voice::~Voice() { |
67 |
} |
} |
68 |
|
|
69 |
Voice::RegionInfo Voice::GetRegionInfo() { |
Voice::RegionInfo Voice::GetRegionInfo() { |
70 |
|
::sf2::Region* reg = NULL; |
71 |
|
::sf2::Preset* preset = GetSf2EngineChannel()->pInstrument; |
72 |
|
for (int i = 0; i < preset->GetRegionCount(); i++) { // TODO: some optimization? |
73 |
|
if (preset->GetRegion(i)->pInstrument == pRegion->GetParentInstrument()) { |
74 |
|
reg = preset->GetRegion(i); // TODO: Can the instrument belongs to more than one preset regions? |
75 |
|
break; |
76 |
|
} |
77 |
|
} |
78 |
|
|
79 |
RegionInfo ri; |
RegionInfo ri; |
80 |
ri.UnityNote = pRegion->GetUnityNote(); |
ri.UnityNote = pRegion->GetUnityNote(); |
81 |
ri.FineTune = pRegion->fineTune; |
ri.FineTune = pRegion->GetFineTune(reg) + (pRegion->GetCoarseTune(reg) * 100); |
82 |
ri.Pan = pRegion->pan; |
ri.Pan = pRegion->GetPan(reg); |
83 |
ri.SampleStartOffset = pRegion->startAddrsOffset + pRegion->startAddrsCoarseOffset; |
ri.SampleStartOffset = pRegion->startAddrsOffset + pRegion->startAddrsCoarseOffset; |
84 |
|
|
85 |
|
// sample amplitude |
86 |
ri.EG1PreAttack = 1000; |
ri.EG1PreAttack = 1000; |
87 |
ri.EG1Attack = pRegion->EG1Attack; |
ri.EG1Attack = pRegion->GetEG1Attack(reg); |
88 |
ri.EG1Hold = pRegion->EG1Hold; |
ri.EG1Hold = pRegion->GetEG1Hold(reg); |
89 |
ri.EG1Decay1 = pRegion->EG1Decay; |
ri.EG1Decay1 = pRegion->GetEG1Decay(reg); |
90 |
ri.EG1Decay2 = pRegion->EG1Decay; |
ri.EG1Decay2 = pRegion->GetEG1Decay(reg); |
91 |
ri.EG1Sustain = pRegion->EG1Sustain; |
ri.EG1Sustain = pRegion->GetEG1Sustain(reg); |
92 |
ri.EG1InfiniteSustain = true; |
ri.EG1InfiniteSustain = true; |
93 |
ri.EG1Release = pRegion->EG1Release; |
ri.EG1Release = pRegion->GetEG1Release(reg); |
94 |
|
|
95 |
|
// filter cutoff frequency |
96 |
ri.EG2PreAttack = 1000; |
ri.EG2PreAttack = 1000; |
97 |
ri.EG2Attack = pRegion->EG2Attack; |
ri.EG2Attack = pRegion->GetEG2Attack(reg); |
98 |
//ri.EG2Hold = pRegion->EG2Hold; // TODO: |
//ri.EG2Hold = pRegion->EG2Hold; // TODO: |
99 |
ri.EG2Decay1 = pRegion->EG2Decay; |
ri.EG2Decay1 = pRegion->GetEG2Decay(reg); |
100 |
ri.EG2Decay2 = pRegion->EG2Decay; |
ri.EG2Decay2 = pRegion->GetEG2Decay(reg); |
101 |
ri.EG2Sustain = pRegion->EG2Sustain; |
ri.EG2Sustain = pRegion->GetEG2Sustain(reg); |
102 |
ri.EG2InfiniteSustain = true; |
ri.EG2InfiniteSustain = true; |
103 |
ri.EG2Release = pRegion->EG2Release; |
ri.EG2Release = pRegion->GetEG2Release(reg); |
104 |
|
|
105 |
|
// sample pitch |
106 |
ri.EG3Attack = 0; // TODO: |
ri.EG3Attack = 0; // TODO: |
107 |
ri.EG3Depth = 0; // TODO: |
ri.EG3Depth = 0; // TODO: |
108 |
ri.VCFEnabled = false; // TODO: |
ri.VCFEnabled = false; // TODO: |
216 |
return eg; |
return eg; |
217 |
} |
} |
218 |
|
|
219 |
|
void Voice::TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) { |
220 |
|
EG1.trigger(uint(RgnInfo.EG1PreAttack), |
221 |
|
RgnInfo.EG1Attack * egInfo.Attack, |
222 |
|
RgnInfo.EG1Hold, |
223 |
|
RgnInfo.EG1Decay1 * egInfo.Decay * velrelease, |
224 |
|
RgnInfo.EG1Decay2 * egInfo.Decay * velrelease, |
225 |
|
RgnInfo.EG1InfiniteSustain, |
226 |
|
uint(RgnInfo.EG1Sustain), |
227 |
|
RgnInfo.EG1Release * egInfo.Release * velrelease, |
228 |
|
velocityAttenuation, |
229 |
|
sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
230 |
|
} |
231 |
|
|
232 |
double Voice::GetEG2ControllerValue(uint8_t MIDIKeyVelocity) { |
double Voice::GetEG2ControllerValue(uint8_t MIDIKeyVelocity) { |
233 |
/*double eg2controllervalue = 0; |
/*double eg2controllervalue = 0; |
234 |
switch (pRegion->EG2Controller.type) { |
switch (pRegion->EG2Controller.type) { |