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
This commit is contained in:
TimeServ 2006-05-08 21:02:39 +00:00
parent de74e43c4a
commit 469fb50e57
9 changed files with 55 additions and 153 deletions

View file

@ -940,9 +940,7 @@ void M_Draw (int uimenu)
#ifdef VM_UI #ifdef VM_UI
UI_DrawMenu(); UI_DrawMenu();
#endif #endif
VID_UnlockBuffer ();
S_ExtraUpdate (); S_ExtraUpdate ();
VID_LockBuffer ();
} }
if (m_state != m_complex) if (m_state != m_complex)
@ -965,9 +963,7 @@ void M_Draw (int uimenu)
if (scr_con_current) if (scr_con_current)
{ {
Draw_ConsoleBackground (vid.height); Draw_ConsoleBackground (vid.height);
VID_UnlockBuffer ();
S_ExtraUpdate (); S_ExtraUpdate ();
VID_LockBuffer ();
} }
else else
Draw_FadeScreen (); Draw_FadeScreen ();
@ -1015,9 +1011,7 @@ void M_Draw (int uimenu)
#endif #endif
} }
VID_UnlockBuffer ();
S_ExtraUpdate (); S_ExtraUpdate ();
VID_LockBuffer ();
} }

View file

@ -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. //so that the video code can call it directly without flushing the models it's just loaded.
void S_DoRestart (void) void S_DoRestart (void)
{ {
if (COM_CheckParm("-nosound")) if (nosound.value)
return; return;
S_StopAllSounds (true); S_StopAllSounds (true);
@ -590,8 +590,6 @@ void S_Init (void)
snd_initialized = true; snd_initialized = true;
SND_InitScaletable ();
known_sfx = Hunk_AllocName (MAX_SFX*sizeof(sfx_t), "sfx_t"); known_sfx = Hunk_AllocName (MAX_SFX*sizeof(sfx_t), "sfx_t");
num_sfx = 0; num_sfx = 0;
@ -1279,11 +1277,7 @@ void GetSoundtime(soundcardinfo_t *sc)
sc->paintedtime = fullsamples; sc->paintedtime = fullsamples;
S_StopAllSounds (true); S_StopAllSounds (true);
} }
sc->rawstart =0;
} }
else
sc->rawstart += samplepos - sc->oldsamplepos;
sc->oldsamplepos = samplepos; sc->oldsamplepos = samplepos;
soundtime = sc->buffers*fullsamples + samplepos/sc->sn.numchannels; soundtime = sc->buffers*fullsamples + samplepos/sc->sn.numchannels;

View file

