get the new sound system mostly working. just getting a bogus read count

in the stream reader at the moment, otherwise it's working wonderfully :)
This commit is contained in:
Bill Currie 2003-04-15 02:34:17 +00:00
parent dfff6bcdb7
commit da44c783fb
8 changed files with 51 additions and 17 deletions

View file

@ -46,6 +46,7 @@ QF_ALSA_NEED (snd_pcm_uframes_t, snd_pcm_hw_params_set_period_size_near, (snd_pc
QF_ALSA_NEED (unsigned int, snd_pcm_hw_params_set_rate_near, (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int *dir)) QF_ALSA_NEED (unsigned int, snd_pcm_hw_params_set_rate_near, (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int *dir))
QF_ALSA_NEED (size_t, snd_pcm_hw_params_sizeof, (void)) QF_ALSA_NEED (size_t, snd_pcm_hw_params_sizeof, (void))
QF_ALSA_NEED (int, snd_pcm_mmap_begin, (snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas, snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames)) QF_ALSA_NEED (int, snd_pcm_mmap_begin, (snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas, snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames))
QF_ALSA_NEED (int, snd_pcm_avail_update, (snd_pcm_t *pcm))
QF_ALSA_NEED (snd_pcm_sframes_t, snd_pcm_mmap_commit, (snd_pcm_t *pcm, snd_pcm_uframes_t offset, snd_pcm_uframes_t frames)) QF_ALSA_NEED (snd_pcm_sframes_t, snd_pcm_mmap_commit, (snd_pcm_t *pcm, snd_pcm_uframes_t offset, snd_pcm_uframes_t frames))
QF_ALSA_NEED (int, snd_pcm_open, (snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode)) QF_ALSA_NEED (int, snd_pcm_open, (snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode))
QF_ALSA_NEED (int, snd_pcm_pause, (snd_pcm_t *pcm, int enable)) QF_ALSA_NEED (int, snd_pcm_pause, (snd_pcm_t *pcm, int enable))

View file

@ -529,11 +529,14 @@ SND_UpdateAmbientSounds (void)
} }
} }
extern double realtime;
static void static void
SND_GetSoundtime (void) SND_GetSoundtime (void)
{ {
int fullsamples, samplepos; int fullsamples, samplepos;
static int buffers, oldsamplepos; static int buffers, oldsamplepos;
static double oldrealtime;
fullsamples = shm->samples / shm->channels; fullsamples = shm->samples / shm->channels;
@ -557,6 +560,9 @@ SND_GetSoundtime (void)
sound_delta = soundtime; sound_delta = soundtime;
soundtime = buffers * fullsamples + samplepos / shm->channels; soundtime = buffers * fullsamples + samplepos / shm->channels;
sound_delta = soundtime - sound_delta; sound_delta = soundtime - sound_delta;
sound_delta = (int)((realtime - oldrealtime) * shm->speed);
oldrealtime = realtime;
} }
static void static void

View file

@ -116,6 +116,7 @@ read_samples (sfxbuffer_t *buffer, int count)
if (buffer->head + count > buffer->length) { if (buffer->head + count > buffer->length) {
count -= buffer->length - buffer->head; count -= buffer->length - buffer->head;
read_samples (buffer, buffer->length - buffer->head); read_samples (buffer, buffer->length - buffer->head);
read_samples (buffer, count);
} else { } else {
byte *data; byte *data;
float stepscale; float stepscale;
@ -124,6 +125,9 @@ read_samples (sfxbuffer_t *buffer, int count)
sfxstream_t *stream = (sfxstream_t *) sfx->data; sfxstream_t *stream = (sfxstream_t *) sfx->data;
wavinfo_t *info = &stream->wavinfo; wavinfo_t *info = &stream->wavinfo;
if (count <= 0)
Sys_Error ("read_samples: count <= 0");
stepscale = (float) info->rate / shm->speed; // usually 0.5, 1, or 2 stepscale = (float) info->rate / shm->speed; // usually 0.5, 1, or 2
samples = count * stepscale; samples = count * stepscale;
@ -162,6 +166,8 @@ SND_StreamAdvance (sfxbuffer_t *buffer, int count)
headpos = sfx->length; headpos = sfx->length;
else else
headpos -= sfx->length - sfx->loopstart; headpos -= sfx->length - sfx->loopstart;
if (headpos > sfx->length)
Sys_Error ("huh");
} }
if (samples < count) { if (samples < count) {
@ -261,6 +267,7 @@ SND_Load (sfx_t *sfx)
SND_LoadWav (file, sfx, realname); SND_LoadWav (file, sfx, realname);
return; return;
} }
Qclose (file);
free (realname); free (realname);
} }
@ -327,6 +334,9 @@ SND_ResampleMono (sfxbuffer_t *sc, byte *data, int length)
sc->paint = SND_PaintChannelFrom16; sc->paint = SND_PaintChannelFrom16;
} }
if (!length)
return;
// resample / decimate to the current source rate // resample / decimate to the current source rate
if (stepscale == 1) { if (stepscale == 1) {
if (inwidth == 1 && outwidth == 1) { if (inwidth == 1 && outwidth == 1) {
@ -443,6 +453,9 @@ SND_ResampleStereo (sfxbuffer_t *sc, byte *data, int length)
sc->paint = SND_PaintChannelStereo16; sc->paint = SND_PaintChannelStereo16;
} }
if (!length)
return;
// resample / decimate to the current source rate // resample / decimate to the current source rate
if (stepscale == 1) { if (stepscale == 1) {
if (inwidth == 1 && outwidth == 1) { if (inwidth == 1 && outwidth == 1) {
@ -533,4 +546,10 @@ SND_ResampleStereo (sfxbuffer_t *sc, byte *data, int length)
} }
} }
} }
{
byte *x = sc->data + sc->length * outwidth * 2;
if (memcmp (x, "\xde\xad\xbe\xef", 4))
Sys_Error ("SND_ResampleMono screwed the pooch %02x%02x%02x%02x",
x[0], x[1], x[2], x[3]);
}
} }

