annotate mixer.c @ 460:2056ddd20c50

add mixer support
author pontscho
date Mon, 16 Apr 2001 00:21:00 +0000
parents c4b4e2aac9de
children a5bfb2cdf70b
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>
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
7
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
8 #include "mixer.h"
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
9
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
10 #define DEV_MIXER "/dev/mixer"
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
11
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
12 char * mixer_device=NULL;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
13 char * devname=NULL;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
14 int mixer_usemaster=0;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
15
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
16 void mixer_getvolume( int *l,int *r )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
17 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
18 int fd,v,cmd,devs;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
19
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
20 if ( !mixer_device ) devname=strdup( DEV_MIXER );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
21 else devname=strdup( mixer_device );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
22 fd=open( devname,O_RDONLY );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
23 free( devname );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
24 if ( fd != -1 )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
25 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
26 ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
27 if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_READ_PCM;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
28 else
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
29 if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_READ_VOLUME;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
30 else
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
31 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
32 close( fd );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
33 return;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
34 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
35 ioctl( fd,cmd,&v );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
36 *r=( v & 0xFF00 ) >> 8;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
37 *l=( v & 0x00FF );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
38 close( fd );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
39 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
40 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
41
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
42 void mixer_setvolume( int l,int r )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
43 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
44 int fd,v,cmd,devs;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
45
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
46 if ( !mixer_device ) devname=strdup( DEV_MIXER );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
47 else devname=strdup( mixer_device );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
48 fd=open( devname,O_RDONLY );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
49 free( devname );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
50 if ( fd != -1 )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
51 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
52 ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
53 if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_WRITE_PCM;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
54 else
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
55 if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_WRITE_VOLUME;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
56 else
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
57 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
58 close( fd );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
59 return;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
60 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
61 v=( r << 8 ) | l;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
62 ioctl( fd,cmd,&v );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
63 close( fd );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
64 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
65 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
66
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
67 int mixer_l=0; int mixer_r=0;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
68
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
69 void mixer_incvolume( void )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
70 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
71 fprintf( stderr,"[mixer] inc.\n" );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
72 mixer_getvolume( &mixer_l,&mixer_r );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
73 if ( mixer_l < 100 ) mixer_l++;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
74 if ( mixer_r < 100 ) mixer_r++;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
75 mixer_setvolume( mixer_l,mixer_r );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
76 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
77
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
78 void mixer_decvolume( void )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
79 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
80 fprintf( stderr,"[mixer] dec.\n" );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
81 mixer_getvolume( &mixer_l,&mixer_r );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
82 if ( mixer_l > 0 ) mixer_l--;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
83 if ( mixer_r > 0 ) mixer_r--;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
84 mixer_setvolume( mixer_l,mixer_r );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
85 }
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
86
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
87 int mixer_getbothvolume( void )
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
88 {
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
89 mixer_getvolume( &mixer_l,&mixer_r );
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
90 return ( mixer_l + mixer_r ) / 2;
c4b4e2aac9de ups, I missed'em..
gabucino
parents:
diff changeset
91 }