@ -27,7 +27,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define PAINTBUFFER_SIZE 2048 #define PAINTBUFFER_SIZE 2048
portable_samplegroup_t paintbuffer[PAINTBUFFER_SIZE]; portable_samplegroup_t paintbuffer[PAINTBUFFER_SIZE];
int snd_scaletable[32][256];
int *snd_p, snd_vol; int *snd_p, snd_vol;
short *snd_out; short *snd_out;
@ -242,17 +241,6 @@ void Snd_WriteLinearBlast6Speaker16 (soundcardinfo_t *sc)
snd_out[i+5] = (short)0x8000; snd_out[i+5] = (short)0x8000;
else else
snd_out[i+5] = val; 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) 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_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_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int endtime);
void SND_PaintChannelFrom8_4Speaker (channel_t *ch, sfxcache_t *sc, int count); void SND_PaintChannelFrom8_4Speaker (channel_t *ch, sfxcache_t *sc, int count);
void SND_PaintChannelFrom16_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->rawstart += sc->paintedtime - sc->oldpaintedtime;
// sc->oldpaintedtime = sc->paintedtime; // sc->oldpaintedtime = sc->paintedtime;
while (sc->paintedtime < endtime) while (sc->paintedtime < endtime)
{ {
// if paintbuffer is smaller than DMA buffer // if paintbuffer is smaller than DMA buffer
@ -479,17 +466,6 @@ void S_PaintChannels(soundcardinfo_t *sc, int endtime)
continue; 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->width == 1)
{ {
if (scache->numchannels==2) if (scache->numchannels==2)
@ -512,19 +488,6 @@ void S_PaintChannels(soundcardinfo_t *sc, int endtime)
else else
SND_PaintChannelFrom16(ch, scache, count); 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;
}
ch->vol[0] = vol;
ch->vol[1] = rvol;
ch->pos = oldpos+count;
*/
ltime += count; ltime += count;
} }
@ -534,10 +497,7 @@ void S_PaintChannels(soundcardinfo_t *sc, int endtime)
if (scache->loopstart >= 0) if (scache->loopstart >= 0)
{ {
if (scache->length == scache->loopstart) if (scache->length == scache->loopstart)
{ break;
// Con_Printf("Looped to end %i\n", ch->pos);
break; //don't bother restarting it it
}
ch->pos = scache->loopstart; ch->pos = scache->loopstart;
ch->end = ltime + scache->length - ch->pos; ch->end = ltime + scache->length - ch->pos;
if (!scache->length) if (!scache->length)
@ -572,23 +532,12 @@ void S_PaintChannels(soundcardinfo_t *sc, int endtime)
} }
} }
void SND_InitScaletable (void) //if defined(NOSOUNDASM) || !id386
{
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
void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int count) void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int count)
{ {
int data; int data;
int *lscale, *rscale; signed char *sfx;
unsigned char *sfx;
int i; int i;
if (ch->vol[0] > 255) if (ch->vol[0] > 255)
@ -596,24 +545,22 @@ void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int count)
if (ch->vol[1] > 255) if (ch->vol[1] > 255)
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; sfx = (signed char *)sc->data + ch->pos;
for (i=0 ; i<count ; i++) for (i=0 ; i<count ; i++)
{ {
data = sfx[i]; data = sfx[i];
paintbuffer[i].s[0] += lscale[data]; paintbuffer[i].s[0] += ch->vol[0] * data;
paintbuffer[i].s[1] += rscale[data]; paintbuffer[i].s[1] += ch->vol[1] * data;
} }
ch->pos += count; ch->pos += count;
} }
#if 0
void SND_PaintChannelFrom8Duel (channel_t *ch, sfxcache_t *sc, int count) void SND_PaintChannelFrom8Duel (channel_t *ch, sfxcache_t *sc, int count)
{ {
int *lscale, *rscale; signed char *sfx1, *sfx2;
unsigned char *sfx1, *sfx2;
int i; int i;
if (ch->vol[0] > 255) if (ch->vol[0] > 255)
@ -621,9 +568,6 @@ void SND_PaintChannelFrom8Duel (channel_t *ch, sfxcache_t *sc, int count)
if (ch->vol[1] > 255) if (ch->vol[1] > 255)
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]; i = ch->pos - ch->delay[0];
if (i < 0) i = 0; if (i < 0) i = 0;
sfx1 = (signed char *)sc->data + i; sfx1 = (signed char *)sc->data + i;
@ -633,20 +577,19 @@ void SND_PaintChannelFrom8Duel (channel_t *ch, sfxcache_t *sc, int count)
for (i=0 ; i<count ; i++) for (i=0 ; i<count ; i++)
{ {
paintbuffer[i].s[0] += lscale[sfx1[i]]; paintbuffer[i].s[0] += ch->vol[0] * sfx1[i];
paintbuffer[i].s[1] += rscale[sfx2[i]]; paintbuffer[i].s[1] += ch->vol[1] * sfx2[i];
} }
ch->pos += count; ch->pos += count;
} }
#endif
#endif // !id386 //endif // !id386
void SND_PaintChannelFrom8Stereo (channel_t *ch, sfxcache_t *sc, int count) void SND_PaintChannelFrom8Stereo (channel_t *ch, sfxcache_t *sc, int count)
{ {
// int data; // int data;
int *lscale, *rscale; signed char *sfx;
unsigned char *sfx;
int i; int i;
if (ch->vol[0] > 255) if (ch->vol[0] > 255)
@ -654,15 +597,12 @@ void SND_PaintChannelFrom8Stereo (channel_t *ch, sfxcache_t *sc, int count)
if (ch->vol[1] > 255) if (ch->vol[1] > 255)
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; sfx = (signed char *)sc->data + ch->pos;
for (i=0 ; i<count ; i++) for (i=0 ; i<count ; i++)
{ {
paintbuffer[i].s[0] += lscale[sfx[(i<<1)]]; paintbuffer[i].s[0] += ch->vol[0] * sfx[(i<<1)];
paintbuffer[i].s[1] += rscale[sfx[(i<<1)+1]]; paintbuffer[i].s[1] += ch->vol[1] * sfx[(i<<1)+1];
} }
ch->pos += count; 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) void SND_PaintChannelFrom8_4Speaker (channel_t *ch, sfxcache_t *sc, int count)
{ {
int *scale0, *scale1, *scale2, *scale3; signed char *sfx;
unsigned char *sfx;
int i; int i;
if (ch->vol[0] > 255) 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) if (ch->vol[3] > 255)
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; sfx = (signed char *)sc->data + ch->pos;
for (i=0 ; i<count ; i++) for (i=0 ; i<count ; i++)
{ {
paintbuffer[i].s[0] += scale0[sfx[i]]; paintbuffer[i].s[0] += ch->vol[0] * sfx[i];
paintbuffer[i].s[1] += scale1[sfx[i]]; paintbuffer[i].s[1] += ch->vol[1] * sfx[i];
paintbuffer[i].s[2] += scale2[sfx[i]]; paintbuffer[i].s[2] += ch->vol[2] * sfx[i];
paintbuffer[i].s[3] += scale3[sfx[i]]; paintbuffer[i].s[3] += ch->vol[3] * sfx[i];
} }
ch->pos += count; 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) void SND_PaintChannelFrom8_6Speaker (channel_t *ch, sfxcache_t *sc, int count)
{ {
int *scale0, *scale1, *scale2, *scale3, *scale4, *scale5; signed char *sfx;
unsigned char *sfx;
int i; int i;
if (ch->vol[0] > 255) 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) if (ch->vol[5] > 255)
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; sfx = (signed char *)sc->data + ch->pos;
for (i=0 ; i<count ; i++) for (i=0 ; i<count ; i++)
{ {
paintbuffer[i].s[0] += scale0[sfx[i]]; paintbuffer[i].s[0] += ch->vol[0] * sfx[i];
paintbuffer[i].s[1] += scale1[sfx[i]]; paintbuffer[i].s[1] += ch->vol[1] * sfx[i];
paintbuffer[i].s[2] += scale2[sfx[i]]; paintbuffer[i].s[2] += ch->vol[2] * sfx[i];
paintbuffer[i].s[3] += scale3[sfx[i]]; paintbuffer[i].s[3] += ch->vol[3] * sfx[i];
paintbuffer[i].s[4] += scale4[sfx[i]]; paintbuffer[i].s[4] += ch->vol[4] * sfx[i];
paintbuffer[i].s[5] += scale5[sfx[i]]; paintbuffer[i].s[5] += ch->vol[5] * sfx[i];
} }
ch->pos += count; ch->pos += count;

View file

@ -39,6 +39,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define sc 8+16 #define sc 8+16
#define count 12+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) .globl C(SND_PaintChannelFrom8)
C(SND_PaintChannelFrom8): C(SND_PaintChannelFrom8):
pushl %esi // preserve register variables pushl %esi // preserve register variables
@ -136,7 +140,7 @@ LDone:
popl %esi popl %esi
ret ret
#endif
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Transfer of stereo buffer to 16-bit DMA buffer code // Transfer of stereo buffer to 16-bit DMA buffer code

View file

@ -193,8 +193,6 @@ qboolean S_RegisterSoundInputPlugin(S_LoadSound_t loadfnc); //called to register
wavinfo_t GetWavinfo (char *name, qbyte *wav, int wavlength); wavinfo_t GetWavinfo (char *name, qbyte *wav, int wavlength);
void SND_InitScaletable (void);
void S_AmbientOff (void); void S_AmbientOff (void);
void S_AmbientOn (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 snd_linear_count; //used by the mixer.
int buffers; //used to keep track of buffer wraps for consistant sound int buffers; //used to keep track of buffer wraps for consistant sound
int rawend; //streaming audio (avi/cin/roq)
int rawstart;
//callbacks //callbacks
void *(*Lock) (soundcardinfo_t *sc); void *(*Lock) (soundcardinfo_t *sc);
void (*Unlock) (soundcardinfo_t *sc, void *buffer); void (*Unlock) (soundcardinfo_t *sc, void *buffer);

View file

@ -275,7 +275,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
.extern spr8entryvec_table .extern spr8entryvec_table
#endif #endif
.extern C(snd_scaletable)
.extern C(paintbuffer) .extern C(paintbuffer)
// .extern C(snd_linear_count) // .extern C(snd_linear_count)
.extern C(cursndcard) .extern C(cursndcard)

View file

@ -885,9 +885,7 @@ void R_ScanEdges (void)
// the next scan // the next scan
if (span_p > max_span_p) if (span_p > max_span_p)
{ {
VID_UnlockBuffer ();
S_ExtraUpdate (); // don't let sound get messed up if going slow S_ExtraUpdate (); // don't let sound get messed up if going slow
VID_LockBuffer ();
if (r_drawculledpolys) if (r_drawculledpolys)
R_DrawCulledPolys (); R_DrawCulledPolys ();

View file

@ -1363,9 +1363,7 @@ void R_EdgeDrawing (void)
if (!r_dspeeds.value) if (!r_dspeeds.value)
{ {
VID_UnlockBuffer ();
S_ExtraUpdate (); // don't let sound get messed up if going slow S_ExtraUpdate (); // don't let sound get messed up if going slow
VID_LockBuffer ();
} }
if (!(r_drawpolys | r_drawculledpolys)) if (!(r_drawpolys | r_drawculledpolys))
@ -1426,9 +1424,7 @@ SetVisibilityByPassages ();
if (!r_dspeeds.value) if (!r_dspeeds.value)
{ {
VID_UnlockBuffer ();
S_ExtraUpdate (); // don't let sound get messed up if going slow S_ExtraUpdate (); // don't let sound get messed up if going slow
VID_LockBuffer ();
} }
R_EdgeDrawing (); R_EdgeDrawing ();

View file

@ -2598,10 +2598,6 @@ void SWDraw_FadeScreen (void)
{ {
int x,y; int x,y;
VID_UnlockBuffer ();
S_ExtraUpdate ();
VID_LockBuffer ();
if (r_pixbytes == 4) if (r_pixbytes == 4)
{ {
qbyte *pbuf; qbyte *pbuf;
@ -2652,9 +2648,7 @@ void SWDraw_FadeScreen (void)
} }
} }
VID_UnlockBuffer ();
S_ExtraUpdate (); S_ExtraUpdate ();
VID_LockBuffer ();
} }