From cfe19f69785b1a2c744384666d5931993d4ef91f Mon Sep 17 00:00:00 2001 From: Ignacio Sanchez Gines <863613+drhelius@users.noreply.github.com> Date: Thu, 7 Dec 2023 00:15:03 +0100 Subject: [PATCH] Avoid using ALSA when running on WSL --- platforms/audio-shared/Sound_Queue.cpp | 15 ++++++++++++++- platforms/audio-shared/Sound_Queue.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/platforms/audio-shared/Sound_Queue.cpp b/platforms/audio-shared/Sound_Queue.cpp index 4dd4fb1bd..1aaf9270f 100644 --- a/platforms/audio-shared/Sound_Queue.cpp +++ b/platforms/audio-shared/Sound_Queue.cpp @@ -39,7 +39,7 @@ Sound_Queue::Sound_Queue() sync_output = true; std::string platform = SDL_GetPlatform(); - if (platform == "Linux") + if ((platform == "Linux") && (!running_in_wsl())) { SDL_InitSubSystem(SDL_INIT_AUDIO); SDL_AudioInit("alsa"); @@ -172,3 +172,16 @@ void Sound_Queue::fill_buffer_( void* user_data, Uint8* out, int count ) { ((Sound_Queue*) user_data)->fill_buffer( out, count ); } + +bool Sound_Queue::running_in_wsl() +{ + FILE *file; + + if ((file = fopen("/proc/sys/fs/binfmt_misc/WSLInterop", "r"))) + { + fclose(file); + return true; + } + + return false; +} diff --git a/platforms/audio-shared/Sound_Queue.h b/platforms/audio-shared/Sound_Queue.h index d7c4230a6..bcd0ddf06 100644 --- a/platforms/audio-shared/Sound_Queue.h +++ b/platforms/audio-shared/Sound_Queue.h @@ -46,6 +46,7 @@ class Sound_Queue { sample_t* buf( int index ); void fill_buffer( Uint8*, int ); static void fill_buffer_( void*, Uint8*, int ); + bool running_in_wsl(); }; #endif