Mercurial > mplayer.hg
annotate libaf/af_sinesuppress.c @ 20653:402484a85b9f
More precise bounding box calculation for karaoke effects.
author | eugeni |
---|---|
date | Sat, 04 Nov 2006 17:58:09 +0000 |
parents | e870cf316f47 |
children | fd6f824ef894 |
rev | line source |
---|---|
18082
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
1 /*============================================================================= |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
2 // |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
3 // This software has been released under the terms of the GNU General Public |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
4 // license. See http://www.gnu.org/copyleft/gpl.html for details. |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
5 // |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
6 // Copyright 2006 Michael Niedermayer |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
7 // Copyright 2004 Alex Beregszaszi & Pierre Lombard (original af_extrastereo.c upon which this is based) |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
8 // |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
9 //============================================================================= |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
10 */ |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
11 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
12 #include <stdio.h> |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
13 #include <stdlib.h> |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
14 #include <string.h> |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
15 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
16 #include <unistd.h> |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
17 #include <inttypes.h> |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
18 #include <math.h> |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
19 #include <limits.h> |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
20 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
21 #include "af.h" |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
22 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
23 // Data for specific instances of this filter |
18611
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
24 typedef struct af_sinesuppress_s |
18082
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
25 { |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
26 double freq; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
27 double decay; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
28 double real; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
29 double imag; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
30 double ref; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
31 double pos; |
18611
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
32 }af_sinesuppress_t; |
18082
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
33 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
34 static af_data_t* play_s16(struct af_instance_s* af, af_data_t* data); |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
35 static af_data_t* play_float(struct af_instance_s* af, af_data_t* data); |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
36 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
37 // Initialization and runtime control |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
38 static int control(struct af_instance_s* af, int cmd, void* arg) |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
39 { |
18611
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
40 af_sinesuppress_t* s = (af_sinesuppress_t*)af->setup; |
18082
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
41 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
42 switch(cmd){ |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
43 case AF_CONTROL_REINIT:{ |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
44 // Sanity check |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
45 if(!arg) return AF_ERROR; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
46 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
47 af->data->rate = ((af_data_t*)arg)->rate; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
48 af->data->nch = 1; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
49 #if 0 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
50 if (((af_data_t*)arg)->format == AF_FORMAT_FLOAT_NE) |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
51 { |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
52 af->data->format = AF_FORMAT_FLOAT_NE; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
53 af->data->bps = 4; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
54 af->play = play_float; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
55 }// else |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
56 #endif |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
57 { |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
58 af->data->format = AF_FORMAT_S16_NE; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
59 af->data->bps = 2; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
60 af->play = play_s16; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
61 } |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
62 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
63 return af_test_output(af,(af_data_t*)arg); |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
64 } |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
65 case AF_CONTROL_COMMAND_LINE:{ |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
66 float f1,f2; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
67 sscanf((char*)arg,"%f:%f", &f1,&f2); |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
68 s->freq = f1; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
69 s->decay = f2; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
70 return AF_OK; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
71 } |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
72 case AF_CONTROL_SS_FREQ | AF_CONTROL_SET: |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
73 s->freq = *(float*)arg; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
74 return AF_OK; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
75 case AF_CONTROL_SS_FREQ | AF_CONTROL_GET: |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
76 *(float*)arg = s->freq; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
77 return AF_OK; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
78 case AF_CONTROL_SS_DECAY | AF_CONTROL_SET: |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
79 s->decay = *(float*)arg; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
80 return AF_OK; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
81 case AF_CONTROL_SS_DECAY | AF_CONTROL_GET: |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
82 *(float*)arg = s->decay; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
83 return AF_OK; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
84 } |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
85 return AF_UNKNOWN; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
86 } |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
87 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
88 // Deallocate memory |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
89 static void uninit(struct af_instance_s* af) |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
90 { |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
91 if(af->data) |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
92 free(af->data); |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
93 if(af->setup) |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
94 free(af->setup); |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
95 } |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
96 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
97 // Filter data through filter |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
98 static af_data_t* play_s16(struct af_instance_s* af, af_data_t* data) |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
99 { |
18611
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
100 af_sinesuppress_t *s = af->setup; |
18082
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
101 register int i = 0; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
102 int16_t *a = (int16_t*)data->audio; // Audio data |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
103 int len = data->len/2; // Number of samples |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
104 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
105 for (i = 0; i < len; i++) |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
106 { |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
107 double co= cos(s->pos); |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
108 double si= sin(s->pos); |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
109 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
110 s->real += co * a[i]; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
111 s->imag += si * a[i]; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
112 s->ref += co * co; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
113 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
114 a[i] -= (s->real * co + s->imag * si) / s->ref; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
115 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
116 s->real -= s->real * s->decay; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
117 s->imag -= s->imag * s->decay; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
118 s->ref -= s->ref * s->decay; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
119 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
120 s->pos += 2 * M_PI * s->freq / data->rate; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
121 } |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
122 |
18611
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
123 af_msg(AF_MSG_VERBOSE,"[sinesuppress] f:%8.2f: amp:%8.2f\n", s->freq, sqrt(s->real*s->real + s->imag*s->imag) / s->ref); |
18082
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
124 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
125 return data; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
126 } |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
127 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
128 #if 0 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
129 static af_data_t* play_float(struct af_instance_s* af, af_data_t* data) |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
130 { |
18611
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
131 af_sinesuppress_t *s = af->setup; |
18082
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
132 register int i = 0; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
133 float *a = (float*)data->audio; // Audio data |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
134 int len = data->len/4; // Number of samples |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
135 float avg, l, r; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
136 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
137 for (i = 0; i < len; i+=2) |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
138 { |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
139 avg = (a[i] + a[i + 1]) / 2; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
140 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
141 /* l = avg + (s->mul * (a[i] - avg)); |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
142 r = avg + (s->mul * (a[i + 1] - avg));*/ |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
143 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
144 a[i] = af_softclip(l); |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
145 a[i + 1] = af_softclip(r); |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
146 } |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
147 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
148 return data; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
149 } |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
150 #endif |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
151 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
152 // Allocate memory and set function pointers |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
153 static int open(af_instance_t* af){ |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
154 af->control=control; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
155 af->uninit=uninit; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
156 af->play=play_s16; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
157 af->mul.n=1; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
158 af->mul.d=1; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
159 af->data=calloc(1,sizeof(af_data_t)); |
18611
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
160 af->setup=calloc(1,sizeof(af_sinesuppress_t)); |
18082
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
161 if(af->data == NULL || af->setup == NULL) |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
162 return AF_ERROR; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
163 |
18611
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
164 ((af_sinesuppress_t*)af->setup)->freq = 50.0; |
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
165 ((af_sinesuppress_t*)af->setup)->decay = 0.0001; |
18082
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
166 return AF_OK; |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
167 } |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
168 |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
169 // Description of this filter |
18611
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
170 af_info_t af_info_sinesuppress = { |
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
171 "Sine Suppress", |
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
172 "sinesuppress", |
18082
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
173 "Michael Niedermayer", |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
174 "", |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
175 0, |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
176 open |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
177 }; |