[vlc-devel] [PATCH] Karaoke Audio Filter Module
pankajdnapster at gmail.com
pankajdnapster at gmail.com
Sun Mar 20 18:35:38 CET 2011
From: Pankaj Yadav <pk at altair.videolan.org>
---
modules/audio_filter/karaoke.c | 155 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 155 insertions(+), 0 deletions(-)
create mode 100644 modules/audio_filter/karaoke.c
diff --git a/modules/audio_filter/karaoke.c b/modules/audio_filter/karaoke.c
new file mode 100644
index 0000000..9032889
--- /dev/null
+++ b/modules/audio_filter/karaoke.c
@@ -0,0 +1,155 @@
+/*****************************************************************************
+ * karaoke.c : Karaoke Audio filter
+ *****************************************************************************
+ * Copyright (C) 2011 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Pankaj Yadav <pk at videolan.org>
+ *
+ * This program 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.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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ *****************************************************************************/
+
+/****************************************************************************
+ * This is an audio filter module to remove vocals from an audio track
+ * New_Left_Sample = OldLeftSample-(OldRightSample * Coefficient)
+ ****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <math.h>
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+
+#include <vlc_aout.h>
+#include <vlc_filter.h>
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+
+static int Open ( vlc_object_t * );
+static void Close ( vlc_object_t * );
+static block_t *DoWork( filter_t *, block_t * );
+
+struct filter_sys_t
+{
+ float f_coefficient;
+};
+
+/*****************************************************************************
+ * Module descriptor
+ *****************************************************************************/
+#define COEFFICIENT_TEXT N_("Karaoke Coefficient" )
+#define COEFFICIENT_LONGTEXT N_("This is coefficient used in the karaoke algorithm." )
+
+vlc_module_begin ()
+ set_description( N_("Karaoke") )
+ set_shortname( N_("Karaoke") )
+ set_category( CAT_AUDIO )
+ set_subcategory( SUBCAT_AUDIO_AFILTER )
+ add_shortcut( "karaoke" )
+ add_float( "karaoke-coeff", 0.7, COEFFICIENT_TEXT,
+ COEFFICIENT_LONGTEXT, true )
+ set_capability( "audio filter", 0 )
+ set_callbacks( Open, Close )
+vlc_module_end ()
+
+/*****************************************************************************
+ * Open: initialize and create stuff
+ *****************************************************************************/
+static int Open( vlc_object_t *p_this )
+{
+ filter_t *p_filter = (filter_t*)p_this;
+ unsigned i_channels;
+ filter_sys_t *p_sys;
+
+ if( p_filter->fmt_in.audio.i_format != VLC_CODEC_FL32 ||
+ p_filter->fmt_out.audio.i_format != VLC_CODEC_FL32 )
+ {
+ p_filter->fmt_in.audio.i_format = VLC_CODEC_FL32;
+ p_filter->fmt_out.audio.i_format = VLC_CODEC_FL32;
+ msg_Warn( p_filter, "Input and Output format should be VLC_CODEC_FL32 in order to use this filter.Forcing VLC_CODEC_FL32" );
+ return VLC_EGENERIC;
+ }
+
+ if ( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) )
+ {
+ memcpy( &p_filter->fmt_out.audio, &p_filter->fmt_in.audio,
+ sizeof(audio_sample_format_t) );
+ msg_Warn( p_filter, "input and output formats are not similar" );
+ return VLC_EGENERIC;
+ }
+
+ p_filter->pf_audio_filter = DoWork;
+
+ i_channels = aout_FormatNbChannels( &p_filter->fmt_in.audio );
+
+ if( i_channels < 2 )
+ {
+ msg_Warn( p_filter, "Karaoke Filter needs at least two channels." );
+ return VLC_EGENERIC;
+ }
+
+ p_sys = p_filter->p_sys = malloc( sizeof( *p_sys ) );
+ if( !p_sys )
+ return VLC_ENOMEM;
+
+ p_sys->f_coefficient = var_InheritFloat( p_this, "karaoke-coeff");
+
+ return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * DoWork : normalizes and sends a buffer
+ *****************************************************************************/
+static block_t *DoWork( filter_t *p_filter, block_t *p_in_buf )
+{
+
+ int i_samples = p_in_buf->i_nb_samples;
+ int i_channels = aout_FormatNbChannels( &p_filter->fmt_in.audio );
+ float *p_out = (float*)p_in_buf->p_buffer;
+ float *p_in = (float*)p_in_buf->p_buffer;
+
+ struct filter_sys_t *p_sys = p_filter->p_sys;
+
+ for(int i = 0 ; i < i_samples; i++ )
+ {
+ p_out[0] = (p_in[0] - p_in[1] )* p_sys->f_coefficient ;
+ p_out[1] = p_out[0] ;
+ p_in += i_channels;
+ p_out += i_channels;
+ }
+
+ return p_in_buf;
+}
+
+/**********************************************************************
+ * Close
+ **********************************************************************/
+static void Close( vlc_object_t *p_this )
+{
+ filter_t *p_filter = (filter_t*)p_this;
+ filter_sys_t *p_sys = p_filter->p_sys;
+
+ free( p_sys );
+}
+
--
1.7.4.1
More information about the vlc-devel
mailing list