From 0d6d61e31cf5f7e9515acea6760f81a44c91997e Mon Sep 17 00:00:00 2001 From: TimeServ Date: Wed, 10 May 2006 07:35:19 +0000 Subject: [PATCH] fix up some q2 sound effects and handle sound delays, misc cleanup git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2270 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/cl_parse.c | 6 +++--- engine/client/cl_tent.c | 2 +- engine/client/snd_alsa.c | 5 ++--- engine/client/snd_dma.c | 15 +++++++++++++-- engine/client/sound.h | 6 +++--- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index 94812c9b9..9af22a7b4 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -3108,7 +3108,7 @@ void CLQ2_ParseMuzzleFlash (void) snprintf(soundname, sizeof(soundname), "weapons/machgf%ib.wav", (rand() % 5) + 1); Q2S_StartSound (NULL, i, CHAN_WEAPON, S_PrecacheSound(soundname), volume, ATTN_NORM, 0); snprintf(soundname, sizeof(soundname), "weapons/machgf%ib.wav", (rand() % 5) + 1); - Q2S_StartSound (NULL, i, CHAN_WEAPON, S_PrecacheSound(soundname), volume, ATTN_NORM, 0.05); + Q2S_StartSound (NULL, i, CHAN_AUTO, S_PrecacheSound(soundname), volume, ATTN_NORM, 0.05); break; case Q2MZ_CHAINGUN3: dl->radius = 250 + (rand()&31); @@ -3117,9 +3117,9 @@ void CLQ2_ParseMuzzleFlash (void) snprintf(soundname, sizeof(soundname), "weapons/machgf%ib.wav", (rand() % 5) + 1); Q2S_StartSound (NULL, i, CHAN_WEAPON, S_PrecacheSound(soundname), volume, ATTN_NORM, 0); snprintf(soundname, sizeof(soundname), "weapons/machgf%ib.wav", (rand() % 5) + 1); - Q2S_StartSound (NULL, i, CHAN_WEAPON, S_PrecacheSound(soundname), volume, ATTN_NORM, 0.033); + Q2S_StartSound (NULL, i, CHAN_AUTO, S_PrecacheSound(soundname), volume, ATTN_NORM, 0.033); snprintf(soundname, sizeof(soundname), "weapons/machgf%ib.wav", (rand() % 5) + 1); - Q2S_StartSound (NULL, i, CHAN_WEAPON, S_PrecacheSound(soundname), volume, ATTN_NORM, 0.066); + Q2S_StartSound (NULL, i, CHAN_AUTO, S_PrecacheSound(soundname), volume, ATTN_NORM, 0.066); break; case Q2MZ_RAILGUN: diff --git a/engine/client/cl_tent.c b/engine/client/cl_tent.c index 500de896e..eaf3a6843 100644 --- a/engine/client/cl_tent.c +++ b/engine/client/cl_tent.c @@ -1571,7 +1571,7 @@ static qbyte splash_color[] = {0x00, 0xe0, 0xb0, 0x50, 0xd0, 0xe0, 0xe8}; #define ATTN_STATIC 1 void Q2S_StartSound(vec3_t origin, int entnum, int entchannel, sfx_t *sfx, float fvol, float attenuation, float timeofs) { - S_StartSound(entnum, entchannel, sfx, origin, fvol, attenuation); + S_StartSoundDelayed(entnum, entchannel, sfx, origin, fvol, attenuation, timeofs); } void CLQ2_ParseTEnt (void) { diff --git a/engine/client/snd_alsa.c b/engine/client/snd_alsa.c index 49cc33867..1eb1a9a03 100755 --- a/engine/client/snd_alsa.c +++ b/engine/client/snd_alsa.c @@ -194,7 +194,6 @@ static int ALSA_InitCard (soundcardinfo_t *sc, int cardnum) { snd_pcm_t *pcm; snd_pcm_uframes_t buffer_size; - extern cvar_t snd_speakers; soundcardinfo_t *ec; //existing card char *pcmname; @@ -375,14 +374,14 @@ static int ALSA_InitCard (soundcardinfo_t *sc, int cardnum) err = psnd_pcm_hw_params_set_buffer_size_near(pcm, hw, &buffer_size); if (err < 0) { - Con_Printf ("ALSA: unable to set buffer size. %s\n", psnd_strerror (err)); + Con_Printf (S_ERROR "ALSA: unable to set buffer size. %s\n", psnd_strerror (err)); goto error; } } err = psnd_pcm_hw_params_get_buffer_size (hw, &buffer_size); if (0 > err) { - Con_Printf ("ALSA: unable to get buffer size. %s\n", + Con_Printf (S_ERROR "ALSA: unable to get buffer size. %s\n", psnd_strerror (err)); goto error; } diff --git a/engine/client/snd_dma.c b/engine/client/snd_dma.c index 7b3758997..aea4767da 100644 --- a/engine/client/snd_dma.c +++ b/engine/client/snd_dma.c @@ -205,8 +205,8 @@ static int SNDDMA_Init(soundcardinfo_t *sc, int *cardnum, int *drivernum) sc->sn.speed = 8000; // set requested speaker count - if (snd_speakers.value > 6) - sc->sn.numchannels = 6; + if (snd_speakers.value > MAXSOUNDCHANNELS) + sc->sn.numchannels = MAXSOUNDCHANNELS; else if (snd_speakers.value > 1) sc->sn.numchannels = (int)snd_speakers.value; else @@ -928,6 +928,17 @@ void S_StartSoundCard(soundcardinfo_t *sc, int entnum, int entchannel, sfx_t *sf } } +void S_StartSoundDelayed(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation, float timeofs) +{ + soundcardinfo_t *sc; + + if (!sfx || !*sfx->name) //no named sounds would need specific starting. + return; + + for (sc = sndcardinfo; sc; sc = sc->next) + S_StartSoundCard(sc, entnum, entchannel, sfx, origin, fvol, attenuation, -(int)(timeofs * sc->sn.speed)); +} + void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation) { soundcardinfo_t *sc; diff --git a/engine/client/sound.h b/engine/client/sound.h index 99aea9828..657112eeb 100644 --- a/engine/client/sound.h +++ b/engine/client/sound.h @@ -77,14 +77,13 @@ typedef struct unsigned char *buffer; } dma_t; -// !!! if this is changed, it much be changed in asm_i386.h too !!! typedef struct { sfx_t *sfx; // sfx number int vol[MAXSOUNDCHANNELS]; // 0-255 volume int delay[MAXSOUNDCHANNELS]; int end; // end time in global paintsamples - int pos; // sample position in sfx + int pos; // sample position in sfx, <0 means delay sound start int looping; // where to loop, -1 = no looping int entnum; // to allow overriding a specific sound int entchannel; //int audio_fd @@ -109,7 +108,8 @@ typedef struct soundcardinfo_s soundcardinfo_t; void S_Init (void); void S_Startup (void); void S_Shutdown (void); -void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation); +void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation); +void S_StartSoundDelayed(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation, float timeofs); void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation); void S_StopSound (int entnum, int entchannel); void S_StopAllSounds(qboolean clear);