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(); |
ResetScaleTuning(); |
113 |
} |
} |
129 |
delete pVoicePool; |
delete pVoicePool; |
130 |
} |
} |
131 |
if (pEventGenerator) delete pEventGenerator; |
if (pEventGenerator) delete pEventGenerator; |
|
if (pMainFilterParameters) delete[] pMainFilterParameters; |
|
|
if (pBasicFilterParameters) delete[] pBasicFilterParameters; |
|
|
if (pSynthesisParameters[0]) free(pSynthesisParameters[0]); |
|
132 |
if (pVoiceStealingQueue) delete pVoiceStealingQueue; |
if (pVoiceStealingQueue) delete pVoiceStealingQueue; |
133 |
if (pSysexBuffer) delete pSysexBuffer; |
if (pSysexBuffer) delete pSysexBuffer; |
134 |
EngineFactory::Destroy(this); |
EngineFactory::Destroy(this); |
236 |
// lower minimum release time |
// lower minimum release time |
237 |
const float minReleaseTime = (float) MaxSamplesPerCycle / (float) SampleRate; |
const float minReleaseTime = (float) MaxSamplesPerCycle / (float) SampleRate; |
238 |
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()) { |
239 |
iterVoice->pEG1->CalculateFadeOutCoeff(minReleaseTime, SampleRate); |
iterVoice->EG1.CalculateFadeOutCoeff(minReleaseTime, SampleRate); |
240 |
} |
} |
241 |
pVoicePool->clear(); |
pVoicePool->clear(); |
242 |
} |
} |
264 |
if (pEventGenerator) delete pEventGenerator; |
if (pEventGenerator) delete pEventGenerator; |
265 |
pEventGenerator = new EventGenerator(pAudioOut->SampleRate()); |
pEventGenerator = new EventGenerator(pAudioOut->SampleRate()); |
266 |
|
|
|
// (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()]; |
|
|
|
|
267 |
dmsg(1,("Starting disk thread...")); |
dmsg(1,("Starting disk thread...")); |
268 |
pDiskThread->StartThread(); |
pDiskThread->StartThread(); |
269 |
dmsg(1,("OK\n")); |
dmsg(1,("OK\n")); |
462 |
* this audio fragment cycle |
* this audio fragment cycle |
463 |
*/ |
*/ |
464 |
void Engine::RenderActiveVoices(EngineChannel* pEngineChannel, uint Samples) { |
void Engine::RenderActiveVoices(EngineChannel* pEngineChannel, uint Samples) { |
465 |
|
#if !CONFIG_PROCESS_MUTED_CHANNELS |
466 |
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
467 |
|
#endif |
468 |
|
|
469 |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
470 |
RTList<uint>::Iterator end = pEngineChannel->pActiveKeys->end(); |
RTList<uint>::Iterator end = pEngineChannel->pActiveKeys->end(); |
594 |
* @param itNoteOnEvent - key, velocity and time stamp of the event |
* @param itNoteOnEvent - key, velocity and time stamp of the event |
595 |
*/ |
*/ |
596 |
void Engine::ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) { |
void Engine::ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) { |
597 |
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
#if !CONFIG_PROCESS_MUTED_CHANNELS |
598 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
599 |
|
#endif |
600 |
|
|
601 |
const int key = itNoteOnEvent->Param.Note.Key; |
const int key = itNoteOnEvent->Param.Note.Key; |
602 |
|
|
656 |
* @param itNoteOffEvent - key, velocity and time stamp of the event |
* @param itNoteOffEvent - key, velocity and time stamp of the event |
657 |
*/ |
*/ |
658 |
void Engine::ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) { |
void Engine::ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) { |
659 |
|
#if !CONFIG_PROCESS_MUTED_CHANNELS |
660 |
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
661 |
|
#endif |
662 |
|
|
663 |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[itNoteOffEvent->Param.Note.Key]; |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[itNoteOffEvent->Param.Note.Key]; |
664 |
pKey->KeyPressed = false; // the MIDI key was now released |
pKey->KeyPressed = false; // the MIDI key was now released |
694 |
} |
} |
695 |
|
|
696 |
/** |
/** |
697 |
* Moves pitchbend event from the general (input) event list to the pitch |
* Moves pitchbend event from the general (input) event list to the engine |
698 |
* event list. |
* channel's event list. It will actually processed later by the |
699 |
|
* respective voice. |
700 |
* |
* |
701 |
* @param pEngineChannel - engine channel on which this event occured on |
* @param pEngineChannel - engine channel on which this event occured on |
702 |
* @param itPitchbendEvent - absolute pitch value and time stamp of the event |
* @param itPitchbendEvent - absolute pitch value and time stamp of the event |
703 |
*/ |
*/ |
704 |
void Engine::ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent) { |
void Engine::ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent) { |
705 |
pEngineChannel->Pitch = itPitchbendEvent->Param.Pitch.Pitch; // store current pitch value |
pEngineChannel->Pitch = itPitchbendEvent->Param.Pitch.Pitch; // store current pitch value |
706 |
itPitchbendEvent.moveToEndOf(pEngineChannel->pSynthesisEvents[Event::destination_vco]); |
itPitchbendEvent.moveToEndOf(pEngineChannel->pEvents); |
707 |
} |
} |
708 |
|
|
709 |
/** |
/** |
1140 |
// update controller value in the engine channel's controller table |
// update controller value in the engine channel's controller table |
1141 |
pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value; |
pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value; |
1142 |
|
|
1143 |
// move event from the unsorted event list to the control change event list |
// move event from the import event list to the engine channel's CC and pitchbend event list |
1144 |
Pool<Event>::Iterator itControlChangeEventOnCCList = itControlChangeEvent.moveToEndOf(pEngineChannel->pCCEvents); |
Pool<Event>::Iterator itControlChangeEventOnCCList = itControlChangeEvent.moveToEndOf(pEngineChannel->pEvents); |
1145 |
|
|
1146 |
switch (itControlChangeEventOnCCList->Param.CC.Controller) { |
switch (itControlChangeEventOnCCList->Param.CC.Controller) { |
1147 |
case 7: { // volume |
case 7: { // volume |
1162 |
dmsg(4,("PEDAL DOWN\n")); |
dmsg(4,("PEDAL DOWN\n")); |
1163 |
pEngineChannel->SustainPedal = true; |
pEngineChannel->SustainPedal = true; |
1164 |
|
|
1165 |
|
#if !CONFIG_PROCESS_MUTED_CHANNELS |
1166 |
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
1167 |
|
#endif |
1168 |
|
|
1169 |
// cancel release process of voices if necessary |
// cancel release process of voices if necessary |
1170 |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
1184 |
dmsg(4,("PEDAL UP\n")); |
dmsg(4,("PEDAL UP\n")); |
1185 |
pEngineChannel->SustainPedal = false; |
pEngineChannel->SustainPedal = false; |
1186 |
|
|
1187 |
|
#if !CONFIG_PROCESS_MUTED_CHANNELS |
1188 |
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
1189 |
|
#endif |
1190 |
|
|
1191 |
// release voices if their respective key is not pressed |
// release voices if their respective key is not pressed |
1192 |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
1360 |
} |
} |
1361 |
} |
} |
1362 |
|
|
|
/** |
|
|
* Initialize the parameter sequence for the modulation destination given by |
|
|
* by 'dst' with the constant value given by val. |
|
|
*/ |
|
|
void Engine::ResetSynthesisParameters(Event::destination_t dst, float val) { |
|
|
int maxsamples = pAudioOutputDevice->MaxSamplesPerCycle(); |
|
|
float* m = &pSynthesisParameters[dst][0]; |
|
|
for (int i = 0; i < maxsamples; i += 4) { |
|
|
m[i] = val; |
|
|
m[i+1] = val; |
|
|
m[i+2] = val; |
|
|
m[i+3] = val; |
|
|
} |
|
|
} |
|
|
|
|
1363 |
uint Engine::VoiceCount() { |
uint Engine::VoiceCount() { |
1364 |
return ActiveVoiceCount; |
return ActiveVoiceCount; |
1365 |
} |
} |
1397 |
} |
} |
1398 |
|
|
1399 |
String Engine::Version() { |
String Engine::Version() { |
1400 |
String s = "$Revision: 1.50 $"; |
String s = "$Revision: 1.52 $"; |
1401 |
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 |
1402 |
} |
} |
1403 |
|
|