Mercurial > mplayer.hg
annotate libaf/af.h @ 13783:4277e06630bf
compilation fix, mostly by Reza Jelveh
author | diego |
---|---|
date | Thu, 28 Oct 2004 00:50:21 +0000 |
parents | aa13937da8a0 |
children | 12239a0d5408 |
rev | line source |
---|---|
12676 | 1 #ifndef __aop_h__ |
2 #define __aop_h__ | |
3 | |
8167 | 4 #include <stdio.h> |
5 | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
6 #include "af_mp.h" |
8167 | 7 #include "config.h" |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
8 #include "control.h" |
8167 | 9 #include "af_format.h" |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
10 |
7568 | 11 struct af_instance_s; |
12 | |
13 // Audio data chunk | |
14 typedef struct af_data_s | |
15 { | |
16 void* audio; // data buffer | |
17 int len; // buffer length | |
18 int rate; // sample rate | |
19 int nch; // number of channels | |
20 int format; // format | |
21 int bps; // bytes per sample | |
22 } af_data_t; | |
23 | |
24 // Fraction, used to calculate buffer lengths | |
25 typedef struct frac_s | |
26 { | |
27 int n; // Numerator | |
28 int d; // Denominator | |
29 } frac_t; | |
30 | |
8167 | 31 // Flags used for defining the behavior of an audio filter |
7615 | 32 #define AF_FLAGS_REENTRANT 0x00000000 |
33 #define AF_FLAGS_NOT_REENTRANT 0x00000001 | |
34 | |
7568 | 35 /* Audio filter information not specific for current instance, but for |
36 a specific filter */ | |
37 typedef struct af_info_s | |
38 { | |
39 const char *info; | |
40 const char *name; | |
41 const char *author; | |
42 const char *comment; | |
7615 | 43 const int flags; |
7568 | 44 int (*open)(struct af_instance_s* vf); |
45 } af_info_t; | |
46 | |
47 // Linked list of audio filters | |
48 typedef struct af_instance_s | |
49 { | |
50 af_info_t* info; | |
51 int (*control)(struct af_instance_s* af, int cmd, void* arg); | |
52 void (*uninit)(struct af_instance_s* af); | |
53 af_data_t* (*play)(struct af_instance_s* af, af_data_t* data); | |
54 void* setup; // setup data for this specific instance and filter | |
55 af_data_t* data; // configuration for outgoing data stream | |
56 struct af_instance_s* next; | |
57 struct af_instance_s* prev; | |
7665
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
58 double delay; // Delay caused by the filter [ms] |
7568 | 59 frac_t mul; /* length multiplier: how much does this instance change |
60 the length of the buffer. */ | |
61 }af_instance_t; | |
62 | |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
63 // Initialization flags |
8167 | 64 extern int* af_cpu_speed; |
65 | |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
66 #define AF_INIT_AUTO 0x00000000 |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
67 #define AF_INIT_SLOW 0x00000001 |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
68 #define AF_INIT_FAST 0x00000002 |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
69 #define AF_INIT_FORCE 0x00000003 |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
70 #define AF_INIT_TYPE_MASK 0x00000003 |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
71 |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8674
diff
changeset
|
72 #define AF_INIT_INT 0x00000000 |
8868
398e3fb7c103
10l bug for float conversion control + feature fix in volume control
anders
parents:
8867
diff
changeset
|
73 #define AF_INIT_FLOAT 0x00000004 |
398e3fb7c103
10l bug for float conversion control + feature fix in volume control
anders
parents:
8867
diff
changeset
|
74 #define AF_INIT_FORMAT_MASK 0x00000004 |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8674
diff
changeset
|
75 |
8167 | 76 // Default init type |
77 #ifndef AF_INIT_TYPE | |
78 #if defined(HAVE_SSE) || defined(HAVE_3DNOW) | |
79 #define AF_INIT_TYPE (af_cpu_speed?*af_cpu_speed:AF_INIT_FAST) | |
80 #else | |
81 #define AF_INIT_TYPE (af_cpu_speed?*af_cpu_speed:AF_INIT_SLOW) | |
82 #endif | |
83 #endif | |
84 | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
85 // Configuration switches |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
86 typedef struct af_cfg_s{ |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
87 int force; // Initialization type |
8167 | 88 char** list; /* list of names of filters that are added to filter |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
89 list during first initialization of stream */ |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
90 }af_cfg_t; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
91 |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
92 // Current audio stream |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
93 typedef struct af_stream_s |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
94 { |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
95 // The first and last filter in the list |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
96 af_instance_t* first; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
97 af_instance_t* last; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
98 // Storage for input and output data formats |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
99 af_data_t input; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
100 af_data_t output; |
8167 | 101 // Configuration for this stream |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
102 af_cfg_t cfg; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
103 }af_stream_t; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
104 |
7568 | 105 /********************************************* |
106 // Return values | |
107 */ | |
108 | |
109 #define AF_DETACH 2 | |
110 #define AF_OK 1 | |
111 #define AF_TRUE 1 | |
112 #define AF_FALSE 0 | |
113 #define AF_UNKNOWN -1 | |
114 #define AF_ERROR -2 | |
8167 | 115 #define AF_FATAL -3 |
7568 | 116 |
117 | |
118 | |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
119 /********************************************* |
7568 | 120 // Export functions |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
121 */ |
7568 | 122 |
8167 | 123 /* Initialize the stream "s". This function creates a new filter list |
124 if necessary according to the values set in input and output. Input | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
125 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
|
126 formate of the preferred output respectively. The function is |
8969
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8957
diff
changeset
|
127 reentrant i.e. if called with an already initialized stream the |
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8957
diff
changeset
|
128 stream will be reinitialized. If the binary parameter |
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8957
diff
changeset
|
129 "force_output" is set, the output format will be converted to the |
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8957
diff
changeset
|
130 format given in "s", otherwise the output fromat in the last filter |
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8957
diff
changeset
|
131 will be copied "s". The return value is 0 if success and -1 if |
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8957
diff
changeset
|
132 failure */ |
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8957
diff
changeset
|
133 int af_init(af_stream_t* s, int force_output); |
7649
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
134 |
7568 | 135 // 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
|
136 void af_uninit(af_stream_t* s); |
7649
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
137 |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
138 /* Add filter during execution. This function adds the filter "name" |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
139 to the stream s. The filter will be inserted somewhere nice in the |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
140 list of filters. The return value is a pointer to the new filter, |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
141 If the filter couldn't be added the return value is NULL. */ |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
142 af_instance_t* af_add(af_stream_t* s, char* name); |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
143 |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
144 // Uninit and remove the filter "af" |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
145 void af_remove(af_stream_t* s, af_instance_t* af); |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
146 |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
147 /* Find filter in the dynamic filter list using it's name This |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
148 function is used for finding already initialized filters */ |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
149 af_instance_t* af_get(af_stream_t* s, char* name); |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
150 |
7568 | 151 // 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
|
152 af_data_t* af_play(af_stream_t* s, af_data_t* data); |
7649
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
153 |
12668
ce6ab8cb8597
Send a command throught the filter chain until some item returns AF_OK. Patch by Reimar Doeffinger
alex
parents:
8969
diff
changeset
|
154 // 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:
8969
diff
changeset
|
155 // one accepts the command with AF_OK. |
ce6ab8cb8597
Send a command throught the filter chain until some item returns AF_OK. Patch by Reimar Doeffinger
alex
parents:
8969
diff
changeset
|
156 // Returns true if accepting filter was found. |
ce6ab8cb8597
Send a command throught the filter chain until some item returns AF_OK. Patch by Reimar Doeffinger
alex
parents:
8969
diff
changeset
|
157 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:
8969
diff
changeset
|
158 |
7568 | 159 /* Calculate how long the output from the filters will be given the |
7589 | 160 input length "len". The calculated length is >= the actual |
161 length */ | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
162 int af_outputlen(af_stream_t* s, int len); |
7649
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
163 |
7568 | 164 /* Calculate how long the input to the filters should be to produce a |
165 certain output length, i.e. the return value of this function is | |
7589 | 166 the input length required to produce the output length "len". The |
167 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
|
168 int af_inputlen(af_stream_t* s, int len); |
7649
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
169 |
7598
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
170 /* Calculate how long the input IN to the filters should be to produce |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
171 a certain output length OUT but with the following three constraints: |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
172 1. IN <= max_insize, where max_insize is the maximum possible input |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
173 block length |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
174 2. OUT <= max_outsize, where max_outsize is the maximum possible |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
175 output block length |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
176 3. If possible OUT >= len. |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
177 Return -1 in case of error */ |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
178 int af_calc_insize_constrained(af_stream_t* s, int len, |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
179 int max_outsize,int max_insize); |
7568 | 180 |
7665
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
181 /* Calculate the total delay caused by the filters */ |
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
182 double af_calc_delay(af_stream_t* s); |
7568 | 183 |
184 // Helper functions and macros used inside the audio filters | |
185 | |
186 /* Helper function called by the macro with the same name only to be | |
187 called from inside filters */ | |
188 int af_resize_local_buffer(af_instance_t* af, af_data_t* data); | |
189 | |
190 /* Helper function used to calculate the exact buffer length needed | |
7589 | 191 when buffers are resized. The returned length is >= than what is |
192 needed */ | |
193 int af_lencalc(frac_t mul, af_data_t* data); | |
7568 | 194 |
8607 | 195 /* Helper function used to convert to gain value from dB. Returns |
196 AF_OK if of and AF_ERROR if fail */ | |
197 int af_from_dB(int n, float* in, float* out, float k, float mi, float ma); | |
198 /* Helper function used to convert from gain value to dB. Returns | |
199 AF_OK if of and AF_ERROR if fail */ | |
200 int af_to_dB(int n, float* in, float* out, float k); | |
201 /* Helper function used to convert from ms to sample time*/ | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8607
diff
changeset
|
202 int af_from_ms(int n, float* in, int* out, int rate, float mi, float ma); |
8607 | 203 /* Helper function used to convert from sample time to ms */ |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8607
diff
changeset
|
204 int af_to_ms(int n, int* in, float* out, int rate); |
8607 | 205 /* Helper function for testing the output format */ |
206 int af_test_output(struct af_instance_s* af, af_data_t* out); | |
207 | |
13269
aa13937da8a0
mplayer -af help now lists all available audio filters.
ivo
parents:
12676
diff
changeset
|
208 /** Print a list of all available audio filters */ |
aa13937da8a0
mplayer -af help now lists all available audio filters.
ivo
parents:
12676
diff
changeset
|
209 void af_help(void); |
aa13937da8a0
mplayer -af help now lists all available audio filters.
ivo
parents:
12676
diff
changeset
|
210 |
7568 | 211 /* Memory reallocation macro: if a local buffer is used (i.e. if the |
212 filter doesn't operate on the incoming buffer this macro must be | |
213 called to ensure the buffer is big enough. */ | |
214 #define RESIZE_LOCAL_BUFFER(a,d)\ | |
7591 | 215 ((a->data->len < af_lencalc(a->mul,d))?af_resize_local_buffer(a,d):AF_OK) |
7568 | 216 |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
217 /* Some other useful macro definitions*/ |
7568 | 218 #ifndef min |
219 #define min(a,b)(((a)>(b))?(b):(a)) | |
220 #endif | |
221 | |
222 #ifndef max | |
223 #define max(a,b)(((a)>(b))?(a):(b)) | |
224 #endif | |
225 | |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
226 #ifndef clamp |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
227 #define clamp(a,min,max) (((a)>(max))?(max):(((a)<(min))?(min):(a))) |
7568 | 228 #endif |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
229 |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
230 #ifndef sign |
8073 | 231 #define sign(a) (((a)>0)?(1):(-1)) |
232 #endif | |
233 | |
8167 | 234 #ifndef lrnd |
235 #define lrnd(a,b) ((b)((a)>=0.0?(a)+0.5:(a)-0.5)) | |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
236 #endif |
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
237 |
8167 | 238 /* Error messages */ |
239 | |
240 typedef struct af_msg_cfg_s | |
241 { | |
242 int level; /* Message level for debug and error messages max = 2 | |
243 min = -2 default = 0 */ | |
244 FILE* err; // Stream to print error messages to | |
245 FILE* msg; // Stream to print information messages to | |
246 }af_msg_cfg_t; | |
247 | |
248 extern af_msg_cfg_t af_msg_cfg; // Message | |
249 | |
250 #define AF_MSG_FATAL -3 // Fatal error exit immediately | |
251 #define AF_MSG_ERROR -2 // Error return gracefully | |
252 #define AF_MSG_WARN -1 // Print warning but do not exit (can be suppressed) | |
253 #define AF_MSG_INFO 0 // Important information | |
254 #define AF_MSG_VERBOSE 1 // Print this if verbose is enabled | |
255 #define AF_MSG_DEBUG0 2 // Print if very verbose | |
256 #define AF_MSG_DEBUG1 3 // Print if very very verbose | |
257 | |
258 /* Macro for printing error messages */ | |
259 #ifndef af_msg | |
260 #define af_msg(lev, args... ) \ | |
8957
36a5cdca733b
bunkus: Encapsulated arguments to #define in ( ... ) so that the #defines can be safely used like functions: mydef(flag ? val1 : val2)
mosu
parents:
8868
diff
changeset
|
261 (((lev)<AF_MSG_WARN)?(fprintf(af_msg_cfg.err?af_msg_cfg.err:stderr, ## args )): \ |
36a5cdca733b
bunkus: Encapsulated arguments to #define in ( ... ) so that the #defines can be safely used like functions: mydef(flag ? val1 : val2)
mosu
parents:
8868
diff
changeset
|
262 (((lev)<=af_msg_cfg.level)?(fprintf(af_msg_cfg.msg?af_msg_cfg.msg:stdout, ## args )):0)) |
7745
1d3a3dc1f488
Adding volume control and moving control() call parameters to a seperate file
anders
parents:
7665
diff
changeset
|
263 #endif |
8167 | 264 |
265 #endif /* __aop_h__ */ | |
266 | |
267 |