10 #include "libao2/audio_out.h"
16 char * mixer_device
=NULL
;
17 char * mixer_channel
=NULL
;
19 float soft_vol_max
= 110.0;
21 void mixer_getvolume(mixer_t
*mixer
, float *l
, float *r
)
27 CONTROL_OK
!= mixer
->audio_out
->control(AOCONTROL_GET_VOLUME
,&vol
)) {
31 float db_vals
[AF_NCH
];
32 if (!af_control_any_rev(mixer
->afilter
,
33 AF_CONTROL_VOLUME_LEVEL
| AF_CONTROL_GET
, db_vals
))
34 db_vals
[0] = db_vals
[1] = 1.0;
36 af_from_dB (2, db_vals
, db_vals
, 20.0, -200.0, 60.0);
37 vol
.left
= (db_vals
[0] / (soft_vol_max
/ 100.0)) * 100.0;
38 vol
.right
= (db_vals
[1] / (soft_vol_max
/ 100.0)) * 100.0;
46 void mixer_setvolume(mixer_t
*mixer
, float l
, float r
)
49 vol
.right
=r
; vol
.left
=l
;
52 CONTROL_OK
!= mixer
->audio_out
->control(AOCONTROL_SET_VOLUME
,&vol
)) {
56 // af_volume uses values in dB
57 float db_vals
[AF_NCH
];
59 db_vals
[0] = (l
/ 100.0) * (soft_vol_max
/ 100.0);
60 db_vals
[1] = (r
/ 100.0) * (soft_vol_max
/ 100.0);
61 for (i
= 2; i
< AF_NCH
; i
++) {
62 db_vals
[i
] = ((l
+ r
) / 100.0) * (soft_vol_max
/ 100.0) / 2.0;
64 af_to_dB (AF_NCH
, db_vals
, db_vals
, 20.0);
65 if (!af_control_any_rev(mixer
->afilter
,
66 AF_CONTROL_VOLUME_LEVEL
| AF_CONTROL_SET
, db_vals
)) {
67 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, MSGTR_InsertingAfVolume
);
68 if (af_add(mixer
->afilter
, "volume")) {
69 if (!af_control_any_rev(mixer
->afilter
,
70 AF_CONTROL_VOLUME_LEVEL
| AF_CONTROL_SET
, db_vals
)) {
71 mp_msg(MSGT_GLOBAL
, MSGL_ERR
, MSGTR_NoVolume
);
82 void mixer_incvolume(mixer_t
*mixer
)
84 float mixer_l
, mixer_r
;
85 mixer_getvolume(mixer
, &mixer_l
, &mixer_r
);
86 mixer_l
+= mixer
->volstep
;
87 if ( mixer_l
> 100 ) mixer_l
= 100;
88 mixer_r
+= mixer
->volstep
;
89 if ( mixer_r
> 100 ) mixer_r
= 100;
90 mixer_setvolume(mixer
, mixer_l
, mixer_r
);
93 void mixer_decvolume(mixer_t
*mixer
)
95 float mixer_l
, mixer_r
;
96 mixer_getvolume(mixer
, &mixer_l
, &mixer_r
);
97 mixer_l
-= mixer
->volstep
;
98 if ( mixer_l
< 0 ) mixer_l
= 0;
99 mixer_r
-= mixer
->volstep
;
100 if ( mixer_r
< 0 ) mixer_r
= 0;
101 mixer_setvolume(mixer
, mixer_l
, mixer_r
);
104 void mixer_getbothvolume(mixer_t
*mixer
, float *b
)
106 float mixer_l
, mixer_r
;
107 mixer_getvolume(mixer
, &mixer_l
, &mixer_r
);
108 *b
= ( mixer_l
+ mixer_r
) / 2;
111 void mixer_mute(mixer_t
*mixer
)
113 if (mixer
->muted
) mixer_setvolume(mixer
, mixer
->last_l
, mixer
->last_r
);
116 mixer_getvolume(mixer
, &mixer
->last_l
, &mixer
->last_r
);
117 mixer_setvolume(mixer
, 0, 0);
122 void mixer_getbalance(mixer_t
*mixer
, float *val
)
127 af_control_any_rev(mixer
->afilter
,
128 AF_CONTROL_PAN_BALANCE
| AF_CONTROL_GET
, val
);
131 void mixer_setbalance(mixer_t
*mixer
, float val
)
135 af_control_ext_t arg_ext
= { .arg
= level
};
136 af_instance_t
* af_pan_balance
;
140 if (af_control_any_rev(mixer
->afilter
,
141 AF_CONTROL_PAN_BALANCE
| AF_CONTROL_SET
, &val
))
144 if (!(af_pan_balance
= af_add(mixer
->afilter
, "pan"))) {
145 mp_msg(MSGT_GLOBAL
, MSGL_ERR
, MSGTR_NoBalance
);
149 af_init(mixer
->afilter
);
150 /* make all other channels pass thru since by default pan blocks all */
151 memset(level
, 0, sizeof(level
));
152 for (i
= 2; i
< AF_NCH
; i
++) {
155 af_pan_balance
->control(af_pan_balance
,
156 AF_CONTROL_PAN_LEVEL
| AF_CONTROL_SET
, &arg_ext
);
160 af_pan_balance
->control(af_pan_balance
,
161 AF_CONTROL_PAN_BALANCE
| AF_CONTROL_SET
, &val
);