1 /*****************************************************************************
2 * karaoke.c : karaoke mode
3 *****************************************************************************
4 * Copyright © 2011 Rémi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
27 #include <vlc_common.h>
29 #include <vlc_filter.h>
30 #include <vlc_plugin.h>
32 static int Open (vlc_object_t *);
35 set_shortname (N_("Karaoke"))
36 set_description (N_("Simple Karaoke filter"))
37 set_category (CAT_AUDIO)
38 set_subcategory (SUBCAT_AUDIO_AFILTER)
40 set_capability ("audio filter", 0)
41 set_callbacks (Open, NULL)
44 static block_t *Process (filter_t *, block_t *);
46 static int Open (vlc_object_t *obj)
48 filter_t *filter = (filter_t *)obj;
50 if (filter->fmt_in.audio.i_channels != 2)
52 msg_Err (filter, "voice removal requires stereo");
56 filter->fmt_in.audio.i_format = VLC_CODEC_FL32;
57 filter->fmt_out.audio = filter->fmt_in.audio;
58 filter->pf_audio_filter = Process;
62 static block_t *Process (filter_t *filter, block_t *block)
64 const float factor = .70710678 /* 1. / sqrtf (2) */;
65 float *spl = (float *)block->p_buffer;
67 for (unsigned i = block->i_nb_samples; i > 0; i--)
69 float s = (spl[0] - spl[1]) * factor;
73 /* TODO: set output format to mono */