22 |
|
|
23 |
#include "SfzSignalUnitRack.h" |
#include "SfzSignalUnitRack.h" |
24 |
#include "Voice.h" |
#include "Voice.h" |
25 |
|
#include <SF.h> |
26 |
|
|
27 |
namespace LinuxSampler { namespace sfz { |
namespace LinuxSampler { namespace sfz { |
28 |
|
|
78 |
GetSampleRate()); |
GetSampleRate()); |
79 |
} |
} |
80 |
|
|
81 |
|
|
82 |
|
void FilEGUnit::Trigger() { |
83 |
|
::sfz::Region* const pRegion = pVoice->pRegion; |
84 |
|
depth = pRegion->fileg_depth; |
85 |
|
|
86 |
|
// the length of the decay and release curves are dependent on the velocity |
87 |
|
const double velrelease = 1 / pVoice->GetVelocityRelease(pVoice->MIDIVelocity); |
88 |
|
|
89 |
|
// set the delay trigger |
90 |
|
uiDelayTrigger = (pRegion->fileg_delay + pRegion->fileg_vel2delay * velrelease) * GetSampleRate(); |
91 |
|
|
92 |
|
EG.trigger(uint(pRegion->fileg_start * 10), |
93 |
|
std::max(0.0, pRegion->fileg_attack + pRegion->fileg_vel2attack * velrelease), |
94 |
|
std::max(0.0, pRegion->fileg_hold + pRegion->fileg_vel2hold * velrelease), |
95 |
|
std::max(0.0, pRegion->fileg_decay + pRegion->fileg_vel2decay * velrelease), |
96 |
|
uint(std::min(std::max(0.0, 10 * (pRegion->fileg_sustain + pRegion->fileg_vel2sustain * velrelease)), 1000.0)), |
97 |
|
std::max(0.0, pRegion->fileg_release + pRegion->fileg_vel2release * velrelease), |
98 |
|
GetSampleRate()); |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
void LFOUnit::Increment() { |
void LFOUnit::Increment() { |
103 |
if (DelayStage()) return; |
if (DelayStage()) return; |
115 |
uiDelayTrigger = pLfoInfo->delay * GetSampleRate(); |
uiDelayTrigger = pLfoInfo->delay * GetSampleRate(); |
116 |
} |
} |
117 |
|
|
118 |
|
void LFOv1Unit::Trigger() { |
119 |
|
LFOUnit::Trigger(); |
120 |
|
|
121 |
|
lfo.trigger ( |
122 |
|
pLfoInfo->freq, |
123 |
|
start_level_mid, |
124 |
|
1, 0, false, GetSampleRate() |
125 |
|
); |
126 |
|
lfo.update(0); |
127 |
|
} |
128 |
|
|
129 |
void LFOv2Unit::Trigger() { |
void LFOv2Unit::Trigger() { |
130 |
LFOUnit::Trigger(); |
LFOUnit::Trigger(); |
131 |
|
|
136 |
); |
); |
137 |
lfo.update(0); |
lfo.update(0); |
138 |
} |
} |
139 |
|
|
140 |
|
void AmpLFOUnit::Trigger() { |
141 |
|
::sfz::Region* const pRegion = pVoice->pRegion; |
142 |
|
pLfoInfo->delay = pRegion->amplfo_delay; |
143 |
|
pLfoInfo->freq = pRegion->amplfo_freq; |
144 |
|
pLfoInfo->volume = pRegion->amplfo_depth; |
145 |
|
|
146 |
|
LFOv1Unit::Trigger(); |
147 |
|
} |
148 |
|
|
149 |
|
void PitchLFOUnit::Trigger() { |
150 |
|
::sfz::Region* const pRegion = pVoice->pRegion; |
151 |
|
pLfoInfo->delay = pRegion->pitchlfo_delay; |
152 |
|
pLfoInfo->freq = pRegion->pitchlfo_freq; |
153 |
|
pLfoInfo->pitch = pRegion->pitchlfo_depth; |
154 |
|
|
155 |
|
LFOv1Unit::Trigger(); |
156 |
|
} |
157 |
|
|
158 |
|
void FilLFOUnit::Trigger() { |
159 |
|
::sfz::Region* const pRegion = pVoice->pRegion; |
160 |
|
pLfoInfo->delay = pRegion->fillfo_delay; |
161 |
|
pLfoInfo->freq = pRegion->fillfo_freq; |
162 |
|
pLfoInfo->cutoff = pRegion->fillfo_depth; |
163 |
|
|
164 |
|
LFOv1Unit::Trigger(); |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack): EndpointSignalUnit(rack) { |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack): EndpointSignalUnit(rack) { |
197 |
vol += eg->GetLevel() * (eg->pEGInfo->amplitude / 100.0f); |
vol += eg->GetLevel() * (eg->pEGInfo->amplitude / 100.0f); |
198 |
} |
} |
199 |
|
|
200 |
|
AmpLFOUnit* u = &(GetRack()->suAmpLFO); |
201 |
|
vol *= u->Active() ? ::sf2::ToRatio((u->GetLevel() * u->pLfoInfo->volume) * 10.0) : 1; |
202 |
|
|
203 |
return vol; |
return vol; |
204 |
} |
} |
205 |
|
|
206 |
float EndpointUnit::GetFilterCutoff() { |
float EndpointUnit::GetFilterCutoff() { |
207 |
float val = 1; |
float val; |
208 |
|
|
209 |
|
FilLFOUnit* u = &(GetRack()->suFilLFO); |
210 |
|
val = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->pLfoInfo->cutoff) : 1; |
211 |
|
|
212 |
|
FilEGUnit* u2 = &(GetRack()->suFilEG); |
213 |
|
val *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * u2->depth) : 1; |
214 |
|
|
215 |
for (int i = 0; i < GetRack()->filLFOs.size(); i++) { |
for (int i = 0; i < GetRack()->filLFOs.size(); i++) { |
216 |
LFOv2Unit* lfo = GetRack()->filLFOs[i]; |
LFOv2Unit* lfo = GetRack()->filLFOs[i]; |
224 |
} |
} |
225 |
|
|
226 |
float EndpointUnit::GetPitch() { |
float EndpointUnit::GetPitch() { |
227 |
|
double p; |
228 |
EGv1Unit* u = &(GetRack()->suPitchEG); |
EGv1Unit* u = &(GetRack()->suPitchEG); |
229 |
double pitchEg = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1; |
p = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1; |
230 |
return pitchEg; |
|
231 |
|
PitchLFOUnit* u2 = &(GetRack()->suPitchLFO); |
232 |
|
p *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * u2->pLfoInfo->pitch) : 1; |
233 |
|
|
234 |
|
return p; |
235 |
} |
} |
236 |
|
|
237 |
float EndpointUnit::GetResonance() { |
float EndpointUnit::GetResonance() { |
265 |
|
|
266 |
|
|
267 |
SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice) |
SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice) |
268 |
: SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suPitchEG(this), |
: SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suFilEG(this), suPitchEG(this), |
269 |
EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), |
EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), |
270 |
|
suAmpLFO(this), suPitchLFO(this), suFilLFO(this), |
271 |
LFOs(maxLfoCount), filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount) |
LFOs(maxLfoCount), filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount) |
272 |
{ |
{ |
273 |
suEndpoint.pVoice = suVolEG.pVoice = suPitchEG.pVoice = voice; |
suEndpoint.pVoice = suVolEG.pVoice = suFilEG.pVoice = suPitchEG.pVoice = voice; |
274 |
|
suAmpLFO.pVoice = suPitchLFO.pVoice = suFilLFO.pVoice = voice; |
275 |
|
|
276 |
for (int i = 0; i < EGs.capacity(); i++) { |
for (int i = 0; i < EGs.capacity(); i++) { |
277 |
EGs[i] = new EGv2Unit(this); |
EGs[i] = new EGv2Unit(this); |
355 |
Units.clear(); |
Units.clear(); |
356 |
|
|
357 |
Units.add(&suVolEG); |
Units.add(&suVolEG); |
358 |
|
Units.add(&suFilEG); |
359 |
Units.add(&suPitchEG); |
Units.add(&suPitchEG); |
360 |
|
Units.add(&suPitchLFO); |
361 |
|
Units.add(&suAmpLFO); |
362 |
|
Units.add(&suFilLFO); |
363 |
|
|
364 |
for (int i = 0; i < EGs.size(); i++) { |
for (int i = 0; i < EGs.size(); i++) { |
365 |
Units.add(EGs[i]); |
Units.add(EGs[i]); |