Mercurial > mplayer.hg
annotate libaf/af_comp.c @ 36843:1078b8dd7625
Cast appropriately.
author | ib |
---|---|
date | Tue, 25 Feb 2014 17:10:39 +0000 |
parents | 2b9bc3c2933d |
children |
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 | |
36395
2b9bc3c2933d
Remove some macros and switch to libavutil equivalents.
reimar
parents:
32537
diff
changeset
|
29 #include "libavutil/common.h" |
8607 | 30 #include "af.h" |
31 | |
32 // Data for specific instances of this filter | |
33 typedef struct af_comp_s | |
34 { | |
35 int enable[AF_NCH]; // Enable/disable / channel | |
36 float time[AF_NCH]; // Forgetting factor for power estimate | |
37 float pow[AF_NCH]; // Estimated power level [dB] | |
38 float tresh[AF_NCH]; // Threshold [dB] | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
39 int attack[AF_NCH]; // Attack time [ms] |
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
40 int release[AF_NCH]; // Release time [ms] |
8607 | 41 float ratio[AF_NCH]; // Compression ratio |
42 }af_comp_t; | |
43 | |
44 // Initialization and runtime control | |
45 static int control(struct af_instance_s* af, int cmd, void* arg) | |
46 { | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
47 af_comp_t* s = (af_comp_t*)af->setup; |
8607 | 48 int i; |
49 | |
50 switch(cmd){ | |
51 case AF_CONTROL_REINIT: | |
52 // Sanity check | |
53 if(!arg) return AF_ERROR; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
54 |
8607 | 55 af->data->rate = ((af_data_t*)arg)->rate; |
56 af->data->nch = ((af_data_t*)arg)->nch; | |
14245 | 57 af->data->format = AF_FORMAT_FLOAT_NE; |
8607 | 58 af->data->bps = 4; |
59 | |
60 // Time constant set to 0.1s | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
61 // s->alpha = (1.0/0.2)/(2.0*M_PI*(float)((af_data_t*)arg)->rate); |
8607 | 62 return af_test_output(af,(af_data_t*)arg); |
63 case AF_CONTROL_COMMAND_LINE:{ | |
64 /* float v=-10.0; */ | |
65 /* float vol[AF_NCH]; */ | |
66 /* float s=0.0; */ | |
67 /* float clipp[AF_NCH]; */ | |
68 /* int i; */ | |
69 /* sscanf((char*)arg,"%f:%f", &v, &s); */ | |
70 /* for(i=0;i<AF_NCH;i++){ */ | |
71 /* vol[i]=v; */ | |
72 /* clipp[i]=s; */ | |
73 /* } */ | |
74 /* if(AF_OK != control(af,AF_CONTROL_VOLUME_SOFTCLIP | AF_CONTROL_SET, clipp)) */ | |
75 /* return AF_ERROR; */ | |
76 /* return control(af,AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_SET, vol); */ | |
77 } | |
78 case AF_CONTROL_COMP_ON_OFF | AF_CONTROL_SET: | |
79 memcpy(s->enable,(int*)arg,AF_NCH*sizeof(int)); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
80 return AF_OK; |
8607 | 81 case AF_CONTROL_COMP_ON_OFF | AF_CONTROL_GET: |
82 memcpy((int*)arg,s->enable,AF_NCH*sizeof(int)); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
83 return AF_OK; |
8607 | 84 case AF_CONTROL_COMP_THRESH | AF_CONTROL_SET: |
85 return af_from_dB(AF_NCH,(float*)arg,s->tresh,20.0,-60.0,-1.0); | |
86 case AF_CONTROL_COMP_THRESH | AF_CONTROL_GET: | |
87 return af_to_dB(AF_NCH,s->tresh,(float*)arg,10.0); | |
88 case AF_CONTROL_COMP_ATTACK | AF_CONTROL_SET: | |
89 return af_from_ms(AF_NCH,(float*)arg,s->attack,af->data->rate,500.0,0.1); | |
90 case AF_CONTROL_COMP_ATTACK | AF_CONTROL_GET: | |
91 return af_to_ms(AF_NCH,s->attack,(float*)arg,af->data->rate); | |
92 case AF_CONTROL_COMP_RELEASE | AF_CONTROL_SET: | |
93 return af_from_ms(AF_NCH,(float*)arg,s->release,af->data->rate,3000.0,10.0); | |
94 case AF_CONTROL_COMP_RELEASE | AF_CONTROL_GET: | |
95 return af_to_ms(AF_NCH,s->release,(float*)arg,af->data->rate); | |
96 case AF_CONTROL_COMP_RATIO | AF_CONTROL_SET: | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
97 for(i=0;i<AF_NCH;i++) |
36395
2b9bc3c2933d
Remove some macros and switch to libavutil equivalents.
reimar
parents:
32537
diff
changeset
|
98 s->ratio[i] = av_clipf(((float*)arg)[i],1.0,10.0); |
8607 | 99 return AF_OK; |
100 case AF_CONTROL_COMP_RATIO | AF_CONTROL_GET: | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
101 for(i=0;i<AF_NCH;i++) |
8607 | 102 ((float*)arg)[i] = s->ratio[i]; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
103 return AF_OK; |
8607 | 104 } |
105 return AF_UNKNOWN; | |
106 } | |
107 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
108 // Deallocate memory |
8607 | 109 static void uninit(struct af_instance_s* af) |
110 { | |
111 free(af->data); | |
112 free(af->setup); | |
113 } | |
114 | |
115 // Filter data through filter | |
116 static af_data_t* play(struct af_instance_s* af, af_data_t* data) | |
117 { | |
118 af_data_t* c = data; // Current working data | |
119 af_comp_t* s = (af_comp_t*)af->setup; // Setup for this instance | |
120 float* a = (float*)c->audio; // Audio data | |
121 int len = c->len/4; // Number of samples | |
122 int ch = 0; // Channel counter | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
123 register int nch = c->nch; // Number of channels |
8607 | 124 register int i = 0; |
125 | |
126 // Compress/expand | |
127 for(ch = 0; ch < nch ; ch++){ | |
128 if(s->enable[ch]){ | |
129 float t = 1.0 - s->time[ch]; | |
130 for(i=ch;i<len;i+=nch){ | |
131 register float x = a[i]; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
132 register float pow = x*x; |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
133 s->pow[ch] = t*s->pow[ch] + |
8607 | 134 pow*s->time[ch]; // LP filter |
135 if(pow < s->pow[ch]){ | |
136 ; | |
137 } | |
138 else{ | |
139 ; | |
140 } | |
141 a[i] = x; | |
142 } | |
143 } | |
144 } | |
145 return c; | |
146 } | |
147 | |
148 // 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
|
149 static int af_open(af_instance_t* af){ |
8607 | 150 af->control=control; |
151 af->uninit=uninit; | |
152 af->play=play; | |
24888 | 153 af->mul=1; |
8607 | 154 af->data=calloc(1,sizeof(af_data_t)); |
155 af->setup=calloc(1,sizeof(af_comp_t)); | |
156 if(af->data == NULL || af->setup == NULL) | |
157 return AF_ERROR; | |
158 return AF_OK; | |
159 } | |
160 | |
161 // Description of this filter | |
162 af_info_t af_info_comp = { | |
163 "Compressor/expander audio filter", | |
164 "comp", | |
165 "Anders", | |
166 "", | |
167 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
|
168 af_open |
8607 | 169 }; |