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

Pausing music also pauses sound effects. #5

Open
evanrinehart opened this issue Feb 4, 2015 · 1 comment
Open

Pausing music also pauses sound effects. #5

evanrinehart opened this issue Feb 4, 2015 · 1 comment
Assignees
Labels

Comments

@evanrinehart
Copy link
Owner

This happens on OSX and Linux. On OSX sound effects refuse to play at all without music and on Linux sound works normally as long as music is not loaded. In either case a song loaded but not playing will cause sound effects to not play.

This is caused by (what I'm calling) a bug in MikMod's main driver. In MikMod_Update it plays sound
if no song is loaded or if a song is loaded and unpaused. I submitted a patch to change this so that sound plays even if song is loaded and paused. It also takes care of stuck notes if the song is paused (which previously was taken care of by the fact that all sound was not working).

@evanrinehart evanrinehart self-assigned this Feb 4, 2015
@evanrinehart
Copy link
Owner Author

Here is the patch

From 0e4dd1f5ffb737243aec2a40ac9c4511bd61ebb2 Mon Sep 17 00:00:00 2001
From: EvanR <evanrinehart@gmail.com>
Date: Tue, 3 Feb 2015 15:47:00 -0600
Subject: [PATCH] Bugfix for allowing sound effects while a song is paused.

These are changes to the way sound effects and pausing interact
which fits how I think it should work. I checked all this on
Linux ALSA driver, and a separate fix for OSX is not included.
(There is a similar issue on OSX which doesn't allow sound
to play at all unless there is a module loaded and unpaused.)

The bug can be reproduced using the sound effect example from
the documentation. First register all loaders, then load a
module, then play the module sometime before playing the two
sound effects. In between the two sound effects place a
Player_TogglePause. First the song and the sound effect will
begin to play, then the pause will cause both to freeze until
another Player_TogglePause is issued. Both the song and the
sound effect will resume and probably the song sound effect
will start from the beginning, regardless of what time before
the unpause it was played.

However if you did not play the module and tried the experiment
the toggle pause would have no effect and both sound effects
would play normally. Sound effects work (on Linux) normally
when there is no current song. When a song is loaded the sound
effects depend on the pausing (forbid flag) of that song.

I think the sound effects should be independent of the song
no matter what. The changes necessary for this for work on Linux
required no changes to the ALSA driver, so will likely work
for any platform that doesn't do weird things with the pf
and forbid variables (current song and paused state). OSX is
unfortunately a driver which is doing weird things but that
is another patch.

The fix involves changing MikMod_Update_internal to play sound
regardless of whether there is a current song or if it is paused.
Currently it plays sound if there is no song (so sound effects
at least minimally work) or if the current song is unpaused.
This is the mechanism by which pausing stops sound effects, which
I think is wrong. By removing this check sound effects always
work. This does not allow the sometimes-available issuing of
driver->Pause(). However the cpu usage of ALSAs non-blocking IO
is already better solved by using a fill thread like in OSX.

The other change for this to work involves cutting music voices
when a pause is issued. This is necessary because pausing no
longer cancels all sound via MikMod_Update_internal. This is
similar to another bug fix I submitted where Player_Stop does
not cut the notes either, instead relying on DisableOutput. That
bug (see the other patch) is caused by not disabling output if
there are sound effects, which makes sense. Anyway you just need
to cut the notes which is included in the patch.
---
 playercode/mdriver.c |    7 +------
 playercode/mplayer.c |    6 +++++-
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/playercode/mdriver.c b/playercode/mdriver.c
index bd8c02b..ffa45f9 100644
--- a/playercode/mdriver.c
+++ b/playercode/mdriver.c
@@ -312,12 +312,7 @@ MIKMODAPI void MikMod_Update(void)
 {
    MUTEX_LOCK(vars);
    if(isplaying) {
-       if((!pf)||(!pf->forbid))
-           md_driver->Update();
-       else {
-           if (md_driver->Pause)
-               md_driver->Pause();
-       }
+       md_driver->Update();
    }
    MUTEX_UNLOCK(vars);
 }
diff --git a/playercode/mplayer.c b/playercode/mplayer.c
index 366df6b..d4b4f64 100644
--- a/playercode/mplayer.c
+++ b/playercode/mplayer.c
@@ -3354,9 +3354,13 @@ MIKMODAPI BOOL Player_Paused(void)

 MIKMODAPI void Player_TogglePause(void)
 {
+   int t;
    MUTEX_LOCK(vars);
-   if (pf)
+   if (pf) {
        pf->forbid=1-pf->forbid;
+       if (pf->forbid)
+           for (t=0;t<md_sngchn;t++) Voice_Stop_internal(t);
+   }
    MUTEX_UNLOCK(vars);
 }

-- 
1.7.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant