- more cleanup of sound code

removed the remaining parts of the old music system in EDuke32 and RedNukem frontends.
This commit is contained in:
Christoph Oelckers 2019-11-28 03:02:33 +01:00
parent d569cd76c1
commit a59917b35d
11 changed files with 4 additions and 412 deletions

View file

@ -97,5 +97,7 @@ extern MusPlayingInfo mus_playing;
extern float relative_volume, saved_relative_volume; extern float relative_volume, saved_relative_volume;
// Note for later when the OPL player is ported.
// DN3D and related games use "d3dtimbr.tmb"
#endif #endif

View file

@ -5556,7 +5556,6 @@ static void G_Cleanup(void)
void G_Shutdown(void) void G_Shutdown(void)
{ {
S_SoundShutdown(); S_SoundShutdown();
S_MusicShutdown();
CONTROL_Shutdown(); CONTROL_Shutdown();
engineUnInit(); engineUnInit();
G_Cleanup(); G_Cleanup();
@ -6174,7 +6173,6 @@ int GameInterface::app_main()
videoSetPalette(0, myplayer.palette, 0); videoSetPalette(0, myplayer.palette, 0);
S_SoundStartup(); S_SoundStartup();
S_MusicStartup();
} }
// check if the minifont will support lowercase letters (3136-3161) // check if the minifont will support lowercase letters (3136-3161)

View file

@ -1760,10 +1760,8 @@ static void Menu_EntryLinkActivate(MenuEntry_t *entry)
mus_device = musicdevice; mus_device = musicdevice;
S_SoundShutdown(); S_SoundShutdown();
S_MusicShutdown();
S_SoundStartup(); S_SoundStartup();
S_MusicStartup();
FX_StopAllSounds(); FX_StopAllSounds();
S_ClearSoundLocks(); S_ClearSoundLocks();

View file

