Mercurial > mplayer.hg
annotate libaf/af_sinesuppress.c @ 32223:c6e682837c8a
Fix format string to match type.
author | reimar |
---|---|
date | Sat, 18 Sep 2010 17:27:17 +0000 |
parents | 0f1b5b68af32 |
children | 8fa2f43cb760 |
rev | line source |
---|---|
28229
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
1 /* |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
2 * Copyright (C) 2006 Michael Niedermayer |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
3 * Copyright (C) 2004 Alex Beregszaszi |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
4 * based upon af_extrastereo.c by Pierre Lombard |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
5 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
6 * This file is part of MPlayer. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
7 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
8 * 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
|
9 * 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
|
10 * 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
|
11 * (at your option) any later version. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
12 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
13 * 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
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
16 * GNU General Public License for more details. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
17 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
18 * 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
|
19 * 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
|
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
21 */ |
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
|
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 #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
|
24 #include <stdlib.h> |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
25 #include <string.h> |
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
|
26 |
0aa3fef68422
very simple filter which can 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 #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
|
28 #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
|
29 #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
|
30 |
0aa3fef68422
very simple filter which can 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 #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
|
32 |
0aa3fef68422
very simple filter which can 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 // Data for specific instances of this filter |
18611
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
34 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
|
35 { |
0aa3fef68422
very simple filter which can 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 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 double pos; |
18611
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
42 }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
|
43 |
0aa3fef68422
very simple filter which can 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 static af_data_t* play_s16(struct af_instance_s* af, af_data_t* data); |
24171 | 45 //static af_data_t* play_float(struct af_instance_s* af, af_data_t* data); |
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
|
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 // 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
|
48 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
|
49 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
50 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
|
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 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
|
53 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
|
54 // 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
|
55 if(!arg) return AF_ERROR; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
56 |
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
|
57 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
|
58 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
|
59 #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
|
60 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
|
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 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
|
63 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
|
64 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
|
65 }// 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
|
66 #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
|
67 { |
0aa3fef68422
very simple filter which can 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 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
|
69 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
|
70 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
|
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 |
0aa3fef68422
very simple filter which can 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 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
|
74 } |
0aa3fef68422
very simple filter which can 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_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
|
76 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
|
77 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
|
78 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
|
79 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
|
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 } |
0aa3fef68422
very simple filter which can 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 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
|
83 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
|
84 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
|
85 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
|
86 *(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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 *(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
|
93 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
|
94 } |
0aa3fef68422
very simple filter which can 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 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
|
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 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
98 // Deallocate memory |
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
|
99 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
|
100 { |
0aa3fef68422
very simple filter which can 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 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
|
102 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
|
103 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
|
104 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
|
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 |
0aa3fef68422
very simple filter which can 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 // 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
|
108 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
|
109 { |
18611
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
110 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
|
111 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
|
112 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
|
113 int len = data->len/2; // Number of samples |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
114 |
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
|
115 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
|
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 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
|
118 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
|
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->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
|
121 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
|
122 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
|
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 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
|
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 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
|
127 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
|
128 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
|
129 |
0aa3fef68422
very simple filter which can 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 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
|
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 |
29049 | 133 mp_msg(MSGT_AFILTER, MSGL_V, "[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
|
134 |
0aa3fef68422
very simple filter which can 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 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
|
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 |
0aa3fef68422
very simple filter which can 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 #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
|
139 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
|
140 { |
18611
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
141 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
|
142 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
|
143 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
|
144 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
|
145 float avg, l, r; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
146 |
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
|
147 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
|
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 avg = (a[i] + a[i + 1]) / 2; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
150 |
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
|
151 /* 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
|
152 r = avg + (s->mul * (a[i + 1] - avg));*/ |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
153 |
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
|
154 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
|
155 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
|
156 } |
0aa3fef68422
very simple filter which can 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 |
0aa3fef68422
very simple filter which can 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 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
|
159 } |
0aa3fef68422
very simple filter which can 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 #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
|
161 |
0aa3fef68422
very simple filter which can 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 // 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:
18905
diff
changeset
|
163 static int af_open(af_instance_t* af){ |
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
|
164 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
|
165 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
|
166 af->play=play_s16; |
24888 | 167 af->mul=1; |
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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 |
18611
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
173 ((af_sinesuppress_t*)af->setup)->freq = 50.0; |
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
174 ((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
|
175 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
|
176 } |
0aa3fef68422
very simple filter which can 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 |
0aa3fef68422
very simple filter which can 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 // Description of this filter |
18611
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
179 af_info_t af_info_sinesuppress = { |
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
180 "Sine Suppress", |
1c2f694d5232
Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents:
18082
diff
changeset
|
181 "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
|
182 "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
|
183 "", |
0aa3fef68422
very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff
changeset
|
184 0, |
22746
fd6f824ef894
Rename open to af_open so as not to conflict with a previous header definition.
diego
parents:
18905
diff
changeset
|
185 af_open |
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
|
186 }; |