[vlc-devel] [PATCH 2/2] audiofilter: add softclip using Opus
Tristan Matthews
tmatth at videolan.org
Thu Jun 29 00:16:39 CEST 2017
---
NEWS | 1 +
modules/MODULES_LIST | 2 +-
modules/codec/opus.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 46 insertions(+), 1 deletion(-)
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..aa2e223 100644
--- a/modules/MODULES_LIST
+++ b/modules/MODULES_LIST
@@ -274,7 +274,7 @@ $Id$
* opencv_example: OpenCV example (face identification)
* opencv_wrapper: OpenCV wrapper video filter
* opensles_android: OpenSL ES audio output for Android
- * opus: a opus audio decoder/packetizer/encoder using the libopus library
+ * opus: a opus audio decoder/packetizer/encoder/filter using the libopus library
* os2drive: service discovery for OS/2 drives
* oss: audio output module using the OSS /dev/dsp interface
* osx_notifications: announce currently playing stream to OS X/Growl
diff --git a/modules/codec/opus.c b/modules/codec/opus.c
index a5953bc..7c2cdd1 100644
--- a/modules/codec/opus.c
+++ b/modules/codec/opus.c
@@ -33,6 +33,7 @@
#include <vlc_input.h>
#include <vlc_codec.h>
#include <vlc_aout.h>
+#include <vlc_filter.h>
#include "../demux/xiph.h"
#include <ogg/ogg.h>
@@ -54,6 +55,8 @@ static void CloseDecoder ( vlc_object_t * );
static int OpenEncoder ( vlc_object_t * );
static void CloseEncoder ( vlc_object_t * );
#endif
+static int OpenFilter ( vlc_object_t * );
+static void CloseFilter ( vlc_object_t * );
vlc_module_begin ()
set_category( CAT_INPUT )
@@ -72,8 +75,16 @@ vlc_module_begin ()
set_callbacks( OpenEncoder, CloseEncoder )
#endif
+ add_submodule ()
+ set_shortname( N_("Softclip") )
+ set_description( N_("Opus softclip") )
+ set_capability( "audio filter", 50 )
+ set_callbacks( OpenFilter, CloseFilter )
+
vlc_module_end ()
+static block_t *ApplyFilter (filter_t *, block_t *);
+
/*****************************************************************************
* decoder_sys_t : opus decoder descriptor
*****************************************************************************/
@@ -743,3 +754,36 @@ static void CloseEncoder(vlc_object_t *p_this)
free(sys);
}
#endif /* ENABLE_SOUT */
+
+static int OpenFilter (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 = ApplyFilter;
+ filter->p_sys = calloc( AOUT_CHAN_MAX, sizeof( float ) );
+ if( unlikely( filter->p_sys == NULL ) )
+ return VLC_ENOMEM;
+
+ return VLC_SUCCESS;
+}
+
+static block_t *ApplyFilter (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 CloseFilter (vlc_object_t *obj)
+{
+ filter_t *filter = (filter_t *)obj;
+ free(filter->p_sys);
+}
--
2.7.4
More information about the vlc-devel
mailing list