diff options
author | Simon Howard | 2014-05-11 00:14:04 -0400 |
---|---|---|
committer | Simon Howard | 2014-05-11 00:14:04 -0400 |
commit | 72ce4242077f23b7de876b977397856bd072a6b1 (patch) | |
tree | 1002b8eb4f15d16564a1acadfcd04a264cde558d /src | |
parent | 495694da29ff736fba2fdc696553ee7197247174 (diff) | |
download | chocolate-doom-72ce4242077f23b7de876b977397856bd072a6b1.tar.gz chocolate-doom-72ce4242077f23b7de876b977397856bd072a6b1.tar.bz2 chocolate-doom-72ce4242077f23b7de876b977397856bd072a6b1.zip |
opl: Change library to use us instead of ms.
Multi-track MIDI files are played back using separate callback chains
for each track, and this introduces the possibility of one track
becoming out of sync with the others. This was noticeable in WADs
that use multi-track MIDIs, such as Alien Vendetta. Increase the
timing resolution to microsecond precision to fix this.
Diffstat (limited to 'src')
-rw-r--r-- | src/i_oplmusic.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/i_oplmusic.c b/src/i_oplmusic.c index 489b6d55..5f9ab462 100644 --- a/src/i_oplmusic.c +++ b/src/i_oplmusic.c @@ -47,7 +47,7 @@ #define PERCUSSION_LOG_LEN 16 // TODO: Figure out why this is needed. -#define TEMPO_FUDGE_FACTOR 0.26 +#define TEMPO_FUDGE_FACTOR 260 typedef struct { @@ -1160,7 +1160,7 @@ static void TrackTimerCallback(void *arg) if (running_tracks <= 0 && song_looping) { - OPL_SetCallback(5, RestartSong, NULL); + OPL_SetCallback(5000, RestartSong, NULL); } return; @@ -1174,19 +1174,18 @@ static void TrackTimerCallback(void *arg) static void ScheduleTrack(opl_track_data_t *track) { unsigned int nticks; - uint64_t ms; + uint64_t us; - // Get the number of milliseconds until the next event. + // Get the number of microseconds until the next event. nticks = MIDI_GetDeltaTime(track->iter); - ms = nticks; - ms *= us_per_beat * TEMPO_FUDGE_FACTOR; - ms /= ticks_per_beat; + us = ((uint64_t) nticks * us_per_beat * TEMPO_FUDGE_FACTOR) + / ticks_per_beat; // Set a timer to be invoked when the next event is // ready to play. - OPL_SetCallback((unsigned int) ms, TrackTimerCallback, track); + OPL_SetCallback(us, TrackTimerCallback, track); } // Initialize a channel. |