Mercurial > mplayer.hg
comparison libao2/ao_plugin.c @ 6027:7c26ef54ff14
fixed sdl+resample bug coused by float point to int rounding error
author | iive |
---|---|
date | Thu, 09 May 2002 07:41:25 +0000 |
parents | 4c6b5ab80de2 |
children | 2eec40929570 |
comparison
equal
deleted
inserted
replaced
6026:16e33d66b813 | 6027:7c26ef54ff14 |
---|---|
25 // local data | 25 // local data |
26 typedef struct ao_plugin_local_data_s | 26 typedef struct ao_plugin_local_data_s |
27 { | 27 { |
28 void* buf; // Output data buffer | 28 void* buf; // Output data buffer |
29 int len; // Amount of data in buffer | 29 int len; // Amount of data in buffer |
30 int channels; | |
31 int format; | |
32 int bpm; //bit of format | |
30 float bps; // Bytes per second out | 33 float bps; // Bytes per second out |
31 ao_functions_t* driver; // Output driver | 34 ao_functions_t* driver; // Output driver |
32 ao_plugin_functions_t** plugins; // List of used plugins | 35 ao_plugin_functions_t** plugins; // List of used plugins |
33 ao_plugin_functions_t* available_plugins[NPL]; // List of available plugins | 36 ao_plugin_functions_t* available_plugins[NPL]; // List of available plugins |
34 } ao_plugin_local_data_t; | 37 } ao_plugin_local_data_t; |
35 | 38 |
36 static ao_plugin_local_data_t ao_plugin_local_data={NULL,0,0.0,NULL,NULL,AO_PLUGINS}; | 39 static ao_plugin_local_data_t ao_plugin_local_data={NULL,0,0,0,0,0.0,NULL,NULL,AO_PLUGINS}; |
37 | 40 |
38 // global data | 41 // global data |
39 volatile ao_plugin_data_t ao_plugin_data; // Data used by the plugins | 42 volatile ao_plugin_data_t ao_plugin_data; // Data used by the plugins |
40 ao_plugin_cfg_t ao_plugin_cfg=CFG_DEFAULTS; // Set in cfg-mplayer.h | 43 ao_plugin_cfg_t ao_plugin_cfg=CFG_DEFAULTS; // Set in cfg-mplayer.h |
41 | 44 |
121 return 0; | 124 return 0; |
122 } | 125 } |
123 | 126 |
124 /* Set input parameters and itterate through plugins each plugin | 127 /* Set input parameters and itterate through plugins each plugin |
125 changes the parameters according to its output */ | 128 changes the parameters according to its output */ |
129 | |
130 ao_plugin_local_data.format=format; | |
131 ao_plugin_local_data.channels=channels; | |
132 ao_plugin_local_data.bpm=audio_out_format_bits(format); | |
133 | |
126 ao_plugin_data.rate=rate; | 134 ao_plugin_data.rate=rate; |
127 ao_plugin_data.channels=channels; | 135 ao_plugin_data.channels=channels; |
128 ao_plugin_data.format=format; | 136 ao_plugin_data.format=format; |
129 ao_plugin_data.sz_mult=1; | 137 ao_plugin_data.sz_mult=1; |
130 ao_plugin_data.sz_fix=0; | 138 ao_plugin_data.sz_fix=0; |
137 if(!ok) return 0; | 145 if(!ok) return 0; |
138 | 146 |
139 // Calculate bps | 147 // Calculate bps |
140 ao_plugin_local_data.bps=(float)(ao_plugin_data.rate * | 148 ao_plugin_local_data.bps=(float)(ao_plugin_data.rate * |
141 ao_plugin_data.channels); | 149 ao_plugin_data.channels); |
142 | 150 ao_plugin_local_data.bps*=audio_out_format_bits(ao_plugin_data.format)/8; |
143 if(ao_plugin_data.format == AFMT_S16_LE || | |
144 ao_plugin_data.format == AFMT_S16_BE || | |
145 ao_plugin_data.format == AFMT_U16_LE || | |
146 ao_plugin_data.format == AFMT_U16_BE) | |
147 ao_plugin_local_data.bps *= 2; | |
148 | |
149 if(ao_plugin_data.format == AFMT_S32_LE || | |
150 ao_plugin_data.format == AFMT_S32_BE) | |
151 ao_plugin_local_data.bps *= 4; | |
152 | 151 |
153 // This should never happen but check anyway | 152 // This should never happen but check anyway |
154 if(NULL==ao_plugin_local_data.driver) | 153 if(NULL==ao_plugin_local_data.driver) |
155 return 0; | 154 return 0; |
156 | 155 |
211 driver()->resume(); | 210 driver()->resume(); |
212 } | 211 } |
213 | 212 |
214 // return: how many bytes can be played without blocking | 213 // return: how many bytes can be played without blocking |
215 static int get_space(){ | 214 static int get_space(){ |
216 double sz=(double)(driver()->get_space()); | 215 double sz; |
216 int isz; | |
217 sz=(double)(driver()->get_space()); | |
217 if(sz+(double)ao_plugin_local_data.len > (double)MAX_OUTBURST) | 218 if(sz+(double)ao_plugin_local_data.len > (double)MAX_OUTBURST) |
218 sz=(double)MAX_OUTBURST-(double)ao_plugin_local_data.len; | 219 sz=(double)MAX_OUTBURST-(double)ao_plugin_local_data.len; |
219 sz*=ao_plugin_data.sz_mult; | 220 sz*=ao_plugin_data.sz_mult; |
220 sz+=ao_plugin_data.sz_fix; | 221 sz+=ao_plugin_data.sz_fix; |
221 return (int)(sz); | 222 isz=(int)(sz); |
223 isz-=isz%(ao_plugin_local_data.channels*ao_plugin_local_data.bpm/8); | |
224 return isz; | |
222 } | 225 } |
223 | 226 |
224 // plays 'len' bytes of 'data' | 227 // plays 'len' bytes of 'data' |
225 // return: number of bytes played | 228 // return: number of bytes played |
226 static int play(void* data,int len,int flags){ | 229 static int play(void* data,int len,int flags){ |
230 int ret_len =(tmp<len)?tmp:len; | 233 int ret_len =(tmp<len)?tmp:len; |
231 if(ret_len){ | 234 if(ret_len){ |
232 // Filter data | 235 // Filter data |
233 ao_plugin_data.len=ret_len; | 236 ao_plugin_data.len=ret_len; |
234 ao_plugin_data.data=data; | 237 ao_plugin_data.data=data; |
238 | |
239 // update plugins and uncoment that | |
240 // ao_plugin_data.channels=ao_plugin_local_data.channels; | |
241 // ao_plugin_data.format=ao_plugin_local_data.format; | |
242 | |
235 while(plugin(i)) | 243 while(plugin(i)) |
236 plugin(i++)->play(); | 244 plugin(i++)->play(); |
237 // Copy data to output buffer | 245 // Copy data to output buffer |
238 memcpy(ao_plugin_local_data.buf+ao_plugin_local_data.len, | 246 memcpy(ao_plugin_local_data.buf+ao_plugin_local_data.len, |
239 ao_plugin_data.data,ao_plugin_data.len); | 247 ao_plugin_data.data,ao_plugin_data.len); |