View file

@ -207,6 +207,10 @@ SND_PaintChannels (int endtime)
ltime += count; ltime += count;
} }
if (sc->advance)
sc->advance (sc, count);
// if at end of loop, restart // if at end of loop, restart
if (ltime >= ch->end) { if (ltime >= ch->end) {
if (ch->sfx->loopstart >= 0) { if (ch->sfx->loopstart >= 0) {
@ -220,9 +224,6 @@ 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);
} }
@ -407,8 +408,8 @@ snd_paint_stereo_16 (int offs, channel_t *ch, void *bytes, int count)
samp = (short *) bytes; samp = (short *) bytes;
pair = paintbuffer + offs; pair = paintbuffer + offs;
while (count-- > 0) { while (count-- > 0) {
pair->left += *samp++ * leftvol; pair->left += (*samp++ * leftvol) >> 8;
pair->right += *samp++ * rightvol; pair->right += (*samp++ * rightvol) >> 8;
pair++; pair++;
} }
} }
@ -425,7 +426,7 @@ SND_PaintChannelFrom8 (channel_t *ch, sfxbuffer_t *sc, int count)
if (pos + count > sc->length) { if (pos + count > sc->length) {
int sub = sc->length - pos; int sub = sc->length - pos;
snd_paint_mono_8 (0, ch, samps, sub); snd_paint_mono_8 (0, ch, samps, sub);
snd_paint_mono_8 (sub, ch, samps, count - sub); snd_paint_mono_8 (sub, ch, sc->data, count - sub);
} else { } else {
snd_paint_mono_8 (0, ch, samps, count); snd_paint_mono_8 (0, ch, samps, count);
} }
@ -444,7 +445,7 @@ SND_PaintChannelFrom16 (channel_t *ch, sfxbuffer_t *sc, int count)
if (pos + count > sc->length) { if (pos + count > sc->length) {
int sub = sc->length - pos; int sub = sc->length - pos;
snd_paint_mono_16 (0, ch, samps, sub); snd_paint_mono_16 (0, ch, samps, sub);
snd_paint_mono_16 (sub, ch, samps, count - sub); snd_paint_mono_16 (sub, ch, sc->data, count - sub);
} else { } else {
snd_paint_mono_16 (0, ch, samps, count); snd_paint_mono_16 (0, ch, samps, count);
} }
@ -463,7 +464,7 @@ SND_PaintChannelStereo8 (channel_t *ch, sfxbuffer_t *sc, int count)
if (pos + count > sc->length) { if (pos + count > sc->length) {
int sub = sc->length - pos; int sub = sc->length - pos;
snd_paint_stereo_8 (0, ch, samps, sub); snd_paint_stereo_8 (0, ch, samps, sub);
snd_paint_stereo_8 (sub, ch, samps, count - sub); snd_paint_stereo_8 (sub, ch, sc->data, count - sub);
} else { } else {
snd_paint_stereo_8 (0, ch, samps, count); snd_paint_stereo_8 (0, ch, samps, count);
} }
@ -482,7 +483,7 @@ SND_PaintChannelStereo16 (channel_t *ch, sfxbuffer_t *sc, int count)
if (pos + count > sc->length) { if (pos + count > sc->length) {
int sub = sc->length - pos; int sub = sc->length - pos;
snd_paint_stereo_16 (0, ch, samps, sub); snd_paint_stereo_16 (0, ch, samps, sub);
snd_paint_stereo_16 (sub, ch, samps, count - sub); snd_paint_stereo_16 (sub, ch, sc->data, count - sub);
} else { } else {
snd_paint_stereo_16 (0, ch, samps, count); snd_paint_stereo_16 (0, ch, samps, count);
} }

