2 * Copyright (C) 1998-2014 Andre Noll <maan@tuebingen.mpg.de>
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);
60 PARA_ERROR_LOG("could not open %s\n", dev
);
63 h
= para_malloc(sizeof(*h
));
69 static char *oss_mix_get_channels(__a_unused
struct mixer_handle
*handle
)
75 const char *name
= channels
[i
].name
;
77 list
= make_message("%s%s%s",
86 static int oss_mix_set_channel(struct mixer_handle
*handle
,
87 const char *mixer_channel
)
92 handle
->id
= SOUND_MIXER_VOLUME
; /* default */
96 if (strcasecmp(channels
[i
].name
, mixer_channel
))
101 return -E_BAD_CHANNEL
;
104 static int oss_mix_get(struct mixer_handle
*handle
)
106 int val
, fd
= handle
->fd
, id
= handle
->id
;
108 if (ioctl(fd
, MIXER_READ(id
), &val
) < 0)
109 return -ERRNO_TO_PARA_ERROR(errno
);
110 /* take the mean value of left and right */
111 return (val
% 256 + (val
>> 8)) / 2;
114 static int oss_mix_set(struct mixer_handle
*handle
, int val
)
116 int fd
= handle
->fd
, id
= handle
->id
, tmp
= (val
<< 8) + val
;
118 if (ioctl(fd
, MIXER_WRITE(id
), &tmp
) < 0)
119 return -ERRNO_TO_PARA_ERROR(errno
);
123 static void oss_mix_close(struct mixer_handle
**handle
)
125 struct mixer_handle
*h
;
139 * The init function of the OSS mixer.
141 * \param self The structure to initialize.
143 * \sa struct \ref mixer, \ref alsa_mix_init().
145 void oss_mix_init(struct mixer
*self
)
147 self
->open
= oss_mix_open
;
148 self
->get_channels
= oss_mix_get_channels
;
149 self
->set_channel
= oss_mix_set_channel
;
150 self
->get
= oss_mix_get
;
151 self
->set
= oss_mix_set
;
152 self
->close
= oss_mix_close
;