summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am3
-rw-r--r--src/i_music.h76
-rw-r--r--src/i_sdlmusic.c62
-rw-r--r--src/s_dummy.c127
-rw-r--r--src/s_sound.c114
-rw-r--r--src/s_sound.h55
6 files changed, 192 insertions, 245 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 031369a7..e044d457 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -167,8 +167,7 @@ chocolate_doom_LDADD = ../textscreen/libtextscreen.a ../pcsound/libpcsound.a @LD
EXTRA_DIST = \
chocolate_doom_icon.c \
- chocolate-doom-screensaver.desktop \
- s_dummy.c
+ chocolate-doom-screensaver.desktop
.rc.o:
$(WINDRES) $^ -o $@
diff --git a/src/i_music.h b/src/i_music.h
deleted file mode 100644
index 70664c9a..00000000
--- a/src/i_music.h
+++ /dev/null
@@ -1,76 +0,0 @@
-// Emacs style mode select -*- C++ -*-
-//-----------------------------------------------------------------------------
-//
-// Copyright(C) 1993-1996 Id Software, Inc.
-// Copyright(C) 2005 Simon Howard
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-// 02111-1307, USA.
-//
-//
-// DESCRIPTION:
-// System interface, music.
-//
-//-----------------------------------------------------------------------------
-
-#ifndef __I_SOUND__
-#define __I_SOUND__
-
-#include "doomdef.h"
-
-#include "doomstat.h"
-#include "sounds.h"
-#include "s_sound.h"
-
-//
-// MUSIC I/O
-//
-
-void I_InitMusic(void);
-void I_ShutdownMusic(void);
-
-// Volume.
-
-void I_SetMusicVolume(int volume);
-
-// PAUSE game handling.
-
-void I_PauseSong(void *handle);
-void I_ResumeSong(void *handle);
-
-// Registers a song handle to song data.
-
-void *I_RegisterSong(void *data, int length);
-
-// Called by anything that wishes to start music.
-// plays a song, and when the song is done,
-// starts playing it again in an endless loop.
-// Horrible thing to do, considering.
-
-void I_PlaySong(void *handle, int looping);
-
-// Stops a song over 3 seconds.
-
-void I_StopSong(void *handle);
-
-// See above (register), then think backwards
-
-void I_UnRegisterSong(void *handle);
-
-boolean I_QrySongPlaying(void *handle);
-
-
-#endif
-
diff --git a/src/i_sdlmusic.c b/src/i_sdlmusic.c
index d2471578..4ece1555 100644
--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -52,7 +52,9 @@ static boolean sdl_was_initialised = false;
static boolean musicpaused = false;
static int current_music_volume;
-void I_ShutdownMusic(void)
+// Shutdown music
+
+static void I_SDL_ShutdownMusic(void)
{
if (music_initialised)
{
@@ -76,7 +78,9 @@ static boolean SDLIsInitialised(void)
return Mix_QuerySpec(&freq, &format, &channels) != 0;
}
-void I_InitMusic()
+// Initialise music subsystem
+
+static boolean I_SDL_InitMusic(void)
{
// When trying to run with music enabled on OSX, display
// a warning message.
@@ -97,14 +101,14 @@ void I_InitMusic()
if (SDL_Init(SDL_INIT_AUDIO) < 0)
{
fprintf(stderr, "Unable to set up sound.\n");
- return;
+ return false;
}
if (Mix_OpenAudio(snd_samplerate, AUDIO_S16SYS, 2, 1024) < 0)
{
fprintf(stderr, "Error initialising SDL_mixer: %s\n", Mix_GetError());
SDL_QuitSubSystem(SDL_INIT_AUDIO);
- return;
+ return false;
}
SDL_PauseAudio(0);
@@ -113,6 +117,8 @@ void I_InitMusic()
}
music_initialised = true;
+
+ return true;
}
//
@@ -136,8 +142,9 @@ static void UpdateMusicVolume(void)
Mix_VolumeMusic(vol);
}
-// MUSIC API - dummy. Some code from DOS version.
-void I_SetMusicVolume(int volume)
+// Set music volume (0 - 127)
+
+static void I_SDL_SetMusicVolume(int volume)
{
// Internal state variable.
current_music_volume = volume;
@@ -145,7 +152,9 @@ void I_SetMusicVolume(int volume)
UpdateMusicVolume();
}
-void I_PlaySong(void *handle, int looping)
+// Start playing a mid
+
+static void I_SDL_PlaySong(void *handle, int looping)
{
Mix_Music *music = (Mix_Music *) handle;
int loops;
@@ -172,7 +181,7 @@ void I_PlaySong(void *handle, int looping)
Mix_PlayMusic(music, loops);
}
-void I_PauseSong (void *handle)
+static void I_SDL_PauseSong(void)
{
if (!music_initialised)
{
@@ -184,7 +193,7 @@ void I_PauseSong (void *handle)
UpdateMusicVolume();
}
-void I_ResumeSong (void *handle)
+static void I_SDL_ResumeSong(void)
{
if (!music_initialised)
{
@@ -196,7 +205,7 @@ void I_ResumeSong (void *handle)
UpdateMusicVolume();
}
-void I_StopSong(void *handle)
+static void I_SDL_StopSong(void)
{
if (!music_initialised)
{
@@ -206,7 +215,7 @@ void I_StopSong(void *handle)
Mix_HaltMusic();
}
-void I_UnRegisterSong(void *handle)
+static void I_SDL_UnRegisterSong(void *handle)
{
Mix_Music *music = (Mix_Music *) handle;
@@ -256,7 +265,7 @@ static boolean ConvertMus(byte *musdata, int len, char *filename)
return result;
}
-void *I_RegisterSong(void *data, int len)
+static void *I_SDL_RegisterSong(void *data, int len)
{
char *filename;
Mix_Music *music;
@@ -303,7 +312,7 @@ void *I_RegisterSong(void *data, int len)
}
// Is the song playing?
-boolean I_QrySongPlaying(void *handle)
+static boolean I_SDL_MusicIsPlaying(void)
{
if (!music_initialised)
{
@@ -313,5 +322,32 @@ boolean I_QrySongPlaying(void *handle)
return Mix_PlayingMusic();
}
+static snddevice_t music_sdl_devices[] =
+{
+ SNDDEVICE_ADLIB,
+ SNDDEVICE_SB,
+ SNDDEVICE_PAS,
+ SNDDEVICE_GUS,
+ SNDDEVICE_WAVEBLASTER,
+ SNDDEVICE_SOUNDCANVAS,
+ SNDDEVICE_GENMIDI,
+ SNDDEVICE_AWE32,
+};
+
+music_module_t music_sdl_module =
+{
+ music_sdl_devices,
+ sizeof(music_sdl_devices) / sizeof(*music_sdl_devices),
+ I_SDL_InitMusic,
+ I_SDL_ShutdownMusic,
+ I_SDL_SetMusicVolume,
+ I_SDL_PauseSong,
+ I_SDL_ResumeSong,
+ I_SDL_RegisterSong,
+ I_SDL_UnRegisterSong,
+ I_SDL_PlaySong,
+ I_SDL_StopSong,
+ I_SDL_MusicIsPlaying,
+};
diff --git a/src/s_dummy.c b/src/s_dummy.c
deleted file mode 100644
index 441ff1e9..00000000
--- a/src/s_dummy.c
+++ /dev/null
@@ -1,127 +0,0 @@
-// Emacs style mode select -*- C++ -*-
-//-----------------------------------------------------------------------------
-//
-// Copyright(C) 1993-1996 Id Software, Inc.
-// Copyright(C) 2005 Simon Howard
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-// 02111-1307, USA.
-//
-// DESCRIPTION: Dummy sound interface for running with FEATURE_SOUND
-// disabled.
-//
-//-----------------------------------------------------------------------------
-
-#include "doomtype.h"
-#include "s_sound.h"
-#include "p_mobj.h"
-#include "sounds.h"
-
-int snd_musicdevice = SNDDEVICE_NONE;
-int snd_sfxdevice = SNDDEVICE_NONE;
-
-// Maximum volume of a sound effect.
-// Internal default is max out of 0-15.
-int sfxVolume = 8;
-
-// Maximum volume of music.
-int musicVolume = 8;
-
-// number of channels available
-
-int numChannels = 8;
-
-//
-// Initializes sound stuff, including volume
-// Sets channels, SFX and music volume,
-// allocates channel buffer, sets S_sfx lookup.
-//
-
-void S_Init(int sfxVolume, int musicVolume)
-{
-}
-
-void S_Shutdown(void)
-{
-}
-
-//
-// Per level startup code.
-// Kills playing sounds at start of level,
-// determines music if any, changes music.
-//
-
-void S_Start(void)
-{
-}
-
-void S_StartSound(mobj_t *origin, int sfx_id)
-{
-}
-
-void S_StopSound(mobj_t *origin)
-{
-}
-
-//
-// Stop and resume music, during game PAUSE.
-//
-
-void S_PauseSound(void)
-{
-}
-
-void S_ResumeSound(void)
-{
-}
-
-
-//
-// Updates music & sounds
-//
-
-void S_UpdateSounds(mobj_t *listener)
-{
-}
-
-void S_SetMusicVolume(int volume)
-{
-}
-
-void S_SetSfxVolume(int volume)
-{
-}
-
-//
-// Starts some music with the music id found in sounds.h.
-//
-
-void S_StartMusic(int m_id)
-{
-}
-
-void S_ChangeMusic(int musicnum, int looping)
-{
-}
-
-boolean S_MusicPlaying(void)
-{
- return false;
-}
-
-void S_StopMusic(void)
-{
-}
-
diff --git a/src/s_sound.c b/src/s_sound.c
index 52462258..8c311009 100644
--- a/src/s_sound.c
+++ b/src/s_sound.c
@@ -26,7 +26,6 @@
#include <stdio.h>
#include <stdlib.h>
-#include "i_music.h"
#include "i_system.h"
#include "doomfeatures.h"
@@ -91,9 +90,10 @@ typedef struct
} channel_t;
-// Low-level sound module we are using
+// Low-level sound and music modules we are using
static sound_module_t *sound_module;
+static music_module_t *music_module;
// The set of channels available
@@ -131,10 +131,11 @@ int numChannels = 8;
int snd_musicdevice = DEFAULT_MUSIC_DEVICE;
int snd_sfxdevice = SNDDEVICE_SB;
-// Sound effect modules
+// Sound modules
extern sound_module_t sound_sdl_module;
extern sound_module_t sound_pcsound_module;
+extern music_module_t music_sdl_module;
// Compiled-in sound modules:
@@ -144,6 +145,17 @@ static sound_module_t *sound_modules[] =
&sound_sdl_module,
&sound_pcsound_module,
#endif
+ NULL,
+};
+
+// Compiled-in music modules:
+
+static music_module_t *music_modules[] =
+{
+#ifdef FEATURE_SOUND
+ &music_sdl_module,
+#endif
+ NULL,
};
// Check if a sound device is in the given list of devices
@@ -173,7 +185,7 @@ static void InitSfxModule(void)
sound_module = NULL;
- for (i=0; i<sizeof(sound_modules) / sizeof(*sound_modules); ++i)
+ for (i=0; sound_modules[i] != NULL; ++i)
{
// Is the sfx device in the list of devices supported by
// this module?
@@ -197,9 +209,27 @@ static void InitSfxModule(void)
static void InitMusicModule(void)
{
- if (snd_musicdevice >= SNDDEVICE_ADLIB)
+ int i;
+
+ music_module = NULL;
+
+ for (i=0; music_modules[i] != NULL; ++i)
{
- I_InitMusic();
+ // Is the music device in the list of devices supported
+ // by this module?
+
+ if (SndDeviceInList(snd_musicdevice,
+ music_modules[i]->sound_devices,
+ music_modules[i]->num_sound_devices))
+ {
+ // Initialise the module
+
+ if (music_modules[i]->Init())
+ {
+ music_module = music_modules[i];
+ return;
+ }
+ }
}
}
@@ -259,7 +289,10 @@ void S_Shutdown(void)
sound_module->Shutdown();
}
- I_ShutdownMusic();
+ if (music_module != NULL)
+ {
+ music_module->Shutdown();
+ }
}
static void S_StopChannel(int cnum)
@@ -616,7 +649,10 @@ void S_PauseSound(void)
{
if (mus_playing && !mus_paused)
{
- I_PauseSong(mus_playing->handle);
+ if (music_module != NULL)
+ {
+ music_module->PauseMusic();
+ }
mus_paused = true;
}
}
@@ -625,7 +661,10 @@ void S_ResumeSound(void)
{
if (mus_playing && mus_paused)
{
- I_ResumeSong(mus_playing->handle);
+ if (music_module != NULL)
+ {
+ music_module->ResumeMusic();
+ }
mus_paused = false;
}
}
@@ -707,8 +746,10 @@ void S_SetMusicVolume(int volume)
volume);
}
- I_SetMusicVolume(127);
- I_SetMusicVolume(volume);
+ if (music_module != NULL)
+ {
+ music_module->SetMusicVolume(volume);
+ }
}
void S_SetSfxVolume(int volume)
@@ -732,8 +773,9 @@ void S_StartMusic(int m_id)
void S_ChangeMusic(int musicnum, int looping)
{
- musicinfo_t* music = NULL;
- char namebuf[9];
+ musicinfo_t *music = NULL;
+ char namebuf[9];
+ void *handle;
if (musicnum <= mus_None || musicnum >= NUMMUSIC)
{
@@ -759,36 +801,54 @@ void S_ChangeMusic(int musicnum, int looping)
music->lumpnum = W_GetNumForName(namebuf);
}
- // load & register it
- music->data = W_CacheLumpNum(music->lumpnum, PU_MUSIC);
- music->handle = I_RegisterSong(music->data, W_LumpLength(music->lumpnum));
+ if (music_module != NULL)
+ {
+ // Load & register it
+
+ music->data = W_CacheLumpNum(music->lumpnum, PU_MUSIC);
+ handle = music_module->RegisterSong(music->data,
+ W_LumpLength(music->lumpnum));
+ music->handle = handle;
- // play it
- I_PlaySong(music->handle, looping);
+ // Play it
+
+ music_module->PlaySong(handle, looping);
+ }
mus_playing = music;
}
boolean S_MusicPlaying(void)
{
- return I_QrySongPlaying(NULL);
+ if (music_module != NULL)
+ {
+ return music_module->MusicIsPlaying();
+ }
+ else
+ {
+ return false;
+ }
}
void S_StopMusic(void)
{
if (mus_playing)
{
- if (mus_paused)
+ if (music_module != NULL)
{
- I_ResumeSong(mus_playing->handle);
+ if (mus_paused)
+ {
+ music_module->ResumeMusic();
+ }
+
+ music_module->StopSong();
+ music_module->UnRegisterSong(mus_playing->handle);
+ Z_ChangeTag(mus_playing->data, PU_CACHE);
+
+ mus_playing->data = NULL;
}
- I_StopSong(mus_playing->handle);
- I_UnRegisterSong(mus_playing->handle);
- Z_ChangeTag(mus_playing->data, PU_CACHE);
-
- mus_playing->data = 0;
- mus_playing = 0;
+ mus_playing = NULL;
}
}
diff --git a/src/s_sound.h b/src/s_sound.h
index 8a5e2c6c..67071338 100644
--- a/src/s_sound.h
+++ b/src/s_sound.h
@@ -45,8 +45,12 @@ typedef enum
SNDDEVICE_AWE32 = 9,
} snddevice_t;
+// Interface for sound modules
+
typedef struct
{
+ // List of sound devices that this sound module is used for.
+
snddevice_t *sound_devices;
int num_sound_devices;
@@ -86,6 +90,57 @@ typedef struct
} sound_module_t;
+// Interface for music modules
+
+typedef struct
+{
+ // List of sound devices that this music module is used for.
+
+ snddevice_t *sound_devices;
+ int num_sound_devices;
+
+ // Initialise the music subsystem
+
+ boolean (*Init)(void);
+
+ // Shutdown the music subsystem
+
+ void (*Shutdown)(void);
+
+ // Set music volume - range 0-127
+
+ void (*SetMusicVolume)(int volume);
+
+ // Pause music
+
+ void (*PauseMusic)(void);
+
+ // Un-pause music
+
+ void (*ResumeMusic)(void);
+
+ // Register a song handle from data
+ // Returns a handle that can be used to play the song
+
+ void *(*RegisterSong)(void *data, int len);
+
+ // Un-register (free) song data
+
+ void (*UnRegisterSong)(void *handle);
+
+ // Play the song
+
+ void (*PlaySong)(void *handle, int looping);
+
+ // Stop playing the current song.
+
+ void (*StopSong)(void);
+
+ // Query if music is playing.
+
+ boolean (*MusicIsPlaying)(void);
+} music_module_t;
+
extern int snd_sfxdevice;
extern int snd_musicdevice;
extern int snd_samplerate;