SDL: Revert "WASAPI_WaitDevice: Check current padding before waiting on event"

From 90beffdeb1425b7c8fd9630c47da052e703838e0 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 30 May 2024 16:48:54 -0700
Subject: [PATCH] Revert "WASAPI_WaitDevice: Check current padding before
 waiting on event"

This reverts commit 09fbb2a07dfca7f3daf4f9c24d5bc0c8ee62cfce.

This was causing issues in CS2 and DOTA:
https://old.reddit.com/r/DotA2/comments/1d4bqe3/dota_2_sound_crackling_since_this_morning/
https://old.reddit.com/r/DotA2/comments/1d44udf/anyone_having_sound_issues_or_any_clue_how_to_fix/
---
 src/audio/wasapi/SDL_wasapi.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/src/audio/wasapi/SDL_wasapi.c b/src/audio/wasapi/SDL_wasapi.c
index c3c8c49d7fe29..a365b0dc1c035 100644
--- a/src/audio/wasapi/SDL_wasapi.c
+++ b/src/audio/wasapi/SDL_wasapi.c
@@ -465,22 +465,20 @@ static int WASAPI_WaitDevice(SDL_AudioDevice *device)
 {
     // WaitDevice does not hold the device lock, so check for recovery/disconnect details here.
     while (RecoverWasapiIfLost(device) && device->hidden->client && device->hidden->event) {
-        UINT32 padding = 0;
-        if (!WasapiFailed(device, IAudioClient_GetCurrentPadding(device->hidden->client, &padding))) {
+        DWORD waitResult = WaitForSingleObjectEx(device->hidden->event, 200, FALSE);
+        if (waitResult == WAIT_OBJECT_0) {
             const UINT32 maxpadding = device->sample_frames;
-            //SDL_Log("WASAPI %s EVENT! padding=%u maxpadding=%u", device->iscapture ? "CAPTURE" : "PLAYBACK", (unsigned int)padding, (unsigned int)maxpadding);
-            if (device->iscapture ? (padding > 0) : (padding < maxpadding)) {
-                break;
+            UINT32 padding = 0;
+            if (!WasapiFailed(device, IAudioClient_GetCurrentPadding(device->hidden->client, &padding))) {
+                //SDL_Log("WASAPI EVENT! padding=%u maxpadding=%u", (unsigned int)padding, (unsigned int)maxpadding);*/
+                if (device->iscapture && (padding > 0)) {
+                    break;
+                } else if (!device->iscapture && (padding <= maxpadding)) {
+                    break;
+                }
             }
-        }
-
-        switch (WaitForSingleObjectEx(device->hidden->event, 200, FALSE)) {
-        case WAIT_OBJECT_0:
-        case WAIT_TIMEOUT:
-            break;
-
-        default:
-            //SDL_Log("WASAPI FAILED EVENT!");
+        } else if (waitResult != WAIT_TIMEOUT) {
+            //SDL_Log("WASAPI FAILED EVENT!");*/
             IAudioClient_Stop(device->hidden->client);
             return -1;
         }