Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: Add a user_data pointer to audio_mixer_sound #17488

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RobLoach
Copy link
Member

@RobLoach RobLoach commented Jan 30, 2025

This change adds a void* userdata to the audio_mixer_sound_t struct. This allows you to keep some context of the sound that's being stopped when using the audio_mixer_stop_cb_t stop_cb callback in audio_mixer_play().

Without this, you need to reference globals within the thread to retrieve any kind of context, which can be problematic, and not thread-safe.

Example

In the below example, you can see we pass an AppContext pointer which is thread-safe and doesn't mess with globals.

void sound_finished(audio_mixer_sound_t* sound, unsigned reason) {
  AppContext* app = sound->user_data;
}

// ...

mySound->user_data = app;
audio_mixer_play(mySound, false, 1.0f, NULL, 0, sound_finished);

@RobLoach RobLoach changed the title common: Add a user_data pointer to audio_mixer_sound common: Add a user_data pointer to audio_mixer_sound Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant