From f3e79d752a76a9d6329759a83ec9800a5e4cc92b Mon Sep 17 00:00:00 2001 From: molivier Date: Fri, 2 Jul 2004 15:30:22 +0000 Subject: [PATCH] Modified the sound code so it can handle sounds outside of a "sound" subdirectory. Changed the video code so it uses the common sound code (nice side-effect: DP video soundtracks can now be Ogg Vorbis files). Removed "wavefile.[ch]" and updated the project files accordingly. Fixed log timestamps on Win32. Cleaned a bit of code and a few header files inclusions here and there. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4258 d7cf8633-e32d-0410-b094-e92efae38249 --- cd_shared.c | 4 +- cl_parse.c | 18 ++--- cl_video.c | 51 +------------ console.c | 4 +- darkplaces.dev | 182 +++++++++++++++++++++++----------------------- darkplaces.dsp | 8 -- dpvsimpledecode.c | 56 +++----------- dpvsimpledecode.h | 6 -- fs.c | 2 - makefile.inc | 1 - menu.c | 94 ++++++++++++------------ prvm_cmds.c | 8 +- snd_dma.c | 63 ++++++++-------- snd_mem.c | 4 +- snd_null.c | 8 +- sound.h | 10 +-- 16 files changed, 208 insertions(+), 311 deletions(-) diff --git a/cd_shared.c b/cd_shared.c index bce1c14b..4923ebbe 100644 --- a/cd_shared.c +++ b/cd_shared.c @@ -110,14 +110,14 @@ void CDAudio_Play (qbyte track, qboolean looping) CDAudio_Stop (); // Try playing a fake track (sound file) first - sfx = S_PrecacheSound (va ("cdtracks/track%02u.wav", track), false); + sfx = S_PrecacheSound (va ("cdtracks/track%02u.wav", track), false, true); if (sfx != NULL) { faketrack = S_StartSound (-1, 0, sfx, vec3_origin, cdvolume, 0); if (faketrack != -1) { if (looping) - S_LoopChannel (faketrack, true); + S_LoopChannel (faketrack, true); Con_DPrintf ("Fake CD track %u playing...\n", track); } } diff --git a/cl_parse.c b/cl_parse.c index b633acf0..23e64ec6 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -411,7 +411,7 @@ void CL_ParseServerInfo (void) for (i = 1;i < numsounds;i++) { CL_KeepaliveMessage(); - S_TouchSound(parse_sound_precache[i]); + S_TouchSound(parse_sound_precache[i], true); } S_PurgeUnused(); @@ -435,7 +435,7 @@ void CL_ParseServerInfo (void) for (i=1 ; i -#include -#include -#include +#include "quakedef.h" #include "dpvsimpledecode.h" -#include "wavefile.h" -#define EMBEDDEDHZREAD 1 - -#ifndef EMBEDDEDHZREAD -#include "hz_read.h" -#include "hz_read.c" -#else #define HZREADERROR_OK 0 #define HZREADERROR_EOF 1 #define HZREADERROR_MALLOCFAILED 2 @@ -214,7 +204,6 @@ void hz_bitstream_read_bytes(hz_bitstream_readblocks_t *blocks, void *outdata, u while (size--) *out++ = hz_bitstream_read_byte(blocks); } -#endif #define BLOCKSIZE 8 @@ -247,8 +236,8 @@ typedef struct dpvsimpledecodestream_s // current video frame data (needed because of delta compression) unsigned int *videopixels; - // wav file the sound is being read from - wavefile_t *wavefile; + // channel the sound file is being played on + int sndchan; } dpvsimpledecodestream_t; @@ -405,9 +394,15 @@ void *dpvsimpledecode_open(char *filename, char **errorstring) wavename = malloc(strlen(filename) + 10); if (wavename) { + sfx_t* sfx; + StripExtension(filename, wavename); strcat(wavename, ".wav"); - s->wavefile = waveopen(wavename, NULL); + sfx = S_PrecacheSound (wavename, false, false); + if (sfx != NULL) + s->sndchan = S_StartSound (-1, 0, sfx, vec3_origin, 1.0f, 0); + else + s->sndchan = -1; free(wavename); } // all is well... @@ -448,8 +443,8 @@ void dpvsimpledecode_close(void *stream) return; if (s->videopixels) free(s->videopixels); - if (s->wavefile) - waveclose(s->wavefile); + if (s->sndchan != -1) + S_StopChannel (s->sndchan); if (s->framedatablocks) hz_bitstream_read_blocks_free(s->framedatablocks); if (s->bitstream) @@ -525,16 +520,6 @@ unsigned int dpvsimpledecode_getheight(void *stream) return s->info_imageheight; } -// returns the sound sample rate of the stream -unsigned int dpvsimpledecode_getsoundrate(void *stream) -{ - dpvsimpledecodestream_t *s = stream; - if (s->wavefile) - return s->wavefile->info_rate; - else - return 0; -} - // returns the framerate of the stream double dpvsimpledecode_getframerate(void *stream) { @@ -678,20 +663,3 @@ int dpvsimpledecode_video(void *stream, void *imagedata, unsigned int Rmask, uns dpvsimpledecode_convertpixels(s, imagedata, imagebytesperrow); return s->error; } - -// (note: sound is 16bit stereo native-endian, left channel first) -int dpvsimpledecode_audio(void *stream, short *soundbuffer, int requestedlength) -{ - int samples; - dpvsimpledecodestream_t *s = stream; - s->error = DPVSIMPLEDECODEERROR_NONE; - if (requestedlength) - { - samples = 0; - if (s->wavefile && requestedlength) - samples = waveread16stereo(s->wavefile, soundbuffer, requestedlength); - if (samples < requestedlength) - memset(soundbuffer + samples * 2, 0, (requestedlength - samples) * sizeof(short[2])); - } - return s->error; -} diff --git a/dpvsimpledecode.h b/dpvsimpledecode.h index 36e61a41..2d1f99c9 100644 --- a/dpvsimpledecode.h +++ b/dpvsimpledecode.h @@ -34,16 +34,10 @@ unsigned int dpvsimpledecode_getwidth(void *stream); // returns the height of the image data unsigned int dpvsimpledecode_getheight(void *stream); -// returns the sound sample rate of the stream -unsigned int dpvsimpledecode_getsoundrate(void *stream); - // returns the framerate of the stream double dpvsimpledecode_getframerate(void *stream); // decodes a video frame to the supplied output pixels int dpvsimpledecode_video(void *stream, void *imagedata, unsigned int Rmask, unsigned int Gmask, unsigned int Bmask, unsigned int bytesperpixel, int imagebytesperrow); -// reads some sound -// (note: sound is 16bit stereo native-endian, left channel first) -int dpvsimpledecode_audio(void *stream, short *soundbuffer, int requestedlength); #endif diff --git a/fs.c b/fs.c index 4bf26d4d..9eb46843 100644 --- a/fs.c +++ b/fs.c @@ -25,8 +25,6 @@ #include "quakedef.h" -#include -#include #include #include diff --git a/makefile.inc b/makefile.inc index 9eb9e709..5d4a35ba 100644 --- a/makefile.inc +++ b/makefile.inc @@ -97,7 +97,6 @@ OBJ_COMMON= \ vid_shared.o \ view.o \ wad.o \ - wavefile.o \ winding.o \ world.o \ zone.o diff --git a/menu.c b/menu.c index b0b5b5cc..ed7724a4 100644 --- a/menu.c +++ b/menu.c @@ -317,7 +317,7 @@ void M_Demo_Key (int k, char ascii) break; case K_ENTER: - S_LocalSound ("misc/menu2.wav"); + S_LocalSound ("misc/menu2.wav", true); m_state = m_none; key_dest = key_game; Cbuf_AddText (va ("playdemo %s\n", NehahraDemos[demo_cursor].name)); @@ -325,7 +325,7 @@ void M_Demo_Key (int k, char ascii) case K_UPARROW: case K_LEFTARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); demo_cursor--; if (demo_cursor < 0) demo_cursor = NumberOfNehahraDemos-1; @@ -333,7 +333,7 @@ void M_Demo_Key (int k, char ascii) case K_DOWNARROW: case K_RIGHTARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); demo_cursor++; if (demo_cursor >= NumberOfNehahraDemos) demo_cursor = 0; @@ -417,13 +417,13 @@ void M_Main_Key (int key, char ascii) break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); if (++m_main_cursor >= MAIN_ITEMS) m_main_cursor = 0; break; case K_UPARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); if (--m_main_cursor < 0) m_main_cursor = MAIN_ITEMS - 1; break; @@ -616,13 +616,13 @@ void M_SinglePlayer_Key (int key, char ascii) break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); if (++m_singleplayer_cursor >= SINGLEPLAYER_ITEMS) m_singleplayer_cursor = 0; break; case K_UPARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); if (--m_singleplayer_cursor < 0) m_singleplayer_cursor = SINGLEPLAYER_ITEMS - 1; break; @@ -764,7 +764,7 @@ void M_Load_Key (int k, char ascii) break; case K_ENTER: - S_LocalSound ("misc/menu2.wav"); + S_LocalSound ("misc/menu2.wav", true); if (!loadable[load_cursor]) return; m_state = m_none; @@ -776,7 +776,7 @@ void M_Load_Key (int k, char ascii) case K_UPARROW: case K_LEFTARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); load_cursor--; if (load_cursor < 0) load_cursor = MAX_SAVEGAMES-1; @@ -784,7 +784,7 @@ void M_Load_Key (int k, char ascii) case K_DOWNARROW: case K_RIGHTARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); load_cursor++; if (load_cursor >= MAX_SAVEGAMES) load_cursor = 0; @@ -809,7 +809,7 @@ void M_Save_Key (int k, char ascii) case K_UPARROW: case K_LEFTARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); load_cursor--; if (load_cursor < 0) load_cursor = MAX_SAVEGAMES-1; @@ -817,7 +817,7 @@ void M_Save_Key (int k, char ascii) case K_DOWNARROW: case K_RIGHTARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); load_cursor++; if (load_cursor >= MAX_SAVEGAMES) load_cursor = 0; @@ -867,13 +867,13 @@ void M_MultiPlayer_Key (int key, char ascii) break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); if (++m_multiplayer_cursor >= MULTIPLAYER_ITEMS) m_multiplayer_cursor = 0; break; case K_UPARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); if (--m_multiplayer_cursor < 0) m_multiplayer_cursor = MULTIPLAYER_ITEMS - 1; break; @@ -1038,14 +1038,14 @@ void M_Setup_Key (int k, char ascii) break; case K_UPARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); setup_cursor--; if (setup_cursor < 0) setup_cursor = NUM_SETUP_CMDS-1; break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); setup_cursor++; if (setup_cursor >= NUM_SETUP_CMDS) setup_cursor = 0; @@ -1054,7 +1054,7 @@ void M_Setup_Key (int k, char ascii) case K_LEFTARROW: if (setup_cursor < 1) return; - S_LocalSound ("misc/menu3.wav"); + S_LocalSound ("misc/menu3.wav", true); if (setup_cursor == 1) setup_top = setup_top - 1; if (setup_cursor == 2) @@ -1071,7 +1071,7 @@ void M_Setup_Key (int k, char ascii) if (setup_cursor < 1) return; forward: - S_LocalSound ("misc/menu3.wav"); + S_LocalSound ("misc/menu3.wav", true); if (setup_cursor == 1) setup_top = setup_top + 1; if (setup_cursor == 2) @@ -1188,7 +1188,7 @@ extern cvar_t gl_texture_anisotropy; void M_Menu_Options_AdjustSliders (int dir) { int optnum; - S_LocalSound ("misc/menu3.wav"); + S_LocalSound ("misc/menu3.wav", true); optnum = 6; if (options_cursor == optnum++) @@ -1400,14 +1400,14 @@ void M_Options_Key (int k, char ascii) return; case K_UPARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); options_cursor--; if (options_cursor < 0) options_cursor = OPTIONS_ITEMS-1; break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); options_cursor++; if (options_cursor >= OPTIONS_ITEMS) options_cursor = 0; @@ -1463,7 +1463,7 @@ extern cvar_t r_lightningbeam_qmbtexture; void M_Menu_Options_Effects_AdjustSliders (int dir) { int optnum; - S_LocalSound ("misc/menu3.wav"); + S_LocalSound ("misc/menu3.wav", true); optnum = 0; if (options_effects_cursor == optnum++) Cvar_SetValueQuick (&r_modellights, bound(0, r_modellights.value + dir, 8)); @@ -1566,14 +1566,14 @@ void M_Options_Effects_Key (int k, char ascii) break; case K_UPARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); options_effects_cursor--; if (options_effects_cursor < 0) options_effects_cursor = OPTIONS_EFFECTS_ITEMS-1; break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); options_effects_cursor++; if (options_effects_cursor >= OPTIONS_EFFECTS_ITEMS) options_effects_cursor = 0; @@ -1612,7 +1612,7 @@ void M_Menu_Options_ColorControl_AdjustSliders (int dir) { int optnum; float f; - S_LocalSound ("misc/menu3.wav"); + S_LocalSound ("misc/menu3.wav", true); optnum = 1; if (options_colorcontrol_cursor == optnum++) @@ -1816,14 +1816,14 @@ void M_Options_ColorControl_Key (int k, char ascii) return; case K_UPARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); options_colorcontrol_cursor--; if (options_colorcontrol_cursor < 0) options_colorcontrol_cursor = OPTIONS_COLORCONTROL_ITEMS-1; break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); options_colorcontrol_cursor++; if (options_colorcontrol_cursor >= OPTIONS_COLORCONTROL_ITEMS) options_colorcontrol_cursor = 0; @@ -2162,7 +2162,7 @@ void M_Keys_Key (int k, char ascii) if (bind_grab) { // defining a key - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); if (k == K_ESCAPE) { bind_grab = false; @@ -2185,7 +2185,7 @@ void M_Keys_Key (int k, char ascii) case K_LEFTARROW: case K_UPARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); do { keys_cursor--; @@ -2197,7 +2197,7 @@ void M_Keys_Key (int k, char ascii) case K_DOWNARROW: case K_RIGHTARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); do { keys_cursor++; @@ -2209,7 +2209,7 @@ void M_Keys_Key (int k, char ascii) case K_ENTER: // go into bind mode M_FindKeysForCommand (bindnames[keys_cursor][0], keys); - S_LocalSound ("misc/menu2.wav"); + S_LocalSound ("misc/menu2.wav", true); if (keys[NUMKEYS - 1] != -1) M_UnbindCommand (bindnames[keys_cursor][0]); bind_grab = true; @@ -2217,7 +2217,7 @@ void M_Keys_Key (int k, char ascii) case K_BACKSPACE: // delete bindings case K_DEL: // delete bindings - S_LocalSound ("misc/menu2.wav"); + S_LocalSound ("misc/menu2.wav", true); M_UnbindCommand (bindnames[keys_cursor][0]); break; } @@ -2303,7 +2303,7 @@ void M_Video_Draw (void) void M_Menu_Video_AdjustSliders (int dir) { - S_LocalSound ("misc/menu3.wav"); + S_LocalSound ("misc/menu3.wav", true); switch (video_cursor) { @@ -2345,7 +2345,7 @@ void M_Video_Key (int key, char ascii) Cvar_SetValueQuick(&vid_height, current_vid_height); Cvar_SetValueQuick(&vid_bitsperpixel, current_vid_bitsperpixel); - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); M_Menu_Options_f (); break; @@ -2363,14 +2363,14 @@ void M_Video_Key (int key, char ascii) break; case K_UPARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); video_cursor--; if (video_cursor < 0) video_cursor = VIDEO_ITEMS-1; break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); video_cursor++; if (video_cursor >= VIDEO_ITEMS) video_cursor = 0; @@ -2668,14 +2668,14 @@ void M_LanConfig_Key (int key, char ascii) break; case K_UPARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); lanConfig_cursor--; if (lanConfig_cursor < 0) lanConfig_cursor = NUM_LANCONFIG_CMDS-1; break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); lanConfig_cursor++; if (lanConfig_cursor >= NUM_LANCONFIG_CMDS) lanConfig_cursor = 0; @@ -3400,14 +3400,14 @@ void M_GameOptions_Key (int key, char ascii) break; case K_UPARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); gameoptions_cursor--; if (gameoptions_cursor < 0) gameoptions_cursor = NUM_GAMEOPTIONS-1; break; case K_DOWNARROW: - S_LocalSound ("misc/menu1.wav"); + S_LocalSound ("misc/menu1.wav", true); gameoptions_cursor++; if (gameoptions_cursor >= NUM_GAMEOPTIONS) gameoptions_cursor = 0; @@ -3416,19 +3416,19 @@ void M_GameOptions_Key (int key, char ascii) case K_LEFTARROW: if (gameoptions_cursor == 0) break; - S_LocalSound ("misc/menu3.wav"); + S_LocalSound ("misc/menu3.wav", true); M_NetStart_Change (-1); break; case K_RIGHTARROW: if (gameoptions_cursor == 0) break; - S_LocalSound ("misc/menu3.wav"); + S_LocalSound ("misc/menu3.wav", true); M_NetStart_Change (1); break; case K_ENTER: - S_LocalSound ("misc/menu2.wav"); + S_LocalSound ("misc/menu2.wav", true); if (gameoptions_cursor == 0) { if (sv.active) @@ -3543,7 +3543,7 @@ void M_ServerList_Key(int k, char ascii) case K_UPARROW: case K_LEFTARROW: - S_LocalSound("misc/menu1.wav"); + S_LocalSound("misc/menu1.wav", true); slist_cursor--; if (slist_cursor < 0) slist_cursor = hostCacheCount - 1; @@ -3551,14 +3551,14 @@ void M_ServerList_Key(int k, char ascii) case K_DOWNARROW: case K_RIGHTARROW: - S_LocalSound("misc/menu1.wav"); + S_LocalSound("misc/menu1.wav", true); slist_cursor++; if (slist_cursor >= hostCacheCount) slist_cursor = 0; break; case K_ENTER: - S_LocalSound("misc/menu2.wav"); + S_LocalSound("misc/menu2.wav", true); Cbuf_AddText(va("connect \"%s\"\n", hostcache[slist_cursor].cname)); break; @@ -3740,7 +3740,7 @@ void M_Draw (void) if (m_entersound) { - S_LocalSound ("misc/menu2.wav"); + S_LocalSound ("misc/menu2.wav", true); m_entersound = false; } diff --git a/prvm_cmds.c b/prvm_cmds.c index f19deb65..ccca3b4c 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -629,14 +629,14 @@ void VM_localsound(void) s = PRVM_G_STRING(OFS_PARM0); - if(!S_GetCached(s)) + if(!S_GetCached(s, true)) { Con_Printf("VM_localsound: %s : %s not cached !\n", PRVM_NAME, s); PRVM_G_FLOAT(OFS_RETURN) = -4; return; } - S_LocalSound(s); + S_LocalSound(s, true); PRVM_G_FLOAT(OFS_RETURN) = 1; } @@ -1109,13 +1109,13 @@ void VM_precache_sound (void) PRVM_G_INT(OFS_RETURN) = PRVM_G_INT(OFS_PARM0); VM_CheckEmptyString (s); - if(S_GetCached(s)) + if(S_GetCached(s, true)) { Con_Printf("VM_precache_sound: %s already cached (%s)\n", s, PRVM_NAME); return; } - if(!S_PrecacheSound(s,true)) + if(!S_PrecacheSound(s,true, true)) Con_Printf("VM_prache_sound: Failed to load %s for %s\n", s, PRVM_NAME); } diff --git a/snd_dma.c b/snd_dma.c index 1c6957e3..01e48254 100644 --- a/snd_dma.c +++ b/snd_dma.c @@ -251,8 +251,8 @@ void S_Init(void) SND_InitScaletable (); - ambient_sfx[AMBIENT_WATER] = S_PrecacheSound ("ambience/water1.wav", false); - ambient_sfx[AMBIENT_SKY] = S_PrecacheSound ("ambience/wind2.wav", false); + ambient_sfx[AMBIENT_WATER] = S_PrecacheSound ("ambience/water1.wav", false, true); + ambient_sfx[AMBIENT_SKY] = S_PrecacheSound ("ambience/wind2.wav", false, true); total_channels = MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS; // no statics memset(channels, 0, MAX_CHANNELS * sizeof(channel_t)); @@ -271,21 +271,25 @@ S_GetCached ========= */ -sfx_t *S_GetCached (const char *name) +sfx_t *S_GetCached (const char *name, qboolean stdpath) { + char namebuffer [MAX_QPATH]; + size_t len; int i; if (!snd_initialized.integer) return NULL; if (!name) - Host_Error("S_IsCached: NULL\n"); + Host_Error("S_GetCached: NULL"); - if (strlen(name) >= MAX_QPATH) - Host_Error("Sound name too long: %s", name); + // Add the default sound directory to the path + len = snprintf (namebuffer, sizeof (namebuffer), stdpath ? "sound/%s" : "%s", name); + if (len >= sizeof (namebuffer)) + Host_Error ("S_GetCached: sound name too long (%s)", name); for(i = 0;i < num_sfx;i++) - if(!strcmp(known_sfx[i].name, name)) + if(!strcmp(known_sfx[i].name, namebuffer)) return &known_sfx[i]; return NULL; @@ -297,31 +301,22 @@ S_FindName ================== */ -sfx_t *S_FindName (char *name) +sfx_t *S_FindName (const char *name, qboolean stdpath) { - int i; sfx_t *sfx; - if (!snd_initialized.integer) - return NULL; - - if (!name) - Host_Error("S_FindName: NULL\n"); - - if (strlen(name) >= MAX_QPATH) - Host_Error("Sound name too long: %s", name); + sfx = S_GetCached (name, stdpath); -// see if already loaded - for (i = 0;i < num_sfx;i++) - if (!strcmp(known_sfx[i].name, name)) - return &known_sfx[i]; - - if (num_sfx == MAX_SFX) - Sys_Error("S_FindName: out of sfx_t"); + // If we haven't allocated a sfx_t struct for it yet + if (sfx == NULL) + { + if (num_sfx == MAX_SFX) + Sys_Error ("S_FindName: out of sfx_t"); - sfx = &known_sfx[num_sfx++]; - memset(sfx, 0, sizeof(*sfx)); - strlcpy (sfx->name, name, sizeof (sfx->name)); + sfx = &known_sfx[num_sfx++]; + memset (sfx, 0, sizeof(*sfx)); + snprintf (sfx->name, sizeof (sfx->name), stdpath ? "sound/%s" : "%s", name); + } return sfx; } @@ -332,11 +327,11 @@ S_TouchSound ================== */ -void S_TouchSound (char *name) +void S_TouchSound (const char *name, qboolean stdpath) { sfx_t *sfx; - sfx = S_FindName (name); + sfx = S_FindName (name, stdpath); // Set the "used" flag for this sound if (sfx != NULL) @@ -387,14 +382,14 @@ S_PrecacheSound ================== */ -sfx_t *S_PrecacheSound (char *name, int complain) +sfx_t *S_PrecacheSound (const char *name, qboolean complain, qboolean stdpath) { sfx_t *sfx; if (!snd_initialized.integer) return NULL; - sfx = S_FindName(name); + sfx = S_FindName (name, stdpath); if (!nosound.integer && snd_precache.integer) S_LoadSound(sfx, complain); @@ -1038,7 +1033,7 @@ static void S_Play_Common(float fvol, float attenuation) snprintf(name, sizeof(name), "%s.wav", Cmd_Argv(i)); else strlcpy(name, Cmd_Argv(i), sizeof(name)); - sfx = S_PrecacheSound(name, true); + sfx = S_PrecacheSound(name, true, true); // If we need to get the volume from the command line if (fvol == -1.0f) @@ -1096,7 +1091,7 @@ void S_SoundList(void) } -void S_LocalSound (char *sound) +void S_LocalSound (const char *sound, qboolean stdpath) { sfx_t *sfx; int ch_ind; @@ -1104,7 +1099,7 @@ void S_LocalSound (char *sound) if (!snd_initialized.integer || nosound.integer) return; - sfx = S_PrecacheSound (sound, true); + sfx = S_PrecacheSound (sound, true, stdpath); if (!sfx) { Con_Printf("S_LocalSound: can't precache %s\n", sound); diff --git a/snd_mem.c b/snd_mem.c index a10b2631..2cb01bee 100644 --- a/snd_mem.c +++ b/snd_mem.c @@ -212,7 +212,7 @@ size_t ResampleSfx (const qbyte *in_data, size_t in_length, const snd_format_t* S_LoadSound ============== */ -qboolean S_LoadSound (sfx_t *s, int complain) +qboolean S_LoadSound (sfx_t *s, qboolean complain) { char namebuffer[MAX_QPATH]; size_t len; @@ -228,7 +228,7 @@ qboolean S_LoadSound (sfx_t *s, int complain) return true; } - len = snprintf (namebuffer, sizeof (namebuffer), "sound/%s", s->name); + len = strlcpy (namebuffer, s->name, sizeof (namebuffer)); if (len >= sizeof (namebuffer)) return false; diff --git a/snd_null.c b/snd_null.c index 52abac6e..35592de9 100755 --- a/snd_null.c +++ b/snd_null.c @@ -44,7 +44,7 @@ void S_Shutdown (void) { } -void S_TouchSound (char *sample) +void S_TouchSound (const char *sample, qboolean stdpath) { } @@ -93,12 +93,12 @@ void S_SetChannelVolume (unsigned int ch_ind, float fvol) { } -sfx_t *S_GetCached(const char *name) +sfx_t *S_GetCached(const char *name, qboolean stdpath) { return NULL; } -sfx_t *S_PrecacheSound (char *sample, int complain) +sfx_t *S_PrecacheSound (const char *sample, qboolean complain, qboolean stdpath) { return NULL; } @@ -115,7 +115,7 @@ void S_ExtraUpdate (void) { } -void S_LocalSound (char *s) +void S_LocalSound (const char *s, qboolean stdpath) { } diff --git a/sound.h b/sound.h index 70a350b5..d9aaeb7a 100644 --- a/sound.h +++ b/sound.h @@ -116,9 +116,9 @@ void S_SetChannelVolume (unsigned int ch_ind, float fvol); void S_Update(vec3_t origin, vec3_t forward, vec3_t left, vec3_t up); void S_ExtraUpdate (void); -sfx_t *S_GetCached(const char *name); -sfx_t *S_PrecacheSound (char *sample, int complain); -void S_TouchSound (char *sample); +sfx_t *S_GetCached(const char *name, qboolean stdpath); +sfx_t *S_PrecacheSound (const char *sample, qboolean complain, qboolean stdpath); +void S_TouchSound (const char *sample, qboolean stdpath); void S_ClearUsed (void); void S_PurgeUnused (void); void S_PaintChannels(int endtime); @@ -179,8 +179,8 @@ extern cvar_t snd_streaming; extern int snd_blocked; -void S_LocalSound (char *s); -qboolean S_LoadSound (sfx_t *s, int complain); +void S_LocalSound (const char *s, qboolean stdpath); +qboolean S_LoadSound (sfx_t *s, qboolean complain); void S_UnloadSound(sfx_t *s); void SND_InitScaletable (void); -- 2.39.2