--- linuxsampler/trunk/src/engines/gig/Engine.cpp 2005/04/03 19:53:43 493 +++ linuxsampler/trunk/src/engines/gig/Engine.cpp 2005/06/06 16:54:20 614 @@ -103,10 +103,10 @@ pAudioOutputDevice = NULL; pDiskThread = NULL; pEventGenerator = NULL; - pSysexBuffer = new RingBuffer(SYSEX_BUFFER_SIZE, 0); - pEventQueue = new RingBuffer(MAX_EVENTS_PER_FRAGMENT, 0); - pEventPool = new Pool(MAX_EVENTS_PER_FRAGMENT); - pVoicePool = new Pool(MAX_AUDIO_VOICES); + pSysexBuffer = new RingBuffer(CONFIG_SYSEX_BUFFER_SIZE, 0); + pEventQueue = new RingBuffer(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0); + pEventPool = new Pool(CONFIG_MAX_EVENTS_PER_FRAGMENT); + pVoicePool = new Pool(CONFIG_MAX_VOICES); pVoiceStealingQueue = new RTList(pEventPool); pGlobalEvents = new RTList(pEventPool); for (RTList::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) { @@ -231,9 +231,9 @@ this->SampleRate = pAudioOutputDevice->SampleRate(); // FIXME: audio drivers with varying fragment sizes might be a problem here - MaxFadeOutPos = MaxSamplesPerCycle - int(double(SampleRate) * EG_MIN_RELEASE_TIME) - 1; + MaxFadeOutPos = MaxSamplesPerCycle - int(double(SampleRate) * CONFIG_EG_MIN_RELEASE_TIME) - 1; if (MaxFadeOutPos < 0) - throw LinuxSamplerException("EG_MIN_RELEASE_TIME in EGADSR.h too big for current audio fragment size / sampling rate!"); + throw LinuxSamplerException("CONFIG_EG_MIN_RELEASE_TIME too big for current audio fragment size / sampling rate!"); // (re)create disk thread if (this->pDiskThread) { @@ -242,7 +242,7 @@ delete this->pDiskThread; dmsg(1,("OK\n")); } - this->pDiskThread = new DiskThread(((pAudioOut->MaxSamplesPerCycle() << MAX_PITCH) << 1) + 6); //FIXME: assuming stereo + this->pDiskThread = new DiskThread(((pAudioOut->MaxSamplesPerCycle() << CONFIG_MAX_PITCH) << 1) + 6); //FIXME: assuming stereo if (!pDiskThread) { dmsg(0,("gig::Engine new diskthread = NULL\n")); exit(EXIT_FAILURE); @@ -370,10 +370,10 @@ } } - // We only allow a maximum of MAX_AUDIO_VOICES voices to be stolen + // 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 = MAX_AUDIO_VOICES; + VoiceTheftsLeft = CONFIG_MAX_VOICES; // reset internal voice counter (just for statistic of active voices) ActiveVoiceCountTemp = 0; @@ -539,8 +539,8 @@ midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey]; ++iuiKey; if (pKey->pActiveVoices->isEmpty()) FreeKey(pEngineChannel, pKey); - #if DEVMODE - else { // FIXME: should be removed before the final release (purpose: just a sanity check for debugging) + #if CONFIG_DEVMODE + else { // just a sanity check for debugging RTList::Iterator itVoice = pKey->pActiveVoices->first(); RTList::Iterator itVoicesEnd = pKey->pActiveVoices->end(); for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key @@ -549,7 +549,7 @@ } } } - #endif // DEVMODE + #endif // CONFIG_DEVMODE } } @@ -584,7 +584,7 @@ // finally place sysex event into input event queue pEventQueue->push(&event); } - else dmsg(1,("Engine: Sysex message too large (%d byte) for input buffer (%d byte)!",Size,SYSEX_BUFFER_SIZE)); + else dmsg(1,("Engine: Sysex message too large (%d byte) for input buffer (%d byte)!",Size,CONFIG_SYSEX_BUFFER_SIZE)); } else dmsg(1,("Engine: Input event queue full!")); } @@ -660,27 +660,27 @@ // release voices on this key if needed if (pKey->Active && !pEngineChannel->SustainPedal) { itNoteOffEvent->Type = Event::type_release; // transform event type - } - // move event to the key's own event list - RTList::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents); + // move event to the key's own event list + RTList::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents); - // spawn release triggered voice(s) if needed - if (pKey->ReleaseTrigger) { - // first, get total amount of required voices (dependant on amount of layers) - ::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(itNoteOffEventOnKeyList->Param.Note.Key); - if (pRegion) { - int voicesRequired = pRegion->Layers; - // now launch the required amount of voices - for (int i = 0; i < voicesRequired; i++) - LaunchVoice(pEngineChannel, itNoteOffEventOnKeyList, i, true, false); //FIXME: for the moment we don't perform voice stealing for release triggered samples + // spawn release triggered voice(s) if needed + if (pKey->ReleaseTrigger && itNoteOffEventOnKeyList->Param.Note.Velocity) { + // first, get total amount of required voices (dependant on amount of layers) + ::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(itNoteOffEventOnKeyList->Param.Note.Key); + if (pRegion) { + int voicesRequired = pRegion->Layers; + // now launch the required amount of voices + for (int i = 0; i < voicesRequired; i++) + LaunchVoice(pEngineChannel, itNoteOffEventOnKeyList, i, true, false); //FIXME: for the moment we don't perform voice stealing for release triggered samples + } + pKey->ReleaseTrigger = false; } - pKey->ReleaseTrigger = false; - } - // 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); + // 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); + } } /** @@ -781,7 +781,7 @@ */ int Engine::StealVoice(EngineChannel* pEngineChannel, Pool::Iterator& itNoteOnEvent) { if (!VoiceTheftsLeft) { - dmsg(1,("Max. voice thefts per audio fragment reached (you may raise MAX_AUDIO_VOICES).\n")); + dmsg(1,("Max. voice thefts per audio fragment reached (you may raise CONFIG_MAX_VOICES).\n")); return -1; } if (!pEventPool->poolIsEmpty()) { @@ -789,30 +789,23 @@ RTList::Iterator itSelectedVoice; // Select one voice for voice stealing - switch (VOICE_STEAL_ALGORITHM) { + switch (CONFIG_VOICE_STEAL_ALGO) { // try to pick the oldest voice on the key where the new // voice should be spawned, if there is no voice on that - // key, or no voice left to kill there, then procceed with + // key, or no voice left to kill, then procceed with // 'oldestkey' algorithm case voice_steal_algo_oldestvoiceonkey: { - #if 0 // FIXME: broken midi_key_info_t* pSelectedKey = &pEngineChannel->pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key]; - if (this->itLastStolenVoice) { - itSelectedVoice = this->itLastStolenVoice; - ++itSelectedVoice; - } - else { // no voice stolen in this audio fragment cycle yet - itSelectedVoice = pSelectedKey->pActiveVoices->first(); - } - if (itSelectedVoice) { - iuiSelectedKey = pSelectedKey->itSelf; - break; // selection succeeded - } - #endif + itSelectedVoice = pSelectedKey->pActiveVoices->first(); + // proceed iterating if voice was created in this fragment cycle + while (itSelectedVoice && !itSelectedVoice->hasRendered()) ++itSelectedVoice; + // if we haven't found a voice then proceed with algorithm 'oldestkey' + if (itSelectedVoice && itSelectedVoice->hasRendered()) break; } // no break - intentional ! // try to pick the oldest voice on the oldest active key + // from the same engine channel // (caution: must stay after 'oldestvoiceonkey' algorithm !) case voice_steal_algo_oldestkey: { if (this->itLastStolenVoice) { @@ -839,7 +832,8 @@ } } - // 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 + // steal oldest voice on the oldest key from any other engine channel if (!itSelectedVoice) { EngineChannel* pSelectedChannel = (pLastStolenChannel) ? pLastStolenChannel : pEngineChannel; int iChannelIndex = pSelectedChannel->iEngineIndexSelf; @@ -857,11 +851,12 @@ } } - //FIXME: can be removed, just a sanity check for debugging + #if CONFIG_DEVMODE if (!itSelectedVoice->IsActive()) { dmsg(1,("gig::Engine: ERROR, tried to steal a voice which was not active !!!\n")); return -1; } + #endif // CONFIG_DEVMODE // now kill the selected voice itSelectedVoice->Kill(itNoteOnEvent); @@ -1054,8 +1049,9 @@ if (reader.read(&scale_tunes[0], 12) != 12) goto free_sysex_data; uint8_t checksum; if (!reader.pop(&checksum)) goto free_sysex_data; - // some are not sending a GS checksum, so we ignore it for now - //if (GSCheckSum(checksum_reader, 12)) goto free_sysex_data; + #if CONFIG_ASSERT_GS_SYSEX_CHECKSUM + if (GSCheckSum(checksum_reader, 12)) goto free_sysex_data; + #endif // CONFIG_ASSERT_GS_SYSEX_CHECKSUM for (int i = 0; i < 12; i++) scale_tunes[i] -= 64; AdjustScale((int8_t*) scale_tunes); dmsg(3,("\t\t\tNew scale applied.\n")); @@ -1199,7 +1195,7 @@ } String Engine::Version() { - String s = "$Revision: 1.35 $"; + String s = "$Revision: 1.39 $"; return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword }