aboutsummaryrefslogtreecommitdiff
path: root/toys/pending/mix.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-12-27 13:52:03 -0600
committerRob Landley <rob@landley.net>2014-12-27 13:52:03 -0600
commit73b8bb5adecf796c717749eeb309f7659c7089db (patch)
tree31c11168bf685a49cdb755f1b149c297c0ffef03 /toys/pending/mix.c
parent4391e57913ab84f1edea56157192692d2e41458c (diff)
downloadtoybox-73b8bb5adecf796c717749eeb309f7659c7089db.tar.gz
Cleanup mix.c.
Diffstat (limited to 'toys/pending/mix.c')
-rw-r--r--toys/pending/mix.c75
1 files changed, 39 insertions, 36 deletions
diff --git a/toys/pending/mix.c b/toys/pending/mix.c
index 4a51fb9e..b59136de 100644
--- a/toys/pending/mix.c
+++ b/toys/pending/mix.c
@@ -3,62 +3,65 @@
* Copyright 2014 Brad Conroy, dedicated to the Public Domain.
*
-USE_MIX(NEWTOY(mix, "m:d:l#r#", TOYFLAG_USR|TOYFLAG_BIN))
+USE_MIX(NEWTOY(mix, "c:d:l#r#", TOYFLAG_USR|TOYFLAG_BIN))
+
config MIX
bool "mix"
default n
help
- usage: mix [-m mixer] [-d device] [-l level / left level] [-r right level]
+ usage: mix [-m DEV] [-d CHANNEL] [-l VOL] [-r RIGHT]
+
+ List OSS sound channels (module snd-mixer-oss), or set volume(s).
- Lists/sets mixer devices/levels.
+ -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 <linux/soundcard.h>
#include "toys.h"
-
+#include <linux/soundcard.h>
GLOBALS(
- int right;
- int level;
- char *device;
- char *mixer;
+ long right;
+ long level;
+ char *dev;
+ char *chan;
)
void mix_main(void)
{
- const char *devices[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES;
- char *mixer_name=(toys.optflags & FLAG_m)?TT.mixer:"/dev/mixer";
- int i, mask, device=-1, level,
- mixer=xopen(mixer_name, O_RDWR|O_NONBLOCK);
+ const char *channels[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES;
+ int mask, channel = -1, level, fd;
- xioctl(mixer, SOUND_MIXER_READ_DEVMASK,&mask);
+ if (!TT.dev) TT.dev = "/dev/mixer";
+ fd = xopen(TT.dev, O_RDWR|O_NONBLOCK);
+ xioctl(fd, SOUND_MIXER_READ_DEVMASK, &mask);
- if (!(toys.optflags & FLAG_d)){
- for (i = 0; i < SOUND_MIXER_NRDEVICES; ++i)
- if (1<<i & mask) printf("%s\n",devices[i]);
- return;
- }else{
- for (i = 0; i < SOUND_MIXER_NRDEVICES; ++i){
- if ((1<<i & mask) && !strcmp(devices[i], TT.device)){
- device=i;
- break;
- }
+ 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 (-1==device) return; //with error
}
- if (!(toys.optflags & FLAG_l)){
- xioctl(mixer, MIXER_READ(device),&level);
- if (0xFF < level) printf("%s:%s = left:%d\t right:%d\n", mixer_name,
- devices[device], level>>8, level & 0xFF);
- else printf("%s:%s = %d\n",mixer_name, devices[device], level);
- return;
- }
+ if (!(toys.optflags & (FLAG_c|FLAG_l))) return;
+ else if (channel == SOUND_MIXER_NRDEVICES) error_exit("bad -c '%s'", TT.chan);
- level=TT.level;
- if (!(toys.optflags & FLAG_r)) level = TT.right | (level<<8);
+ 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);
+ }
- xioctl(mixer, MIXER_WRITE(device),&level);
- close(mixer);
+ if (CFG_TOYBOX_FREE) close(fd);
}