From 11b6a629dad33193cdbac2c6dac3c99854535388 Mon Sep 17 00:00:00 2001
From: onesixromcom <[EMAIL REDACTED]>
Date: Tue, 29 Sep 2026 22:24:50 +0300
Subject: [PATCH] [ps2] disconnected audio fix
---
src/audio/ps2/SDL_ps2audio.c | 20 +++++++++++++-------
src/audio/ps2/SDL_ps2audio.h | 1 -
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/src/audio/ps2/SDL_ps2audio.c b/src/audio/ps2/SDL_ps2audio.c
index 2100bf04055ca..92dc78b9fcd07 100644
--- a/src/audio/ps2/SDL_ps2audio.c
+++ b/src/audio/ps2/SDL_ps2audio.c
@@ -20,6 +20,8 @@
*/
#include "SDL_internal.h"
+#ifdef SDL_AUDIO_DRIVER_PS2
+
#include "../SDL_sysaudio.h"
#include "SDL_ps2audio.h"
@@ -68,9 +70,9 @@ static bool PS2AUDIO_OpenDevice(SDL_AudioDevice *device)
// Update the fragment size as size in bytes.
SDL_UpdatedAudioDeviceFormat(device);
- /* Allocate the mixing buffer. Its size and starting address must
- be a multiple of 64 bytes. Our sample count is already a multiple of
- 64, so spec->size should be a multiple of 64 as well. */
+ // Allocate the mixing buffer. Its size and starting address must
+ // be a multiple of 64 bytes. Our sample count is already a multiple of
+ // 64, so spec->size should be a multiple of 64 as well.
const int mixlen = device->buffer_size * NUM_BUFFERS;
device->hidden->rawbuf = (Uint8 *)SDL_aligned_alloc(64, mixlen);
if (!device->hidden->rawbuf) {
@@ -87,8 +89,10 @@ static bool PS2AUDIO_OpenDevice(SDL_AudioDevice *device)
static bool PS2AUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
{
- // this returns number of bytes accepted or a negative error. We assume anything other than buflen is a fatal error.
- return (audsrv_play_audio((char *)buffer, buflen) == buflen);
+ // We assume it's working by default. In case if we throw error
+ // audio device will be removed and never recreated.
+ audsrv_play_audio((char *)buffer, buflen);
+ return true;
}
static bool PS2AUDIO_WaitDevice(SDL_AudioDevice *device)
@@ -123,8 +127,8 @@ static void PS2AUDIO_CloseDevice(SDL_AudioDevice *device)
static void PS2AUDIO_ThreadInit(SDL_AudioDevice *device)
{
- /* Increase the priority of this audio thread by 1 to put it
- ahead of other SDL threads. */
+ // Increase the priority of this audio thread by 1 to put it
+ // ahead of other SDL threads.
const int32_t thid = GetThreadId();
ee_thread_status_t status;
if (ReferThreadStatus(thid, &status) == 0) {
@@ -157,3 +161,5 @@ static bool PS2AUDIO_Init(SDL_AudioDriverImpl *impl)
AudioBootStrap PS2AUDIO_bootstrap = {
"ps2", "PS2 audio driver", PS2AUDIO_Init, false, false
};
+
+#endif // SDL_AUDIO_DRIVER_PS2
diff --git a/src/audio/ps2/SDL_ps2audio.h b/src/audio/ps2/SDL_ps2audio.h
index b79e396149726..8e878963bd17e 100644
--- a/src/audio/ps2/SDL_ps2audio.h
+++ b/src/audio/ps2/SDL_ps2audio.h
@@ -18,7 +18,6 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
-#include "SDL_internal.h"
#ifndef SDL_ps2audio_h_
#define SDL_ps2audio_h_