View file

@ -275,6 +275,9 @@ vorbis_stream (sfx_t *sfx, char *realname, OggVorbis_File *vf, wavinfo_t info)
stream->buffer.advance = SND_StreamAdvance; stream->buffer.advance = SND_StreamAdvance;
stream->buffer.sfx = sfx; stream->buffer.sfx = sfx;
stream->resample (&stream->buffer, 0, 0); // get sfx setup properly
stream->seek (stream->file, 0, &stream->wavinfo);
stream->buffer.advance (&stream->buffer, 0); stream->buffer.advance (&stream->buffer, 0);
} }
@ -296,10 +299,10 @@ SND_LoadOgg (QFile *file, sfx_t *sfx, char *realname)
return; return;
} }
if (info.samples / info.rate < 3) { if (info.samples / info.rate < 3) {
printf ("cache %s\n", realname); Sys_DPrintf ("cache %s\n", realname);
vorbis_cache (sfx, realname, &vf, info); vorbis_cache (sfx, realname, &vf, info);
} else { } else {
printf ("stream %s\n", realname); Sys_DPrintf ("stream %s\n", realname);
vorbis_stream (sfx, realname, &vf, info); vorbis_stream (sfx, realname, &vf, info);
} }
} }

View file

@ -145,6 +145,9 @@ wav_stream (sfx_t *sfx, char *realname, void *file, wavinfo_t info)
stream->buffer.advance = SND_StreamAdvance; stream->buffer.advance = SND_StreamAdvance;
stream->buffer.sfx = sfx; stream->buffer.sfx = sfx;
stream->resample (&stream->buffer, 0, 0); // get sfx setup properly
stream->seek (stream->file, 0, &stream->wavinfo);
stream->buffer.advance (&stream->buffer, 0); stream->buffer.advance (&stream->buffer, 0);
} }
@ -236,10 +239,10 @@ get_info (QFile *file)
if (dltxt) if (dltxt)
info.samples = info.loopstart + dltxt->len; info.samples = info.loopstart + dltxt->len;
else else
info.samples = data->ck.len / info.width; info.samples = data->ck.len / (info.width * info.channels);
} else { } else {
info.loopstart = -1; info.loopstart = -1;
info.samples = data->ck.len / info.width; info.samples = data->ck.len / (info.width * info.channels);
} }
info.dataofs = *(int *)data->data; info.dataofs = *(int *)data->data;
info.datalen = data->ck.len; info.datalen = data->ck.len;
@ -261,10 +264,10 @@ SND_LoadWav (QFile *file, sfx_t *sfx, char *realname)
} }
if (info.samples / info.rate < 3) { if (info.samples / info.rate < 3) {
printf ("cache %s\n", realname); Sys_DPrintf ("cache %s\n", realname);
wav_cache (sfx, realname, file, info); wav_cache (sfx, realname, file, info);
} else { } else {
printf ("stream %s\n", realname); Sys_DPrintf ("stream %s\n", realname);
wav_stream (sfx, realname, file, info); wav_stream (sfx, realname, file, info);
} }
} }

View file

@ -238,8 +238,8 @@ S_EndPrecaching (void)
void void
S_ExtraUpdate (void) S_ExtraUpdate (void)
{ {
if (snd_render_funcs) //if (snd_render_funcs)
snd_render_funcs->pS_ExtraUpdate (); // snd_render_funcs->pS_ExtraUpdate ();
} }
void void

View file

@ -291,6 +291,7 @@ SNDDMA_GetDMAPos (void)
if (!snd_inited) if (!snd_inited)
return 0; return 0;
qfsnd_pcm_avail_update (pcm);
qfsnd_pcm_mmap_begin (pcm, &areas, &offset, &nframes); qfsnd_pcm_mmap_begin (pcm, &areas, &offset, &nframes);
offset *= shm->channels; offset *= shm->channels;
nframes *= shm->channels; nframes *= shm->channels;