Mercurial > mplayer.hg
annotate libaf/af_format.c @ 14772:70f0de24b30a
renamed init_adelay to vdelay with opposite range
author | nicodvb |
---|---|
date | Tue, 22 Feb 2005 21:49:08 +0000 |
parents | 94456deb0624 |
children | df515839c8a9 |
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" | |
12486 | 14 #include "../bswap.h" |
14272 | 15 #include "../libvo/fastmemcpy.h" |
7568 | 16 |
8167 | 17 /* Functions used by play to convert the input audio to the correct |
18 format */ | |
7568 | 19 |
8167 | 20 /* The below includes retrives functions for converting to and from |
21 ulaw and alaw */ | |
22 #include "af_format_ulaw.c" | |
23 #include "af_format_alaw.c" | |
7568 | 24 |
8167 | 25 // Switch endianess |
26 static void endian(void* in, void* out, int len, int bps); | |
27 // From singed to unsigned | |
28 static void si2us(void* in, void* out, int len, int bps); | |
29 // From unsinged to signed | |
30 static void us2si(void* in, void* out, int len, int bps); | |
31 // Change the number of bits per sample | |
32 static void change_bps(void* in, void* out, int len, int inbps, int outbps); | |
33 // From float to int signed | |
34 static void float2int(void* in, void* out, int len, int bps); | |
35 // From signed int to float | |
36 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
|
37 |
14272 | 38 static af_data_t* play(struct af_instance_s* af, af_data_t* data); |
39 static af_data_t* play_swapendian(struct af_instance_s* af, af_data_t* data); | |
40 static af_data_t* play_float_s16(struct af_instance_s* af, af_data_t* data); | |
41 static af_data_t* play_s16_float(struct af_instance_s* af, af_data_t* data); | |
42 | |
8607 | 43 // Helper functions to check sanity for input arguments |
44 | |
45 // Sanity check for bytes per sample | |
13989
dcb6b4a33aaa
declare check_format and check_bps static, they are used nowhere else.
reimar
parents:
12486
diff
changeset
|
46 static int check_bps(int bps) |
8607 | 47 { |
12478 | 48 if(bps != 4 && bps != 3 && bps != 2 && bps != 1){ |
8607 | 49 af_msg(AF_MSG_ERROR,"[format] The number of bytes per sample" |
12478 | 50 " must be 1, 2, 3 or 4. Current value is %i \n",bps); |
8607 | 51 return AF_ERROR; |
52 } | |
53 return AF_OK; | |
54 } | |
55 | |
56 // Check for unsupported formats | |
13989
dcb6b4a33aaa
declare check_format and check_bps static, they are used nowhere else.
reimar
parents:
12486
diff
changeset
|
57 static int check_format(int format) |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
58 { |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
59 char buf[256]; |
8607 | 60 switch(format & AF_FORMAT_SPECIAL_MASK){ |
14335
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
61 case(AF_FORMAT_IMA_ADPCM): |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
62 case(AF_FORMAT_MPEG2): |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
63 case(AF_FORMAT_AC3): |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
64 af_msg(AF_MSG_ERROR,"[format] Sample format %s not yet supported \n", |
14399
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
65 af_fmt2str(format,buf,256)); |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
66 return AF_ERROR; |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
67 } |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
68 return AF_OK; |
8607 | 69 } |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
70 |
7568 | 71 // Initialization and runtime control |
72 static int control(struct af_instance_s* af, int cmd, void* arg) | |
73 { | |
74 switch(cmd){ | |
8167 | 75 case AF_CONTROL_REINIT:{ |
76 char buf1[256]; | |
77 char buf2[256]; | |
14272 | 78 af_data_t *data = arg; |
79 | |
7568 | 80 // Make sure this filter isn't redundant |
14717
51a7560a92b7
confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents:
14433
diff
changeset
|
81 if(af->data->format == data->format && |
51a7560a92b7
confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents:
14433
diff
changeset
|
82 af->data->bps == data->bps) |
7568 | 83 return AF_DETACH; |
8607 | 84 |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
85 // Check for errors in configuraton |
14717
51a7560a92b7
confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents:
14433
diff
changeset
|
86 if((AF_OK != check_bps(data->bps)) || |
51a7560a92b7
confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents:
14433
diff
changeset
|
87 (AF_OK != check_format(data->format)) || |
8607 | 88 (AF_OK != check_bps(af->data->bps)) || |
89 (AF_OK != check_format(af->data->format))) | |
8167 | 90 return AF_ERROR; |
91 | |
14399
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
92 af_msg(AF_MSG_VERBOSE,"[format] Changing sample format from %s to %s\n", |
14717
51a7560a92b7
confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents:
14433
diff
changeset
|
93 af_fmt2str(data->format,buf1,256), |
14399
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
94 af_fmt2str(af->data->format,buf2,256)); |
7568 | 95 |
14717
51a7560a92b7
confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents:
14433
diff
changeset
|
96 af->data->rate = data->rate; |
51a7560a92b7
confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents:
14433
diff
changeset
|
97 af->data->nch = data->nch; |
7568 | 98 af->mul.n = af->data->bps; |
14717
51a7560a92b7
confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents:
14433
diff
changeset
|
99 af->mul.d = data->bps; |
14433
95bb94a930a3
always cancel down fractions (frac_t) to avoid overflows and playback
reimar
parents:
14399
diff
changeset
|
100 af_frac_cancel(&af->mul); |
14272 | 101 |
102 af->play = play; // set default | |
103 | |
104 // look whether only endianess differences are there | |
105 if ((af->data->format & ~AF_FORMAT_END_MASK) == | |
106 (data->format & ~AF_FORMAT_END_MASK)) | |
107 { | |
108 af_msg(AF_MSG_VERBOSE,"[format] Accelerated endianess conversion only\n"); | |
109 af->play = play_swapendian; | |
110 } | |
111 if ((data->format == AF_FORMAT_FLOAT_NE) && | |
112 (af->data->format == AF_FORMAT_S16_NE)) | |
113 { | |
14399
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
114 af_msg(AF_MSG_VERBOSE,"[format] Accelerated %s to %s conversion\n", |
14717
51a7560a92b7
confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents:
14433
diff
changeset
|
115 af_fmt2str(data->format,buf1,256), |
14399
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
116 af_fmt2str(af->data->format,buf2,256)); |
14272 | 117 af->play = play_float_s16; |
118 } | |
119 if ((data->format == AF_FORMAT_S16_NE) && | |
120 (af->data->format == AF_FORMAT_FLOAT_NE)) | |
121 { | |
14399
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
122 af_msg(AF_MSG_VERBOSE,"[format] Accelerated %s to %s conversion\n", |
14717
51a7560a92b7
confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents:
14433
diff
changeset
|
123 af_fmt2str(data->format,buf1,256), |
14399
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
124 af_fmt2str(af->data->format,buf2,256)); |
14272 | 125 af->play = play_s16_float; |
126 } | |
7568 | 127 return AF_OK; |
8167 | 128 } |
7998
d48a06d07afb
Adding commandline options for filters and fixing stupid bug in cfg
anders
parents:
7719
diff
changeset
|
129 case AF_CONTROL_COMMAND_LINE:{ |
14335
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
130 int format = af_str2fmt_short(arg); |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
131 if(AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET,&format)) |
8607 | 132 return AF_ERROR; |
133 return AF_OK; | |
8167 | 134 } |
14335
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
135 case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET:{ |
8607 | 136 // Check for errors in configuraton |
137 if(AF_OK != check_format(*(int*)arg)) | |
138 return AF_ERROR; | |
139 | |
140 af->data->format = *(int*)arg; | |
14335
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
141 af->data->bps = af_fmt2bits(af->data->format)/8; |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
142 |
7568 | 143 return AF_OK; |
144 } | |
14335
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
145 } |
7568 | 146 return AF_UNKNOWN; |
147 } | |
148 | |
149 // Deallocate memory | |
150 static void uninit(struct af_instance_s* af) | |
151 { | |
152 if(af->data) | |
153 free(af->data); | |
12386 | 154 af->setup = 0; |
7568 | 155 } |
156 | |
14272 | 157 static af_data_t* play_swapendian(struct af_instance_s* af, af_data_t* data) |
158 { | |
159 af_data_t* l = af->data; // Local data | |
160 af_data_t* c = data; // Current working data | |
161 int len = c->len/c->bps; // Lenght in samples of current audio block | |
162 | |
163 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) | |
164 return NULL; | |
165 | |
166 endian(c->audio,l->audio,len,c->bps); | |
167 | |
168 c->audio = l->audio; | |
169 c->format = l->format; | |
170 | |
171 return c; | |
172 } | |
173 | |
174 static af_data_t* play_float_s16(struct af_instance_s* af, af_data_t* data) | |
175 { | |
176 af_data_t* l = af->data; // Local data | |
177 af_data_t* c = data; // Current working data | |
178 int len = c->len/4; // Lenght in samples of current audio block | |
179 | |
180 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) | |
181 return NULL; | |
182 | |
183 float2int(c->audio, l->audio, len, 2); | |
184 | |
185 c->audio = l->audio; | |
186 c->len = len*2; | |
187 c->bps = 2; | |
188 c->format = l->format; | |
189 | |
190 return c; | |
191 } | |
192 | |
193 static af_data_t* play_s16_float(struct af_instance_s* af, af_data_t* data) | |
194 { | |
195 af_data_t* l = af->data; // Local data | |
196 af_data_t* c = data; // Current working data | |
197 int len = c->len/2; // Lenght in samples of current audio block | |
198 | |
199 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) | |
200 return NULL; | |
201 | |
202 int2float(c->audio, l->audio, len, 2); | |
203 | |
204 c->audio = l->audio; | |
205 c->len = len*4; | |
206 c->bps = 4; | |
207 c->format = l->format; | |
208 | |
209 return c; | |
210 } | |
211 | |
7568 | 212 // Filter data through filter |
213 static af_data_t* play(struct af_instance_s* af, af_data_t* data) | |
214 { | |
8167 | 215 af_data_t* l = af->data; // Local data |
216 af_data_t* c = data; // Current working data | |
217 int len = c->len/c->bps; // Lenght in samples of current audio block | |
7568 | 218 |
219 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) | |
220 return NULL; | |
221 | |
8167 | 222 // Change to cpu native endian format |
223 if((c->format&AF_FORMAT_END_MASK)!=AF_FORMAT_NE) | |
224 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
|
225 |
8167 | 226 // Conversion table |
14261
710b223604fa
100l use right mask type when checking for input format
rtognimp
parents:
14256
diff
changeset
|
227 if((c->format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_MU_LAW) { |
8167 | 228 from_ulaw(c->audio, l->audio, len, l->bps, l->format&AF_FORMAT_POINT_MASK); |
229 if(AF_FORMAT_A_LAW == (l->format&AF_FORMAT_SPECIAL_MASK)) | |
230 to_ulaw(l->audio, l->audio, len, 1, AF_FORMAT_SI); | |
231 if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US) | |
232 si2us(l->audio,l->audio,len,l->bps); | |
14261
710b223604fa
100l use right mask type when checking for input format
rtognimp
parents:
14256
diff
changeset
|
233 } else if((c->format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_A_LAW) { |
8167 | 234 from_alaw(c->audio, l->audio, len, l->bps, l->format&AF_FORMAT_POINT_MASK); |
235 if(AF_FORMAT_A_LAW == (l->format&AF_FORMAT_SPECIAL_MASK)) | |
236 to_alaw(l->audio, l->audio, len, 1, AF_FORMAT_SI); | |
237 if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US) | |
238 si2us(l->audio,l->audio,len,l->bps); | |
14261
710b223604fa
100l use right mask type when checking for input format
rtognimp
parents:
14256
diff
changeset
|
239 } else if((c->format & AF_FORMAT_POINT_MASK) == AF_FORMAT_F) { |
8167 | 240 switch(l->format&AF_FORMAT_SPECIAL_MASK){ |
241 case(AF_FORMAT_MU_LAW): | |
242 to_ulaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK); | |
243 break; | |
244 case(AF_FORMAT_A_LAW): | |
245 to_alaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK); | |
7568 | 246 break; |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
247 default: |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
248 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
|
249 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
|
250 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
|
251 break; |
8167 | 252 } |
14261
710b223604fa
100l use right mask type when checking for input format
rtognimp
parents:
14256
diff
changeset
|
253 } else { |
8167 | 254 // Input must be int |
255 | |
256 // Change signed/unsigned | |
257 if((c->format&AF_FORMAT_SIGN_MASK) != (l->format&AF_FORMAT_SIGN_MASK)){ | |
258 if((c->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US) | |
259 us2si(c->audio,c->audio,len,c->bps); | |
260 else | |
261 si2us(c->audio,c->audio,len,c->bps); | |
262 } | |
263 // Convert to special formats | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
264 switch(l->format&(AF_FORMAT_SPECIAL_MASK|AF_FORMAT_POINT_MASK)){ |
8167 | 265 case(AF_FORMAT_MU_LAW): |
266 to_ulaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK); | |
267 break; | |
268 case(AF_FORMAT_A_LAW): | |
269 to_alaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK); | |
270 break; | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
271 case(AF_FORMAT_F): |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
272 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
|
273 break; |
8167 | 274 default: |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
275 // Change the number of bits |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
276 if(c->bps != l->bps) |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
277 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
|
278 else |
8185 | 279 memcpy(l->audio,c->audio,len*c->bps); |
7568 | 280 break; |
281 } | |
282 } | |
7719
41e8d0916c60
Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents:
7711
diff
changeset
|
283 |
41e8d0916c60
Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents:
7711
diff
changeset
|
284 // Switch from cpu native endian to the correct endianess |
8167 | 285 if((l->format&AF_FORMAT_END_MASK)!=AF_FORMAT_NE) |
286 endian(l->audio,l->audio,len,l->bps); | |
7568 | 287 |
288 // Set output data | |
289 c->audio = l->audio; | |
8167 | 290 c->len = len*l->bps; |
7568 | 291 c->bps = l->bps; |
292 c->format = l->format; | |
293 return c; | |
294 } | |
295 | |
296 // Allocate memory and set function pointers | |
297 static int open(af_instance_t* af){ | |
298 af->control=control; | |
299 af->uninit=uninit; | |
300 af->play=play; | |
301 af->mul.n=1; | |
302 af->mul.d=1; | |
303 af->data=calloc(1,sizeof(af_data_t)); | |
304 if(af->data == NULL) | |
305 return AF_ERROR; | |
306 return AF_OK; | |
307 } | |
308 | |
309 // Description of this filter | |
310 af_info_t af_info_format = { | |
311 "Sample format conversion", | |
312 "format", | |
313 "Anders", | |
314 "", | |
7615 | 315 AF_FLAGS_REENTRANT, |
7568 | 316 open |
317 }; | |
8167 | 318 |
12478 | 319 static inline uint32_t load24bit(void* data, int pos) { |
320 #if WORDS_BIGENDIAN | |
321 return (((uint32_t)((uint8_t*)data)[3*pos])<<24) | | |
322 (((uint32_t)((uint8_t*)data)[3*pos+1])<<16) | | |
323 (((uint32_t)((uint8_t*)data)[3*pos+2])<<8); | |
324 #else | |
325 return (((uint32_t)((uint8_t*)data)[3*pos])<<8) | | |
326 (((uint32_t)((uint8_t*)data)[3*pos+1])<<16) | | |
327 (((uint32_t)((uint8_t*)data)[3*pos+2])<<24); | |
328 #endif | |
329 } | |
330 | |
331 static inline void store24bit(void* data, int pos, uint32_t expanded_value) { | |
332 #if WORDS_BIGENDIAN | |
333 ((uint8_t*)data)[3*pos]=expanded_value>>24; | |
334 ((uint8_t*)data)[3*pos+1]=expanded_value>>16; | |
335 ((uint8_t*)data)[3*pos+2]=expanded_value>>8; | |
336 #else | |
337 ((uint8_t*)data)[3*pos]=expanded_value>>8; | |
338 ((uint8_t*)data)[3*pos+1]=expanded_value>>16; | |
339 ((uint8_t*)data)[3*pos+2]=expanded_value>>24; | |
340 #endif | |
341 } | |
342 | |
8167 | 343 // Function implementations used by play |
344 static void endian(void* in, void* out, int len, int bps) | |
345 { | |
346 register int i; | |
347 switch(bps){ | |
348 case(2):{ | |
349 for(i=0;i<len;i++){ | |
12486 | 350 ((uint16_t*)out)[i]=bswap_16(((uint16_t*)in)[i]); |
8167 | 351 } |
352 break; | |
353 } | |
12478 | 354 case(3):{ |
355 register uint8_t s; | |
356 for(i=0;i<len;i++){ | |
357 s=((uint8_t*)in)[3*i]; | |
358 ((uint8_t*)out)[3*i]=((uint8_t*)in)[3*i+2]; | |
12481
dbbc25ea6403
fix endian conversion for (curently unused) case where in buffer != out buffer
reimar
parents:
12478
diff
changeset
|
359 if (in != out) |
dbbc25ea6403
fix endian conversion for (curently unused) case where in buffer != out buffer
reimar
parents:
12478
diff
changeset
|
360 ((uint8_t*)out)[3*i+1]=((uint8_t*)in)[3*i+1]; |
12478 | 361 ((uint8_t*)out)[3*i+2]=s; |
362 } | |
363 break; | |
364 } | |
8167 | 365 case(4):{ |
366 for(i=0;i<len;i++){ | |
12486 | 367 ((uint32_t*)out)[i]=bswap_32(((uint32_t*)in)[i]); |
8167 | 368 } |
369 break; | |
370 } | |
371 } | |
372 } | |
373 | |
374 static void si2us(void* in, void* out, int len, int bps) | |
375 { | |
376 register int i; | |
377 switch(bps){ | |
378 case(1): | |
379 for(i=0;i<len;i++) | |
380 ((uint8_t*)out)[i]=(uint8_t)(SCHAR_MAX+((int)((int8_t*)in)[i])); | |
381 break; | |
382 case(2): | |
383 for(i=0;i<len;i++) | |
384 ((uint16_t*)out)[i]=(uint16_t)(SHRT_MAX+((int)((int16_t*)in)[i])); | |
385 break; | |
12478 | 386 case(3): |
387 for(i=0;i<len;i++) | |
388 store24bit(out, i, (uint32_t)(INT_MAX+(int32_t)load24bit(in, i))); | |
389 break; | |
8167 | 390 case(4): |
391 for(i=0;i<len;i++) | |
392 ((uint32_t*)out)[i]=(uint32_t)(INT_MAX+((int32_t*)in)[i]); | |
393 break; | |
394 } | |
395 } | |
396 | |
397 static void us2si(void* in, void* out, int len, int bps) | |
398 { | |
399 register int i; | |
400 switch(bps){ | |
401 case(1): | |
402 for(i=0;i<len;i++) | |
403 ((int8_t*)out)[i]=(int8_t)(SCHAR_MIN+((int)((uint8_t*)in)[i])); | |
404 break; | |
405 case(2): | |
406 for(i=0;i<len;i++) | |
407 ((int16_t*)out)[i]=(int16_t)(SHRT_MIN+((int)((uint16_t*)in)[i])); | |
408 break; | |
12478 | 409 case(3): |
410 for(i=0;i<len;i++) | |
411 store24bit(out, i, (int32_t)(INT_MIN+(uint32_t)load24bit(in, i))); | |
412 break; | |
8167 | 413 case(4): |
414 for(i=0;i<len;i++) | |
415 ((int32_t*)out)[i]=(int32_t)(INT_MIN+((uint32_t*)in)[i]); | |
416 break; | |
417 } | |
418 } | |
419 | |
420 static void change_bps(void* in, void* out, int len, int inbps, int outbps) | |
421 { | |
422 register int i; | |
423 switch(inbps){ | |
424 case(1): | |
425 switch(outbps){ | |
426 case(2): | |
427 for(i=0;i<len;i++) | |
428 ((uint16_t*)out)[i]=((uint16_t)((uint8_t*)in)[i])<<8; | |
429 break; | |
12478 | 430 case(3): |
431 for(i=0;i<len;i++) | |
432 store24bit(out, i, ((uint32_t)((uint8_t*)in)[i])<<24); | |
433 break; | |
8167 | 434 case(4): |
435 for(i=0;i<len;i++) | |
436 ((uint32_t*)out)[i]=((uint32_t)((uint8_t*)in)[i])<<24; | |
437 break; | |
438 } | |
439 break; | |
440 case(2): | |
441 switch(outbps){ | |
442 case(1): | |
443 for(i=0;i<len;i++) | |
444 ((uint8_t*)out)[i]=(uint8_t)((((uint16_t*)in)[i])>>8); | |
445 break; | |
12478 | 446 case(3): |
447 for(i=0;i<len;i++) | |
448 store24bit(out, i, ((uint32_t)((uint16_t*)in)[i])<<16); | |
449 break; | |
8167 | 450 case(4): |
451 for(i=0;i<len;i++) | |
452 ((uint32_t*)out)[i]=((uint32_t)((uint16_t*)in)[i])<<16; | |
453 break; | |
454 } | |
455 break; | |
12478 | 456 case(3): |
457 switch(outbps){ | |
458 case(1): | |
459 for(i=0;i<len;i++) | |
460 ((uint8_t*)out)[i]=(uint8_t)(load24bit(in, i)>>24); | |
461 break; | |
462 case(2): | |
463 for(i=0;i<len;i++) | |
464 ((uint16_t*)out)[i]=(uint16_t)(load24bit(in, i)>>16); | |
465 break; | |
466 case(4): | |
467 for(i=0;i<len;i++) | |
468 ((uint32_t*)out)[i]=(uint32_t)load24bit(in, i); | |
469 break; | |
470 } | |
471 break; | |
8167 | 472 case(4): |
473 switch(outbps){ | |
474 case(1): | |
475 for(i=0;i<len;i++) | |
476 ((uint8_t*)out)[i]=(uint8_t)((((uint32_t*)in)[i])>>24); | |
477 break; | |
478 case(2): | |
479 for(i=0;i<len;i++) | |
480 ((uint16_t*)out)[i]=(uint16_t)((((uint32_t*)in)[i])>>16); | |
481 break; | |
12478 | 482 case(3): |
483 for(i=0;i<len;i++) | |
484 store24bit(out, i, ((uint32_t*)in)[i]); | |
485 break; | |
8167 | 486 } |
487 break; | |
488 } | |
489 } | |
490 | |
491 static void float2int(void* in, void* out, int len, int bps) | |
492 { | |
493 register int i; | |
494 switch(bps){ | |
495 case(1): | |
496 for(i=0;i<len;i++) | |
14758
94456deb0624
finally the dreaded white-noise-with-floats bug is fixed!!!!
rfelker
parents:
14748
diff
changeset
|
497 ((int8_t*)out)[i] = (int)(127.0 * (1.0+((float*)in)[i])) - 127; |
8167 | 498 break; |
499 case(2): | |
500 for(i=0;i<len;i++) | |
14758
94456deb0624
finally the dreaded white-noise-with-floats bug is fixed!!!!
rfelker
parents:
14748
diff
changeset
|
501 ((int16_t*)out)[i] = (int)(32767.0 * (1.0+((float*)in)[i])) - 32767; |
8167 | 502 break; |
12478 | 503 case(3): |
504 for(i=0;i<len;i++) | |
14758
94456deb0624
finally the dreaded white-noise-with-floats bug is fixed!!!!
rfelker
parents:
14748
diff
changeset
|
505 store24bit(out, i, (int)(2147483647.0 * (1.0+((float*)in)[i])) - 2147483647); |
12478 | 506 break; |
8167 | 507 case(4): |
508 for(i=0;i<len;i++) | |
14758
94456deb0624
finally the dreaded white-noise-with-floats bug is fixed!!!!
rfelker
parents:
14748
diff
changeset
|
509 ((int32_t*)out)[i] = (int)(2147483647.0 * (1.0+((float*)in)[i])) - 2147483647; |
8167 | 510 break; |
511 } | |
512 } | |
513 | |
514 static void int2float(void* in, void* out, int len, int bps) | |
515 { | |
516 register int i; | |
517 switch(bps){ | |
518 case(1): | |
519 for(i=0;i<len;i++) | |
14758
94456deb0624
finally the dreaded white-noise-with-floats bug is fixed!!!!
rfelker
parents:
14748
diff
changeset
|
520 ((float*)out)[i]=(1.0/128.0)*((float)((int8_t*)in)[i]); |
8167 | 521 break; |
522 case(2): | |
523 for(i=0;i<len;i++) | |
14758
94456deb0624
finally the dreaded white-noise-with-floats bug is fixed!!!!
rfelker
parents:
14748
diff
changeset
|
524 ((float*)out)[i]=(1.0/32768.0)*((float)((int16_t*)in)[i]); |
8167 | 525 break; |
12478 | 526 case(3): |
527 for(i=0;i<len;i++) | |
14758
94456deb0624
finally the dreaded white-noise-with-floats bug is fixed!!!!
rfelker
parents:
14748
diff
changeset
|
528 ((float*)out)[i]=(1.0/2147483648.0)*((float)((int32_t)load24bit(in, i))); |
12478 | 529 break; |
8167 | 530 case(4): |
531 for(i=0;i<len;i++) | |
14758
94456deb0624
finally the dreaded white-noise-with-floats bug is fixed!!!!
rfelker
parents:
14748
diff
changeset
|
532 ((float*)out)[i]=(1.0/2147483648.0)*((float)((int32_t*)in)[i]); |
8167 | 533 break; |
534 } | |
535 } |