Mercurial > mplayer.hg
annotate libaf/af_comp.c @ 30885:c634d15b475f
Announce Windows XP SP2 instead of Windows 95 OSR2.
It's time we move to 2010: Announce Windows XP SP2 to codecs instead of Win95
OSR2.
Note: We still don't support the *Ex fields in the version info struct
properly (we shouldn't really overwrite the structure size, but rather check
it to see if it's safe to fill the extra fields). No codec I've found seems
to care.
author | sesse |
---|---|
date | Wed, 17 Mar 2010 23:38:26 +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) 2002 Anders Johansson ajh@atri.curtin.edu.au |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
3 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
4 * This file is part of MPlayer. |
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 * 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
|
7 * 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
|
8 * 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
|
9 * (at your option) any later version. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
10 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
11 * 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
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
14 * GNU General Public License for more details. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
15 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
16 * 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
|
17 * 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
|
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
19 */ |
8607 | 20 |
21 #include <stdio.h> | |
22 #include <stdlib.h> | |
8623
440301fef3fe
Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents:
8607
diff
changeset
|
23 #include <string.h> |
8607 | 24 |
25 #include <inttypes.h> | |
26 #include <math.h> | |
27 #include <limits.h> | |
28 | |
29 #include "af.h" | |
30 | |
31 // Data for specific instances of this filter | |
32 typedef struct af_comp_s | |
33 { | |
34 int enable[AF_NCH]; // Enable/disable / channel | |
35 float time[AF_NCH]; // Forgetting factor for power estimate | |
36 float pow[AF_NCH]; // Estimated power level [dB] | |
37 float tresh[AF_NCH]; // Threshold [dB] | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
38 int attack[AF_NCH]; // Attack time [ms] |
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
39 int release[AF_NCH]; // Release time [ms] |
8607 | 40 float ratio[AF_NCH]; // Compression ratio |
41 }af_comp_t; | |
42 | |
43 // Initialization and runtime control | |
44 static int control(struct af_instance_s* af, int cmd, void* arg) | |
45 { | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
46 af_comp_t* s = (af_comp_t*)af->setup; |
8607 | 47 int i; |
48 | |
49 switch(cmd){ | |
50 case AF_CONTROL_REINIT: | |
51 // Sanity check | |
52 if(!arg) return AF_ERROR; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
53 |
8607 | 54 af->data->rate = ((af_data_t*)arg)->rate; |
55 af->data->nch = ((af_data_t*)arg)->nch; | |
14245 | 56 af->data->format = AF_FORMAT_FLOAT_NE; |
8607 | 57 af->data->bps = 4; |
58 | |
59 // Time constant set to 0.1s | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
60 // s->alpha = (1.0/0.2)/(2.0*M_PI*(float)((af_data_t*)arg)->rate); |
8607 | 61 return af_test_output(af,(af_data_t*)arg); |
62 case AF_CONTROL_COMMAND_LINE:{ | |
63 /* float v=-10.0; */ | |
64 /* float vol[AF_NCH]; */ | |
65 /* float s=0.0; */ | |
66 /* float clipp[AF_NCH]; */ | |
67 /* int i; */ | |
68 /* sscanf((char*)arg,"%f:%f", &v, &s); */ | |
69 /* for(i=0;i<AF_NCH;i++){ */ | |
70 /* vol[i]=v; */ | |
71 /* clipp[i]=s; */ | |
72 /* } */ | |
73 /* if(AF_OK != control(af,AF_CONTROL_VOLUME_SOFTCLIP | AF_CONTROL_SET, clipp)) */ | |
74 /* return AF_ERROR; */ | |
75 /* return control(af,AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_SET, vol); */ | |
76 } | |
77 case AF_CONTROL_COMP_ON_OFF | AF_CONTROL_SET: | |
78 memcpy(s->enable,(int*)arg,AF_NCH*sizeof(int)); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
79 return AF_OK; |
8607 | 80 case AF_CONTROL_COMP_ON_OFF | AF_CONTROL_GET: |
81 memcpy((int*)arg,s->enable,AF_NCH*sizeof(int)); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
82 return AF_OK; |
8607 | 83 case AF_CONTROL_COMP_THRESH | AF_CONTROL_SET: |
84 return af_from_dB(AF_NCH,(float*)arg,s->tresh,20.0,-60.0,-1.0); | |
85 case AF_CONTROL_COMP_THRESH | AF_CONTROL_GET: | |
86 return af_to_dB(AF_NCH,s->tresh,(float*)arg,10.0); | |
87 case AF_CONTROL_COMP_ATTACK | AF_CONTROL_SET: | |
88 return af_from_ms(AF_NCH,(float*)arg,s->attack,af->data->rate,500.0,0.1); | |
89 case AF_CONTROL_COMP_ATTACK | AF_CONTROL_GET: | |
90 return af_to_ms(AF_NCH,s->attack,(float*)arg,af->data->rate); | |
91 case AF_CONTROL_COMP_RELEASE | AF_CONTROL_SET: | |
92 return af_from_ms(AF_NCH,(float*)arg,s->release,af->data->rate,3000.0,10.0); | |
93 case AF_CONTROL_COMP_RELEASE | AF_CONTROL_GET: | |
94 return af_to_ms(AF_NCH,s->release,(float*)arg,af->data->rate); | |
95 case AF_CONTROL_COMP_RATIO | AF_CONTROL_SET: | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
96 for(i=0;i<AF_NCH;i++) |
8607 | 97 s->ratio[i] = clamp(((float*)arg)[i],1.0,10.0); |
98 return AF_OK; | |
99 case AF_CONTROL_COMP_RATIO | AF_CONTROL_GET: | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
100 for(i=0;i<AF_NCH;i++) |
8607 | 101 ((float*)arg)[i] = s->ratio[i]; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
102 return AF_OK; |
8607 | 103 } |
104 return AF_UNKNOWN; | |
105 } | |
106 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
107 // Deallocate memory |
8607 | 108 static void uninit(struct af_instance_s* af) |
109 { | |
110 if(af->data) | |
111 free(af->data); | |
112 if(af->setup) | |
113 free(af->setup); | |
114 } | |
115 | |
116 // Filter data through filter | |
117 static af_data_t* play(struct af_instance_s* af, af_data_t* data) | |
118 { | |
119 af_data_t* c = data; // Current working data | |
120 af_comp_t* s = (af_comp_t*)af->setup; // Setup for this instance | |
121 float* a = (float*)c->audio; // Audio data | |
122 int len = c->len/4; // Number of samples | |
123 int ch = 0; // Channel counter | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
124 register int nch = c->nch; // Number of channels |
8607 | 125 register int i = 0; |
126 | |
127 // Compress/expand | |
128 for(ch = 0; ch < nch ; ch++){ | |
129 if(s->enable[ch]){ | |
130 float t = 1.0 - s->time[ch]; | |
131 for(i=ch;i<len;i+=nch){ | |
132 register float x = a[i]; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
133 register float pow = x*x; |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
134 s->pow[ch] = t*s->pow[ch] + |
8607 | 135 pow*s->time[ch]; // LP filter |
136 if(pow < s->pow[ch]){ | |
137 ; | |
138 } | |
139 else{ | |
140 ; | |
141 } | |
142 a[i] = x; | |
143 } | |
144 } | |
145 } | |
146 return c; | |
147 } | |
148 | |
149 // 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
|
150 static int af_open(af_instance_t* af){ |
8607 | 151 af->control=control; |
152 af->uninit=uninit; | |
153 af->play=play; | |
24888 | 154 af->mul=1; |
8607 | 155 af->data=calloc(1,sizeof(af_data_t)); |
156 af->setup=calloc(1,sizeof(af_comp_t)); | |
157 if(af->data == NULL || af->setup == NULL) | |
158 return AF_ERROR; | |
159 return AF_OK; | |
160 } | |
161 | |
162 // Description of this filter | |
163 af_info_t af_info_comp = { | |
164 "Compressor/expander audio filter", | |
165 "comp", | |
166 "Anders", | |
167 "", | |
168 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
|
169 af_open |
8607 | 170 }; |