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-2008 Christian Schoenebeck * |
* Copyright (C) 2005 - 2008 Christian Schoenebeck * |
7 |
* Copyright (C) 2009-2010 Christian Schoenebeck and 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 * |
27 |
#include "Engine.h" |
#include "Engine.h" |
28 |
#include "EngineChannel.h" |
#include "EngineChannel.h" |
29 |
|
|
30 |
|
#define LN_10_DIV_20 0.115129254649702 |
31 |
|
|
32 |
namespace LinuxSampler { namespace sfz { |
namespace LinuxSampler { namespace sfz { |
33 |
|
|
34 |
Voice::Voice() { |
Voice::Voice() { |
69 |
Voice::RegionInfo Voice::GetRegionInfo() { |
Voice::RegionInfo Voice::GetRegionInfo() { |
70 |
RegionInfo ri; |
RegionInfo ri; |
71 |
ri.UnityNote = pRegion->pitch_keycenter; |
ri.UnityNote = pRegion->pitch_keycenter; |
72 |
ri.FineTune = pRegion->tune; |
ri.FineTune = pRegion->tune + pRegion->transpose * 100; |
73 |
ri.Pan = int(pRegion->pan * 0.63); // convert from -100..100 to -64..63 |
ri.Pan = int(pRegion->pan * 0.63); // convert from -100..100 to -64..63 |
74 |
ri.SampleStartOffset = 0; // TODO: |
ri.SampleStartOffset = 0; // TODO: |
75 |
|
|
78 |
ri.EG1Hold = pRegion->ampeg_hold; |
ri.EG1Hold = pRegion->ampeg_hold; |
79 |
ri.EG1Decay1 = pRegion->ampeg_decay; |
ri.EG1Decay1 = pRegion->ampeg_decay; |
80 |
ri.EG1Decay2 = pRegion->ampeg_decay; |
ri.EG1Decay2 = pRegion->ampeg_decay; |
81 |
ri.EG1Sustain = pRegion->ampeg_sustain; |
ri.EG1Sustain = pRegion->ampeg_sustain * 10; |
82 |
ri.EG1InfiniteSustain = true; |
ri.EG1InfiniteSustain = true; |
83 |
ri.EG1Release = pRegion->ampeg_release; |
ri.EG1Release = pRegion->ampeg_release; |
84 |
|
|
85 |
ri.EG2PreAttack = pRegion->fileg_start; |
ri.EG2PreAttack = pRegion->fileg_start * 10; |
86 |
ri.EG2Attack = pRegion->fileg_attack; |
ri.EG2Attack = pRegion->fileg_attack; |
87 |
//ri.EG2Hold = pRegion->fileg_hold; // TODO: |
//ri.EG2Hold = pRegion->fileg_hold; // TODO: |
88 |
ri.EG2Decay1 = pRegion->fileg_decay; |
ri.EG2Decay1 = pRegion->fileg_decay; |
89 |
ri.EG2Decay2 = pRegion->fileg_decay; |
ri.EG2Decay2 = pRegion->fileg_decay; |
90 |
ri.EG2Sustain = pRegion->fileg_sustain; |
ri.EG2Sustain = pRegion->fileg_sustain * 10; |
91 |
ri.EG2InfiniteSustain = true; |
ri.EG2InfiniteSustain = true; |
92 |
ri.EG2Release = pRegion->fileg_release; |
ri.EG2Release = pRegion->fileg_release; |
93 |
|
|
97 |
ri.VCFType = ::gig::vcf_type_lowpass; // TODO: |
ri.VCFType = ::gig::vcf_type_lowpass; // TODO: |
98 |
ri.VCFResonance = 0; // TODO: |
ri.VCFResonance = 0; // TODO: |
99 |
|
|
100 |
ri.ReleaseTriggerDecay = 0; |
// rt_decay is in dB. Precalculate a suitable value for exp in |
101 |
|
// GetReleaseTriggerAttenuation: -ln(10) / 20 * rt_decay |
102 |
|
ri.ReleaseTriggerDecay = -LN_10_DIV_20 * pRegion->rt_decay; |
103 |
|
|
104 |
return ri; |
return ri; |
105 |
} |
} |
113 |
} |
} |
114 |
|
|
115 |
double Voice::GetSampleAttenuation() { |
double Voice::GetSampleAttenuation() { |
116 |
return 1.0; // TODO: |
return exp(LN_10_DIV_20 * pRegion->volume); |
117 |
} |
} |
118 |
|
|
119 |
double Voice::GetVelocityAttenuation(uint8_t MIDIKeyVelocity) { |
double Voice::GetVelocityAttenuation(uint8_t MIDIKeyVelocity) { |
120 |
return double(MIDIKeyVelocity) / 127.0f; // TODO: |
return pRegion->amp_velcurve[MIDIKeyVelocity]; |
121 |
} |
} |
122 |
|
|
123 |
double Voice::GetVelocityRelease(uint8_t MIDIKeyVelocity) { |
double Voice::GetVelocityRelease(uint8_t MIDIKeyVelocity) { |
206 |
return eg; |
return eg; |
207 |
} |
} |
208 |
|
|
209 |
double Voice::GetEG2ControllerValue(uint8_t MIDIKeyVelocity) { |
void Voice::TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) { |
210 |
|
|
211 |
|
// TODO: controller modulation |
212 |
|
|
213 |
|
// first check if there is a v2 EG for amplitude |
214 |
|
for (int i = 0 ; i < pRegion->eg.size() ; i++) { |
215 |
|
if (pRegion->eg[i].amplitude > 0) { |
216 |
|
// TODO: actually use the value of the amplitude parameter |
217 |
|
pEG1 = &EG1; |
218 |
|
EG1.trigger(pRegion->eg[i], sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE, velocity); |
219 |
|
return; |
220 |
|
} |
221 |
|
} |
222 |
|
|
223 |
|
// otherwise use the v1 EGADSR |
224 |
|
pEG1 = &EGADSR1; |
225 |
|
EGADSR1.trigger(uint(RgnInfo.EG1PreAttack), |
226 |
|
RgnInfo.EG1Attack, |
227 |
|
RgnInfo.EG1Hold, |
228 |
|
RgnInfo.EG1Decay1, |
229 |
|
uint(RgnInfo.EG1Sustain), |
230 |
|
RgnInfo.EG1Release, |
231 |
|
sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
232 |
|
} |
233 |
|
|
234 |
|
double Voice::GetEG2ControllerValue(uint8_t MIDIKeyVelocity) { |
235 |
/*double eg2controllervalue = 0; |
/*double eg2controllervalue = 0; |
236 |
switch (pRegion->EG2Controller.type) { |
switch (pRegion->EG2Controller.type) { |
237 |
case ::gig::eg2_ctrl_t::type_none: // no controller defined |
case ::gig::eg2_ctrl_t::type_none: // no controller defined |
496 |
return 0; |
return 0; |
497 |
} |
} |
498 |
|
|
499 |
|
float Voice::GetReleaseTriggerAttenuation(float noteLength) { |
500 |
|
// pow(10, -rt_decay * noteLength / 20): |
501 |
|
return expf(RgnInfo.ReleaseTriggerDecay * noteLength); |
502 |
|
} |
503 |
|
|
504 |
}} // namespace LinuxSampler::sfz |
}} // namespace LinuxSampler::sfz |