[vlc-commits] aout: add common helpers for software amplification

Rémi Denis-Courmont git at videolan.org
Thu Jul 19 19:42:00 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Jul 19 17:40:35 2012 +0300| [db635d17d86e4a98bb80795fd53408fff77406d8] | committer: Rémi Denis-Courmont

aout: add common helpers for software amplification

These helper handle mute (i.e. zero gain) and keep track of the volume
across sessions on a per-output basis. This is intended for the "old"
audio outputs that cannot amplify natively.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=db635d17d86e4a98bb80795fd53408fff77406d8
---

 modules/audio_output/volume.h |   87 +++++++++++++++++++++++++++++++++++++++++
 po/POTFILES.in                |    1 +
 2 files changed, 88 insertions(+)

diff --git a/modules/audio_output/volume.h b/modules/audio_output/volume.h
new file mode 100644
index 0000000..2c07a5e
--- /dev/null
+++ b/modules/audio_output/volume.h
@@ -0,0 +1,87 @@
+/*****************************************************************************
+ * volume.c : helper for software audio amplification
+ *****************************************************************************
+ * Copyright (C) 2012 Rémi Denis-Courmont
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdio.h>
+#include <math.h>
+#include <vlc_common.h>
+#include <vlc_aout.h>
+
+#define add_sw_gain() \
+        add_float(MODULE_STRING"-gain", 1., N_("Software gain"), \
+                  N_("This linear gain will be applied in software."), true) \
+             change_float_range(0., 8.)
+
+static int aout_SoftVolumeSet(audio_output_t *aout, float volume)
+{
+    aout_sys_t *sys = aout->sys;
+    /*
+     * Cubic mapping from software volume to amplification factor.
+     * This provides a good tradeoff between low and high volume ranges.
+     *
+     * This code is only used for the VLC software mixer. If you change this
+     * formula, be sure to update the volume-capable plugins also.
+     */
+    float gain = volume * volume * volume;
+
+    if (!sys->soft_mute && aout_GainRequest(aout, gain))
+        return -1;
+    sys->soft_gain = gain;
+    if (var_InheritBool(aout, "volume-save"))
+        config_PutFloat(aout, MODULE_STRING"-gain", gain);
+
+    aout_VolumeReport(aout, volume);
+    return 0;
+}
+
+static int aout_SoftMuteSet (audio_output_t *aout, bool mute)
+{
+    aout_sys_t *sys = aout->sys;
+
+    if (aout_GainRequest(aout, mute ? 0.f : sys->soft_gain))
+        return -1;
+    sys->soft_mute = mute;
+
+    aout_MuteReport(aout, mute);
+    return 0;
+}
+
+static void aout_SoftVolumeInit(audio_output_t *aout)
+{
+    aout_sys_t *sys = aout->sys;
+    float gain = var_InheritFloat(aout, MODULE_STRING"-gain");
+    bool mute = var_InheritBool(aout, "mute");
+
+    if (aout_GainRequest(aout, mute ? 0.f : gain))
+    {
+        mute = false;
+        gain = 1.f;
+    }
+
+    aout->volume_set = aout_SoftVolumeSet;
+    aout->mute_set = aout_SoftMuteSet;
+    sys->soft_gain = gain;
+    sys->soft_mute = mute;
+
+    aout_MuteReport(aout, mute);
+    aout_VolumeReport(aout, cbrtf(gain));
+}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 7114653..bd2e832 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -332,6 +332,7 @@ modules/audio_output/opensles_android.c
 modules/audio_output/oss.c
 modules/audio_output/pulse.c
 modules/audio_output/sndio.c
+modules/audio_output/volume.h
 modules/audio_output/wasapi.c
 modules/audio_output/waveout.c
 modules/audio_output/windows_audio_common.h



More information about the vlc-commits mailing list