Mercurial > mplayer.hg
annotate mixer.c @ 13349:2bfd09c32fba
Depend on bio2jack v0.3 as it fixes an important bug in JACK_Write() function patch by ismail donmez <kde@myrealbox.com>
author | faust3 |
---|---|
date | Wed, 15 Sep 2004 16:01:34 +0000 |
parents | 7b9b4f07d2c4 |
children | 75b84965d137 |
rev | line source |
---|---|
441 | 1 #include <string.h> |
9772 | 2 #ifndef __MINGW32__ |
441 | 3 #include <sys/ioctl.h> |
9772 | 4 #endif |
441 | 5 #include <fcntl.h> |
6 #include <stdio.h> | |
605 | 7 #include <unistd.h> |
441 | 8 |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
9 #include "config.h" |
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
10 #include "libao2/audio_out.h" |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
11 #include "libaf/af.h" |
441 | 12 #include "mixer.h" |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
13 |
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
14 #include "help_mp.h" |
1061 | 15 |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4749
diff
changeset
|
16 char * mixer_device=NULL; |
11837 | 17 char * mixer_channel=NULL; |
441 | 18 |
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
19 void mixer_getvolume(mixer_t *mixer, float *l, float *r) |
441 | 20 { |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4749
diff
changeset
|
21 ao_control_vol_t vol; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4749
diff
changeset
|
22 *l=0; *r=0; |
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
23 if(mixer->audio_out){ |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
24 if(CONTROL_OK != mixer->audio_out->control(AOCONTROL_GET_VOLUME,&vol)) { |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
25 if (!mixer->afilter) |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
26 return; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
27 else { |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
28 float db_vals[AF_NCH]; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
29 if (!af_control_any_rev(mixer->afilter, |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
30 AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_GET, db_vals)) |
12908
7b9b4f07d2c4
automatic loading of af_volume, original patch by Dan Christiansen (danchr (at) daimi (dot) au (dot) dk)
reimar
parents:
12688
diff
changeset
|
31 db_vals[0] = db_vals[1] = 1.0; |
7b9b4f07d2c4
automatic loading of af_volume, original patch by Dan Christiansen (danchr (at) daimi (dot) au (dot) dk)
reimar
parents:
12688
diff
changeset
|
32 else |
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
33 af_from_dB (2, db_vals, db_vals, 20.0, -200.0, 60.0); |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
34 vol.left = db_vals[0] * 90.0; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
35 vol.right = db_vals[1] * 90.0; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
36 } |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
37 } |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4749
diff
changeset
|
38 *r=vol.right; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4749
diff
changeset
|
39 *l=vol.left; |
441 | 40 } |
41 } | |
42 | |
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
43 void mixer_setvolume(mixer_t *mixer, float l, float r) |
441 | 44 { |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4749
diff
changeset
|
45 ao_control_vol_t vol; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4749
diff
changeset
|
46 vol.right=r; vol.left=l; |
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
47 if(mixer->audio_out){ |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
48 if(CONTROL_OK != mixer->audio_out->control(AOCONTROL_SET_VOLUME,&vol)) { |
12688 | 49 if (!mixer->afilter) |
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
50 return; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
51 else { |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
52 // af_volume uses values in dB |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
53 float db_vals[AF_NCH]; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
54 int i; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
55 // a volume of 90% will give 0 dB (no change) |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
56 // like this, amplification is possible as well |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
57 db_vals[0] = l / 90.0; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
58 db_vals[1] = r / 90.0; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
59 for (i = 2; i < AF_NCH; i++) { |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
60 db_vals[i] = (l + r) / 180.0; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
61 } |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
62 af_to_dB (AF_NCH, db_vals, db_vals, 20.0); |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
63 if (!af_control_any_rev(mixer->afilter, |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
64 AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_SET, db_vals)) { |
12908
7b9b4f07d2c4
automatic loading of af_volume, original patch by Dan Christiansen (danchr (at) daimi (dot) au (dot) dk)
reimar
parents:
12688
diff
changeset
|
65 mp_msg(MSGT_GLOBAL, MSGL_INFO, MSGTR_InsertingAfVolume); |
7b9b4f07d2c4
automatic loading of af_volume, original patch by Dan Christiansen (danchr (at) daimi (dot) au (dot) dk)
reimar
parents:
12688
diff
changeset
|
66 if (af_add(mixer->afilter, "volume")) { |
7b9b4f07d2c4
automatic loading of af_volume, original patch by Dan Christiansen (danchr (at) daimi (dot) au (dot) dk)
reimar
parents:
12688
diff
changeset
|
67 if (!af_control_any_rev(mixer->afilter, |
7b9b4f07d2c4
automatic loading of af_volume, original patch by Dan Christiansen (danchr (at) daimi (dot) au (dot) dk)
reimar
parents:
12688
diff
changeset
|
68 AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_SET, db_vals)) { |
7b9b4f07d2c4
automatic loading of af_volume, original patch by Dan Christiansen (danchr (at) daimi (dot) au (dot) dk)
reimar
parents:
12688
diff
changeset
|
69 mp_msg(MSGT_GLOBAL, MSGL_ERR, MSGTR_NoVolume); |
7b9b4f07d2c4
automatic loading of af_volume, original patch by Dan Christiansen (danchr (at) daimi (dot) au (dot) dk)
reimar
parents:
12688
diff
changeset
|
70 return; |
7b9b4f07d2c4
automatic loading of af_volume, original patch by Dan Christiansen (danchr (at) daimi (dot) au (dot) dk)
reimar
parents:
12688
diff
changeset
|
71 } |
7b9b4f07d2c4
automatic loading of af_volume, original patch by Dan Christiansen (danchr (at) daimi (dot) au (dot) dk)
reimar
parents:
12688
diff
changeset
|
72 } |
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
73 } |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
74 } |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
75 } |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
76 } |
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
77 mixer->muted=0; |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
78 } |
1061 | 79 |
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
80 void mixer_incvolume(mixer_t *mixer) |
441 | 81 { |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
82 float mixer_l, mixer_r; |
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
83 mixer_getvolume(mixer, &mixer_l, &mixer_r); |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
84 mixer_l += mixer->volstep; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
85 if ( mixer_l > 100 ) mixer_l = 100; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
86 mixer_r += mixer->volstep; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
87 if ( mixer_r > 100 ) mixer_r = 100; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
88 mixer_setvolume(mixer, mixer_l, mixer_r); |
441 | 89 } |
90 | |
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
91 void mixer_decvolume(mixer_t *mixer) |
441 | 92 { |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
93 float mixer_l, mixer_r; |
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
94 mixer_getvolume(mixer, &mixer_l, &mixer_r); |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
95 mixer_l -= mixer->volstep; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
96 if ( mixer_l < 0 ) mixer_l = 0; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
97 mixer_r -= mixer->volstep; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
98 if ( mixer_r < 0 ) mixer_r = 0; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
99 mixer_setvolume(mixer, mixer_l, mixer_r); |
441 | 100 } |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4749
diff
changeset
|
101 |
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
102 void mixer_getbothvolume(mixer_t *mixer, float *b) |
6311
da2dda48b7ec
add mute support ( step 1 ) and fixed panscan bugs (1000l for me)
pontscho
parents:
4788
diff
changeset
|
103 { |
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
104 float mixer_l, mixer_r; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
105 mixer_getvolume(mixer, &mixer_l, &mixer_r); |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
106 *b = ( mixer_l + mixer_r ) / 2; |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
107 } |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
108 |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
109 void mixer_mute(mixer_t *mixer) |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
110 { |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
111 if (mixer->muted) mixer_setvolume(mixer, mixer->last_l, mixer->last_r); |
6311
da2dda48b7ec
add mute support ( step 1 ) and fixed panscan bugs (1000l for me)
pontscho
parents:
4788
diff
changeset
|
112 else |
da2dda48b7ec
add mute support ( step 1 ) and fixed panscan bugs (1000l for me)
pontscho
parents:
4788
diff
changeset
|
113 { |
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
114 mixer_getvolume(mixer, &mixer->last_l, &mixer->last_r); |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
115 mixer_setvolume(mixer, 0, 0); |
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
parents:
11837
diff
changeset
|
116 mixer->muted=1; |
6311
da2dda48b7ec
add mute support ( step 1 ) and fixed panscan bugs (1000l for me)
pontscho
parents:
4788
diff
changeset
|
117 } |
da2dda48b7ec
add mute support ( step 1 ) and fixed panscan bugs (1000l for me)
pontscho
parents:
4788
diff
changeset
|
118 } |