Browse Source

First work on rewriting the SFX sound system using FMOD:

- Isolated all the bits from the old sound system that are obsolete, and compile them out with USE_FMOD directive
- Moved FMOD_System_Update call to S_Update function in new snd_fmod.c where it belongs
- Mute FMOD when application is not in focus
- Added stubs with research on what needs to happen for relevant sound API functions
console
Nico de Poel 5 years ago
parent
commit
db31892192
  1. 16
      engine/Quake/bgmusic.c
  2. 14
      engine/Quake/snd_dma.c
  3. 123
      engine/Quake/snd_fmod.c
  4. 3
      engine/Quake/snd_mem.c
  5. 3
      engine/Quake/snd_mix.c
  6. 3
      engine/Quake/snd_sdl.c

16
engine/Quake/bgmusic.c

@ -39,9 +39,10 @@ static qboolean no_extmusic = false;
static float old_volume = -1.0f; static float old_volume = -1.0f;
extern FMOD_SYSTEM *fmod_system; extern FMOD_SYSTEM *fmod_system;
FMOD_CHANNELGROUP *bgm_channelGroup = NULL;
FMOD_CHANNEL *bgm_channel = NULL;
FMOD_SOUND *bgm_sound = NULL;
static FMOD_CHANNELGROUP *bgm_channelGroup = NULL;
static FMOD_CHANNEL *bgm_channel = NULL;
static FMOD_SOUND *bgm_sound = NULL;
static const char *extensions[] = static const char *extensions[] =
{ {
@ -312,14 +313,9 @@ void BGM_Update (void)
old_volume = bgmvolume.value; old_volume = bgmvolume.value;
} }
if (fmod_system)
if (fmod_system && bgm_channelGroup)
{ {
FMOD_System_Update(fmod_system); // TODO: move this to main FMOD sound handler (snd_fmod.c)
if (bgm_channelGroup)
{
FMOD_ChannelGroup_SetVolume(bgm_channelGroup, bgmvolume.value);
}
FMOD_ChannelGroup_SetVolume(bgm_channelGroup, bgmvolume.value);
} }
} }

14
engine/Quake/snd_dma.c

