--- linuxsampler/trunk/src/engines/gig/Voice.cpp 2008/02/17 12:40:59 1700 +++ linuxsampler/trunk/src/engines/gig/Voice.cpp 2009/03/07 19:23:10 1857 @@ -3,7 +3,7 @@ * LinuxSampler - modular, streaming capable sampler * * * * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * - * Copyright (C) 2005 - 2007 Christian Schoenebeck * + * Copyright (C) 2005 - 2009 Christian Schoenebeck * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -781,13 +781,34 @@ RTList::Iterator itCCEvent = pEngineChannel->pEvents->first(); RTList::Iterator itNoteEvent = pEngineChannel->pMIDIKeyInfo[MIDIKey].pEvents->first(); - if (Skip) { // skip events that happened before this voice was triggered + if (itTriggerEvent) { // skip events that happened before this voice was triggered while (itCCEvent && itCCEvent->FragmentPos() <= Skip) ++itCCEvent; - while (itNoteEvent && itNoteEvent->FragmentPos() <= Skip) ++itNoteEvent; + // we can't simply compare the timestamp here, because note events + // might happen on the same time stamp, so we have to deal on the + // actual sequence the note events arrived instead (see bug #112) + for (; itNoteEvent; ++itNoteEvent) { + if (itTriggerEvent == itNoteEvent) { + ++itNoteEvent; + break; + } + } } uint killPos; - if (itKillEvent) killPos = RTMath::Min(itKillEvent->FragmentPos(), pEngine->MaxFadeOutPos); + if (itKillEvent) { + int maxFadeOutPos = Samples - pEngine->MinFadeOutSamples; + if (maxFadeOutPos < 0) { + // There's not enough space in buffer to do a fade out + // from max volume (this can only happen for audio + // drivers that use Samples < MaxSamplesPerCycle). + // End the EG1 here, at pos 0, with a shorter max fade + // out time. + EG1.enterFadeOutStage(Samples / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); + itKillEvent = Pool::Iterator(); + } else { + killPos = RTMath::Min(itKillEvent->FragmentPos(), maxFadeOutPos); + } + } uint i = Skip; while (i < Samples) {