Mercurial > mplayer.hg
annotate libaf/af_format.c @ 8660:39476cbd1673
I have looked at the fullscreen code and realized that there are
generally two types of layer support for window managers:
- NetWM states (FULLSCREEN, STAYS_ON_TOP, ABOVE)
sawfish, metacity, kwin
- _WIN_LAYER
IceWM, WindowMaker
So we don't need any other window manager detection functions, we need
only to check for these two.
Code tested on lots of windowmanagers.
patch by Filip Kalinski <filon@pld.org.pl>
author | arpi |
---|---|
date | Mon, 30 Dec 2002 18:50:15 +0000 |
parents | d6f40a06867b |
children | 06d7ef3c7b01 |
rev | line source |
---|---|
7568 | 1 /* This audio output filter changes the format of a data block. Valid |
2 formats are: AFMT_U8, AFMT_S8, AFMT_S16_LE, AFMT_S16_BE | |
3 AFMT_U16_LE, AFMT_U16_BE, AFMT_S32_LE and AFMT_S32_BE. | |
4 */ | |
5 | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <unistd.h> | |
10 #include <inttypes.h> | |
11 #include <limits.h> | |
12 | |
13 #include "af.h" | |
14 | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
15 // Integer to float conversion through lrintf() |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
16 #ifdef HAVE_LRINTF |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
17 #define __USE_ISOC99 1 |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
18 #include <math.h> |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
19 #else |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
20 #define lrintf(x) ((int)(x)) |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
21 #endif |
8167 | 22 |
23 /* Functions used by play to convert the input audio to the correct | |
24 format */ | |
7568 | 25 |
8167 | 26 /* The below includes retrives functions for converting to and from |
27 ulaw and alaw */ | |
28 #include "af_format_ulaw.c" | |
29 #include "af_format_alaw.c" | |
7568 | 30 |
8167 | 31 // Switch endianess |
32 static void endian(void* in, void* out, int len, int bps); | |
33 // From singed to unsigned | |
34 static void si2us(void* in, void* out, int len, int bps); | |
35 // From unsinged to signed | |
36 static void us2si(void* in, void* out, int len, int bps); | |
37 // Change the number of bits per sample | |
38 static void change_bps(void* in, void* out, int len, int inbps, int outbps); | |
39 // From float to int signed | |
40 static void float2int(void* in, void* out, int len, int bps); | |
41 // From signed int to float | |
42 static void int2float(void* in, void* out, int len, int bps); | |
7719
41e8d0916c60
Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents:
7711
diff
changeset
|
43 |
8167 | 44 // Convert from string to format |
45 static int str2fmt(char* str) | |
7568 | 46 { |
8167 | 47 int format=0; |
48 // Scan for endianess | |
49 if(strstr(str,"be") || strstr(str,"BE")) | |
50 format |= AF_FORMAT_BE; | |
51 else if(strstr(str,"le") || strstr(str,"LE")) | |
52 format |= AF_FORMAT_LE; | |
53 else | |
54 format |= AF_FORMAT_NE; | |
55 | |
56 // Scan for special formats | |
57 if(strstr(str,"mulaw") || strstr(str,"MULAW")){ | |
58 format |= AF_FORMAT_MU_LAW; return format; | |
59 } | |
60 if(strstr(str,"alaw") || strstr(str,"ALAW")){ | |
61 format |= AF_FORMAT_A_LAW; return format; | |
62 } | |
63 if(strstr(str,"ac3") || strstr(str,"AC3")){ | |
64 format |= AF_FORMAT_AC3; return format; | |
65 } | |
66 if(strstr(str,"mpeg2") || strstr(str,"MPEG2")){ | |
67 format |= AF_FORMAT_MPEG2; return format; | |
68 } | |
69 if(strstr(str,"imaadpcm") || strstr(str,"IMAADPCM")){ | |
70 format |= AF_FORMAT_IMA_ADPCM; return format; | |
71 } | |
72 | |
73 // Scan for int/float | |
74 if(strstr(str,"float") || strstr(str,"FLOAT")){ | |
75 format |= AF_FORMAT_F; return format; | |
7568 | 76 } |
8167 | 77 else |
78 format |= AF_FORMAT_I; | |
7568 | 79 |
8167 | 80 // Scan for signed/unsigned |
81 if(strstr(str,"unsigned") || strstr(str,"UNSIGNED")) | |
82 format |= AF_FORMAT_US; | |
83 else | |
84 format |= AF_FORMAT_SI; | |
85 | |
86 return format; | |
87 } | |
88 | |
89 /* Convert format to str input str is a buffer for the | |
90 converted string, size is the size of the buffer */ | |
91 static char* fmt2str(int format, char* str, size_t size) | |
92 { | |
93 int i=0; | |
94 // Print endinaness | |
95 if(AF_FORMAT_LE == (format & AF_FORMAT_END_MASK)) | |
96 i+=snprintf(str,size,"little endian "); | |
97 else | |
98 i+=snprintf(str,size,"big endian "); | |
99 | |
100 if(format & AF_FORMAT_SPECIAL_MASK){ | |
101 switch(format & AF_FORMAT_SPECIAL_MASK){ | |
102 case(AF_FORMAT_MU_LAW): | |
103 i+=snprintf(&str[i],size-i,"mu law "); break; | |
104 case(AF_FORMAT_A_LAW): | |
105 i+=snprintf(&str[i],size-i,"A law "); break; | |
106 case(AF_FORMAT_MPEG2): | |
107 i+=snprintf(&str[i],size-i,"MPEG 2 "); break; | |
108 case(AF_FORMAT_AC3): | |
109 i+=snprintf(&str[i],size-i,"AC3 "); break; | |
110 } | |
111 } | |
112 else{ | |
113 // Point | |
114 if(AF_FORMAT_F == (format & AF_FORMAT_POINT_MASK)) | |
115 i+=snprintf(&str[i],size,"float "); | |
116 else{ | |
117 // Sign | |
118 if(AF_FORMAT_US == (format & AF_FORMAT_SIGN_MASK)) | |
119 i+=snprintf(&str[i],size-i,"unsigned "); | |
120 else | |
121 i+=snprintf(&str[i],size-i,"signed "); | |
122 | |
123 i+=snprintf(&str[i],size,"int "); | |
124 } | |
125 } | |
126 return str; | |
7568 | 127 } |
128 | |
8607 | 129 // Helper functions to check sanity for input arguments |
130 | |
131 // Sanity check for bytes per sample | |
132 int check_bps(int bps) | |
133 { | |
134 if(bps != 4 && bps != 2 && bps != 1){ | |
135 af_msg(AF_MSG_ERROR,"[format] The number of bytes per sample" | |
136 " must be 1, 2 or 4. Current value is %i \n",bps); | |
137 return AF_ERROR; | |
138 } | |
139 return AF_OK; | |
140 } | |
141 | |
142 // Check for unsupported formats | |
143 int check_format(int format) | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
144 { |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
145 char buf[256]; |
8607 | 146 switch(format & AF_FORMAT_SPECIAL_MASK){ |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
147 case(AF_FORMAT_MPEG2): |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
148 case(AF_FORMAT_AC3): |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
149 af_msg(AF_MSG_ERROR,"[format] Sample format %s not yet supported \n", |
8607 | 150 fmt2str(format,buf,255)); |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
151 return AF_ERROR; |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
152 } |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
153 return AF_OK; |
8607 | 154 } |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
155 |
7568 | 156 // Initialization and runtime control |
157 static int control(struct af_instance_s* af, int cmd, void* arg) | |
158 { | |
159 switch(cmd){ | |
8167 | 160 case AF_CONTROL_REINIT:{ |
161 char buf1[256]; | |
162 char buf2[256]; | |
7568 | 163 // Make sure this filter isn't redundant |
8167 | 164 if(af->data->format == ((af_data_t*)arg)->format && |
165 af->data->bps == ((af_data_t*)arg)->bps) | |
7568 | 166 return AF_DETACH; |
8607 | 167 |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
168 // Check for errors in configuraton |
8607 | 169 if((AF_OK != check_bps(((af_data_t*)arg)->bps)) || |
170 (AF_OK != check_format(((af_data_t*)arg)->format)) || | |
171 (AF_OK != check_bps(af->data->bps)) || | |
172 (AF_OK != check_format(af->data->format))) | |
8167 | 173 return AF_ERROR; |
174 | |
175 af_msg(AF_MSG_VERBOSE,"[format] Changing sample format from %ibit %sto %ibit %s \n", | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
176 ((af_data_t*)arg)->bps*8,fmt2str(((af_data_t*)arg)->format,buf1,255), |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
177 af->data->bps*8,fmt2str(af->data->format,buf2,255)); |
7568 | 178 |
179 af->data->rate = ((af_data_t*)arg)->rate; | |
180 af->data->nch = ((af_data_t*)arg)->nch; | |
181 af->mul.n = af->data->bps; | |
182 af->mul.d = ((af_data_t*)arg)->bps; | |
183 return AF_OK; | |
8167 | 184 } |
7998
d48a06d07afb
Adding commandline options for filters and fixing stupid bug in cfg
anders
parents:
7719
diff
changeset
|
185 case AF_CONTROL_COMMAND_LINE:{ |
8607 | 186 int bps = 2; |
187 int format = AF_FORMAT_NE; | |
8167 | 188 char str[256]; |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
189 str[0] = '\0'; |
8607 | 190 sscanf((char*)arg,"%i:%s",&bps,str); |
8167 | 191 // Convert string to format |
8607 | 192 format = str2fmt(str); |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
193 |
8167 | 194 // Automatic correction of errors |
8607 | 195 switch(format & AF_FORMAT_SPECIAL_MASK){ |
8167 | 196 case(AF_FORMAT_A_LAW): |
197 case(AF_FORMAT_MU_LAW): | |
8607 | 198 bps=1; break; |
8167 | 199 case(AF_FORMAT_AC3): |
8607 | 200 bps=4; break; // I think |
8167 | 201 } |
8607 | 202 if(AF_FORMAT_F == (format & AF_FORMAT_POINT_MASK)) |
203 bps=4; | |
204 | |
205 if((AF_OK != af->control(af,AF_CONTROL_FORMAT_BPS | AF_CONTROL_SET,&bps)) || | |
206 (AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET,&format))) | |
207 return AF_ERROR; | |
208 return AF_OK; | |
8167 | 209 } |
8607 | 210 case AF_CONTROL_FORMAT_BPS | AF_CONTROL_SET: |
7568 | 211 // Reinit must be called after this function has been called |
212 | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
213 // Check for errors in configuraton |
8607 | 214 if(AF_OK != check_bps(*(int*)arg)) |
7568 | 215 return AF_ERROR; |
8167 | 216 |
8607 | 217 af->data->bps = *(int*)arg; |
218 return AF_OK; | |
219 case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET: | |
220 // Reinit must be called after this function has been called | |
221 | |
222 // Check for errors in configuraton | |
223 if(AF_OK != check_format(*(int*)arg)) | |
224 return AF_ERROR; | |
225 | |
226 af->data->format = *(int*)arg; | |
7568 | 227 return AF_OK; |
228 } | |
229 return AF_UNKNOWN; | |
230 } | |
231 | |
232 // Deallocate memory | |
233 static void uninit(struct af_instance_s* af) | |
234 { | |
235 if(af->data) | |
236 free(af->data); | |
237 (int)af->setup = 0; | |
238 } | |
239 | |
240 // Filter data through filter | |
241 static af_data_t* play(struct af_instance_s* af, af_data_t* data) | |
242 { | |
8167 | 243 af_data_t* l = af->data; // Local data |
244 af_data_t* c = data; // Current working data | |
245 int len = c->len/c->bps; // Lenght in samples of current audio block | |
7568 | 246 |
247 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) | |
248 return NULL; | |
249 | |
8167 | 250 // Change to cpu native endian format |
251 if((c->format&AF_FORMAT_END_MASK)!=AF_FORMAT_NE) | |
252 endian(c->audio,c->audio,len,c->bps); | |
7719
41e8d0916c60
Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents:
7711
diff
changeset
|
253 |
8167 | 254 // Conversion table |
255 switch(c->format & ~AF_FORMAT_END_MASK){ | |
256 case(AF_FORMAT_MU_LAW): | |
257 from_ulaw(c->audio, l->audio, len, l->bps, l->format&AF_FORMAT_POINT_MASK); | |
258 if(AF_FORMAT_A_LAW == (l->format&AF_FORMAT_SPECIAL_MASK)) | |
259 to_ulaw(l->audio, l->audio, len, 1, AF_FORMAT_SI); | |
260 if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US) | |
261 si2us(l->audio,l->audio,len,l->bps); | |
262 break; | |
263 case(AF_FORMAT_A_LAW): | |
264 from_alaw(c->audio, l->audio, len, l->bps, l->format&AF_FORMAT_POINT_MASK); | |
265 if(AF_FORMAT_A_LAW == (l->format&AF_FORMAT_SPECIAL_MASK)) | |
266 to_alaw(l->audio, l->audio, len, 1, AF_FORMAT_SI); | |
267 if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US) | |
268 si2us(l->audio,l->audio,len,l->bps); | |
269 break; | |
270 case(AF_FORMAT_F): | |
271 switch(l->format&AF_FORMAT_SPECIAL_MASK){ | |
272 case(AF_FORMAT_MU_LAW): | |
273 to_ulaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK); | |
274 break; | |
275 case(AF_FORMAT_A_LAW): | |
276 to_alaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK); | |
7568 | 277 break; |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
278 default: |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
279 float2int(c->audio, l->audio, len, l->bps); |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
280 if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US) |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
281 si2us(l->audio,l->audio,len,l->bps); |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
282 break; |
8167 | 283 } |
284 break; | |
285 default: | |
286 // Input must be int | |
287 | |
288 // Change signed/unsigned | |
289 if((c->format&AF_FORMAT_SIGN_MASK) != (l->format&AF_FORMAT_SIGN_MASK)){ | |
290 if((c->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US) | |
291 us2si(c->audio,c->audio,len,c->bps); | |
292 else | |
293 si2us(c->audio,c->audio,len,c->bps); | |
294 } | |
295 // Convert to special formats | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
296 switch(l->format&(AF_FORMAT_SPECIAL_MASK|AF_FORMAT_POINT_MASK)){ |
8167 | 297 case(AF_FORMAT_MU_LAW): |
298 to_ulaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK); | |
299 break; | |
300 case(AF_FORMAT_A_LAW): | |
301 to_alaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK); | |
302 break; | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
303 case(AF_FORMAT_F): |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
304 int2float(c->audio, l->audio, len, c->bps); |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
305 break; |
8167 | 306 default: |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
307 // Change the number of bits |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
308 if(c->bps != l->bps) |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
309 change_bps(c->audio,l->audio,len,c->bps,l->bps); |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
310 else |
8185 | 311 memcpy(l->audio,c->audio,len*c->bps); |
7568 | 312 break; |
313 } | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
314 break; |
7568 | 315 } |
7719
41e8d0916c60
Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents:
7711
diff
changeset
|
316 |
41e8d0916c60
Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents:
7711
diff
changeset
|
317 // Switch from cpu native endian to the correct endianess |
8167 | 318 if((l->format&AF_FORMAT_END_MASK)!=AF_FORMAT_NE) |
319 endian(l->audio,l->audio,len,l->bps); | |
7568 | 320 |
321 // Set output data | |
322 c->audio = l->audio; | |
8167 | 323 c->len = len*l->bps; |
7568 | 324 c->bps = l->bps; |
325 c->format = l->format; | |
326 return c; | |
327 } | |
328 | |
329 // Allocate memory and set function pointers | |
330 static int open(af_instance_t* af){ | |
331 af->control=control; | |
332 af->uninit=uninit; | |
333 af->play=play; | |
334 af->mul.n=1; | |
335 af->mul.d=1; | |
336 af->data=calloc(1,sizeof(af_data_t)); | |
337 if(af->data == NULL) | |
338 return AF_ERROR; | |
339 return AF_OK; | |
340 } | |
341 | |
342 // Description of this filter | |
343 af_info_t af_info_format = { | |
344 "Sample format conversion", | |
345 "format", | |
346 "Anders", | |
347 "", | |
7615 | 348 AF_FLAGS_REENTRANT, |
7568 | 349 open |
350 }; | |
8167 | 351 |
352 // Function implementations used by play | |
353 static void endian(void* in, void* out, int len, int bps) | |
354 { | |
355 register int i; | |
356 switch(bps){ | |
357 case(2):{ | |
358 register uint16_t s; | |
359 for(i=0;i<len;i++){ | |
360 s=((uint16_t*)in)[i]; | |
361 ((uint16_t*)out)[i]=(uint16_t)(((s&0x00FF)<<8) | (s&0xFF00)>>8); | |
362 } | |
363 break; | |
364 } | |
365 case(4):{ | |
366 register uint32_t s; | |
367 for(i=0;i<len;i++){ | |
368 s=((uint32_t*)in)[i]; | |
369 ((uint32_t*)out)[i]=(uint32_t)(((s&0x000000FF)<<24) | | |
370 ((s&0x0000FF00)<<8) | | |
371 ((s&0x00FF0000)>>8) | | |
372 ((s&0xFF000000)>>24)); | |
373 } | |
374 break; | |
375 } | |
376 } | |
377 } | |
378 | |
379 static void si2us(void* in, void* out, int len, int bps) | |
380 { | |
381 register int i; | |
382 switch(bps){ | |
383 case(1): | |
384 for(i=0;i<len;i++) | |
385 ((uint8_t*)out)[i]=(uint8_t)(SCHAR_MAX+((int)((int8_t*)in)[i])); | |
386 break; | |
387 case(2): | |
388 for(i=0;i<len;i++) | |
389 ((uint16_t*)out)[i]=(uint16_t)(SHRT_MAX+((int)((int16_t*)in)[i])); | |
390 break; | |
391 case(4): | |
392 for(i=0;i<len;i++) | |
393 ((uint32_t*)out)[i]=(uint32_t)(INT_MAX+((int32_t*)in)[i]); | |
394 break; | |
395 } | |
396 } | |
397 | |
398 static void us2si(void* in, void* out, int len, int bps) | |
399 { | |
400 register int i; | |
401 switch(bps){ | |
402 case(1): | |
403 for(i=0;i<len;i++) | |
404 ((int8_t*)out)[i]=(int8_t)(SCHAR_MIN+((int)((uint8_t*)in)[i])); | |
405 break; | |
406 case(2): | |
407 for(i=0;i<len;i++) | |
408 ((int16_t*)out)[i]=(int16_t)(SHRT_MIN+((int)((uint16_t*)in)[i])); | |
409 break; | |
410 case(4): | |
411 for(i=0;i<len;i++) | |
412 ((int32_t*)out)[i]=(int32_t)(INT_MIN+((uint32_t*)in)[i]); | |
413 break; | |
414 } | |
415 } | |
416 | |
417 static void change_bps(void* in, void* out, int len, int inbps, int outbps) | |
418 { | |
419 register int i; | |
420 switch(inbps){ | |
421 case(1): | |
422 switch(outbps){ | |
423 case(2): | |
424 for(i=0;i<len;i++) | |
425 ((uint16_t*)out)[i]=((uint16_t)((uint8_t*)in)[i])<<8; | |
426 break; | |
427 case(4): | |
428 for(i=0;i<len;i++) | |
429 ((uint32_t*)out)[i]=((uint32_t)((uint8_t*)in)[i])<<24; | |
430 break; | |
431 } | |
432 break; | |
433 case(2): | |
434 switch(outbps){ | |
435 case(1): | |
436 for(i=0;i<len;i++) | |
437 ((uint8_t*)out)[i]=(uint8_t)((((uint16_t*)in)[i])>>8); | |
438 break; | |
439 case(4): | |
440 for(i=0;i<len;i++) | |
441 ((uint32_t*)out)[i]=((uint32_t)((uint16_t*)in)[i])<<16; | |
442 break; | |
443 } | |
444 break; | |
445 case(4): | |
446 switch(outbps){ | |
447 case(1): | |
448 for(i=0;i<len;i++) | |
449 ((uint8_t*)out)[i]=(uint8_t)((((uint32_t*)in)[i])>>24); | |
450 break; | |
451 case(2): | |
452 for(i=0;i<len;i++) | |
453 ((uint16_t*)out)[i]=(uint16_t)((((uint32_t*)in)[i])>>16); | |
454 break; | |
455 } | |
456 break; | |
457 } | |
458 } | |
459 | |
460 static void float2int(void* in, void* out, int len, int bps) | |
461 { | |
462 register int i; | |
463 switch(bps){ | |
464 case(1): | |
465 for(i=0;i<len;i++) | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
466 ((int8_t*)out)[i]=(int8_t)lrintf(SCHAR_MAX*((float*)in)[i]); |
8167 | 467 break; |
468 case(2): | |
469 for(i=0;i<len;i++) | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
470 ((int16_t*)out)[i]=(int16_t)lrintf(SHRT_MAX*((float*)in)[i]); |
8167 | 471 break; |
472 case(4): | |
473 for(i=0;i<len;i++) | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
474 ((int32_t*)out)[i]=(int32_t)lrintf(INT_MAX*((float*)in)[i]); |
8167 | 475 break; |
476 } | |
477 } | |
478 | |
479 static void int2float(void* in, void* out, int len, int bps) | |
480 { | |
481 register int i; | |
482 switch(bps){ | |
483 case(1): | |
484 for(i=0;i<len;i++) | |
485 ((float*)out)[i]=(1.0/SCHAR_MAX)*((float)((int8_t*)in)[i]); | |
486 break; | |
487 case(2): | |
488 for(i=0;i<len;i++) | |
489 ((float*)out)[i]=(1.0/SHRT_MAX)*((float)((int16_t*)in)[i]); | |
490 break; | |
491 case(4): | |
492 for(i=0;i<len;i++) | |
493 ((float*)out)[i]=(1.0/INT_MAX)*((float)((int32_t*)in)[i]); | |
494 break; | |
495 } | |
496 } |