attempt to fix choppy audio in alsa caused by non-power-of 2 buffer size

This commit is contained in:
Bill Currie 2005-06-14 05:37:26 +00:00
parent 4a8bc0a4c4
commit 76305e7e6b
2 changed files with 22 additions and 0 deletions

View file

@ -45,6 +45,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))
#else
QF_ALSA_NEED (int, snd_pcm_hw_params_get_buffer_size, (const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val))
QF_ALSA_NEED (int, snd_pcm_hw_params_set_buffer_size, (snd_pcm_t *pcm, const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val))
QF_ALSA_NEED (int, snd_pcm_hw_params_get_period_size, (const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *frames, int *dir))
QF_ALSA_NEED (int, snd_pcm_hw_params_set_access, (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t access))
QF_ALSA_NEED (int, snd_pcm_hw_params_set_period_size_near, (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir))

View file

@ -106,6 +106,18 @@ SNDDMA_Init_Cvars (void)
static int SNDDMA_GetDMAPos (void);
static snd_pcm_uframes_t
round_buffer_size (snd_pcm_uframes_t sz)
{
snd_pcm_uframes_t mask = ~0;
while (sz & mask) {
sz &= mask;
mask <<= 1;
}
return sz;
}
static volatile dma_t *
SNDDMA_Init (void)
{
@ -325,6 +337,15 @@ SNDDMA_Init (void)
qfsnd_strerror (err));
goto error;
}
if (buffer_size != round_buffer_size (buffer_size)) {
buffer_size = round_buffer_size (buffer_size);
err = qfsnd_pcm_hw_params_set_buffer_size (pcm, hw, &buffer_size);
if (0 > err) {
Sys_Printf ("ALSA: unable to set buffer size. %s\n",
qfsnd_strerror (err));
goto error;
}
}
sn.samples = buffer_size * sn.channels; // mono samples in buffer
sn.speed = rate;