annotate mixer.c @ 1798:ddeafb1dbc73

fix sub redraw
author pontscho
date Fri, 31 Aug 2001 11:27:21 +0000
parents 0f7be115a4db
children d75b24bda7ce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
1
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
2 #include <string.h>
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
3 #include <sys/ioctl.h>
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
4 #include <fcntl.h>
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
5 #include <stdio.h>
605
abd7391a31e3 warnings killed
szabii
parents: 556
diff changeset
6 #include <unistd.h>
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
7
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
8 #include "config.h"
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
9 #include "mixer.h"
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
10
1061
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
11
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
12 #if defined(USE_OSS_AUDIO)
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
13
1061
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
14 /*
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
15 * Mixer interface using OSS style soundcard commands.
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
16 */
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
17
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
18 #include <sys/soundcard.h>
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
19
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
20
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
21 char * mixer_device=DEV_MIXER;
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
22 int mixer_usemaster=0;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
23
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
24 void mixer_getvolume( float *l,float *r )
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
25 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
26 int fd,v,cmd,devs;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
27
512
5cc44d8c20f2 some code cleanup
pontscho
parents: 461
diff changeset
28 fd=open( mixer_device,O_RDONLY );
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
29 if ( fd != -1 )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
30 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
31 ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
32 if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_READ_PCM;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
33 else
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
34 if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_READ_VOLUME;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
35 else
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
36 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
37 close( fd );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
38 return;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
39 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
40 ioctl( fd,cmd,&v );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
41 *r=( v & 0xFF00 ) >> 8;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
42 *l=( v & 0x00FF );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
43 close( fd );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
44 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
45 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
46
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
47 void mixer_setvolume( float l,float r )
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
48 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
49 int fd,v,cmd,devs;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
50
512
5cc44d8c20f2 some code cleanup
pontscho
parents: 461
diff changeset
51 fd=open( mixer_device,O_RDONLY );
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
52 if ( fd != -1 )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
53 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
54 ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
55 if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_WRITE_PCM;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
56 else
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
57 if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_WRITE_VOLUME;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
58 else
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
59 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
60 close( fd );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
61 return;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
62 }
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
63 v=( (int)r << 8 ) | (int)l;
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
64 ioctl( fd,cmd,&v );
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
65 close( fd );
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
66 }
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
67 }
1061
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
68
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
69 #elif defined(USE_SUN_AUDIO)
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
70
1061
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
71 /*
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
72 * Mixer interface using Sun style soundcard commands.
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
73 */
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
74
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
75 #include <sys/audioio.h>
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
76
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
77
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
78 char * mixer_device="/dev/audioctl";
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
79 int mixer_usemaster=0;
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
80
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
81 void mixer_getvolume( float *l,float *r )
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
82 {
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
83 int fd,v,cmd,devs;
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
84
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
85 fd=open( mixer_device,O_RDONLY );
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
86 if ( fd != -1 )
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
87 {
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
88 struct audio_info info;
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
89
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
90 ioctl( fd,AUDIO_GETINFO,&info);
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
91 *r=info.play.gain * 100. / AUDIO_MAX_GAIN;
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
92 *l=info.play.gain * 100. / AUDIO_MAX_GAIN;
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
93 close( fd );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
94 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
95 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
96
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
97 void mixer_setvolume( float l,float r )
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
98 {
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
99 int fd,v,cmd,devs;
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
100
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
101 fd=open( mixer_device,O_RDONLY );
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
102 if ( fd != -1 )
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
103 {
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
104 struct audio_info info;
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
105 AUDIO_INITINFO(&info);
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
106 info.play.gain = (r+l) * AUDIO_MAX_GAIN / 100 / 2;
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
107 ioctl( fd,AUDIO_SETINFO,&info );
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
108 close( fd );
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
109 }
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
110 }
1061
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
111
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
112 #else
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
113
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
114 /*
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
115 * No usable Mixer interface selected.
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
116 * Just some stub routines.
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
117 */
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
118
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
119 char * mixer_device=NULL;
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
120 int mixer_usemaster=0;
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
121
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
122 void mixer_getvolume( float *l,float *r ){
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
123 *l = *r = 50.0;
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
124 }
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
125 void mixer_setvolume( float l,float r ){
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
126 }
0f7be115a4db patch by J¸«ärgen Keil
arpi_esp
parents: 1038
diff changeset
127
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
128 #endif
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
129
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
130
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
131 void mixer_incvolume( void )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
132 {
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
133 float mixer_l, mixer_r;
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
134 mixer_getvolume( &mixer_l,&mixer_r );
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
135 mixer_l++;
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
136 if ( mixer_l > 100 ) mixer_l = 100;
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
137 mixer_r++;
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
138 if ( mixer_r > 100 ) mixer_r = 100;
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
139 mixer_setvolume( mixer_l,mixer_r );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
140 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
141
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
142 void mixer_decvolume( void )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
143 {
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
144 float mixer_l, mixer_r;
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
145 mixer_getvolume( &mixer_l,&mixer_r );
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
146 mixer_l--;
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
147 if ( mixer_l < 0 ) mixer_l = 0;
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
148 mixer_r--;
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
149 if ( mixer_r < 0 ) mixer_r = 0;
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
150 mixer_setvolume( mixer_l,mixer_r );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
151 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
152
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
153 float mixer_getbothvolume( void )
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
154 {
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
155 float mixer_l, mixer_r;
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
156 mixer_getvolume( &mixer_l,&mixer_r );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
157 return ( mixer_l + mixer_r ) / 2;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
158 }