-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
karaoke.c
80 lines (67 loc) · 2.4 KB
/
karaoke.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*****************************************************************************
* karaoke.c : karaoke mode
*****************************************************************************
* Copyright © 2011 Rémi Denis-Courmont
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
#include <vlc_aout.h>
#include <vlc_filter.h>
#include <vlc_plugin.h>
static int Open (vlc_object_t *);
vlc_module_begin ()
set_shortname (N_("Karaoke"))
set_description (N_("Simple Karaoke filter"))
set_subcategory (SUBCAT_AUDIO_AFILTER)
set_capability ("audio filter", 0)
set_callback(Open)
vlc_module_end ()
static block_t *Process (filter_t *, block_t *);
static int Open (vlc_object_t *obj)
{
filter_t *filter = (filter_t *)obj;
if (filter->fmt_in.audio.i_channels != 2)
{
msg_Err (filter, "voice removal requires stereo");
return VLC_EGENERIC;
}
filter->fmt_in.audio.i_format = VLC_CODEC_FL32;
aout_FormatPrepare(&filter->fmt_in.audio);
filter->fmt_out.audio = filter->fmt_in.audio;
static const struct vlc_filter_operations filter_ops =
{
.filter_audio = Process,
};
filter->ops = &filter_ops;
return VLC_SUCCESS;
}
static block_t *Process (filter_t *filter, block_t *block)
{
const float factor = .70710678 /* 1. / sqrtf (2) */;
float *spl = (float *)block->p_buffer;
for (unsigned i = block->i_nb_samples; i > 0; i--)
{
float s = (spl[0] - spl[1]) * factor;
*(spl++) = s;
*(spl++) = s;
/* TODO: set output format to mono */
}
(void) filter;
return block;
}