Mercurial > mplayer.hg
comparison libao2/pl_format.c @ 3309:28f2ebcb5c95
Format plugin now with working switch statements
author | anders |
---|---|
date | Tue, 04 Dec 2001 12:28:26 +0000 |
parents | d6ea11bed983 |
children | 2eec40929570 |
comparison
equal
deleted
inserted
replaced
3308:ea7c1bfc4391 | 3309:28f2ebcb5c95 |
---|---|
58 // to set/get/query special features/parameters | 58 // to set/get/query special features/parameters |
59 static int control(int cmd,int arg){ | 59 static int control(int cmd,int arg){ |
60 switch(cmd){ | 60 switch(cmd){ |
61 case AOCONTROL_PLUGIN_SET_LEN: | 61 case AOCONTROL_PLUGIN_SET_LEN: |
62 if(pl_format.data) | 62 if(pl_format.data) |
63 uninit(); | 63 free(pl_format.data); |
64 pl_format.len = ao_plugin_data.len; | 64 pl_format.len = ao_plugin_data.len; |
65 if(ao_plugin_data.data) | |
66 free(ao_plugin_data.data); | |
67 pl_format.data=(void*)malloc(ao_plugin_data.len); | 65 pl_format.data=(void*)malloc(ao_plugin_data.len); |
68 ao_plugin_data.len=(int)(((double)ao_plugin_data.len)*pl_format.sz_mult); | 66 if(!pl_format.data) |
67 return CONTROL_ERROR; | |
68 ao_plugin_data.len=(int)(((double)ao_plugin_data.len)/pl_format.sz_mult); | |
69 return CONTROL_OK; | 69 return CONTROL_OK; |
70 } | 70 } |
71 return -1; | 71 return -1; |
72 } | 72 } |
73 | 73 |
95 case(AFMT_IMA_ADPCM): | 95 case(AFMT_IMA_ADPCM): |
96 case(AFMT_MU_LAW): | 96 case(AFMT_MU_LAW): |
97 case(AFMT_A_LAW): | 97 case(AFMT_A_LAW): |
98 case(AFMT_MPEG): | 98 case(AFMT_MPEG): |
99 case(AFMT_AC3): | 99 case(AFMT_AC3): |
100 printf("[pl_format] Audio format not yet suported \n"); | 100 printf("[pl_format] Input audio format not yet suported \n"); |
101 return 0; | 101 return 0; |
102 default: | 102 default: |
103 printf("[pl_format] Unrecognised input audio format\n"); //This can not happen .... | 103 printf("[pl_format] Unrecognised input audio format\n"); //This can not happen .... |
104 return 0; | 104 return 0; |
105 } | 105 } |
124 case(AFMT_IMA_ADPCM): | 124 case(AFMT_IMA_ADPCM): |
125 case(AFMT_MU_LAW): | 125 case(AFMT_MU_LAW): |
126 case(AFMT_A_LAW): | 126 case(AFMT_A_LAW): |
127 case(AFMT_MPEG): | 127 case(AFMT_MPEG): |
128 case(AFMT_AC3): | 128 case(AFMT_AC3): |
129 printf("[pl_format] Audio format not yet suported \n"); | 129 printf("[pl_format] Output audio format not yet suported \n"); |
130 return 0; | 130 return 0; |
131 default: | 131 default: |
132 printf("[pl_format] Unrecognised audio output format\n"); | 132 printf("[pl_format] Unrecognised audio output format\n"); |
133 return 0; | 133 return 0; |
134 } | 134 } |
139 audio_out_format_name(ao_plugin_cfg.pl_format_type)); | 139 audio_out_format_name(ao_plugin_cfg.pl_format_type)); |
140 | 140 |
141 // We are changing the format | 141 // We are changing the format |
142 ao_plugin_data.format=ao_plugin_cfg.pl_format_type; | 142 ao_plugin_data.format=ao_plugin_cfg.pl_format_type; |
143 | 143 |
144 // Perhaps the buffer size | 144 // And perhaps the buffer size |
145 pl_format.sz_mult=1; | 145 pl_format.sz_mult=1; |
146 if((pl_format.in&NBITS_MASK) > (pl_format.out&NBITS_MASK)) | 146 if((pl_format.in&NBITS_MASK) > (pl_format.out&NBITS_MASK)) |
147 pl_format.sz_mult/=(double)(1<<((pl_format.in&NBITS_MASK)-(pl_format.out&NBITS_MASK))); | 147 pl_format.sz_mult/=(double)(1<<((pl_format.in&NBITS_MASK)-(pl_format.out&NBITS_MASK))); |
148 if((pl_format.in&NBITS_MASK) < (pl_format.out&NBITS_MASK)) | 148 if((pl_format.in&NBITS_MASK) < (pl_format.out&NBITS_MASK)) |
149 pl_format.sz_mult*=(double)(1<<((pl_format.out&NBITS_MASK)-(pl_format.in&NBITS_MASK))); | 149 pl_format.sz_mult*=(double)(1<<((pl_format.out&NBITS_MASK)-(pl_format.in&NBITS_MASK))); |
159 pl_format.data=NULL; | 159 pl_format.data=NULL; |
160 } | 160 } |
161 | 161 |
162 // empty buffers | 162 // empty buffers |
163 static void reset(){ | 163 static void reset(){ |
164 int i = 0; | 164 memset(pl_format.data, 0, pl_format.len); |
165 for(i=0;i<pl_format.len;i++) | |
166 ((char*)pl_format.data)[i]=0; | |
167 } | 165 } |
168 | 166 |
169 // processes 'ao_plugin_data.len' bytes of 'data' | 167 // processes 'ao_plugin_data.len' bytes of 'data' |
170 // called for every block of data | 168 // called for every block of data |
171 // FIXME: this routine needs to be optimized (it is probably possible to do a lot here) | 169 // FIXME: this routine needs to be optimized (it is probably possible to do a lot here) |
173 register int i=0; | 171 register int i=0; |
174 void* in_data=ao_plugin_data.data; | 172 void* in_data=ao_plugin_data.data; |
175 void* out_data=pl_format.data; | 173 void* out_data=pl_format.data; |
176 int len=(ao_plugin_data.len)>>(pl_format.in&NBITS_MASK); | 174 int len=(ao_plugin_data.len)>>(pl_format.in&NBITS_MASK); |
177 ao_plugin_data.len=(int)(((double)ao_plugin_data.len)*=pl_format.sz_mult); | 175 ao_plugin_data.len=(int)(((double)ao_plugin_data.len)*=pl_format.sz_mult); |
178 ao_plugin_data.len; | 176 |
179 | |
180 // Change to little endian (Is this true for sun ?) | 177 // Change to little endian (Is this true for sun ?) |
181 if((pl_format.in&END_MASK)!=LE){ | 178 if((pl_format.in&END_MASK)!=LE){ |
182 switch(pl_format.in&NBITS_MASK){ | 179 switch(pl_format.in&NBITS_MASK){ |
183 case(B16):{ | 180 case(B16):{ |
184 register uint16_t s; | 181 register uint16_t s; |
185 for(i=1;i<len;i++){ | 182 for(i=1;i<len;i++){ |
186 s=((uint16_t*)in_data)[i]; | 183 s=((uint16_t*)in_data)[i]; |
187 ((uint16_t*)in_data)[i]=(uint16_t)(((s&0x00FF)<<8) | (s&0xFF00)>>8); | 184 ((uint16_t*)in_data)[i]=(uint16_t)(((s&0x00FF)<<8) | (s&0xFF00)>>8); |
188 } | 185 } |
189 break; | 186 } |
190 } | 187 break; |
191 case(B32):{ | 188 case(B32):{ |
192 register uint32_t s; | 189 register uint32_t s; |
193 for(i=1;i<len;i++){ | 190 for(i=1;i<len;i++){ |
194 s=((uint32_t*)in_data)[i]; | 191 s=((uint32_t*)in_data)[i]; |
195 ((uint32_t*)in_data)[i]=(uint32_t)(((s&0x000000FF)<<24) | ((s&0x0000FF00)<<8) | | 192 ((uint32_t*)in_data)[i]=(uint32_t)(((s&0x000000FF)<<24) | ((s&0x0000FF00)<<8) | |
196 ((s&0x00FF0000)>>8) | ((s&0xFF000000)>>24)); | 193 ((s&0x00FF0000)>>8) | ((s&0xFF000000)>>24)); |
197 } | 194 } |
198 break; | 195 } |
199 } | 196 break; |
200 } | 197 } |
201 } | 198 } |
202 | |
203 // Change signed/unsigned | 199 // Change signed/unsigned |
204 if((pl_format.in&SIGN_MASK) != (pl_format.out&SIGN_MASK)){ | 200 if((pl_format.in&SIGN_MASK) != (pl_format.out&SIGN_MASK)){ |
205 switch(pl_format.in&NBITS_MASK){ | 201 switch((pl_format.in&NBITS_MASK)){ |
206 case(B08):{ | 202 case(B08): |
207 switch(pl_format.in&SIGN_MASK){ | 203 switch(pl_format.in&SIGN_MASK){ |
208 case(US):{ | 204 case(US): |
209 for(i=0;i<len;i++) | 205 for(i=0;i<len;i++) |
210 ((int8_t*)in_data)[i]=(int8_t)(-127+((int)((uint8_t*)in_data)[i])); | 206 ((int8_t*)in_data)[i]=(int8_t)(-127+((int)((uint8_t*)in_data)[i])); |
211 break; | 207 break; |
212 } | 208 case(SI): |
213 case(SI):{ | 209 for(i=0;i<len;i++) |
214 for(i=0;i<len;i++) | 210 ((uint8_t*)in_data)[i]=(uint8_t)(+128+((int)((int8_t*)in_data)[i])); |
215 ((uint8_t*)in_data)[i]=(uint8_t)(+127+((int)((int8_t*)in_data)[i])); | 211 break; |
216 break; | 212 } |
217 } | 213 break; |
218 break; | 214 case(B16): |
219 } | |
220 } | |
221 case(B16):{ | |
222 switch(pl_format.in&SIGN_MASK){ | 215 switch(pl_format.in&SIGN_MASK){ |
223 case(US):{ | 216 case(US): |
224 for(i=0;i<len;i++) | 217 for(i=0;i<len;i++) |
225 ((int16_t*)in_data)[i]=(int16_t)(-32767+((int)((uint16_t*)in_data)[i])); | 218 ((int16_t*)in_data)[i]=(int16_t)(-32767+((int)((uint16_t*)in_data)[i])); |
226 break; | 219 break; |
227 } | 220 case(SI): |
228 case(SI):{ | 221 for(i=0;i<len;i++) |
229 for(i=0;i<len;i++) | 222 ((uint16_t*)in_data)[i]=(uint16_t)(+32768+((int)((int16_t*)in_data)[i])); |
230 ((uint16_t*)in_data)[i]=(uint16_t)(+32767+((int)((int16_t*)in_data)[i])); | 223 break; |
231 break; | 224 } |
232 } | 225 break; |
233 break; | 226 case(B32): |
234 } | |
235 } | |
236 case(B32):{ | |
237 switch(pl_format.in&SIGN_MASK){ | 227 switch(pl_format.in&SIGN_MASK){ |
238 case(US):{ | 228 case(US): |
239 for(i=0;i<len;i++) | 229 for(i=0;i<len;i++) |
240 ((int32_t*)in_data)[i]=(int32_t)(-(1<<31-1)+((uint32_t*)in_data)[i]); | 230 ((int32_t*)in_data)[i]=(int32_t)(-(1<<31-1)+((uint32_t*)in_data)[i]); |
241 break; | 231 break; |
242 } | 232 case(SI): |
243 case(SI):{ | 233 for(i=0;i<len;i++) |
244 for(i=0;i<len;i++) | 234 ((uint32_t*)in_data)[i]=(uint32_t)(+(1<<31)+((int32_t*)in_data)[i]); |
245 ((uint32_t*)in_data)[i]=(uint32_t)(+(1<<31-1)+((int32_t*)in_data)[i]); | 235 break; |
246 break; | 236 } |
247 } | 237 break; |
248 break; | 238 } |
249 } | |
250 } | |
251 } | |
252 } | 239 } |
253 // Change the number of bits | 240 // Change the number of bits |
254 if((pl_format.in&NBITS_MASK) == (pl_format.out&NBITS_MASK)){ | 241 if((pl_format.in&NBITS_MASK) == (pl_format.out&NBITS_MASK)){ |
255 int sz=(int)((double)ao_plugin_data.len/pl_format.sz_mult); | 242 int sz=(int)((double)ao_plugin_data.len/pl_format.sz_mult); |
256 for(i=0;i<sz;i++) | 243 for(i=0;i<sz;i++) |
257 ((char*)out_data)[i]=((char*)in_data)[i]; | 244 ((char*)out_data)[i]=((char*)in_data)[i]; |
258 } else { | 245 } else { |
259 switch(pl_format.in&NBITS_MASK){ | 246 switch(pl_format.in&NBITS_MASK){ |
260 case(B08):{ | 247 case(B08): |
261 switch(pl_format.out&NBITS_MASK){ | 248 switch(pl_format.out&NBITS_MASK){ |
262 case(B16):{ | 249 case(B16): |
263 for(i=1;i<len;i++) | 250 for(i=1;i<len;i++) |
264 ((uint16_t*)out_data)[i]=((uint16_t)((uint8_t*)in_data)[i])<<8; | 251 ((uint16_t*)out_data)[i]=((uint16_t)((uint8_t*)in_data)[i])<<8; |
265 break; | 252 break; |
266 } | 253 case(B32): |
267 case(B32):{ | |
268 for(i=1;i<len;i++) | 254 for(i=1;i<len;i++) |
269 ((uint32_t*)out_data)[i]=((uint32_t)((uint8_t*)in_data)[i])<<24; | 255 ((uint32_t*)out_data)[i]=((uint32_t)((uint8_t*)in_data)[i])<<24; |
270 break; | 256 break; |
271 } | 257 } |
272 } | 258 break; |
273 } | 259 case(B16): |
274 case(B16):{ | |
275 switch(pl_format.out&NBITS_MASK){ | 260 switch(pl_format.out&NBITS_MASK){ |
276 case(B08):{ | 261 case(B08): |
277 for(i=0;i<len;i++) | 262 for(i=0;i<len;i++) |
278 ((uint8_t*)out_data)[i]=(uint8_t)((((uint16_t*)in_data)[i])>>8); | 263 ((uint8_t*)out_data)[i]=(uint8_t)((((uint16_t*)in_data)[i])>>8); |
279 break; | 264 break; |
280 } | 265 case(B32): |
281 case(B32):{ | |
282 for(i=1;i<len;i++) | 266 for(i=1;i<len;i++) |
283 ((uint32_t*)out_data)[i]=((uint32_t)((uint16_t*)in_data)[i])<<16; | 267 ((uint32_t*)out_data)[i]=((uint32_t)((uint16_t*)in_data)[i])<<16; |
284 break; | 268 break; |
285 } | 269 } |
286 } | 270 break; |
287 } | 271 case(B32): |
288 case(B32):{ | |
289 switch(pl_format.out&NBITS_MASK){ | 272 switch(pl_format.out&NBITS_MASK){ |
290 case(B08):{ | 273 case(B08): |
291 for(i=0;i<len;i++) | 274 for(i=0;i<len;i++) |
292 ((uint8_t*)out_data)[i]=(uint8_t)((((uint32_t*)in_data)[i])>>24); | 275 ((uint8_t*)out_data)[i]=(uint8_t)((((uint32_t*)in_data)[i])>>24); |
293 break; | 276 break; |
294 } | 277 case(B16): |
295 case(B16):{ | |
296 for(i=1;i<len;i++) | 278 for(i=1;i<len;i++) |
297 ((uint16_t*)out_data)[i]=(uint16_t)((((uint32_t*)in_data)[i])>>16); | 279 ((uint16_t*)out_data)[i]=(uint16_t)((((uint32_t*)in_data)[i])>>16); |
298 break; | 280 break; |
299 } | 281 } |
300 } | 282 break; |
301 } | 283 } |
302 } | 284 } |
303 } | |
304 | |
305 // Switch to the correct endainess (agiain the problem with sun?) | 285 // Switch to the correct endainess (agiain the problem with sun?) |
306 if((pl_format.out&END_MASK)!=LE){ | 286 if((pl_format.out&END_MASK)!=LE){ |
307 switch(pl_format.in&NBITS_MASK){ | 287 switch(pl_format.in&NBITS_MASK){ |
308 case(B16):{ | 288 case(B16):{ |
309 register uint16_t s; | 289 register uint16_t s; |
310 for(i=1;i<len;i++){ | 290 for(i=1;i<len;i++){ |
311 s=((uint16_t*)out_data)[i]; | 291 s=((uint16_t*)out_data)[i]; |
312 ((uint16_t*)out_data)[i]=(uint16_t)(((s&0x00FF)<<8) | (s&0xFF00)>>8); | 292 ((uint16_t*)out_data)[i]=(uint16_t)(((s&0x00FF)<<8) | (s&0xFF00)>>8); |
313 } | 293 } |
314 break; | 294 } |
315 } | 295 break; |
316 case(B32):{ | 296 case(B32):{ |
317 register uint32_t s; | 297 register uint32_t s; |
318 for(i=1;i<len;i++){ | 298 for(i=1;i<len;i++){ |
319 s=((uint32_t*)out_data)[i]; | 299 s=((uint32_t*)out_data)[i]; |
320 ((uint32_t*)out_data)[i]=(uint32_t)(((s&0x000000FF)<<24) | ((s&0x0000FF00)<<8) | | 300 ((uint32_t*)out_data)[i]=(uint32_t)(((s&0x000000FF)<<24) | ((s&0x0000FF00)<<8) | |
321 ((s&0x00FF0000)>>8) | ((s&0xFF000000)>>24)); | 301 ((s&0x00FF0000)>>8) | ((s&0xFF000000)>>24)); |
322 } | 302 } |
323 break; | 303 } |
324 } | 304 break; |
325 } | 305 } |
326 } | 306 } |
327 | |
328 ao_plugin_data.data=out_data; | 307 ao_plugin_data.data=out_data; |
329 return 1; | 308 return 1; |
330 } | 309 } |
331 | 310 |
332 | 311 |