]> git.sesse.net Git - vlc/blob - modules/audio_filter/karaoke.c
mediacodec: handle error_state in one place
[vlc] / modules / audio_filter / karaoke.c
1 /*****************************************************************************
2  * karaoke.c : karaoke mode
3  *****************************************************************************
4  * Copyright © 2011 Rémi Denis-Courmont
5  *
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.
10  *
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.
15  *
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  *****************************************************************************/
20
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
24
25 #include <assert.h>
26
27 #include <vlc_common.h>
28 #include <vlc_aout.h>
29 #include <vlc_filter.h>
30 #include <vlc_plugin.h>
31
32 static int Open (vlc_object_t *);
33
34 vlc_module_begin ()
35     set_shortname (N_("Karaoke"))
36     set_description (N_("Simple Karaoke filter"))
37     set_category (CAT_AUDIO)
38     set_subcategory (SUBCAT_AUDIO_AFILTER)
39
40     set_capability ("audio filter", 0)
41     set_callbacks (Open, NULL)
42 vlc_module_end ()
43
44 static block_t *Process (filter_t *, block_t *);
45
46 static int Open (vlc_object_t *obj)
47 {
48     filter_t *filter = (filter_t *)obj;
49
50     if (filter->fmt_in.audio.i_channels != 2)
51     {
52         msg_Err (filter, "voice removal requires stereo");
53         return VLC_EGENERIC;
54     }
55
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;
59     return VLC_SUCCESS;
60 }
61
62 static block_t *Process (filter_t *filter, block_t *block)
63 {
64     const float factor = .70710678 /* 1. / sqrtf (2) */;
65     float *spl = (float *)block->p_buffer;
66
67     for (unsigned i = block->i_nb_samples; i > 0; i--)
68     {
69         float s = (spl[0] - spl[1]) * factor;
70
71         *(spl++) = s;
72         *(spl++) = s;
73         /* TODO: set output format to mono */
74     }
75     (void) filter;
76     return block;
77 }