streamed sounds /almost/ work. sound like crap but no crashes

This commit is contained in:
Bill Currie 2003-04-14 15:47:08 +00:00
parent d5c2c092b1
commit 9fda72c119
6 changed files with 119 additions and 34 deletions

View file

@ -156,7 +156,7 @@ extern channel_t channels[MAX_CHANNELS];
// 0 to MAX_DYNAMIC_CHANNELS-1 = normal entity sounds // 0 to MAX_DYNAMIC_CHANNELS-1 = normal entity sounds
// MAX_DYNAMIC_CHANNELS to MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS -1 = water, etc // MAX_DYNAMIC_CHANNELS to MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS -1 = water, etc
// MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS to total_channels = static sounds // MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS to total_channels = static sounds
extern int sound_delta;
extern int total_channels; extern int total_channels;
#endif//__snd_render_h #endif//__snd_render_h

View file

@ -69,6 +69,7 @@ vec3_t listener_up;
vec_t sound_nominal_clip_dist = 1000.0; vec_t sound_nominal_clip_dist = 1000.0;
int soundtime; // sample PAIRS int soundtime; // sample PAIRS
int sound_delta;
#define MAX_SFX 512 #define MAX_SFX 512
sfx_t *known_sfx; // hunk allocated [MAX_SFX] sfx_t *known_sfx; // hunk allocated [MAX_SFX]
@ -553,7 +554,9 @@ SND_GetSoundtime (void)
} }
oldsamplepos = samplepos; oldsamplepos = samplepos;
sound_delta = soundtime;
soundtime = buffers * fullsamples + samplepos / shm->channels; soundtime = buffers * fullsamples + samplepos / shm->channels;
sound_delta = soundtime - sound_delta;
} }
static void static void

View file

