annotate libaf/af_sinesuppress.c @ 25652:6e25dda14b62

Add extradata to sh_sub_t.
author eugeni
date Fri, 11 Jan 2008 21:45:10 +0000
parents b2402b4f0afa
children 72d0b1444141
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 <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
17 #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
18 #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
19
0aa3fef68422 very simple filter which can 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 #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
21
0aa3fef68422 very simple filter which can 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 // Data for specific instances of this filter
18611
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
23 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
24 {
0aa3fef68422 very simple filter which can 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 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
26 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
27 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
28 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
29 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
30 double pos;
18611
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
31 }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
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 static af_data_t* play_s16(struct af_instance_s* af, af_data_t* data);
24171
6dcbc0080be8 Fix warning:
diego
parents: 22748
diff changeset
34 //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
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 // 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
37 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
38 {
18611
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
39 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
40
0aa3fef68422 very simple filter which can 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 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
42 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
43 // 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
44 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
45
0aa3fef68422 very simple filter which can 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 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
47 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
48 #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
49 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
50 {
0aa3fef68422 very simple filter which can 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 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
52 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
53 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
54 }// 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
55 #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
56 {
0aa3fef68422 very simple filter which can 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->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
58 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
59 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
60 }
0aa3fef68422 very simple filter which can 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 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
63 }
0aa3fef68422 very simple filter which can 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 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
65 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
66 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
67 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
68 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
69 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
70 }
0aa3fef68422 very simple filter which can 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 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
72 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
73 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
74 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
75 *(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
76 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
77 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
78 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
79 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
80 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
81 *(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
82 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
83 }
0aa3fef68422 very simple filter which can 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_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
85 }
0aa3fef68422 very simple filter which can 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 // 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
88 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
89 {
0aa3fef68422 very simple filter which can 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 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
91 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
92 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
93 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
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
0aa3fef68422 very simple filter which can 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 // 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
97 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
98 {
18611
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
99 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
100 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
101 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
102 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
103
0aa3fef68422 very simple filter which can 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 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
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 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
107 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
108
0aa3fef68422 very simple filter which can 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 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
110 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
111 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
112
0aa3fef68422 very simple filter which can 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 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
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 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
116 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
117 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
118
0aa3fef68422 very simple filter which can 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->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
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
18611
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
122 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
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 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
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
0aa3fef68422 very simple filter which can 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 #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
128 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
129 {
18611
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
130 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
131 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
132 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
133 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
134 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
135
0aa3fef68422 very simple filter which can 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 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
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 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
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 /* 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
141 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
142
0aa3fef68422 very simple filter which can 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 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
144 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
145 }
0aa3fef68422 very simple filter which can 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 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
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 #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
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 // 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
152 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
153 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
154 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
155 af->play=play_s16;
24888
b2402b4f0afa libaf: change filter input/output ratio calculations
uau
parents: 24171
diff changeset
156 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
157 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
158 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
159 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
160 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
161
18611
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
162 ((af_sinesuppress_t*)af->setup)->freq = 50.0;
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
163 ((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
164 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
165 }
0aa3fef68422 very simple filter which can 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
0aa3fef68422 very simple filter which can 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 // Description of this filter
18611
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
168 af_info_t af_info_sinesuppress = {
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
169 "Sine Suppress",
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
170 "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
171 "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
172 "",
0aa3fef68422 very simple filter which can 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 0,
22746
fd6f824ef894 Rename open to af_open so as not to conflict with a previous header definition.
diego
parents: 18905
diff changeset
174 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
175 };