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 Christian Schoenebeck * |
* Copyright (C) 2005, 2006 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* 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 |
#include "Engine.h" |
#include "Engine.h" |
31 |
|
|
|
#if defined(__APPLE__) |
|
|
# include <stdlib.h> |
|
|
#else |
|
|
# include <malloc.h> |
|
|
#endif |
|
|
|
|
32 |
namespace LinuxSampler { namespace gig { |
namespace LinuxSampler { namespace gig { |
33 |
|
|
34 |
InstrumentResourceManager Engine::instruments; |
InstrumentResourceManager Engine::instruments; |
108 |
} |
} |
109 |
pVoicePool->clear(); |
pVoicePool->clear(); |
110 |
|
|
|
pSynthesisParameters[0] = NULL; // we allocate when an audio device is connected |
|
|
pBasicFilterParameters = NULL; |
|
|
pMainFilterParameters = NULL; |
|
|
|
|
111 |
ResetInternal(); |
ResetInternal(); |
112 |
|
ResetScaleTuning(); |
113 |
} |
} |
114 |
|
|
115 |
/** |
/** |
116 |
* Destructor |
* Destructor |
117 |
*/ |
*/ |
118 |
Engine::~Engine() { |
Engine::~Engine() { |
119 |
|
MidiInputPort::RemoveSysexListener(this); |
120 |
if (pDiskThread) { |
if (pDiskThread) { |
121 |
dmsg(1,("Stopping disk thread...")); |
dmsg(1,("Stopping disk thread...")); |
122 |
pDiskThread->StopThread(); |
pDiskThread->StopThread(); |
130 |
delete pVoicePool; |
delete pVoicePool; |
131 |
} |
} |
132 |
if (pEventGenerator) delete pEventGenerator; |
if (pEventGenerator) delete pEventGenerator; |
|
if (pMainFilterParameters) delete[] pMainFilterParameters; |
|
|
if (pBasicFilterParameters) delete[] pBasicFilterParameters; |
|
|
if (pSynthesisParameters[0]) free(pSynthesisParameters[0]); |
|
133 |
if (pVoiceStealingQueue) delete pVoiceStealingQueue; |
if (pVoiceStealingQueue) delete pVoiceStealingQueue; |
134 |
if (pSysexBuffer) delete pSysexBuffer; |
if (pSysexBuffer) delete pSysexBuffer; |
135 |
EngineFactory::Destroy(this); |
EngineFactory::Destroy(this); |
160 |
void Engine::Reset() { |
void Engine::Reset() { |
161 |
DisableAndLock(); |
DisableAndLock(); |
162 |
ResetInternal(); |
ResetInternal(); |
163 |
|
ResetScaleTuning(); |
164 |
Enable(); |
Enable(); |
165 |
} |
} |
166 |
|
|
167 |
/** |
/** |
168 |
* Reset all voices and disk thread and clear input event queue and all |
* Reset all voices and disk thread and clear input event queue and all |
169 |
* control and status variables. This method is not thread safe! |
* control and status variables. This method is protected by a mutex. |
170 |
*/ |
*/ |
171 |
void Engine::ResetInternal() { |
void Engine::ResetInternal() { |
172 |
|
ResetInternalMutex.Lock(); |
173 |
|
|
174 |
|
// make sure that the engine does not get any sysex messages |
175 |
|
// while it's reseting |
176 |
|
bool sysexDisabled = MidiInputPort::RemoveSysexListener(this); |
177 |
ActiveVoiceCount = 0; |
ActiveVoiceCount = 0; |
178 |
ActiveVoiceCountMax = 0; |
ActiveVoiceCountMax = 0; |
179 |
|
|
180 |
// reset voice stealing parameters |
// reset voice stealing parameters |
181 |
pVoiceStealingQueue->clear(); |
pVoiceStealingQueue->clear(); |
182 |
itLastStolenVoice = RTList<Voice>::Iterator(); |
itLastStolenVoice = RTList<Voice>::Iterator(); |
183 |
iuiLastStolenKey = RTList<uint>::Iterator(); |
itLastStolenVoiceGlobally = RTList<Voice>::Iterator(); |
184 |
pLastStolenChannel = NULL; |
iuiLastStolenKey = RTList<uint>::Iterator(); |
185 |
|
iuiLastStolenKeyGlobally = RTList<uint>::Iterator(); |
186 |
// reset to normal chromatic scale (means equal temper) |
pLastStolenChannel = NULL; |
|
memset(&ScaleTuning[0], 0x00, 12); |
|
187 |
|
|
188 |
// reset all voices |
// reset all voices |
189 |
for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) { |
for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) { |
196 |
|
|
197 |
// delete all input events |
// delete all input events |
198 |
pEventQueue->init(); |
pEventQueue->init(); |
199 |
|
pSysexBuffer->init(); |
200 |
|
if (sysexDisabled) MidiInputPort::AddSysexListener(this); |
201 |
|
ResetInternalMutex.Unlock(); |
202 |
|
} |
203 |
|
|
204 |
|
/** |
205 |
|
* Reset to normal, chromatic scale (means equal tempered). |
206 |
|
*/ |
207 |
|
void Engine::ResetScaleTuning() { |
208 |
|
memset(&ScaleTuning[0], 0x00, 12); |
209 |
} |
} |
210 |
|
|
211 |
/** |
/** |
236 |
|
|
237 |
// FIXME: audio drivers with varying fragment sizes might be a problem here |
// FIXME: audio drivers with varying fragment sizes might be a problem here |
238 |
MaxFadeOutPos = MaxSamplesPerCycle - int(double(SampleRate) * CONFIG_EG_MIN_RELEASE_TIME) - 1; |
MaxFadeOutPos = MaxSamplesPerCycle - int(double(SampleRate) * CONFIG_EG_MIN_RELEASE_TIME) - 1; |
239 |
if (MaxFadeOutPos < 0) |
if (MaxFadeOutPos < 0) { |
240 |
throw LinuxSamplerException("CONFIG_EG_MIN_RELEASE_TIME too big for current audio fragment size / sampling rate!"); |
std::cerr << "gig::Engine: WARNING, CONFIG_EG_MIN_RELEASE_TIME " |
241 |
|
<< "too big for current audio fragment size & sampling rate! " |
242 |
|
<< "May lead to click sounds if voice stealing chimes in!\n" << std::flush; |
243 |
|
// force volume ramp downs at the beginning of each fragment |
244 |
|
MaxFadeOutPos = 0; |
245 |
|
// lower minimum release time |
246 |
|
const float minReleaseTime = (float) MaxSamplesPerCycle / (float) SampleRate; |
247 |
|
for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) { |
248 |
|
iterVoice->EG1.CalculateFadeOutCoeff(minReleaseTime, SampleRate); |
249 |
|
} |
250 |
|
pVoicePool->clear(); |
251 |
|
} |
252 |
|
|
253 |
// (re)create disk thread |
// (re)create disk thread |
254 |
if (this->pDiskThread) { |
if (this->pDiskThread) { |
273 |
if (pEventGenerator) delete pEventGenerator; |
if (pEventGenerator) delete pEventGenerator; |
274 |
pEventGenerator = new EventGenerator(pAudioOut->SampleRate()); |
pEventGenerator = new EventGenerator(pAudioOut->SampleRate()); |
275 |
|
|
|
// (re)allocate synthesis parameter matrix |
|
|
if (pSynthesisParameters[0]) free(pSynthesisParameters[0]); |
|
|
|
|
|
#if defined(__APPLE__) |
|
|
pSynthesisParameters[0] = (float *) malloc(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle()); |
|
|
#else |
|
|
pSynthesisParameters[0] = (float *) memalign(16,(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle())); |
|
|
#endif |
|
|
for (int dst = 1; dst < Event::destination_count; dst++) |
|
|
pSynthesisParameters[dst] = pSynthesisParameters[dst - 1] + pAudioOut->MaxSamplesPerCycle(); |
|
|
|
|
|
// (re)allocate biquad filter parameter sequence |
|
|
if (pBasicFilterParameters) delete[] pBasicFilterParameters; |
|
|
if (pMainFilterParameters) delete[] pMainFilterParameters; |
|
|
pBasicFilterParameters = new biquad_param_t[pAudioOut->MaxSamplesPerCycle()]; |
|
|
pMainFilterParameters = new biquad_param_t[pAudioOut->MaxSamplesPerCycle()]; |
|
|
|
|
276 |
dmsg(1,("Starting disk thread...")); |
dmsg(1,("Starting disk thread...")); |
277 |
pDiskThread->StartThread(); |
pDiskThread->StartThread(); |
278 |
dmsg(1,("OK\n")); |
dmsg(1,("OK\n")); |
350 |
// update time of start and end of this audio fragment (as events' time stamps relate to this) |
// update time of start and end of this audio fragment (as events' time stamps relate to this) |
351 |
pEventGenerator->UpdateFragmentTime(Samples); |
pEventGenerator->UpdateFragmentTime(Samples); |
352 |
|
|
353 |
|
// We only allow a maximum of CONFIG_MAX_VOICES voices to be spawned |
354 |
|
// in each audio fragment. All subsequent request for spawning new |
355 |
|
// voices in the same audio fragment will be ignored. |
356 |
|
VoiceSpawnsLeft = CONFIG_MAX_VOICES; |
357 |
|
|
358 |
// get all events from the engine's global input event queue which belong to the current fragment |
// get all events from the engine's global input event queue which belong to the current fragment |
359 |
// (these are usually just SysEx messages) |
// (these are usually just SysEx messages) |
360 |
ImportEvents(Samples); |
ImportEvents(Samples); |
373 |
} |
} |
374 |
} |
} |
375 |
|
|
|
// We only allow a maximum of CONFIG_MAX_VOICES voices to be stolen |
|
|
// in each audio fragment. All subsequent request for spawning new |
|
|
// voices in the same audio fragment will be ignored. |
|
|
VoiceTheftsLeft = CONFIG_MAX_VOICES; |
|
|
|
|
376 |
// reset internal voice counter (just for statistic of active voices) |
// reset internal voice counter (just for statistic of active voices) |
377 |
ActiveVoiceCountTemp = 0; |
ActiveVoiceCountTemp = 0; |
378 |
|
|
|
|
|
379 |
// handle events on all engine channels |
// handle events on all engine channels |
380 |
for (int i = 0; i < engineChannels.size(); i++) { |
for (int i = 0; i < engineChannels.size(); i++) { |
381 |
if (!engineChannels[i]->pInstrument) continue; // ignore if no instrument loaded |
if (!engineChannels[i]->pInstrument) continue; // ignore if no instrument loaded |
403 |
|
|
404 |
// reset voice stealing for the next audio fragment |
// reset voice stealing for the next audio fragment |
405 |
pVoiceStealingQueue->clear(); |
pVoiceStealingQueue->clear(); |
|
itLastStolenVoice = RTList<Voice>::Iterator(); |
|
|
iuiLastStolenKey = RTList<uint>::Iterator(); |
|
|
pLastStolenChannel = NULL; |
|
406 |
|
|
407 |
// just some statistics about this engine instance |
// just some statistics about this engine instance |
408 |
ActiveVoiceCount = ActiveVoiceCountTemp; |
ActiveVoiceCount = ActiveVoiceCountTemp; |
409 |
if (ActiveVoiceCount > ActiveVoiceCountMax) ActiveVoiceCountMax = ActiveVoiceCount; |
if (ActiveVoiceCount > ActiveVoiceCountMax) ActiveVoiceCountMax = ActiveVoiceCount; |
410 |
|
|
411 |
|
FrameTime += Samples; |
412 |
|
|
413 |
return 0; |
return 0; |
414 |
} |
} |
415 |
|
|
452 |
} |
} |
453 |
} |
} |
454 |
} |
} |
455 |
|
|
456 |
|
// reset voice stealing for the next engine channel (or next audio fragment) |
457 |
|
itLastStolenVoice = RTList<Voice>::Iterator(); |
458 |
|
itLastStolenVoiceGlobally = RTList<Voice>::Iterator(); |
459 |
|
iuiLastStolenKey = RTList<uint>::Iterator(); |
460 |
|
iuiLastStolenKeyGlobally = RTList<uint>::Iterator(); |
461 |
|
pLastStolenChannel = NULL; |
462 |
} |
} |
463 |
|
|
464 |
/** |
/** |
471 |
* this audio fragment cycle |
* this audio fragment cycle |
472 |
*/ |
*/ |
473 |
void Engine::RenderActiveVoices(EngineChannel* pEngineChannel, uint Samples) { |
void Engine::RenderActiveVoices(EngineChannel* pEngineChannel, uint Samples) { |
474 |
|
#if !CONFIG_PROCESS_MUTED_CHANNELS |
475 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
476 |
|
#endif |
477 |
|
|
478 |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
479 |
RTList<uint>::Iterator end = pEngineChannel->pActiveKeys->end(); |
RTList<uint>::Iterator end = pEngineChannel->pActiveKeys->end(); |
480 |
while (iuiKey != end) { // iterate through all active keys |
while (iuiKey != end) { // iterate through all active keys |
513 |
for (; itVoiceStealEvent != end; ++itVoiceStealEvent) { |
for (; itVoiceStealEvent != end; ++itVoiceStealEvent) { |
514 |
EngineChannel* pEngineChannel = (EngineChannel*) itVoiceStealEvent->pEngineChannel; |
EngineChannel* pEngineChannel = (EngineChannel*) itVoiceStealEvent->pEngineChannel; |
515 |
Pool<Voice>::Iterator itNewVoice = |
Pool<Voice>::Iterator itNewVoice = |
516 |
LaunchVoice(pEngineChannel, itVoiceStealEvent, itVoiceStealEvent->Param.Note.Layer, itVoiceStealEvent->Param.Note.ReleaseTrigger, false); |
LaunchVoice(pEngineChannel, itVoiceStealEvent, itVoiceStealEvent->Param.Note.Layer, itVoiceStealEvent->Param.Note.ReleaseTrigger, false, false); |
517 |
if (itNewVoice) { |
if (itNewVoice) { |
518 |
itNewVoice->Render(Samples); |
itNewVoice->Render(Samples); |
519 |
if (itNewVoice->IsActive()) ActiveVoiceCountTemp++; // still active |
if (itNewVoice->IsActive()) ActiveVoiceCountTemp++; // still active |
547 |
++iuiKey; |
++iuiKey; |
548 |
if (pKey->pActiveVoices->isEmpty()) FreeKey(pEngineChannel, pKey); |
if (pKey->pActiveVoices->isEmpty()) FreeKey(pEngineChannel, pKey); |
549 |
#if CONFIG_DEVMODE |
#if CONFIG_DEVMODE |
550 |
else { // FIXME: should be removed before the final release (purpose: just a sanity check for debugging) |
else { // just a sanity check for debugging |
551 |
RTList<Voice>::Iterator itVoice = pKey->pActiveVoices->first(); |
RTList<Voice>::Iterator itVoice = pKey->pActiveVoices->first(); |
552 |
RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end(); |
RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end(); |
553 |
for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key |
for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key |
603 |
* @param itNoteOnEvent - key, velocity and time stamp of the event |
* @param itNoteOnEvent - key, velocity and time stamp of the event |
604 |
*/ |
*/ |
605 |
void Engine::ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) { |
void Engine::ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) { |
606 |
|
#if !CONFIG_PROCESS_MUTED_CHANNELS |
607 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
608 |
|
#endif |
609 |
|
|
610 |
const int key = itNoteOnEvent->Param.Note.Key; |
const int key = itNoteOnEvent->Param.Note.Key; |
611 |
|
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[key]; |
612 |
|
|
613 |
|
// move note on event to the key's own event list |
614 |
|
RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents); |
615 |
|
|
616 |
|
// if Solo Mode then kill all already active voices |
617 |
|
if (pEngineChannel->SoloMode) { |
618 |
|
Pool<uint>::Iterator itYoungestKey = pEngineChannel->pActiveKeys->last(); |
619 |
|
if (itYoungestKey) { |
620 |
|
const int iYoungestKey = *itYoungestKey; |
621 |
|
const midi_key_info_t* pOtherKey = &pEngineChannel->pMIDIKeyInfo[iYoungestKey]; |
622 |
|
if (pOtherKey->Active) { |
623 |
|
// get final portamento position of currently active voice |
624 |
|
if (pEngineChannel->PortamentoMode) { |
625 |
|
RTList<Voice>::Iterator itVoice = pOtherKey->pActiveVoices->last(); |
626 |
|
if (itVoice) itVoice->UpdatePortamentoPos(itNoteOnEventOnKeyList); |
627 |
|
} |
628 |
|
// kill all voices on the (other) key |
629 |
|
RTList<Voice>::Iterator itVoiceToBeKilled = pOtherKey->pActiveVoices->first(); |
630 |
|
RTList<Voice>::Iterator end = pOtherKey->pActiveVoices->end(); |
631 |
|
for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) { |
632 |
|
if (itVoiceToBeKilled->Type != Voice::type_release_trigger) |
633 |
|
itVoiceToBeKilled->Kill(itNoteOnEventOnKeyList); |
634 |
|
} |
635 |
|
} |
636 |
|
} |
637 |
|
// set this key as 'currently active solo key' |
638 |
|
pEngineChannel->SoloKey = key; |
639 |
|
} |
640 |
|
|
641 |
// Change key dimension value if key is in keyswitching area |
// Change key dimension value if key is in keyswitching area |
642 |
{ |
{ |
646 |
(pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1); |
(pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1); |
647 |
} |
} |
648 |
|
|
|
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[key]; |
|
|
|
|
649 |
pKey->KeyPressed = true; // the MIDI key was now pressed down |
pKey->KeyPressed = true; // the MIDI key was now pressed down |
650 |
|
pKey->Velocity = itNoteOnEventOnKeyList->Param.Note.Velocity; |
651 |
|
pKey->NoteOnTime = FrameTime + itNoteOnEventOnKeyList->FragmentPos(); // will be used to calculate note length |
652 |
|
|
653 |
// cancel release process of voices on this key if needed |
// cancel release process of voices on this key if needed |
654 |
if (pKey->Active && !pEngineChannel->SustainPedal) { |
if (pKey->Active && !pEngineChannel->SustainPedal) { |
655 |
RTList<Event>::Iterator itCancelReleaseEvent = pKey->pEvents->allocAppend(); |
RTList<Event>::Iterator itCancelReleaseEvent = pKey->pEvents->allocAppend(); |
656 |
if (itCancelReleaseEvent) { |
if (itCancelReleaseEvent) { |
657 |
*itCancelReleaseEvent = *itNoteOnEvent; // copy event |
*itCancelReleaseEvent = *itNoteOnEventOnKeyList; // copy event |
658 |
itCancelReleaseEvent->Type = Event::type_cancel_release; // transform event type |
itCancelReleaseEvent->Type = Event::type_cancel_release; // transform event type |
659 |
} |
} |
660 |
else dmsg(1,("Event pool emtpy!\n")); |
else dmsg(1,("Event pool emtpy!\n")); |
661 |
} |
} |
662 |
|
|
|
// move note on event to the key's own event list |
|
|
RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents); |
|
|
|
|
663 |
// allocate and trigger new voice(s) for the key |
// allocate and trigger new voice(s) for the key |
664 |
{ |
{ |
665 |
// first, get total amount of required voices (dependant on amount of layers) |
// first, get total amount of required voices (dependant on amount of layers) |
668 |
int voicesRequired = pRegion->Layers; |
int voicesRequired = pRegion->Layers; |
669 |
// now launch the required amount of voices |
// now launch the required amount of voices |
670 |
for (int i = 0; i < voicesRequired; i++) |
for (int i = 0; i < voicesRequired; i++) |
671 |
LaunchVoice(pEngineChannel, itNoteOnEventOnKeyList, i, false, true); |
LaunchVoice(pEngineChannel, itNoteOnEventOnKeyList, i, false, true, true); |
672 |
} |
} |
673 |
} |
} |
674 |
|
|
676 |
if (!pKey->Active && !pKey->VoiceTheftsQueued) |
if (!pKey->Active && !pKey->VoiceTheftsQueued) |
677 |
pKey->pEvents->free(itNoteOnEventOnKeyList); |
pKey->pEvents->free(itNoteOnEventOnKeyList); |
678 |
|
|
679 |
|
if (!pEngineChannel->SoloMode || pEngineChannel->PortamentoPos < 0.0f) pEngineChannel->PortamentoPos = (float) key; |
680 |
pKey->RoundRobinIndex++; |
pKey->RoundRobinIndex++; |
681 |
} |
} |
682 |
|
|
690 |
* @param itNoteOffEvent - key, velocity and time stamp of the event |
* @param itNoteOffEvent - key, velocity and time stamp of the event |
691 |
*/ |
*/ |
692 |
void Engine::ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) { |
void Engine::ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) { |
693 |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[itNoteOffEvent->Param.Note.Key]; |
#if !CONFIG_PROCESS_MUTED_CHANNELS |
694 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
695 |
|
#endif |
696 |
|
|
697 |
|
const int iKey = itNoteOffEvent->Param.Note.Key; |
698 |
|
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[iKey]; |
699 |
pKey->KeyPressed = false; // the MIDI key was now released |
pKey->KeyPressed = false; // the MIDI key was now released |
700 |
|
|
701 |
// release voices on this key if needed |
// move event to the key's own event list |
702 |
if (pKey->Active && !pEngineChannel->SustainPedal) { |
RTList<Event>::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents); |
|
itNoteOffEvent->Type = Event::type_release; // transform event type |
|
703 |
|
|
704 |
// move event to the key's own event list |
bool bShouldRelease = pKey->Active && ShouldReleaseVoice(pEngineChannel, itNoteOffEventOnKeyList->Param.Note.Key); |
705 |
RTList<Event>::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents); |
|
706 |
|
// in case Solo Mode is enabled, kill all voices on this key and respawn a voice on the highest pressed key (if any) |
707 |
|
if (pEngineChannel->SoloMode) { //TODO: this feels like too much code just for handling solo mode :P |
708 |
|
bool bOtherKeysPressed = false; |
709 |
|
if (iKey == pEngineChannel->SoloKey) { |
710 |
|
pEngineChannel->SoloKey = -1; |
711 |
|
// if there's still a key pressed down, respawn a voice (group) on the highest key |
712 |
|
for (int i = 127; i > 0; i--) { |
713 |
|
midi_key_info_t* pOtherKey = &pEngineChannel->pMIDIKeyInfo[i]; |
714 |
|
if (pOtherKey->KeyPressed) { |
715 |
|
bOtherKeysPressed = true; |
716 |
|
// make the other key the new 'currently active solo key' |
717 |
|
pEngineChannel->SoloKey = i; |
718 |
|
// get final portamento position of currently active voice |
719 |
|
if (pEngineChannel->PortamentoMode) { |
720 |
|
RTList<Voice>::Iterator itVoice = pKey->pActiveVoices->first(); |
721 |
|
if (itVoice) itVoice->UpdatePortamentoPos(itNoteOffEventOnKeyList); |
722 |
|
} |
723 |
|
// create a pseudo note on event |
724 |
|
RTList<Event>::Iterator itPseudoNoteOnEvent = pOtherKey->pEvents->allocAppend(); |
725 |
|
if (itPseudoNoteOnEvent) { |
726 |
|
// copy event |
727 |
|
*itPseudoNoteOnEvent = *itNoteOffEventOnKeyList; |
728 |
|
// transform event to a note on event |
729 |
|
itPseudoNoteOnEvent->Type = Event::type_note_on; |
730 |
|
itPseudoNoteOnEvent->Param.Note.Key = i; |
731 |
|
itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity; |
732 |
|
// allocate and trigger new voice(s) for the other key |
733 |
|
{ |
734 |
|
// first, get total amount of required voices (dependant on amount of layers) |
735 |
|
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(i); |
736 |
|
if (pRegion) { |
737 |
|
int voicesRequired = pRegion->Layers; |
738 |
|
// now launch the required amount of voices |
739 |
|
for (int iLayer = 0; iLayer < voicesRequired; iLayer++) |
740 |
|
LaunchVoice(pEngineChannel, itPseudoNoteOnEvent, iLayer, false, true, false); |
741 |
|
} |
742 |
|
} |
743 |
|
// if neither a voice was spawned or postponed then remove note on event from key again |
744 |
|
if (!pOtherKey->Active && !pOtherKey->VoiceTheftsQueued) |
745 |
|
pOtherKey->pEvents->free(itPseudoNoteOnEvent); |
746 |
|
|
747 |
|
} else dmsg(1,("Could not respawn voice, no free event left\n")); |
748 |
|
break; // done |
749 |
|
} |
750 |
|
} |
751 |
|
} |
752 |
|
if (bOtherKeysPressed) { |
753 |
|
if (pKey->Active) { // kill all voices on this key |
754 |
|
bShouldRelease = false; // no need to release, as we kill it here |
755 |
|
RTList<Voice>::Iterator itVoiceToBeKilled = pKey->pActiveVoices->first(); |
756 |
|
RTList<Voice>::Iterator end = pKey->pActiveVoices->end(); |
757 |
|
for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) { |
758 |
|
if (itVoiceToBeKilled->Type != Voice::type_release_trigger) |
759 |
|
itVoiceToBeKilled->Kill(itNoteOffEventOnKeyList); |
760 |
|
} |
761 |
|
} |
762 |
|
} else pEngineChannel->PortamentoPos = -1.0f; |
763 |
|
} |
764 |
|
|
765 |
|
// if no solo mode (the usual case) or if solo mode and no other key pressed, then release voices on this key if needed |
766 |
|
if (bShouldRelease) { |
767 |
|
itNoteOffEventOnKeyList->Type = Event::type_release; // transform event type |
768 |
|
|
769 |
// spawn release triggered voice(s) if needed |
// spawn release triggered voice(s) if needed |
770 |
if (pKey->ReleaseTrigger) { |
if (pKey->ReleaseTrigger) { |
772 |
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(itNoteOffEventOnKeyList->Param.Note.Key); |
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(itNoteOffEventOnKeyList->Param.Note.Key); |
773 |
if (pRegion) { |
if (pRegion) { |
774 |
int voicesRequired = pRegion->Layers; |
int voicesRequired = pRegion->Layers; |
775 |
|
|
776 |
|
// MIDI note-on velocity is used instead of note-off velocity |
777 |
|
itNoteOffEventOnKeyList->Param.Note.Velocity = pKey->Velocity; |
778 |
|
|
779 |
// now launch the required amount of voices |
// now launch the required amount of voices |
780 |
for (int i = 0; i < voicesRequired; i++) |
for (int i = 0; i < voicesRequired; i++) |
781 |
LaunchVoice(pEngineChannel, itNoteOffEventOnKeyList, i, true, false); //FIXME: for the moment we don't perform voice stealing for release triggered samples |
LaunchVoice(pEngineChannel, itNoteOffEventOnKeyList, i, true, false, false); //FIXME: for the moment we don't perform voice stealing for release triggered samples |
782 |
} |
} |
783 |
pKey->ReleaseTrigger = false; |
pKey->ReleaseTrigger = false; |
784 |
} |
} |
|
|
|
|
// if neither a voice was spawned or postponed then remove note off event from key again |
|
|
if (!pKey->Active && !pKey->VoiceTheftsQueued) |
|
|
pKey->pEvents->free(itNoteOffEventOnKeyList); |
|
785 |
} |
} |
786 |
|
|
787 |
|
// if neither a voice was spawned or postponed on this key then remove note off event from key again |
788 |
|
if (!pKey->Active && !pKey->VoiceTheftsQueued) |
789 |
|
pKey->pEvents->free(itNoteOffEventOnKeyList); |
790 |
} |
} |
791 |
|
|
792 |
/** |
/** |
793 |
* Moves pitchbend event from the general (input) event list to the pitch |
* Moves pitchbend event from the general (input) event list to the engine |
794 |
* event list. |
* channel's event list. It will actually processed later by the |
795 |
|
* respective voice. |
796 |
* |
* |
797 |
* @param pEngineChannel - engine channel on which this event occured on |
* @param pEngineChannel - engine channel on which this event occured on |
798 |
* @param itPitchbendEvent - absolute pitch value and time stamp of the event |
* @param itPitchbendEvent - absolute pitch value and time stamp of the event |
799 |
*/ |
*/ |
800 |
void Engine::ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent) { |
void Engine::ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent) { |
801 |
pEngineChannel->Pitch = itPitchbendEvent->Param.Pitch.Pitch; // store current pitch value |
pEngineChannel->Pitch = itPitchbendEvent->Param.Pitch.Pitch; // store current pitch value |
|
itPitchbendEvent.moveToEndOf(pEngineChannel->pSynthesisEvents[Event::destination_vco]); |
|
802 |
} |
} |
803 |
|
|
804 |
/** |
/** |
815 |
* @param VoiceStealing - if voice stealing should be performed |
* @param VoiceStealing - if voice stealing should be performed |
816 |
* when there is no free voice |
* when there is no free voice |
817 |
* (optional, default = true) |
* (optional, default = true) |
818 |
|
* @param HandleKeyGroupConflicts - if voices should be killed due to a |
819 |
|
* key group conflict |
820 |
* @returns pointer to new voice or NULL if there was no free voice or |
* @returns pointer to new voice or NULL if there was no free voice or |
821 |
* if the voice wasn't triggered (for example when no region is |
* if the voice wasn't triggered (for example when no region is |
822 |
* defined for the given key). |
* defined for the given key). |
823 |
*/ |
*/ |
824 |
Pool<Voice>::Iterator Engine::LaunchVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing) { |
Pool<Voice>::Iterator Engine::LaunchVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing, bool HandleKeyGroupConflicts) { |
825 |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key]; |
int MIDIKey = itNoteOnEvent->Param.Note.Key; |
826 |
|
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[MIDIKey]; |
827 |
|
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(MIDIKey); |
828 |
|
|
829 |
|
// if nothing defined for this key |
830 |
|
if (!pRegion) return Pool<Voice>::Iterator(); // nothing to do |
831 |
|
|
832 |
|
// only mark the first voice of a layered voice (group) to be in a |
833 |
|
// key group, so the layered voices won't kill each other |
834 |
|
int iKeyGroup = (iLayer == 0 && !ReleaseTriggerVoice) ? pRegion->KeyGroup : 0; |
835 |
|
|
836 |
|
// handle key group (a.k.a. exclusive group) conflicts |
837 |
|
if (HandleKeyGroupConflicts) { |
838 |
|
if (iKeyGroup) { // if this voice / key belongs to a key group |
839 |
|
uint** ppKeyGroup = &pEngineChannel->ActiveKeyGroups[iKeyGroup]; |
840 |
|
if (*ppKeyGroup) { // if there's already an active key in that key group |
841 |
|
midi_key_info_t* pOtherKey = &pEngineChannel->pMIDIKeyInfo[**ppKeyGroup]; |
842 |
|
// kill all voices on the (other) key |
843 |
|
RTList<Voice>::Iterator itVoiceToBeKilled = pOtherKey->pActiveVoices->first(); |
844 |
|
RTList<Voice>::Iterator end = pOtherKey->pActiveVoices->end(); |
845 |
|
for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) { |
846 |
|
if (itVoiceToBeKilled->Type != Voice::type_release_trigger) { |
847 |
|
itVoiceToBeKilled->Kill(itNoteOnEvent); |
848 |
|
--VoiceSpawnsLeft; //FIXME: just a hack, we should better check in StealVoice() if the voice was killed due to key conflict |
849 |
|
} |
850 |
|
} |
851 |
|
} |
852 |
|
} |
853 |
|
} |
854 |
|
|
855 |
|
Voice::type_t VoiceType = Voice::type_normal; |
856 |
|
|
857 |
|
// get current dimension values to select the right dimension region |
858 |
|
//TODO: for stolen voices this dimension region selection block is processed twice, this should be changed |
859 |
|
//FIXME: controller values for selecting the dimension region here are currently not sample accurate |
860 |
|
uint DimValues[8] = { 0 }; |
861 |
|
for (int i = pRegion->Dimensions - 1; i >= 0; i--) { |
862 |
|
switch (pRegion->pDimensionDefinitions[i].dimension) { |
863 |
|
case ::gig::dimension_samplechannel: |
864 |
|
DimValues[i] = 0; //TODO: we currently ignore this dimension |
865 |
|
break; |
866 |
|
case ::gig::dimension_layer: |
867 |
|
DimValues[i] = iLayer; |
868 |
|
break; |
869 |
|
case ::gig::dimension_velocity: |
870 |
|
DimValues[i] = itNoteOnEvent->Param.Note.Velocity; |
871 |
|
break; |
872 |
|
case ::gig::dimension_channelaftertouch: |
873 |
|
DimValues[i] = 0; //TODO: we currently ignore this dimension |
874 |
|
break; |
875 |
|
case ::gig::dimension_releasetrigger: |
876 |
|
VoiceType = (ReleaseTriggerVoice) ? Voice::type_release_trigger : (!iLayer) ? Voice::type_release_trigger_required : Voice::type_normal; |
877 |
|
DimValues[i] = (uint) ReleaseTriggerVoice; |
878 |
|
break; |
879 |
|
case ::gig::dimension_keyboard: |
880 |
|
DimValues[i] = (uint) pEngineChannel->CurrentKeyDimension; |
881 |
|
break; |
882 |
|
case ::gig::dimension_roundrobin: |
883 |
|
DimValues[i] = (uint) pEngineChannel->pMIDIKeyInfo[MIDIKey].RoundRobinIndex; // incremented for each note on |
884 |
|
break; |
885 |
|
case ::gig::dimension_random: |
886 |
|
RandomSeed = RandomSeed * 1103515245 + 12345; // classic pseudo random number generator |
887 |
|
DimValues[i] = (uint) RandomSeed >> (32 - pRegion->pDimensionDefinitions[i].bits); // highest bits are most random |
888 |
|
break; |
889 |
|
case ::gig::dimension_modwheel: |
890 |
|
DimValues[i] = pEngineChannel->ControllerTable[1]; |
891 |
|
break; |
892 |
|
case ::gig::dimension_breath: |
893 |
|
DimValues[i] = pEngineChannel->ControllerTable[2]; |
894 |
|
break; |
895 |
|
case ::gig::dimension_foot: |
896 |
|
DimValues[i] = pEngineChannel->ControllerTable[4]; |
897 |
|
break; |
898 |
|
case ::gig::dimension_portamentotime: |
899 |
|
DimValues[i] = pEngineChannel->ControllerTable[5]; |
900 |
|
break; |
901 |
|
case ::gig::dimension_effect1: |
902 |
|
DimValues[i] = pEngineChannel->ControllerTable[12]; |
903 |
|
break; |
904 |
|
case ::gig::dimension_effect2: |
905 |
|
DimValues[i] = pEngineChannel->ControllerTable[13]; |
906 |
|
break; |
907 |
|
case ::gig::dimension_genpurpose1: |
908 |
|
DimValues[i] = pEngineChannel->ControllerTable[16]; |
909 |
|
break; |
910 |
|
case ::gig::dimension_genpurpose2: |
911 |
|
DimValues[i] = pEngineChannel->ControllerTable[17]; |
912 |
|
break; |
913 |
|
case ::gig::dimension_genpurpose3: |
914 |
|
DimValues[i] = pEngineChannel->ControllerTable[18]; |
915 |
|
break; |
916 |
|
case ::gig::dimension_genpurpose4: |
917 |
|
DimValues[i] = pEngineChannel->ControllerTable[19]; |
918 |
|
break; |
919 |
|
case ::gig::dimension_sustainpedal: |
920 |
|
DimValues[i] = pEngineChannel->ControllerTable[64]; |
921 |
|
break; |
922 |
|
case ::gig::dimension_portamento: |
923 |
|
DimValues[i] = pEngineChannel->ControllerTable[65]; |
924 |
|
break; |
925 |
|
case ::gig::dimension_sostenutopedal: |
926 |
|
DimValues[i] = pEngineChannel->ControllerTable[66]; |
927 |
|
break; |
928 |
|
case ::gig::dimension_softpedal: |
929 |
|
DimValues[i] = pEngineChannel->ControllerTable[67]; |
930 |
|
break; |
931 |
|
case ::gig::dimension_genpurpose5: |
932 |
|
DimValues[i] = pEngineChannel->ControllerTable[80]; |
933 |
|
break; |
934 |
|
case ::gig::dimension_genpurpose6: |
935 |
|
DimValues[i] = pEngineChannel->ControllerTable[81]; |
936 |
|
break; |
937 |
|
case ::gig::dimension_genpurpose7: |
938 |
|
DimValues[i] = pEngineChannel->ControllerTable[82]; |
939 |
|
break; |
940 |
|
case ::gig::dimension_genpurpose8: |
941 |
|
DimValues[i] = pEngineChannel->ControllerTable[83]; |
942 |
|
break; |
943 |
|
case ::gig::dimension_effect1depth: |
944 |
|
DimValues[i] = pEngineChannel->ControllerTable[91]; |
945 |
|
break; |
946 |
|
case ::gig::dimension_effect2depth: |
947 |
|
DimValues[i] = pEngineChannel->ControllerTable[92]; |
948 |
|
break; |
949 |
|
case ::gig::dimension_effect3depth: |
950 |
|
DimValues[i] = pEngineChannel->ControllerTable[93]; |
951 |
|
break; |
952 |
|
case ::gig::dimension_effect4depth: |
953 |
|
DimValues[i] = pEngineChannel->ControllerTable[94]; |
954 |
|
break; |
955 |
|
case ::gig::dimension_effect5depth: |
956 |
|
DimValues[i] = pEngineChannel->ControllerTable[95]; |
957 |
|
break; |
958 |
|
case ::gig::dimension_none: |
959 |
|
std::cerr << "gig::Engine::LaunchVoice() Error: dimension=none\n" << std::flush; |
960 |
|
break; |
961 |
|
default: |
962 |
|
std::cerr << "gig::Engine::LaunchVoice() Error: Unknown dimension\n" << std::flush; |
963 |
|
} |
964 |
|
} |
965 |
|
::gig::DimensionRegion* pDimRgn = pRegion->GetDimensionRegionByValue(DimValues); |
966 |
|
|
967 |
|
// no need to continue if sample is silent |
968 |
|
if (!pDimRgn->pSample || !pDimRgn->pSample->SamplesTotal) return Pool<Voice>::Iterator(); |
969 |
|
|
970 |
// allocate a new voice for the key |
// allocate a new voice for the key |
971 |
Pool<Voice>::Iterator itNewVoice = pKey->pActiveVoices->allocAppend(); |
Pool<Voice>::Iterator itNewVoice = pKey->pActiveVoices->allocAppend(); |
972 |
if (itNewVoice) { |
if (itNewVoice) { |
973 |
// launch the new voice |
// launch the new voice |
974 |
if (itNewVoice->Trigger(pEngineChannel, itNoteOnEvent, pEngineChannel->Pitch, pEngineChannel->pInstrument, iLayer, ReleaseTriggerVoice, VoiceStealing) < 0) { |
if (itNewVoice->Trigger(pEngineChannel, itNoteOnEvent, pEngineChannel->Pitch, pDimRgn, VoiceType, iKeyGroup) < 0) { |
975 |
dmsg(4,("Voice not triggered\n")); |
dmsg(4,("Voice not triggered\n")); |
976 |
pKey->pActiveVoices->free(itNewVoice); |
pKey->pActiveVoices->free(itNewVoice); |
977 |
} |
} |
978 |
else { // on success |
else { // on success |
979 |
uint** ppKeyGroup = NULL; |
--VoiceSpawnsLeft; |
|
if (itNewVoice->KeyGroup) { // if this voice / key belongs to a key group |
|
|
ppKeyGroup = &pEngineChannel->ActiveKeyGroups[itNewVoice->KeyGroup]; |
|
|
if (*ppKeyGroup) { // if there's already an active key in that key group |
|
|
midi_key_info_t* pOtherKey = &pEngineChannel->pMIDIKeyInfo[**ppKeyGroup]; |
|
|
// kill all voices on the (other) key |
|
|
RTList<Voice>::Iterator itVoiceToBeKilled = pOtherKey->pActiveVoices->first(); |
|
|
RTList<Voice>::Iterator end = pOtherKey->pActiveVoices->end(); |
|
|
for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) { |
|
|
if (itVoiceToBeKilled->Type != Voice::type_release_trigger) itVoiceToBeKilled->Kill(itNoteOnEvent); |
|
|
} |
|
|
} |
|
|
} |
|
980 |
if (!pKey->Active) { // mark as active key |
if (!pKey->Active) { // mark as active key |
981 |
pKey->Active = true; |
pKey->Active = true; |
982 |
pKey->itSelf = pEngineChannel->pActiveKeys->allocAppend(); |
pKey->itSelf = pEngineChannel->pActiveKeys->allocAppend(); |
983 |
*pKey->itSelf = itNoteOnEvent->Param.Note.Key; |
*pKey->itSelf = itNoteOnEvent->Param.Note.Key; |
984 |
} |
} |
985 |
if (itNewVoice->KeyGroup) { |
if (itNewVoice->KeyGroup) { |
986 |
|
uint** ppKeyGroup = &pEngineChannel->ActiveKeyGroups[itNewVoice->KeyGroup]; |
987 |
*ppKeyGroup = &*pKey->itSelf; // put key as the (new) active key to its key group |
*ppKeyGroup = &*pKey->itSelf; // put key as the (new) active key to its key group |
988 |
} |
} |
989 |
if (itNewVoice->Type == Voice::type_release_trigger_required) pKey->ReleaseTrigger = true; // mark key for the need of release triggered voice(s) |
if (itNewVoice->Type == Voice::type_release_trigger_required) pKey->ReleaseTrigger = true; // mark key for the need of release triggered voice(s) |
1020 |
* @returns 0 on success, a value < 0 if no active voice could be picked for voice stealing |
* @returns 0 on success, a value < 0 if no active voice could be picked for voice stealing |
1021 |
*/ |
*/ |
1022 |
int Engine::StealVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) { |
int Engine::StealVoice(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) { |
1023 |
if (!VoiceTheftsLeft) { |
if (VoiceSpawnsLeft <= 0) { |
1024 |
dmsg(1,("Max. voice thefts per audio fragment reached (you may raise CONFIG_MAX_VOICES).\n")); |
dmsg(1,("Max. voice thefts per audio fragment reached (you may raise CONFIG_MAX_VOICES).\n")); |
1025 |
return -1; |
return -1; |
1026 |
} |
} |
1033 |
|
|
1034 |
// try to pick the oldest voice on the key where the new |
// try to pick the oldest voice on the key where the new |
1035 |
// voice should be spawned, if there is no voice on that |
// voice should be spawned, if there is no voice on that |
1036 |
// key, or no voice left to kill there, then procceed with |
// key, or no voice left to kill, then procceed with |
1037 |
// 'oldestkey' algorithm |
// 'oldestkey' algorithm |
1038 |
case voice_steal_algo_oldestvoiceonkey: { |
case voice_steal_algo_oldestvoiceonkey: { |
|
#if 0 // FIXME: broken |
|
1039 |
midi_key_info_t* pSelectedKey = &pEngineChannel->pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key]; |
midi_key_info_t* pSelectedKey = &pEngineChannel->pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key]; |
1040 |
if (this->itLastStolenVoice) { |
itSelectedVoice = pSelectedKey->pActiveVoices->first(); |
1041 |
itSelectedVoice = this->itLastStolenVoice; |
// proceed iterating if voice was created in this fragment cycle |
1042 |
++itSelectedVoice; |
while (itSelectedVoice && !itSelectedVoice->IsStealable()) ++itSelectedVoice; |
1043 |
} |
// if we haven't found a voice then proceed with algorithm 'oldestkey' |
1044 |
else { // no voice stolen in this audio fragment cycle yet |
if (itSelectedVoice && itSelectedVoice->IsStealable()) break; |
|
itSelectedVoice = pSelectedKey->pActiveVoices->first(); |
|
|
} |
|
|
if (itSelectedVoice) { |
|
|
iuiSelectedKey = pSelectedKey->itSelf; |
|
|
break; // selection succeeded |
|
|
} |
|
|
#endif |
|
1045 |
} // no break - intentional ! |
} // no break - intentional ! |
1046 |
|
|
1047 |
// try to pick the oldest voice on the oldest active key |
// try to pick the oldest voice on the oldest active key |
1048 |
|
// from the same engine channel |
1049 |
// (caution: must stay after 'oldestvoiceonkey' algorithm !) |
// (caution: must stay after 'oldestvoiceonkey' algorithm !) |
1050 |
case voice_steal_algo_oldestkey: { |
case voice_steal_algo_oldestkey: { |
1051 |
|
// if we already stole in this fragment, try to proceed on same key |
1052 |
if (this->itLastStolenVoice) { |
if (this->itLastStolenVoice) { |
1053 |
itSelectedVoice = this->itLastStolenVoice; |
itSelectedVoice = this->itLastStolenVoice; |
1054 |
++itSelectedVoice; |
do { |
1055 |
if (itSelectedVoice) break; // selection succeeded |
++itSelectedVoice; |
1056 |
RTList<uint>::Iterator iuiSelectedKey = this->iuiLastStolenKey; |
} while (itSelectedVoice && !itSelectedVoice->IsStealable()); // proceed iterating if voice was created in this fragment cycle |
1057 |
++iuiSelectedKey; |
// found a "stealable" voice ? |
1058 |
if (iuiSelectedKey) { |
if (itSelectedVoice && itSelectedVoice->IsStealable()) { |
1059 |
this->iuiLastStolenKey = iuiSelectedKey; |
// remember which voice we stole, so we can simply proceed on next voice stealing |
1060 |
midi_key_info_t* pSelectedKey = &pEngineChannel->pMIDIKeyInfo[*iuiSelectedKey]; |
this->itLastStolenVoice = itSelectedVoice; |
|
itSelectedVoice = pSelectedKey->pActiveVoices->first(); |
|
1061 |
break; // selection succeeded |
break; // selection succeeded |
1062 |
} |
} |
1063 |
} |
} |
1064 |
|
// get (next) oldest key |
1065 |
|
RTList<uint>::Iterator iuiSelectedKey = (this->iuiLastStolenKey) ? ++this->iuiLastStolenKey : pEngineChannel->pActiveKeys->first(); |
1066 |
|
while (iuiSelectedKey) { |
1067 |
|
midi_key_info_t* pSelectedKey = &pEngineChannel->pMIDIKeyInfo[*iuiSelectedKey]; |
1068 |
|
itSelectedVoice = pSelectedKey->pActiveVoices->first(); |
1069 |
|
// proceed iterating if voice was created in this fragment cycle |
1070 |
|
while (itSelectedVoice && !itSelectedVoice->IsStealable()) ++itSelectedVoice; |
1071 |
|
// found a "stealable" voice ? |
1072 |
|
if (itSelectedVoice && itSelectedVoice->IsStealable()) { |
1073 |
|
// remember which voice on which key we stole, so we can simply proceed on next voice stealing |
1074 |
|
this->iuiLastStolenKey = iuiSelectedKey; |
1075 |
|
this->itLastStolenVoice = itSelectedVoice; |
1076 |
|
break; // selection succeeded |
1077 |
|
} |
1078 |
|
++iuiSelectedKey; // get next oldest key |
1079 |
|
} |
1080 |
break; |
break; |
1081 |
} |
} |
1082 |
|
|
1088 |
} |
} |
1089 |
} |
} |
1090 |
|
|
1091 |
// steal oldest voice on the oldest key from this or any other engine channel |
// if we couldn't steal a voice from the same engine channel then |
1092 |
if (!itSelectedVoice) { |
// steal oldest voice on the oldest key from any other engine channel |
1093 |
EngineChannel* pSelectedChannel = (pLastStolenChannel) ? pLastStolenChannel : pEngineChannel; |
// (the smaller engine channel number, the higher priority) |
1094 |
int iChannelIndex = pSelectedChannel->iEngineIndexSelf; |
if (!itSelectedVoice || !itSelectedVoice->IsStealable()) { |
1095 |
while (true) { |
EngineChannel* pSelectedChannel; |
1096 |
RTList<uint>::Iterator iuiSelectedKey = pSelectedChannel->pActiveKeys->first(); |
int iChannelIndex; |
1097 |
if (iuiSelectedKey) { |
// select engine channel |
1098 |
|
if (pLastStolenChannel) { |
1099 |
|
pSelectedChannel = pLastStolenChannel; |
1100 |
|
iChannelIndex = pSelectedChannel->iEngineIndexSelf; |
1101 |
|
} else { // pick the engine channel followed by this engine channel |
1102 |
|
iChannelIndex = (pEngineChannel->iEngineIndexSelf + 1) % engineChannels.size(); |
1103 |
|
pSelectedChannel = engineChannels[iChannelIndex]; |
1104 |
|
} |
1105 |
|
|
1106 |
|
// if we already stole in this fragment, try to proceed on same key |
1107 |
|
if (this->itLastStolenVoiceGlobally) { |
1108 |
|
itSelectedVoice = this->itLastStolenVoiceGlobally; |
1109 |
|
do { |
1110 |
|
++itSelectedVoice; |
1111 |
|
} while (itSelectedVoice && !itSelectedVoice->IsStealable()); // proceed iterating if voice was created in this fragment cycle |
1112 |
|
} |
1113 |
|
|
1114 |
|
#if CONFIG_DEVMODE |
1115 |
|
EngineChannel* pBegin = pSelectedChannel; // to detect endless loop |
1116 |
|
#endif // CONFIG_DEVMODE |
1117 |
|
|
1118 |
|
// did we find a 'stealable' voice? |
1119 |
|
if (itSelectedVoice && itSelectedVoice->IsStealable()) { |
1120 |
|
// remember which voice we stole, so we can simply proceed on next voice stealing |
1121 |
|
this->itLastStolenVoiceGlobally = itSelectedVoice; |
1122 |
|
} else while (true) { // iterate through engine channels |
1123 |
|
// get (next) oldest key |
1124 |
|
RTList<uint>::Iterator iuiSelectedKey = (this->iuiLastStolenKeyGlobally) ? ++this->iuiLastStolenKeyGlobally : pSelectedChannel->pActiveKeys->first(); |
1125 |
|
this->iuiLastStolenKeyGlobally = RTList<uint>::Iterator(); // to prevent endless loop (see line above) |
1126 |
|
while (iuiSelectedKey) { |
1127 |
midi_key_info_t* pSelectedKey = &pSelectedChannel->pMIDIKeyInfo[*iuiSelectedKey]; |
midi_key_info_t* pSelectedKey = &pSelectedChannel->pMIDIKeyInfo[*iuiSelectedKey]; |
1128 |
itSelectedVoice = pSelectedKey->pActiveVoices->first(); |
itSelectedVoice = pSelectedKey->pActiveVoices->first(); |
1129 |
iuiLastStolenKey = iuiSelectedKey; |
// proceed iterating if voice was created in this fragment cycle |
1130 |
pLastStolenChannel = pSelectedChannel; |
while (itSelectedVoice && !itSelectedVoice->IsStealable()) ++itSelectedVoice; |
1131 |
break; // selection succeeded |
// found a "stealable" voice ? |
1132 |
|
if (itSelectedVoice && itSelectedVoice->IsStealable()) { |
1133 |
|
// remember which voice on which key on which engine channel we stole, so we can simply proceed on next voice stealing |
1134 |
|
this->iuiLastStolenKeyGlobally = iuiSelectedKey; |
1135 |
|
this->itLastStolenVoiceGlobally = itSelectedVoice; |
1136 |
|
this->pLastStolenChannel = pSelectedChannel; |
1137 |
|
goto stealable_voice_found; // selection succeeded |
1138 |
|
} |
1139 |
|
++iuiSelectedKey; // get next key on current engine channel |
1140 |
} |
} |
1141 |
|
// get next engine channel |
1142 |
iChannelIndex = (iChannelIndex + 1) % engineChannels.size(); |
iChannelIndex = (iChannelIndex + 1) % engineChannels.size(); |
1143 |
pSelectedChannel = engineChannels[iChannelIndex]; |
pSelectedChannel = engineChannels[iChannelIndex]; |
1144 |
|
|
1145 |
|
#if CONFIG_DEVMODE |
1146 |
|
if (pSelectedChannel == pBegin) { |
1147 |
|
dmsg(1,("FATAL ERROR: voice stealing endless loop!\n")); |
1148 |
|
dmsg(1,("VoiceSpawnsLeft=%d.\n", VoiceSpawnsLeft)); |
1149 |
|
dmsg(1,("Exiting.\n")); |
1150 |
|
exit(-1); |
1151 |
|
} |
1152 |
|
#endif // CONFIG_DEVMODE |
1153 |
} |
} |
1154 |
} |
} |
1155 |
|
|
1156 |
//FIXME: can be removed, just a sanity check for debugging |
// jump point if a 'stealable' voice was found |
1157 |
|
stealable_voice_found: |
1158 |
|
|
1159 |
|
#if CONFIG_DEVMODE |
1160 |
if (!itSelectedVoice->IsActive()) { |
if (!itSelectedVoice->IsActive()) { |
1161 |
dmsg(1,("gig::Engine: ERROR, tried to steal a voice which was not active !!!\n")); |
dmsg(1,("gig::Engine: ERROR, tried to steal a voice which was not active !!!\n")); |
1162 |
return -1; |
return -1; |
1163 |
} |
} |
1164 |
|
#endif // CONFIG_DEVMODE |
1165 |
|
|
1166 |
// now kill the selected voice |
// now kill the selected voice |
1167 |
itSelectedVoice->Kill(itNoteOnEvent); |
itSelectedVoice->Kill(itNoteOnEvent); |
1168 |
|
|
1169 |
// remember which voice we stole, so we can simply proceed for the next voice stealing |
--VoiceSpawnsLeft; |
|
itLastStolenVoice = itSelectedVoice; |
|
|
|
|
|
--VoiceTheftsLeft; |
|
1170 |
|
|
1171 |
return 0; // success |
return 0; // success |
1172 |
} |
} |
1235 |
// update controller value in the engine channel's controller table |
// update controller value in the engine channel's controller table |
1236 |
pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value; |
pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value; |
1237 |
|
|
1238 |
// move event from the unsorted event list to the control change event list |
switch (itControlChangeEvent->Param.CC.Controller) { |
1239 |
Pool<Event>::Iterator itControlChangeEventOnCCList = itControlChangeEvent.moveToEndOf(pEngineChannel->pCCEvents); |
case 5: { // portamento time |
1240 |
|
pEngineChannel->PortamentoTime = (float) itControlChangeEvent->Param.CC.Value / 127.0f * (float) CONFIG_PORTAMENTO_TIME_MAX + (float) CONFIG_PORTAMENTO_TIME_MIN; |
1241 |
switch (itControlChangeEventOnCCList->Param.CC.Controller) { |
break; |
1242 |
|
} |
1243 |
case 7: { // volume |
case 7: { // volume |
1244 |
//TODO: not sample accurate yet |
//TODO: not sample accurate yet |
1245 |
pEngineChannel->GlobalVolume = (float) itControlChangeEventOnCCList->Param.CC.Value / 127.0f; |
pEngineChannel->GlobalVolume = VolumeCurve[itControlChangeEvent->Param.CC.Value] * CONFIG_GLOBAL_ATTENUATION; |
1246 |
|
pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag |
1247 |
break; |
break; |
1248 |
} |
} |
1249 |
case 10: { // panpot |
case 10: { // panpot |
1250 |
//TODO: not sample accurate yet |
//TODO: not sample accurate yet |
1251 |
const int pan = (int) itControlChangeEventOnCCList->Param.CC.Value - 64; |
pEngineChannel->GlobalPanLeft = PanCurve[128 - itControlChangeEvent->Param.CC.Value]; |
1252 |
pEngineChannel->GlobalPanLeft = 1.0f - float(RTMath::Max(pan, 0)) / 63.0f; |
pEngineChannel->GlobalPanRight = PanCurve[itControlChangeEvent->Param.CC.Value]; |
|
pEngineChannel->GlobalPanRight = 1.0f - float(RTMath::Min(pan, 0)) / -64.0f; |
|
1253 |
break; |
break; |
1254 |
} |
} |
1255 |
case 64: { // sustain |
case 64: { // sustain |
1256 |
if (itControlChangeEventOnCCList->Param.CC.Value >= 64 && !pEngineChannel->SustainPedal) { |
if (itControlChangeEvent->Param.CC.Value >= 64 && !pEngineChannel->SustainPedal) { |
1257 |
dmsg(4,("PEDAL DOWN\n")); |
dmsg(4,("DAMPER (RIGHT) PEDAL DOWN\n")); |
1258 |
pEngineChannel->SustainPedal = true; |
pEngineChannel->SustainPedal = true; |
1259 |
|
|
1260 |
|
#if !CONFIG_PROCESS_MUTED_CHANNELS |
1261 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
1262 |
|
#endif |
1263 |
|
|
1264 |
// cancel release process of voices if necessary |
// cancel release process of voices if necessary |
1265 |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
1266 |
for (; iuiKey; ++iuiKey) { |
for (; iuiKey; ++iuiKey) { |
1268 |
if (!pKey->KeyPressed) { |
if (!pKey->KeyPressed) { |
1269 |
RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend(); |
RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend(); |
1270 |
if (itNewEvent) { |
if (itNewEvent) { |
1271 |
*itNewEvent = *itControlChangeEventOnCCList; // copy event to the key's own event list |
*itNewEvent = *itControlChangeEvent; // copy event to the key's own event list |
1272 |
itNewEvent->Type = Event::type_cancel_release; // transform event type |
itNewEvent->Type = Event::type_cancel_release; // transform event type |
1273 |
} |
} |
1274 |
else dmsg(1,("Event pool emtpy!\n")); |
else dmsg(1,("Event pool emtpy!\n")); |
1275 |
} |
} |
1276 |
} |
} |
1277 |
} |
} |
1278 |
if (itControlChangeEventOnCCList->Param.CC.Value < 64 && pEngineChannel->SustainPedal) { |
if (itControlChangeEvent->Param.CC.Value < 64 && pEngineChannel->SustainPedal) { |
1279 |
dmsg(4,("PEDAL UP\n")); |
dmsg(4,("DAMPER (RIGHT) PEDAL UP\n")); |
1280 |
pEngineChannel->SustainPedal = false; |
pEngineChannel->SustainPedal = false; |
1281 |
|
|
1282 |
|
#if !CONFIG_PROCESS_MUTED_CHANNELS |
1283 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
1284 |
|
#endif |
1285 |
|
|
1286 |
// release voices if their respective key is not pressed |
// release voices if their respective key is not pressed |
1287 |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
1288 |
for (; iuiKey; ++iuiKey) { |
for (; iuiKey; ++iuiKey) { |
1289 |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey]; |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey]; |
1290 |
if (!pKey->KeyPressed) { |
if (!pKey->KeyPressed && ShouldReleaseVoice(pEngineChannel, *iuiKey)) { |
1291 |
RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend(); |
RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend(); |
1292 |
if (itNewEvent) { |
if (itNewEvent) { |
1293 |
*itNewEvent = *itControlChangeEventOnCCList; // copy event to the key's own event list |
*itNewEvent = *itControlChangeEvent; // copy event to the key's own event list |
1294 |
|
itNewEvent->Type = Event::type_release; // transform event type |
1295 |
|
} |
1296 |
|
else dmsg(1,("Event pool emtpy!\n")); |
1297 |
|
} |
1298 |
|
} |
1299 |
|
} |
1300 |
|
break; |
1301 |
|
} |
1302 |
|
case 65: { // portamento on / off |
1303 |
|
KillAllVoices(pEngineChannel, itControlChangeEvent); |
1304 |
|
pEngineChannel->PortamentoMode = itControlChangeEvent->Param.CC.Value >= 64; |
1305 |
|
break; |
1306 |
|
} |
1307 |
|
case 66: { // sostenuto |
1308 |
|
if (itControlChangeEvent->Param.CC.Value >= 64 && !pEngineChannel->SostenutoPedal) { |
1309 |
|
dmsg(4,("SOSTENUTO (CENTER) PEDAL DOWN\n")); |
1310 |
|
pEngineChannel->SostenutoPedal = true; |
1311 |
|
|
1312 |
|
#if !CONFIG_PROCESS_MUTED_CHANNELS |
1313 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
1314 |
|
#endif |
1315 |
|
|
1316 |
|
SostenutoKeyCount = 0; |
1317 |
|
// Remeber the pressed keys |
1318 |
|
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
1319 |
|
for (; iuiKey; ++iuiKey) { |
1320 |
|
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey]; |
1321 |
|
if (pKey->KeyPressed && SostenutoKeyCount < 128) SostenutoKeys[SostenutoKeyCount++] = *iuiKey; |
1322 |
|
} |
1323 |
|
} |
1324 |
|
if (itControlChangeEvent->Param.CC.Value < 64 && pEngineChannel->SostenutoPedal) { |
1325 |
|
dmsg(4,("SOSTENUTO (CENTER) PEDAL UP\n")); |
1326 |
|
pEngineChannel->SostenutoPedal = false; |
1327 |
|
|
1328 |
|
#if !CONFIG_PROCESS_MUTED_CHANNELS |
1329 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
1330 |
|
#endif |
1331 |
|
|
1332 |
|
// release voices if the damper pedal is up and their respective key is not pressed |
1333 |
|
for (int i = 0; i < SostenutoKeyCount; i++) { |
1334 |
|
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[SostenutoKeys[i]]; |
1335 |
|
if (!pKey->KeyPressed && !pEngineChannel->SustainPedal) { |
1336 |
|
RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend(); |
1337 |
|
if (itNewEvent) { |
1338 |
|
*itNewEvent = *itControlChangeEvent; // copy event to the key's own event list |
1339 |
itNewEvent->Type = Event::type_release; // transform event type |
itNewEvent->Type = Event::type_release; // transform event type |
1340 |
} |
} |
1341 |
else dmsg(1,("Event pool emtpy!\n")); |
else dmsg(1,("Event pool emtpy!\n")); |
1349 |
// Channel Mode Messages |
// Channel Mode Messages |
1350 |
|
|
1351 |
case 120: { // all sound off |
case 120: { // all sound off |
1352 |
KillAllVoices(pEngineChannel, itControlChangeEventOnCCList); |
KillAllVoices(pEngineChannel, itControlChangeEvent); |
1353 |
break; |
break; |
1354 |
} |
} |
1355 |
case 121: { // reset all controllers |
case 121: { // reset all controllers |
1357 |
break; |
break; |
1358 |
} |
} |
1359 |
case 123: { // all notes off |
case 123: { // all notes off |
1360 |
ReleaseAllVoices(pEngineChannel, itControlChangeEventOnCCList); |
#if CONFIG_PROCESS_ALL_NOTES_OFF |
1361 |
|
ReleaseAllVoices(pEngineChannel, itControlChangeEvent); |
1362 |
|
#endif // CONFIG_PROCESS_ALL_NOTES_OFF |
1363 |
|
break; |
1364 |
|
} |
1365 |
|
case 126: { // mono mode on |
1366 |
|
KillAllVoices(pEngineChannel, itControlChangeEvent); |
1367 |
|
pEngineChannel->SoloMode = true; |
1368 |
|
break; |
1369 |
|
} |
1370 |
|
case 127: { // poly mode on |
1371 |
|
KillAllVoices(pEngineChannel, itControlChangeEvent); |
1372 |
|
pEngineChannel->SoloMode = false; |
1373 |
break; |
break; |
1374 |
} |
} |
1375 |
} |
} |
1417 |
if (reader.read(&scale_tunes[0], 12) != 12) goto free_sysex_data; |
if (reader.read(&scale_tunes[0], 12) != 12) goto free_sysex_data; |
1418 |
uint8_t checksum; |
uint8_t checksum; |
1419 |
if (!reader.pop(&checksum)) goto free_sysex_data; |
if (!reader.pop(&checksum)) goto free_sysex_data; |
1420 |
// some are not sending a GS checksum, so we ignore it for now |
#if CONFIG_ASSERT_GS_SYSEX_CHECKSUM |
1421 |
//if (GSCheckSum(checksum_reader, 12)) goto free_sysex_data; |
if (GSCheckSum(checksum_reader, 12)) goto free_sysex_data; |
1422 |
|
#endif // CONFIG_ASSERT_GS_SYSEX_CHECKSUM |
1423 |
for (int i = 0; i < 12; i++) scale_tunes[i] -= 64; |
for (int i = 0; i < 12; i++) scale_tunes[i] -= 64; |
1424 |
AdjustScale((int8_t*) scale_tunes); |
AdjustScale((int8_t*) scale_tunes); |
1425 |
dmsg(3,("\t\t\tNew scale applied.\n")); |
dmsg(3,("\t\t\tNew scale applied.\n")); |
1507 |
RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end(); |
RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end(); |
1508 |
for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key |
for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key |
1509 |
itVoice->Kill(itKillEvent); |
itVoice->Kill(itKillEvent); |
1510 |
|
--VoiceSpawnsLeft; //FIXME: just a temporary workaround, we should check the cause in StealVoice() instead |
1511 |
} |
} |
1512 |
} |
} |
1513 |
} |
} |
1514 |
|
|
1515 |
/** |
/** |
1516 |
* Initialize the parameter sequence for the modulation destination given by |
* Determines whether the specified voice should be released. |
1517 |
* by 'dst' with the constant value given by val. |
* |
1518 |
|
* @param pEngineChannel - The engine channel on which the voice should be checked |
1519 |
|
* @param Key - The key number |
1520 |
|
* @returns true if the specified should be released, false otherwise. |
1521 |
*/ |
*/ |
1522 |
void Engine::ResetSynthesisParameters(Event::destination_t dst, float val) { |
bool Engine::ShouldReleaseVoice(EngineChannel* pEngineChannel, int Key) { |
1523 |
int maxsamples = pAudioOutputDevice->MaxSamplesPerCycle(); |
if (pEngineChannel->SustainPedal) return false; |
1524 |
float* m = &pSynthesisParameters[dst][0]; |
|
1525 |
for (int i = 0; i < maxsamples; i += 4) { |
if (pEngineChannel->SostenutoPedal) { |
1526 |
m[i] = val; |
for (int i = 0; i < SostenutoKeyCount; i++) |
1527 |
m[i+1] = val; |
if (Key == SostenutoKeys[i]) return false; |
|
m[i+2] = val; |
|
|
m[i+3] = val; |
|
1528 |
} |
} |
1529 |
|
|
1530 |
|
return true; |
1531 |
} |
} |
1532 |
|
|
1533 |
uint Engine::VoiceCount() { |
uint Engine::VoiceCount() { |
1567 |
} |
} |
1568 |
|
|
1569 |
String Engine::Version() { |
String Engine::Version() { |
1570 |
String s = "$Revision: 1.37 $"; |
String s = "$Revision: 1.61 $"; |
1571 |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
1572 |
} |
} |
1573 |
|
|
1574 |
|
// static constant initializers |
1575 |
|
const float* Engine::VolumeCurve(InitVolumeCurve()); |
1576 |
|
const float* Engine::PanCurve(InitPanCurve()); |
1577 |
|
const float* Engine::CrossfadeCurve(InitCrossfadeCurve()); |
1578 |
|
|
1579 |
|
float* Engine::InitVolumeCurve() { |
1580 |
|
// line-segment approximation |
1581 |
|
const float segments[] = { |
1582 |
|
0, 0, 2, 0.0046, 16, 0.016, 31, 0.051, 45, 0.115, 54.5, 0.2, |
1583 |
|
64.5, 0.39, 74, 0.74, 92, 1.03, 114, 1.94, 119.2, 2.2, 127, 2.2 |
1584 |
|
}; |
1585 |
|
return InitCurve(segments); |
1586 |
|
} |
1587 |
|
|
1588 |
|
float* Engine::InitPanCurve() { |
1589 |
|
// line-segment approximation |
1590 |
|
const float segments[] = { |
1591 |
|
0, 0, 1, 0, |
1592 |
|
2, 0.05, 31.5, 0.7, 51, 0.851, 74.5, 1.12, |
1593 |
|
127, 1.41, 128, 1.41 |
1594 |
|
}; |
1595 |
|
return InitCurve(segments, 129); |
1596 |
|
} |
1597 |
|
|
1598 |
|
float* Engine::InitCrossfadeCurve() { |
1599 |
|
// line-segment approximation |
1600 |
|
const float segments[] = { |
1601 |
|
0, 0, 1, 0.03, 10, 0.1, 51, 0.58, 127, 1 |
1602 |
|
}; |
1603 |
|
return InitCurve(segments); |
1604 |
|
} |
1605 |
|
|
1606 |
|
float* Engine::InitCurve(const float* segments, int size) { |
1607 |
|
float* y = new float[size]; |
1608 |
|
for (int x = 0 ; x < size ; x++) { |
1609 |
|
if (x > segments[2]) segments += 2; |
1610 |
|
y[x] = segments[1] + (x - segments[0]) * |
1611 |
|
(segments[3] - segments[1]) / (segments[2] - segments[0]); |
1612 |
|
} |
1613 |
|
return y; |
1614 |
|
} |
1615 |
|
|
1616 |
}} // namespace LinuxSampler::gig |
}} // namespace LinuxSampler::gig |