@ -220,6 +220,9 @@ SND_PaintChannels (int endtime)
} }
} }
if (sc->advance)
sc->advance (sc, sound_delta);
if (ch->sfx) if (ch->sfx)
ch->sfx->release (ch->sfx); ch->sfx->release (ch->sfx);
} }
@ -246,12 +249,13 @@ SND_InitScaletable (void)
snd_scaletable[i][j] = ((signed char) j) * i * 8; snd_scaletable[i][j] = ((signed char) j) * i * 8;
} }
void static void
SND_PaintChannelFrom8 (channel_t *ch, sfxbuffer_t *sc, int count) snd_paint_mono_8 (int offs, channel_t *ch, void *bytes, int count)
{ {
unsigned char *sfx; unsigned char *sfx;
int data, i; int data, i;
int *lscale, *rscale; int *lscale, *rscale;
portable_samplepair_t *pair;
if (ch->leftvol > 255) if (ch->leftvol > 255)
ch->leftvol = 255; ch->leftvol = 255;
@ -260,24 +264,25 @@ SND_PaintChannelFrom8 (channel_t *ch, sfxbuffer_t *sc, int count)
lscale = snd_scaletable[ch->leftvol >> 3]; lscale = snd_scaletable[ch->leftvol >> 3];
rscale = snd_scaletable[ch->rightvol >> 3]; rscale = snd_scaletable[ch->rightvol >> 3];
sfx = (signed char *) sc->data + ch->pos; sfx = (signed char *) bytes;
pair = paintbuffer + offs;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
data = sfx[i]; data = sfx[i];
paintbuffer[i].left += lscale[data]; pair[i].left += lscale[data];
paintbuffer[i].right += rscale[data]; pair[i].right += rscale[data];
} }
ch->pos += count;
} }
void static void
SND_PaintChannelFrom16 (channel_t *ch, sfxbuffer_t *sc, int count) snd_paint_mono_16 (int offs, channel_t *ch, void *bytes, int count)
{ {
int leftvol, rightvol; int leftvol, rightvol;
unsigned int left_phase, right_phase; // Never allowed < 0 anyway unsigned int left_phase, right_phase; // Never allowed < 0 anyway
unsigned int i = 0; unsigned int i = 0;
signed short *sfx; signed short *sfx;
portable_samplepair_t *pair;
leftvol = ch->leftvol; leftvol = ch->leftvol;
rightvol = ch->rightvol; rightvol = ch->rightvol;
@ -285,8 +290,9 @@ SND_PaintChannelFrom16 (channel_t *ch, sfxbuffer_t *sc, int count)
max_overpaint = max (abs (ch->phase), max_overpaint = max (abs (ch->phase),
max (abs (ch->oldphase), max_overpaint)); max (abs (ch->oldphase), max_overpaint));
sfx = (signed short *) sc->data + ch->pos; sfx = (signed short *) bytes;
ch->pos += count;
pair = paintbuffer + offs;
if (ch->phase >= 0) { if (ch->phase >= 0) {
left_phase = ch->phase; left_phase = ch->phase;
@ -329,30 +335,30 @@ SND_PaintChannelFrom16 (channel_t *ch, sfxbuffer_t *sc, int count)
if (new_phase_left < old_phase_left) { if (new_phase_left < old_phase_left) {
if (!(count_left & 1)) { if (!(count_left & 1)) {
paintbuffer[i + old_phase_left].left += left; pair[i + old_phase_left].left += left;
old_phase_left--; old_phase_left--;
} }
count_left--; count_left--;
} else { } else {
if (new_phase_left > old_phase_left) { if (new_phase_left > old_phase_left) {
paintbuffer[i + old_phase_left].left += left; pair[i + old_phase_left].left += left;
old_phase_left++; old_phase_left++;
} }
paintbuffer[i + old_phase_left].left += left; pair[i + old_phase_left].left += left;
} }
if (new_phase_right < old_phase_right) { if (new_phase_right < old_phase_right) {
if (!(count_right & 1)) { if (!(count_right & 1)) {
paintbuffer[i + old_phase_right].right += right; pair[i + old_phase_right].right += right;
old_phase_right--; old_phase_right--;
} }
count_right--; count_right--;
} else { } else {
if (new_phase_right > old_phase_right) { if (new_phase_right > old_phase_right) {
paintbuffer[i + old_phase_right].right += right; pair[i + old_phase_right].right += right;
old_phase_right++; old_phase_right++;
} }
paintbuffer[i + old_phase_right].right += right; pair[i + old_phase_right].right += right;
} }
c--; c--;
@ -361,13 +367,13 @@ SND_PaintChannelFrom16 (channel_t *ch, sfxbuffer_t *sc, int count)
} }
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
paintbuffer[i + left_phase].left += (sfx[i] * leftvol) >> 8; pair[i + left_phase].left += (sfx[i] * leftvol) >> 8;
paintbuffer[i + right_phase].right += (sfx[i] * rightvol) >> 8; pair[i + right_phase].right += (sfx[i] * rightvol) >> 8;
} }
} }
void static void
SND_PaintChannelStereo8 (channel_t *ch, sfxbuffer_t *sc, int count) snd_paint_stereo_8 (int offs, channel_t *ch, void *bytes, int count)
{ {
byte *samp; byte *samp;
portable_samplepair_t *pair; portable_samplepair_t *pair;
@ -381,8 +387,8 @@ SND_PaintChannelStereo8 (channel_t *ch, sfxbuffer_t *sc, int count)
lscale = snd_scaletable[ch->leftvol >> 3]; lscale = snd_scaletable[ch->leftvol >> 3];
rscale = snd_scaletable[ch->rightvol >> 3]; rscale = snd_scaletable[ch->rightvol >> 3];
samp = sc->data + ch->pos; samp = bytes;
pair = paintbuffer; pair = paintbuffer + offs;
while (count-- > 0) { while (count-- > 0) {
pair->left += lscale[*samp++]; pair->left += lscale[*samp++];
pair->right += rscale[*samp++]; pair->right += rscale[*samp++];
@ -390,19 +396,95 @@ SND_PaintChannelStereo8 (channel_t *ch, sfxbuffer_t *sc, int count)
} }
} }
void static void
SND_PaintChannelStereo16 (channel_t *ch, sfxbuffer_t *sc, int count) snd_paint_stereo_16 (int offs, channel_t *ch, void *bytes, int count)
{ {
short *samp; short *samp;
portable_samplepair_t *pair; portable_samplepair_t *pair;
int leftvol = ch->leftvol; int leftvol = ch->leftvol;
int rightvol = ch->rightvol; int rightvol = ch->rightvol;
samp = (short *) sc->data + ch->pos * 2; samp = (short *) bytes;
pair = paintbuffer; pair = paintbuffer + offs;
while (count-- > 0) { while (count-- > 0) {
pair->left += *samp++ * leftvol; pair->left += *samp++ * leftvol;
pair->right += *samp++ * rightvol; pair->right += *samp++ * rightvol;
pair++; pair++;
} }
} }
void
SND_PaintChannelFrom8 (channel_t *ch, sfxbuffer_t *sc, int count)
{
int pos;
byte *samps;
pos = (ch->pos - sc->pos + sc->tail) % sc->length;
samps = sc->data + pos;
if (pos + count > sc->length) {
int sub = sc->length - pos;
snd_paint_mono_8 (0, ch, samps, sub);
snd_paint_mono_8 (sub, ch, samps, count - sub);
} else {
snd_paint_mono_8 (0, ch, samps, count);
}
ch->pos += count;
}
void
SND_PaintChannelFrom16 (channel_t *ch, sfxbuffer_t *sc, int count)
{
int pos;
short *samps;
pos = (ch->pos - sc->pos + sc->tail) % sc->length;
samps = (short *) sc->data + pos;
if (pos + count > sc->length) {
int sub = sc->length - pos;
snd_paint_mono_16 (0, ch, samps, sub);
snd_paint_mono_16 (sub, ch, samps, count - sub);
} else {
snd_paint_mono_16 (0, ch, samps, count);
}
ch->pos += count;
}
void
SND_PaintChannelStereo8 (channel_t *ch, sfxbuffer_t *sc, int count)
{
int pos;
short *samps;
pos = (ch->pos - sc->pos + sc->tail) % sc->length;
samps = (short *) sc->data + pos;
if (pos + count > sc->length) {
int sub = sc->length - pos;
snd_paint_stereo_8 (0, ch, samps, sub);
snd_paint_stereo_8 (sub, ch, samps, count - sub);
} else {
snd_paint_stereo_8 (0, ch, samps, count);
}
ch->pos += count;
}
void
SND_PaintChannelStereo16 (channel_t *ch, sfxbuffer_t *sc, int count)
{
int pos;
int *samps;
pos = (ch->pos - sc->pos + sc->tail) % sc->length;
samps = (int *) sc->data + pos;
if (pos + count > sc->length) {
int sub = sc->length - pos;
snd_paint_stereo_16 (0, ch, samps, sub);
snd_paint_stereo_16 (sub, ch, samps, count - sub);
} else {
snd_paint_stereo_16 (0, ch, samps, count);
}
ch->pos += count;
}

