annotate mixer.c @ 1004:57972eb8127a

prefix add to config.h
author pontscho
date Mon, 04 Jun 2001 18:23:10 +0000
parents abd7391a31e3
children 72cacd3b8f30
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 <sys/soundcard.h>
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
5 #include <fcntl.h>
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
6 #include <stdio.h>
605
abd7391a31e3 warnings killed
szabii
parents: 556
diff changeset
7 #include <unistd.h>
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
8
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
9 #include "mixer.h"
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
10
556
3d1e8b618594 using /dev/mixer as default
arpi_esp
parents: 512
diff changeset
11 char * mixer_device="/dev/mixer";
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
12 int mixer_usemaster=0;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
13
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
14 void mixer_getvolume( int *l,int *r )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
15 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
16 int fd,v,cmd,devs;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
17
512
5cc44d8c20f2 some code cleanup
pontscho
parents: 461
diff changeset
18 fd=open( mixer_device,O_RDONLY );
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
19 if ( fd != -1 )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
20 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
21 ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
22 if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_READ_PCM;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
23 else
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
24 if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_READ_VOLUME;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
25 else
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
26 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
27 close( fd );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
28 return;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
29 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
30 ioctl( fd,cmd,&v );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
31 *r=( v & 0xFF00 ) >> 8;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
32 *l=( v & 0x00FF );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
33 close( fd );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
34 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
35 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
36
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
37 void mixer_setvolume( int l,int r )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
38 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
39 int fd,v,cmd,devs;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
40
512
5cc44d8c20f2 some code cleanup
pontscho
parents: 461
diff changeset
41 fd=open( mixer_device,O_RDONLY );
441
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
42 if ( fd != -1 )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
43 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
44 ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
45 if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_WRITE_PCM;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
46 else
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
47 if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_WRITE_VOLUME;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
48 else
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
49 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
50 close( fd );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
51 return;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
52 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
53 v=( r << 8 ) | l;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
54 ioctl( fd,cmd,&v );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
55 close( fd );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
56 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
57 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
58
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
59 int mixer_l=0; int mixer_r=0;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
60
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
61 void mixer_incvolume( void )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
62 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
63 mixer_getvolume( &mixer_l,&mixer_r );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
64 if ( mixer_l < 100 ) mixer_l++;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
65 if ( mixer_r < 100 ) mixer_r++;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
66 mixer_setvolume( mixer_l,mixer_r );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
67 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
68
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
69 void mixer_decvolume( void )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
70 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
71 mixer_getvolume( &mixer_l,&mixer_r );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
72 if ( mixer_l > 0 ) mixer_l--;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
73 if ( mixer_r > 0 ) mixer_r--;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
74 mixer_setvolume( mixer_l,mixer_r );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
75 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
76
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
77 int mixer_getbothvolume( void )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
78 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
79 mixer_getvolume( &mixer_l,&mixer_r );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
80 return ( mixer_l + mixer_r ) / 2;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
81 }