annotate libaf/af_karaoke.c @ 19532:13599373bb02

added new helpers to allow easy metadata retrieval and make libmenu use them
author ben
date Fri, 25 Aug 2006 23:14:32 +0000
parents ff3ed01e9043
children fd6f824ef894
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
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
64 static int open(af_instance_t* af){
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;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
68 af->mul.n = 1;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
69 af->mul.d = 1;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
70 af->data = calloc(1,sizeof(af_data_t));
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
71
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
72 if(af->data == NULL)
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
73 return AF_ERROR;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
74
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
75 return AF_OK;
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
76 }
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
77
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
78 // Description of this filter
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
79 af_info_t af_info_karaoke = {
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
80 "Simple karaoke/voice-removal audio filter",
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
81 "karaoke",
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
82 "Reynaldo H. Verdejo Pinochet",
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
83 "",
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
84 AF_FLAGS_NOT_REENTRANT,
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
85 open
0ea3c732d72d New karaoke af
reynaldo
parents:
diff changeset
86 };