Mercurial > mplayer.hg
annotate libaf/af_comp.c @ 11499:8f3305688c21
double nVidia VIDIx link removed
EMPHASIS -> emphasis, wording
matroxfb compilation instructions
author | wight |
---|---|
date | Thu, 20 Nov 2003 11:56:04 +0000 |
parents | 93212da0032e |
children | 14090f7300a8 |
rev | line source |
---|---|
8607 | 1 /*============================================================================= |
2 // | |
3 // This software has been released under the terms of the GNU Public | |
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 <unistd.h> | |
16 #include <inttypes.h> | |
17 #include <math.h> | |
18 #include <limits.h> | |
19 | |
20 #include "af.h" | |
21 | |
22 // Data for specific instances of this filter | |
23 typedef struct af_comp_s | |
24 { | |
25 int enable[AF_NCH]; // Enable/disable / channel | |
26 float time[AF_NCH]; // Forgetting factor for power estimate | |
27 float pow[AF_NCH]; // Estimated power level [dB] | |
28 float tresh[AF_NCH]; // Threshold [dB] | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
29 int attack[AF_NCH]; // Attack time [ms] |
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8623
diff
changeset
|
30 int release[AF_NCH]; // Release time [ms] |
8607 | 31 float ratio[AF_NCH]; // Compression ratio |
32 }af_comp_t; | |
33 | |
34 // Initialization and runtime control | |
35 static int control(struct af_instance_s* af, int cmd, void* arg) | |
36 { | |
37 af_comp_t* s = (af_comp_t*)af->setup; | |
38 int i; | |
39 | |
40 switch(cmd){ | |
41 case AF_CONTROL_REINIT: | |
42 // Sanity check | |
43 if(!arg) return AF_ERROR; | |
44 | |
45 af->data->rate = ((af_data_t*)arg)->rate; | |
46 af->data->nch = ((af_data_t*)arg)->nch; | |
47 af->data->format = AF_FORMAT_F | AF_FORMAT_NE; | |
48 af->data->bps = 4; | |
49 | |
50 // Time constant set to 0.1s | |
51 // s->alpha = (1.0/0.2)/(2.0*M_PI*(float)((af_data_t*)arg)->rate); | |
52 return af_test_output(af,(af_data_t*)arg); | |
53 case AF_CONTROL_COMMAND_LINE:{ | |
54 /* float v=-10.0; */ | |
55 /* float vol[AF_NCH]; */ | |
56 /* float s=0.0; */ | |
57 /* float clipp[AF_NCH]; */ | |
58 /* int i; */ | |
59 /* sscanf((char*)arg,"%f:%f", &v, &s); */ | |
60 /* for(i=0;i<AF_NCH;i++){ */ | |
61 /* vol[i]=v; */ | |
62 /* clipp[i]=s; */ | |
63 /* } */ | |
64 /* if(AF_OK != control(af,AF_CONTROL_VOLUME_SOFTCLIP | AF_CONTROL_SET, clipp)) */ | |
65 /* return AF_ERROR; */ | |
66 /* return control(af,AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_SET, vol); */ | |
67 } | |
68 case AF_CONTROL_COMP_ON_OFF | AF_CONTROL_SET: | |
69 memcpy(s->enable,(int*)arg,AF_NCH*sizeof(int)); | |
70 return AF_OK; | |
71 case AF_CONTROL_COMP_ON_OFF | AF_CONTROL_GET: | |
72 memcpy((int*)arg,s->enable,AF_NCH*sizeof(int)); | |
73 return AF_OK; | |
74 case AF_CONTROL_COMP_THRESH | AF_CONTROL_SET: | |
75 return af_from_dB(AF_NCH,(float*)arg,s->tresh,20.0,-60.0,-1.0); | |
76 case AF_CONTROL_COMP_THRESH | AF_CONTROL_GET: | |
77 return af_to_dB(AF_NCH,s->tresh,(float*)arg,10.0); | |
78 case AF_CONTROL_COMP_ATTACK | AF_CONTROL_SET: | |
79 return af_from_ms(AF_NCH,(float*)arg,s->attack,af->data->rate,500.0,0.1); | |
80 case AF_CONTROL_COMP_ATTACK | AF_CONTROL_GET: | |
81 return af_to_ms(AF_NCH,s->attack,(float*)arg,af->data->rate); | |
82 case AF_CONTROL_COMP_RELEASE | AF_CONTROL_SET: | |
83 return af_from_ms(AF_NCH,(float*)arg,s->release,af->data->rate,3000.0,10.0); | |
84 case AF_CONTROL_COMP_RELEASE | AF_CONTROL_GET: | |
85 return af_to_ms(AF_NCH,s->release,(float*)arg,af->data->rate); | |
86 case AF_CONTROL_COMP_RATIO | AF_CONTROL_SET: | |
87 for(i=0;i<AF_NCH;i++) | |
88 s->ratio[i] = clamp(((float*)arg)[i],1.0,10.0); | |
89 return AF_OK; | |
90 case AF_CONTROL_COMP_RATIO | AF_CONTROL_GET: | |
91 for(i=0;i<AF_NCH;i++) | |
92 ((float*)arg)[i] = s->ratio[i]; | |
93 return AF_OK; | |
94 } | |
95 return AF_UNKNOWN; | |
96 } | |
97 | |
98 // Deallocate memory | |
99 static void uninit(struct af_instance_s* af) | |
100 { | |
101 if(af->data) | |
102 free(af->data); | |
103 if(af->setup) | |
104 free(af->setup); | |
105 } | |
106 | |
107 // Filter data through filter | |
108 static af_data_t* play(struct af_instance_s* af, af_data_t* data) | |
109 { | |
110 af_data_t* c = data; // Current working data | |
111 af_comp_t* s = (af_comp_t*)af->setup; // Setup for this instance | |
112 float* a = (float*)c->audio; // Audio data | |
113 int len = c->len/4; // Number of samples | |
114 int ch = 0; // Channel counter | |
115 register int nch = c->nch; // Number of channels | |
116 register int i = 0; | |
117 | |
118 // Compress/expand | |
119 for(ch = 0; ch < nch ; ch++){ | |
120 if(s->enable[ch]){ | |
121 float t = 1.0 - s->time[ch]; | |
122 for(i=ch;i<len;i+=nch){ | |
123 register float x = a[i]; | |
124 register float pow = x*x; | |
125 s->pow[ch] = t*s->pow[ch] + | |
126 pow*s->time[ch]; // LP filter | |
127 if(pow < s->pow[ch]){ | |
128 ; | |
129 } | |
130 else{ | |
131 ; | |
132 } | |
133 a[i] = x; | |
134 } | |
135 } | |
136 } | |
137 return c; | |
138 } | |
139 | |
140 // Allocate memory and set function pointers | |
141 static int open(af_instance_t* af){ | |
142 af->control=control; | |
143 af->uninit=uninit; | |
144 af->play=play; | |
145 af->mul.n=1; | |
146 af->mul.d=1; | |
147 af->data=calloc(1,sizeof(af_data_t)); | |
148 af->setup=calloc(1,sizeof(af_comp_t)); | |
149 if(af->data == NULL || af->setup == NULL) | |
150 return AF_ERROR; | |
151 return AF_OK; | |
152 } | |
153 | |
154 // Description of this filter | |
155 af_info_t af_info_comp = { | |
156 "Compressor/expander audio filter", | |
157 "comp", | |
158 "Anders", | |
159 "", | |
160 AF_FLAGS_NOT_REENTRANT, | |
161 open | |
162 }; |