annotate libaf/af_karaoke.c @ 32137:b7d5e57af959

swscale: avoid reading prior to the source buffer in planar2x() MMX2
author ramiro
date Mon, 13 Sep 2010 14:25:18 +0000
parents 0f1b5b68af32
children 8fa2f43cb760
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
1 /*
28229
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
2 * simple voice removal filter
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
3 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
4 * copyright (c) 2006 Reynaldo H. Verdejo Pinochet
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
5 * Based on code by Alex Beregszaszi for his 'center' filter.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
6 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
7 * This file is part of MPlayer.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
8 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
9 * MPlayer is free software; you can redistribute it and/or modify
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
10 * it under the terms of the GNU General Public License as published by
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
12 * (at your option) any later version.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
13 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
14 * MPlayer is distributed in the hope that it will be useful,
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
17 * GNU General Public License for more details.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
18 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
19 * You should have received a copy of the GNU General Public License along
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
20 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
22 */
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
23
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
24 #include <stdio.h>
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
25 #include <stdlib.h>
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
26 #include <string.h>
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
27
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
28 #include "af.h"
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
29
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
30 // Data for specific instances of this filter
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
31
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
32 // Initialization and runtime control
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
33 static int control(struct af_instance_s* af, int cmd, void* arg)
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
34 {
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
35 switch(cmd){
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
36 case AF_CONTROL_REINIT:
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
37 af->data->rate = ((af_data_t*)arg)->rate;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
38 af->data->nch = ((af_data_t*)arg)->nch;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
39 af->data->format= AF_FORMAT_FLOAT_NE;
19199
ff3ed01e9043 fix wrong and unrelated change done in r19199
reynaldo
parents: 19194
diff changeset
40 af->data->bps = 4;
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
41 return af_test_output(af,(af_data_t*)arg);
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
42 }
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
43 return AF_UNKNOWN;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
44 }
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
45
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
46 // Deallocate memory
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
47 static void uninit(struct af_instance_s* af)
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
48 {
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
49 if(af->data)
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
50 free(af->data);
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
51 }
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
52
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
53 // Filter data through filter
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
54 static af_data_t* play(struct af_instance_s* af, af_data_t* data)
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
55 {
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
56 af_data_t* c = data; // Current working data
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
57 float* a = c->audio; // Audio data
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
58 int len = c->len/4; // Number of samples in current audio block
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
59 int nch = c->nch; // Number of channels
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
60 register int i;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
61
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
62 /*
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
63 FIXME1 add a low band pass filter to avoid suppressing
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
64 centered bass/drums
18589
de155823ef82 Fix a few minor spelling errors in comments.
corey
parents: 18470
diff changeset
65 FIXME2 better calculated* attenuation factor
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
66 */
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
67
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
68 for(i=0;i<len;i+=nch)
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
69 {
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
70 a[i] = (a[i] - a[i+1]) * 0.7;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
71 a[i+1]=a[i];
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
72 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
73
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
74 return c;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
75 }
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
76
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
77 // Allocate memory and set function pointers
22746
fd6f824ef894 Rename open to af_open so as not to conflict with a previous header definition.
diego
parents: 19199
diff changeset
78 static int af_open(af_instance_t* af){
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
79 af->control = control;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
80 af->uninit = uninit;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
81 af->play = play;
24888
b2402b4f0afa libaf: change filter input/output ratio calculations
uau
parents: 22746
diff changeset
82 af->mul = 1;
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
83 af->data = calloc(1,sizeof(af_data_t));
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
84
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
85 if(af->data == NULL)
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
86 return AF_ERROR;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
87
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
88 return AF_OK;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
89 }
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
90
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
91 // Description of this filter
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
92 af_info_t af_info_karaoke = {
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
93 "Simple karaoke/voice-removal audio filter",
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
94 "karaoke",
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
95 "Reynaldo H. Verdejo Pinochet",
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
96 "",
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
97 AF_FLAGS_NOT_REENTRANT,
22746
fd6f824ef894 Rename open to af_open so as not to conflict with a previous header definition.
diego
parents: 19199
diff changeset
98 af_open
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
99 };