@ -28,6 +28,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "snd_codec.h" #include "snd_codec.h"
#include "bgmusic.h" #include "bgmusic.h"
#ifndef USE_FMOD
static void S_Play (void); static void S_Play (void);
static void S_PlayVol (void); static void S_PlayVol (void);
static void S_SoundList (void); static void S_SoundList (void);
@ -43,7 +45,6 @@ channel_t snd_channels[MAX_CHANNELS];
int total_channels; int total_channels;
static int snd_blocked = 0; static int snd_blocked = 0;
static qboolean snd_initialized = false;
static dma_t sn; static dma_t sn;
volatile dma_t *shm = NULL; volatile dma_t *shm = NULL;
@ -61,6 +62,7 @@ int paintedtime; // sample PAIRS
int s_rawend; int s_rawend;
portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES]; portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES];
#endif // USE_FMOD
#define MAX_SFX 1024 #define MAX_SFX 1024
static sfx_t *known_sfx = NULL; // hunk allocated [MAX_SFX] static sfx_t *known_sfx = NULL; // hunk allocated [MAX_SFX]
@ -69,6 +71,7 @@ static int num_sfx;
static sfx_t *ambient_sfx[NUM_AMBIENTS]; static sfx_t *ambient_sfx[NUM_AMBIENTS];
static qboolean sound_started = false; static qboolean sound_started = false;
static qboolean snd_initialized = false;
cvar_t bgmvolume = {"bgmvolume", "1", CVAR_ARCHIVE}; cvar_t bgmvolume = {"bgmvolume", "1", CVAR_ARCHIVE};
cvar_t sfxvolume = {"volume", "0.7", CVAR_ARCHIVE}; cvar_t sfxvolume = {"volume", "0.7", CVAR_ARCHIVE};
@ -95,6 +98,7 @@ static cvar_t snd_noextraupdate = {"snd_noextraupdate", "0", CVAR_NONE};
static cvar_t snd_show = {"snd_show", "0", CVAR_NONE}; static cvar_t snd_show = {"snd_show", "0", CVAR_NONE};
static cvar_t _snd_mixahead = {"_snd_mixahead", "0.1", CVAR_ARCHIVE}; static cvar_t _snd_mixahead = {"_snd_mixahead", "0.1", CVAR_ARCHIVE};
#ifndef USE_FMOD
static void S_SoundInfo_f (void) static void S_SoundInfo_f (void)
{ {
@ -153,6 +157,7 @@ void S_Startup (void)
} }
} }
#endif // USE_FMOD
/* /*
================ ================
@ -188,11 +193,13 @@ void S_Init (void)
Con_Printf("\nSound Initialization\n"); Con_Printf("\nSound Initialization\n");
#ifndef USE_FMOD
Cmd_AddCommand("play", S_Play); Cmd_AddCommand("play", S_Play);
Cmd_AddCommand("playvol", S_PlayVol); Cmd_AddCommand("playvol", S_PlayVol);
Cmd_AddCommand("stopsound", S_StopAllSoundsC); Cmd_AddCommand("stopsound", S_StopAllSoundsC);
Cmd_AddCommand("soundlist", S_SoundList); Cmd_AddCommand("soundlist", S_SoundList);
Cmd_AddCommand("soundinfo", S_SoundInfo_f); Cmd_AddCommand("soundinfo", S_SoundInfo_f);
#endif // USE_FMOD
i = COM_CheckParm("-sndspeed"); i = COM_CheckParm("-sndspeed");
if (i && i < com_argc-1) if (i && i < com_argc-1)
@ -212,10 +219,12 @@ void S_Init (void)
Con_Printf ("loading all sounds as 8bit\n"); Con_Printf ("loading all sounds as 8bit\n");
} }
#ifndef USE_FMOD
Cvar_SetCallback(&sfxvolume, SND_Callback_sfxvolume); Cvar_SetCallback(&sfxvolume, SND_Callback_sfxvolume);
Cvar_SetCallback(&snd_filterquality, &SND_Callback_snd_filterquality); Cvar_SetCallback(&snd_filterquality, &SND_Callback_snd_filterquality);
SND_InitScaletable (); SND_InitScaletable ();
#endif // USE_FMOD
known_sfx = (sfx_t *) Hunk_AllocName (MAX_SFX*sizeof(sfx_t), "sfx_t"); known_sfx = (sfx_t *) Hunk_AllocName (MAX_SFX*sizeof(sfx_t), "sfx_t");
num_sfx = 0; num_sfx = 0;
@ -238,6 +247,7 @@ void S_Init (void)
S_StopAllSounds (true); S_StopAllSounds (true);
} }
#ifndef USE_FMOD
// ======================================================================= // =======================================================================
// Shutdown sound engine // Shutdown sound engine
@ -1034,6 +1044,7 @@ static void S_SoundList (void)
Con_Printf ("%i sounds, %i bytes\n", num_sfx, total); //johnfitz -- added count Con_Printf ("%i sounds, %i bytes\n", num_sfx, total); //johnfitz -- added count
} }
#endif // USE_FMOD
void S_LocalSound (const char *name) void S_LocalSound (const char *name)
{ {
@ -1067,4 +1078,3 @@ void S_BeginPrecaching (void)
void S_EndPrecaching (void) void S_EndPrecaching (void)
{ {
} }

123
engine/Quake/snd_fmod.c

@ -6,4 +6,127 @@
FMOD_SYSTEM *fmod_system = NULL; FMOD_SYSTEM *fmod_system = NULL;
#if 1
//void S_Init(void)
//{
// // Register cvars (see snd_dma.c) and check parameters
// // Call S_Startup
// // Call S_StopAllSounds(true)
//
// // Note: could actually keep the original S_Init from snd_dma.c and have it call the above functions in here
//}
void S_Startup(void)
{
// Create FMOD System if it doesn't exist already
// Create SFX channel group
// Could use System::set3DRolloffCallback to set up a (attenuation / sound_nominal_clip_dist) distance multiplier (would need to use ChannelControl::setUserData to hold ref to attn value)
// Note: sound_nominal_clip_dist could be dynamic to allow a small sound 'bubble' for local multiplayer
// Set sound_started to true
Con_DPrintf("[FMOD] Startup\n");
}
void S_Shutdown(void)
{
// Destroy SFX channel group
// If we created FMOD System (and consequently own it), destroy it here
Con_DPrintf("[FMOD] Shutdown\n");
}
void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
{
// Find channel group for entity number (or create) => note entnum can also be some random hash value
// ChannelControl::setMode => set to 3D
// Pre-define channels for each entity (could be an array of ints, probably array of entchannel_t structs)
// For entchannel 0, dynamically select a free channel (or just play without doing anything, let FMOD handle it)
// If channel at index entchannel >0 is already playing: stop
// Special case entchannel -1 => just play locally on listener, no 3D
// System::playSound with paused = true
// ChannelControl::set3DAttributes
// Use ChannelControl::setDelay and ChannelControl::getDSPClock to add a delay to move sounds out of phase if necessary
// ChannelControl::setPaused = false
// Store channel handle at position entchannel
if (sfx)
Con_DPrintf("[FMOD] Start sound %s for entity %d channel %d\n", sfx->name, entnum, entchannel);
else
Con_DPrintf("[FMOD] Start sound NULL for entity %d channel %d\n", entnum, entchannel);
}
void S_StaticSound(sfx_t *sfx, vec3_t origin, float vol, float attenuation)
{
// Similar to above, but without the per-entity channel group song and dance
// Check if sound is looped (should be) and FMOD_Channel_SetMode to looped
// Set Channel::setLoopPoints if the sfxcache specifies something non-standard
if (sfx)
Con_DPrintf("[FMOD] Static sound: %s\n", sfx->name);
else
Con_DPrintf("[FMOD] Static sound: NULL\n");
}
void S_StopSound(int entnum, int entchannel)
{
Con_DPrintf("[FMOD] Stop sound for entity %d channel %d\n", entnum, entchannel);
}
void S_StopAllSounds(qboolean clear)
{
}
void S_ClearBuffer(void)
{
}
void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
{
// System::set3DListenerAttributes
FMOD_System_Update(fmod_system);
}
void S_ExtraUpdate(void)
{
FMOD_System_Update(fmod_system);
}
static void S_SetMasterMute(FMOD_BOOL mute)
{
FMOD_CHANNELGROUP *master;
if (!fmod_system)
return;
FMOD_System_GetMasterChannelGroup(fmod_system, &master);
FMOD_ChannelGroup_SetMute(master, mute);
}
void S_BlockSound(void)
{
S_SetMasterMute(1);
}
void S_UnblockSound(void)
{
S_SetMasterMute(0);
}
sfx_t *S_PrecacheSound(const char *sample)
{
// System::createSound with FMOD_3D (sfx_t will need a pointer to FMOD_Sound)
// Might need to set rate and width? FMOD can probably figure this out by itself based on the WAV file contents
Con_DPrintf("[FMOD] Precaching sound: %s\n", sample);
return NULL;
}
void S_TouchSound(const char *sample)
{
}
#endif
#endif // USE_FMOD #endif // USE_FMOD

3
engine/Quake/snd_mem.c

@ -22,6 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "quakedef.h" #include "quakedef.h"
#ifndef USE_FMOD
/* /*
================ ================
ResampleSfx ResampleSfx
@ -350,3 +352,4 @@ wavinfo_t GetWavinfo (const char *name, byte *wav, int wavlength)
return info; return info;
} }
#endif // USE_FMOD

3
engine/Quake/snd_mix.c

@ -23,6 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "quakedef.h" #include "quakedef.h"
#ifndef USE_FMOD
#define PAINTBUFFER_SIZE 2048 #define PAINTBUFFER_SIZE 2048
portable_samplepair_t paintbuffer[PAINTBUFFER_SIZE]; portable_samplepair_t paintbuffer[PAINTBUFFER_SIZE];
int snd_scaletable[32][256]; int snd_scaletable[32][256];
@ -525,3 +527,4 @@ static void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int count, in
ch->pos += count; ch->pos += count;
} }
#endif // USE_FMOD

3
engine/Quake/snd_sdl.c

@ -24,6 +24,8 @@
#include "quakedef.h" #include "quakedef.h"
#ifndef USE_FMOD
#if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG) #if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG)
#if defined(USE_SDL2) #if defined(USE_SDL2)
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
@ -210,3 +212,4 @@ void SNDDMA_UnblockSound (void)
SDL_PauseAudio(0); SDL_PauseAudio(0);
} }
#endif // USE_FMOD
Loading…
Cancel
Save