summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-07-17 19:21:28 +0200
committerwm4 <wm4@nowhere>2016-07-17 19:21:28 +0200
commit77e1e8e38e7b8d9318dc1bb437a88d8f13b7a5c9 (patch)
treed64c47c331174f59eeecb9a713ba76aa4b7110cb /audio
parent79974e7ad94e7658c780e3b446a7822a533675e4 (diff)
downloadmpv-77e1e8e38e7b8d9318dc1bb437a88d8f13b7a5c9.tar.bz2
mpv-77e1e8e38e7b8d9318dc1bb437a88d8f13b7a5c9.tar.xz
audio: refactor mixer code and delete mixer.c
mixer.c didn't really deserve to be separate anymore, as half of its contents were unnecessary glue code after recent changes. It also created a weird split between audio.c and af.c due to the fact that mixer.c could insert audio filters. With the code being in audio.c directly, together with other code that unserts filters during runtime, it will be possible to cleanup this code a bit and make it work like the video filter code. As part of this change, make the balance code work like the volume code, and add an option to back the current balance value. Also, since the balance semantics are unexpected for most users (panning between the audio channels, instead of just changing the relative volume), and there are some other volumes, formally deprecate both the old property and the new option.
Diffstat (limited to 'audio')
-rw-r--r--audio/mixer.c147
-rw-r--r--audio/mixer.h43
2 files changed, 0 insertions, 190 deletions
diff --git a/audio/mixer.c b/audio/mixer.c
deleted file mode 100644
index 795edfa628..0000000000
--- a/audio/mixer.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * This file is part of mpv.
- *
- * mpv is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * mpv is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with mpv. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <string.h>
-#include <stdio.h>
-#include <math.h>
-#include <assert.h>
-
-#include <libavutil/common.h>
-
-#include "config.h"
-#include "audio/filter/af.h"
-#include "common/global.h"
-#include "common/msg.h"
-#include "mpv_talloc.h"
-#include "mixer.h"
-
-struct mixer {
- struct mp_log *log;
- struct MPOpts *opts;
- struct af_stream *af;
- // Other stuff
- float balance;
-};
-
-struct mixer *mixer_init(void *talloc_ctx, struct mpv_global *global)
-{
- struct mixer *mixer = talloc_ptrtype(talloc_ctx, mixer);
- *mixer = (struct mixer) {
- .log = mp_log_new(mixer, global->log, "mixer"),
- .opts = global->opts,
- };
- return mixer;
-}
-
-bool mixer_audio_initialized(struct mixer *mixer)
-{
- return !!mixer->af;
-}
-
-// Called when opts->softvol_volume or opts->softvol_mute were changed.
-void mixer_update_volume(struct mixer *mixer)
-{
- if (!mixer->af)
- return;
-
- float gain = MPMAX(mixer->opts->softvol_volume / 100.0, 0);
- if (mixer->opts->softvol_mute == 1)
- gain = 0.0;
-
- if (!af_control_any_rev(mixer->af, AF_CONTROL_SET_VOLUME, &gain)) {
- if (gain == 1.0)
- return;
- MP_VERBOSE(mixer, "Inserting volume filter.\n");
- if (!(af_add(mixer->af, "volume", "softvol", NULL)
- && af_control_any_rev(mixer->af, AF_CONTROL_SET_VOLUME, &gain)))
- MP_ERR(mixer, "No volume control available.\n");
- }
-}
-
-void mixer_getbalance(struct mixer *mixer, float *val)
-{
- if (mixer->af)
- af_control_any_rev(mixer->af, AF_CONTROL_GET_PAN_BALANCE, &mixer->balance);
- *val = mixer->balance;
-}
-
-/* NOTE: Currently the balance code is seriously buggy: it always changes
- * the af_pan mapping between the first two input channels and first two
- * output channels to particular values. These values make sense for an
- * af_pan instance that was automatically inserted for balance control
- * only and is otherwise an identity transform, but if the filter was
- * there for another reason, then ignoring and overriding the original
- * values is completely wrong.
- */
-
-void mixer_setbalance(struct mixer *mixer, float val)
-{
- struct af_instance *af_pan_balance;
-
- mixer->balance = val;
-
- if (!mixer->af)
- return;
-
- if (af_control_any_rev(mixer->af, AF_CONTROL_SET_PAN_BALANCE, &val))
- return;
-
- if (val == 0)
- return;
-
- if (!(af_pan_balance = af_add(mixer->af, "pan", "autopan", NULL))) {
- MP_ERR(mixer, "No balance control available.\n");
- return;
- }
-
- /* make all other channels pass through since by default pan blocks all */
- for (int i = 2; i < AF_NCH; i++) {
- float level[AF_NCH] = {0};
- level[i] = 1.f;
- af_control_ext_t arg_ext = { .ch = i, .arg = level };
- af_pan_balance->control(af_pan_balance, AF_CONTROL_SET_PAN_LEVEL,
- &arg_ext);
- }
-
- af_pan_balance->control(af_pan_balance, AF_CONTROL_SET_PAN_BALANCE, &val);
-}
-
-// Called after the audio filter chain is built or rebuilt.
-// (Can be called multiple times, even without mixer_uninit() in-between.)
-void mixer_reinit_audio(struct mixer *mixer, struct af_stream *af)
-{
- mixer->af = af;
- if (!af)
- return;
-
- if (mixer->opts->softvol == SOFTVOL_NO)
- MP_ERR(mixer, "--softvol=no is not supported anymore.\n");
-
- mixer_update_volume(mixer);
-
- if (mixer->balance != 0)
- mixer_setbalance(mixer, mixer->balance);
-}
-
-/* Called before uninitializing the audio filter chain. The main purpose is to
- * turn off mute, in case it's a global/persistent setting which might
- * otherwise be left enabled even after this player instance exits.
- */
-void mixer_uninit_audio(struct mixer *mixer)
-{
- mixer->af = NULL;
-}
diff --git a/audio/mixer.h b/audio/mixer.h
deleted file mode 100644
index b475c12700..0000000000
--- a/audio/mixer.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * This file is part of mpv.
- *
- * mpv is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * mpv is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with mpv. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef MPLAYER_MIXER_H
-#define MPLAYER_MIXER_H
-
-#include <stdbool.h>
-
-// Values of MPOpts.softvol
-enum {
- SOFTVOL_NO = 0,
- SOFTVOL_YES = 1,
- SOFTVOL_AUTO = 2,
-};
-
-struct mpv_global;
-struct ao;
-struct af_stream;
-struct mixer;
-
-struct mixer *mixer_init(void *talloc_ctx, struct mpv_global *global);
-void mixer_reinit_audio(struct mixer *mixer, struct af_stream *af);
-void mixer_uninit_audio(struct mixer *mixer);
-bool mixer_audio_initialized(struct mixer *mixer);
-void mixer_update_volume(struct mixer *mixer);
-void mixer_getbalance(struct mixer *mixer, float *bal);
-void mixer_setbalance(struct mixer *mixer, float bal);
-
-#endif /* MPLAYER_MIXER_H */