first attempt at stereo phase separation. sortof works but is staticy due to

lost samples. currently disabled so nobody complains
This commit is contained in:
Bill Currie 2000-10-06 23:48:09 +00:00
parent b17b8afa3c
commit 8bb5d9decb
4 changed files with 27 additions and 4 deletions

View file

@ -93,7 +93,8 @@
#define ch_origin 32
#define ch_dist_mult 44
#define ch_master_vol 48
#define ch_size 52
#define ch_phase 52
#define ch_size 56
// portable_samplepair_t structure
// !!! if this is changed, it much be changed in sound.h too !!!

View file

@ -89,6 +89,7 @@ typedef struct
vec3_t origin; // origin of sound effect
vec_t dist_mult; // distance multiplier (attenuation/clipK)
int master_vol; // 0-255 master volume
int phase; // phase shift between l-r in samples
} channel_t;
typedef struct
@ -173,6 +174,7 @@ extern cvar_t *bgmvolume;
extern cvar_t *volume;
extern cvar_t *snd_interp;
extern cvar_t *snd_stereo_phase_separation;
extern qboolean snd_initialized;

View file

@ -100,6 +100,7 @@ cvar_t *ambient_fade;
cvar_t *snd_noextraupdate;
cvar_t *snd_show;
cvar_t *snd_interp;
cvar_t *snd_stereo_phase_separation;
cvar_t *_snd_mixahead;
@ -207,6 +208,7 @@ void S_Init (void)
snd_noextraupdate = Cvar_Get("snd_noextraupdate", "0", CVAR_NONE, "None");
snd_show = Cvar_Get("snd_show", "0", CVAR_NONE, "None");
snd_interp = Cvar_Get("snd_interp", "1", CVAR_ARCHIVE, "control sample interpolation");
snd_stereo_phase_separation = Cvar_Get("snd_stereo_phase_separation", "0.0", CVAR_ARCHIVE, "max stereo phase separation in ms. 0.6 is for 20cm head");
_snd_mixahead = Cvar_Get("_snd_mixahead", "0.1", CVAR_ARCHIVE, "None");
if (COM_CheckParm("-nosound"))
@ -424,6 +426,7 @@ void SND_Spatialize(channel_t *ch)
{
vec_t dot;
vec_t dist;
int phase; // in samples
vec_t lscale, rscale, scale;
vec3_t source_vec;
sfx_t *snd;
@ -433,6 +436,7 @@ void SND_Spatialize(channel_t *ch)
{
ch->leftvol = ch->master_vol;
ch->rightvol = ch->master_vol;
ch->phase = 0;
return;
}
@ -449,11 +453,15 @@ void SND_Spatialize(channel_t *ch)
{
rscale = 1.0;
lscale = 1.0;
phase = 0;
}
else
{
rscale = 1.0 + dot;
lscale = 1.0 - dot;
//rscale = 1.0;
//lscale = 1.0;
phase = snd_stereo_phase_separation->value * 0.001 * shm->speed * dot;
}
// add in distance effect
@ -466,6 +474,8 @@ void SND_Spatialize(channel_t *ch)
ch->leftvol = (int) (ch->master_vol * scale);
if (ch->leftvol < 0)
ch->leftvol = 0;
ch->phase = phase;
}

View file

@ -39,7 +39,7 @@
#endif
#define PAINTBUFFER_SIZE 512
portable_samplepair_t paintbuffer[PAINTBUFFER_SIZE];
portable_samplepair_t paintbuffer[PAINTBUFFER_SIZE+100];
int snd_scaletable[32][256];
int *snd_p, snd_linear_count, snd_vol;
short *snd_out;
@ -390,9 +390,17 @@ void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int count)
int leftvol, rightvol;
signed short *sfx;
int i;
int left_phase, right_phase;
leftvol = ch->leftvol;
rightvol = ch->rightvol;
if (ch->phase >= 0) {
left_phase = ch->phase;
right_phase = 0;
} else {
left_phase = 0;
right_phase = -ch->phase;
}
sfx = (signed short *)sc->data + ch->pos;
for (i=0 ; i<count ; i++)
@ -400,8 +408,10 @@ void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int count)
data = sfx[i];
left = (data * leftvol) >> 8;
right = (data * rightvol) >> 8;
paintbuffer[i].left += left;
paintbuffer[i].right += right;
//paintbuffer[i].left += left;
//paintbuffer[i].right += right;
paintbuffer[i+left_phase].left += left;
paintbuffer[i+right_phase].right += right;
}
ch->pos += count;