VT: only use hw decoding unless explicitely requested
[vlc.git] / modules / audio_filter / karaoke.c
blobcd89e1c5e67294a9505536da3c090602168639b9
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 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <vlc_common.h>
26 #include <vlc_aout.h>
27 #include <vlc_filter.h>
28 #include <vlc_plugin.h>
30 static int Open (vlc_object_t *);
32 vlc_module_begin ()
33 set_shortname (N_("Karaoke"))
34 set_description (N_("Simple Karaoke filter"))
35 set_category (CAT_AUDIO)
36 set_subcategory (SUBCAT_AUDIO_AFILTER)
38 set_capability ("audio filter", 0)
39 set_callbacks (Open, NULL)
40 vlc_module_end ()
42 static block_t *Process (filter_t *, block_t *);
44 static int Open (vlc_object_t *obj)
46 filter_t *filter = (filter_t *)obj;
48 if (filter->fmt_in.audio.i_channels != 2)
50 msg_Err (filter, "voice removal requires stereo");
51 return VLC_EGENERIC;
54 filter->fmt_in.audio.i_format = VLC_CODEC_FL32;
55 aout_FormatPrepare(&filter->fmt_in.audio);
56 filter->fmt_out.audio = filter->fmt_in.audio;
57 filter->pf_audio_filter = Process;
58 return VLC_SUCCESS;
61 static block_t *Process (filter_t *filter, block_t *block)
63 const float factor = .70710678 /* 1. / sqrtf (2) */;
64 float *spl = (float *)block->p_buffer;
66 for (unsigned i = block->i_nb_samples; i > 0; i--)
68 float s = (spl[0] - spl[1]) * factor;
70 *(spl++) = s;
71 *(spl++) = s;
72 /* TODO: set output format to mono */
74 (void) filter;
75 return block;