summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am1
-rw-r--r--src/doom/sounds.h63
-rw-r--r--src/i_pcsound.c17
-rw-r--r--src/i_sdlmusic.c2
-rw-r--r--src/i_sdlsound.c48
-rw-r--r--src/i_sound.c358
-rw-r--r--src/i_sound.h225
-rw-r--r--src/s_sound.c258
-rw-r--r--src/s_sound.h114
9 files changed, 650 insertions, 436 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 81fbc16e..5f5f8f3e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -35,6 +35,7 @@ i_main.c \
i_joystick.c i_joystick.h \
i_scale.c i_scale.h \
i_swap.h \
+i_sound.c i_sound.h \
i_system.c i_system.h \
i_timer.c i_timer.h \
i_video.c i_video.h \
diff --git a/src/doom/sounds.h b/src/doom/sounds.h
index 325d1d63..3d190910 100644
--- a/src/doom/sounds.h
+++ b/src/doom/sounds.h
@@ -28,68 +28,7 @@
#ifndef __SOUNDS__
#define __SOUNDS__
-
-//
-// SoundFX struct.
-//
-typedef struct sfxinfo_struct sfxinfo_t;
-
-struct sfxinfo_struct
-{
- // up to 6-character name
- char* name;
-
- // Sfx singularity (only one at a time)
- int singularity;
-
- // Sfx priority
- int priority;
-
- // referenced sound if a link
- sfxinfo_t* link;
-
- // pitch if a link
- int pitch;
-
- // volume if a link
- int volume;
-
- // sound data
- void* data;
-
- // this is checked every second to see if sound
- // can be thrown out (if 0, then decrement, if -1,
- // then throw out, if > 0, then it is in use)
- int usefulness;
-
- // lump number of sfx
- int lumpnum;
-};
-
-
-
-
-//
-// MusicInfo struct.
-//
-typedef struct
-{
- // up to 6-character name
- char* name;
-
- // lump number of music
- int lumpnum;
-
- // music data
- void* data;
-
- // music handle once registered
- void *handle;
-
-} musicinfo_t;
-
-
-
+#include "i_sound.h"
// the complete set of sound effects
extern sfxinfo_t S_sfx[];
diff --git a/src/i_pcsound.c b/src/i_pcsound.c
index ad82180c..500deb99 100644
--- a/src/i_pcsound.c
+++ b/src/i_pcsound.c
@@ -28,8 +28,7 @@
#include "doomtype.h"
#include "deh_str.h"
-#include "s_sound.h"
-#include "sounds.h"
+#include "i_sound.h"
#include "w_wad.h"
#include "z_zone.h"
@@ -102,7 +101,7 @@ static void PCSCallbackFunc(int *duration, int *freq)
SDL_UnlockMutex(sound_lock);
}
-static boolean CachePCSLump(int sound_id)
+static boolean CachePCSLump(sfxinfo_t *sfxinfo)
{
int lumplen;
int headerlen;
@@ -117,8 +116,8 @@ static boolean CachePCSLump(int sound_id)
// Load from WAD
- current_sound_lump = W_CacheLumpNum(S_sfx[sound_id].lumpnum, PU_STATIC);
- lumplen = W_LumpLength(S_sfx[sound_id].lumpnum);
+ current_sound_lump = W_CacheLumpNum(sfxinfo->lumpnum, PU_STATIC);
+ lumplen = W_LumpLength(sfxinfo->lumpnum);
// Read header
@@ -138,12 +137,12 @@ static boolean CachePCSLump(int sound_id)
current_sound_remaining = headerlen;
current_sound_pos = current_sound_lump + 4;
- current_sound_lump_num = S_sfx[sound_id].lumpnum;
+ current_sound_lump_num = sfxinfo->lumpnum;
return true;
}
-static int I_PCS_StartSound(int id,
+static int I_PCS_StartSound(sfxinfo_t *sfxinfo,
int channel,
int vol,
int sep)
@@ -155,6 +154,7 @@ static int I_PCS_StartSound(int id,
return -1;
}
+/* TODO
// These PC speaker sounds are not played - this can be seen in the
// Heretic source code, where there are remnants of this left over
// from Doom.
@@ -164,13 +164,14 @@ static int I_PCS_StartSound(int id,
{
return -1;
}
+ */
if (SDL_LockMutex(sound_lock) < 0)
{
return -1;
}
- result = CachePCSLump(id);
+ result = CachePCSLump(sfxinfo);
if (result)
{
diff --git a/src/i_sdlmusic.c b/src/i_sdlmusic.c
index 2ac207d1..3acccde6 100644
--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -154,7 +154,7 @@ static void I_SDL_SetMusicVolume(int volume)
// Start playing a mid
-static void I_SDL_PlaySong(void *handle, int looping)
+static void I_SDL_PlaySong(void *handle, boolean looping)
{
Mix_Music *music = (Mix_Music *) handle;
int loops;
diff --git a/src/i_sdlsound.c b/src/i_sdlsound.c
index 5c6dd5f7..43f030d5 100644
--- a/src/i_sdlsound.c
+++ b/src/i_sdlsound.c
@@ -40,8 +40,8 @@
#include "deh_str.h"
#include "i_system.h"
-#include "s_sound.h"
#include "m_argv.h"
+#include "sounds.h"
#include "w_wad.h"
#include "z_zone.h"
@@ -53,7 +53,7 @@
static boolean sound_initialised = false;
static Mix_Chunk sound_chunks[NUMSFX];
-static int channels_playing[NUM_CHANNELS];
+static sfxinfo_t *channels_playing[NUM_CHANNELS];
static int mixer_freq;
static Uint16 mixer_format;
@@ -70,25 +70,27 @@ int use_libsamplerate = 0;
static void ReleaseSoundOnChannel(int channel)
{
int i;
- int id = channels_playing[channel];
+ sfxinfo_t *sfxinfo = channels_playing[channel];
+ int id;
- if (!id)
+ if (sfxinfo == NULL)
{
return;
}
- channels_playing[channel] = sfx_None;
+ channels_playing[channel] = NULL;
for (i=0; i<NUM_CHANNELS; ++i)
{
// Playing on this channel? if so, don't release.
- if (channels_playing[i] == id)
+ if (channels_playing[i] == sfxinfo)
return;
}
// Not used on any channel, and can be safely released
-
+ // TODO
+ id = sfxinfo - S_sfx;
Z_ChangeTag(sound_chunks[id].abuf, PU_CACHE);
}
@@ -351,18 +353,19 @@ static uint32_t ExpandSoundData_SDL(byte *data,
// Load and convert a sound effect
// Returns true if successful
-static boolean CacheSFX(int sound)
+static boolean CacheSFX(sfxinfo_t *sfxinfo)
{
int lumpnum;
unsigned int lumplen;
int samplerate;
int clipped;
unsigned int length;
+ int sound_id;
byte *data;
// need to load the sound
- lumpnum = S_sfx[sound].lumpnum;
+ lumpnum = sfxinfo->lumpnum;
data = W_CacheLumpNum(lumpnum, PU_STATIC);
lumplen = W_LumpLength(lumpnum);
@@ -393,19 +396,20 @@ static boolean CacheSFX(int sound)
// DWF 2008-02-10: sound_chunks[sound].alen and abuf are determined
// by ExpandSoundData.
- sound_chunks[sound].allocated = 1;
- sound_chunks[sound].volume = MIX_MAX_VOLUME;
+ sound_id = sfxinfo - S_sfx;
+ sound_chunks[sound_id].allocated = 1;
+ sound_chunks[sound_id].volume = MIX_MAX_VOLUME;
clipped = ExpandSoundData(data + 8,
samplerate,
length,
- &sound_chunks[sound]);
+ &sound_chunks[sound_id]);
if (clipped)
{
fprintf(stderr, "Sound %d: clipped %u samples (%0.2f %%)\n",
- sound, clipped,
- 400.0 * clipped / sound_chunks[sound].alen);
+ sound_id, clipped,
+ 400.0 * clipped / sound_chunks[sound_id].alen);
}
// don't need the original lump any more
@@ -440,7 +444,7 @@ static void I_PrecacheSounds(void)
if (S_sfx[i].lumpnum != -1)
{
- CacheSFX(i);
+ CacheSFX(&S_sfx[i]);
if (sound_chunks[i].abuf != NULL)
{
@@ -454,11 +458,15 @@ static void I_PrecacheSounds(void)
#endif
-static Mix_Chunk *GetSFXChunk(int sound_id)
+static Mix_Chunk *GetSFXChunk(sfxinfo_t *sfxinfo)
{
+ int sound_id;
+
+ sound_id = sfxinfo - S_sfx;
+
if (sound_chunks[sound_id].abuf == NULL)
{
- if (!CacheSFX(sound_id))
+ if (!CacheSFX(sfxinfo))
return NULL;
}
else
@@ -515,7 +523,7 @@ static void I_SDL_UpdateSoundParams(int handle, int vol, int sep)
// is set, but currently not used by mixing.
//
-static int I_SDL_StartSound(int id, int channel, int vol, int sep)
+static int I_SDL_StartSound(sfxinfo_t *sfxinfo, int channel, int vol, int sep)
{
Mix_Chunk *chunk;
@@ -531,7 +539,7 @@ static int I_SDL_StartSound(int id, int channel, int vol, int sep)
// Get the sound data
- chunk = GetSFXChunk(id);
+ chunk = GetSFXChunk(sfxinfo);
if (chunk == NULL)
{
@@ -542,7 +550,7 @@ static int I_SDL_StartSound(int id, int channel, int vol, int sep)
Mix_PlayChannelTimed(channel, chunk, 0, -1);
- channels_playing[channel] = id;
+ channels_playing[channel] = sfxinfo;
// set separation, etc.
diff --git a/src/i_sound.c b/src/i_sound.c
new file mode 100644
index 00000000..3f057c62
--- /dev/null
+++ b/src/i_sound.c
@@ -0,0 +1,358 @@
+// 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: none
+//
+//-----------------------------------------------------------------------------
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "config.h"
+#include "doomfeatures.h"
+#include "doomtype.h"
+
+#include "i_sound.h"
+#include "i_video.h"
+#include "m_argv.h"
+
+// Disable music on OSX by default; there are problems with SDL_mixer.
+
+#ifndef __APPLE__
+#define DEFAULT_MUSIC_DEVICE SNDDEVICE_SB
+#else
+#define DEFAULT_MUSIC_DEVICE SNDDEVICE_NONE
+#endif
+
+// Low-level sound and music modules we are using
+
+static sound_module_t *sound_module;
+static music_module_t *music_module;
+
+int snd_musicdevice = DEFAULT_MUSIC_DEVICE;
+int snd_sfxdevice = SNDDEVICE_SB;
+
+// 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:
+
+static sound_module_t *sound_modules[] =
+{
+#ifdef FEATURE_SOUND
+ &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
+
+static boolean SndDeviceInList(snddevice_t device, snddevice_t *list,
+ int len)
+{
+ int i;
+
+ for (i=0; i<len; ++i)
+ {
+ if (device == list[i])
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+// Find and initialise a sound_module_t appropriate for the setting
+// in snd_sfxdevice.
+
+static void InitSfxModule(void)
+{
+ int i;
+
+ sound_module = NULL;
+
+ for (i=0; sound_modules[i] != NULL; ++i)
+ {
+ // Is the sfx device in the list of devices supported by
+ // this module?
+
+ if (SndDeviceInList(snd_sfxdevice,
+ sound_modules[i]->sound_devices,
+ sound_modules[i]->num_sound_devices))
+ {
+ // Initialise the module
+
+ if (sound_modules[i]->Init())
+ {
+ sound_module = sound_modules[i];
+ return;
+ }
+ }
+ }
+}
+
+// Initialise music according to snd_musicdevice.
+
+static void InitMusicModule(void)
+{
+ int i;
+
+ music_module = NULL;
+
+ for (i=0; music_modules[i] != NULL; ++i)
+ {
+ // 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;
+ }
+ }
+ }
+}
+
+//
+// Initializes sound stuff, including volume
+// Sets channels, SFX and music volume,
+// allocates channel buffer, sets S_sfx lookup.
+//
+
+void I_InitSound(void)
+{
+ boolean nosound, nosfx, nomusic;
+
+ //!
+ // @vanilla
+ //
+ // Disable all sound output.
+ //
+
+ nosound = M_CheckParm("-nosound") > 0;
+
+ //!
+ // @vanilla
+ //
+ // Disable sound effects.
+ //
+
+ nosfx = M_CheckParm("-nosfx") > 0;
+
+ //!
+ // @vanilla
+ //
+ // Disable music.
+ //
+
+ nomusic = M_CheckParm("-nomusic") > 0;
+
+ // Initialise the sound and music subsystems.
+
+ if (!nosound && !screensaver_mode)
+ {
+ if (!nosfx)
+ {
+ InitSfxModule();
+ }
+
+ if (!nomusic)
+ {
+ InitMusicModule();
+ }
+ }
+}
+
+void I_ShutdownSound(void)
+{
+ if (sound_module != NULL)
+ {
+ sound_module->Shutdown();
+ }
+
+ if (music_module != NULL)
+ {
+ music_module->Shutdown();
+ }
+}
+
+int I_GetSfxLumpNum(sfxinfo_t *sfxinfo)
+{
+ if (sound_module != NULL)
+ {
+ return sound_module->GetSfxLumpNum(sfxinfo);
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+void I_UpdateSound(void)
+{
+ if (sound_module != NULL)
+ {
+ sound_module->Update();
+ }
+}
+
+void I_UpdateSoundParams(int channel, int vol, int sep)
+{
+ if (sound_module != NULL)
+ {
+ sound_module->UpdateSoundParams(channel, vol, sep);
+ }
+}
+
+int I_StartSound(sfxinfo_t *sfxinfo, int channel, int vol, int sep)
+{
+ if (sound_module != NULL)
+ {
+ return sound_module->StartSound(sfxinfo, channel, vol, sep);
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+void I_StopSound(int channel)
+{
+ if (sound_module != NULL)
+ {
+ sound_module->StopSound(channel);
+ }
+}
+
+boolean I_SoundIsPlaying(int channel)
+{
+ if (sound_module != NULL)
+ {
+ return sound_module->SoundIsPlaying(channel);
+ }
+ else
+ {
+ return false;
+ }
+}
+
+void I_InitMusic(void)
+{
+}
+
+void I_ShutdownMusic(void)
+{
+
+}
+
+void I_SetMusicVolume(int volume)
+{
+ if (music_module != NULL)
+ {
+ music_module->SetMusicVolume(volume);
+ }
+}
+
+void I_PauseSong(void)
+{
+ if (music_module != NULL)
+ {
+ music_module->PauseMusic();
+ }
+}
+
+void I_ResumeSong(void)
+{
+ if (music_module != NULL)
+ {
+ music_module->ResumeMusic();
+ }
+}
+
+void *I_RegisterSong(void *data, int len)
+{
+ if (music_module != NULL)
+ {
+ return music_module->RegisterSong(data, len);
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+void I_UnRegisterSong(void *handle)
+{
+ if (music_module != NULL)
+ {
+ music_module->UnRegisterSong(handle);
+ }
+}
+
+void I_PlaySong(void *handle, boolean looping)
+{
+ if (music_module != NULL)
+ {
+ music_module->PlaySong(handle, looping);
+ }
+}
+
+void I_StopSong(void)
+{
+ if (music_module != NULL)
+ {
+ music_module->StopSong();
+ }
+}
+
+boolean I_MusicIsPlaying(void)
+{
+ if (music_module != NULL)
+ {
+ return music_module->MusicIsPlaying();
+ }
+ else
+ {
+ return false;
+ }
+}
+
diff --git a/src/i_sound.h b/src/i_sound.h
new file mode 100644
index 00000000..3b525fc9
--- /dev/null
+++ b/src/i_sound.h
@@ -0,0 +1,225 @@
+// 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:
+// The not so system specific sound interface.
+//
+//-----------------------------------------------------------------------------
+
+
+#ifndef __I_SOUND__
+#define __I_SOUND__
+
+#include "doomtype.h"
+
+
+//
+// SoundFX struct.
+//
+typedef struct sfxinfo_struct sfxinfo_t;
+
+struct sfxinfo_struct
+{
+ // up to 6-character name
+ char *name;
+
+ // Sfx singularity (only one at a time)
+ int singularity;
+
+ // Sfx priority
+ int priority;
+
+ // referenced sound if a link
+ sfxinfo_t *link;
+
+ // pitch if a link
+ int pitch;
+
+ // volume if a link
+ int volume;
+
+ // sound data
+ void *data;
+
+ // this is checked every second to see if sound
+ // can be thrown out (if 0, then decrement, if -1,
+ // then throw out, if > 0, then it is in use)
+ int usefulness;
+
+ // lump number of sfx
+ int lumpnum;
+};
+
+//
+// MusicInfo struct.
+//
+typedef struct
+{
+ // up to 6-character name
+ char *name;
+
+ // lump number of music
+ int lumpnum;
+
+ // music data
+ void *data;
+
+ // music handle once registered
+ void *handle;
+
+} musicinfo_t;
+
+typedef enum
+{
+ SNDDEVICE_NONE = 0,
+ SNDDEVICE_PCSPEAKER = 1,
+ SNDDEVICE_ADLIB = 2,
+ SNDDEVICE_SB = 3,
+ SNDDEVICE_PAS = 4,
+ SNDDEVICE_GUS = 5,
+ SNDDEVICE_WAVEBLASTER = 6,
+ SNDDEVICE_SOUNDCANVAS = 7,
+ SNDDEVICE_GENMIDI = 8,
+ 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;
+
+ // Initialise sound module
+ // Returns true if successfully initialised
+
+ boolean (*Init)(void);
+
+ // Shutdown sound module
+
+ void (*Shutdown)(void);
+
+ // Returns the lump index of the given sound.
+
+ int (*GetSfxLumpNum)(sfxinfo_t *sfxinfo);
+
+ // Called periodically to update the subsystem.
+
+ void (*Update)(void);
+
+ // Update the sound settings on the given channel.
+
+ void (*UpdateSoundParams)(int channel, int vol, int sep);
+
+ // Start a sound on a given channel. Returns the channel id
+ // or -1 on failure.
+
+ int (*StartSound)(sfxinfo_t *sfxinfo, int channel, int vol, int sep);
+
+ // Stop the sound playing on the given channel.
+
+ void (*StopSound)(int channel);
+
+ // Query if a sound is playing on the given channel
+
+ boolean (*SoundIsPlaying)(int channel);
+
+} sound_module_t;
+
+void I_InitSound(void);
+void I_ShutdownSound(void);
+int I_GetSfxLumpNum(sfxinfo_t *sfxinfo);
+void I_UpdateSound(void);
+void I_UpdateSoundParams(int channel, int vol, int sep);
+int I_StartSound(sfxinfo_t *sfxinfo, int channel, int vol, int sep);
+void I_StopSound(int channel);
+boolean I_SoundIsPlaying(int channel);
+
+// 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, boolean looping);
+
+ // Stop playing the current song.
+
+ void (*StopSong)(void);
+
+ // Query if music is playing.
+
+ boolean (*MusicIsPlaying)(void);
+} music_module_t;
+
+void I_InitMusic(void);
+void I_ShutdownMusic(void);
+void I_SetMusicVolume(int volume);
+void I_PauseSong(void);
+void I_ResumeSong(void);
+void *I_RegisterSong(void *data, int len);
+void I_UnRegisterSong(void *handle);
+void I_PlaySong(void *handle, boolean looping);
+void I_StopSong(void);
+boolean I_MusicIsPlaying(void);
+
+extern int snd_sfxdevice;
+extern int snd_musicdevice;
+extern int snd_samplerate;
+
+#endif
+
diff --git a/src/s_sound.c b/src/s_sound.c
index 26bbb5fd..1dc575a3 100644
--- a/src/s_sound.c
+++ b/src/s_sound.c
@@ -26,6 +26,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include "i_sound.h"
#include "i_system.h"
#include "doomfeatures.h"
@@ -69,14 +70,6 @@
#define NORM_PRIORITY 64
#define NORM_SEP 128
-// Disable music on OSX by default; there are problems with SDL_mixer.
-
-#ifndef __APPLE__
-#define DEFAULT_MUSIC_DEVICE SNDDEVICE_SB
-#else
-#define DEFAULT_MUSIC_DEVICE SNDDEVICE_NONE
-#endif
-
typedef struct
{
// sound information (if null, channel avail.)
@@ -90,11 +83,6 @@ typedef struct
} channel_t;
-// 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
static channel_t *channels;
@@ -128,111 +116,6 @@ static musicinfo_t *mus_playing = NULL;
int numChannels = 8;
-int snd_musicdevice = DEFAULT_MUSIC_DEVICE;
-int snd_sfxdevice = SNDDEVICE_SB;
-
-// 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:
-
-static sound_module_t *sound_modules[] =
-{
-#ifdef FEATURE_SOUND
- &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
-
-static boolean SndDeviceInList(snddevice_t device, snddevice_t *list,
- int len)
-{
- int i;
-
- for (i=0; i<len; ++i)
- {
- if (device == list[i])
- {
- return true;
- }
- }
-
- return false;
-}
-
-// Find and initialise a sound_module_t appropriate for the setting
-// in snd_sfxdevice.
-
-static void InitSfxModule(void)
-{
- int i;
-
- sound_module = NULL;
-
- for (i=0; sound_modules[i] != NULL; ++i)
- {
- // Is the sfx device in the list of devices supported by
- // this module?
-
- if (SndDeviceInList(snd_sfxdevice,
- sound_modules[i]->sound_devices,
- sound_modules[i]->num_sound_devices))
- {
- // Initialise the module
-
- if (sound_modules[i]->Init())
- {
- sound_module = sound_modules[i];
- return;
- }
- }
- }
-}
-
-// Initialise music according to snd_musicdevice.
-
-static void InitMusicModule(void)
-{
- int i;
-
- music_module = NULL;
-
- for (i=0; music_modules[i] != NULL; ++i)
- {
- // 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;
- }
- }
- }
-}
-
//
// Initializes sound stuff, including volume
// Sets channels, SFX and music volume,
@@ -241,47 +124,10 @@ static void InitMusicModule(void)
void S_Init(int sfxVolume, int musicVolume)
{
- boolean nosound, nosfx, nomusic;
int i;
- //!
- // @vanilla
- //
- // Disable all sound output.
- //
-
- nosound = M_CheckParm("-nosound") > 0;
-
- //!
- // @vanilla
- //
- // Disable sound effects.
- //
-
- nosfx = M_CheckParm("-nosfx") > 0;
-
- //!
- // @vanilla
- //
- // Disable music.
- //
-
- nomusic = M_CheckParm("-nomusic") > 0;
-
- // Initialise the sound and music subsystems.
-
- if (!nosound && !screensaver_mode)
- {
- if (!nosfx)
- {
- InitSfxModule();
- }
-
- if (!nomusic)
- {
- InitMusicModule();
- }
- }
+ I_InitSound();
+ I_InitMusic();
S_SetSfxVolume(sfxVolume);
S_SetMusicVolume(musicVolume);
@@ -309,15 +155,8 @@ void S_Init(int sfxVolume, int musicVolume)
void S_Shutdown(void)
{
- if (sound_module != NULL)
- {
- sound_module->Shutdown();
- }
-
- if (music_module != NULL)
- {
- music_module->Shutdown();
- }
+ I_ShutdownSound();
+ I_ShutdownMusic();
}
static void S_StopChannel(int cnum)
@@ -331,12 +170,9 @@ static void S_StopChannel(int cnum)
{
// stop the sound playing
- if (sound_module != NULL)
+ if (I_SoundIsPlaying(c->handle))
{
- if (sound_module->SoundIsPlaying(c->handle))
- {
- sound_module->StopSound(c->handle);
- }
+ I_StopSound(c->handle);
}
// check to see if other channels are playing the sound
@@ -647,23 +483,12 @@ void S_StartSound(void *origin_p, int sfx_id)
sfx->usefulness = 1;
}
- if (sound_module != NULL)
+ if (sfx->lumpnum < 0)
{
- // Get lumpnum if necessary
-
- if (sfx->lumpnum < 0)
- {
- sfx->lumpnum = sound_module->GetSfxLumpNum(sfx);
- }
-
- // Assigns the handle to one of the channels in the
- // mix/output buffer.
-
- channels[cnum].handle = sound_module->StartSound(sfx_id,
- cnum,
- volume,
- sep);
+ sfx->lumpnum = I_GetSfxLumpNum(sfx);
}
+
+ channels[cnum].handle = I_StartSound(sfx, cnum, volume, sep);
}
//
@@ -674,10 +499,7 @@ void S_PauseSound(void)
{
if (mus_playing && !mus_paused)
{
- if (music_module != NULL)
- {
- music_module->PauseMusic();
- }
+ I_PauseSong();
mus_paused = true;
}
}
@@ -686,10 +508,7 @@ void S_ResumeSound(void)
{
if (mus_playing && mus_paused)
{
- if (music_module != NULL)
- {
- music_module->ResumeMusic();
- }
+ I_ResumeSong();
mus_paused = false;
}
}
@@ -714,7 +533,7 @@ void S_UpdateSounds(mobj_t *listener)
if (c->sfxinfo)
{
- if (sound_module != NULL && sound_module->SoundIsPlaying(c->handle))
+ if (I_SoundIsPlaying(c->handle))
{
// initialize parameters
volume = snd_SfxVolume;
@@ -749,7 +568,7 @@ void S_UpdateSounds(mobj_t *listener)
}
else
{
- sound_module->UpdateSoundParams(c->handle, volume, sep);
+ I_UpdateSoundParams(c->handle, volume, sep);
}
}
}
@@ -771,10 +590,7 @@ void S_SetMusicVolume(int volume)
volume);
}
- if (music_module != NULL)
- {
- music_module->SetMusicVolume(volume);
- }
+ I_SetMusicVolume(volume);
}
void S_SetSfxVolume(int volume)
@@ -826,53 +642,33 @@ void S_ChangeMusic(int musicnum, int looping)
music->lumpnum = W_GetNumForName(namebuf);
}
- if (music_module != NULL)
- {
- // Load & register it
-
- music->data = W_CacheLumpNum(music->lumpnum, PU_STATIC);
- handle = music_module->RegisterSong(music->data,
- W_LumpLength(music->lumpnum));
- music->handle = handle;
-
- // Play it
+ music->data = W_CacheLumpNum(music->lumpnum, PU_STATIC);
- music_module->PlaySong(handle, looping);
- }
+ handle = I_RegisterSong(music->data, W_LumpLength(music->lumpnum));
+ music->handle = handle;
+ I_PlaySong(handle, looping);
mus_playing = music;
}
boolean S_MusicPlaying(void)
{
- if (music_module != NULL)
- {
- return music_module->MusicIsPlaying();
- }
- else
- {
- return false;
- }
+ return I_MusicIsPlaying();
}
void S_StopMusic(void)
{
if (mus_playing)
{
- if (music_module != NULL)
+ if (mus_paused)
{
- if (mus_paused)
- {
- music_module->ResumeMusic();
- }
-
- music_module->StopSong();
- music_module->UnRegisterSong(mus_playing->handle);
- W_ReleaseLumpNum(mus_playing->lumpnum);
-
- mus_playing->data = NULL;
+ I_ResumeSong();
}
+ I_StopSong();
+ I_UnRegisterSong(mus_playing->handle);
+ W_ReleaseLumpNum(mus_playing->lumpnum);
+ mus_playing->data = NULL;
mus_playing = NULL;
}
}
diff --git a/src/s_sound.h b/src/s_sound.h
index 67071338..d2af9e88 100644
--- a/src/s_sound.h
+++ b/src/s_sound.h
@@ -31,120 +31,6 @@
#include "p_mobj.h"
#include "sounds.h"
-typedef enum
-{
- SNDDEVICE_NONE = 0,
- SNDDEVICE_PCSPEAKER = 1,
- SNDDEVICE_ADLIB = 2,
- SNDDEVICE_SB = 3,
- SNDDEVICE_PAS = 4,
- SNDDEVICE_GUS = 5,
- SNDDEVICE_WAVEBLASTER = 6,
- SNDDEVICE_SOUNDCANVAS = 7,
- SNDDEVICE_GENMIDI = 8,
- 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;
-
- // Initialise sound module
- // Returns true if successfully initialised
-
- boolean (*Init)(void);
-
- // Shutdown sound module
-
- void (*Shutdown)(void);
-
- // Returns the lump index of the given sound.
-
- int (*GetSfxLumpNum)(sfxinfo_t *sfxinfo);
-
- // Called periodically to update the subsystem.
-
- void (*Update)(void);
-
- // Update the sound settings on the given channel.
-
- void (*UpdateSoundParams)(int channel, int vol, int sep);
-
- // Start a sound on a given channel. Returns the channel id
- // or -1 on failure.
-
- int (*StartSound)(int id, int channel, int vol, int sep);
-
- // Stop the sound playing on the given channel.
-
- void (*StopSound)(int channel);
-
- // Query if a sound is playing on the given channel
-
- boolean (*SoundIsPlaying)(int channel);
-
-} 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;
-
//
// Initializes sound stuff, including volume
// Sets channels, SFX and music volume,