Mercurial > mplayer.hg
annotate libaf/af_sinesupress.c @ 18360:d604c7f2baba
patches should be always created from root dir
author | attila |
---|---|
date | Sun, 30 Apr 2006 20:32:01 +0000 |
parents | 0aa3fef68422 |
children |
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 |
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
|
24 typedef struct af_sinesupress_s |
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; |
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
|
32 }af_sinesupress_t; |
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 { |
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
|
40 af_sinesupress_t* s = (af_sinesupress_t*)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
|
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 { |
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
|
100 af_sinesupress_t *s = 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
|
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 int 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
|
105 |
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 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
|
107 { |
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 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
|
109 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
|
110 |
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->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
|
112 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
|
113 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
|
114 |
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 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
|
116 |
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->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
|
118 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
|
119 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
|
120 |
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 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
|
122 } |
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
|
123 |
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 af_msg(AF_MSG_VERBOSE,"[sinesupress] f:%8.2f: amp:%8.2f\n", s->freq, sqrt(s->real*s->real + s->imag*s->imag) / 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
|
125 |
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 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
|
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 |
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 #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
|
130 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
|
131 { |
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 af_sinesupress_t *s = 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 |
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 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
|
139 { |
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 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
|
141 |
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 /* 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
|
143 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
|
144 |
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] = 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
|
146 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
|
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 |
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 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
|
150 } |
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 #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
|
152 |
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 // 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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 af->data=calloc(1,sizeof(af_data_t)); |
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 af->setup=calloc(1,sizeof(af_sinesupress_t)); |
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 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
|
163 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
|
164 |
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
|
165 ((af_sinesupress_t*)af->setup)->freq = 50.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
|
166 ((af_sinesupress_t*)af->setup)->decay = 0.0001; |
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 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
|
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 |
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
|
170 // Description of this 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
|
171 af_info_t af_info_sinesupress = { |
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
|
172 "Sine Supress", |
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 "sinesupress", |
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 "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
|
175 "", |
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 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
|
177 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
|
178 }; |