From 7c4339c195e29b17c8f76e6fbe9c8ee1b4f7b9b8 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 2 Feb 2014 02:39:56 -0800 Subject: Rework MIDI clock timing It's best to avoid using doubles in the mixer since the FPU's set to single- precision mode. The new clock timing is similar to the device clock timing, and should hopefully be less prone to drift caused by fp rounding errors. --- Alc/midi/dummy.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'Alc/midi/dummy.c') diff --git a/Alc/midi/dummy.c b/Alc/midi/dummy.c index 71c03efb..79f82b87 100644 --- a/Alc/midi/dummy.c +++ b/Alc/midi/dummy.c @@ -49,30 +49,17 @@ static void DSynth_processQueue(DSynth *self, ALuint64 time) static void DSynth_process(DSynth *self, ALuint SamplesToDo, ALfloatBUFFERSIZE*restrict UNUSED(DryBuffer)) { MidiSynth *synth = STATIC_CAST(MidiSynth, self); + ALuint64 curtime; if(synth->State != AL_PLAYING) return; - synth->SamplesSinceLast += SamplesToDo; - synth->SamplesToNext -= SamplesToDo; - while(synth->SamplesToNext < 1.0f) - { - ALuint64 time = synth->NextEvtTime; - if(time == UINT64_MAX) - { - synth->SamplesToNext = 0.0; - break; - } - - synth->SamplesSinceLast -= (time - synth->LastEvtTime) * synth->SamplesPerTick; - synth->SamplesSinceLast = maxd(synth->SamplesSinceLast, 0.0); - synth->LastEvtTime = time; - DSynth_processQueue(self, time); - - synth->NextEvtTime = MidiSynth_getNextEvtTime(synth); - if(synth->NextEvtTime != UINT64_MAX) - synth->SamplesToNext += (synth->NextEvtTime - synth->LastEvtTime) * synth->SamplesPerTick; - } + synth->SamplesDone += SamplesToDo; + synth->ClockBase += (synth->SamplesDone/synth->SampleRate) * MIDI_CLOCK_RES; + synth->SamplesDone %= synth->SampleRate; + + curtime = MidiSynth_getTime(synth); + DSynth_processQueue(self, maxi64(curtime-1, 0)); } -- cgit v1.2.3