43 |
|
|
44 |
finalSynthesisParameters.filterLeft.Reset(); |
finalSynthesisParameters.filterLeft.Reset(); |
45 |
finalSynthesisParameters.filterRight.Reset(); |
finalSynthesisParameters.filterRight.Reset(); |
46 |
|
|
47 |
|
pEq = NULL; |
48 |
|
bEqSupport = false; |
49 |
} |
} |
50 |
|
|
51 |
AbstractVoice::~AbstractVoice() { |
AbstractVoice::~AbstractVoice() { |
52 |
if (pLFO1) delete pLFO1; |
if (pLFO1) delete pLFO1; |
53 |
if (pLFO2) delete pLFO2; |
if (pLFO2) delete pLFO2; |
54 |
if (pLFO3) delete pLFO3; |
if (pLFO3) delete pLFO3; |
55 |
|
|
56 |
|
if(pEq != NULL) delete pEq; |
57 |
|
} |
58 |
|
|
59 |
|
void AbstractVoice::CreateEq() { |
60 |
|
if(!bEqSupport) return; |
61 |
|
if(pEq != NULL) delete pEq; |
62 |
|
pEq = new EqSupport; |
63 |
|
pEq->InitEffect(GetEngine()->pAudioOutputDevice); |
64 |
} |
} |
65 |
|
|
66 |
/** |
/** |
111 |
|
|
112 |
Type = VoiceType; |
Type = VoiceType; |
113 |
MIDIKey = itNoteOnEvent->Param.Note.Key; |
MIDIKey = itNoteOnEvent->Param.Note.Key; |
114 |
|
MIDIVelocity = itNoteOnEvent->Param.Note.Velocity; |
115 |
|
MIDIPan = pEngineChannel->ControllerTable[10]; |
116 |
|
if (MIDIPan == 0 && pEngineChannel->GlobalPanRight == 1) MIDIPan = 64; // workaround used to determine whether the MIDI pan has not been set |
117 |
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 |
118 |
Delay = itNoteOnEvent->FragmentPos(); |
Delay = itNoteOnEvent->FragmentPos(); |
119 |
itTriggerEvent = itNoteOnEvent; |
itTriggerEvent = itNoteOnEvent; |
306 |
VCFCutoffCtrl.controller = 0; |
VCFCutoffCtrl.controller = 0; |
307 |
VCFResonanceCtrl.controller = 0; |
VCFResonanceCtrl.controller = 0; |
308 |
} |
} |
309 |
|
|
310 |
|
const bool bEq = |
311 |
|
pSignalUnitRack != NULL && pSignalUnitRack->HasEq() && pEq->HasSupport(); |
312 |
|
|
313 |
|
if (bEq) { |
314 |
|
pEq->GetInChannelLeft()->Clear(); |
315 |
|
pEq->GetInChannelRight()->Clear(); |
316 |
|
pEq->RenderAudio(GetEngine()->pAudioOutputDevice->MaxSamplesPerCycle()); |
317 |
|
} |
318 |
|
|
319 |
return 0; // success |
return 0; // success |
320 |
} |
} |
333 |
* @param Skip - number of sample points to skip in output buffer |
* @param Skip - number of sample points to skip in output buffer |
334 |
*/ |
*/ |
335 |
void AbstractVoice::Synthesize(uint Samples, sample_t* pSrc, uint Skip) { |
void AbstractVoice::Synthesize(uint Samples, sample_t* pSrc, uint Skip) { |
336 |
|
bool delay = false; // Whether the voice playback should be delayed for this call |
337 |
|
|
338 |
|
if (pSignalUnitRack != NULL) { |
339 |
|
uint delaySteps = pSignalUnitRack->GetEndpointUnit()->DelayTrigger(); |
340 |
|
if (delaySteps > 0) { // delay on the endpoint unit means delay of the voice playback |
341 |
|
if (delaySteps >= Samples) { |
342 |
|
pSignalUnitRack->GetEndpointUnit()->DecreaseDelay(Samples); |
343 |
|
delay = true; |
344 |
|
} else { |
345 |
|
pSignalUnitRack->GetEndpointUnit()->DecreaseDelay(delaySteps); |
346 |
|
Samples -= delaySteps; |
347 |
|
Skip += delaySteps; |
348 |
|
} |
349 |
|
} |
350 |
|
} |
351 |
|
|
352 |
AbstractEngineChannel* pChannel = pEngineChannel; |
AbstractEngineChannel* pChannel = pEngineChannel; |
353 |
MidiKeyBase* pMidiKeyInfo = GetMidiKeyInfo(MIDIKey); |
MidiKeyBase* pMidiKeyInfo = GetMidiKeyInfo(MIDIKey); |
354 |
|
|
355 |
const bool bVoiceRequiresDedicatedRouting = |
const bool bVoiceRequiresDedicatedRouting = |
356 |
pEngineChannel->GetFxSendCount() > 0 && |
pEngineChannel->GetFxSendCount() > 0 && |
357 |
(pMidiKeyInfo->ReverbSend || pMidiKeyInfo->ChorusSend); |
(pMidiKeyInfo->ReverbSend || pMidiKeyInfo->ChorusSend); |
358 |
|
|
359 |
|
const bool bEq = |
360 |
|
pSignalUnitRack != NULL && pSignalUnitRack->HasEq() && pEq->HasSupport(); |
361 |
|
|
362 |
if (bVoiceRequiresDedicatedRouting) { |
if (bEq) { |
363 |
|
pEq->GetInChannelLeft()->Clear(); |
364 |
|
pEq->GetInChannelRight()->Clear(); |
365 |
|
finalSynthesisParameters.pOutLeft = &pEq->GetInChannelLeft()->Buffer()[Skip]; |
366 |
|
finalSynthesisParameters.pOutRight = &pEq->GetInChannelRight()->Buffer()[Skip]; |
367 |
|
pSignalUnitRack->UpdateEqSettings(pEq); |
368 |
|
} else if (bVoiceRequiresDedicatedRouting) { |
369 |
finalSynthesisParameters.pOutLeft = &GetEngine()->pDedicatedVoiceChannelLeft->Buffer()[Skip]; |
finalSynthesisParameters.pOutLeft = &GetEngine()->pDedicatedVoiceChannelLeft->Buffer()[Skip]; |
370 |
finalSynthesisParameters.pOutRight = &GetEngine()->pDedicatedVoiceChannelRight->Buffer()[Skip]; |
finalSynthesisParameters.pOutRight = &GetEngine()->pDedicatedVoiceChannelRight->Buffer()[Skip]; |
371 |
} else { |
} else { |
426 |
|
|
427 |
// process MIDI control change and pitchbend events for this subfragment |
// process MIDI control change and pitchbend events for this subfragment |
428 |
processCCEvents(itCCEvent, iSubFragmentEnd); |
processCCEvents(itCCEvent, iSubFragmentEnd); |
429 |
|
uint8_t pan = MIDIPan; |
430 |
|
if (pSignalUnitRack != NULL) pan = pSignalUnitRack->GetEndpointUnit()->CaluclatePan(pan); |
431 |
|
|
432 |
|
PanLeftSmoother.update(AbstractEngine::PanCurve[128 - pan]); |
433 |
|
PanRightSmoother.update(AbstractEngine::PanCurve[pan]); |
434 |
|
|
435 |
finalSynthesisParameters.fFinalPitch = Pitch.PitchBase * Pitch.PitchBend; |
finalSynthesisParameters.fFinalPitch = Pitch.PitchBase * Pitch.PitchBend; |
436 |
float fFinalVolume = VolumeSmoother.render() * CrossfadeSmoother.render(); |
float fFinalVolume = VolumeSmoother.render() * CrossfadeSmoother.render(); |
441 |
// process transition events (note on, note off & sustain pedal) |
// process transition events (note on, note off & sustain pedal) |
442 |
processTransitionEvents(itNoteEvent, iSubFragmentEnd); |
processTransitionEvents(itNoteEvent, iSubFragmentEnd); |
443 |
processGroupEvents(itGroupEvent, iSubFragmentEnd); |
processGroupEvents(itGroupEvent, iSubFragmentEnd); |
444 |
|
|
445 |
if (pSignalUnitRack == NULL) { |
if (pSignalUnitRack == NULL) { |
446 |
// if the voice was killed in this subfragment, or if the |
// if the voice was killed in this subfragment, or if the |
447 |
// filter EG is finished, switch EG1 to fade out stage |
// filter EG is finished, switch EG1 to fade out stage |
539 |
fFinalVolume * VolumeRight * PanRightSmoother.render(); |
fFinalVolume * VolumeRight * PanRightSmoother.render(); |
540 |
#endif |
#endif |
541 |
// render audio for one subfragment |
// render audio for one subfragment |
542 |
RunSynthesisFunction(SynthesisMode, &finalSynthesisParameters, &loop); |
if (!delay) RunSynthesisFunction(SynthesisMode, &finalSynthesisParameters, &loop); |
543 |
|
|
544 |
if (pSignalUnitRack == NULL) { |
if (pSignalUnitRack == NULL) { |
545 |
// stop the rendering if volume EG is finished |
// stop the rendering if volume EG is finished |
576 |
}*/ |
}*/ |
577 |
// TODO: ^^^ |
// TODO: ^^^ |
578 |
|
|
579 |
pSignalUnitRack->Increment(); |
if (!delay) pSignalUnitRack->Increment(); |
580 |
} |
} |
581 |
|
|
582 |
Pos = newPos; |
Pos = newPos; |
583 |
i = iSubFragmentEnd; |
i = iSubFragmentEnd; |
584 |
} |
} |
585 |
|
|
586 |
|
if (delay) return; |
587 |
|
|
588 |
if (bVoiceRequiresDedicatedRouting) { |
if (bVoiceRequiresDedicatedRouting) { |
589 |
|
if (bEq) { |
590 |
|
pEq->RenderAudio(Samples); |
591 |
|
pEq->GetOutChannelLeft()->CopyTo(GetEngine()->pDedicatedVoiceChannelLeft, Samples); |
592 |
|
pEq->GetOutChannelRight()->CopyTo(GetEngine()->pDedicatedVoiceChannelRight, Samples); |
593 |
|
} |
594 |
optional<float> effectSendLevels[2] = { |
optional<float> effectSendLevels[2] = { |
595 |
pMidiKeyInfo->ReverbSend, |
pMidiKeyInfo->ReverbSend, |
596 |
pMidiKeyInfo->ChorusSend |
pMidiKeyInfo->ChorusSend |
597 |
}; |
}; |
598 |
GetEngine()->RouteDedicatedVoiceChannels(pEngineChannel, effectSendLevels, Samples); |
GetEngine()->RouteDedicatedVoiceChannels(pEngineChannel, effectSendLevels, Samples); |
599 |
|
} else if (bEq) { |
600 |
|
pEq->RenderAudio(Samples); |
601 |
|
pEq->GetOutChannelLeft()->MixTo(pChannel->pChannelLeft, Samples); |
602 |
|
pEq->GetOutChannelRight()->MixTo(pChannel->pChannelRight, Samples); |
603 |
} |
} |
604 |
} |
} |
605 |
|
|
633 |
if (itEvent->Param.CC.Controller == 7) { // volume |
if (itEvent->Param.CC.Controller == 7) { // volume |
634 |
VolumeSmoother.update(AbstractEngine::VolumeCurve[itEvent->Param.CC.Value]); |
VolumeSmoother.update(AbstractEngine::VolumeCurve[itEvent->Param.CC.Value]); |
635 |
} else if (itEvent->Param.CC.Controller == 10) { // panpot |
} else if (itEvent->Param.CC.Controller == 10) { // panpot |
636 |
PanLeftSmoother.update(AbstractEngine::PanCurve[128 - itEvent->Param.CC.Value]); |
MIDIPan = itEvent->Param.CC.Value; |
|
PanRightSmoother.update(AbstractEngine::PanCurve[itEvent->Param.CC.Value]); |
|
637 |
} |
} |
638 |
} else if (itEvent->Type == Event::type_pitchbend) { // if pitch bend event |
} else if (itEvent->Type == Event::type_pitchbend) { // if pitch bend event |
639 |
processPitchEvent(itEvent); |
processPitchEvent(itEvent); |