ref: 8921099fb0ecc9497cbd433a96dfa243a593cffc
parent: c3e9173772e07ee21f3cea39fd6e3935ed95a02c
author: Michael Day <mikeguy42@gmail.com>
date: Mon Jun 28 17:58:25 EDT 2021
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.
--- a/opl/opl_sdl.c
+++ b/opl/opl_sdl.c
@@ -172,9 +172,10 @@
// 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 @@
// 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;
}
--- a/pcsound/pcsound_sdl.c
+++ b/pcsound/pcsound_sdl.c
@@ -53,7 +53,7 @@
// 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 @@
current_freq = 0;
current_remaining = 0;
- Mix_SetPostMix(PCSound_Mix_Callback, NULL);
+ Mix_RegisterEffect(MIX_CHANNEL_POST, PCSound_Mix_Callback, NULL, NULL);
return 1;
}