diff options
author | Chris Robinson <[email protected]> | 2009-05-26 10:03:17 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2009-05-26 10:03:17 -0700 |
commit | e01cd92d561ab9a11238d296ff8aaf852dff1ec6 (patch) | |
tree | 45d2e5c0f6c9c04edc362e6ed842ff7abd688354 /Alc | |
parent | 923af8c3a6626a43f7564afe0de61fcd55f2fce1 (diff) |
Set avail_min so snd_pcm_wait will wait for the full update to be ready
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/alsa.c | 37 |
1 files changed, 33 insertions, 4 deletions
@@ -74,6 +74,11 @@ MAKE_FUNC(snd_pcm_hw_params_get_buffer_size); MAKE_FUNC(snd_pcm_hw_params_get_period_size); MAKE_FUNC(snd_pcm_hw_params_get_access); MAKE_FUNC(snd_pcm_hw_params); +MAKE_FUNC(snd_pcm_sw_params_malloc); +MAKE_FUNC(snd_pcm_sw_params_current); +MAKE_FUNC(snd_pcm_sw_params_set_avail_min); +MAKE_FUNC(snd_pcm_sw_params); +MAKE_FUNC(snd_pcm_sw_params_free); MAKE_FUNC(snd_pcm_prepare); MAKE_FUNC(snd_pcm_start); MAKE_FUNC(snd_pcm_resume); @@ -177,7 +182,7 @@ static ALuint ALSAProc(ALvoid *ptr) } // make sure there's frames to process - if(avail < (snd_pcm_sframes_t)pDevice->UpdateSize) + if(avail >= 0 && avail < (snd_pcm_sframes_t)pDevice->UpdateSize) { if(state != SND_PCM_STATE_RUNNING) { @@ -190,10 +195,8 @@ static ALuint ALSAProc(ALvoid *ptr) break; } } - else if(avail == 0 && psnd_pcm_wait(data->pcmHandle, 1000) == 0) + else if(psnd_pcm_wait(data->pcmHandle, 1000) == 0) AL_PRINT("Wait timeout... buffer size too low?\n"); - else if(avail != 0) - Sleep(1); continue; } avail = pDevice->UpdateSize; @@ -320,6 +323,7 @@ static ALuint ALSANoMMapCaptureProc(ALvoid *ptr) static ALCboolean alsa_open_playback(ALCdevice *device, const ALCchar *deviceName) { snd_pcm_uframes_t bufferSizeInFrames; + snd_pcm_sw_params_t *sp = NULL; snd_pcm_hw_params_t *p = NULL; snd_pcm_access_t access; unsigned int periods; @@ -464,6 +468,26 @@ open_alsa: psnd_pcm_hw_params_free(p); + err = NULL; + psnd_pcm_sw_params_malloc(&sp); + + if((i=psnd_pcm_sw_params_current(data->pcmHandle, sp)) != 0) + err = "sw current"; + if(err == NULL && (i=psnd_pcm_sw_params_set_avail_min(data->pcmHandle, sp, bufferSizeInFrames)) != 0) + err = "sw set avail min"; + if(err == NULL && (i=psnd_pcm_sw_params(data->pcmHandle, sp)) != 0) + err = "sw set params"; + if(err != NULL) + { + AL_PRINT("%s failed: %s\n", err, psnd_strerror(i)); + psnd_pcm_sw_params_free(sp); + psnd_pcm_close(data->pcmHandle); + free(data); + return ALC_FALSE; + } + + psnd_pcm_sw_params_free(sp); + data->size = psnd_pcm_frames_to_bytes(data->pcmHandle, device->UpdateSize); if(access == SND_PCM_ACCESS_RW_INTERLEAVED) { @@ -960,6 +984,11 @@ LOAD_FUNC(snd_pcm_hw_params_get_buffer_size); LOAD_FUNC(snd_pcm_hw_params_get_period_size); LOAD_FUNC(snd_pcm_hw_params_get_access); LOAD_FUNC(snd_pcm_hw_params); +LOAD_FUNC(snd_pcm_sw_params_malloc); +LOAD_FUNC(snd_pcm_sw_params_current); +LOAD_FUNC(snd_pcm_sw_params_set_avail_min); +LOAD_FUNC(snd_pcm_sw_params); +LOAD_FUNC(snd_pcm_sw_params_free); LOAD_FUNC(snd_pcm_prepare); LOAD_FUNC(snd_pcm_start); LOAD_FUNC(snd_pcm_resume); |