aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2010-01-20 01:19:32 -0800
committerChris Robinson <[email protected]>2010-01-20 01:19:32 -0800
commit11d7a0e394b6ec4fcc23b73800fbe7eb0bb8bc70 (patch)
tree3a99ec83e4fbb70b323d88b4a34be4e469f9e613
parent3ad86a1c1b592579514d07495f5feac97c3a8131 (diff)
Specify the buffer size to ALSA, so the period count remains flexible
Under conditions where the period size is fixed (such as dmix), ALSA will still attempt to provide the requested number of periods even if the requested period size needs to be dramatically altered. In these cases, it would be better to increase or decrease the period count, instead of growing or shrinking the total buffer size and significantly changing the latency.
-rw-r--r--Alc/alsa.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/Alc/alsa.c b/Alc/alsa.c
index b0b35305..b56d0537 100644
--- a/Alc/alsa.c
+++ b/Alc/alsa.c
@@ -510,6 +510,7 @@ static ALCboolean alsa_reset_playback(ALCdevice *device)
{
alsa_data *data = (alsa_data*)device->ExtraData;
snd_pcm_uframes_t periodSizeInFrames;
+ snd_pcm_uframes_t bufferSizeInFrames;
snd_pcm_sw_params_t *sp = NULL;
snd_pcm_hw_params_t *p = NULL;
snd_pcm_access_t access;
@@ -614,12 +615,13 @@ static ALCboolean alsa_reset_playback(ALCdevice *device)
err = "set channels";
}
}
- /* set periods (implicitly constrains period/buffer parameters) */
- if(i >= 0 && (i=psnd_pcm_hw_params_set_periods_near(data->pcmHandle, p, &periods, NULL)) < 0)
- err = "set periods near";
/* set rate (implicitly constrains period/buffer parameters) */
if(i >= 0 && (i=psnd_pcm_hw_params_set_rate_near(data->pcmHandle, p, &rate, NULL)) < 0)
err = "set rate near";
+ /* set buffer size (implicitly constrains period/buffer parameters) */
+ bufferSizeInFrames = periodSizeInFrames * periods;
+ if(i >= 0 && (i=psnd_pcm_hw_params_set_buffer_size_near(data->pcmHandle, p, &bufferSizeInFrames)) < 0)
+ err = "set buffer size near";
/* set period size in frame units (implicitly sets buffer size/bytes/time and period time/bytes) */
if(i >= 0 && (i=psnd_pcm_hw_params_set_period_size_near(data->pcmHandle, p, &periodSizeInFrames, NULL)) < 0)
err = "set period size near";