mirror of
https://git.code.sf.net/p/quake/nuq
synced 2024-11-25 05:21:41 +00:00
Stereo using phase separation now works without static. It is turned off by
default, but can be turned on simply by setting snd_stereo_phase_separation to something resonable (eg 0.6). snd_stereo_phase_separation is measured in milliseconds and the 0.6 is based on assuming a 20cm diameter head with speed of sound being 331m/s (0.000604229607 is more accurate for that, but I didn't want to type it in the console:) at the moment, phase and volume separation happen together. I'm not sure if it's worth disabling volume separation when phase separation is used, it sounds good to me :).
This commit is contained in:
parent
b08583c57e
commit
4323b3039e
1 changed files with 19 additions and 10 deletions
|
@ -39,7 +39,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define PAINTBUFFER_SIZE 512
|
#define PAINTBUFFER_SIZE 512
|
||||||
portable_samplepair_t paintbuffer[PAINTBUFFER_SIZE+100];
|
portable_samplepair_t paintbuffer[PAINTBUFFER_SIZE * 2];
|
||||||
|
int max_overpaint; // number of extra samples painted due to phase shift
|
||||||
int snd_scaletable[32][256];
|
int snd_scaletable[32][256];
|
||||||
int *snd_p, snd_linear_count, snd_vol;
|
int *snd_p, snd_linear_count, snd_vol;
|
||||||
short *snd_out;
|
short *snd_out;
|
||||||
|
@ -279,15 +280,16 @@ void S_PaintChannels(int endtime)
|
||||||
|
|
||||||
while (paintedtime < endtime)
|
while (paintedtime < endtime)
|
||||||
{
|
{
|
||||||
// if paintbuffer is smaller than DMA buffer
|
// if paintbuffer is smaller than DMA buffer
|
||||||
end = endtime;
|
end = endtime;
|
||||||
if (endtime - paintedtime > PAINTBUFFER_SIZE)
|
if (endtime - paintedtime > PAINTBUFFER_SIZE)
|
||||||
end = paintedtime + PAINTBUFFER_SIZE;
|
end = paintedtime + PAINTBUFFER_SIZE;
|
||||||
|
|
||||||
// clear the paint buffer
|
// clear the paint buffer
|
||||||
memset(paintbuffer, 0, (end - paintedtime) * sizeof(portable_samplepair_t));
|
//memset(paintbuffer, 0, (end - paintedtime) * sizeof(portable_samplepair_t));
|
||||||
|
max_overpaint = 0;
|
||||||
|
|
||||||
// paint in the channels.
|
// paint in the channels.
|
||||||
ch = channels;
|
ch = channels;
|
||||||
for (i=0; i<total_channels ; i++, ch++)
|
for (i=0; i<total_channels ; i++, ch++)
|
||||||
{
|
{
|
||||||
|
@ -302,7 +304,8 @@ void S_PaintChannels(int endtime)
|
||||||
ltime = paintedtime;
|
ltime = paintedtime;
|
||||||
|
|
||||||
while (ltime < end)
|
while (ltime < end)
|
||||||
{ // paint up to end
|
{
|
||||||
|
// paint up to end
|
||||||
if (ch->end < end)
|
if (ch->end < end)
|
||||||
count = ch->end - ltime;
|
count = ch->end - ltime;
|
||||||
else
|
else
|
||||||
|
@ -318,7 +321,7 @@ void S_PaintChannels(int endtime)
|
||||||
ltime += count;
|
ltime += count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if at end of loop, restart
|
// if at end of loop, restart
|
||||||
if (ltime >= ch->end)
|
if (ltime >= ch->end)
|
||||||
{
|
{
|
||||||
if (sc->loopstart >= 0)
|
if (sc->loopstart >= 0)
|
||||||
|
@ -336,8 +339,12 @@ void S_PaintChannels(int endtime)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// transfer out according to DMA format
|
// transfer out according to DMA format
|
||||||
S_TransferPaintBuffer(end);
|
S_TransferPaintBuffer(end);
|
||||||
|
|
||||||
|
memcpy (paintbuffer, paintbuffer + end - paintedtime, max_overpaint * sizeof (paintbuffer[0]));
|
||||||
|
memset (paintbuffer + max_overpaint, 0, sizeof (paintbuffer) - max_overpaint * sizeof (paintbuffer[0]));
|
||||||
|
|
||||||
paintedtime = end;
|
paintedtime = end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -397,9 +404,13 @@ void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int count)
|
||||||
if (ch->phase >= 0) {
|
if (ch->phase >= 0) {
|
||||||
left_phase = ch->phase;
|
left_phase = ch->phase;
|
||||||
right_phase = 0;
|
right_phase = 0;
|
||||||
|
if (ch->phase > max_overpaint)
|
||||||
|
max_overpaint = ch->phase;
|
||||||
} else {
|
} else {
|
||||||
left_phase = 0;
|
left_phase = 0;
|
||||||
right_phase = -ch->phase;
|
right_phase = -ch->phase;
|
||||||
|
if (-ch->phase > max_overpaint)
|
||||||
|
max_overpaint = -ch->phase;
|
||||||
}
|
}
|
||||||
sfx = (signed short *)sc->data + ch->pos;
|
sfx = (signed short *)sc->data + ch->pos;
|
||||||
|
|
||||||
|
@ -408,8 +419,6 @@ void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int count)
|
||||||
data = sfx[i];
|
data = sfx[i];
|
||||||
left = (data * leftvol) >> 8;
|
left = (data * leftvol) >> 8;
|
||||||
right = (data * rightvol) >> 8;
|
right = (data * rightvol) >> 8;
|
||||||
//paintbuffer[i].left += left;
|
|
||||||
//paintbuffer[i].right += right;
|
|
||||||
paintbuffer[i+left_phase].left += left;
|
paintbuffer[i+left_phase].left += left;
|
||||||
paintbuffer[i+right_phase].right += right;
|
paintbuffer[i+right_phase].right += right;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue