<div dir="ltr">/* mix.c - A very basic mixer.<br> *<br> * Copyright 2014 Brad Conroy, dedicated to the Public Domain.<br> *<br><br>USE_MIX(NEWTOY(mix, "m:d:l#r#", TOYFLAG_USR|TOYFLAG_BIN))<br>config MIX<br> bool "mix"<br>
default n<br> help<br> usage: mix [-m mixer] [-d device] [-l level / left level] [-r right level]<br><br> Lists/sets mixer devices/levels.<br>*/<br><br>#define FOR_mix<br>#include <linux/soundcard.h><br>#include "toys.h"<br>
<br><br>GLOBALS(<br> int right;<br> int level;<br> char *device;<br> char *mixer;<br>)<br><br>void mix_main(void)<br>{<br> const char *devices[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES;<br> char *mixer_name=(toys.optflags & FLAG_m)?TT.mixer:"/dev/mixer";<br>
int i, mask, device=-1, level,<br> mixer=xopen(mixer_name, O_RDWR|O_NONBLOCK);<br><br> xioctl(mixer, SOUND_MIXER_READ_DEVMASK,&mask);<br><br> if (!(toys.optflags & FLAG_d)){<br> for (i = 0; i < SOUND_MIXER_NRDEVICES; ++i)<br>
if (1<<i & mask) printf("%s\n",devices[i]);<br> return;<br> }else{<br> for (i = 0; i < SOUND_MIXER_NRDEVICES; ++i){<br> if ((1<<i & mask) && !strcmp(devices[i], TT.device)){<br>
device=i;<br> break;<br> }<br> }<br> if (-1==device) return; //with error<br> }<br><br> if (!(toys.optflags & FLAG_l)){<br> xioctl(mixer, MIXER_READ(device),&level);<br> if (0xFF < level) printf("%s:%s = left:%d\t right:%d\n", mixer_name,<br>
devices[device], level>>8, level & 0xFF);<br> else printf("%s:%s = %d\n",mixer_name, devices[device], level);<br> return;<br> }<br><br> level=TT.level;<br> if (!(toys.optflags & FLAG_r)) level = TT.right | (level<<8);<br>
<br> xioctl(mixer, MIXER_WRITE(device),&level);<br> close(mixer);<br>}<br></div>