ma_sound_set_end_callback should be called on ma_sound_stop
The callback is not triggered after calling ma_sound_stop, it is called only when we reach the end of the audio file. This may cause a race cindition as we do not know at this point if the audio thread is properly stopped.
I found my answer:
ma_engine_init(nullptr, &engine);
engine.pDevice->onNotification = &on_notification;
That technique is not technically the right way to do it, but probably won't cause any issues. Typically you would configure that via the device config, but that is inconvenient because you would need a self-managed device in that case. A better solution might be for the onNotification callback to be added to ma_engine_config. I'll leave this issue open to remind me to consider adding support for that.
It turns out that support for setting the notification callback via ma_engine_config already exists. The correct way to set the callback is like this:
ma_engine_config engineConfig = ma_engine_config_init();
engineConfig.notificationCallback = on_notification;
ma_engine_init(&engineConfig, &engine);
Thanks you can close this issue.