30429
|
1 /*
|
|
2 * This file is part of MPlayer.
|
|
3 *
|
|
4 * MPlayer is free software; you can redistribute it and/or modify
|
|
5 * it under the terms of the GNU General Public License as published by
|
|
6 * the Free Software Foundation; either version 2 of the License, or
|
|
7 * (at your option) any later version.
|
|
8 *
|
|
9 * MPlayer is distributed in the hope that it will be useful,
|
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 * GNU General Public License for more details.
|
|
13 *
|
|
14 * You should have received a copy of the GNU General Public License along
|
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
17 */
|
|
18
|
441
|
19 #include <string.h>
|
9772
|
20 #ifndef __MINGW32__
|
441
|
21 #include <sys/ioctl.h>
|
9772
|
22 #endif
|
441
|
23 #include <fcntl.h>
|
|
24 #include <stdio.h>
|
605
|
25 #include <unistd.h>
|
441
|
26
|
1038
|
27 #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
diff
changeset
|
28 #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
diff
changeset
|
29 #include "libaf/af.h"
|
441
|
30 #include "mixer.h"
|
1038
|
31
|
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
32 #include "help_mp.h"
|
1061
|
33
|
4788
|
34 char * mixer_device=NULL;
|
11837
|
35 char * mixer_channel=NULL;
|
13933
|
36 int soft_vol = 0;
|
|
37 float soft_vol_max = 110.0;
|
441
|
38
|
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
39 void mixer_getvolume(mixer_t *mixer, float *l, float *r)
|
441
|
40 {
|
4788
|
41 ao_control_vol_t vol;
|
|
42 *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
diff
changeset
|
43 if(mixer->audio_out){
|
13933
|
44 if(soft_vol ||
|
|
45 CONTROL_OK != mixer->audio_out->control(AOCONTROL_GET_VOLUME,&vol)) {
|
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
46 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
diff
changeset
|
47 return;
|
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
48 else {
|
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
49 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
diff
changeset
|
50 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
diff
changeset
|
51 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
diff
changeset
|
52 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
diff
changeset
|
53 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
diff
changeset
|
54 af_from_dB (2, db_vals, db_vals, 20.0, -200.0, 60.0);
|
13933
|
55 vol.left = (db_vals[0] / (soft_vol_max / 100.0)) * 100.0;
|
|
56 vol.right = (db_vals[1] / (soft_vol_max / 100.0)) * 100.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
diff
changeset
|
57 }
|
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
58 }
|
4788
|
59 *r=vol.right;
|
|
60 *l=vol.left;
|
441
|
61 }
|
|
62 }
|
|
63
|
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
64 void mixer_setvolume(mixer_t *mixer, float l, float r)
|
441
|
65 {
|
4788
|
66 ao_control_vol_t vol;
|
|
67 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
diff
changeset
|
68 if(mixer->audio_out){
|
13933
|
69 if(soft_vol ||
|
|
70 CONTROL_OK != mixer->audio_out->control(AOCONTROL_SET_VOLUME,&vol)) {
|
12688
|
71 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
diff
changeset
|
72 return;
|
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
73 else {
|
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
74 // 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
diff
changeset
|
75 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
diff
changeset
|
76 int i;
|
13933
|
77 db_vals[0] = (l / 100.0) * (soft_vol_max / 100.0);
|
|
78 db_vals[1] = (r / 100.0) * (soft_vol_max / 100.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
diff
changeset
|
79 for (i = 2; i < AF_NCH; i++) {
|
13933
|
80 db_vals[i] = ((l + r) / 100.0) * (soft_vol_max / 100.0) / 2.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
diff
changeset
|
81 }
|
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
82 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
diff
changeset
|
83 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
diff
changeset
|
84 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
diff
changeset
|
85 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
diff
changeset
|
86 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
diff
changeset
|
87 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
diff
changeset
|
88 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
diff
changeset
|
89 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
diff
changeset
|
90 return;
|
7b9b4f07d2c4
automatic loading of af_volume, original patch by Dan Christiansen (danchr (at) daimi (dot) au (dot) dk)
reimar
diff
changeset
|
91 }
|
7b9b4f07d2c4
automatic loading of af_volume, original patch by Dan Christiansen (danchr (at) daimi (dot) au (dot) dk)
reimar
diff
changeset
|
92 }
|
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
93 }
|
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
94 }
|
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
95 }
|
1038
|
96 }
|
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
97 mixer->muted=0;
|
1038
|
98 }
|
1061
|
99
|
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
100 void mixer_incvolume(mixer_t *mixer)
|
441
|
101 {
|
1038
|
102 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
diff
changeset
|
103 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
diff
changeset
|
104 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
diff
changeset
|
105 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
diff
changeset
|
106 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
diff
changeset
|
107 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
diff
changeset
|
108 mixer_setvolume(mixer, mixer_l, mixer_r);
|
441
|
109 }
|
|
110
|
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
111 void mixer_decvolume(mixer_t *mixer)
|
441
|
112 {
|
1038
|
113 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
diff
changeset
|
114 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
diff
changeset
|
115 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
diff
changeset
|
116 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
diff
changeset
|
117 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
diff
changeset
|
118 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
diff
changeset
|
119 mixer_setvolume(mixer, mixer_l, mixer_r);
|
441
|
120 }
|
4788
|
121
|
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
122 void mixer_getbothvolume(mixer_t *mixer, float *b)
|
6311
|
123 {
|
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
124 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
diff
changeset
|
125 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
diff
changeset
|
126 *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
diff
changeset
|
127 }
|
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
128
|
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
129 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
diff
changeset
|
130 {
|
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
131 if (mixer->muted) mixer_setvolume(mixer, mixer->last_l, mixer->last_r);
|
6311
|
132 else
|
29263
|
133 {
|
12672
9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
alex
diff
changeset
|
134 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
diff
changeset
|
135 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
diff
changeset
|
136 mixer->muted=1;
|
6311
|
137 }
|
|
138 }
|
23568
|
139
|
|
140 void mixer_getbalance(mixer_t *mixer, float *val)
|
|
141 {
|
|
142 *val = 0.f;
|
|
143 if(!mixer->afilter)
|
|
144 return;
|
|
145 af_control_any_rev(mixer->afilter,
|
|
146 AF_CONTROL_PAN_BALANCE | AF_CONTROL_GET, val);
|
|
147 }
|
|
148
|
|
149 void mixer_setbalance(mixer_t *mixer, float val)
|
|
150 {
|
|
151 float level[AF_NCH];
|
|
152 int i;
|
|
153 af_control_ext_t arg_ext = { .arg = level };
|
|
154 af_instance_t* af_pan_balance;
|
|
155
|
|
156 if(!mixer->afilter)
|
|
157 return;
|
|
158 if (af_control_any_rev(mixer->afilter,
|
|
159 AF_CONTROL_PAN_BALANCE | AF_CONTROL_SET, &val))
|
|
160 return;
|
|
161
|
|
162 if (!(af_pan_balance = af_add(mixer->afilter, "pan"))) {
|
|
163 mp_msg(MSGT_GLOBAL, MSGL_ERR, MSGTR_NoBalance);
|
|
164 return;
|
|
165 }
|
|
166
|
|
167 af_init(mixer->afilter);
|
|
168 /* make all other channels pass thru since by default pan blocks all */
|
|
169 memset(level, 0, sizeof(level));
|
|
170 for (i = 2; i < AF_NCH; i++) {
|
|
171 arg_ext.ch = i;
|
|
172 level[i] = 1.f;
|
|
173 af_pan_balance->control(af_pan_balance,
|
|
174 AF_CONTROL_PAN_LEVEL | AF_CONTROL_SET, &arg_ext);
|
|
175 level[i] = 0.f;
|
|
176 }
|
|
177
|
|
178 af_pan_balance->control(af_pan_balance,
|
|
179 AF_CONTROL_PAN_BALANCE | AF_CONTROL_SET, &val);
|
|
180 }
|