X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/2e9ba080dd30434f3e8f88e63029280889586a32..063854700ea54b4fd277e945ee256c33d103f72d:/lib/uaudio-alsa.c diff --git a/lib/uaudio-alsa.c b/lib/uaudio-alsa.c index ff85c08..3ae056e 100644 --- a/lib/uaudio-alsa.c +++ b/lib/uaudio-alsa.c @@ -1,6 +1,6 @@ /* * This file is part of DisOrder. - * Copyright (C) 2009 Richard Kettlewell + * Copyright (C) 2009, 2013 Richard Kettlewell * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -84,7 +84,7 @@ static size_t alsa_play(void *buffer, size_t samples, unsigned flags) { switch(rc) { case -EPIPE: if((err = snd_pcm_prepare(alsa_pcm))) - fatal(0, "error calling snd_pcm_prepare: %d", err); + disorder_fatal(0, "error calling snd_pcm_prepare: %d", err); return 0; case -EAGAIN: return 0; @@ -105,6 +105,7 @@ static void alsa_open(void) { SND_PCM_STREAM_PLAYBACK, 0))) disorder_fatal(0, "error from snd_pcm_open: %d", err); + /* Hardware parameters */ snd_pcm_hw_params_t *hwparams; snd_pcm_hw_params_alloca(&hwparams); if((err = snd_pcm_hw_params_any(alsa_pcm, hwparams)) < 0) @@ -131,11 +132,20 @@ static void alsa_open(void) { uaudio_channels, err); if((err = snd_pcm_hw_params(alsa_pcm, hwparams)) < 0) disorder_fatal(0, "error calling snd_pcm_hw_params: %d", err); - + /* Software parameters */ + snd_pcm_sw_params_t *swparams; + snd_pcm_sw_params_alloca(&swparams); + if((err = snd_pcm_sw_params_current(alsa_pcm, swparams)) < 0) + disorder_fatal(-err, "error calling snd_pcm_sw_params_current"); + /* Bump the start threshold a bit since Pulseaudio sulks with the defaults */ + if((err = snd_pcm_sw_params_set_start_threshold(alsa_pcm, swparams, 1024)) < 0) + disorder_fatal(-err, "error calling snd_pcm_sw_params_set_start_threshold"); + if((err = snd_pcm_sw_params(alsa_pcm, swparams)) < 0) + disorder_fatal(-err, "error calling snd_pcm_sw_params"); } static void alsa_start(uaudio_callback *callback, - void *userdata) { + void *userdata) { if(uaudio_channels != 1 && uaudio_channels != 2) disorder_fatal(0, "asked for %d channels but only support 1 or 2", uaudio_channels); @@ -170,7 +180,7 @@ static void alsa_open_mixer(void) { snd_mixer_selem_id_t *id; const char *device = uaudio_get("device", "default"); const char *mixer = uaudio_get("mixer-control", "0"); - const char *channel = uaudio_get("mixer-channel", "PCM"); + const char *channel = uaudio_get("mixer-channel", "Master"); snd_mixer_selem_id_alloca(&id); if((err = snd_mixer_open(&alsa_mixer_handle, 0))) @@ -278,7 +288,8 @@ const struct uaudio uaudio_alsa = { .close_mixer = alsa_close_mixer, .get_volume = alsa_get_volume, .set_volume = alsa_set_volume, - .configure = alsa_configure + .configure = alsa_configure, + .flags = UAUDIO_API_CLIENT | UAUDIO_API_SERVER, }; #endif