-
Notifications
You must be signed in to change notification settings - Fork 1
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
Sound effects do not play without music on OSX. #4
Comments
This issue can be reproduced by simply trying to run the sound effect examples from MikMod's documentation. They don't play sound. The reason is the following macro in drivers/drv_osx.c
What's happening here is... OSX uses an audio callback instead of relying on polling MikMod_Update. OSX_Update, called by MikMod_Update when not paused, is a no-op. MikMod_Update is completely unnecessary to use on OSX, but doesn't hurt either. Since OSX_Update doesn't do anything anyway, avoiding it during a pause doesn't have the effect of pausing sound. Therefore this hack in the fill code for the fill thread / core audio callback. Checking if removing the silence case is a possible solution. Which means understanding how the song is being played in the first place on OSX. |
The example program attempts to play the samples, which will set their voices to kick=1, but they will not start playing until virtch runs (VC_WriteSamples) and reacts to this kick and sets active=1 (kick=0). Since no song is loaded and Player_Paused is true, the samples aren't playing, and the example exits immediately. |
If we remove the silence case of fill buffer, then as long as output is enabled (MikMod_EnableOutput) sound effects will work. The music will either play or not depending on the pause flag seen here in Player_HandleTick, called by virtch.
The only issue left would be hanging notes if you pause the song while it is playing. In another patch I fix this by simply silencing all music voices in Player_Pause. And so the OSX driver doesn't need to worry about pausing, it just needs to worry about outputting sound while sound is enabled. |
Checking what this does, the example indeed plays the first sound effect until the second one starts. However there is some delay between activating a sample and when Voice_Stopped reports 0, allowing the do-while to work. So it stops as soon as it hits the second sample instead of playing the second sample to the end. |
Putting a single extra usleep(10000) after playing the second sample makes the example work as intended. It plays both samples and exits. Next I will check that I can play, pause, and unpause music while these sound effects occur... |
And it works as expected. Of course Player_TogglePause and Player_Stop will cause stuck notes. The latter was a bug before I started working on this so isn't my fault! Nonetheless both problems are fixed in two other patches. Here is the patch for the OSX issue
|
I should say that anyone trying to actually run the MikMod sound effect examples in the documentation should turn down the usleep numbers (on not OSX) because usleep(100000) is way too slow to play many samples found online. Again this doesn't make a difference on OSX except to determine how long the loops will take, they have no other effect. |
Thanks for tracking this down. I notice this still seems broken on OS X with the official release (though FILL_BUFFER has changed in the intervening time). Did the mikmod maintainer have any comments on your patch? |
Actually yes see patch 15 on sourceforge: https://sourceforge.net/p/mikmod/patches/13/ |
This appears to be a combination of bugs in the OSX sound driver (see FILL_BUFFER macro) and in MikMod's main handling of pausing.
The text was updated successfully, but these errors were encountered: