annotate libaf/af_karaoke.c @ 26965:3fe9b7d8e4b2

Fix codec-specific options syntax declaration to be less confusing and wrong. The option separator is a colon, all options can receive parameters, not just the first one. Closes Bugzilla #1100.
author diego
date Fri, 06 Jun 2008 16:21:41 +0000
parents b2402b4f0afa
children 72d0b1444141
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
1 /*
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
2 (c)2006 MPlayer / Reynaldo H. Verdejo Pinochet
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
3 Based on code by Alex Beregszaszi for his 'center' filter
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
4
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
5 License: GPL
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
6
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
7 Simple voice removal filter
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
8 */
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
9
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
10 #include <stdio.h>
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
11 #include <stdlib.h>
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
12 #include <string.h>
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
13
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
14 #include "af.h"
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
15
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
16 // Data for specific instances of this filter
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
17
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
18 // Initialization and runtime control
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
19 static int control(struct af_instance_s* af, int cmd, void* arg)
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
20 {
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
21 switch(cmd){
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
22 case AF_CONTROL_REINIT:
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
23 af->data->rate = ((af_data_t*)arg)->rate;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
24 af->data->nch = ((af_data_t*)arg)->nch;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
25 af->data->format= AF_FORMAT_FLOAT_NE;
19199
ff3ed01e9043 fix wrong and unrelated change done in r19199
reynaldo
parents: 19194
diff changeset
26 af->data->bps = 4;
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
27 return af_test_output(af,(af_data_t*)arg);
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
28 }
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
29 return AF_UNKNOWN;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
30 }
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
31
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
32 // Deallocate memory
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
33 static void uninit(struct af_instance_s* af)
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
34 {
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
35 if(af->data)
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
36 free(af->data);
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
37 }
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
38
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
39 // Filter data through filter
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
40 static af_data_t* play(struct af_instance_s* af, af_data_t* data)
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
41 {
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
42 af_data_t* c = data; // Current working data
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
43 float* a = c->audio; // Audio data
19199
ff3ed01e9043 fix wrong and unrelated change done in r19199
reynaldo
parents: 19194
diff changeset
44 int len = c->len/4; // Number of samples in current audio block
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
45 int nch = c->nch; // Number of channels
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
46 register int i;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
47
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
48 /*
18589
de155823ef82 Fix a few minor spelling errors in comments.
corey
parents: 18470
diff changeset
49 FIXME1 add a low band pass filter to avoid suppressing
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
50 centered bass/drums
18589
de155823ef82 Fix a few minor spelling errors in comments.
corey
parents: 18470
diff changeset
51 FIXME2 better calculated* attenuation factor
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
52 */
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
53
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
54 for(i=0;i<len;i+=nch)
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
55 {
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
56 a[i] = (a[i] - a[i+1]) * 0.7;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
57 a[i+1]=a[i];
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
58 }
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
59
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
60 return c;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
61 }
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
62
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
63 // 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
64 static int af_open(af_instance_t* af){
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
65 af->control = control;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
66 af->uninit = uninit;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
67 af->play = play;
24888
b2402b4f0afa libaf: change filter input/output ratio calculations
uau
parents: 22746
diff changeset
68 af->mul = 1;
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
69 af->data = calloc(1,sizeof(af_data_t));
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
70
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
71 if(af->data == NULL)
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
72 return AF_ERROR;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
73
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
74 return AF_OK;
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 // Description of this filter
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
78 af_info_t af_info_karaoke = {
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
79 "Simple karaoke/voice-removal audio filter",
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
80 "karaoke",
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
81 "Reynaldo H. Verdejo Pinochet",
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
82 "",
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
83 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
84 af_open
18470
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
85 };