1 // mixctl.h - MixCtl class provides control of audio mixer functions
2 // 05/09/98 Release 1.0 Beta1
3 // Copyright (C) 1998 Sam Hawker <shawkie@geocities.com>
4 // This software comes with ABSOLUTELY NO WARRANTY
5 // This software is free software, and you are welcome to redistribute it
6 // under certain conditions
7 // See the COPYING file for details.
9 // Although mixctl.h is an integral part of wmmixer, it may also be distributed seperately.
13 #include <sys/ioctl.h>
14 #include <sys/types.h>
19 #include <soundcard.h>
22 #include <machine/soundcard.h>
25 #include <linux/soundcard.h>
32 device
=(char *)malloc(sizeof(char)*(strlen(dname
)+1));
34 if(mixfdopen
=(mixfd
=open(device
,O_RDONLY
| O_NONBLOCK
))!=-1){
35 nrdevices
=SOUND_MIXER_NRDEVICES
;
36 char *devnames
[]=SOUND_DEVICE_NAMES
;
37 char *devlabels
[]=SOUND_DEVICE_LABELS
;
38 ioctl(mixfd
, SOUND_MIXER_READ_DEVMASK
, &devmask
);
39 ioctl(mixfd
, SOUND_MIXER_READ_STEREODEVS
, &stmask
);
40 ioctl(mixfd
, SOUND_MIXER_READ_RECMASK
, &recmask
);
41 ioctl(mixfd
, SOUND_MIXER_READ_CAPS
, &caps
);
42 mixdevs
=(struct MixDev
*)malloc(sizeof(struct MixDev
)*nrdevices
);
44 for(int i
=0;i
<nrdevices
;i
++){
45 mixdevs
[i
].support
=devmask
& mixmask
;
46 mixdevs
[i
].stereo
=stmask
& mixmask
;
47 mixdevs
[i
].records
=recmask
& mixmask
;
48 mixdevs
[i
].mask
=mixmask
;
49 mixdevs
[i
].name
=devnames
[i
];
50 mixdevs
[i
].label
=devlabels
[i
];
67 ioctl(mixfd
, SOUND_MIXER_READ_RECSRC
, &recsrc
);
68 for(int i
=0;i
<nrdevices
;i
++){
69 if(mixdevs
[i
].support
)
70 ioctl(mixfd
, MIXER_READ(i
), &mixdevs
[i
].value
);
71 mixdevs
[i
].recsrc
=(recsrc
& mixdevs
[i
].mask
);
75 // Return volume for a device, optionally reading it from device first.
76 // Can be used as a way to avoid calling doStatus().
77 int readVol(int dev
, bool read
){
79 ioctl(mixfd
, MIXER_READ(dev
), &mixdevs
[dev
].value
);
80 return mixdevs
[dev
].value
;
83 // Return left and right componenets of volume for a device.
84 // If you are lazy, you can call readVol to read from the device, then these
85 // to get left and right values.
86 int readLeft(int dev
){
87 return mixdevs
[dev
].value
%256;
89 int readRight(int dev
){
90 return mixdevs
[dev
].value
/256;
93 // Write volume to device. Use setVolume, setLeft and setRight first.
94 void writeVol(int dev
){
95 ioctl(mixfd
, MIXER_WRITE(dev
), &mixdevs
[dev
].value
);
98 // Set volume (or left or right component) for a device. You must call writeVol to write it.
99 void setVol(int dev
, int value
){
100 mixdevs
[dev
].value
=value
;
102 void setBoth(int dev
, int l
, int r
){
103 mixdevs
[dev
].value
=256*r
+l
;
105 void setLeft(int dev
, int l
){
107 if(mixdevs
[dev
].stereo
)
108 r
=mixdevs
[dev
].value
/256;
111 mixdevs
[dev
].value
=256*r
+l
;
113 void setRight(int dev
, int r
){
115 if(mixdevs
[dev
].stereo
)
116 l
=mixdevs
[dev
].value
%256;
119 mixdevs
[dev
].value
=256*r
+l
;
122 // Return record source value for a device, optionally reading it from device first.
123 bool readRec(int dev
, bool read
){
125 ioctl(mixfd
, SOUND_MIXER_READ_RECSRC
, &recsrc
);
126 mixdevs
[dev
].recsrc
=(recsrc
& mixdevs
[dev
].mask
);
128 return mixdevs
[dev
].recsrc
;
131 // Write record source values to device. Use setRec first.
133 ioctl(mixfd
, SOUND_MIXER_WRITE_RECSRC
, &recsrc
);
136 // Make a device (not) a record source.
137 void setRec(int dev
, bool rec
){
139 if(caps
& SOUND_CAP_EXCL_INPUT
)
140 recsrc
=mixdevs
[dev
].mask
;
142 recsrc
|=mixdevs
[dev
].mask
;
145 recsrc
&=~mixdevs
[dev
].mask
;
148 // Return various other info
155 int getCapabilities(){
158 bool getSupport(int dev
){
159 return mixdevs
[dev
].support
;
161 bool getStereo(int dev
){
162 return mixdevs
[dev
].stereo
;
164 bool getRecords(int dev
){
165 return mixdevs
[dev
].records
;
167 char *getName(int dev
){
168 return mixdevs
[dev
].name
;
170 char *getLabel(int dev
){
171 return mixdevs
[dev
].label
;
190 int nrdevices
; // maximum number of devices
191 int devmask
; // supported devices
192 int stmask
; // stereo devices
193 int recmask
; // devices which can be recorded from
194 int caps
; // capabilities
195 int recsrc
; // devices which are being recorded from
196 struct MixDev
*mixdevs
;