mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
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:
parent
dfff6bcdb7
commit
da44c783fb
8 changed files with 51 additions and 17 deletions
|
@ -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 (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_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 (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))
|
||||
|
|
|
@ -529,11 +529,14 @@ SND_UpdateAmbientSounds (void)
|
|||
}
|
||||
}
|
||||
|
||||
extern double realtime;
|
||||
|
||||
static void
|
||||
SND_GetSoundtime (void)
|
||||
{
|
||||
int fullsamples, samplepos;
|
||||
static int buffers, oldsamplepos;
|
||||
static double oldrealtime;
|
||||
|
||||
fullsamples = shm->samples / shm->channels;
|
||||
|
||||
|
@ -557,6 +560,9 @@ SND_GetSoundtime (void)
|
|||
sound_delta = soundtime;
|
||||
soundtime = buffers * fullsamples + samplepos / shm->channels;
|
||||
sound_delta = soundtime - sound_delta;
|
||||
|
||||
sound_delta = (int)((realtime - oldrealtime) * shm->speed);
|
||||
oldrealtime = realtime;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -116,6 +116,7 @@ read_samples (sfxbuffer_t *buffer, int count)
|
|||
if (buffer->head + count > buffer->length) {
|
||||
count -= buffer->length - buffer->head;
|
||||
read_samples (buffer, buffer->length - buffer->head);
|
||||
read_samples (buffer, count);
|
||||
} else {
|
||||
byte *data;
|
||||
float stepscale;
|
||||
|
@ -124,6 +125,9 @@ read_samples (sfxbuffer_t *buffer, int count)
|
|||
sfxstream_t *stream = (sfxstream_t *) sfx->data;
|
||||
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
|
||||
|
||||
samples = count * stepscale;
|
||||
|
@ -162,6 +166,8 @@ SND_StreamAdvance (sfxbuffer_t *buffer, int count)
|
|||
headpos = sfx->length;
|
||||
else
|
||||
headpos -= sfx->length - sfx->loopstart;
|
||||
if (headpos > sfx->length)
|
||||
Sys_Error ("huh");
|
||||
}
|
||||
|
||||
if (samples < count) {
|
||||
|
@ -261,6 +267,7 @@ SND_Load (sfx_t *sfx)
|
|||
SND_LoadWav (file, sfx, realname);
|
||||
return;
|
||||
}
|
||||
Qclose (file);
|
||||
free (realname);
|
||||
}
|
||||
|
||||
|
@ -327,6 +334,9 @@ SND_ResampleMono (sfxbuffer_t *sc, byte *data, int length)
|
|||
sc->paint = SND_PaintChannelFrom16;
|
||||
}
|
||||
|
||||
if (!length)
|
||||
return;
|
||||
|
||||
// resample / decimate to the current source rate
|
||||
if (stepscale == 1) {
|
||||
if (inwidth == 1 && outwidth == 1) {
|
||||
|
@ -443,6 +453,9 @@ SND_ResampleStereo (sfxbuffer_t *sc, byte *data, int length)
|
|||
sc->paint = SND_PaintChannelStereo16;
|
||||
}
|
||||
|
||||
if (!length)
|
||||
return;
|
||||
|
||||
// resample / decimate to the current source rate
|
||||
if (stepscale == 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]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -207,6 +207,10 @@ SND_PaintChannels (int endtime)
|
|||
|
||||
ltime += count;
|
||||
}
|
||||
|
||||
if (sc->advance)
|
||||
sc->advance (sc, count);
|
||||
|
||||
// if at end of loop, restart
|
||||
if (ltime >= ch->end) {
|
||||
if (ch->sfx->loopstart >= 0) {
|
||||
|
@ -220,9 +224,6 @@ SND_PaintChannels (int endtime)
|
|||
}
|
||||
}
|
||||
|
||||
if (sc->advance)
|
||||
sc->advance (sc, sound_delta);
|
||||
|
||||
if (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;
|
||||
pair = paintbuffer + offs;
|
||||
while (count-- > 0) {
|
||||
pair->left += *samp++ * leftvol;
|
||||
pair->right += *samp++ * rightvol;
|
||||
pair->left += (*samp++ * leftvol) >> 8;
|
||||
pair->right += (*samp++ * rightvol) >> 8;
|
||||
pair++;
|
||||
}
|
||||
}
|
||||
|
@ -425,7 +426,7 @@ 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, samps, count - sub);
|
||||
snd_paint_mono_8 (sub, ch, sc->data, count - sub);
|
||||
} else {
|
||||
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) {
|
||||
int sub = sc->length - pos;
|
||||
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 {
|
||||
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) {
|
||||
int sub = sc->length - pos;
|
||||
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 {
|
||||
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) {
|
||||
int sub = sc->length - pos;
|
||||
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 {
|
||||
snd_paint_stereo_16 (0, ch, samps, count);
|
||||
}
|
||||
|
|
|
@ -275,6 +275,9 @@ vorbis_stream (sfx_t *sfx, char *realname, OggVorbis_File *vf, wavinfo_t info)
|
|||
stream->buffer.advance = SND_StreamAdvance;
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -296,10 +299,10 @@ SND_LoadOgg (QFile *file, sfx_t *sfx, char *realname)
|
|||
return;
|
||||
}
|
||||
if (info.samples / info.rate < 3) {
|
||||
printf ("cache %s\n", realname);
|
||||
Sys_DPrintf ("cache %s\n", realname);
|
||||
vorbis_cache (sfx, realname, &vf, info);
|
||||
} else {
|
||||
printf ("stream %s\n", realname);
|
||||
Sys_DPrintf ("stream %s\n", realname);
|
||||
vorbis_stream (sfx, realname, &vf, info);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,6 +145,9 @@ wav_stream (sfx_t *sfx, char *realname, void *file, wavinfo_t info)
|
|||
stream->buffer.advance = SND_StreamAdvance;
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -236,10 +239,10 @@ get_info (QFile *file)
|
|||
if (dltxt)
|
||||
info.samples = info.loopstart + dltxt->len;
|
||||
else
|
||||
info.samples = data->ck.len / info.width;
|
||||
info.samples = data->ck.len / (info.width * info.channels);
|
||||
} else {
|
||||
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.datalen = data->ck.len;
|
||||
|
@ -261,10 +264,10 @@ SND_LoadWav (QFile *file, sfx_t *sfx, char *realname)
|
|||
}
|
||||
|
||||
if (info.samples / info.rate < 3) {
|
||||
printf ("cache %s\n", realname);
|
||||
Sys_DPrintf ("cache %s\n", realname);
|
||||
wav_cache (sfx, realname, file, info);
|
||||
} else {
|
||||
printf ("stream %s\n", realname);
|
||||
Sys_DPrintf ("stream %s\n", realname);
|
||||
wav_stream (sfx, realname, file, info);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -238,8 +238,8 @@ S_EndPrecaching (void)
|
|||
void
|
||||
S_ExtraUpdate (void)
|
||||
{
|
||||
if (snd_render_funcs)
|
||||
snd_render_funcs->pS_ExtraUpdate ();
|
||||
//if (snd_render_funcs)
|
||||
// snd_render_funcs->pS_ExtraUpdate ();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -291,6 +291,7 @@ SNDDMA_GetDMAPos (void)
|
|||
if (!snd_inited)
|
||||
return 0;
|
||||
|
||||
qfsnd_pcm_avail_update (pcm);
|
||||
qfsnd_pcm_mmap_begin (pcm, &areas, &offset, &nframes);
|
||||
offset *= shm->channels;
|
||||
nframes *= shm->channels;
|
||||
|
|
Loading…
Reference in a new issue