Skip to content

Commit

Permalink
remove sub millisecond check in MIDI player loop
Browse files Browse the repository at this point in the history
From my tests, it appears that I_SleepUS for periods < 500 us just return
immediately, at least on Windows.
  • Loading branch information
rfomin committed Sep 20, 2024
1 parent d931f75 commit 5c952ca
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
4 changes: 0 additions & 4 deletions src/i_midimusic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1237,10 +1237,6 @@ static int PlayerThread(void *unused)
sleep = true;
break;
}
if (remaining_time > 0)
{
I_SleepUS(remaining_time);
}
ProcessEvent(position.event, position.track);
midi_state = STATE_PLAYING;
}
Expand Down
9 changes: 3 additions & 6 deletions src/i_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,14 @@ void I_InitTimer(void)

#ifdef _WIN32
// Create an unnamed waitable timer.
hTimer = NULL;
#ifdef HAVE_HIGH_RES_TIMER
hTimer = CreateWaitableTimerEx(NULL, NULL,
CREATE_WAITABLE_TIMER_MANUAL_RESET
| CREATE_WAITABLE_TIMER_HIGH_RESOLUTION,
TIMER_ALL_ACCESS);
#else
hTimer = CreateWaitableTimer(NULL, TRUE, NULL);
#endif
if (hTimer == NULL)
{
hTimer = CreateWaitableTimer(NULL, TRUE, NULL);
}

if (hTimer == NULL)
{
Expand Down Expand Up @@ -218,7 +215,7 @@ void I_SleepUS(uint64_t us)
{
#if defined(_WIN32)
LARGE_INTEGER liDueTime;
liDueTime.QuadPart = -(LONGLONG)(us * 1000 / 100);
liDueTime.QuadPart = -(LONGLONG)(us * 10);
if (SetWaitableTimer(hTimer, &liDueTime, 0, NULL, NULL, 0))
{
WaitForSingleObject(hTimer, INFINITE);
Expand Down

0 comments on commit 5c952ca

Please sign in to comment.