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-2020 Christian Schoenebeck * |
7 |
* Copyright (C) 2009-2011 Christian Schoenebeck and Grigor Iliev * |
* Copyright (C) 2009-2012 Grigor Iliev * |
8 |
|
* Copyright (C) 2013-2017 Andreas Persson * |
9 |
* * |
* * |
10 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
11 |
* 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 |
AbstractVoice::AbstractVoice(SignalUnitRack* pRack): pSignalUnitRack(pRack) { |
AbstractVoice::AbstractVoice(SignalUnitRack* pRack): pSignalUnitRack(pRack) { |
31 |
pEngineChannel = NULL; |
pEngineChannel = NULL; |
32 |
pLFO1 = new LFOUnsigned(1.0f); // amplitude LFO (0..1 range) |
pLFO1 = new LFOClusterUnsigned(1.0f); // amplitude LFO (0..1 range) |
33 |
pLFO2 = new LFOUnsigned(1.0f); // filter LFO (0..1 range) |
pLFO2 = new LFOClusterUnsigned(1.0f); // filter LFO (0..1 range) |
34 |
pLFO3 = new LFOSigned(1200.0f); // pitch LFO (-1200..+1200 range) |
pLFO3 = new LFOClusterSigned(1200.0f); // pitch LFO (-1200..+1200 range) |
35 |
PlaybackState = playback_state_end; |
PlaybackState = playback_state_end; |
36 |
SynthesisMode = 0; // set all mode bits to 0 first |
SynthesisMode = 0; // set all mode bits to 0 first |
37 |
// select synthesis implementation (asm core is not supported ATM) |
// select synthesis implementation (asm core is not supported ATM) |
44 |
|
|
45 |
finalSynthesisParameters.filterLeft.Reset(); |
finalSynthesisParameters.filterLeft.Reset(); |
46 |
finalSynthesisParameters.filterRight.Reset(); |
finalSynthesisParameters.filterRight.Reset(); |
47 |
|
|
48 |
|
pEq = NULL; |
49 |
|
bEqSupport = false; |
50 |
} |
} |
51 |
|
|
52 |
AbstractVoice::~AbstractVoice() { |
AbstractVoice::~AbstractVoice() { |
53 |
if (pLFO1) delete pLFO1; |
if (pLFO1) delete pLFO1; |
54 |
if (pLFO2) delete pLFO2; |
if (pLFO2) delete pLFO2; |
55 |
if (pLFO3) delete pLFO3; |
if (pLFO3) delete pLFO3; |
56 |
|
|
57 |
|
if(pEq != NULL) delete pEq; |
58 |
|
} |
59 |
|
|
60 |
|
void AbstractVoice::CreateEq() { |
61 |
|
if(!bEqSupport) return; |
62 |
|
if(pEq != NULL) delete pEq; |
63 |
|
pEq = new EqSupport; |
64 |
|
pEq->InitEffect(GetEngine()->pAudioOutputDevice); |
65 |
} |
} |
66 |
|
|
67 |
/** |
/** |
111 |
#endif // CONFIG_DEVMODE |
#endif // CONFIG_DEVMODE |
112 |
|
|
113 |
Type = VoiceType; |
Type = VoiceType; |
114 |
MIDIKey = itNoteOnEvent->Param.Note.Key; |
pNote = pEngineChannel->pEngine->NoteByID( itNoteOnEvent->Param.Note.ID ); |
115 |
PlaybackState = playback_state_init; // mark voice as triggered, but no audio rendered yet |
PlaybackState = playback_state_init; // mark voice as triggered, but no audio rendered yet |
116 |
Delay = itNoteOnEvent->FragmentPos(); |
Delay = itNoteOnEvent->FragmentPos(); |
117 |
itTriggerEvent = itNoteOnEvent; |
itTriggerEvent = itNoteOnEvent; |
118 |
itKillEvent = Pool<Event>::Iterator(); |
itKillEvent = Pool<Event>::Iterator(); |
119 |
MidiKeyBase* pKeyInfo = GetMidiKeyInfo(MIDIKey); |
MidiKeyBase* pKeyInfo = GetMidiKeyInfo(MIDIKey()); |
120 |
|
|
121 |
pGroupEvents = iKeyGroup ? pEngineChannel->ActiveKeyGroups[iKeyGroup] : 0; |
// when editing key groups with an instrument editor while sound was |
122 |
|
// already loaded, ActiveKeyGroups may not have the KeyGroup in question |
123 |
|
// so use find() here instead of array subscript operator[] to avoid an |
124 |
|
// implied creation of a NULL entry, to prevent a crash while editing |
125 |
|
// instruments |
126 |
|
{ |
127 |
|
AbstractEngineChannel::ActiveKeyGroupMap::const_iterator it = |
128 |
|
pEngineChannel->ActiveKeyGroups.find(iKeyGroup); |
129 |
|
pGroupEvents = |
130 |
|
(iKeyGroup && it != pEngineChannel->ActiveKeyGroups.end()) ? |
131 |
|
it->second : NULL; |
132 |
|
} |
133 |
|
|
134 |
SmplInfo = GetSampleInfo(); |
SmplInfo = GetSampleInfo(); |
135 |
RgnInfo = GetRegionInfo(); |
RgnInfo = GetRegionInfo(); |
136 |
InstrInfo = GetInstrumentInfo(); |
InstrInfo = GetInstrumentInfo(); |
137 |
|
|
138 |
|
MIDIPan = CalculatePan(pEngineChannel->iLastPanRequest); |
139 |
|
|
140 |
AboutToTrigger(); |
AboutToTrigger(); |
141 |
|
|
142 |
// calculate volume |
// calculate volume |
143 |
const double velocityAttenuation = GetVelocityAttenuation(itNoteOnEvent->Param.Note.Velocity); |
const double velocityAttenuation = GetVelocityAttenuation(MIDIVelocity()); |
144 |
float volume = CalculateVolume(velocityAttenuation) * pKeyInfo->Volume; |
float volume = CalculateVolume(velocityAttenuation) * pKeyInfo->Volume; |
145 |
if (volume <= 0) return -1; |
if (volume <= 0) return -1; |
146 |
|
|
150 |
SYNTHESIS_MODE_SET_BITDEPTH24(SynthesisMode, SmplInfo.BitDepth == 24); |
SYNTHESIS_MODE_SET_BITDEPTH24(SynthesisMode, SmplInfo.BitDepth == 24); |
151 |
|
|
152 |
// get starting crossfade volume level |
// get starting crossfade volume level |
153 |
float crossfadeVolume = CalculateCrossfadeVolume(itNoteOnEvent->Param.Note.Velocity); |
float crossfadeVolume = CalculateCrossfadeVolume(MIDIVelocity()); |
154 |
|
|
155 |
VolumeLeft = volume * pKeyInfo->PanLeft * AbstractEngine::PanCurve[64 - RgnInfo.Pan]; |
VolumeLeft = volume * pKeyInfo->PanLeft; |
156 |
VolumeRight = volume * pKeyInfo->PanRight * AbstractEngine::PanCurve[64 + RgnInfo.Pan]; |
VolumeRight = volume * pKeyInfo->PanRight; |
157 |
|
|
158 |
float subfragmentRate = GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
// this rate is used for rather mellow volume fades |
159 |
|
const float subfragmentRate = GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
160 |
|
// this rate is used for very fast volume fades |
161 |
|
const float quickRampRate = RTMath::Min(subfragmentRate, GetEngine()->SampleRate * 0.001f /* approx. 13ms */); |
162 |
CrossfadeSmoother.trigger(crossfadeVolume, subfragmentRate); |
CrossfadeSmoother.trigger(crossfadeVolume, subfragmentRate); |
163 |
|
|
164 |
VolumeSmoother.trigger(pEngineChannel->MidiVolume, subfragmentRate); |
VolumeSmoother.trigger(pEngineChannel->MidiVolume, subfragmentRate); |
165 |
PanLeftSmoother.trigger(pEngineChannel->GlobalPanLeft, subfragmentRate); |
NoteVolume.setCurveOnly(pNote ? pNote->Override.VolumeCurve : DEFAULT_FADE_CURVE); |
166 |
PanRightSmoother.trigger(pEngineChannel->GlobalPanRight, subfragmentRate); |
NoteVolume.setCurrentValue(pNote ? pNote->Override.Volume.Value : 1.f); |
167 |
|
NoteVolume.setDefaultDuration(pNote ? pNote->Override.VolumeTime : DEFAULT_NOTE_VOLUME_TIME_S); |
168 |
|
NoteVolume.setFinal(pNote ? pNote->Override.Volume.Final : false); |
169 |
|
|
170 |
// Check if the sample needs disk streaming or is too short for that |
// Check if the sample needs disk streaming or is too short for that |
171 |
long cachedsamples = GetSampleCacheSize() / SmplInfo.FrameSize; |
long cachedsamples = GetSampleCacheSize() / SmplInfo.FrameSize; |
189 |
RAMLoop = (SmplInfo.HasLoops && (SmplInfo.LoopStart + SmplInfo.LoopLength) <= MaxRAMPos); |
RAMLoop = (SmplInfo.HasLoops && (SmplInfo.LoopStart + SmplInfo.LoopLength) <= MaxRAMPos); |
190 |
|
|
191 |
if (OrderNewStream()) return -1; |
if (OrderNewStream()) return -1; |
192 |
dmsg(4,("Disk voice launched (cached samples: %d, total Samples: %d, MaxRAMPos: %d, RAMLooping: %s)\n", cachedsamples, SmplInfo.TotalFrameCount, MaxRAMPos, (RAMLoop) ? "yes" : "no")); |
dmsg(4,("Disk voice launched (cached samples: %ld, total Samples: %d, MaxRAMPos: %lu, RAMLooping: %s)\n", cachedsamples, SmplInfo.TotalFrameCount, MaxRAMPos, (RAMLoop) ? "yes" : "no")); |
193 |
} |
} |
194 |
else { // RAM only voice |
else { // RAM only voice |
195 |
MaxRAMPos = cachedsamples; |
MaxRAMPos = cachedsamples; |
205 |
} |
} |
206 |
|
|
207 |
Pitch = CalculatePitchInfo(PitchBend); |
Pitch = CalculatePitchInfo(PitchBend); |
208 |
|
NotePitch.setCurveOnly(pNote ? pNote->Override.PitchCurve : DEFAULT_FADE_CURVE); |
209 |
|
NotePitch.setCurrentValue(pNote ? pNote->Override.Pitch.Value : 1.0f); |
210 |
|
NotePitch.setFinal(pNote ? pNote->Override.Pitch.Final : false); |
211 |
|
NotePitch.setDefaultDuration(pNote ? pNote->Override.PitchTime : DEFAULT_NOTE_PITCH_TIME_S); |
212 |
|
NoteCutoff.Value = (pNote) ? pNote->Override.Cutoff.Value : 1.0f; |
213 |
|
NoteCutoff.Final = (pNote) ? pNote->Override.Cutoff.isFinal() : false; |
214 |
|
NoteResonance.Value = (pNote) ? pNote->Override.Resonance.Value : 1.0f; |
215 |
|
NoteResonance.Final = (pNote) ? pNote->Override.Resonance.Final : false; |
216 |
|
|
217 |
// the length of the decay and release curves are dependent on the velocity |
// the length of the decay and release curves are dependent on the velocity |
218 |
const double velrelease = 1 / GetVelocityRelease(itNoteOnEvent->Param.Note.Velocity); |
const double velrelease = 1 / GetVelocityRelease(MIDIVelocity()); |
219 |
|
|
220 |
if (pSignalUnitRack == NULL) { // setup EG 1 (VCA EG) |
if (pSignalUnitRack == NULL) { // setup EG 1 (VCA EG) |
221 |
// get current value of EG1 controller |
// get current value of EG1 controller |
222 |
double eg1controllervalue = GetEG1ControllerValue(itNoteOnEvent->Param.Note.Velocity); |
double eg1controllervalue = GetEG1ControllerValue(MIDIVelocity()); |
223 |
|
|
224 |
// calculate influence of EG1 controller on EG1's parameters |
// calculate influence of EG1 controller on EG1's parameters |
225 |
EGInfo egInfo = CalculateEG1ControllerInfluence(eg1controllervalue); |
EGInfo egInfo = CalculateEG1ControllerInfluence(eg1controllervalue); |
226 |
|
|
227 |
TriggerEG1(egInfo, velrelease, velocityAttenuation, GetEngine()->SampleRate, itNoteOnEvent->Param.Note.Velocity); |
if (pNote) { |
228 |
|
pNote->Override.Attack.applyTo(egInfo.Attack); |
229 |
|
pNote->Override.Decay.applyTo(egInfo.Decay); |
230 |
|
pNote->Override.Release.applyTo(egInfo.Release); |
231 |
|
} |
232 |
|
|
233 |
|
TriggerEG1(egInfo, velrelease, velocityAttenuation, GetEngine()->SampleRate, MIDIVelocity()); |
234 |
} else { |
} else { |
235 |
pSignalUnitRack->Trigger(); |
pSignalUnitRack->Trigger(); |
236 |
} |
} |
237 |
|
|
238 |
#ifdef CONFIG_INTERPOLATE_VOLUME |
const uint8_t pan = (pSignalUnitRack) ? pSignalUnitRack->GetEndpointUnit()->CalculatePan(MIDIPan) : MIDIPan; |
239 |
|
for (int c = 0; c < 2; ++c) { |
240 |
|
float value = (pNote) ? AbstractEngine::PanCurveValueNorm(pNote->Override.Pan.Value, c) : 1.f; |
241 |
|
NotePan[c].setCurveOnly(pNote ? pNote->Override.PanCurve : DEFAULT_FADE_CURVE); |
242 |
|
NotePan[c].setCurrentValue(value); |
243 |
|
NotePan[c].setFinal(pNote ? pNote->Override.Pan.Final : false); |
244 |
|
NotePan[c].setDefaultDuration(pNote ? pNote->Override.PanTime : DEFAULT_NOTE_PAN_TIME_S); |
245 |
|
} |
246 |
|
|
247 |
|
PanLeftSmoother.trigger( |
248 |
|
AbstractEngine::PanCurve[128 - pan], |
249 |
|
quickRampRate //NOTE: maybe we should have 2 separate pan smoothers, one for MIDI CC10 (with slow rate) and one for instrument script change_pan() calls (with fast rate) |
250 |
|
); |
251 |
|
PanRightSmoother.trigger( |
252 |
|
AbstractEngine::PanCurve[pan], |
253 |
|
quickRampRate //NOTE: maybe we should have 2 separate pan smoothers, one for MIDI CC10 (with slow rate) and one for instrument script change_pan() calls (with fast rate) |
254 |
|
); |
255 |
|
|
256 |
|
#if CONFIG_INTERPOLATE_VOLUME |
257 |
// setup initial volume in synthesis parameters |
// setup initial volume in synthesis parameters |
258 |
#ifdef CONFIG_PROCESS_MUTED_CHANNELS |
#if CONFIG_PROCESS_MUTED_CHANNELS |
259 |
if (pEngineChannel->GetMute()) { |
if (pEngineChannel->GetMute()) { |
260 |
finalSynthesisParameters.fFinalVolumeLeft = 0; |
finalSynthesisParameters.fFinalVolumeLeft = 0; |
261 |
finalSynthesisParameters.fFinalVolumeRight = 0; |
finalSynthesisParameters.fFinalVolumeRight = 0; |
263 |
else |
else |
264 |
#else |
#else |
265 |
{ |
{ |
266 |
float finalVolume; |
float finalVolume = pEngineChannel->MidiVolume * crossfadeVolume; |
267 |
|
float fModVolume; |
268 |
if (pSignalUnitRack == NULL) { |
if (pSignalUnitRack == NULL) { |
269 |
finalVolume = pEngineChannel->MidiVolume * crossfadeVolume * pEG1->getLevel(); |
fModVolume = pEG1->getLevel(); |
270 |
} else { |
} else { |
271 |
finalVolume = pEngineChannel->MidiVolume * crossfadeVolume * pSignalUnitRack->GetEndpointUnit()->GetVolume(); |
fModVolume = pSignalUnitRack->GetEndpointUnit()->GetVolume(); |
272 |
} |
} |
273 |
|
NoteVolume.applyCurrentValueTo(fModVolume); |
274 |
|
finalVolume *= fModVolume; |
275 |
|
|
276 |
finalSynthesisParameters.fFinalVolumeLeft = finalVolume * VolumeLeft * pEngineChannel->GlobalPanLeft; |
float panL = PanLeftSmoother.render(); |
277 |
finalSynthesisParameters.fFinalVolumeRight = finalVolume * VolumeRight * pEngineChannel->GlobalPanRight; |
float panR = PanRightSmoother.render(); |
278 |
|
NotePan[0].applyCurrentValueTo(panL); |
279 |
|
NotePan[1].applyCurrentValueTo(panR); |
280 |
|
|
281 |
|
finalSynthesisParameters.fFinalVolumeLeft = finalVolume * VolumeLeft * panL; |
282 |
|
finalSynthesisParameters.fFinalVolumeRight = finalVolume * VolumeRight * panR; |
283 |
} |
} |
284 |
#endif |
#endif |
285 |
#endif |
#endif |
288 |
// setup EG 2 (VCF Cutoff EG) |
// setup EG 2 (VCF Cutoff EG) |
289 |
{ |
{ |
290 |
// get current value of EG2 controller |
// get current value of EG2 controller |
291 |
double eg2controllervalue = GetEG2ControllerValue(itNoteOnEvent->Param.Note.Velocity); |
double eg2controllervalue = GetEG2ControllerValue(MIDIVelocity()); |
292 |
|
|
293 |
// calculate influence of EG2 controller on EG2's parameters |
// calculate influence of EG2 controller on EG2's parameters |
294 |
EGInfo egInfo = CalculateEG2ControllerInfluence(eg2controllervalue); |
EGInfo egInfo = CalculateEG2ControllerInfluence(eg2controllervalue); |
295 |
|
|
296 |
TriggerEG2(egInfo, velrelease, velocityAttenuation, GetEngine()->SampleRate, itNoteOnEvent->Param.Note.Velocity); |
if (pNote) { |
297 |
|
pNote->Override.CutoffAttack.applyTo(egInfo.Attack); |
298 |
|
pNote->Override.CutoffDecay.applyTo(egInfo.Decay); |
299 |
|
pNote->Override.CutoffRelease.applyTo(egInfo.Release); |
300 |
|
} |
301 |
|
|
302 |
|
TriggerEG2(egInfo, velrelease, velocityAttenuation, GetEngine()->SampleRate, MIDIVelocity()); |
303 |
} |
} |
304 |
|
|
305 |
|
|
308 |
// if portamento mode is on, we dedicate EG3 purely for portamento, otherwise if portamento is off we do as told by the patch |
// if portamento mode is on, we dedicate EG3 purely for portamento, otherwise if portamento is off we do as told by the patch |
309 |
bool bPortamento = pEngineChannel->PortamentoMode && pEngineChannel->PortamentoPos >= 0.0f; |
bool bPortamento = pEngineChannel->PortamentoMode && pEngineChannel->PortamentoPos >= 0.0f; |
310 |
float eg3depth = (bPortamento) |
float eg3depth = (bPortamento) |
311 |
? RTMath::CentsToFreqRatio((pEngineChannel->PortamentoPos - (float) MIDIKey) * 100) |
? RTMath::CentsToFreqRatio((pEngineChannel->PortamentoPos - (float) MIDIKey()) * 100) |
312 |
: RTMath::CentsToFreqRatio(RgnInfo.EG3Depth); |
: RTMath::CentsToFreqRatio(RgnInfo.EG3Depth); |
313 |
float eg3time = (bPortamento) |
float eg3time = (bPortamento) |
314 |
? pEngineChannel->PortamentoTime |
? pEngineChannel->PortamentoTime |
358 |
VCFResonanceCtrl.value = pEngineChannel->ControllerTable[VCFResonanceCtrl.controller]; |
VCFResonanceCtrl.value = pEngineChannel->ControllerTable[VCFResonanceCtrl.controller]; |
359 |
|
|
360 |
// calculate cutoff frequency |
// calculate cutoff frequency |
361 |
CutoffBase = CalculateCutoffBase(itNoteOnEvent->Param.Note.Velocity); |
CutoffBase = CalculateCutoffBase(MIDIVelocity()); |
362 |
|
|
363 |
VCFCutoffCtrl.fvalue = CalculateFinalCutoff(CutoffBase); |
VCFCutoffCtrl.fvalue = CalculateFinalCutoff(CutoffBase); |
364 |
|
|
369 |
VCFCutoffCtrl.controller = 0; |
VCFCutoffCtrl.controller = 0; |
370 |
VCFResonanceCtrl.controller = 0; |
VCFResonanceCtrl.controller = 0; |
371 |
} |
} |
372 |
|
|
373 |
|
const bool bEq = |
374 |
|
pSignalUnitRack != NULL && pSignalUnitRack->HasEq() && pEq->HasSupport(); |
375 |
|
|
376 |
|
if (bEq) { |
377 |
|
pEq->GetInChannelLeft()->Clear(); |
378 |
|
pEq->GetInChannelRight()->Clear(); |
379 |
|
pEq->RenderAudio(GetEngine()->pAudioOutputDevice->MaxSamplesPerCycle()); |
380 |
|
} |
381 |
|
|
382 |
return 0; // success |
return 0; // success |
383 |
} |
} |
384 |
|
|
385 |
void AbstractVoice::SetSampleStartOffset() { |
void AbstractVoice::SetSampleStartOffset() { |
386 |
finalSynthesisParameters.dPos = RgnInfo.SampleStartOffset; // offset where we should start playback of sample (0 - 2000 sample points) |
double pos = RgnInfo.SampleStartOffset; // offset where we should start playback of sample |
387 |
Pos = RgnInfo.SampleStartOffset; |
|
388 |
|
// if another sample playback start position was requested by instrument |
389 |
|
// script (built-in script function play_note()) |
390 |
|
if (pNote && pNote->Override.SampleOffset >= 0) { |
391 |
|
double overridePos = |
392 |
|
double(SmplInfo.SampleRate) * double(pNote->Override.SampleOffset) / 1000000.0; |
393 |
|
if (overridePos < SmplInfo.TotalFrameCount) |
394 |
|
pos = overridePos; |
395 |
|
} |
396 |
|
|
397 |
|
finalSynthesisParameters.dPos = pos; |
398 |
|
Pos = pos; |
399 |
} |
} |
400 |
|
|
401 |
/** |
/** |
407 |
* @param Skip - number of sample points to skip in output buffer |
* @param Skip - number of sample points to skip in output buffer |
408 |
*/ |
*/ |
409 |
void AbstractVoice::Synthesize(uint Samples, sample_t* pSrc, uint Skip) { |
void AbstractVoice::Synthesize(uint Samples, sample_t* pSrc, uint Skip) { |
410 |
|
bool delay = false; // Whether the voice playback should be delayed for this call |
411 |
|
|
412 |
|
if (pSignalUnitRack != NULL) { |
413 |
|
uint delaySteps = pSignalUnitRack->GetEndpointUnit()->DelayTrigger(); |
414 |
|
if (delaySteps > 0) { // delay on the endpoint unit means delay of the voice playback |
415 |
|
if (delaySteps >= Samples) { |
416 |
|
pSignalUnitRack->GetEndpointUnit()->DecreaseDelay(Samples); |
417 |
|
delay = true; |
418 |
|
} else { |
419 |
|
pSignalUnitRack->GetEndpointUnit()->DecreaseDelay(delaySteps); |
420 |
|
Samples -= delaySteps; |
421 |
|
Skip += delaySteps; |
422 |
|
} |
423 |
|
} |
424 |
|
} |
425 |
|
|
426 |
AbstractEngineChannel* pChannel = pEngineChannel; |
AbstractEngineChannel* pChannel = pEngineChannel; |
427 |
MidiKeyBase* pMidiKeyInfo = GetMidiKeyInfo(MIDIKey); |
MidiKeyBase* pMidiKeyInfo = GetMidiKeyInfo(MIDIKey()); |
428 |
|
|
429 |
const bool bVoiceRequiresDedicatedRouting = |
const bool bVoiceRequiresDedicatedRouting = |
430 |
pEngineChannel->GetFxSendCount() > 0 && |
pEngineChannel->GetFxSendCount() > 0 && |
431 |
(pMidiKeyInfo->ReverbSend || pMidiKeyInfo->ChorusSend); |
(pMidiKeyInfo->ReverbSend || pMidiKeyInfo->ChorusSend); |
432 |
|
|
433 |
|
const bool bEq = |
434 |
|
pSignalUnitRack != NULL && pSignalUnitRack->HasEq() && pEq->HasSupport(); |
435 |
|
|
436 |
if (bVoiceRequiresDedicatedRouting) { |
if (bEq) { |
437 |
|
pEq->GetInChannelLeft()->Clear(); |
438 |
|
pEq->GetInChannelRight()->Clear(); |
439 |
|
finalSynthesisParameters.pOutLeft = &pEq->GetInChannelLeft()->Buffer()[Skip]; |
440 |
|
finalSynthesisParameters.pOutRight = &pEq->GetInChannelRight()->Buffer()[Skip]; |
441 |
|
pSignalUnitRack->UpdateEqSettings(pEq); |
442 |
|
} else if (bVoiceRequiresDedicatedRouting) { |
443 |
finalSynthesisParameters.pOutLeft = &GetEngine()->pDedicatedVoiceChannelLeft->Buffer()[Skip]; |
finalSynthesisParameters.pOutLeft = &GetEngine()->pDedicatedVoiceChannelLeft->Buffer()[Skip]; |
444 |
finalSynthesisParameters.pOutRight = &GetEngine()->pDedicatedVoiceChannelRight->Buffer()[Skip]; |
finalSynthesisParameters.pOutRight = &GetEngine()->pDedicatedVoiceChannelRight->Buffer()[Skip]; |
445 |
} else { |
} else { |
450 |
|
|
451 |
RTList<Event>::Iterator itCCEvent = pChannel->pEvents->first(); |
RTList<Event>::Iterator itCCEvent = pChannel->pEvents->first(); |
452 |
RTList<Event>::Iterator itNoteEvent; |
RTList<Event>::Iterator itNoteEvent; |
453 |
GetFirstEventOnKey(MIDIKey, itNoteEvent); |
GetFirstEventOnKey(HostKey(), itNoteEvent); |
454 |
|
|
455 |
RTList<Event>::Iterator itGroupEvent; |
RTList<Event>::Iterator itGroupEvent; |
456 |
if (pGroupEvents) itGroupEvent = pGroupEvents->first(); |
if (pGroupEvents && !Orphan) itGroupEvent = pGroupEvents->first(); |
457 |
|
|
458 |
if (itTriggerEvent) { // skip events that happened before this voice was triggered |
if (itTriggerEvent) { // skip events that happened before this voice was triggered |
459 |
while (itCCEvent && itCCEvent->FragmentPos() <= Skip) ++itCCEvent; |
while (itCCEvent && itCCEvent->FragmentPos() <= Skip) ++itCCEvent; |
470 |
} |
} |
471 |
} |
} |
472 |
|
|
473 |
uint killPos; |
uint killPos = 0; |
474 |
if (itKillEvent) { |
if (itKillEvent) { |
475 |
int maxFadeOutPos = Samples - GetEngine()->GetMinFadeOutSamples(); |
int maxFadeOutPos = Samples - GetEngine()->GetMinFadeOutSamples(); |
476 |
if (maxFadeOutPos < 0) { |
if (maxFadeOutPos < 0) { |
482 |
if (pSignalUnitRack == NULL) { |
if (pSignalUnitRack == NULL) { |
483 |
pEG1->enterFadeOutStage(Samples / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
pEG1->enterFadeOutStage(Samples / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
484 |
} else { |
} else { |
485 |
// TODO: |
pSignalUnitRack->EnterFadeOutStage(Samples / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
486 |
} |
} |
487 |
itKillEvent = Pool<Event>::Iterator(); |
itKillEvent = Pool<Event>::Iterator(); |
488 |
} else { |
} else { |
498 |
fFinalCutoff = VCFCutoffCtrl.fvalue; |
fFinalCutoff = VCFCutoffCtrl.fvalue; |
499 |
fFinalResonance = VCFResonanceCtrl.fvalue; |
fFinalResonance = VCFResonanceCtrl.fvalue; |
500 |
|
|
501 |
// process MIDI control change and pitchbend events for this subfragment |
// process MIDI control change, aftertouch and pitchbend events for this subfragment |
502 |
processCCEvents(itCCEvent, iSubFragmentEnd); |
processCCEvents(itCCEvent, iSubFragmentEnd); |
503 |
|
uint8_t pan = MIDIPan; |
504 |
|
if (pSignalUnitRack != NULL) pan = pSignalUnitRack->GetEndpointUnit()->CalculatePan(MIDIPan); |
505 |
|
|
506 |
|
PanLeftSmoother.update(AbstractEngine::PanCurve[128 - pan]); |
507 |
|
PanRightSmoother.update(AbstractEngine::PanCurve[pan]); |
508 |
|
|
509 |
finalSynthesisParameters.fFinalPitch = Pitch.PitchBase * Pitch.PitchBend; |
finalSynthesisParameters.fFinalPitch = Pitch.PitchBase * Pitch.PitchBend; |
510 |
|
|
511 |
float fFinalVolume = VolumeSmoother.render() * CrossfadeSmoother.render(); |
float fFinalVolume = VolumeSmoother.render() * CrossfadeSmoother.render(); |
512 |
#ifdef CONFIG_PROCESS_MUTED_CHANNELS |
#if CONFIG_PROCESS_MUTED_CHANNELS |
513 |
if (pChannel->GetMute()) fFinalVolume = 0; |
if (pChannel->GetMute()) fFinalVolume = 0; |
514 |
#endif |
#endif |
515 |
|
|
517 |
processTransitionEvents(itNoteEvent, iSubFragmentEnd); |
processTransitionEvents(itNoteEvent, iSubFragmentEnd); |
518 |
processGroupEvents(itGroupEvent, iSubFragmentEnd); |
processGroupEvents(itGroupEvent, iSubFragmentEnd); |
519 |
|
|
520 |
|
float fModVolume = 1; |
521 |
|
float fModPitch = 1; |
522 |
|
|
523 |
if (pSignalUnitRack == NULL) { |
if (pSignalUnitRack == NULL) { |
524 |
// if the voice was killed in this subfragment, or if the |
// if the voice was killed in this subfragment, or if the |
525 |
// filter EG is finished, switch EG1 to fade out stage |
// filter EG is finished, switch EG1 to fade out stage |
533 |
// process envelope generators |
// process envelope generators |
534 |
switch (pEG1->getSegmentType()) { |
switch (pEG1->getSegmentType()) { |
535 |
case EG::segment_lin: |
case EG::segment_lin: |
536 |
fFinalVolume *= pEG1->processLin(); |
fModVolume *= pEG1->processLin(); |
537 |
break; |
break; |
538 |
case EG::segment_exp: |
case EG::segment_exp: |
539 |
fFinalVolume *= pEG1->processExp(); |
fModVolume *= pEG1->processExp(); |
540 |
break; |
break; |
541 |
case EG::segment_end: |
case EG::segment_end: |
542 |
fFinalVolume *= pEG1->getLevel(); |
fModVolume *= pEG1->getLevel(); |
543 |
break; // noop |
break; // noop |
544 |
case EG::segment_pow: |
case EG::segment_pow: |
545 |
fFinalVolume *= pEG1->processPow(); |
fModVolume *= pEG1->processPow(); |
546 |
break; |
break; |
547 |
} |
} |
548 |
switch (pEG2->getSegmentType()) { |
switch (pEG2->getSegmentType()) { |
559 |
fFinalCutoff *= pEG2->processPow(); |
fFinalCutoff *= pEG2->processPow(); |
560 |
break; |
break; |
561 |
} |
} |
562 |
if (EG3.active()) finalSynthesisParameters.fFinalPitch *= EG3.render(); |
if (EG3.active()) fModPitch *= EG3.render(); |
563 |
|
|
564 |
// process low frequency oscillators |
// process low frequency oscillators |
565 |
if (bLFO1Enabled) fFinalVolume *= (1.0f - pLFO1->render()); |
if (bLFO1Enabled) fModVolume *= (1.0f - pLFO1->render()); |
566 |
if (bLFO2Enabled) fFinalCutoff *= pLFO2->render(); |
if (bLFO2Enabled) fFinalCutoff *= (1.0f - pLFO2->render()); |
567 |
if (bLFO3Enabled) finalSynthesisParameters.fFinalPitch *= RTMath::CentsToFreqRatio(pLFO3->render()); |
if (bLFO3Enabled) fModPitch *= RTMath::CentsToFreqRatio(pLFO3->render()); |
568 |
} else { |
} else { |
569 |
// if the voice was killed in this subfragment, or if the |
// if the voice was killed in this subfragment, enter fade out stage |
570 |
// filter EG is finished, switch EG1 to fade out stage |
if (itKillEvent && killPos <= iSubFragmentEnd) { |
571 |
/*if ((itKillEvent && killPos <= iSubFragmentEnd) || |
pSignalUnitRack->EnterFadeOutStage(); |
572 |
(SYNTHESIS_MODE_GET_FILTER(SynthesisMode) && |
itKillEvent = Pool<Event>::Iterator(); |
573 |
pEG2->getSegmentType() == EG::segment_end)) { |
} |
574 |
|
|
575 |
|
// if the filter EG is finished, switch EG1 to fade out stage |
576 |
|
/*if (SYNTHESIS_MODE_GET_FILTER(SynthesisMode) && |
577 |
|
pEG2->getSegmentType() == EG::segment_end) { |
578 |
pEG1->enterFadeOutStage(); |
pEG1->enterFadeOutStage(); |
579 |
itKillEvent = Pool<Event>::Iterator(); |
itKillEvent = Pool<Event>::Iterator(); |
580 |
}*/ |
}*/ |
584 |
fFinalCutoff = pSignalUnitRack->GetEndpointUnit()->CalculateFilterCutoff(fFinalCutoff); |
fFinalCutoff = pSignalUnitRack->GetEndpointUnit()->CalculateFilterCutoff(fFinalCutoff); |
585 |
fFinalResonance = pSignalUnitRack->GetEndpointUnit()->CalculateResonance(fFinalResonance); |
fFinalResonance = pSignalUnitRack->GetEndpointUnit()->CalculateResonance(fFinalResonance); |
586 |
|
|
587 |
finalSynthesisParameters.fFinalPitch = |
fModPitch = pSignalUnitRack->GetEndpointUnit()->CalculatePitch(fModPitch); |
|
pSignalUnitRack->GetEndpointUnit()->CalculatePitch(finalSynthesisParameters.fFinalPitch); |
|
|
|
|
588 |
} |
} |
589 |
|
|
590 |
|
NoteVolume.renderApplyTo(fModVolume); |
591 |
|
NotePitch.renderApplyTo(fModPitch); |
592 |
|
NoteCutoff.applyTo(fFinalCutoff); |
593 |
|
NoteResonance.applyTo(fFinalResonance); |
594 |
|
|
595 |
|
fFinalVolume *= fModVolume; |
596 |
|
|
597 |
|
finalSynthesisParameters.fFinalPitch *= fModPitch; |
598 |
|
|
599 |
// limit the pitch so we don't read outside the buffer |
// limit the pitch so we don't read outside the buffer |
600 |
finalSynthesisParameters.fFinalPitch = RTMath::Min(finalSynthesisParameters.fFinalPitch, float(1 << CONFIG_MAX_PITCH)); |
finalSynthesisParameters.fFinalPitch = RTMath::Min(finalSynthesisParameters.fFinalPitch, float(1 << CONFIG_MAX_PITCH)); |
601 |
|
|
614 |
|
|
615 |
// prepare final synthesis parameters structure |
// prepare final synthesis parameters structure |
616 |
finalSynthesisParameters.uiToGo = iSubFragmentEnd - i; |
finalSynthesisParameters.uiToGo = iSubFragmentEnd - i; |
617 |
#ifdef CONFIG_INTERPOLATE_VOLUME |
|
618 |
|
float panL = PanLeftSmoother.render(); |
619 |
|
float panR = PanRightSmoother.render(); |
620 |
|
NotePan[0].renderApplyTo(panL); |
621 |
|
NotePan[1].renderApplyTo(panR); |
622 |
|
|
623 |
|
#if CONFIG_INTERPOLATE_VOLUME |
624 |
finalSynthesisParameters.fFinalVolumeDeltaLeft = |
finalSynthesisParameters.fFinalVolumeDeltaLeft = |
625 |
(fFinalVolume * VolumeLeft * PanLeftSmoother.render() - |
(fFinalVolume * VolumeLeft * panL - |
626 |
finalSynthesisParameters.fFinalVolumeLeft) / finalSynthesisParameters.uiToGo; |
finalSynthesisParameters.fFinalVolumeLeft) / finalSynthesisParameters.uiToGo; |
627 |
finalSynthesisParameters.fFinalVolumeDeltaRight = |
finalSynthesisParameters.fFinalVolumeDeltaRight = |
628 |
(fFinalVolume * VolumeRight * PanRightSmoother.render() - |
(fFinalVolume * VolumeRight * panR - |
629 |
finalSynthesisParameters.fFinalVolumeRight) / finalSynthesisParameters.uiToGo; |
finalSynthesisParameters.fFinalVolumeRight) / finalSynthesisParameters.uiToGo; |
630 |
#else |
#else |
631 |
finalSynthesisParameters.fFinalVolumeLeft = |
finalSynthesisParameters.fFinalVolumeLeft = |
632 |
fFinalVolume * VolumeLeft * PanLeftSmoother.render(); |
fFinalVolume * VolumeLeft * panL; |
633 |
finalSynthesisParameters.fFinalVolumeRight = |
finalSynthesisParameters.fFinalVolumeRight = |
634 |
fFinalVolume * VolumeRight * PanRightSmoother.render(); |
fFinalVolume * VolumeRight * panR; |
635 |
#endif |
#endif |
636 |
// render audio for one subfragment |
// render audio for one subfragment |
637 |
RunSynthesisFunction(SynthesisMode, &finalSynthesisParameters, &loop); |
if (!delay) RunSynthesisFunction(SynthesisMode, &finalSynthesisParameters, &loop); |
638 |
|
|
639 |
if (pSignalUnitRack == NULL) { |
if (pSignalUnitRack == NULL) { |
640 |
// stop the rendering if volume EG is finished |
// stop the rendering if volume EG is finished |
671 |
}*/ |
}*/ |
672 |
// TODO: ^^^ |
// TODO: ^^^ |
673 |
|
|
674 |
pSignalUnitRack->Increment(); |
if (!delay) pSignalUnitRack->Increment(); |
675 |
} |
} |
676 |
|
|
677 |
Pos = newPos; |
Pos = newPos; |
678 |
i = iSubFragmentEnd; |
i = iSubFragmentEnd; |
679 |
} |
} |
680 |
|
|
681 |
|
if (delay) return; |
682 |
|
|
683 |
if (bVoiceRequiresDedicatedRouting) { |
if (bVoiceRequiresDedicatedRouting) { |
684 |
|
if (bEq) { |
685 |
|
pEq->RenderAudio(Samples); |
686 |
|
pEq->GetOutChannelLeft()->CopyTo(GetEngine()->pDedicatedVoiceChannelLeft, Samples); |
687 |
|
pEq->GetOutChannelRight()->CopyTo(GetEngine()->pDedicatedVoiceChannelRight, Samples); |
688 |
|
} |
689 |
optional<float> effectSendLevels[2] = { |
optional<float> effectSendLevels[2] = { |
690 |
pMidiKeyInfo->ReverbSend, |
pMidiKeyInfo->ReverbSend, |
691 |
pMidiKeyInfo->ChorusSend |
pMidiKeyInfo->ChorusSend |
692 |
}; |
}; |
693 |
GetEngine()->RouteDedicatedVoiceChannels(pEngineChannel, effectSendLevels, Samples); |
GetEngine()->RouteDedicatedVoiceChannels(pEngineChannel, effectSendLevels, Samples); |
694 |
|
} else if (bEq) { |
695 |
|
pEq->RenderAudio(Samples); |
696 |
|
pEq->GetOutChannelLeft()->MixTo(pChannel->pChannelLeft, Samples); |
697 |
|
pEq->GetOutChannelRight()->MixTo(pChannel->pChannelRight, Samples); |
698 |
} |
} |
699 |
} |
} |
700 |
|
|
701 |
/** |
/** |
702 |
* Process given list of MIDI control change and pitch bend events for |
* Process given list of MIDI control change, aftertouch and pitch bend |
703 |
* the given time. |
* events for the given time. |
704 |
* |
* |
705 |
* @param itEvent - iterator pointing to the next event to be processed |
* @param itEvent - iterator pointing to the next event to be processed |
706 |
* @param End - youngest time stamp where processing should be stopped |
* @param End - youngest time stamp where processing should be stopped |
707 |
*/ |
*/ |
708 |
void AbstractVoice::processCCEvents(RTList<Event>::Iterator& itEvent, uint End) { |
void AbstractVoice::processCCEvents(RTList<Event>::Iterator& itEvent, uint End) { |
709 |
for (; itEvent && itEvent->FragmentPos() <= End; ++itEvent) { |
for (; itEvent && itEvent->FragmentPos() <= End; ++itEvent) { |
710 |
if (itEvent->Type == Event::type_control_change && itEvent->Param.CC.Controller) { // if (valid) MIDI control change event |
if ((itEvent->Type == Event::type_control_change || itEvent->Type == Event::type_channel_pressure) |
711 |
|
&& itEvent->Param.CC.Controller) // if (valid) MIDI control change event |
712 |
|
{ |
713 |
if (itEvent->Param.CC.Controller == VCFCutoffCtrl.controller) { |
if (itEvent->Param.CC.Controller == VCFCutoffCtrl.controller) { |
714 |
ProcessCutoffEvent(itEvent); |
ProcessCutoffEvent(itEvent); |
715 |
} |
} |
716 |
if (itEvent->Param.CC.Controller == VCFResonanceCtrl.controller) { |
if (itEvent->Param.CC.Controller == VCFResonanceCtrl.controller) { |
717 |
processResonanceEvent(itEvent); |
processResonanceEvent(itEvent); |
718 |
} |
} |
719 |
|
if (itEvent->Param.CC.Controller == CTRL_TABLE_IDX_AFTERTOUCH || |
720 |
|
itEvent->Type == Event::type_channel_pressure) |
721 |
|
{ |
722 |
|
ProcessChannelPressureEvent(itEvent); |
723 |
|
} |
724 |
if (pSignalUnitRack == NULL) { |
if (pSignalUnitRack == NULL) { |
725 |
if (itEvent->Param.CC.Controller == pLFO1->ExtController) { |
if (itEvent->Param.CC.Controller == pLFO1->ExtController) { |
726 |
pLFO1->update(itEvent->Param.CC.Value); |
pLFO1->updateByMIDICtrlValue(itEvent->Param.CC.Value); |
727 |
} |
} |
728 |
if (itEvent->Param.CC.Controller == pLFO2->ExtController) { |
if (itEvent->Param.CC.Controller == pLFO2->ExtController) { |
729 |
pLFO2->update(itEvent->Param.CC.Value); |
pLFO2->updateByMIDICtrlValue(itEvent->Param.CC.Value); |
730 |
} |
} |
731 |
if (itEvent->Param.CC.Controller == pLFO3->ExtController) { |
if (itEvent->Param.CC.Controller == pLFO3->ExtController) { |
732 |
pLFO3->update(itEvent->Param.CC.Value); |
pLFO3->updateByMIDICtrlValue(itEvent->Param.CC.Value); |
733 |
} |
} |
734 |
} |
} |
735 |
if (itEvent->Param.CC.Controller == 7) { // volume |
if (itEvent->Param.CC.Controller == 7) { // volume |
736 |
VolumeSmoother.update(AbstractEngine::VolumeCurve[itEvent->Param.CC.Value]); |
VolumeSmoother.update(AbstractEngine::VolumeCurve[itEvent->Param.CC.Value]); |
737 |
} else if (itEvent->Param.CC.Controller == 10) { // panpot |
} else if (itEvent->Param.CC.Controller == 10) { // panpot |
738 |
PanLeftSmoother.update(AbstractEngine::PanCurve[128 - itEvent->Param.CC.Value]); |
MIDIPan = CalculatePan(itEvent->Param.CC.Value); |
|
PanRightSmoother.update(AbstractEngine::PanCurve[itEvent->Param.CC.Value]); |
|
739 |
} |
} |
740 |
} else if (itEvent->Type == Event::type_pitchbend) { // if pitch bend event |
} else if (itEvent->Type == Event::type_pitchbend) { // if pitch bend event |
741 |
processPitchEvent(itEvent); |
processPitchEvent(itEvent); |
742 |
|
} else if (itEvent->Type == Event::type_note_pressure) { |
743 |
|
ProcessPolyphonicKeyPressureEvent(itEvent); |
744 |
} |
} |
745 |
|
|
746 |
ProcessCCEvent(itEvent); |
ProcessCCEvent(itEvent); |
765 |
} |
} |
766 |
|
|
767 |
/** |
/** |
768 |
* Process given list of MIDI note on, note off and sustain pedal events |
* Process given list of MIDI note on, note off, sustain pedal events and |
769 |
* for the given time. |
* note synthesis parameter events for the given time. |
770 |
* |
* |
771 |
* @param itEvent - iterator pointing to the next event to be processed |
* @param itEvent - iterator pointing to the next event to be processed |
772 |
* @param End - youngest time stamp where processing should be stopped |
* @param End - youngest time stamp where processing should be stopped |
775 |
for (; itEvent && itEvent->FragmentPos() <= End; ++itEvent) { |
for (; itEvent && itEvent->FragmentPos() <= End; ++itEvent) { |
776 |
// some voice types ignore note off |
// some voice types ignore note off |
777 |
if (!(Type & (Voice::type_one_shot | Voice::type_release_trigger | Voice::type_controller_triggered))) { |
if (!(Type & (Voice::type_one_shot | Voice::type_release_trigger | Voice::type_controller_triggered))) { |
778 |
if (itEvent->Type == Event::type_release) { |
if (itEvent->Type == Event::type_release_key) { |
779 |
EnterReleaseStage(); |
EnterReleaseStage(); |
780 |
} else if (itEvent->Type == Event::type_cancel_release) { |
} else if (itEvent->Type == Event::type_cancel_release_key) { |
781 |
if (pSignalUnitRack == NULL) { |
if (pSignalUnitRack == NULL) { |
782 |
pEG1->update(EG::event_cancel_release, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
pEG1->update(EG::event_cancel_release, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
783 |
pEG2->update(EG::event_cancel_release, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
pEG2->update(EG::event_cancel_release, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
786 |
} |
} |
787 |
} |
} |
788 |
} |
} |
789 |
|
// process stop-note events (caused by built-in instrument script function note_off()) |
790 |
|
if (itEvent->Type == Event::type_release_note && pNote && |
791 |
|
pEngineChannel->pEngine->NoteByID( itEvent->Param.Note.ID ) == pNote) |
792 |
|
{ |
793 |
|
EnterReleaseStage(); |
794 |
|
} |
795 |
|
// process kill-note events (caused by built-in instrument script function fade_out()) |
796 |
|
if (itEvent->Type == Event::type_kill_note && pNote && |
797 |
|
pEngineChannel->pEngine->NoteByID( itEvent->Param.Note.ID ) == pNote) |
798 |
|
{ |
799 |
|
Kill(itEvent); |
800 |
|
} |
801 |
|
// process synthesis parameter events (caused by built-in realt-time instrument script functions) |
802 |
|
if (itEvent->Type == Event::type_note_synth_param && pNote && |
803 |
|
pEngineChannel->pEngine->NoteByID( itEvent->Param.NoteSynthParam.NoteID ) == pNote) |
804 |
|
{ |
805 |
|
switch (itEvent->Param.NoteSynthParam.Type) { |
806 |
|
case Event::synth_param_volume: |
807 |
|
NoteVolume.fadeTo(itEvent->Param.NoteSynthParam.AbsValue, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
808 |
|
NoteVolume.setFinal(itEvent->Param.NoteSynthParam.isFinal()); |
809 |
|
break; |
810 |
|
case Event::synth_param_volume_time: |
811 |
|
NoteVolume.setDefaultDuration(itEvent->Param.NoteSynthParam.AbsValue); |
812 |
|
break; |
813 |
|
case Event::synth_param_volume_curve: |
814 |
|
NoteVolume.setCurve((fade_curve_t)itEvent->Param.NoteSynthParam.AbsValue, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
815 |
|
break; |
816 |
|
case Event::synth_param_pitch: |
817 |
|
NotePitch.fadeTo(itEvent->Param.NoteSynthParam.AbsValue, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
818 |
|
NotePitch.setFinal(itEvent->Param.NoteSynthParam.isFinal()); |
819 |
|
break; |
820 |
|
case Event::synth_param_pitch_time: |
821 |
|
NotePitch.setDefaultDuration(itEvent->Param.NoteSynthParam.AbsValue); |
822 |
|
break; |
823 |
|
case Event::synth_param_pitch_curve: |
824 |
|
NotePitch.setCurve((fade_curve_t)itEvent->Param.NoteSynthParam.AbsValue, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
825 |
|
break; |
826 |
|
case Event::synth_param_pan: |
827 |
|
NotePan[0].fadeTo( |
828 |
|
AbstractEngine::PanCurveValueNorm(itEvent->Param.NoteSynthParam.AbsValue, 0 /*left*/), |
829 |
|
GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE |
830 |
|
); |
831 |
|
NotePan[1].fadeTo( |
832 |
|
AbstractEngine::PanCurveValueNorm(itEvent->Param.NoteSynthParam.AbsValue, 1 /*right*/), |
833 |
|
GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE |
834 |
|
); |
835 |
|
NotePan[0].setFinal(itEvent->Param.NoteSynthParam.isFinal()); |
836 |
|
NotePan[1].setFinal(itEvent->Param.NoteSynthParam.isFinal()); |
837 |
|
break; |
838 |
|
case Event::synth_param_pan_time: |
839 |
|
NotePan[0].setDefaultDuration(itEvent->Param.NoteSynthParam.AbsValue); |
840 |
|
NotePan[1].setDefaultDuration(itEvent->Param.NoteSynthParam.AbsValue); |
841 |
|
break; |
842 |
|
case Event::synth_param_pan_curve: |
843 |
|
NotePan[0].setCurve((fade_curve_t)itEvent->Param.NoteSynthParam.AbsValue, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
844 |
|
NotePan[1].setCurve((fade_curve_t)itEvent->Param.NoteSynthParam.AbsValue, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
845 |
|
break; |
846 |
|
case Event::synth_param_cutoff: |
847 |
|
NoteCutoff.Value = itEvent->Param.NoteSynthParam.AbsValue; |
848 |
|
NoteCutoff.Final = itEvent->Param.NoteSynthParam.isFinal(); |
849 |
|
break; |
850 |
|
case Event::synth_param_resonance: |
851 |
|
NoteResonance.Value = itEvent->Param.NoteSynthParam.AbsValue; |
852 |
|
NoteResonance.Final = itEvent->Param.NoteSynthParam.isFinal(); |
853 |
|
break; |
854 |
|
case Event::synth_param_amp_lfo_depth: |
855 |
|
pLFO1->setScriptDepthFactor( |
856 |
|
itEvent->Param.NoteSynthParam.AbsValue, |
857 |
|
itEvent->Param.NoteSynthParam.isFinal() |
858 |
|
); |
859 |
|
break; |
860 |
|
case Event::synth_param_amp_lfo_freq: |
861 |
|
if (itEvent->Param.NoteSynthParam.isFinal()) |
862 |
|
pLFO1->setScriptFrequencyFinal(itEvent->Param.NoteSynthParam.AbsValue, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
863 |
|
else |
864 |
|
pLFO1->setScriptFrequencyFactor(itEvent->Param.NoteSynthParam.AbsValue, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
865 |
|
break; |
866 |
|
case Event::synth_param_cutoff_lfo_depth: |
867 |
|
pLFO2->setScriptDepthFactor( |
868 |
|
itEvent->Param.NoteSynthParam.AbsValue, |
869 |
|
itEvent->Param.NoteSynthParam.isFinal() |
870 |
|
); |
871 |
|
break; |
872 |
|
case Event::synth_param_cutoff_lfo_freq: |
873 |
|
if (itEvent->Param.NoteSynthParam.isFinal()) |
874 |
|
pLFO2->setScriptFrequencyFinal(itEvent->Param.NoteSynthParam.AbsValue, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
875 |
|
else |
876 |
|
pLFO2->setScriptFrequencyFactor(itEvent->Param.NoteSynthParam.AbsValue, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
877 |
|
break; |
878 |
|
case Event::synth_param_pitch_lfo_depth: |
879 |
|
pLFO3->setScriptDepthFactor( |
880 |
|
itEvent->Param.NoteSynthParam.AbsValue, |
881 |
|
itEvent->Param.NoteSynthParam.isFinal() |
882 |
|
); |
883 |
|
break; |
884 |
|
case Event::synth_param_pitch_lfo_freq: |
885 |
|
pLFO3->setScriptFrequencyFactor(itEvent->Param.NoteSynthParam.AbsValue, GetEngine()->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
886 |
|
break; |
887 |
|
|
888 |
|
case Event::synth_param_attack: |
889 |
|
case Event::synth_param_decay: |
890 |
|
case Event::synth_param_sustain: |
891 |
|
case Event::synth_param_release: |
892 |
|
case Event::synth_param_cutoff_attack: |
893 |
|
case Event::synth_param_cutoff_decay: |
894 |
|
case Event::synth_param_cutoff_sustain: |
895 |
|
case Event::synth_param_cutoff_release: |
896 |
|
break; // noop |
897 |
|
} |
898 |
|
} |
899 |
} |
} |
900 |
} |
} |
901 |
|
|
922 |
void AbstractVoice::UpdatePortamentoPos(Pool<Event>::Iterator& itNoteOffEvent) { |
void AbstractVoice::UpdatePortamentoPos(Pool<Event>::Iterator& itNoteOffEvent) { |
923 |
if (pSignalUnitRack == NULL) { |
if (pSignalUnitRack == NULL) { |
924 |
const float fFinalEG3Level = EG3.level(itNoteOffEvent->FragmentPos()); |
const float fFinalEG3Level = EG3.level(itNoteOffEvent->FragmentPos()); |
925 |
pEngineChannel->PortamentoPos = (float) MIDIKey + RTMath::FreqRatioToCents(fFinalEG3Level) * 0.01f; |
pEngineChannel->PortamentoPos = (float) MIDIKey() + RTMath::FreqRatioToCents(fFinalEG3Level) * 0.01f; |
926 |
} else { |
} else { |
927 |
// TODO: |
// TODO: |
928 |
} |
} |
949 |
|
|
950 |
Voice::PitchInfo AbstractVoice::CalculatePitchInfo(int PitchBend) { |
Voice::PitchInfo AbstractVoice::CalculatePitchInfo(int PitchBend) { |
951 |
PitchInfo pitch; |
PitchInfo pitch; |
952 |
double pitchbasecents = InstrInfo.FineTune + RgnInfo.FineTune + GetEngine()->ScaleTuning[MIDIKey % 12]; |
double pitchbasecents = InstrInfo.FineTune + RgnInfo.FineTune + GetEngine()->ScaleTuning[MIDIKey() % 12]; |
953 |
|
|
954 |
// GSt behaviour: maximum transpose up is 40 semitones. If |
// GSt behaviour: maximum transpose up is 40 semitones. If |
955 |
// MIDI key is more than 40 semitones above unity note, |
// MIDI key is more than 40 semitones above unity note, |
956 |
// the transpose is not done. |
// the transpose is not done. |
957 |
if (!SmplInfo.Unpitched && (MIDIKey - (int) RgnInfo.UnityNote) < 40) pitchbasecents += (MIDIKey - (int) RgnInfo.UnityNote) * 100; |
// |
958 |
|
// Update: Removed this GSt misbehavior. I don't think that any stock |
959 |
|
// gig sound requires it to resemble its original sound. |
960 |
|
// -- Christian, 2017-07-09 |
961 |
|
if (!SmplInfo.Unpitched /* && (MIDIKey() - (int) RgnInfo.UnityNote) < 40*/) |
962 |
|
pitchbasecents += (MIDIKey() - (int) RgnInfo.UnityNote) * 100; |
963 |
|
|
964 |
pitch.PitchBase = RTMath::CentsToFreqRatioUnlimited(pitchbasecents) * (double(SmplInfo.SampleRate) / double(GetEngine()->SampleRate)); |
pitch.PitchBase = RTMath::CentsToFreqRatioUnlimited(pitchbasecents) * (double(SmplInfo.SampleRate) / double(GetEngine()->SampleRate)); |
965 |
pitch.PitchBendRange = 1.0 / 8192.0 * 100.0 * InstrInfo.PitchbendRange; |
pitch.PitchBendRange = 1.0 / 8192.0 * 100.0 * InstrInfo.PitchbendRange; |
967 |
|
|
968 |
return pitch; |
return pitch; |
969 |
} |
} |
970 |
|
|
971 |
|
void AbstractVoice::onScaleTuningChanged() { |
972 |
|
PitchInfo pitch = this->Pitch; |
973 |
|
double pitchbasecents = InstrInfo.FineTune + RgnInfo.FineTune + GetEngine()->ScaleTuning[MIDIKey() % 12]; |
974 |
|
|
975 |
|
// GSt behaviour: maximum transpose up is 40 semitones. If |
976 |
|
// MIDI key is more than 40 semitones above unity note, |
977 |
|
// the transpose is not done. |
978 |
|
// |
979 |
|
// Update: Removed this GSt misbehavior. I don't think that any stock |
980 |
|
// gig sound requires it to resemble its original sound. |
981 |
|
// -- Christian, 2017-07-09 |
982 |
|
if (!SmplInfo.Unpitched /* && (MIDIKey() - (int) RgnInfo.UnityNote) < 40*/) |
983 |
|
pitchbasecents += (MIDIKey() - (int) RgnInfo.UnityNote) * 100; |
984 |
|
|
985 |
|
pitch.PitchBase = RTMath::CentsToFreqRatioUnlimited(pitchbasecents) * (double(SmplInfo.SampleRate) / double(GetEngine()->SampleRate)); |
986 |
|
this->Pitch = pitch; |
987 |
|
} |
988 |
|
|
989 |
double AbstractVoice::CalculateVolume(double velocityAttenuation) { |
double AbstractVoice::CalculateVolume(double velocityAttenuation) { |
990 |
// For 16 bit samples, we downscale by 32768 to convert from |
// For 16 bit samples, we downscale by 32768 to convert from |
997 |
// the volume of release triggered samples depends on note length |
// the volume of release triggered samples depends on note length |
998 |
if (Type & Voice::type_release_trigger) { |
if (Type & Voice::type_release_trigger) { |
999 |
float noteLength = float(GetEngine()->FrameTime + Delay - |
float noteLength = float(GetEngine()->FrameTime + Delay - |
1000 |
GetNoteOnTime(MIDIKey) ) / GetEngine()->SampleRate; |
GetNoteOnTime(MIDIKey()) ) / GetEngine()->SampleRate; |
1001 |
|
|
1002 |
volume *= GetReleaseTriggerAttenuation(noteLength); |
volume *= GetReleaseTriggerAttenuation(noteLength); |
1003 |
} |
} |