changeset 1412:b513c9c64c71 draft

mix.c - A very basic mixer.
author Bradley Conroy <bradley.conroy@gmail.com>
date Sat, 02 Aug 2014 11:49:30 -0500
parents dd336488a69b
children 27a0fe0b7582
files toys/pending/mix.c
diffstat 1 files changed, 64 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/toys/pending/mix.c	Sat Aug 02 11:49:30 2014 -0500
@@ -0,0 +1,64 @@
+/* mix.c - A very basic mixer.
+ *
+ * Copyright 2014 Brad Conroy, dedicated to the Public Domain.
+ *
+
+USE_MIX(NEWTOY(mix, "m: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]
+
+   Lists/sets mixer devices/levels.
+*/
+
+#define FOR_mix
+#include <linux/soundcard.h>
+#include "toys.h"
+
+
+GLOBALS(
+   int right;
+   int level;
+   char *device;
+   char *mixer;
+)
+
+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);
+
+  xioctl(mixer, 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;
+      }
+    }
+    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;
+  }
+
+  level=TT.level;
+  if (!(toys.optflags & FLAG_r)) level = TT.right | (level<<8);
+
+  xioctl(mixer, MIXER_WRITE(device),&level);
+  close(mixer);
+}