aboutsummaryrefslogtreecommitdiff
path: root/toys/other/mix.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-12-27 13:52:40 -0600
committerRob Landley <rob@landley.net>2014-12-27 13:52:40 -0600
commit989f453e133962c711d360b6f2e87ee5b0e56b22 (patch)
tree7b40d397a713d5a1e22b1cd2edc76391dc9e9f89 /toys/other/mix.c
parent73b8bb5adecf796c717749eeb309f7659c7089db (diff)
downloadtoybox-989f453e133962c711d360b6f2e87ee5b0e56b22.tar.gz
Promote mix
Diffstat (limited to 'toys/other/mix.c')
-rw-r--r--toys/other/mix.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/toys/other/mix.c b/toys/other/mix.c
new file mode 100644
index 00000000..2b8165e3
--- /dev/null
+++ b/toys/other/mix.c
@@ -0,0 +1,67 @@
+/* mix.c - A very basic mixer.
+ *
+ * Copyright 2014 Brad Conroy, dedicated to the Public Domain.
+ *
+
+USE_MIX(NEWTOY(mix, "c:d:l#r#", TOYFLAG_USR|TOYFLAG_BIN))
+
+config MIX
+ bool "mix"
+ default y
+ help
+ usage: mix [-m DEV] [-d CHANNEL] [-l VOL] [-r RIGHT]
+
+ List OSS sound channels (module snd-mixer-oss), or set volume(s).
+
+ -d DEV Device node (default /dev/mixer)
+ -l VOL Volume level
+ -c CHANNEL Set/show volume of CHANNEL (default first channel found)
+ -r RIGHT Volume of right stereo channel (with -r, -l sets left volume)
+*/
+
+#define FOR_mix
+#include "toys.h"
+#include <linux/soundcard.h>
+
+GLOBALS(
+ long right;
+ long level;
+ char *dev;
+ char *chan;
+)
+
+void mix_main(void)
+{
+ const char *channels[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES;
+ int mask, channel = -1, level, fd;
+
+ if (!TT.dev) TT.dev = "/dev/mixer";
+ fd = xopen(TT.dev, O_RDWR|O_NONBLOCK);
+ xioctl(fd, SOUND_MIXER_READ_DEVMASK, &mask);
+
+ for (channel = 0; channel < SOUND_MIXER_NRDEVICES; channel++) {
+ if ((1<<channel) & mask) {
+ if (TT.chan && !strcmp(channels[channel], TT.chan)) break;
+ else if (toys.optflags & FLAG_l) break;
+ else printf("%s\n", channels[channel]);
+ }
+ }
+
+ if (!(toys.optflags & (FLAG_c|FLAG_l))) return;
+ else if (channel == SOUND_MIXER_NRDEVICES) error_exit("bad -c '%s'", TT.chan);
+
+ if (!(toys.optflags & FLAG_l)) {
+ xioctl(fd, MIXER_READ(channel), &level);
+ if (level > 0xFF)
+ xprintf("%s:%s = left:%d\t right:%d\n",
+ TT.dev, channels[channel], level>>8, level & 0xFF);
+ else xprintf("%s:%s = %d\n", TT.dev, channels[channel], level);
+ } else {
+ level = TT.level;
+ if (!(toys.optflags & FLAG_r)) level = TT.right | (level<<8);
+
+ xioctl(fd, MIXER_WRITE(channel), &level);
+ }
+
+ if (CFG_TOYBOX_FREE) close(fd);
+}