#include "mem.h"
#include "log.h"
#include "uaudio.h"
+ #include "configuration.h"
/** @brief The current PCM handle */
static snd_pcm_t *alsa_pcm;
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",
*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
#include "mem.h"
#include "log.h"
#include "uaudio.h"
+ #include "configuration.h"
#ifndef AFMT_U16_NE
# if BYTE_ORDER == BIG_ENDIAN
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;
}
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