From f496718617f3f149e8b15ba6a4f47efa5bc71a99 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Fri, 19 Dec 2025 22:08:32 -0500
Subject: [PATCH] api: Added mixer property of opened audio device ID (if any).
Fixes #782.
---
include/SDL3_mixer/SDL_mixer.h | 12 ++++++++----
src/SDL_mixer.c | 7 +++++++
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/include/SDL3_mixer/SDL_mixer.h b/include/SDL3_mixer/SDL_mixer.h
index 76073aa2..3555060b 100644
--- a/include/SDL3_mixer/SDL_mixer.h
+++ b/include/SDL3_mixer/SDL_mixer.h
@@ -463,14 +463,15 @@ extern SDL_DECLSPEC MIX_Mixer * SDLCALL MIX_CreateMixer(const SDL_AudioSpec *spe
*/
extern SDL_DECLSPEC void SDLCALL MIX_DestroyMixer(MIX_Mixer *mixer);
+
/**
* Get the properties associated with a mixer.
*
- * Currently SDL_mixer assigns no properties of its own to a mixer, but this
- * can be a convenient place to store app-specific data.
+ * The following read-only properties are provided by SDL_mixer:
*
- * A SDL_PropertiesID is created the first time this function is called for a
- * given mixer.
+ * - `MIX_PROP_MIXER_DEVICE_NUMBER`: the SDL_AudioDeviceID that this mixer
+ * has opened for playback. This will be zero (no device) if the mixer was
+ * created with Mix_CreateMixer() instead of Mix_CreateMixerDevice().
*
* \param mixer the mixer to query.
* \returns a valid property ID on success or 0 on failure; call
@@ -482,6 +483,9 @@ extern SDL_DECLSPEC void SDLCALL MIX_DestroyMixer(MIX_Mixer *mixer);
*/
extern SDL_DECLSPEC SDL_PropertiesID SDLCALL MIX_GetMixerProperties(MIX_Mixer *mixer);
+#define MIX_PROP_MIXER_DEVICE_NUMBER "SDL_mixer.mixer.device"
+
+
/**
* Get the audio format a mixer is generating.
*
diff --git a/src/SDL_mixer.c b/src/SDL_mixer.c
index 432cd572..dba481cb 100644
--- a/src/SDL_mixer.c
+++ b/src/SDL_mixer.c
@@ -760,6 +760,11 @@ static MIX_Mixer *CreateMixer(SDL_AudioStream *stream)
mixer->gain = 1.0f;
mixer->output_stream = stream;
+ mixer->props = SDL_CreateProperties();
+ if (!mixer->props) {
+ goto failed;
+ }
+
mixer->track_tags = SDL_CreateProperties();
if (!mixer->track_tags) {
goto failed;
@@ -770,6 +775,8 @@ static MIX_Mixer *CreateMixer(SDL_AudioStream *stream)
goto failed;
}
+ SDL_SetNumberProperty(mixer->props, MIX_PROP_MIXER_DEVICE_NUMBER, SDL_GetAudioStreamDevice(stream));
+
SDL_SetAudioStreamGetCallback(stream, MixerCallback, mixer);
MIX_VBAP2D_Init(&mixer->vbap2d, output_spec.channels);