aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/midi/dummy.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-02-02 02:39:56 -0800
committerChris Robinson <[email protected]>2014-02-02 02:39:56 -0800
commit7c4339c195e29b17c8f76e6fbe9c8ee1b4f7b9b8 (patch)
tree728e3298bff7d7612ee6d7fcd88a2049d343d763 /Alc/midi/dummy.c
parent755f161fc58aec0b541c7783ed716bd5c861a615 (diff)
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.
Diffstat (limited to 'Alc/midi/dummy.c')
-rw-r--r--Alc/midi/dummy.c27
1 files changed, 7 insertions, 20 deletions
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));
}