2 * This file is part of MPlayer.
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.
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.
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.
22 #include "libao2/audio_out.h"
28 void mixer_getvolume(mixer_t
*mixer
, float *l
, float *r
)
36 if (mixer
->softvol
|| CONTROL_OK
!= ao_control(mixer
->ao
,
37 AOCONTROL_GET_VOLUME
, &vol
)) {
38 float db_vals
[AF_NCH
];
39 if (!af_control_any_rev(mixer
->afilter
,
40 AF_CONTROL_VOLUME_LEVEL
| AF_CONTROL_GET
, db_vals
))
41 db_vals
[0] = db_vals
[1] = 1.0;
43 af_from_dB(2, db_vals
, db_vals
, 20.0, -200.0, 60.0);
44 vol
.left
= (db_vals
[0] / (mixer
->softvol_max
/ 100.0)) * 100.0;
45 vol
.right
= (db_vals
[1] / (mixer
->softvol_max
/ 100.0)) * 100.0;
51 void mixer_setvolume(mixer_t
*mixer
, float l
, float r
)
60 if (mixer
->softvol
|| CONTROL_OK
!= ao_control(mixer
->ao
,
61 AOCONTROL_SET_VOLUME
, &vol
)) {
62 // af_volume uses values in dB
63 float db_vals
[AF_NCH
];
65 db_vals
[0] = (l
/ 100.0) * (mixer
->softvol_max
/ 100.0);
66 db_vals
[1] = (r
/ 100.0) * (mixer
->softvol_max
/ 100.0);
67 for (i
= 2; i
< AF_NCH
; i
++)
68 db_vals
[i
] = ((l
+ r
) / 100.0) * (mixer
->softvol_max
/ 100.0) / 2.0;
69 af_to_dB(AF_NCH
, db_vals
, db_vals
, 20.0);
70 if (!af_control_any_rev(mixer
->afilter
,
71 AF_CONTROL_VOLUME_LEVEL
| AF_CONTROL_SET
, db_vals
)) {
72 mp_tmsg(MSGT_GLOBAL
, MSGL_INFO
,
73 "[Mixer] No hardware mixing, inserting volume filter.\n");
74 if (af_add(mixer
->afilter
, "volume")) {
75 if (!af_control_any_rev(mixer
->afilter
,
76 AF_CONTROL_VOLUME_LEVEL
|AF_CONTROL_SET
, db_vals
)) {
77 mp_tmsg(MSGT_GLOBAL
, MSGL_ERR
,
78 "[Mixer] No volume control available.\n");
87 void mixer_incvolume(mixer_t
*mixer
)
89 float mixer_l
, mixer_r
;
90 mixer_getvolume(mixer
, &mixer_l
, &mixer_r
);
91 mixer_l
+= mixer
->volstep
;
94 mixer_r
+= mixer
->volstep
;
97 mixer_setvolume(mixer
, mixer_l
, mixer_r
);
100 void mixer_decvolume(mixer_t
*mixer
)
102 float mixer_l
, mixer_r
;
103 mixer_getvolume(mixer
, &mixer_l
, &mixer_r
);
104 mixer_l
-= mixer
->volstep
;
107 mixer_r
-= mixer
->volstep
;
110 mixer_setvolume(mixer
, mixer_l
, mixer_r
);
113 void mixer_getbothvolume(mixer_t
*mixer
, float *b
)
115 float mixer_l
, mixer_r
;
116 mixer_getvolume(mixer
, &mixer_l
, &mixer_r
);
117 *b
= (mixer_l
+ mixer_r
) / 2;
120 void mixer_mute(mixer_t
*mixer
)
123 mixer_setvolume(mixer
, mixer
->last_l
, mixer
->last_r
);
125 mixer_getvolume(mixer
, &mixer
->last_l
, &mixer
->last_r
);
126 mixer_setvolume(mixer
, 0, 0);
131 void mixer_getbalance(mixer_t
*mixer
, float *val
)
136 af_control_any_rev(mixer
->afilter
, AF_CONTROL_PAN_BALANCE
| AF_CONTROL_GET
,
140 void mixer_setbalance(mixer_t
*mixer
, float val
)
144 af_control_ext_t arg_ext
= { .arg
= level
};
145 af_instance_t
*af_pan_balance
;
150 if (af_control_any_rev(mixer
->afilter
,
151 AF_CONTROL_PAN_BALANCE
| AF_CONTROL_SET
, &val
))
154 if (!(af_pan_balance
= af_add(mixer
->afilter
, "pan"))) {
155 mp_tmsg(MSGT_GLOBAL
, MSGL_ERR
,
156 "[Mixer] No balance control available.\n");
160 af_init(mixer
->afilter
);
161 /* make all other channels pass thru since by default pan blocks all */
162 memset(level
, 0, sizeof(level
));
163 for (i
= 2; i
< AF_NCH
; i
++) {
166 af_pan_balance
->control(af_pan_balance
,
167 AF_CONTROL_PAN_LEVEL
| AF_CONTROL_SET
,
172 af_pan_balance
->control(af_pan_balance
,
173 AF_CONTROL_PAN_BALANCE
| AF_CONTROL_SET
, &val
);