From d72b9a3bfa4d15c0bf906cf3ad86bc921667b6b0 Mon Sep 17 00:00:00 2001 From: Christian Gmeiner Date: Thu, 24 Jun 2010 19:29:57 +0200 Subject: alsa: try to use mmap access type and fall back to slow write, if mmap not avaiable --- dxr3audio-alsa.c | 16 ++++++++++++---- dxr3audio-alsa.h | 2 ++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/dxr3audio-alsa.c b/dxr3audio-alsa.c index a946d2f..23af170 100644 --- a/dxr3audio-alsa.c +++ b/dxr3audio-alsa.c @@ -92,9 +92,17 @@ void cAudioAlsa::setup(int channels, int samplerate) } // set access type - err = snd_pcm_hw_params_set_access(handle, alsa_hwparams, SND_PCM_ACCESS_RW_INTERLEAVED); + pcm_write_func = &snd_pcm_mmap_writei; + err = snd_pcm_hw_params_set_access(handle, alsa_hwparams, SND_PCM_ACCESS_MMAP_INTERLEAVED); if (err < 0) { - esyslog("[dxr3-audio-alsa] Unable to set access type: %s", snd_strerror(err)); + esyslog("[dxr3-audio-alsa] mmap not available, attempting to fall back to slow writes"); + + pcm_write_func = &snd_pcm_writei; + err = snd_pcm_hw_params_set_access(handle, alsa_hwparams, SND_PCM_ACCESS_RW_INTERLEAVED); + if (err < 0) { + esyslog("[dxr3-audio-alsa] Unable to set access type: %s", snd_strerror(err)); + exit(-2); + } } // set format @@ -228,10 +236,10 @@ void cAudioAlsa::write(uchar* data, size_t size) snd_pcm_sframes_t res = 0; while (frames > 0) { - res = snd_pcm_writei(handle, output_samples, frames); + res = pcm_write_func(handle, output_samples, frames); if (res == -EAGAIN) { - snd_pcm_wait(handle, 500); + snd_pcm_wait(handle, 10); } else if (res == -EINTR) { // nothing to do res = 0; diff --git a/dxr3audio-alsa.h b/dxr3audio-alsa.h index c5eda3e..81588ab 100644 --- a/dxr3audio-alsa.h +++ b/dxr3audio-alsa.h @@ -44,6 +44,8 @@ private: snd_pcm_status_t *status; size_t bytesFrame; + snd_pcm_sframes_t (*pcm_write_func)(snd_pcm_t*, const void*, snd_pcm_uframes_t); + void Xrun(); }; -- cgit v1.2.3