Mercurial > mplayer.hg
annotate libaf/af.c @ 13926:b7ba9bcd1916
Avoid drawing before transformation matrices are set up.
author | reimar |
---|---|
date | Sat, 13 Nov 2004 12:01:20 +0000 |
parents | 0c2e5c9476df |
children | be8f4abbe960 |
rev | line source |
---|---|
7568 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 | |
5 #ifdef HAVE_MALLOC_H | |
6 #include <malloc.h> | |
7 #endif | |
8 | |
9 #include "af.h" | |
10908 | 10 #include "../config.h" |
7568 | 11 |
12 // Static list of filters | |
13 extern af_info_t af_info_dummy; | |
14 extern af_info_t af_info_delay; | |
15 extern af_info_t af_info_channels; | |
16 extern af_info_t af_info_format; | |
17 extern af_info_t af_info_resample; | |
7974
db1f16543379
enable volume filter and fix nonsense default volume (still not usable
rfelker
parents:
7745
diff
changeset
|
18 extern af_info_t af_info_volume; |
8073 | 19 extern af_info_t af_info_equalizer; |
8607 | 20 extern af_info_t af_info_gate; |
21 extern af_info_t af_info_comp; | |
22 extern af_info_t af_info_pan; | |
8678 | 23 extern af_info_t af_info_surround; |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
8711
diff
changeset
|
24 extern af_info_t af_info_sub; |
10892
2167ac4c1d72
Adding filter for exporting audio data to visual effect applications
anders
parents:
8969
diff
changeset
|
25 extern af_info_t af_info_export; |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
13269
diff
changeset
|
26 extern af_info_t af_info_volnorm; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
13269
diff
changeset
|
27 extern af_info_t af_info_extrastereo; |
13713 | 28 extern af_info_t af_info_lavcresample; |
13721 | 29 extern af_info_t af_info_sweep; |
7568 | 30 |
10908 | 31 static af_info_t* filter_list[]={ |
32 &af_info_dummy, | |
33 &af_info_delay, | |
34 &af_info_channels, | |
35 &af_info_format, | |
36 &af_info_resample, | |
37 &af_info_volume, | |
38 &af_info_equalizer, | |
39 &af_info_gate, | |
40 &af_info_comp, | |
41 &af_info_pan, | |
42 &af_info_surround, | |
43 &af_info_sub, | |
44 #ifdef HAVE_SYS_MMAN_H | |
45 &af_info_export, | |
46 #endif | |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
13269
diff
changeset
|
47 &af_info_volnorm, |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
13269
diff
changeset
|
48 &af_info_extrastereo, |
13713 | 49 #ifdef USE_LIBAVCODEC |
50 &af_info_lavcresample, | |
51 #endif | |
13721 | 52 &af_info_sweep, |
10908 | 53 NULL |
7568 | 54 }; |
55 | |
8167 | 56 // Message printing |
57 af_msg_cfg_t af_msg_cfg={0,NULL,NULL}; | |
58 | |
59 // CPU speed | |
60 int* af_cpu_speed = NULL; | |
61 | |
7568 | 62 /* Find a filter in the static list of filters using it's name. This |
63 function is used internally */ | |
64 af_info_t* af_find(char*name) | |
65 { | |
66 int i=0; | |
67 while(filter_list[i]){ | |
68 if(!strcmp(filter_list[i]->name,name)) | |
69 return filter_list[i]; | |
70 i++; | |
71 } | |
8167 | 72 af_msg(AF_MSG_ERROR,"Couldn't find audio filter '%s'\n",name); |
7568 | 73 return NULL; |
74 } | |
75 | |
7615 | 76 /* Find filter in the dynamic filter list using it's name This |
77 function is used for finding already initialized filters */ | |
78 af_instance_t* af_get(af_stream_t* s, char* name) | |
79 { | |
80 af_instance_t* af=s->first; | |
81 // Find the filter | |
82 while(af != NULL){ | |
83 if(!strcmp(af->info->name,name)) | |
84 return af; | |
85 af=af->next; | |
86 } | |
87 return NULL; | |
88 } | |
89 | |
7993
ea0680d87f3f
Changing the behavour of the commandline parameter -af to conform with -vop. Adding new commanline parameter -af-adv for advanced af options. Adding changes to volume control to support commandline parameters.
anders
parents:
7974
diff
changeset
|
90 /*/ Function for creating a new filter of type name. The name may |
ea0680d87f3f
Changing the behavour of the commandline parameter -af to conform with -vop. Adding new commanline parameter -af-adv for advanced af options. Adding changes to volume control to support commandline parameters.
anders
parents:
7974
diff
changeset
|
91 contain the commandline parameters for the filter */ |
7615 | 92 af_instance_t* af_create(af_stream_t* s, char* name) |
7568 | 93 { |
7993
ea0680d87f3f
Changing the behavour of the commandline parameter -af to conform with -vop. Adding new commanline parameter -af-adv for advanced af options. Adding changes to volume control to support commandline parameters.
anders
parents:
7974
diff
changeset
|
94 char* cmdline = name; |
7998
d48a06d07afb
Adding commandline options for filters and fixing stupid bug in cfg
anders
parents:
7993
diff
changeset
|
95 |
7568 | 96 // Allocate space for the new filter and reset all pointers |
97 af_instance_t* new=malloc(sizeof(af_instance_t)); | |
98 if(!new){ | |
8607 | 99 af_msg(AF_MSG_ERROR,"[libaf] Could not allocate memory\n"); |
7568 | 100 return NULL; |
101 } | |
102 memset(new,0,sizeof(af_instance_t)); | |
103 | |
7993
ea0680d87f3f
Changing the behavour of the commandline parameter -af to conform with -vop. Adding new commanline parameter -af-adv for advanced af options. Adding changes to volume control to support commandline parameters.
anders
parents:
7974
diff
changeset
|
104 // Check for commandline parameters |
12668
ce6ab8cb8597
Send a command throught the filter chain until some item returns AF_OK. Patch by Reimar Doeffinger
alex
parents:
11859
diff
changeset
|
105 strsep(&cmdline, "="); |
7993
ea0680d87f3f
Changing the behavour of the commandline parameter -af to conform with -vop. Adding new commanline parameter -af-adv for advanced af options. Adding changes to volume control to support commandline parameters.
anders
parents:
7974
diff
changeset
|
106 |
7568 | 107 // Find filter from name |
7615 | 108 if(NULL == (new->info=af_find(name))) |
109 return NULL; | |
110 | |
7993
ea0680d87f3f
Changing the behavour of the commandline parameter -af to conform with -vop. Adding new commanline parameter -af-adv for advanced af options. Adding changes to volume control to support commandline parameters.
anders
parents:
7974
diff
changeset
|
111 /* Make sure that the filter is not already in the list if it is |
ea0680d87f3f
Changing the behavour of the commandline parameter -af to conform with -vop. Adding new commanline parameter -af-adv for advanced af options. Adding changes to volume control to support commandline parameters.
anders
parents:
7974
diff
changeset
|
112 non-reentrant */ |
7615 | 113 if(new->info->flags & AF_FLAGS_NOT_REENTRANT){ |
114 if(af_get(s,name)){ | |
8607 | 115 af_msg(AF_MSG_ERROR,"[libaf] There can only be one instance of" |
116 " the filter '%s' in each stream\n",name); | |
7615 | 117 free(new); |
118 return NULL; | |
119 } | |
120 } | |
7993
ea0680d87f3f
Changing the behavour of the commandline parameter -af to conform with -vop. Adding new commanline parameter -af-adv for advanced af options. Adding changes to volume control to support commandline parameters.
anders
parents:
7974
diff
changeset
|
121 |
8607 | 122 af_msg(AF_MSG_VERBOSE,"[libaf] Adding filter %s \n",name); |
7993
ea0680d87f3f
Changing the behavour of the commandline parameter -af to conform with -vop. Adding new commanline parameter -af-adv for advanced af options. Adding changes to volume control to support commandline parameters.
anders
parents:
7974
diff
changeset
|
123 |
7568 | 124 // Initialize the new filter |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
125 if(AF_OK == new->info->open(new) && |
7993
ea0680d87f3f
Changing the behavour of the commandline parameter -af to conform with -vop. Adding new commanline parameter -af-adv for advanced af options. Adding changes to volume control to support commandline parameters.
anders
parents:
7974
diff
changeset
|
126 AF_ERROR < new->control(new,AF_CONTROL_POST_CREATE,&s->cfg)){ |
ea0680d87f3f
Changing the behavour of the commandline parameter -af to conform with -vop. Adding new commanline parameter -af-adv for advanced af options. Adding changes to volume control to support commandline parameters.
anders
parents:
7974
diff
changeset
|
127 if(cmdline){ |
ea0680d87f3f
Changing the behavour of the commandline parameter -af to conform with -vop. Adding new commanline parameter -af-adv for advanced af options. Adding changes to volume control to support commandline parameters.
anders
parents:
7974
diff
changeset
|
128 if(AF_ERROR<new->control(new,AF_CONTROL_COMMAND_LINE,cmdline)) |
ea0680d87f3f
Changing the behavour of the commandline parameter -af to conform with -vop. Adding new commanline parameter -af-adv for advanced af options. Adding changes to volume control to support commandline parameters.
anders
parents:
7974
diff
changeset
|
129 return new; |
ea0680d87f3f
Changing the behavour of the commandline parameter -af to conform with -vop. Adding new commanline parameter -af-adv for advanced af options. Adding changes to volume control to support commandline parameters.
anders
parents:
7974
diff
changeset
|
130 } |
ea0680d87f3f
Changing the behavour of the commandline parameter -af to conform with -vop. Adding new commanline parameter -af-adv for advanced af options. Adding changes to volume control to support commandline parameters.
anders
parents:
7974
diff
changeset
|
131 else |
ea0680d87f3f
Changing the behavour of the commandline parameter -af to conform with -vop. Adding new commanline parameter -af-adv for advanced af options. Adding changes to volume control to support commandline parameters.
anders
parents:
7974
diff
changeset
|
132 return new; |
ea0680d87f3f
Changing the behavour of the commandline parameter -af to conform with -vop. Adding new commanline parameter -af-adv for advanced af options. Adding changes to volume control to support commandline parameters.
anders
parents:
7974
diff
changeset
|
133 } |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
134 |
7568 | 135 free(new); |
8607 | 136 af_msg(AF_MSG_ERROR,"[libaf] Couldn't create or open audio filter '%s'\n", |
137 name); | |
7568 | 138 return NULL; |
139 } | |
140 | |
141 /* Create and insert a new filter of type name before the filter in the | |
142 argument. This function can be called during runtime, the return | |
143 value is the new filter */ | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
144 af_instance_t* af_prepend(af_stream_t* s, af_instance_t* af, char* name) |
7568 | 145 { |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
146 // Create the new filter and make sure it is OK |
7615 | 147 af_instance_t* new=af_create(s,name); |
7568 | 148 if(!new) |
149 return NULL; | |
150 // Update pointers | |
151 new->next=af; | |
152 if(af){ | |
153 new->prev=af->prev; | |
154 af->prev=new; | |
155 } | |
156 else | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
157 s->last=new; |
7568 | 158 if(new->prev) |
159 new->prev->next=new; | |
160 else | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
161 s->first=new; |
7568 | 162 return new; |
163 } | |
164 | |
165 /* Create and insert a new filter of type name after the filter in the | |
166 argument. This function can be called during runtime, the return | |
167 value is the new filter */ | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
168 af_instance_t* af_append(af_stream_t* s, af_instance_t* af, char* name) |
7568 | 169 { |
170 // Create the new filter and make sure it is OK | |
7615 | 171 af_instance_t* new=af_create(s,name); |
7568 | 172 if(!new) |
173 return NULL; | |
174 // Update pointers | |
175 new->prev=af; | |
176 if(af){ | |
177 new->next=af->next; | |
178 af->next=new; | |
179 } | |
180 else | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
181 s->first=new; |
7568 | 182 if(new->next) |
183 new->next->prev=new; | |
184 else | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
185 s->last=new; |
7568 | 186 return new; |
187 } | |
188 | |
189 // Uninit and remove the filter "af" | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
190 void af_remove(af_stream_t* s, af_instance_t* af) |
7568 | 191 { |
192 if(!af) return; | |
193 | |
8607 | 194 // Print friendly message |
195 af_msg(AF_MSG_VERBOSE,"[libaf] Removing filter %s \n",af->info->name); | |
196 | |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
197 // Notify filter before changing anything |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
198 af->control(af,AF_CONTROL_PRE_DESTROY,0); |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
199 |
7568 | 200 // Detach pointers |
201 if(af->prev) | |
202 af->prev->next=af->next; | |
203 else | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
204 s->first=af->next; |
7568 | 205 if(af->next) |
206 af->next->prev=af->prev; | |
207 else | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
208 s->last=af->prev; |
7568 | 209 |
210 // Uninitialize af and free memory | |
211 af->uninit(af); | |
212 free(af); | |
213 } | |
214 | |
7649
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
215 /* Reinitializes all filters downstream from the filter given in the |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
216 argument the return value is AF_OK if success and AF_ERROR if |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
217 failure */ |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
218 int af_reinit(af_stream_t* s, af_instance_t* af) |
7568 | 219 { |
220 if(!af) | |
221 return AF_ERROR; | |
222 | |
223 do{ | |
224 af_data_t in; // Format of the input to current filter | |
225 int rv=0; // Return value | |
226 | |
227 // Check if this is the first filter | |
228 if(!af->prev) | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
229 memcpy(&in,&(s->input),sizeof(af_data_t)); |
7568 | 230 else |
231 memcpy(&in,af->prev->data,sizeof(af_data_t)); | |
232 // Reset just in case... | |
233 in.audio=NULL; | |
234 in.len=0; | |
235 | |
236 rv = af->control(af,AF_CONTROL_REINIT,&in); | |
237 switch(rv){ | |
238 case AF_OK: | |
239 break; | |
240 case AF_FALSE:{ // Configuration filter is needed | |
8167 | 241 // Do auto insertion only if force is not specified |
242 if((AF_INIT_TYPE_MASK & s->cfg.force) != AF_INIT_FORCE){ | |
243 af_instance_t* new = NULL; | |
244 // Insert channels filter | |
245 if((af->prev?af->prev->data->nch:s->input.nch) != in.nch){ | |
246 // Create channels filter | |
247 if(NULL == (new = af_prepend(s,af,"channels"))) | |
248 return AF_ERROR; | |
249 // Set number of output channels | |
250 if(AF_OK != (rv = new->control(new,AF_CONTROL_CHANNELS,&in.nch))) | |
251 return rv; | |
252 // Initialize channels filter | |
253 if(!new->prev) | |
254 memcpy(&in,&(s->input),sizeof(af_data_t)); | |
255 else | |
256 memcpy(&in,new->prev->data,sizeof(af_data_t)); | |
257 if(AF_OK != (rv = new->control(new,AF_CONTROL_REINIT,&in))) | |
258 return rv; | |
259 } | |
260 // Insert format filter | |
261 if(((af->prev?af->prev->data->format:s->input.format) != in.format) || | |
262 ((af->prev?af->prev->data->bps:s->input.bps) != in.bps)){ | |
263 // Create format filter | |
264 if(NULL == (new = af_prepend(s,af,"format"))) | |
265 return AF_ERROR; | |
8607 | 266 // Set output bits per sample |
267 if(AF_OK != (rv = new->control(new,AF_CONTROL_FORMAT_BPS,&in.bps)) || | |
268 AF_OK != (rv = new->control(new,AF_CONTROL_FORMAT_FMT,&in.format))) | |
8167 | 269 return rv; |
270 // Initialize format filter | |
271 if(!new->prev) | |
272 memcpy(&in,&(s->input),sizeof(af_data_t)); | |
273 else | |
274 memcpy(&in,new->prev->data,sizeof(af_data_t)); | |
275 if(AF_OK != (rv = new->control(new,AF_CONTROL_REINIT,&in))) | |
276 return rv; | |
277 } | |
8607 | 278 if(!new){ // Should _never_ happen |
279 af_msg(AF_MSG_ERROR,"[libaf] Unable to correct audio format. " | |
280 "This error should never uccur, please send bugreport.\n"); | |
7568 | 281 return AF_ERROR; |
8607 | 282 } |
8167 | 283 af=new; |
7568 | 284 } |
285 break; | |
286 } | |
287 case AF_DETACH:{ // Filter is redundant and wants to be unloaded | |
8167 | 288 // Do auto remove only if force is not specified |
289 if((AF_INIT_TYPE_MASK & s->cfg.force) != AF_INIT_FORCE){ | |
290 af_instance_t* aft=af->prev; | |
291 af_remove(s,af); | |
292 if(aft) | |
293 af=aft; | |
294 else | |
295 af=s->first; // Restart configuration | |
296 } | |
7568 | 297 break; |
298 } | |
299 default: | |
8607 | 300 af_msg(AF_MSG_ERROR,"[libaf] Reinitialization did not work, audio" |
301 " filter '%s' returned error code %i\n",af->info->name,rv); | |
7568 | 302 return AF_ERROR; |
303 } | |
8607 | 304 // Check if there are any filters left in the list |
305 if(NULL == af){ | |
8711
906f7a2dc085
sig 11 fix in reinit and resample + spelling error fixes
anders
parents:
8678
diff
changeset
|
306 if(!(af=af_append(s,s->first,"dummy"))) |
8607 | 307 return -1; |
308 } | |
309 else | |
310 af=af->next; | |
7568 | 311 }while(af); |
312 return AF_OK; | |
313 } | |
314 | |
315 // Uninit and remove all filters | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
316 void af_uninit(af_stream_t* s) |
7568 | 317 { |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
318 while(s->first) |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
319 af_remove(s,s->first); |
7568 | 320 } |
321 | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
322 /* Initialize the stream "s". This function creates a new filter list |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
323 if necessary according to the values set in input and output. Input |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
324 and output should contain the format of the current movie and the |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
325 formate of the preferred output respectively. The function is |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
326 reentrant i.e. if called with an already initialized stream the |
8969
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8832
diff
changeset
|
327 stream will be reinitialized. If the binary parameter |
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8832
diff
changeset
|
328 "force_output" is set, the output format will be converted to the |
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8832
diff
changeset
|
329 format given in "s", otherwise the output fromat in the last filter |
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8832
diff
changeset
|
330 will be copied "s". The return value is 0 if success and -1 if |
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8832
diff
changeset
|
331 failure */ |
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8832
diff
changeset
|
332 int af_init(af_stream_t* s, int force_output) |
7568 | 333 { |
334 int i=0; | |
335 | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
336 // Sanity check |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
337 if(!s) return -1; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
338 |
7568 | 339 // Precaution in case caller is misbehaving |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
340 s->input.audio = s->output.audio = NULL; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
341 s->input.len = s->output.len = 0; |
7568 | 342 |
343 // Figure out how fast the machine is | |
8167 | 344 if(AF_INIT_AUTO == (AF_INIT_TYPE_MASK & s->cfg.force)) |
345 s->cfg.force = (s->cfg.force & ~AF_INIT_TYPE_MASK) | AF_INIT_TYPE; | |
7568 | 346 |
347 // Check if this is the first call | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
348 if(!s->first){ |
7568 | 349 // Add all filters in the list (if there are any) |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
350 if(!s->cfg.list){ // To make automatic format conversion work |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
351 if(!af_append(s,s->first,"dummy")) |
7568 | 352 return -1; |
353 } | |
354 else{ | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
355 while(s->cfg.list[i]){ |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
356 if(!af_append(s,s->last,s->cfg.list[i++])) |
7568 | 357 return -1; |
358 } | |
359 } | |
360 } | |
8607 | 361 |
7568 | 362 // Init filters |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
363 if(AF_OK != af_reinit(s,s->first)) |
7568 | 364 return -1; |
365 | |
8969
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8832
diff
changeset
|
366 // If force_output isn't set do not compensate for output format |
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8832
diff
changeset
|
367 if(!force_output){ |
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8832
diff
changeset
|
368 memcpy(&s->output, s->last->data, sizeof(af_data_t)); |
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8832
diff
changeset
|
369 return 0; |
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8832
diff
changeset
|
370 } |
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8832
diff
changeset
|
371 |
7568 | 372 // Check output format |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
373 if((AF_INIT_TYPE_MASK & s->cfg.force) != AF_INIT_FORCE){ |
7568 | 374 af_instance_t* af = NULL; // New filter |
375 // Check output frequency if not OK fix with resample | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
376 if(s->last->data->rate!=s->output.rate){ |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
377 if(NULL==(af=af_get(s,"resample"))){ |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
378 if((AF_INIT_TYPE_MASK & s->cfg.force) == AF_INIT_SLOW){ |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
379 if(!strcmp(s->first->info->name,"format")) |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
380 af = af_append(s,s->first,"resample"); |
7568 | 381 else |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
382 af = af_prepend(s,s->first,"resample"); |
7568 | 383 } |
384 else{ | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
385 if(!strcmp(s->last->info->name,"format")) |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
386 af = af_prepend(s,s->last,"resample"); |
7568 | 387 else |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
388 af = af_append(s,s->last,"resample"); |
7568 | 389 } |
390 } | |
391 // Init the new filter | |
8607 | 392 if(!af || (AF_OK != af->control(af,AF_CONTROL_RESAMPLE_RATE, |
393 &(s->output.rate)))) | |
7568 | 394 return -1; |
11859
b8bee4f4b8bb
if the user wants fast, use fast code! otherwise the user has to put
rfelker
parents:
10908
diff
changeset
|
395 // Use lin int if the user wants fast |
b8bee4f4b8bb
if the user wants fast, use fast code! otherwise the user has to put
rfelker
parents:
10908
diff
changeset
|
396 if ((AF_INIT_TYPE_MASK & s->cfg.force) == AF_INIT_FAST) { |
b8bee4f4b8bb
if the user wants fast, use fast code! otherwise the user has to put
rfelker
parents:
10908
diff
changeset
|
397 char args[32]; |
b8bee4f4b8bb
if the user wants fast, use fast code! otherwise the user has to put
rfelker
parents:
10908
diff
changeset
|
398 sprintf(args, "%d:0:0", s->output.rate); |
b8bee4f4b8bb
if the user wants fast, use fast code! otherwise the user has to put
rfelker
parents:
10908
diff
changeset
|
399 af->control(af, AF_CONTROL_COMMAND_LINE, args); |
b8bee4f4b8bb
if the user wants fast, use fast code! otherwise the user has to put
rfelker
parents:
10908
diff
changeset
|
400 } |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
401 if(AF_OK != af_reinit(s,af)) |
7568 | 402 return -1; |
403 } | |
404 | |
405 // Check number of output channels fix if not OK | |
406 // If needed always inserted last -> easy to screw up other filters | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
407 if(s->last->data->nch!=s->output.nch){ |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
408 if(!strcmp(s->last->info->name,"format")) |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
409 af = af_prepend(s,s->last,"channels"); |
7568 | 410 else |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
411 af = af_append(s,s->last,"channels"); |
7568 | 412 // Init the new filter |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
413 if(!af || (AF_OK != af->control(af,AF_CONTROL_CHANNELS,&(s->output.nch)))) |
7568 | 414 return -1; |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
415 if(AF_OK != af_reinit(s,af)) |
7568 | 416 return -1; |
417 } | |
418 | |
419 // Check output format fix if not OK | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
420 if((s->last->data->format != s->output.format) || |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
421 (s->last->data->bps != s->output.bps)){ |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
422 if(strcmp(s->last->info->name,"format")) |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
423 af = af_append(s,s->last,"format"); |
7568 | 424 else |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
425 af = s->last; |
7568 | 426 // Init the new filter |
8607 | 427 if(!af ||(AF_OK != af->control(af,AF_CONTROL_FORMAT_BPS,&(s->output.bps))) |
428 || (AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT,&(s->output.format)))) | |
7568 | 429 return -1; |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
430 if(AF_OK != af_reinit(s,af)) |
7568 | 431 return -1; |
432 } | |
433 | |
434 // Re init again just in case | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
435 if(AF_OK != af_reinit(s,s->first)) |
7568 | 436 return -1; |
437 | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
438 if((s->last->data->format != s->output.format) || |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
439 (s->last->data->bps != s->output.bps) || |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
440 (s->last->data->nch != s->output.nch) || |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
441 (s->last->data->rate != s->output.rate)) { |
7568 | 442 // Something is stuffed audio out will not work |
8607 | 443 af_msg(AF_MSG_ERROR,"[libaf] Unable to setup filter system can not" |
444 " meet sound-card demands, please send bugreport. \n"); | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
445 af_uninit(s); |
7568 | 446 return -1; |
447 } | |
448 } | |
449 return 0; | |
450 } | |
451 | |
7649
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
452 /* Add filter during execution. This function adds the filter "name" |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
453 to the stream s. The filter will be inserted somewhere nice in the |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
454 list of filters. The return value is a pointer to the new filter, |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
455 If the filter couldn't be added the return value is NULL. */ |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
456 af_instance_t* af_add(af_stream_t* s, char* name){ |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
457 af_instance_t* new; |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
458 // Sanity check |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
459 if(!s || !s->first || !name) |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
460 return NULL; |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
461 // Insert the filter somwhere nice |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
462 if(!strcmp(s->first->info->name,"format")) |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
463 new = af_append(s, s->first, name); |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
464 else |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
465 new = af_prepend(s, s->first, name); |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
466 if(!new) |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
467 return NULL; |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
468 |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
469 // Reinitalize the filter list |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
470 if(AF_OK != af_reinit(s, s->first)){ |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
471 free(new); |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
472 return NULL; |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
473 } |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
474 return new; |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
475 } |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7617
diff
changeset
|
476 |
7568 | 477 // Filter data chunk through the filters in the list |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
478 af_data_t* af_play(af_stream_t* s, af_data_t* data) |
7568 | 479 { |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
480 af_instance_t* af=s->first; |
7568 | 481 // Iterate through all filters |
482 do{ | |
483 data=af->play(af,data); | |
484 af=af->next; | |
485 }while(af); | |
486 return data; | |
487 } | |
488 | |
489 /* Helper function used to calculate the exact buffer length needed | |
7589 | 490 when buffers are resized. The returned length is >= than what is |
491 needed */ | |
492 inline int af_lencalc(frac_t mul, af_data_t* d){ | |
493 register int t = d->bps*d->nch; | |
7590 | 494 return t*(((d->len/t)*mul.n)/mul.d + 1); |
7568 | 495 } |
496 | |
497 /* Calculate how long the output from the filters will be given the | |
7589 | 498 input length "len". The calculated length is >= the actual |
499 length. */ | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
500 int af_outputlen(af_stream_t* s, int len) |
7568 | 501 { |
7589 | 502 int t = s->input.bps*s->input.nch; |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
503 af_instance_t* af=s->first; |
7589 | 504 register frac_t mul = {1,1}; |
7568 | 505 // Iterate through all filters |
506 do{ | |
507 mul.n *= af->mul.n; | |
508 mul.d *= af->mul.d; | |
509 af=af->next; | |
510 }while(af); | |
7589 | 511 return t * (((len/t)*mul.n + 1)/mul.d); |
7568 | 512 } |
513 | |
514 /* Calculate how long the input to the filters should be to produce a | |
515 certain output length, i.e. the return value of this function is | |
7589 | 516 the input length required to produce the output length "len". The |
517 calculated length is <= the actual length */ | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
518 int af_inputlen(af_stream_t* s, int len) |
7568 | 519 { |
7589 | 520 int t = s->input.bps*s->input.nch; |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
521 af_instance_t* af=s->first; |
7589 | 522 register frac_t mul = {1,1}; |
7568 | 523 // Iterate through all filters |
524 do{ | |
7589 | 525 mul.n *= af->mul.n; |
526 mul.d *= af->mul.d; | |
7568 | 527 af=af->next; |
528 }while(af); | |
7589 | 529 return t * (((len/t) * mul.d - 1)/mul.n); |
7568 | 530 } |
531 | |
7598
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
532 /* Calculate how long the input IN to the filters should be to produce |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
533 a certain output length OUT but with the following three constraints: |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
534 1. IN <= max_insize, where max_insize is the maximum possible input |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
535 block length |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
536 2. OUT <= max_outsize, where max_outsize is the maximum possible |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
537 output block length |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
538 3. If possible OUT >= len. |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
539 Return -1 in case of error */ |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
540 int af_calc_insize_constrained(af_stream_t* s, int len, |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
541 int max_outsize,int max_insize) |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
542 { |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
543 int t = s->input.bps*s->input.nch; |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
544 int in = 0; |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
545 int out = 0; |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
546 af_instance_t* af=s->first; |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
547 register frac_t mul = {1,1}; |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
548 // Iterate through all filters and calculate total multiplication factor |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
549 do{ |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
550 mul.n *= af->mul.n; |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
551 mul.d *= af->mul.d; |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
552 af=af->next; |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
553 }while(af); |
8607 | 554 // Sanity check |
555 if(!mul.n || !mul.d) | |
556 return -1; | |
557 | |
7603
c89106306f5a
af_calc_insize_constrained() rounding changes, works better for me this way
arpi
parents:
7599
diff
changeset
|
558 in = t * (((len/t) * mul.d - 1)/mul.n); |
c89106306f5a
af_calc_insize_constrained() rounding changes, works better for me this way
arpi
parents:
7599
diff
changeset
|
559 |
c89106306f5a
af_calc_insize_constrained() rounding changes, works better for me this way
arpi
parents:
7599
diff
changeset
|
560 if(in>max_insize) in=t*(max_insize/t); |
7598
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
561 |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
562 // Try to meet constraint nr 3. |
7612 | 563 while((out=t * (((in/t+1)*mul.n - 1)/mul.d)) <= max_outsize && in<=max_insize){ |
7603
c89106306f5a
af_calc_insize_constrained() rounding changes, works better for me this way
arpi
parents:
7599
diff
changeset
|
564 if( (t * (((in/t)*mul.n))/mul.d) >= len) return in; |
7598
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
565 in+=t; |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
566 } |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
567 |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
568 // Could no meet constraint nr 3. |
7603
c89106306f5a
af_calc_insize_constrained() rounding changes, works better for me this way
arpi
parents:
7599
diff
changeset
|
569 while(out > max_outsize || in > max_insize){ |
7598
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
570 in-=t; |
7603
c89106306f5a
af_calc_insize_constrained() rounding changes, works better for me this way
arpi
parents:
7599
diff
changeset
|
571 if(in<t) return -1; // Input parameters are probably incorrect |
7598
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
572 out = t * (((in/t)*mul.n + 1)/mul.d); |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
573 } |
7603
c89106306f5a
af_calc_insize_constrained() rounding changes, works better for me this way
arpi
parents:
7599
diff
changeset
|
574 return in; |
7598
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
575 } |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7590
diff
changeset
|
576 |
7665
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
577 /* Calculate the total delay [ms] caused by the filters */ |
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
578 double af_calc_delay(af_stream_t* s) |
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
579 { |
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
580 af_instance_t* af=s->first; |
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
581 register double delay = 0.0; |
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
582 // Iterate through all filters |
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
583 while(af){ |
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
584 delay += af->delay; |
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
585 af=af->next; |
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
586 } |
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
587 return delay; |
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
588 } |
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
589 |
7568 | 590 /* Helper function called by the macro with the same name this |
591 function should not be called directly */ | |
592 inline int af_resize_local_buffer(af_instance_t* af, af_data_t* data) | |
593 { | |
594 // Calculate new length | |
7589 | 595 register int len = af_lencalc(af->mul,data); |
8607 | 596 af_msg(AF_MSG_VERBOSE,"[libaf] Reallocating memory in module %s, " |
597 "old len = %i, new len = %i\n",af->info->name,af->data->len,len); | |
7568 | 598 // If there is a buffer free it |
599 if(af->data->audio) | |
600 free(af->data->audio); | |
601 // Create new buffer and check that it is OK | |
602 af->data->audio = malloc(len); | |
603 if(!af->data->audio){ | |
8607 | 604 af_msg(AF_MSG_FATAL,"[libaf] Could not allocate memory \n"); |
7568 | 605 return AF_ERROR; |
606 } | |
607 af->data->len=len; | |
608 return AF_OK; | |
609 } | |
12668
ce6ab8cb8597
Send a command throught the filter chain until some item returns AF_OK. Patch by Reimar Doeffinger
alex
parents:
11859
diff
changeset
|
610 |
ce6ab8cb8597
Send a command throught the filter chain until some item returns AF_OK. Patch by Reimar Doeffinger
alex
parents:
11859
diff
changeset
|
611 // send control to all filters, starting with the last until |
ce6ab8cb8597
Send a command throught the filter chain until some item returns AF_OK. Patch by Reimar Doeffinger
alex
parents:
11859
diff
changeset
|
612 // one responds with AF_OK |
ce6ab8cb8597
Send a command throught the filter chain until some item returns AF_OK. Patch by Reimar Doeffinger
alex
parents:
11859
diff
changeset
|
613 int af_control_any_rev (af_stream_t* s, int cmd, void* arg) { |
ce6ab8cb8597
Send a command throught the filter chain until some item returns AF_OK. Patch by Reimar Doeffinger
alex
parents:
11859
diff
changeset
|
614 int res = AF_UNKNOWN; |
ce6ab8cb8597
Send a command throught the filter chain until some item returns AF_OK. Patch by Reimar Doeffinger
alex
parents:
11859
diff
changeset
|
615 af_instance_t* filt = s->last; |
ce6ab8cb8597
Send a command throught the filter chain until some item returns AF_OK. Patch by Reimar Doeffinger
alex
parents:
11859
diff
changeset
|
616 while (filt && res != AF_OK) { |
ce6ab8cb8597
Send a command throught the filter chain until some item returns AF_OK. Patch by Reimar Doeffinger
alex
parents:
11859
diff
changeset
|
617 res = filt->control(filt, cmd, arg); |
ce6ab8cb8597
Send a command throught the filter chain until some item returns AF_OK. Patch by Reimar Doeffinger
alex
parents:
11859
diff
changeset
|
618 filt = filt->prev; |
ce6ab8cb8597
Send a command throught the filter chain until some item returns AF_OK. Patch by Reimar Doeffinger
alex
parents:
11859
diff
changeset
|
619 } |
ce6ab8cb8597
Send a command throught the filter chain until some item returns AF_OK. Patch by Reimar Doeffinger
alex
parents:
11859
diff
changeset
|
620 return (res == AF_OK); |
ce6ab8cb8597
Send a command throught the filter chain until some item returns AF_OK. Patch by Reimar Doeffinger
alex
parents:
11859
diff
changeset
|
621 } |
ce6ab8cb8597
Send a command throught the filter chain until some item returns AF_OK. Patch by Reimar Doeffinger
alex
parents:
11859
diff
changeset
|
622 |
13269
aa13937da8a0
mplayer -af help now lists all available audio filters.
ivo
parents:
12668
diff
changeset
|
623 void af_help (void) { |
aa13937da8a0
mplayer -af help now lists all available audio filters.
ivo
parents:
12668
diff
changeset
|
624 int i = 0; |
13566
2cfb32a737aa
make af_help conform better to the the afm/vfm/etc equivalents
alex
parents:
13550
diff
changeset
|
625 af_msg(AF_MSG_INFO, "Available audio filters:\n"); |
13269
aa13937da8a0
mplayer -af help now lists all available audio filters.
ivo
parents:
12668
diff
changeset
|
626 while (filter_list[i]) { |
13566
2cfb32a737aa
make af_help conform better to the the afm/vfm/etc equivalents
alex
parents:
13550
diff
changeset
|
627 if (filter_list[i]->comment && filter_list[i]->comment[0]) |
2cfb32a737aa
make af_help conform better to the the afm/vfm/etc equivalents
alex
parents:
13550
diff
changeset
|
628 af_msg(AF_MSG_INFO, " %-15s: %s (%s)\n", filter_list[i]->name, filter_list[i]->info, filter_list[i]->comment); |
2cfb32a737aa
make af_help conform better to the the afm/vfm/etc equivalents
alex
parents:
13550
diff
changeset
|
629 else |
2cfb32a737aa
make af_help conform better to the the afm/vfm/etc equivalents
alex
parents:
13550
diff
changeset
|
630 af_msg(AF_MSG_INFO, " %-15s: %s\n", filter_list[i]->name, filter_list[i]->info); |
13269
aa13937da8a0
mplayer -af help now lists all available audio filters.
ivo
parents:
12668
diff
changeset
|
631 i++; |
aa13937da8a0
mplayer -af help now lists all available audio filters.
ivo
parents:
12668
diff
changeset
|
632 } |
aa13937da8a0
mplayer -af help now lists all available audio filters.
ivo
parents:
12668
diff
changeset
|
633 } |
aa13937da8a0
mplayer -af help now lists all available audio filters.
ivo
parents:
12668
diff
changeset
|
634 |