From: Richard Kettlewell Date: Sun, 8 Mar 2009 14:01:44 +0000 (+0000) Subject: Merge configuration fixes X-Git-Tag: 5.0~178^2~8 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/67895023d60fc492720d2f575045ed0173948947?hp=-c Merge configuration fixes --- 67895023d60fc492720d2f575045ed0173948947 diff --combined lib/uaudio-alsa.c index 2236c91,14b2d2a..48ae1be --- a/lib/uaudio-alsa.c +++ b/lib/uaudio-alsa.c @@@ -26,6 -26,7 +26,7 @@@ #include "mem.h" #include "log.h" #include "uaudio.h" + #include "configuration.h" /** @brief The current PCM handle */ static snd_pcm_t *alsa_pcm; @@@ -149,11 -150,6 +150,11 @@@ static int to_percent(long n) return (n - alsa_mixer_min) * 100 / (alsa_mixer_max - alsa_mixer_min); } +/** @brief Convert a percentage to a level */ +static int from_percent(int n) { + return alsa_mixer_min + n * (alsa_mixer_max - alsa_mixer_min) / 100; +} + static void alsa_open_mixer(void) { int err; snd_mixer_selem_id_t *id; @@@ -164,8 -160,8 +165,8 @@@ snd_mixer_selem_id_alloca(&id); if((err = snd_mixer_open(&alsa_mixer_handle, 0))) fatal(0, "snd_mixer_open: %s", snd_strerror(err)); - if((err = snd_mixer_attach(alsa_mixer_handle, config->device))) - fatal(0, "snd_mixer_attach %s: %s", config->device, snd_strerror(err)); + if((err = snd_mixer_attach(alsa_mixer_handle, device))) + fatal(0, "snd_mixer_attach %s: %s", device, snd_strerror(err)); if((err = snd_mixer_selem_register(alsa_mixer_handle, 0/*options*/, 0/*classp*/))) fatal(0, "snd_mixer_selem_register %s: %s", @@@ -245,6 -241,12 +246,12 @@@ static void alsa_set_volume(int *left, *right = to_percent(r); } + static void alsa_configure(void) { + uaudio_set("device", config->device); + uaudio_set("mixer-control", config->mixer); + uaudio_set("mixer-channel", config->channel); + } + const struct uaudio uaudio_alsa = { .name = "alsa", .options = alsa_options, @@@ -256,6 -258,7 +263,7 @@@ .close_mixer = alsa_close_mixer, .get_volume = alsa_get_volume, .set_volume = alsa_set_volume, + .configure = alsa_configure }; #endif diff --combined lib/uaudio-oss.c index 081e1eb,adb227b..35e14c0 --- a/lib/uaudio-oss.c +++ b/lib/uaudio-oss.c @@@ -32,6 -32,7 +32,7 @@@ #include "mem.h" #include "log.h" #include "uaudio.h" + #include "configuration.h" #ifndef AFMT_U16_NE # if BYTE_ORDER == BIG_ENDIAN @@@ -145,11 -146,11 +146,11 @@@ static void oss_stop(void) static const char *oss_channels[] = SOUND_DEVICE_NAMES; static int oss_mixer_find_channel(const char *channel) { - if(!channel[strspn(c, "0123456789")]) + if(!channel[strspn(channel, "0123456789")]) return atoi(channel); else { - for(int n = 0; n < sizeof oss_channels / sizeof *oss_channels; ++n) - if(!strcmp(oss_channels[n], channels)) + for(unsigned n = 0; n < sizeof oss_channels / sizeof *oss_channels; ++n) + if(!strcmp(oss_channels[n], channel)) return n; return -1; } @@@ -175,7 -176,7 +176,7 @@@ static void oss_get_volume(int *left, i int r; *left = *right = 0; - if(ioctl(oss_mixer_fd, SOUND_MIXER_READ(ch), &r) < 0) + if(ioctl(oss_mixer_fd, SOUND_MIXER_READ(oss_mixer_channel), &r) < 0) error(errno, "error getting volume"); else { *left = r & 0xff; @@@ -185,9 -186,9 +186,9 @@@ static void oss_set_volume(int *left, int *right) { int r = (*left & 0xff) + (*right & 0xff) * 256; - if(ioctl(fd, SOUND_MIXER_WRITE(ch), &r) == -1) + if(ioctl(oss_mixer_fd, SOUND_MIXER_WRITE(oss_mixer_channel), &r) == -1) error(errno, "error setting volume"); - else if(ioctl(oss_mixer_fd, SOUND_MIXER_READ(ch), &r) < 0) + else if(ioctl(oss_mixer_fd, SOUND_MIXER_READ(oss_mixer_channel), &r) < 0) error(errno, "error getting volume"); else { *left = r & 0xff; @@@ -195,6 -196,12 +196,12 @@@ } } + static void oss_configure(void) { + uaudio_set("device", config->device); + uaudio_set("mixer-device", config->mixer); + uaudio_set("mixer-channel", config->channel); + } + const struct uaudio uaudio_oss = { .name = "oss", .options = oss_options, @@@ -206,6 -213,7 +213,7 @@@ .close_mixer = oss_close_mixer, .get_volume = oss_get_volume, .set_volume = oss_set_volume, + .configure = oss_configure, }; #endif