@ -326,10 +326,8 @@ static int osdcmd_restartsound(osdcmdptr_t UNUSED(parm))
{ {
UNREFERENCED_CONST_PARAMETER(parm); UNREFERENCED_CONST_PARAMETER(parm);
S_SoundShutdown(); S_SoundShutdown();
S_MusicShutdown();
S_SoundStartup(); S_SoundStartup();
S_MusicStartup();
FX_StopAllSounds(); FX_StopAllSounds();
S_ClearSoundLocks(); S_ClearSoundLocks();
@ -340,36 +338,6 @@ static int osdcmd_restartsound(osdcmdptr_t UNUSED(parm))
return OSDCMD_OK; return OSDCMD_OK;
} }
static int osdcmd_music(osdcmdptr_t parm)
{
if (parm->numparms == 1)
{
int32_t sel = G_GetMusicIdx(parm->parms[0]);
if (sel == -1)
return OSDCMD_SHOWHELP;
if (sel == -2)
{
OSD_Printf("%s is not a valid episode/level number pair\n", parm->parms[0]);
return OSDCMD_OK;
}
if (!S_TryPlayLevelMusic(sel))
{
G_PrintCurrentMusic();
}
else
{
OSD_Printf("No music defined for %s\n", parm->parms[0]);
}
return OSDCMD_OK;
}
return OSDCMD_SHOWHELP;
}
int osdcmd_restartmap(osdcmdptr_t UNUSED(parm)) int osdcmd_restartmap(osdcmdptr_t UNUSED(parm))
{ {
UNREFERENCED_CONST_PARAMETER(parm); UNREFERENCED_CONST_PARAMETER(parm);
@ -1012,8 +980,6 @@ int32_t registerosdcommands(void)
OSD_RegisterFunction("god","god: toggles god mode", osdcmd_god); OSD_RegisterFunction("god","god: toggles god mode", osdcmd_god);
OSD_RegisterFunction("activatecheat","activatecheat <id>: activates a cheat code", osdcmd_activatecheat); OSD_RegisterFunction("activatecheat","activatecheat <id>: activates a cheat code", osdcmd_activatecheat);
OSD_RegisterFunction("music","music E<ep>L<lev>: change music", osdcmd_music);
OSD_RegisterFunction("noclip","noclip: toggles clipping mode", osdcmd_noclip); OSD_RegisterFunction("noclip","noclip: toggles clipping mode", osdcmd_noclip);

View file

@ -88,7 +88,6 @@ void S_SoundStartup(void)
cacheAllSounds(); cacheAllSounds();
snd_fxvolume.Callback(); snd_fxvolume.Callback();
S_MusicVolume(mus_volume);
snd_reversestereo.Callback(); snd_reversestereo.Callback();
FX_SetCallBack(S_Callback); FX_SetCallBack(S_Callback);
@ -97,9 +96,6 @@ void S_SoundStartup(void)
void S_SoundShutdown(void) void S_SoundShutdown(void)
{ {
if (MusicVoice >= 0)
S_MusicShutdown();
int status = FX_Shutdown(); int status = FX_Shutdown();
if (status != FX_Ok) if (status != FX_Ok)
{ {
@ -108,45 +104,6 @@ void S_SoundShutdown(void)
} }
} }
void S_MusicStartup(void)
{
initprintf("Initializing MIDI driver... ");
int status;
if ((status = MUSIC_Init(MusicDevice)) == MUSIC_Ok)
{
if (MusicDevice == ASS_AutoDetect)
MusicDevice = MIDI_GetDevice();
}
else if ((status = MUSIC_Init(ASS_AutoDetect)) == MUSIC_Ok)
{
MusicDevice = MIDI_GetDevice();
}
else
{
initprintf("S_MusicStartup(): failed initializing: %s\n", MUSIC_ErrorString(status));
return;
}
MUSIC_SetVolume(mus_volume);
auto fr = kopenFileReader("d3dtimbr.tmb", 0);
if (fr.isOpen())
{
auto tmb = fr.Read();
AL_RegisterTimbreBank(tmb.Data());
}
}
void S_MusicShutdown(void)
{
S_StopMusic();
int status = MUSIC_Shutdown();
if (status != MUSIC_Ok)
initprintf("S_MusicShutdown(): %s\n", MUSIC_ErrorString(status));
}
void S_PauseSounds(bool paused) void S_PauseSounds(bool paused)
{ {
if (SoundPaused == paused) if (SoundPaused == paused)
@ -162,17 +119,9 @@ void S_PauseSounds(bool paused)
} }
} }
void S_MusicVolume(int32_t volume)
{
if (MusicIsWaveform && MusicVoice >= 0)
FX_SetPan(MusicVoice, volume, volume, volume);
MUSIC_SetVolume(volume);
}
void S_RestartMusic(void) void S_RestartMusic(void)
{ {
// Fixme: This should be completely decided by the backend, not here.
if (ud.recstat != 2 && g_player[myconnectindex].ps->gm&MODE_GAME) if (ud.recstat != 2 && g_player[myconnectindex].ps->gm&MODE_GAME)
{ {
S_PlayLevelMusicOrNothing(g_musicIndex); S_PlayLevelMusicOrNothing(g_musicIndex);
@ -196,125 +145,7 @@ void S_MenuSound(void)
S_PlaySound(s); S_PlaySound(s);
} }
#if 0 // In case you desperately want the old system back... ;)
static int S_PlayMusic(const char *, const char *fn, int loop)
{
if (!MusicEnabled())
return 0;
if (fn == NULL)
return 1;
auto fp = S_OpenAudio(fn, 0, 1);
if (!fp.isOpen())
{
OSD_Printf(OSD_ERROR "S_PlayMusic(): error: can't open \"%s\" for playback!\n",fn);
return 2;
}
int32_t MusicLen = fp.GetLength();
if (EDUKE32_PREDICT_FALSE(MusicLen < 4))
{
OSD_Printf(OSD_ERROR "S_PlayMusic(): error: empty music file \"%s\"\n", fn);
return 3;
}
char * MyMusicPtr = (char *)Xaligned_alloc(16, MusicLen);
int MyMusicSize = fp.Read(MyMusicPtr, MusicLen);
if (EDUKE32_PREDICT_FALSE(MyMusicSize != MusicLen))
{
OSD_Printf(OSD_ERROR "S_PlayMusic(): error: read %d bytes from \"%s\", expected %d\n",
MyMusicSize, fn, MusicLen);
ALIGNED_FREE_AND_NULL(MyMusicPtr);
return 4;
}
if (!Bmemcmp(MyMusicPtr, "MThd", 4))
{
int32_t retval = MUSIC_PlaySong(MyMusicPtr, MyMusicSize, MUSIC_LoopSong, fn);
if (retval != MUSIC_Ok)
{
ALIGNED_FREE_AND_NULL(MyMusicPtr);
return 5;
}
if (MusicIsWaveform && MusicVoice >= 0)
{
FX_StopSound(MusicVoice);
MusicVoice = -1;
}
MusicIsWaveform = 0;
ALIGNED_FREE_AND_NULL(MusicPtr);
MusicPtr = MyMusicPtr;
g_musicSize = MyMusicSize;
}
else
{
int MyMusicVoice = FX_Play(MyMusicPtr, MusicLen, 0, 0, 0, mus_volume, mus_volume, mus_volume,
FX_MUSIC_PRIORITY, 1.f, MUSIC_ID);
if (MyMusicVoice <= FX_Ok)
{
ALIGNED_FREE_AND_NULL(MyMusicPtr);
return 5;
}
if (MusicIsWaveform && MusicVoice >= 0)
FX_StopSound(MusicVoice);
MUSIC_StopSong();
MusicVoice = MyMusicVoice;
MusicIsWaveform = 1;
ALIGNED_FREE_AND_NULL(MusicPtr);
MusicPtr = MyMusicPtr;
g_musicSize = MyMusicSize;
}
return 0;
}
void S_StopMusic(void)
{
MusicPaused = 0;
if (MusicIsWaveform && MusicVoice >= 0)
{
FX_StopSound(MusicVoice);
MusicVoice = -1;
MusicIsWaveform = 0;
}
MUSIC_StopSong();
ALIGNED_FREE_AND_NULL(MusicPtr);
g_musicSize = 0;
}
void S_PauseMusic(bool paused)
{
if (MusicPaused == paused || (MusicIsWaveform && MusicVoice < 0))
return;
MusicPaused = paused;
if (MusicIsWaveform)
{
FX_PauseVoice(MusicVoice, paused);
return;
}
if (paused)
MUSIC_Pause();
else
MUSIC_Continue();
}
#else
static int S_PlayMusic(const char *mapname, const char* fn, bool looping = true) static int S_PlayMusic(const char *mapname, const char* fn, bool looping = true)
{ {
return Mus_Play(mapname, fn, looping); return Mus_Play(mapname, fn, looping);
@ -331,8 +162,6 @@ void S_PauseMusic(bool paused)
} }
#endif
static void S_SetMusicIndex(unsigned int m) static void S_SetMusicIndex(unsigned int m)
{ {
g_musicIndex = m; g_musicIndex = m;

View file

@ -70,9 +70,6 @@ inline void S_ClearSoundLocks(void) {}
int32_t S_LoadSound(uint32_t num); int32_t S_LoadSound(uint32_t num);
void cacheAllSounds(void); void cacheAllSounds(void);
void S_MenuSound(void); void S_MenuSound(void);
void S_MusicShutdown(void);
void S_MusicStartup(void);
void S_MusicVolume(int32_t volume);
void S_RestartMusic(void); void S_RestartMusic(void);
void S_PauseMusic(bool paused); void S_PauseMusic(bool paused);
void S_PauseSounds(bool paused); void S_PauseSounds(bool paused);

View file

@ -7046,7 +7046,6 @@ static void G_Cleanup(void)
void G_Shutdown(void) void G_Shutdown(void)
{ {
S_SoundShutdown(); S_SoundShutdown();
S_MusicShutdown();
CONTROL_Shutdown(); CONTROL_Shutdown();
G_SetFog(0); G_SetFog(0);
engineUnInit(); engineUnInit();
@ -7708,7 +7707,6 @@ int GameInterface::app_main()
} }
videoSetPalette(0, g_player[myconnectindex].ps->palette, 0); videoSetPalette(0, g_player[myconnectindex].ps->palette, 0);
S_MusicStartup();
S_SoundStartup(); S_SoundStartup();
} }

View file

@ -3434,9 +3434,7 @@ static void Menu_EntryLinkActivate(MenuEntry_t *entry)
snd_numvoices = soundvoices; snd_numvoices = soundvoices;
S_SoundShutdown(); S_SoundShutdown();
S_MusicShutdown();
S_MusicStartup();
S_SoundStartup(); S_SoundStartup();
FX_StopAllSounds(); FX_StopAllSounds();
@ -3623,8 +3621,6 @@ static int32_t Menu_EntryRangeInt32Modify(MenuEntry_t *entry, int32_t newValue)
G_SetStatusBarScale(newValue); G_SetStatusBarScale(newValue);
else if (entry == &ME_SOUND_VOLUME_FX) else if (entry == &ME_SOUND_VOLUME_FX)
FX_SetVolume(newValue); FX_SetVolume(newValue);
else if (entry == &ME_SOUND_VOLUME_MUSIC)
S_MusicVolume(newValue);
else if (entry == &ME_JOYSTICKAXIS_SCALE) else if (entry == &ME_JOYSTICKAXIS_SCALE)
CONTROL_SetAnalogAxisScale(M_JOYSTICKAXES.currentEntry, newValue, controldevice_joystick); CONTROL_SetAnalogAxisScale(M_JOYSTICKAXES.currentEntry, newValue, controldevice_joystick);
else if (entry == &ME_JOYSTICKAXIS_DEAD) else if (entry == &ME_JOYSTICKAXIS_DEAD)

View file

@ -323,9 +323,7 @@ static int osdcmd_restartsound(osdcmdptr_t UNUSED(parm))
{ {
UNREFERENCED_CONST_PARAMETER(parm); UNREFERENCED_CONST_PARAMETER(parm);
S_SoundShutdown(); S_SoundShutdown();
S_MusicShutdown();
S_MusicStartup();
S_SoundStartup(); S_SoundStartup();
FX_StopAllSounds(); FX_StopAllSounds();
@ -337,36 +335,6 @@ static int osdcmd_restartsound(osdcmdptr_t UNUSED(parm))
return OSDCMD_OK; return OSDCMD_OK;
} }
static int osdcmd_music(osdcmdptr_t parm)
{
if (parm->numparms == 1)
{
int32_t sel = G_GetMusicIdx(parm->parms[0]);
if (sel == -1)
return OSDCMD_SHOWHELP;
if (sel == -2)
{
OSD_Printf("%s is not a valid episode/level number pair\n", parm->parms[0]);
return OSDCMD_OK;
}
if (!S_TryPlayLevelMusic(sel))
{
G_PrintCurrentMusic();
}
else
{
OSD_Printf("No music defined for %s\n", parm->parms[0]);
}
return OSDCMD_OK;
}
return OSDCMD_SHOWHELP;
}
int osdcmd_restartmap(osdcmdptr_t UNUSED(parm)) int osdcmd_restartmap(osdcmdptr_t UNUSED(parm))
{ {
UNREFERENCED_CONST_PARAMETER(parm); UNREFERENCED_CONST_PARAMETER(parm);
@ -864,8 +832,6 @@ int32_t registerosdcommands(void)
OSD_RegisterFunction("listplayers","listplayers: lists currently connected multiplayer clients", osdcmd_listplayers); OSD_RegisterFunction("listplayers","listplayers: lists currently connected multiplayer clients", osdcmd_listplayers);
#endif #endif
OSD_RegisterFunction("music","music E<ep>L<lev>: change music", osdcmd_music);
OSD_RegisterFunction("noclip","noclip: toggles clipping mode", osdcmd_noclip); OSD_RegisterFunction("noclip","noclip: toggles clipping mode", osdcmd_noclip);
#if !defined NETCODE_DISABLE #if !defined NETCODE_DISABLE

View file

@ -77,7 +77,6 @@ void S_SoundStartup(void)
S_PrecacheSounds(); S_PrecacheSounds();
snd_fxvolume.Callback(); snd_fxvolume.Callback();
S_MusicVolume(mus_volume);
snd_reversestereo.Callback(); snd_reversestereo.Callback();
FX_SetCallBack(S_Callback); FX_SetCallBack(S_Callback);
@ -86,9 +85,6 @@ void S_SoundStartup(void)
void S_SoundShutdown(void) void S_SoundShutdown(void)
{ {
if (MusicVoice >= 0)
S_MusicShutdown();
if (FX_Shutdown() != FX_Ok) if (FX_Shutdown() != FX_Ok)
{ {
Bsprintf(tempbuf, "S_SoundShutdown(): error: %s", FX_ErrorString(FX_Error)); Bsprintf(tempbuf, "S_SoundShutdown(): error: %s", FX_ErrorString(FX_Error));
@ -96,26 +92,7 @@ void S_SoundShutdown(void)
} }
} }
void S_MusicStartup(void)
{
initprintf("Initializing music...\n");
if (MUSIC_Init(MusicDevice) == MUSIC_Ok)
{
MUSIC_SetVolume(mus_volume);
return;
}
initprintf("S_MusicStartup(): failed initializing\n");
}
void S_MusicShutdown(void)
{
S_StopMusic();
if (MUSIC_Shutdown() != MUSIC_Ok)
initprintf("%s\n", MUSIC_ErrorString(MUSIC_ErrorCode));
}
void S_PauseSounds(bool paused) void S_PauseSounds(bool paused)
{ {
if (SoundPaused == paused) if (SoundPaused == paused)
@ -131,18 +108,9 @@ void S_PauseSounds(bool paused)
} }
} }
void S_MusicVolume(int32_t volume)
{
if (MusicIsWaveform && MusicVoice >= 0)
FX_SetPan(MusicVoice, volume, volume, volume);
MUSIC_SetVolume(volume);
}
void S_RestartMusic(void) void S_RestartMusic(void)
{ {
// Fixme: This should be completely decided by the backend, not here.
if (ud.recstat != 2 && g_player[myconnectindex].ps->gm&MODE_GAME) if (ud.recstat != 2 && g_player[myconnectindex].ps->gm&MODE_GAME)
{ {
S_PlayLevelMusicOrNothing(g_musicIndex); S_PlayLevelMusicOrNothing(g_musicIndex);
@ -166,128 +134,7 @@ void S_MenuSound(void)
S_PlaySound(s); S_PlaySound(s);
} }
#if 0 // In case you desperately want the old system back... ;)
static int S_PlayMusic(const char *, const char *fn, int loop)
{
if (!MusicEnabled())
return 0;
if (fn == NULL)
return 1;
auto fp = S_OpenAudio(fn, 0, 1);
if (!fp.isOpen())
{
OSD_Printf(OSD_ERROR "S_PlayMusic(): error: can't open \"%s\" for playback!\n",fn);
return 2;
}
int32_t MusicLen = fp.GetLength();
if (EDUKE32_PREDICT_FALSE(MusicLen < 4))
{
OSD_Printf(OSD_ERROR "S_PlayMusic(): error: empty music file \"%s\"\n", fn);
return 3;
}
char * MyMusicPtr = (char *)Xaligned_alloc(16, MusicLen);
int MyMusicSize = fp.Read(MyMusicPtr, MusicLen);
if (EDUKE32_PREDICT_FALSE(MyMusicSize != MusicLen))
{
OSD_Printf(OSD_ERROR "S_PlayMusic(): error: read %d bytes from \"%s\", expected %d\n",
MyMusicSize, fn, MusicLen);
ALIGNED_FREE_AND_NULL(MyMusicPtr);
return 4;
}
if (!Bmemcmp(MyMusicPtr, "MThd", 4))
{
int32_t retval = MUSIC_PlaySong(MyMusicPtr, MyMusicSize, loop);
if (retval != MUSIC_Ok)
{
ALIGNED_FREE_AND_NULL(MyMusicPtr);
return 5;
}
if (MusicIsWaveform && MusicVoice >= 0)
{
FX_StopSound(MusicVoice);
MusicVoice = -1;
}
MusicIsWaveform = 0;
ALIGNED_FREE_AND_NULL(MusicPtr);
MusicPtr = MyMusicPtr;
g_musicSize = MyMusicSize;
}
else
{
int MyMusicVoice = FX_Play(MyMusicPtr, MusicLen, 0, 0, 0, mus_volume, mus_volume, mus_volume,
FX_MUSIC_PRIORITY, 1.f, MUSIC_ID);
if (MyMusicVoice <= FX_Ok)
{
ALIGNED_FREE_AND_NULL(MyMusicPtr);
return 5;
}
if (MusicIsWaveform && MusicVoice >= 0)
FX_StopSound(MusicVoice);
MUSIC_StopSong();
MusicVoice = MyMusicVoice;
MusicIsWaveform = 1;
ALIGNED_FREE_AND_NULL(MusicPtr);
MusicPtr = MyMusicPtr;
g_musicSize = MyMusicSize;
}
return 0;
}
void S_StopMusic(void)
{
MusicPaused = 0;
if (MusicIsWaveform && MusicVoice >= 0)
{
FX_StopSound(MusicVoice);
MusicVoice = -1;
MusicIsWaveform = 0;
}
MUSIC_StopSong();
ALIGNED_FREE_AND_NULL(MusicPtr);
g_musicSize = 0;
}
void S_PauseMusic(bool paused)
{
if (MusicPaused == paused || (MusicIsWaveform && MusicVoice < 0))
return;
MusicPaused = paused;
if (MusicIsWaveform)
{
FX_PauseVoice(MusicVoice, paused);
return;
}
if (paused)
MUSIC_Pause();
else
MUSIC_Continue();
}
#else
static int S_PlayMusic(const char *mapname, const char* fn, bool looping = true) static int S_PlayMusic(const char *mapname, const char* fn, bool looping = true)
{ {
return Mus_Play(mapname, fn, looping); return Mus_Play(mapname, fn, looping);
@ -304,8 +151,6 @@ void S_PauseMusic(bool paused)
Mus_SetPaused(paused); Mus_SetPaused(paused);
} }
#endif
static void S_SetMusicIndex(unsigned int m) static void S_SetMusicIndex(unsigned int m)
{ {

View file

@ -71,9 +71,6 @@ inline void S_ClearSoundLocks(void) {}
int32_t S_LoadSound(uint32_t num); int32_t S_LoadSound(uint32_t num);
void S_PrecacheSounds(void); void S_PrecacheSounds(void);
void S_MenuSound(void); void S_MenuSound(void);
void S_MusicShutdown(void);
void S_MusicStartup(void);
void S_MusicVolume(int32_t volume);
void S_RestartMusic(void); void S_RestartMusic(void);
void S_PauseMusic(bool paused); void S_PauseMusic(bool paused);
void S_PauseSounds(bool paused); void S_PauseSounds(bool paused);