1 /* Copyright (C) 1998 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
3 /** \file oss_mix.c The OSS mixer plugin. */
5 #include <sys/soundcard.h>
15 struct oss_mixer_channel {
20 static const struct oss_mixer_channel channels[] = {
21 {.name = "volume", .id = SOUND_MIXER_VOLUME},
22 {.name = "bass", .id = SOUND_MIXER_BASS},
23 {.name = "treble", .id = SOUND_MIXER_TREBLE},
24 {.name = "synth", .id = SOUND_MIXER_SYNTH},
25 {.name = "pcm", .id = SOUND_MIXER_PCM},
26 {.name = "speaker", .id = SOUND_MIXER_SPEAKER},
27 {.name = "line", .id = SOUND_MIXER_LINE},
28 {.name = "mic", .id = SOUND_MIXER_MIC},
29 {.name = "cd", .id = SOUND_MIXER_CD},
30 {.name = "imix", .id = SOUND_MIXER_IMIX},
31 {.name = "altpcm", .id = SOUND_MIXER_ALTPCM},
32 {.name = "reclev", .id = SOUND_MIXER_RECLEV},
33 {.name = "igain", .id = SOUND_MIXER_IGAIN},
34 {.name = "ogain", .id = SOUND_MIXER_OGAIN},
37 /** Iterate over all defined mixer channels. */
38 #define FOR_EACH_CHANNEL(i) for ((i) = 0; (i) < ARRAY_SIZE(channels); (i)++)
45 static int oss_mix_open(const char *dev, struct mixer_handle **handle)
48 struct mixer_handle *h;
53 PARA_INFO_LOG("opening %s\n", dev);
54 ret = para_open(dev, O_RDWR, 42);
56 PARA_ERROR_LOG("could not open %s\n", dev);
59 h = para_malloc(sizeof(*h));
65 static char *oss_mix_get_channels(__a_unused struct mixer_handle *handle)
71 const char *name = channels[i].name;
73 list = make_message("%s%s%s",
82 static int oss_mix_set_channel(struct mixer_handle *handle,
83 const char *mixer_channel)
88 handle->id = SOUND_MIXER_VOLUME; /* default */
92 if (strcasecmp(channels[i].name, mixer_channel))
97 return -E_BAD_CHANNEL;
100 static int oss_mix_get(struct mixer_handle *handle)
102 int val, fd = handle->fd, id = handle->id;
104 if (ioctl(fd, MIXER_READ(id), &val) < 0)
105 return -ERRNO_TO_PARA_ERROR(errno);
106 /* take the mean value of left and right */
107 return (val % 256 + (val >> 8)) / 2;
110 static int oss_mix_set(struct mixer_handle *handle, int val)
112 int fd = handle->fd, id = handle->id, tmp = (val << 8) + val;
114 if (ioctl(fd, MIXER_WRITE(id), &tmp) < 0)
115 return -ERRNO_TO_PARA_ERROR(errno);
119 static void oss_mix_close(struct mixer_handle **handle)
121 struct mixer_handle *h;
134 /** The mixer operations for the OSS mixer. */
135 const struct mixer oss_mixer = {
137 .open = oss_mix_open,
138 .get_channels = oss_mix_get_channels,
139 .set_channel = oss_mix_set_channel,
140 .close = oss_mix_close,