From 469fb50e57ea5455865ab1093fecb81d148f6c9b Mon Sep 17 00:00:00 2001 From: TimeServ Date: Mon, 8 May 2006 21:02:39 +0000 Subject: [PATCH] use better mixing for 8-bit sounds, some cleanup git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2254 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/menu.c | 6 -- engine/client/snd_dma.c | 8 +- engine/client/snd_mix.c | 170 +++++++++++---------------------------- engine/client/snd_mixa.s | 6 +- engine/client/sound.h | 5 -- engine/common/quakeasm.h | 1 - engine/sw/r_edge.c | 2 - engine/sw/r_main.c | 4 - engine/sw/sw_draw.c | 6 -- 9 files changed, 55 insertions(+), 153 deletions(-) diff --git a/engine/client/menu.c b/engine/client/menu.c index 101a23762..fe6404e4a 100644 --- a/engine/client/menu.c +++ b/engine/client/menu.c @@ -940,9 +940,7 @@ void M_Draw (int uimenu) #ifdef VM_UI UI_DrawMenu(); #endif - VID_UnlockBuffer (); S_ExtraUpdate (); - VID_LockBuffer (); } if (m_state != m_complex) @@ -965,9 +963,7 @@ void M_Draw (int uimenu) if (scr_con_current) { Draw_ConsoleBackground (vid.height); - VID_UnlockBuffer (); S_ExtraUpdate (); - VID_LockBuffer (); } else Draw_FadeScreen (); @@ -1015,9 +1011,7 @@ void M_Draw (int uimenu) #endif } - VID_UnlockBuffer (); S_ExtraUpdate (); - VID_LockBuffer (); } diff --git a/engine/client/snd_dma.c b/engine/client/snd_dma.c index 6a14bbaee..bdc2e6bfb 100644 --- a/engine/client/snd_dma.c +++ b/engine/client/snd_dma.c @@ -351,7 +351,7 @@ void SNDDMA_SetUnderWater(qboolean underwater) //so that the video code can call it directly without flushing the models it's just loaded. void S_DoRestart (void) { - if (COM_CheckParm("-nosound")) + if (nosound.value) return; S_StopAllSounds (true); @@ -590,8 +590,6 @@ void S_Init (void) snd_initialized = true; - SND_InitScaletable (); - known_sfx = Hunk_AllocName (MAX_SFX*sizeof(sfx_t), "sfx_t"); num_sfx = 0; @@ -1279,11 +1277,7 @@ void GetSoundtime(soundcardinfo_t *sc) sc->paintedtime = fullsamples; S_StopAllSounds (true); } - - sc->rawstart =0; } - else - sc->rawstart += samplepos - sc->oldsamplepos; sc->oldsamplepos = samplepos; soundtime = sc->buffers*fullsamples + samplepos/sc->sn.numchannels; diff --git a/engine/client/snd_mix.c b/engine/client/snd_mix.c index 5e99b7123..f0f385d01 100644 --- a/engine/client/snd_mix.c +++ b/engine/client/snd_mix.c @@ -27,7 +27,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define PAINTBUFFER_SIZE 2048 portable_samplegroup_t paintbuffer[PAINTBUFFER_SIZE]; -int snd_scaletable[32][256]; int *snd_p, snd_vol; short *snd_out; @@ -242,17 +241,6 @@ void Snd_WriteLinearBlast6Speaker16 (soundcardinfo_t *sc) snd_out[i+5] = (short)0x8000; else snd_out[i+5] = val; - -#if 0 - snd_out[i+0] = rand(); - snd_out[i+1] = rand(); - snd_out[i+2] = rand(); - snd_out[i+3] = rand(); - snd_out[i+4] = rand(); - snd_out[i+5] = rand(); -#elif 0 - snd_out[i+0]=snd_out[i+1]=snd_out[i+2]=snd_out[i+3]=snd_out[i+4]=snd_out[i+5] = rand(); -#endif } } void S_Transfer6Speaker16 (soundcardinfo_t *sc, int endtime) @@ -382,7 +370,7 @@ CHANNEL MIXING */ void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int endtime); -void SND_PaintChannelFrom8Duel (channel_t *ch, sfxcache_t *sc, int endtime); +//void SND_PaintChannelFrom8Duel (channel_t *ch, sfxcache_t *sc, int endtime); void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int endtime); void SND_PaintChannelFrom8_4Speaker (channel_t *ch, sfxcache_t *sc, int count); void SND_PaintChannelFrom16_4Speaker (channel_t *ch, sfxcache_t *sc, int count); @@ -402,7 +390,6 @@ void S_PaintChannels(soundcardinfo_t *sc, int endtime) // sc->rawstart += sc->paintedtime - sc->oldpaintedtime; // sc->oldpaintedtime = sc->paintedtime; - while (sc->paintedtime < endtime) { // if paintbuffer is smaller than DMA buffer @@ -479,52 +466,28 @@ void S_PaintChannels(soundcardinfo_t *sc, int endtime) continue; } -/*dmw having fun - int uw; - int oldpos = ch->pos; - int vol = ch->vol[0]; - int rvol = ch->vol[1]; - int end = ch->end; - ch->vol[1]=0; - ch->vol[0]/=2; - for (uw = 0; uw < 5; uw++) - { -*/ - if (scache->width == 1) - { - if (scache->numchannels==2) - SND_PaintChannelFrom8Stereo(ch, scache, count); - else if (sc->sn.numchannels == 6) - SND_PaintChannelFrom8_6Speaker(ch, scache, count); - else if (sc->sn.numchannels == 4) - SND_PaintChannelFrom8_4Speaker(ch, scache, count); - else - SND_PaintChannelFrom8(ch, scache, count); - } - else - { - if (scache->numchannels==2) - SND_PaintChannelFrom16Stereo(ch, scache, count); - else if (sc->sn.numchannels == 6) - SND_PaintChannelFrom16_6Speaker(ch, scache, count); - else if (sc->sn.numchannels == 4) - SND_PaintChannelFrom16_4Speaker(ch, scache, count); - else - SND_PaintChannelFrom16(ch, scache, count); - } -/* lots of fun -// ch->vol[0]*=-1; - ch->vol[1]=0; - ch->vol[0]/=1.3; - ch->pos=oldpos-cursndcard->sn.speed*uw*0.06; - if (ch->pos >= sc->length || ch->pos < 0) - break; - + if (scache->width == 1) + { + if (scache->numchannels==2) + SND_PaintChannelFrom8Stereo(ch, scache, count); + else if (sc->sn.numchannels == 6) + SND_PaintChannelFrom8_6Speaker(ch, scache, count); + else if (sc->sn.numchannels == 4) + SND_PaintChannelFrom8_4Speaker(ch, scache, count); + else + SND_PaintChannelFrom8(ch, scache, count); + } + else + { + if (scache->numchannels==2) + SND_PaintChannelFrom16Stereo(ch, scache, count); + else if (sc->sn.numchannels == 6) + SND_PaintChannelFrom16_6Speaker(ch, scache, count); + else if (sc->sn.numchannels == 4) + SND_PaintChannelFrom16_4Speaker(ch, scache, count); + else + SND_PaintChannelFrom16(ch, scache, count); } - ch->vol[0] = vol; - ch->vol[1] = rvol; - ch->pos = oldpos+count; - */ ltime += count; } @@ -534,10 +497,7 @@ void S_PaintChannels(soundcardinfo_t *sc, int endtime) if (scache->loopstart >= 0) { if (scache->length == scache->loopstart) - { -// Con_Printf("Looped to end %i\n", ch->pos); - break; //don't bother restarting it it - } + break; ch->pos = scache->loopstart; ch->end = ltime + scache->length - ch->pos; if (!scache->length) @@ -572,23 +532,12 @@ void S_PaintChannels(soundcardinfo_t *sc, int endtime) } } -void SND_InitScaletable (void) -{ - int i, j; - - for (i=0 ; i<32 ; i++) - for (j=0 ; j<256 ; j++) - snd_scaletable[i][j] = ((signed char)j) * i * 8; -} - - -#if defined(NOSOUNDASM) || !id386 +//if defined(NOSOUNDASM) || !id386 void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int count) { int data; - int *lscale, *rscale; - unsigned char *sfx; + signed char *sfx; int i; if (ch->vol[0] > 255) @@ -596,34 +545,29 @@ void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int count) if (ch->vol[1] > 255) ch->vol[1] = 255; - - lscale = snd_scaletable[ch->vol[0] >> 3]; - rscale = snd_scaletable[ch->vol[1] >> 3]; sfx = (signed char *)sc->data + ch->pos; for (i=0 ; ivol[0] * data; + paintbuffer[i].s[1] += ch->vol[1] * data; } ch->pos += count; } + +#if 0 void SND_PaintChannelFrom8Duel (channel_t *ch, sfxcache_t *sc, int count) { - int *lscale, *rscale; - unsigned char *sfx1, *sfx2; + signed char *sfx1, *sfx2; int i; if (ch->vol[0] > 255) ch->vol[0] = 255; if (ch->vol[1] > 255) ch->vol[1] = 255; - - lscale = snd_scaletable[ch->vol[0] >> 3]; - rscale = snd_scaletable[ch->vol[1] >> 3]; i = ch->pos - ch->delay[0]; if (i < 0) i = 0; sfx1 = (signed char *)sc->data + i; @@ -633,36 +577,32 @@ void SND_PaintChannelFrom8Duel (channel_t *ch, sfxcache_t *sc, int count) for (i=0 ; ivol[0] * sfx1[i]; + paintbuffer[i].s[1] += ch->vol[1] * sfx2[i]; } ch->pos += count; } - -#endif // !id386 +#endif +//endif // !id386 void SND_PaintChannelFrom8Stereo (channel_t *ch, sfxcache_t *sc, int count) { // int data; - int *lscale, *rscale; - unsigned char *sfx; + signed char *sfx; int i; if (ch->vol[0] > 255) ch->vol[0] = 255; if (ch->vol[1] > 255) ch->vol[1] = 255; - - lscale = snd_scaletable[ch->vol[0] >> 3]; - rscale = snd_scaletable[ch->vol[1] >> 3]; sfx = (signed char *)sc->data + ch->pos; for (i=0 ; ivol[0] * sfx[(i<<1)]; + paintbuffer[i].s[1] += ch->vol[1] * sfx[(i<<1)+1]; } ch->pos += count; @@ -670,8 +610,7 @@ void SND_PaintChannelFrom8Stereo (channel_t *ch, sfxcache_t *sc, int count) void SND_PaintChannelFrom8_4Speaker (channel_t *ch, sfxcache_t *sc, int count) { - int *scale0, *scale1, *scale2, *scale3; - unsigned char *sfx; + signed char *sfx; int i; if (ch->vol[0] > 255) @@ -683,18 +622,14 @@ void SND_PaintChannelFrom8_4Speaker (channel_t *ch, sfxcache_t *sc, int count) if (ch->vol[3] > 255) ch->vol[3] = 255; - scale0 = snd_scaletable[ch->vol[0] >> 3]; - scale1 = snd_scaletable[ch->vol[1] >> 3]; - scale2 = snd_scaletable[ch->vol[2] >> 3]; - scale3 = snd_scaletable[ch->vol[3] >> 3]; sfx = (signed char *)sc->data + ch->pos; for (i=0 ; ivol[0] * sfx[i]; + paintbuffer[i].s[1] += ch->vol[1] * sfx[i]; + paintbuffer[i].s[2] += ch->vol[2] * sfx[i]; + paintbuffer[i].s[3] += ch->vol[3] * sfx[i]; } ch->pos += count; @@ -702,8 +637,7 @@ void SND_PaintChannelFrom8_4Speaker (channel_t *ch, sfxcache_t *sc, int count) void SND_PaintChannelFrom8_6Speaker (channel_t *ch, sfxcache_t *sc, int count) { - int *scale0, *scale1, *scale2, *scale3, *scale4, *scale5; - unsigned char *sfx; + signed char *sfx; int i; if (ch->vol[0] > 255) @@ -719,22 +653,16 @@ void SND_PaintChannelFrom8_6Speaker (channel_t *ch, sfxcache_t *sc, int count) if (ch->vol[5] > 255) ch->vol[5] = 255; - scale0 = snd_scaletable[ch->vol[0] >> 3]; - scale1 = snd_scaletable[ch->vol[1] >> 3]; - scale2 = snd_scaletable[ch->vol[2] >> 3]; - scale3 = snd_scaletable[ch->vol[3] >> 3]; - scale4 = snd_scaletable[ch->vol[4] >> 3]; - scale5 = snd_scaletable[ch->vol[5] >> 3]; sfx = (signed char *)sc->data + ch->pos; for (i=0 ; ivol[0] * sfx[i]; + paintbuffer[i].s[1] += ch->vol[1] * sfx[i]; + paintbuffer[i].s[2] += ch->vol[2] * sfx[i]; + paintbuffer[i].s[3] += ch->vol[3] * sfx[i]; + paintbuffer[i].s[4] += ch->vol[4] * sfx[i]; + paintbuffer[i].s[5] += ch->vol[5] * sfx[i]; } ch->pos += count; diff --git a/engine/client/snd_mixa.s b/engine/client/snd_mixa.s index ad8b614af..bbc6f09dc 100644 --- a/engine/client/snd_mixa.s +++ b/engine/client/snd_mixa.s @@ -39,6 +39,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define sc 8+16 #define count 12+16 +#if 0 +// This code isn't maintained. It needs the snd_scaletable references removed. +// snd_scaletable[x][y] -> x * 8 * y + .globl C(SND_PaintChannelFrom8) C(SND_PaintChannelFrom8): pushl %esi // preserve register variables @@ -136,7 +140,7 @@ LDone: popl %esi ret - +#endif //---------------------------------------------------------------------- // Transfer of stereo buffer to 16-bit DMA buffer code diff --git a/engine/client/sound.h b/engine/client/sound.h index c5457e450..aa7d5dd50 100644 --- a/engine/client/sound.h +++ b/engine/client/sound.h @@ -193,8 +193,6 @@ qboolean S_RegisterSoundInputPlugin(S_LoadSound_t loadfnc); //called to register wavinfo_t GetWavinfo (char *name, qbyte *wav, int wavlength); -void SND_InitScaletable (void); - void S_AmbientOff (void); void S_AmbientOn (void); @@ -231,9 +229,6 @@ struct soundcardinfo_s { //windows has one defined AFTER directsound int snd_linear_count; //used by the mixer. int buffers; //used to keep track of buffer wraps for consistant sound - int rawend; //streaming audio (avi/cin/roq) - int rawstart; - //callbacks void *(*Lock) (soundcardinfo_t *sc); void (*Unlock) (soundcardinfo_t *sc, void *buffer); diff --git a/engine/common/quakeasm.h b/engine/common/quakeasm.h index 0680671fa..4fe0ad16b 100644 --- a/engine/common/quakeasm.h +++ b/engine/common/quakeasm.h @@ -275,7 +275,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. .extern spr8entryvec_table #endif - .extern C(snd_scaletable) .extern C(paintbuffer) // .extern C(snd_linear_count) .extern C(cursndcard) diff --git a/engine/sw/r_edge.c b/engine/sw/r_edge.c index 6eeef491b..13c3499b2 100644 --- a/engine/sw/r_edge.c +++ b/engine/sw/r_edge.c @@ -885,9 +885,7 @@ void R_ScanEdges (void) // the next scan if (span_p > max_span_p) { - VID_UnlockBuffer (); S_ExtraUpdate (); // don't let sound get messed up if going slow - VID_LockBuffer (); if (r_drawculledpolys) R_DrawCulledPolys (); diff --git a/engine/sw/r_main.c b/engine/sw/r_main.c index c73ae4eaf..836674160 100644 --- a/engine/sw/r_main.c +++ b/engine/sw/r_main.c @@ -1363,9 +1363,7 @@ void R_EdgeDrawing (void) if (!r_dspeeds.value) { - VID_UnlockBuffer (); S_ExtraUpdate (); // don't let sound get messed up if going slow - VID_LockBuffer (); } if (!(r_drawpolys | r_drawculledpolys)) @@ -1426,9 +1424,7 @@ SetVisibilityByPassages (); if (!r_dspeeds.value) { - VID_UnlockBuffer (); S_ExtraUpdate (); // don't let sound get messed up if going slow - VID_LockBuffer (); } R_EdgeDrawing (); diff --git a/engine/sw/sw_draw.c b/engine/sw/sw_draw.c index 657b2c761..82f071811 100644 --- a/engine/sw/sw_draw.c +++ b/engine/sw/sw_draw.c @@ -2598,10 +2598,6 @@ void SWDraw_FadeScreen (void) { int x,y; - VID_UnlockBuffer (); - S_ExtraUpdate (); - VID_LockBuffer (); - if (r_pixbytes == 4) { qbyte *pbuf; @@ -2652,9 +2648,7 @@ void SWDraw_FadeScreen (void) } } - VID_UnlockBuffer (); S_ExtraUpdate (); - VID_LockBuffer (); }