annotate mixer.c @ 1026:435feedf9f89

Did some cleanup around STREAMING defined.
author bertrand
date Tue, 05 Jun 2001 08:42:16 +0000
parents 72cacd3b8f30
children b36fb1ae4b53
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>
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
4 #ifdef __sun
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
5 #include <sys/audioio.h>
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
6 #else
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
7 #include <sys/soundcard.h>
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
8 #endif
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
9 #include <fcntl.h>
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
10 #include <stdio.h>
605
abd7391a31e3 warnings killed
szabii
parents: 556
diff changeset
11 #include <unistd.h>
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
12
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
13 #include "mixer.h"
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
14
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
15 #ifdef __sun
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
16 char * mixer_device="/dev/audioctl";
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
17 #else
556
3d1e8b618594 using /dev/mixer as default
arpi_esp
parents: 512
diff changeset
18 char * mixer_device="/dev/mixer";
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
19 #endif
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
20 int mixer_usemaster=0;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
21
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
22 void mixer_getvolume( int *l,int *r )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
23 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
24 int fd,v,cmd,devs;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
25
512
5cc44d8c20f2 some code cleanup
pontscho
parents: 461
diff changeset
26 fd=open( mixer_device,O_RDONLY );
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
27 if ( fd != -1 )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
28 {
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
29 #ifdef __sun
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
30 audio_info_t info;
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
31 ioctl( fd,AUDIO_GETINFO,&info );
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
32 *r=*l=(info.play.gain * 100 + (AUDIO_MAX_GAIN-1))/AUDIO_MAX_GAIN;
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
33 #else
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
34 ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
35 if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_READ_PCM;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
36 else
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
37 if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_READ_VOLUME;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
38 else
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
39 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
40 close( fd );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
41 return;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
42 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
43 ioctl( fd,cmd,&v );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
44 *r=( v & 0xFF00 ) >> 8;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
45 *l=( v & 0x00FF );
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
46 #endif
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
47 close( fd );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
48 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
49 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
50
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
51 void mixer_setvolume( int l,int r )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
52 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
53 int fd,v,cmd,devs;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
54
512
5cc44d8c20f2 some code cleanup
pontscho
parents: 461
diff changeset
55 fd=open( mixer_device,O_RDONLY );
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
56 if ( fd != -1 )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
57 {
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
58 #ifdef __sun
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
59 audio_info_t info;
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
60 ioctl( fd,AUDIO_GETINFO,&info );
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
61 info.play.gain = ((l+r)*AUDIO_MAX_GAIN+199)/200;
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
62 ioctl( fd,AUDIO_SETINFO,&info );
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
63 #else
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
64 ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
65 if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_WRITE_PCM;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
66 else
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
67 if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_WRITE_VOLUME;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
68 else
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
69 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
70 close( fd );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
71 return;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
72 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
73 v=( r << 8 ) | l;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
74 ioctl( fd,cmd,&v );
1020
72cacd3b8f30 Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents: 605
diff changeset
75 #endif
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
76 close( fd );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
77 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
78 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
79
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
80 int mixer_l=0; int mixer_r=0;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
81
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
82 void mixer_incvolume( void )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
83 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
84 mixer_getvolume( &mixer_l,&mixer_r );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
85 if ( mixer_l < 100 ) mixer_l++;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
86 if ( mixer_r < 100 ) mixer_r++;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
87 mixer_setvolume( mixer_l,mixer_r );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
88 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
89
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
90 void mixer_decvolume( void )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
91 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
92 mixer_getvolume( &mixer_l,&mixer_r );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
93 if ( mixer_l > 0 ) mixer_l--;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
94 if ( mixer_r > 0 ) mixer_r--;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
95 mixer_setvolume( mixer_l,mixer_r );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
96 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
97
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
98 int mixer_getbothvolume( void )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
99 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
100 mixer_getvolume( &mixer_l,&mixer_r );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
101 return ( mixer_l + mixer_r ) / 2;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
102 }