Mercurial > mplayer.hg
annotate libaf/af_gate.c @ 25063:29260745e4fa
Pass all available formats to chain building routine and
establish connection with first of available formats.
This will make further format negotiation patch slightly
simpler.
To avoid pins connection error due to unsuported format
at top of the list, put requested video format to the
top of list. This will also useful with upcoming patch -
negotiation will be started from requested format.
author | voroshil |
---|---|
date | Sun, 18 Nov 2007 10:51:22 +0000 |
parents | b2402b4f0afa |
children | 72d0b1444141 |
rev | line source |
---|---|
8607 | 1 /*============================================================================= |
2 // | |
13602
14090f7300a8
The full name of the GPL is GNU General Public License.
diego
parents:
8674
diff
changeset
|
3 // This software has been released under the terms of the GNU General Public |
8607 | 4 // license. See http://www.gnu.org/copyleft/gpl.html for details. |
5 // | |
6 // Copyright 2002 Anders Johansson ajh@atri.curtin.edu.au | |
7 // | |
8 //============================================================================= | |
9 */ | |
10 | |
11 #include <stdio.h> | |
12 #include <stdlib.h> | |
8623
440301fef3fe
Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents:
8607
diff
changeset
|
13 #include <string.h> |
8607 | 14 |
15 #include <inttypes.h> | |
16 #include <math.h> | |
17 #include <limits.h> | |
18 | |
19 #include "af.h" | |
20 | |
21 // Data for specific instances of this filter | |
22 typedef struct af_gate_s | |
23 { | |
24 int enable[AF_NCH]; // Enable/disable / channel | |
25 float time[AF_NCH]; // Forgetting factor for power estimate | |
26 float pow[AF_NCH]; // Estimated power level [dB] | |
27 float tresh[AF_NCH]; // Threshold [dB] | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
28 int attack[AF_NCH]; // Attack time [ms] |
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
29 int release[AF_NCH]; // Release time [ms] |
8607 | 30 float range[AF_NCH]; // Range level [dB] |
31 }af_gate_t; | |
32 | |
33 // Initialization and runtime control | |
34 static int control(struct af_instance_s* af, int cmd, void* arg) | |
35 { | |
36 af_gate_t* s = (af_gate_t*)af->setup; | |
37 switch(cmd){ | |
38 case AF_CONTROL_REINIT: | |
39 // Sanity check | |
40 if(!arg) return AF_ERROR; | |
41 | |
42 af->data->rate = ((af_data_t*)arg)->rate; | |
43 af->data->nch = ((af_data_t*)arg)->nch; | |
14245 | 44 af->data->format = AF_FORMAT_FLOAT_NE; |
8607 | 45 af->data->bps = 4; |
46 | |
47 // Time constant set to 0.1s | |
48 // s->alpha = (1.0/0.2)/(2.0*M_PI*(float)((af_data_t*)arg)->rate); | |
49 return af_test_output(af,(af_data_t*)arg); | |
50 case AF_CONTROL_COMMAND_LINE:{ | |
51 /* float v=-10.0; */ | |
52 /* float vol[AF_NCH]; */ | |
53 /* float s=0.0; */ | |
54 /* float clipp[AF_NCH]; */ | |
55 /* int i; */ | |
56 /* sscanf((char*)arg,"%f:%f", &v, &s); */ | |
57 /* for(i=0;i<AF_NCH;i++){ */ | |
58 /* vol[i]=v; */ | |
59 /* clipp[i]=s; */ | |
60 /* } */ | |
61 /* if(AF_OK != control(af,AF_CONTROL_VOLUME_SOFTCLIP | AF_CONTROL_SET, clipp)) */ | |
62 /* return AF_ERROR; */ | |
63 /* return control(af,AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_SET, vol); */ | |
64 } | |
65 | |
66 case AF_CONTROL_GATE_ON_OFF | AF_CONTROL_SET: | |
67 memcpy(s->enable,(int*)arg,AF_NCH*sizeof(int)); | |
68 return AF_OK; | |
69 case AF_CONTROL_GATE_ON_OFF | AF_CONTROL_GET: | |
70 memcpy((int*)arg,s->enable,AF_NCH*sizeof(int)); | |
71 return AF_OK; | |
72 case AF_CONTROL_GATE_THRESH | AF_CONTROL_SET: | |
73 return af_from_dB(AF_NCH,(float*)arg,s->tresh,20.0,-60.0,-1.0); | |
74 case AF_CONTROL_GATE_THRESH | AF_CONTROL_GET: | |
75 return af_to_dB(AF_NCH,s->tresh,(float*)arg,10.0); | |
76 case AF_CONTROL_GATE_ATTACK | AF_CONTROL_SET: | |
77 return af_from_ms(AF_NCH,(float*)arg,s->attack,af->data->rate,500.0,0.1); | |
78 case AF_CONTROL_GATE_ATTACK | AF_CONTROL_GET: | |
79 return af_to_ms(AF_NCH,s->attack,(float*)arg,af->data->rate); | |
80 case AF_CONTROL_GATE_RELEASE | AF_CONTROL_SET: | |
81 return af_from_ms(AF_NCH,(float*)arg,s->release,af->data->rate,3000.0,10.0); | |
82 case AF_CONTROL_GATE_RELEASE | AF_CONTROL_GET: | |
83 return af_to_ms(AF_NCH,s->release,(float*)arg,af->data->rate); | |
84 case AF_CONTROL_GATE_RANGE | AF_CONTROL_SET: | |
85 return af_from_dB(AF_NCH,(float*)arg,s->range,20.0,100.0,0.0); | |
86 case AF_CONTROL_GATE_RANGE | AF_CONTROL_GET: | |
87 return af_to_dB(AF_NCH,s->range,(float*)arg,10.0); | |
88 } | |
89 return AF_UNKNOWN; | |
90 } | |
91 | |
92 // Deallocate memory | |
93 static void uninit(struct af_instance_s* af) | |
94 { | |
95 if(af->data) | |
96 free(af->data); | |
97 if(af->setup) | |
98 free(af->setup); | |
99 } | |
100 | |
101 // Filter data through filter | |
102 static af_data_t* play(struct af_instance_s* af, af_data_t* data) | |
103 { | |
104 af_data_t* c = data; // Current working data | |
105 af_gate_t* s = (af_gate_t*)af->setup; // Setup for this instance | |
106 float* a = (float*)c->audio; // Audio data | |
107 int len = c->len/4; // Number of samples | |
108 int ch = 0; // Channel counter | |
109 register int nch = c->nch; // Number of channels | |
110 register int i = 0; | |
111 | |
112 | |
113 // Noise gate | |
114 for(ch = 0; ch < nch ; ch++){ | |
115 if(s->enable[ch]){ | |
116 float t = 1.0 - s->time[ch]; | |
117 for(i=ch;i<len;i+=nch){ | |
118 register float x = a[i]; | |
119 register float pow = x*x; | |
120 s->pow[ch] = t*s->pow[ch] + | |
121 pow*s->time[ch]; // LP filter | |
122 if(pow < s->pow[ch]){ | |
123 ; | |
124 } | |
125 else{ | |
126 ; | |
127 } | |
128 a[i] = x; | |
129 } | |
130 } | |
131 } | |
132 return c; | |
133 } | |
134 | |
135 // 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:
14245
diff
changeset
|
136 static int af_open(af_instance_t* af){ |
8607 | 137 af->control=control; |
138 af->uninit=uninit; | |
139 af->play=play; | |
24888 | 140 af->mul=1; |
8607 | 141 af->data=calloc(1,sizeof(af_data_t)); |
142 af->setup=calloc(1,sizeof(af_gate_t)); | |
143 if(af->data == NULL || af->setup == NULL) | |
144 return AF_ERROR; | |
145 return AF_OK; | |
146 } | |
147 | |
148 // Description of this filter | |
149 af_info_t af_info_gate = { | |
150 "Noise gate audio filter", | |
151 "gate", | |
152 "Anders", | |
153 "", | |
154 AF_FLAGS_NOT_REENTRANT, | |
22746
fd6f824ef894
Rename open to af_open so as not to conflict with a previous header definition.
diego
parents:
14245
diff
changeset
|
155 af_open |
8607 | 156 }; |