mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
better sound offsetting
This commit is contained in:
parent
33a7c395dc
commit
f2d7630ac1
2 changed files with 63 additions and 26 deletions
|
@ -576,8 +576,8 @@ SND_StartSound (int entnum, int entchannel, sfx_t *sfx, const vec3_t origin,
|
|||
// new channel
|
||||
if (!(osfx = sfx->open (sfx)))
|
||||
return;
|
||||
target_chan->pos = 0.0;
|
||||
target_chan->end = snd_paintedtime + osfx->length;
|
||||
target_chan->pos = 0;
|
||||
target_chan->end = 0;
|
||||
|
||||
// if an identical sound has also been started this frame, offset the pos
|
||||
// a bit to keep it from just making the first one louder
|
||||
|
@ -585,11 +585,12 @@ SND_StartSound (int entnum, int entchannel, sfx_t *sfx, const vec3_t origin,
|
|||
if (!check || check == target_chan)
|
||||
continue;
|
||||
if (check->sfx == osfx && !check->pos) {
|
||||
skip = rand () % (int) (0.1 * snd_shm->speed);
|
||||
if (skip >= target_chan->end)
|
||||
skip = target_chan->end - 1;
|
||||
target_chan->pos += skip;
|
||||
target_chan->end -= skip;
|
||||
skip = rand () % (int) (0.01 * snd_shm->speed);
|
||||
target_chan->pos = -skip;
|
||||
//if (skip >= target_chan->end)
|
||||
// skip = target_chan->end - 1;
|
||||
//target_chan->pos += skip;
|
||||
//target_chan->end -= skip;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -597,11 +598,12 @@ SND_StartSound (int entnum, int entchannel, sfx_t *sfx, const vec3_t origin,
|
|||
if (!check || check == target_chan)
|
||||
continue;
|
||||
if (check->sfx == osfx && !check->pos) {
|
||||
skip = rand () % (int) (0.1 * snd_shm->speed);
|
||||
if (skip >= target_chan->end)
|
||||
skip = target_chan->end - 1;
|
||||
target_chan->pos += skip;
|
||||
target_chan->end -= skip;
|
||||
skip = rand () % (int) (0.01 * snd_shm->speed);
|
||||
target_chan->pos = -skip;
|
||||
//if (skip >= target_chan->end)
|
||||
// skip = target_chan->end - 1;
|
||||
//target_chan->pos += skip;
|
||||
//target_chan->end -= skip;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,8 +88,8 @@ SND_PaintChannels (unsigned int endtime)
|
|||
end = snd_paintedtime + PAINTBUFFER_SIZE;
|
||||
|
||||
// clear the paint buffer
|
||||
// memset (snd_paintbuffer, 0, (end - snd_paintedtime) *
|
||||
// sizeof (portable_samplepair_t));
|
||||
memset (snd_paintbuffer, 0, (end - snd_paintedtime) *
|
||||
sizeof (portable_samplepair_t));
|
||||
max_overpaint = 0;
|
||||
|
||||
// paint in the channels.
|
||||
|
@ -102,6 +102,9 @@ SND_PaintChannels (unsigned int endtime)
|
|||
ch->done = 1; // acknowledge stopped signal
|
||||
continue;
|
||||
}
|
||||
if (!ch->end) {
|
||||
ch->end = snd_paintedtime + ch->sfx->length;
|
||||
}
|
||||
if (!ch->leftvol && !ch->rightvol) {
|
||||
ltime = snd_paintedtime;
|
||||
if (ch->end < end)
|
||||
|
@ -329,8 +332,16 @@ void
|
|||
SND_PaintChannelFrom8 (channel_t *ch, sfxbuffer_t *sc, int count)
|
||||
{
|
||||
unsigned int pos;
|
||||
int offs = 0;
|
||||
byte *samps;
|
||||
|
||||
if ((int) ch->pos < 0) {
|
||||
ch->pos += count;
|
||||
if ((int) ch->pos < 0)
|
||||
return;
|
||||
offs = ch->pos;
|
||||
ch->pos = 0;
|
||||
}
|
||||
if (ch->pos < sc->pos)
|
||||
sc->setpos (sc, ch->pos);
|
||||
pos = (ch->pos - sc->pos + sc->tail) % sc->length;
|
||||
|
@ -338,10 +349,10 @@ SND_PaintChannelFrom8 (channel_t *ch, sfxbuffer_t *sc, int count)
|
|||
|
||||
if (pos + count > sc->length) {
|
||||
int sub = sc->length - pos;
|
||||
snd_paint_mono_8 (0, ch, samps, sub);
|
||||
snd_paint_mono_8 (sub, ch, sc->data, count - sub);
|
||||
snd_paint_mono_8 (offs, ch, samps, sub);
|
||||
snd_paint_mono_8 (offs + sub, ch, sc->data, count - sub);
|
||||
} else {
|
||||
snd_paint_mono_8 (0, ch, samps, count);
|
||||
snd_paint_mono_8 (offs, ch, samps, count);
|
||||
}
|
||||
ch->pos += count;
|
||||
}
|
||||
|
@ -350,8 +361,16 @@ void
|
|||
SND_PaintChannelFrom16 (channel_t *ch, sfxbuffer_t *sc, int count)
|
||||
{
|
||||
unsigned int pos;
|
||||
int offs = 0;
|
||||
short *samps;
|
||||
|
||||
if ((int) ch->pos < 0) {
|
||||
ch->pos += count;
|
||||
if ((int) ch->pos < 0)
|
||||
return;
|
||||
offs = ch->pos;
|
||||
ch->pos = 0;
|
||||
}
|
||||
if (ch->pos < sc->pos)
|
||||
sc->setpos (sc, ch->pos);
|
||||
pos = (ch->pos - sc->pos + sc->tail) % sc->length;
|
||||
|
@ -360,10 +379,10 @@ SND_PaintChannelFrom16 (channel_t *ch, sfxbuffer_t *sc, int count)
|
|||
if (pos + count > sc->length) {
|
||||
unsigned int sub = sc->length - pos;
|
||||
|
||||
snd_paint_mono_16 (0, ch, samps, sub);
|
||||
snd_paint_mono_16 (sub, ch, sc->data, count - sub);
|
||||
snd_paint_mono_16 (offs, ch, samps, sub);
|
||||
snd_paint_mono_16 (offs + sub, ch, sc->data, count - sub);
|
||||
} else {
|
||||
snd_paint_mono_16 (0, ch, samps, count);
|
||||
snd_paint_mono_16 (offs, ch, samps, count);
|
||||
}
|
||||
ch->pos += count;
|
||||
}
|
||||
|
@ -372,8 +391,16 @@ void
|
|||
SND_PaintChannelStereo8 (channel_t *ch, sfxbuffer_t *sc, int count)
|
||||
{
|
||||
unsigned int pos;
|
||||
int offs = 0;
|
||||
short *samps;
|
||||
|
||||
if ((int) ch->pos < 0) {
|
||||
ch->pos += count;
|
||||
if ((int) ch->pos < 0)
|
||||
return;
|
||||
offs = ch->pos;
|
||||
ch->pos = 0;
|
||||
}
|
||||
if (ch->pos < sc->pos)
|
||||
sc->setpos (sc, ch->pos);
|
||||
pos = (ch->pos - sc->pos + sc->tail) % sc->length;
|
||||
|
@ -382,10 +409,10 @@ SND_PaintChannelStereo8 (channel_t *ch, sfxbuffer_t *sc, int count)
|
|||
if (pos + count > sc->length) {
|
||||
unsigned int sub = sc->length - pos;
|
||||
|
||||
snd_paint_stereo_8 (0, ch, samps, sub);
|
||||
snd_paint_stereo_8 (sub, ch, sc->data, count - sub);
|
||||
snd_paint_stereo_8 (offs, ch, samps, sub);
|
||||
snd_paint_stereo_8 (offs + sub, ch, sc->data, count - sub);
|
||||
} else {
|
||||
snd_paint_stereo_8 (0, ch, samps, count);
|
||||
snd_paint_stereo_8 (offs, ch, samps, count);
|
||||
}
|
||||
ch->pos += count;
|
||||
}
|
||||
|
@ -394,8 +421,16 @@ void
|
|||
SND_PaintChannelStereo16 (channel_t *ch, sfxbuffer_t *sc, int count)
|
||||
{
|
||||
unsigned int pos;
|
||||
int offs = 0;
|
||||
int *samps;
|
||||
|
||||
if ((int) ch->pos < 0) {
|
||||
ch->pos += count;
|
||||
if ((int) ch->pos < 0)
|
||||
return;
|
||||
offs = ch->pos;
|
||||
ch->pos = 0;
|
||||
}
|
||||
if (ch->pos < sc->pos)
|
||||
sc->setpos (sc, ch->pos);
|
||||
pos = (ch->pos - sc->pos + sc->tail) % sc->length;
|
||||
|
@ -404,10 +439,10 @@ SND_PaintChannelStereo16 (channel_t *ch, sfxbuffer_t *sc, int count)
|
|||
if (pos + count > sc->length) {
|
||||
unsigned int sub = sc->length - pos;
|
||||
|
||||
snd_paint_stereo_16 (0, ch, samps, sub);
|
||||
snd_paint_stereo_16 (sub, ch, sc->data, count - sub);
|
||||
snd_paint_stereo_16 (offs, ch, samps, sub);
|
||||
snd_paint_stereo_16 (offs + sub, ch, sc->data, count - sub);
|
||||
} else {
|
||||
snd_paint_stereo_16 (0, ch, samps, count);
|
||||
snd_paint_stereo_16 (offs, ch, samps, count);
|
||||
}
|
||||
ch->pos += count;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue