2 * Copyright (C) 1998-2012 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file oss_mix.c The OSS mixer plugin. */
9 #include <sys/soundcard.h>
10 #include <sys/ioctl.h>
19 struct oss_mixer_channel {
24 static const struct oss_mixer_channel channels[] = {
25 {.name = "volume", .id = SOUND_MIXER_VOLUME},
26 {.name = "bass", .id = SOUND_MIXER_BASS},
27 {.name = "treble", .id = SOUND_MIXER_TREBLE},
28 {.name = "synth", .id = SOUND_MIXER_SYNTH},
29 {.name = "pcm", .id = SOUND_MIXER_PCM},
30 {.name = "speaker", .id = SOUND_MIXER_SPEAKER},
31 {.name = "line", .id = SOUND_MIXER_LINE},
32 {.name = "mic", .id = SOUND_MIXER_MIC},
33 {.name = "cd", .id = SOUND_MIXER_CD},
34 {.name = "imix", .id = SOUND_MIXER_IMIX},
35 {.name = "altpcm", .id = SOUND_MIXER_ALTPCM},
36 {.name = "reclev", .id = SOUND_MIXER_RECLEV},
37 {.name = "igain", .id = SOUND_MIXER_IGAIN},
38 {.name = "ogain", .id = SOUND_MIXER_OGAIN},
41 /** Iterate over all defined mixer channels. */
42 #define FOR_EACH_CHANNEL(i) for ((i) = 0; (i) < ARRAY_SIZE(channels); (i)++)
49 static int oss_mix_open(const char *dev, struct mixer_handle **handle)
52 struct mixer_handle *h;
57 PARA_INFO_LOG("opening %s\n", dev);
58 ret = para_open(dev, O_RDWR, 42);
61 h = para_malloc(sizeof(*h));
67 static char *oss_mix_get_channels(__a_unused struct mixer_handle *handle)
73 const char *name = channels[i].name;
75 list = make_message("%s%s%s",
84 static int oss_mix_set_channel(struct mixer_handle *handle,
85 const char *mixer_channel)
90 handle->id = SOUND_MIXER_VOLUME; /* default */
94 if (strcasecmp(channels[i].name, mixer_channel))
99 return -E_OSS_MIXER_CHANNEL;
102 static int oss_mix_get(struct mixer_handle *handle)
104 int val, fd = handle->fd, id = handle->id;
106 if (ioctl(fd, MIXER_READ(id), &val) < 0)
107 return -ERRNO_TO_PARA_ERROR(errno);
108 /* take the mean value of left and right */
109 return (val % 256 + (val >> 8)) / 2;
112 static int oss_mix_set(struct mixer_handle *handle, int val)
114 int fd = handle->fd, id = handle->id, tmp = (val << 8) + val;
116 if (ioctl(fd, MIXER_WRITE(id), &tmp) < 0)
117 return -ERRNO_TO_PARA_ERROR(errno);
121 static void oss_mix_close(struct mixer_handle **handle)
123 struct mixer_handle *h;
137 * The init function of the OSS mixer.
139 * \param self The structure to initialize.
141 * \sa struct \ref mixer, \ref alsa_mix_init().
143 void oss_mix_init(struct mixer *self)
145 self->open = oss_mix_open;
146 self->get_channels = oss_mix_get_channels;
147 self->set_channel = oss_mix_set_channel;
148 self->get = oss_mix_get;
149 self->set = oss_mix_set;
150 self->close = oss_mix_close;