chiark / gitweb /
Merge configuration fixes
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 8 Mar 2009 14:01:44 +0000 (14:01 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 8 Mar 2009 14:01:44 +0000 (14:01 +0000)
1  2 
lib/uaudio-alsa.c
lib/uaudio-oss.c

diff --combined lib/uaudio-alsa.c
index 2236c918b522b71587b4f7a7f64a0e00856a5246,14b2d2a8a85493eb420c06f1c12c8cf64d4ea625..48ae1bea52f33b2961966001bf9ad4ec25e0598d
@@@ -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;
    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,
    .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 081e1eb4bef09c6b595706cc57f816b7a4c223f5,adb227bd170457eec78750933dae0fa52bd30f76..35e14c0305bc000c0e8a36bc7b521b80bd5ff36c
@@@ -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;
  
  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;
    }
  }
  
+ 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,
    .close_mixer = oss_close_mixer,
    .get_volume = oss_get_volume,
    .set_volume = oss_set_volume,
+   .configure = oss_configure,
  };
  
  #endif