annotate libaf/af_sinesuppress.c @ 34929:c410ef9752a0

Initialize a few more AVFrame fields to avoid FFmpeg errors. However this really needs to be done via FFmpeg somehow to avoid issues each time new fields are added, either by exposing ff_init_buffer_info as public API or by calling get_buffer etc. through wrappers that take care of the initialization.
author reimar
date Sat, 14 Jul 2012 11:37:22 +0000
parents a93891202051
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
34174
a93891202051 Add missing mp_msg.h #includes, remove some unnecessary ones.
diego
parents: 32537
diff changeset
31 #include "mp_msg.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
32 #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
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 // Data for specific instances of this filter
18611
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
35 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
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 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
38 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
39 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
40 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
41 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
42 double pos;
18611
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
43 }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
44
0aa3fef68422 very simple filter which can 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 static af_data_t* play_s16(struct af_instance_s* af, af_data_t* data);
24171
6dcbc0080be8 Fix warning:
diego
parents: 22748
diff changeset
46 //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
47
0aa3fef68422 very simple filter which can 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 // 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
49 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
50 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
51 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
52
0aa3fef68422 very simple filter which can 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 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
54 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
55 // 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
56 if(!arg) return AF_ERROR;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
57
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
58 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
59 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
60 #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
61 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
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 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
64 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
65 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
66 }// 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
67 #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
68 {
0aa3fef68422 very simple filter which can 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->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
70 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
71 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
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
0aa3fef68422 very simple filter which can 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_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
75 }
0aa3fef68422 very simple filter which can 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 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
77 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
78 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
79 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
80 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
81 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
82 }
0aa3fef68422 very simple filter which can 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 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
84 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
85 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
86 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
87 *(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
88 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
89 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
90 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
91 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
92 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
93 *(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
94 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
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 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
97 }
0aa3fef68422 very simple filter which can 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
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
99 // 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
100 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
101 {
0aa3fef68422 very simple filter which can 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 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
104 }
0aa3fef68422 very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff changeset
105
0aa3fef68422 very simple filter which can 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 // 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
107 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
108 {
18611
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
109 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
110 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
111 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
112 int len = data->len/2; // Number of samples
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
113
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
114 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
115 {
0aa3fef68422 very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff changeset
116 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
117 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
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->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
120 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
121 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
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 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
124
0aa3fef68422 very simple filter which can remove a sine at a specified frequency, usefull to get rid of the 50/60hz noise on ultra crappy equipment
michael
parents:
diff changeset
125 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
126 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
127 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
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 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
130 }
0aa3fef68422 very simple filter which can 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
29049
8c706ce21c6f Remove af_msg special-casing API in libaf.
bircoph
parents: 28229
diff changeset
132 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
133
0aa3fef68422 very simple filter which can 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 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
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
0aa3fef68422 very simple filter which can 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 #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
138 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
139 {
18611
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
140 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
141 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
142 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
143 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
144 float avg, l, r;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
145
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
146 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
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 avg = (a[i] + a[i + 1]) / 2;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
149
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
150 /* 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
151 r = avg + (s->mul * (a[i + 1] - avg));*/
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
152
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 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
154 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
155 }
0aa3fef68422 very simple filter which can 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 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
158 }
0aa3fef68422 very simple filter which can 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 #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
160
0aa3fef68422 very simple filter which can 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 // 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
162 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
163 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
164 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
165 af->play=play_s16;
24888
b2402b4f0afa libaf: change filter input/output ratio calculations
uau
parents: 24171
diff changeset
166 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
167 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
168 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
169 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
170 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
171
18611
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
172 ((af_sinesuppress_t*)af->setup)->freq = 50.0;
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
173 ((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
174 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
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
0aa3fef68422 very simple filter which can 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 // Description of this filter
18611
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
178 af_info_t af_info_sinesuppress = {
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
179 "Sine Suppress",
1c2f694d5232 Rename sinesupress to sinesuppress, including af_sinesupress.c file rename.
corey
parents: 18082
diff changeset
180 "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
181 "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
182 "",
0aa3fef68422 very simple filter which can 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 0,
22746
fd6f824ef894 Rename open to af_open so as not to conflict with a previous header definition.
diego
parents: 18905
diff changeset
184 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
185 };