[vlc-devel] [PATCH 2/2] audiofilter: Add softclip using Opus

Tristan Matthews tmatth at videolan.org
Wed Jun 28 19:18:46 CEST 2017


---
 NEWS                             |  1 +
 modules/MODULES_LIST             |  1 +
 modules/audio_filter/Makefile.am |  7 ++++
 modules/audio_filter/softclip.c  | 78 ++++++++++++++++++++++++++++++++++++++++
 po/POTFILES.in                   |  1 +
 5 files changed, 88 insertions(+)
 create mode 100644 modules/audio_filter/softclip.c

diff --git a/NEWS b/NEWS
index 9eae56c..e009d6c 100644
--- a/NEWS
+++ b/NEWS
@@ -148,6 +148,7 @@ Audio output:
  * Support EAC3 and TRUEHD pass-through for PulseAudio
 
 Audio filters:
+ * Add softclip filter using Opus
  * Add SoX Resampler library audio filter module (converter and resampler)
  * a52tospdif and dtstospdif audio converters are merged into tospdif,
    this new converter can convert AC3, DTS, EAC3 and TRUEHD to a IEC61937 frame
diff --git a/modules/MODULES_LIST b/modules/MODULES_LIST
index 04468e4..7c6e2d7 100644
--- a/modules/MODULES_LIST
+++ b/modules/MODULES_LIST
@@ -352,6 +352,7 @@ $Id$
  * smb: SMB shares access module
  * smf: Standard MIDI file demuxer
  * sndio: OpenBSD sndio audio output
+ * softclip: Soft clip using Opus
  * soxr: SoX Resampler library audio filter
  * spatializer: A spatializer audio filter
  * spdif: S/PDIF audio pass-through decoder
diff --git a/modules/audio_filter/Makefile.am b/modules/audio_filter/Makefile.am
index b935045..bf0fe94 100644
--- a/modules/audio_filter/Makefile.am
+++ b/modules/audio_filter/Makefile.am
@@ -118,3 +118,10 @@ libspeex_resampler_plugin_la_LIBADD = $(SPEEXDSP_LIBS)
 if HAVE_SPEEXDSP
 audio_filter_LTLIBRARIES += libspeex_resampler_plugin.la
 endif
+
+libopus_softclip_plugin_la_SOURCES = audio_filter/softclip.c
+libopus_softclip_plugin_la_CFLAGS = $(AM_CFLAGS) $(OPUS_CFLAGS)
+libopus_softclip_plugin_la_LIBADD = $(OPUS_LIBS)
+if HAVE_OPUS
+audio_filter_LTLIBRARIES += libopus_softclip_plugin.la
+endif
diff --git a/modules/audio_filter/softclip.c b/modules/audio_filter/softclip.c
new file mode 100644
index 0000000..1552d09
--- /dev/null
+++ b/modules/audio_filter/softclip.c
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ * softclip.c : soft clip using Opus
+ *****************************************************************************
+ * Copyright © 2017 Tristan Matthews
+ *
+ * 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 <vlc_common.h>
+#include <vlc_aout.h>
+#include <vlc_filter.h>
+#include <vlc_plugin.h>
+
+#include <opus.h>
+
+static int Open (vlc_object_t *);
+static void Close (vlc_object_t *);
+
+vlc_module_begin ()
+    set_shortname (N_("Softclip"))
+    set_description (N_("Opus softclip"))
+    set_category (CAT_AUDIO)
+    set_subcategory (SUBCAT_AUDIO_AFILTER)
+
+    set_capability ("audio filter", 50)
+    set_callbacks (Open, Close)
+vlc_module_end ()
+
+static block_t *Process (filter_t *, block_t *);
+
+static int Open (vlc_object_t *obj)
+{
+    filter_t *filter = (filter_t *)obj;
+
+    filter->fmt_out.audio.i_format = filter->fmt_in.audio.i_format = VLC_CODEC_FL32;
+    /* Cannot remix */
+    if (filter->fmt_in.audio.i_physical_channels != filter->fmt_out.audio.i_physical_channels
+     || filter->fmt_in.audio.i_original_channels != filter->fmt_out.audio.i_original_channels)
+        return VLC_EGENERIC;
+
+    filter->pf_audio_filter = Process;
+    filter->p_sys = calloc( AOUT_CHAN_MAX, sizeof( float ) );
+    if( unlikely( filter->p_sys == NULL ) )
+        return VLC_ENOMEM;
+
+    return VLC_SUCCESS;
+}
+
+static block_t *Process (filter_t *filter, block_t *block)
+{
+    float *p_softclip_state = (float *)filter->p_sys;
+    int channels = aout_FormatNbChannels(&filter->fmt_in.audio);
+    opus_pcm_soft_clip((float *)block->p_buffer, block->i_nb_samples, channels,
+        p_softclip_state);
+    return block;
+}
+
+static void Close (vlc_object_t *obj)
+{
+    filter_t *filter = (filter_t *)obj;
+    free(filter->p_sys);
+}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 66ea2dd..38a68ad 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -288,6 +288,7 @@ modules/audio_filter/resampler/speex.c
 modules/audio_filter/resampler/src.c
 modules/audio_filter/resampler/ugly.c
 modules/audio_filter/scaletempo.c
+modules/audio_filter/softclip.c
 modules/audio_filter/spatializer/allpass.cpp
 modules/audio_filter/spatializer/allpass.hpp
 modules/audio_filter/spatializer/comb.cpp
-- 
2.7.4



More information about the vlc-devel mailing list