summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--DOCS/man/en/mplayer.12
-rw-r--r--DOCS/tech/slave.txt1
-rw-r--r--command.c54
-rw-r--r--etc/input.conf2
-rw-r--r--etc/menu.conf1
-rw-r--r--help/help_mp-en.h3
-rw-r--r--input/input.c3
-rw-r--r--input/input.h1
-rw-r--r--libvo/sub.c5
-rw-r--r--libvo/sub.h1
-rw-r--r--mixer.c43
-rw-r--r--mixer.h2
12 files changed, 116 insertions, 2 deletions
diff --git a/DOCS/man/en/mplayer.1 b/DOCS/man/en/mplayer.1
index 0eb0b04b20..29fdb4a3dd 100644
--- a/DOCS/man/en/mplayer.1
+++ b/DOCS/man/en/mplayer.1
@@ -238,6 +238,8 @@ Adjust audio delay by +/- 0.1 seconds.
Decrease/\:increase volume.
.IPs "9 and 0"
Decrease/\:increase volume.
+.IPs "( and )"
+Adjust audio balance in favor of left/\:right channel.
.IPs "m\ \ \ \ "
Mute sound.
.IPs "_ (MPEG-TS and libavformat only)"
diff --git a/DOCS/tech/slave.txt b/DOCS/tech/slave.txt
index b1d1158ebb..485ec20adb 100644
--- a/DOCS/tech/slave.txt
+++ b/DOCS/tech/slave.txt
@@ -419,6 +419,7 @@ time_pos time 0 X X X position in seconds
metadata str list X list of metadata key/value
metadata/* string X metadata values
volume float 0 100 X X X change volume
+balance float -1 1 X X X change audio balance
mute flag 0 1 X X X
audio_delay float -100 100 X X X
audio_format int X
diff --git a/command.c b/command.c
index dcf96df608..f8680500ac 100644
--- a/command.c
+++ b/command.c
@@ -571,6 +571,57 @@ static int mp_property_channels(m_option_t * prop, int action, void *arg,
return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
}
+/// Balance (RW)
+static int mp_property_balance(m_option_t * prop, int action, void *arg,
+ MPContext * mpctx)
+{
+ float bal;
+
+ if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
+ return M_PROPERTY_UNAVAILABLE;
+
+ switch (action) {
+ case M_PROPERTY_GET:
+ if (!arg)
+ return M_PROPERTY_ERROR;
+ mixer_getbalance(&mpctx->mixer, arg);
+ return M_PROPERTY_OK;
+ case M_PROPERTY_PRINT: {
+ char** str = arg;
+ if (!arg)
+ return M_PROPERTY_ERROR;
+ mixer_getbalance(&mpctx->mixer, &bal);
+ if (bal == 0.f)
+ *str = strdup("center");
+ else if (bal == -1.f)
+ *str = strdup("left only");
+ else if (bal == 1.f)
+ *str = strdup("right only");
+ else {
+ unsigned right = (bal + 1.f) / 2.f * 100.f;
+ *str = malloc(sizeof("left xxx%, right xxx%"));
+ sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
+ }
+ return M_PROPERTY_OK;
+ }
+ case M_PROPERTY_STEP_UP:
+ case M_PROPERTY_STEP_DOWN:
+ mixer_getbalance(&mpctx->mixer, &bal);
+ bal += (arg ? *(float*)arg : .1f) *
+ (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
+ M_PROPERTY_CLAMP(prop, bal);
+ mixer_setbalance(&mpctx->mixer, bal);
+ return M_PROPERTY_OK;
+ case M_PROPERTY_SET:
+ if (!arg)
+ return M_PROPERTY_ERROR;
+ M_PROPERTY_CLAMP(prop, *(float*)arg);
+ mixer_setbalance(&mpctx->mixer, *(float*)arg);
+ return M_PROPERTY_OK;
+ }
+ return M_PROPERTY_NOT_IMPLEMENTED;
+}
+
/// Selected audio id (RW)
static int mp_property_audio(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
@@ -1589,6 +1640,8 @@ static m_option_t mp_properties[] = {
0, 0, 0, NULL },
{ "switch_audio", mp_property_audio, CONF_TYPE_INT,
CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
+ { "balance", mp_property_balance, CONF_TYPE_FLOAT,
+ M_OPT_RANGE, -1, 1, NULL },
// Video
{ "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
@@ -1743,6 +1796,7 @@ static struct {
{ "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
{ "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
{ "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
+ { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
// video
{ "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
{ "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
diff --git a/etc/input.conf b/etc/input.conf
index ebe7539078..733cb18b08 100644
--- a/etc/input.conf
+++ b/etc/input.conf
@@ -51,6 +51,8 @@ x sub_delay +0.1 # add
6 hue 1
7 saturation -1
8 saturation 1
+( balance -0.1 # adjust audio balance in favor of left
+) balance +0.1 # right
d frame_drop
r sub_pos -1 # move subtitles up
t sub_pos +1 # down
diff --git a/etc/menu.conf b/etc/menu.conf
index 603d527495..51c329b849 100644
--- a/etc/menu.conf
+++ b/etc/menu.conf
@@ -33,6 +33,7 @@
<pref name="audio_pref" title="Audio">
<e property="volume" name="Volume"/>
+ <e property="balance" name="Balance"/>
<e property="mute" name="Mute"/>
<e property="audio_delay" name="Delay"/>
</pref>
diff --git a/help/help_mp-en.h b/help/help_mp-en.h
index 36dac3e980..e5ac9cb0bc 100644
--- a/help/help_mp-en.h
+++ b/help/help_mp-en.h
@@ -231,6 +231,7 @@ static char help_text[]=
#define MSGTR_Contrast "Contrast"
#define MSGTR_Saturation "Saturation"
#define MSGTR_Hue "Hue"
+#define MSGTR_Balance "Balance"
// property state
#define MSGTR_MuteStatus "Mute: %s"
@@ -706,6 +707,7 @@ static char help_text[]=
#define MSGTR_InsertingAfVolume "[Mixer] No hardware mixing, inserting volume filter.\n"
#define MSGTR_NoVolume "[Mixer] No volume control available.\n"
+#define MSGTR_NoBalance "[Mixer] No balance control available.\n"
// ====================== GUI messages/buttons ========================
@@ -1077,6 +1079,7 @@ static char help_text[]=
#define MSGTR_VO_SUB_Volume "Volume"
#define MSGTR_VO_SUB_Brightness "Brightness"
#define MSGTR_VO_SUB_Hue "Hue"
+#define MSGTR_VO_SUB_Balance "Balance"
// vo_xv.c
#define MSGTR_VO_XV_ImagedimTooHigh "Source image dimensions are too high: %ux%u (maximum is %ux%u)\n"
diff --git a/input/input.c b/input/input.c
index 7086782198..a37e00128c 100644
--- a/input/input.c
+++ b/input/input.c
@@ -71,6 +71,7 @@ static mp_cmd_t mp_cmds[] = {
{ MP_CMD_OSD_SHOW_TEXT, "osd_show_text", 1, { {MP_CMD_ARG_STRING, {0}}, {MP_CMD_ARG_INT,{-1}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
{ MP_CMD_OSD_SHOW_PROPERTY_TEXT, "osd_show_property_text",1, { {MP_CMD_ARG_STRING, {0}}, {MP_CMD_ARG_INT,{-1}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
{ MP_CMD_VOLUME, "volume", 1, { { MP_CMD_ARG_FLOAT,{0} }, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
+ { MP_CMD_BALANCE, "balance", 1, { { MP_CMD_ARG_FLOAT,{0} }, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
{ MP_CMD_MIXER_USEMASTER, "use_master", 0, { {-1,{0}} } },
{ MP_CMD_MUTE, "mute", 0, { {MP_CMD_ARG_INT,{-1}}, {-1,{0}} } },
{ MP_CMD_CONTRAST, "contrast",1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
@@ -363,6 +364,8 @@ static mp_cmd_bind_t def_cmd_binds[] = {
{ { '/', 0 }, "volume -1" },
{ { '0', 0 }, "volume 1" },
{ { '*', 0 }, "volume 1" },
+ { { '(', 0 }, "balance -0.1" },
+ { { ')', 0 }, "balance 0.1" },
{ { 'm', 0 }, "mute" },
{ { '1', 0 }, "contrast -1" },
{ { '2', 0 }, "contrast 1" },
diff --git a/input/input.h b/input/input.h
index 4fb51422b1..5791831954 100644
--- a/input/input.h
+++ b/input/input.h
@@ -95,6 +95,7 @@
#define MP_CMD_TV_STEP_FREQ 93
#define MP_CMD_TV_TELETEXT_ADD_DEC 94
#define MP_CMD_TV_TELETEXT_GO_LINK 95
+#define MP_CMD_BALANCE 96
#define MP_CMD_GUI_EVENTS 5000
#define MP_CMD_GUI_LOADFILE 5001
diff --git a/libvo/sub.c b/libvo/sub.c
index c901e28fe5..7a87c725aa 100644
--- a/libvo/sub.c
+++ b/libvo/sub.c
@@ -58,9 +58,10 @@ char * __sub_osd_names[]={
MSGTR_VO_SUB_Saturation,
MSGTR_VO_SUB_Volume,
MSGTR_VO_SUB_Brightness,
- MSGTR_VO_SUB_Hue
+ MSGTR_VO_SUB_Hue,
+ MSGTR_VO_SUB_Balance
};
-char * __sub_osd_names_short[] ={ "", "|>", "||", "[]", "<<" , ">>", "", "", "", "", "", ""};
+char * __sub_osd_names_short[] ={ "", "|>", "||", "[]", "<<" , ">>", "", "", "", "", "", "", "" };
//static int vo_font_loaded=-1;
font_desc_t* vo_font=NULL;
diff --git a/libvo/sub.h b/libvo/sub.h
index efc0277ba4..866eb5804e 100644
--- a/libvo/sub.h
+++ b/libvo/sub.h
@@ -91,6 +91,7 @@ extern void* vo_vobsub;
#define OSD_VOLUME 0x09
#define OSD_BRIGHTNESS 0x0A
#define OSD_HUE 0x0B
+#define OSD_BALANCE 0x0C
#define OSD_PANSCAN 0x50
#define OSD_PB_START 0x10
diff --git a/mixer.c b/mixer.c
index f3de6cdeb7..8f70b0c02d 100644
--- a/mixer.c
+++ b/mixer.c
@@ -118,3 +118,46 @@ void mixer_mute(mixer_t *mixer)
mixer->muted=1;
}
}
+
+void mixer_getbalance(mixer_t *mixer, float *val)
+{
+ *val = 0.f;
+ if(!mixer->afilter)
+ return;
+ af_control_any_rev(mixer->afilter,
+ AF_CONTROL_PAN_BALANCE | AF_CONTROL_GET, val);
+}
+
+void mixer_setbalance(mixer_t *mixer, float val)
+{
+ float level[AF_NCH];
+ int i;
+ af_control_ext_t arg_ext = { .arg = level };
+ af_instance_t* af_pan_balance;
+
+ if(!mixer->afilter)
+ return;
+ if (af_control_any_rev(mixer->afilter,
+ AF_CONTROL_PAN_BALANCE | AF_CONTROL_SET, &val))
+ return;
+
+ if (!(af_pan_balance = af_add(mixer->afilter, "pan"))) {
+ mp_msg(MSGT_GLOBAL, MSGL_ERR, MSGTR_NoBalance);
+ return;
+ }
+
+ af_init(mixer->afilter);
+ /* make all other channels pass thru since by default pan blocks all */
+ memset(level, 0, sizeof(level));
+ for (i = 2; i < AF_NCH; i++) {
+ arg_ext.ch = i;
+ level[i] = 1.f;
+ af_pan_balance->control(af_pan_balance,
+ AF_CONTROL_PAN_LEVEL | AF_CONTROL_SET, &arg_ext);
+ level[i] = 0.f;
+ }
+
+ af_pan_balance->control(af_pan_balance,
+ AF_CONTROL_PAN_BALANCE | AF_CONTROL_SET, &val);
+}
+
diff --git a/mixer.h b/mixer.h
index 26a9be18bd..3a1e332b26 100644
--- a/mixer.h
+++ b/mixer.h
@@ -23,6 +23,8 @@ void mixer_incvolume(mixer_t *mixer);
void mixer_decvolume(mixer_t *mixer);
void mixer_getbothvolume(mixer_t *mixer, float *b);
void mixer_mute(mixer_t *mixer);
+void mixer_getbalance(mixer_t *mixer, float *bal);
+void mixer_setbalance(mixer_t *mixer, float bal);
//extern void mixer_setbothvolume( int v );
#define mixer_setbothvolume(m, v) mixer_setvolume(m, v, v)