View file

@ -55,11 +55,11 @@
#define sc 8+16 #define sc 8+16
#define count 12+16 #define count 12+16
.globl C(SND_PaintChannelFrom8) .globl C(NOT_SND_PaintChannelFrom8)
#ifdef PIC #ifdef PIC
.type C(SND_PaintChannelFrom8),@function .type C(NOT_SND_PaintChannelFrom8),@function
#endif #endif
C(SND_PaintChannelFrom8): C(NOT_SND_PaintChannelFrom8):
pushl %esi // preserve register variables pushl %esi // preserve register variables
pushl %edi pushl %edi
pushl %ebx pushl %ebx
@ -179,7 +179,7 @@ LDone:
ret ret
#ifdef PIC #ifdef PIC
.Lfe1: .Lfe1:
.size C(SND_PaintChannelFrom8),.Lfe1-C(SND_PaintChannelFrom8) .size C(NOT_SND_PaintChannelFrom8),.Lfe1-C(NOT_SND_PaintChannelFrom8)
#endif #endif
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View file

@ -294,7 +294,7 @@ SND_LoadOgg (QFile *file, sfx_t *sfx, char *realname)
Sys_Printf ("unsupported number of channels"); Sys_Printf ("unsupported number of channels");
return; return;
} }
if (info.samples / info.rate < 30) { if (info.samples / info.rate < 3) {
printf ("cache %s\n", realname); printf ("cache %s\n", realname);
vorbis_cache (sfx, realname, &vf, info); vorbis_cache (sfx, realname, &vf, info);
} else { } else {

View file

@ -260,7 +260,7 @@ SND_LoadWav (QFile *file, sfx_t *sfx, char *realname)
return; return;
} }
if (info.samples / info.rate < 30) { if (info.samples / info.rate < 3) {
printf ("cache %s\n", realname); printf ("cache %s\n", realname);
wav_cache (sfx, realname, file, info); wav_cache (sfx, realname, file, info);
} else { } else {