commit 8921099fb0ecc9497cbd433a96dfa243a593cffc
Author: Michael Day <mikeguy42@gmail.com>
AuthorDate: Mon Jun 28 21:58:25 2021 -0400
Commit: Michael Day <mikeguy42@gmail.com>
CommitDate: Mon Jun 28 21:58:25 2021 -0400
Fix PC speaker emulation when using OPL
Replace Mix_SetPostMix calls with Mix_RegisterEffect calls.
Mix_SetPostMix allows only one callback to be registered, while
Mix_RegisterEffect can handle multiple.
This fixes an issue where PC speaker effects would not work when used
simultaneously with OPL emulation.
Fixes #1184.
---
opl/opl_sdl.c | 5 +++--
pcsound/pcsound_sdl.c | 4 ++--
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/opl/opl_sdl.c b/opl/opl_sdl.c
index e2c16490..fc71be31 100644
--- a/opl/opl_sdl.c
+++ b/opl/opl_sdl.c
@@ -172,9 +172,10 @@ static void FillBuffer(uint8_t *buffer, unsigned int nsamples)
// Callback function to fill a new sound buffer:
-static void OPL_Mix_Callback(void *udata, Uint8 *buffer, int len)
+static void OPL_Mix_Callback(int chan, void *stream, int len, void *udata)
{
unsigned int filled, buffer_samples;
+ Uint8 *buffer = (Uint8*)stream;
// Repeatedly call the OPL emulator update function until the buffer is
// full.
@@ -351,7 +352,7 @@ static int OPL_SDL_Init(unsigned int port_base)
// Set postmix that adds the OPL music. This is deliberately done
// as a postmix and not using Mix_HookMusic() as the latter disables
// normal SDL_mixer music mixing.
- Mix_SetPostMix(OPL_Mix_Callback, NULL);
+ Mix_RegisterEffect(MIX_CHANNEL_POST, OPL_Mix_Callback, NULL, NULL);
return 1;
}
diff --git a/pcsound/pcsound_sdl.c b/pcsound/pcsound_sdl.c
index ee82f527..c25ac7f9 100644
--- a/pcsound/pcsound_sdl.c
+++ b/pcsound/pcsound_sdl.c
@@ -53,7 +53,7 @@ static int phase_offset = 0;
// Mixer function that does the PC speaker emulation
-static void PCSound_Mix_Callback(void *udata, Uint8 *stream, int len)
+static void PCSound_Mix_Callback(int chan, void *stream, int len, void *udata)
{
Sint16 *leftptr;
Sint16 *rightptr;
@@ -236,7 +236,7 @@ static int PCSound_SDL_Init(pcsound_callback_func callback_func)
current_freq = 0;
current_remaining = 0;
- Mix_SetPostMix(PCSound_Mix_Callback, NULL);
+ Mix_RegisterEffect(MIX_CHANNEL_POST, PCSound_Mix_Callback, NULL, NULL);
return 1;
}