26 |
#include "EGADSR.h" |
#include "EGADSR.h" |
27 |
|
|
28 |
#include "Engine.h" |
#include "Engine.h" |
29 |
|
#include <malloc.h> |
30 |
|
|
31 |
namespace LinuxSampler { namespace gig { |
namespace LinuxSampler { namespace gig { |
32 |
|
|
77 |
|
|
78 |
Engine::~Engine() { |
Engine::~Engine() { |
79 |
if (pDiskThread) { |
if (pDiskThread) { |
80 |
|
dmsg(1,("Stopping disk thread...")); |
81 |
pDiskThread->StopThread(); |
pDiskThread->StopThread(); |
82 |
delete pDiskThread; |
delete pDiskThread; |
83 |
|
dmsg(1,("OK\n")); |
84 |
} |
} |
85 |
|
|
86 |
|
if (pInstrument) Instruments.HandBack(pInstrument, this); |
87 |
|
|
88 |
if (pGig) delete pGig; |
if (pGig) delete pGig; |
89 |
if (pRIFF) delete pRIFF; |
if (pRIFF) delete pRIFF; |
90 |
for (uint i = 0; i < 128; i++) { |
for (uint i = 0; i < 128; i++) { |
94 |
for (uint i = 0; i < Event::destination_count; i++) { |
for (uint i = 0; i < Event::destination_count; i++) { |
95 |
if (pSynthesisEvents[i]) delete pSynthesisEvents[i]; |
if (pSynthesisEvents[i]) delete pSynthesisEvents[i]; |
96 |
} |
} |
|
delete[] pSynthesisEvents; |
|
97 |
if (pEvents) delete pEvents; |
if (pEvents) delete pEvents; |
98 |
if (pCCEvents) delete pCCEvents; |
if (pCCEvents) delete pCCEvents; |
99 |
if (pEventQueue) delete pEventQueue; |
if (pEventQueue) delete pEventQueue; |
100 |
if (pEventPool) delete pEventPool; |
if (pEventPool) delete pEventPool; |
101 |
if (pVoicePool) delete pVoicePool; |
if (pVoicePool) { |
102 |
|
pVoicePool->clear(); |
103 |
|
delete pVoicePool; |
104 |
|
} |
105 |
if (pActiveKeys) delete pActiveKeys; |
if (pActiveKeys) delete pActiveKeys; |
106 |
if (pSysexBuffer) delete pSysexBuffer; |
if (pSysexBuffer) delete pSysexBuffer; |
107 |
if (pEventGenerator) delete pEventGenerator; |
if (pEventGenerator) delete pEventGenerator; |
108 |
if (pMainFilterParameters) delete[] pMainFilterParameters; |
if (pMainFilterParameters) delete[] pMainFilterParameters; |
109 |
if (pBasicFilterParameters) delete[] pBasicFilterParameters; |
if (pBasicFilterParameters) delete[] pBasicFilterParameters; |
110 |
if (pSynthesisParameters[0]) delete[] pSynthesisParameters[0]; |
if (pSynthesisParameters[0]) free(pSynthesisParameters[0]); |
111 |
if (pVoiceStealingQueue) delete pVoiceStealingQueue; |
if (pVoiceStealingQueue) delete pVoiceStealingQueue; |
112 |
} |
} |
113 |
|
|
166 |
ActiveVoiceCount = 0; |
ActiveVoiceCount = 0; |
167 |
ActiveVoiceCountMax = 0; |
ActiveVoiceCountMax = 0; |
168 |
GlobalVolume = 1.0; |
GlobalVolume = 1.0; |
169 |
|
CurrentKeyDimension = 0; |
170 |
|
|
171 |
// reset voice stealing parameters |
// reset voice stealing parameters |
172 |
itLastStolenVoice = RTList<Voice>::Iterator(); |
itLastStolenVoice = RTList<Voice>::Iterator(); |
330 |
|
|
331 |
// (re)create disk thread |
// (re)create disk thread |
332 |
if (this->pDiskThread) { |
if (this->pDiskThread) { |
333 |
|
dmsg(1,("Stopping disk thread...")); |
334 |
this->pDiskThread->StopThread(); |
this->pDiskThread->StopThread(); |
335 |
delete this->pDiskThread; |
delete this->pDiskThread; |
336 |
|
dmsg(1,("OK\n")); |
337 |
} |
} |
338 |
this->pDiskThread = new DiskThread(((pAudioOut->MaxSamplesPerCycle() << MAX_PITCH) << 1) + 6); //FIXME: assuming stereo |
this->pDiskThread = new DiskThread(((pAudioOut->MaxSamplesPerCycle() << MAX_PITCH) << 1) + 6); //FIXME: assuming stereo |
339 |
if (!pDiskThread) { |
if (!pDiskThread) { |
352 |
pEventGenerator = new EventGenerator(pAudioOut->SampleRate()); |
pEventGenerator = new EventGenerator(pAudioOut->SampleRate()); |
353 |
|
|
354 |
// (re)allocate synthesis parameter matrix |
// (re)allocate synthesis parameter matrix |
355 |
if (pSynthesisParameters[0]) delete[] pSynthesisParameters[0]; |
if (pSynthesisParameters[0]) free(pSynthesisParameters[0]); |
356 |
pSynthesisParameters[0] = new float[Event::destination_count * pAudioOut->MaxSamplesPerCycle()]; |
pSynthesisParameters[0] = (float *) memalign(16,(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle())); |
357 |
for (int dst = 1; dst < Event::destination_count; dst++) |
for (int dst = 1; dst < Event::destination_count; dst++) |
358 |
pSynthesisParameters[dst] = pSynthesisParameters[dst - 1] + pAudioOut->MaxSamplesPerCycle(); |
pSynthesisParameters[dst] = pSynthesisParameters[dst - 1] + pAudioOut->MaxSamplesPerCycle(); |
359 |
|
|
409 |
} |
} |
410 |
|
|
411 |
|
|
412 |
|
// update time of start and end of this audio fragment (as events' time stamps relate to this) |
413 |
|
pEventGenerator->UpdateFragmentTime(Samples); |
414 |
|
|
415 |
|
|
416 |
// empty the event lists for the new fragment |
// empty the event lists for the new fragment |
417 |
pEvents->clear(); |
pEvents->clear(); |
418 |
pCCEvents->clear(); |
pCCEvents->clear(); |
427 |
} |
} |
428 |
} |
} |
429 |
|
|
|
// read and copy events from input queue |
|
|
Event event = pEventGenerator->CreateEvent(); |
|
|
while (true) { |
|
|
if (!pEventQueue->pop(&event) || pEvents->poolIsEmpty()) break; |
|
|
*pEvents->allocAppend() = event; |
|
|
} |
|
|
|
|
430 |
|
|
431 |
// update time of start and end of this audio fragment (as events' time stamps relate to this) |
// get all events from the input event queue which belong to the current fragment |
432 |
pEventGenerator->UpdateFragmentTime(Samples); |
{ |
433 |
|
RingBuffer<Event>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader(); |
434 |
|
Event* pEvent; |
435 |
|
while (true) { |
436 |
|
// get next event from input event queue |
437 |
|
if (!(pEvent = eventQueueReader.pop())) break; |
438 |
|
// if younger event reached, ignore that and all subsequent ones for now |
439 |
|
if (pEvent->FragmentPos() >= Samples) { |
440 |
|
eventQueueReader--; |
441 |
|
dmsg(2,("Younger Event, pos=%d ,Samples=%d!\n",pEvent->FragmentPos(),Samples)); |
442 |
|
pEvent->ResetFragmentPos(); |
443 |
|
break; |
444 |
|
} |
445 |
|
// copy event to internal event list |
446 |
|
if (pEvents->poolIsEmpty()) { |
447 |
|
dmsg(1,("Event pool emtpy!\n")); |
448 |
|
break; |
449 |
|
} |
450 |
|
*pEvents->allocAppend() = *pEvent; |
451 |
|
} |
452 |
|
eventQueueReader.free(); // free all copied events from input queue |
453 |
|
} |
454 |
|
|
455 |
|
|
456 |
// process events |
// process events |
663 |
* @param itNoteOnEvent - key, velocity and time stamp of the event |
* @param itNoteOnEvent - key, velocity and time stamp of the event |
664 |
*/ |
*/ |
665 |
void Engine::ProcessNoteOn(Pool<Event>::Iterator& itNoteOnEvent) { |
void Engine::ProcessNoteOn(Pool<Event>::Iterator& itNoteOnEvent) { |
666 |
midi_key_info_t* pKey = &pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key]; |
|
667 |
|
const int key = itNoteOnEvent->Param.Note.Key; |
668 |
|
|
669 |
|
// Change key dimension value if key is in keyswitching area |
670 |
|
if (key >= pInstrument->DimensionKeyRange.low && key <= pInstrument->DimensionKeyRange.high) |
671 |
|
CurrentKeyDimension = ((key - pInstrument->DimensionKeyRange.low) * 128) / |
672 |
|
(pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1); |
673 |
|
|
674 |
|
midi_key_info_t* pKey = &pMIDIKeyInfo[key]; |
675 |
|
|
676 |
pKey->KeyPressed = true; // the MIDI key was now pressed down |
pKey->KeyPressed = true; // the MIDI key was now pressed down |
677 |
|
|
745 |
* when there is no free voice |
* when there is no free voice |
746 |
* (optional, default = true) |
* (optional, default = true) |
747 |
* @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 |
748 |
* if an error occured while trying to trigger the new voice |
* if the voice wasn't triggered (for example when no region is |
749 |
|
* defined for the given key). |
750 |
*/ |
*/ |
751 |
Pool<Voice>::Iterator Engine::LaunchVoice(Pool<Event>::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing) { |
Pool<Voice>::Iterator Engine::LaunchVoice(Pool<Event>::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing) { |
752 |
midi_key_info_t* pKey = &pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key]; |
midi_key_info_t* pKey = &pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key]; |
756 |
if (itNewVoice) { |
if (itNewVoice) { |
757 |
// launch the new voice |
// launch the new voice |
758 |
if (itNewVoice->Trigger(itNoteOnEvent, this->Pitch, this->pInstrument, iLayer, ReleaseTriggerVoice, VoiceStealing) < 0) { |
if (itNewVoice->Trigger(itNoteOnEvent, this->Pitch, this->pInstrument, iLayer, ReleaseTriggerVoice, VoiceStealing) < 0) { |
759 |
dmsg(1,("Triggering new voice failed!\n")); |
dmsg(4,("Voice not triggered\n")); |
760 |
pKey->pActiveVoices->free(itNewVoice); |
pKey->pActiveVoices->free(itNewVoice); |
761 |
} |
} |
762 |
else { // on success |
else { // on success |
1184 |
} |
} |
1185 |
|
|
1186 |
String Engine::Version() { |
String Engine::Version() { |
1187 |
String s = "$Revision: 1.17 $"; |
String s = "$Revision: 1.22 $"; |
1188 |
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 |
1189 |
} |
} |
1190 |
|
|