1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#define FOR_mix
23#include "toys.h"
24#include <linux/soundcard.h>
25
26GLOBALS(
27 long r, l;
28 char *d, *c;
29)
30
31void mix_main(void)
32{
33 const char *channels[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES;
34 int mask, channel = -1, level, fd;
35
36 if (!TT.d) TT.d = "/dev/mixer";
37 fd = xopen(TT.d, O_RDWR|O_NONBLOCK);
38 xioctl(fd, SOUND_MIXER_READ_DEVMASK, &mask);
39
40 for (channel = 0; channel < SOUND_MIXER_NRDEVICES; channel++) {
41 if ((1<<channel) & mask) {
42 if (TT.c) {
43 if (!strcmp(channels[channel], TT.c)) break;
44 } else if (toys.optflags & FLAG_l) break;
45 else printf("%s\n", channels[channel]);
46 }
47 }
48
49 if (!(toys.optflags & (FLAG_c|FLAG_l))) return;
50 else if (channel == SOUND_MIXER_NRDEVICES) error_exit("bad -c '%s'", TT.c);
51
52 if (!(toys.optflags & FLAG_l)) {
53 xioctl(fd, MIXER_READ(channel), &level);
54 if (level > 0xFF)
55 xprintf("%s:%s = left:%d\t right:%d\n",
56 TT.d, channels[channel], level>>8, level & 0xFF);
57 else xprintf("%s:%s = %d\n", TT.d, channels[channel], level);
58 } else {
59 level = TT.l;
60 if (!(toys.optflags & FLAG_r)) level = TT.r | (level<<8);
61
62 xioctl(fd, MIXER_WRITE(channel), &level);
63 }
64
65 if (CFG_TOYBOX_FREE) close(fd);
66}
67