Mercurial > mplayer.hg
annotate libaf/af_format.c @ 14568:bfdec335c4d4
Play RV30 with 8-elements cmsg24
Fixes rv30_cmsg24_test.rmvb (now in samples)
author | rtognimp |
---|---|
date | Sat, 22 Jan 2005 00:06:59 +0000 |
parents | 95bb94a930a3 |
children | 51a7560a92b7 |
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 |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
17 // Integer to float conversion through lrintf() |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
18 #ifdef HAVE_LRINTF |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
19 #define __USE_ISOC99 1 |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
20 #include <math.h> |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
21 #else |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
22 #define lrintf(x) ((int)(x)) |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
23 #endif |
8167 | 24 |
25 /* Functions used by play to convert the input audio to the correct | |
26 format */ | |
7568 | 27 |
8167 | 28 /* The below includes retrives functions for converting to and from |
29 ulaw and alaw */ | |
30 #include "af_format_ulaw.c" | |
31 #include "af_format_alaw.c" | |
7568 | 32 |
8167 | 33 // Switch endianess |
34 static void endian(void* in, void* out, int len, int bps); | |
35 // From singed to unsigned | |
36 static void si2us(void* in, void* out, int len, int bps); | |
37 // From unsinged to signed | |
38 static void us2si(void* in, void* out, int len, int bps); | |
39 // Change the number of bits per sample | |
40 static void change_bps(void* in, void* out, int len, int inbps, int outbps); | |
41 // From float to int signed | |
42 static void float2int(void* in, void* out, int len, int bps); | |
43 // From signed int to float | |
44 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
|
45 |
14272 | 46 static af_data_t* play(struct af_instance_s* af, af_data_t* data); |
47 static af_data_t* play_swapendian(struct af_instance_s* af, af_data_t* data); | |
48 static af_data_t* play_float_s16(struct af_instance_s* af, af_data_t* data); | |
49 static af_data_t* play_s16_float(struct af_instance_s* af, af_data_t* data); | |
50 | |
8167 | 51 // Convert from string to format |
14245 | 52 int af_str2fmt(char* str) |
7568 | 53 { |
8167 | 54 int format=0; |
55 // Scan for endianess | |
56 if(strstr(str,"be") || strstr(str,"BE")) | |
57 format |= AF_FORMAT_BE; | |
58 else if(strstr(str,"le") || strstr(str,"LE")) | |
59 format |= AF_FORMAT_LE; | |
60 else | |
61 format |= AF_FORMAT_NE; | |
62 | |
63 // Scan for special formats | |
64 if(strstr(str,"mulaw") || strstr(str,"MULAW")){ | |
65 format |= AF_FORMAT_MU_LAW; return format; | |
66 } | |
67 if(strstr(str,"alaw") || strstr(str,"ALAW")){ | |
68 format |= AF_FORMAT_A_LAW; return format; | |
69 } | |
70 if(strstr(str,"ac3") || strstr(str,"AC3")){ | |
71 format |= AF_FORMAT_AC3; return format; | |
72 } | |
73 if(strstr(str,"mpeg2") || strstr(str,"MPEG2")){ | |
74 format |= AF_FORMAT_MPEG2; return format; | |
75 } | |
76 if(strstr(str,"imaadpcm") || strstr(str,"IMAADPCM")){ | |
77 format |= AF_FORMAT_IMA_ADPCM; return format; | |
78 } | |
79 | |
80 // Scan for int/float | |
81 if(strstr(str,"float") || strstr(str,"FLOAT")){ | |
82 format |= AF_FORMAT_F; return format; | |
7568 | 83 } |
8167 | 84 else |
85 format |= AF_FORMAT_I; | |
7568 | 86 |
8167 | 87 // Scan for signed/unsigned |
88 if(strstr(str,"unsigned") || strstr(str,"UNSIGNED")) | |
89 format |= AF_FORMAT_US; | |
90 else | |
91 format |= AF_FORMAT_SI; | |
92 | |
93 return format; | |
94 } | |
95 | |
14245 | 96 inline int af_fmt2bits(int format) |
97 { | |
98 return (format & AF_FORMAT_BITS_MASK)+8; | |
99 // return (((format & AF_FORMAT_BITS_MASK)>>3)+1) * 8; | |
100 #if 0 | |
101 switch(format & AF_FORMAT_BITS_MASK) | |
102 { | |
103 case AF_FORMAT_8BIT: return 8; | |
104 case AF_FORMAT_16BIT: return 16; | |
105 case AF_FORMAT_24BIT: return 24; | |
106 case AF_FORMAT_32BIT: return 32; | |
107 case AF_FORMAT_48BIT: return 48; | |
108 } | |
109 #endif | |
110 return -1; | |
111 } | |
112 | |
14335
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
113 inline int af_bits2fmt(int bits) |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
114 { |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
115 return (bits/8 - 1) << 3; |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
116 } |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
117 |
8167 | 118 /* Convert format to str input str is a buffer for the |
119 converted string, size is the size of the buffer */ | |
14245 | 120 char* af_fmt2str(int format, char* str, int size) |
8167 | 121 { |
122 int i=0; | |
14245 | 123 |
14256
27002dcf0a70
ensure af_fmt2str always return a 0 terminated string
reimar
parents:
14245
diff
changeset
|
124 if (size < 1) |
27002dcf0a70
ensure af_fmt2str always return a 0 terminated string
reimar
parents:
14245
diff
changeset
|
125 return NULL; |
27002dcf0a70
ensure af_fmt2str always return a 0 terminated string
reimar
parents:
14245
diff
changeset
|
126 size--; // reserve one for terminating 0 |
27002dcf0a70
ensure af_fmt2str always return a 0 terminated string
reimar
parents:
14245
diff
changeset
|
127 |
14245 | 128 // Endianess |
8167 | 129 if(AF_FORMAT_LE == (format & AF_FORMAT_END_MASK)) |
14272 | 130 i+=snprintf(str,size-i,"little-endian "); |
8167 | 131 else |
14272 | 132 i+=snprintf(str,size-i,"big-endian "); |
8167 | 133 |
134 if(format & AF_FORMAT_SPECIAL_MASK){ | |
135 switch(format & AF_FORMAT_SPECIAL_MASK){ | |
136 case(AF_FORMAT_MU_LAW): | |
14272 | 137 i+=snprintf(&str[i],size-i,"mu-law "); break; |
8167 | 138 case(AF_FORMAT_A_LAW): |
14272 | 139 i+=snprintf(&str[i],size-i,"A-law "); break; |
8167 | 140 case(AF_FORMAT_MPEG2): |
14272 | 141 i+=snprintf(&str[i],size-i,"MPEG-2 "); break; |
8167 | 142 case(AF_FORMAT_AC3): |
143 i+=snprintf(&str[i],size-i,"AC3 "); break; | |
14263 | 144 case(AF_FORMAT_IMA_ADPCM): |
14272 | 145 i+=snprintf(&str[i],size-i,"IMA-ADPCM "); break; |
14245 | 146 default: |
147 printf("Unknown special\n"); | |
8167 | 148 } |
149 } | |
150 else{ | |
14245 | 151 // Bits |
152 i+=snprintf(&str[i],size-i,"%d-bit ", af_fmt2bits(format)); | |
153 | |
8167 | 154 // Point |
155 if(AF_FORMAT_F == (format & AF_FORMAT_POINT_MASK)) | |
14245 | 156 i+=snprintf(&str[i],size-i,"float "); |
8167 | 157 else{ |
158 // Sign | |
159 if(AF_FORMAT_US == (format & AF_FORMAT_SIGN_MASK)) | |
160 i+=snprintf(&str[i],size-i,"unsigned "); | |
161 else | |
162 i+=snprintf(&str[i],size-i,"signed "); | |
163 | |
14245 | 164 i+=snprintf(&str[i],size-i,"int "); |
8167 | 165 } |
166 } | |
14399
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
167 // remove trailing space |
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
168 if (i > 0 && str[i - 1] == ' ') |
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
169 i--; |
14256
27002dcf0a70
ensure af_fmt2str always return a 0 terminated string
reimar
parents:
14245
diff
changeset
|
170 str[i] = 0; // make sure it is 0 terminated. |
8167 | 171 return str; |
7568 | 172 } |
173 | |
14263 | 174 char *af_fmt2str_short(int format) |
175 { | |
176 switch(format) | |
177 { | |
178 // special | |
179 case AF_FORMAT_MU_LAW: return "mulaw"; | |
180 case AF_FORMAT_A_LAW: return "alaw"; | |
181 case AF_FORMAT_MPEG2: return "mpeg2"; | |
182 case AF_FORMAT_AC3: return "ac3"; | |
183 case AF_FORMAT_IMA_ADPCM: return "imaadpcm"; | |
184 // ordinary | |
185 case AF_FORMAT_U8: return "u8"; | |
186 case AF_FORMAT_S8: return "s8"; | |
187 case AF_FORMAT_U16_LE: return "u16le"; | |
188 case AF_FORMAT_U16_BE: return "u16be"; | |
189 case AF_FORMAT_S16_LE: return "s16le"; | |
190 case AF_FORMAT_S16_BE: return "s16be"; | |
191 case AF_FORMAT_U24_LE: return "u24le"; | |
192 case AF_FORMAT_U24_BE: return "u24be"; | |
193 case AF_FORMAT_S24_LE: return "s24le"; | |
194 case AF_FORMAT_S24_BE: return "s24be"; | |
195 case AF_FORMAT_U32_LE: return "u32le"; | |
196 case AF_FORMAT_U32_BE: return "u32be"; | |
197 case AF_FORMAT_S32_LE: return "s32le"; | |
198 case AF_FORMAT_S32_BE: return "s32be"; | |
199 case AF_FORMAT_FLOAT_LE: return "floatle"; | |
200 case AF_FORMAT_FLOAT_BE: return "floatbe"; | |
201 } | |
202 return "??"; | |
203 } | |
204 | |
14335
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
205 int af_str2fmt_short(char* str) |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
206 { |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
207 int i; |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
208 static struct { |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
209 const char *name; |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
210 const int format; |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
211 } table[] = { |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
212 { "mulaw", AF_FORMAT_MU_LAW }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
213 { "alaw", AF_FORMAT_A_LAW }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
214 { "mpeg2", AF_FORMAT_MPEG2 }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
215 { "ac3", AF_FORMAT_AC3 }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
216 { "imaadpcm", AF_FORMAT_IMA_ADPCM }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
217 |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
218 { "u8", AF_FORMAT_U8 }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
219 { "s8", AF_FORMAT_S8 }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
220 { "u16le", AF_FORMAT_U16_LE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
221 { "u16be", AF_FORMAT_U16_BE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
222 { "u16ne", AF_FORMAT_U16_NE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
223 { "s16le", AF_FORMAT_S16_LE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
224 { "s16be", AF_FORMAT_S16_BE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
225 { "s16ne", AF_FORMAT_S16_NE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
226 { "u24le", AF_FORMAT_U24_LE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
227 { "u24be", AF_FORMAT_U24_BE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
228 { "u24ne", AF_FORMAT_U24_NE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
229 { "s24le", AF_FORMAT_S24_LE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
230 { "s24be", AF_FORMAT_S24_BE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
231 { "s24ne", AF_FORMAT_S24_NE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
232 { "u32le", AF_FORMAT_U32_LE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
233 { "u32be", AF_FORMAT_U32_BE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
234 { "u32ne", AF_FORMAT_U32_NE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
235 { "s32le", AF_FORMAT_S32_LE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
236 { "s32be", AF_FORMAT_S32_BE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
237 { "s32ne", AF_FORMAT_S32_NE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
238 { "floatle", AF_FORMAT_FLOAT_LE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
239 { "floatbe", AF_FORMAT_FLOAT_BE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
240 { "floatne", AF_FORMAT_FLOAT_NE }, |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
241 |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
242 { NULL, 0 } |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
243 }; |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
244 |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
245 for (i = 0; table[i].name; i++) |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
246 if (!strcasecmp(str, table[i].name)) |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
247 return table[i].format; |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
248 |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
249 return -1; |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
250 } |
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
251 |
8607 | 252 // Helper functions to check sanity for input arguments |
253 | |
254 // 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
|
255 static int check_bps(int bps) |
8607 | 256 { |
12478 | 257 if(bps != 4 && bps != 3 && bps != 2 && bps != 1){ |
8607 | 258 af_msg(AF_MSG_ERROR,"[format] The number of bytes per sample" |
12478 | 259 " must be 1, 2, 3 or 4. Current value is %i \n",bps); |
8607 | 260 return AF_ERROR; |
261 } | |
262 return AF_OK; | |
263 } | |
264 | |
265 // Check for unsupported formats | |
13989
dcb6b4a33aaa
declare check_format and check_bps static, they are used nowhere else.
reimar
parents:
12486
diff
changeset
|
266 static int check_format(int format) |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
267 { |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
268 char buf[256]; |
8607 | 269 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
|
270 case(AF_FORMAT_IMA_ADPCM): |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
271 case(AF_FORMAT_MPEG2): |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
272 case(AF_FORMAT_AC3): |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
273 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
|
274 af_fmt2str(format,buf,256)); |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
275 return AF_ERROR; |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
276 } |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
277 return AF_OK; |
8607 | 278 } |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
279 |
7568 | 280 // Initialization and runtime control |
281 static int control(struct af_instance_s* af, int cmd, void* arg) | |
282 { | |
283 switch(cmd){ | |
8167 | 284 case AF_CONTROL_REINIT:{ |
285 char buf1[256]; | |
286 char buf2[256]; | |
14272 | 287 af_data_t *data = arg; |
288 | |
7568 | 289 // Make sure this filter isn't redundant |
8167 | 290 if(af->data->format == ((af_data_t*)arg)->format && |
291 af->data->bps == ((af_data_t*)arg)->bps) | |
7568 | 292 return AF_DETACH; |
8607 | 293 |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
294 // Check for errors in configuraton |
8607 | 295 if((AF_OK != check_bps(((af_data_t*)arg)->bps)) || |
296 (AF_OK != check_format(((af_data_t*)arg)->format)) || | |
297 (AF_OK != check_bps(af->data->bps)) || | |
298 (AF_OK != check_format(af->data->format))) | |
8167 | 299 return AF_ERROR; |
300 | |
14399
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
301 af_msg(AF_MSG_VERBOSE,"[format] Changing sample format from %s to %s\n", |
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
302 af_fmt2str(((af_data_t*)arg)->format,buf1,256), |
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
303 af_fmt2str(af->data->format,buf2,256)); |
7568 | 304 |
305 af->data->rate = ((af_data_t*)arg)->rate; | |
306 af->data->nch = ((af_data_t*)arg)->nch; | |
307 af->mul.n = af->data->bps; | |
308 af->mul.d = ((af_data_t*)arg)->bps; | |
14433
95bb94a930a3
always cancel down fractions (frac_t) to avoid overflows and playback
reimar
parents:
14399
diff
changeset
|
309 af_frac_cancel(&af->mul); |
14272 | 310 |
311 af->play = play; // set default | |
312 | |
313 // look whether only endianess differences are there | |
314 if ((af->data->format & ~AF_FORMAT_END_MASK) == | |
315 (data->format & ~AF_FORMAT_END_MASK)) | |
316 { | |
317 af_msg(AF_MSG_VERBOSE,"[format] Accelerated endianess conversion only\n"); | |
318 af->play = play_swapendian; | |
319 } | |
320 if ((data->format == AF_FORMAT_FLOAT_NE) && | |
321 (af->data->format == AF_FORMAT_S16_NE)) | |
322 { | |
14399
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
323 af_msg(AF_MSG_VERBOSE,"[format] Accelerated %s to %s conversion\n", |
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
324 af_fmt2str(((af_data_t*)arg)->format,buf1,256), |
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
325 af_fmt2str(af->data->format,buf2,256)); |
14272 | 326 af->play = play_float_s16; |
327 } | |
328 if ((data->format == AF_FORMAT_S16_NE) && | |
329 (af->data->format == AF_FORMAT_FLOAT_NE)) | |
330 { | |
14399
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
331 af_msg(AF_MSG_VERBOSE,"[format] Accelerated %s to %s conversion\n", |
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
332 af_fmt2str(((af_data_t*)arg)->format,buf1,256), |
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
333 af_fmt2str(af->data->format,buf2,256)); |
14272 | 334 af->play = play_s16_float; |
335 } | |
7568 | 336 return AF_OK; |
8167 | 337 } |
7998
d48a06d07afb
Adding commandline options for filters and fixing stupid bug in cfg
anders
parents:
7719
diff
changeset
|
338 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
|
339 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
|
340 if(AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET,&format)) |
8607 | 341 return AF_ERROR; |
342 return AF_OK; | |
8167 | 343 } |
14335
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
344 case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET:{ |
8607 | 345 // Check for errors in configuraton |
346 if(AF_OK != check_format(*(int*)arg)) | |
347 return AF_ERROR; | |
348 | |
349 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
|
350 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
|
351 |
7568 | 352 return AF_OK; |
353 } | |
14335
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
354 } |
7568 | 355 return AF_UNKNOWN; |
356 } | |
357 | |
358 // Deallocate memory | |
359 static void uninit(struct af_instance_s* af) | |
360 { | |
361 if(af->data) | |
362 free(af->data); | |
12386 | 363 af->setup = 0; |
7568 | 364 } |
365 | |
14272 | 366 static af_data_t* play_swapendian(struct af_instance_s* af, af_data_t* data) |
367 { | |
368 af_data_t* l = af->data; // Local data | |
369 af_data_t* c = data; // Current working data | |
370 int len = c->len/c->bps; // Lenght in samples of current audio block | |
371 | |
372 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) | |
373 return NULL; | |
374 | |
375 endian(c->audio,l->audio,len,c->bps); | |
376 | |
377 c->audio = l->audio; | |
378 c->format = l->format; | |
379 | |
380 return c; | |
381 } | |
382 | |
383 static af_data_t* play_float_s16(struct af_instance_s* af, af_data_t* data) | |
384 { | |
385 af_data_t* l = af->data; // Local data | |
386 af_data_t* c = data; // Current working data | |
387 int len = c->len/4; // Lenght in samples of current audio block | |
388 | |
389 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) | |
390 return NULL; | |
391 | |
392 float2int(c->audio, l->audio, len, 2); | |
393 | |
394 c->audio = l->audio; | |
395 c->len = len*2; | |
396 c->bps = 2; | |
397 c->format = l->format; | |
398 | |
399 return c; | |
400 } | |
401 | |
402 static af_data_t* play_s16_float(struct af_instance_s* af, af_data_t* data) | |
403 { | |
404 af_data_t* l = af->data; // Local data | |
405 af_data_t* c = data; // Current working data | |
406 int len = c->len/2; // Lenght in samples of current audio block | |
407 | |
408 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) | |
409 return NULL; | |
410 | |
411 int2float(c->audio, l->audio, len, 2); | |
412 | |
413 c->audio = l->audio; | |
414 c->len = len*4; | |
415 c->bps = 4; | |
416 c->format = l->format; | |
417 | |
418 return c; | |
419 } | |
420 | |
7568 | 421 // Filter data through filter |
422 static af_data_t* play(struct af_instance_s* af, af_data_t* data) | |
423 { | |
8167 | 424 af_data_t* l = af->data; // Local data |
425 af_data_t* c = data; // Current working data | |
426 int len = c->len/c->bps; // Lenght in samples of current audio block | |
7568 | 427 |
428 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) | |
429 return NULL; | |
430 | |
8167 | 431 // Change to cpu native endian format |
432 if((c->format&AF_FORMAT_END_MASK)!=AF_FORMAT_NE) | |
433 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
|
434 |
8167 | 435 // Conversion table |
14261
710b223604fa
100l use right mask type when checking for input format
rtognimp
parents:
14256
diff
changeset
|
436 if((c->format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_MU_LAW) { |
8167 | 437 from_ulaw(c->audio, l->audio, len, l->bps, l->format&AF_FORMAT_POINT_MASK); |
438 if(AF_FORMAT_A_LAW == (l->format&AF_FORMAT_SPECIAL_MASK)) | |
439 to_ulaw(l->audio, l->audio, len, 1, AF_FORMAT_SI); | |
440 if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US) | |
441 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
|
442 } else if((c->format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_A_LAW) { |
8167 | 443 from_alaw(c->audio, l->audio, len, l->bps, l->format&AF_FORMAT_POINT_MASK); |
444 if(AF_FORMAT_A_LAW == (l->format&AF_FORMAT_SPECIAL_MASK)) | |
445 to_alaw(l->audio, l->audio, len, 1, AF_FORMAT_SI); | |
446 if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US) | |
447 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
|
448 } else if((c->format & AF_FORMAT_POINT_MASK) == AF_FORMAT_F) { |
8167 | 449 switch(l->format&AF_FORMAT_SPECIAL_MASK){ |
450 case(AF_FORMAT_MU_LAW): | |
451 to_ulaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK); | |
452 break; | |
453 case(AF_FORMAT_A_LAW): | |
454 to_alaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK); | |
7568 | 455 break; |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
456 default: |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
457 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
|
458 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
|
459 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
|
460 break; |
8167 | 461 } |
14261
710b223604fa
100l use right mask type when checking for input format
rtognimp
parents:
14256
diff
changeset
|
462 } else { |
8167 | 463 // Input must be int |
464 | |
465 // Change signed/unsigned | |
466 if((c->format&AF_FORMAT_SIGN_MASK) != (l->format&AF_FORMAT_SIGN_MASK)){ | |
467 if((c->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US) | |
468 us2si(c->audio,c->audio,len,c->bps); | |
469 else | |
470 si2us(c->audio,c->audio,len,c->bps); | |
471 } | |
472 // Convert to special formats | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
473 switch(l->format&(AF_FORMAT_SPECIAL_MASK|AF_FORMAT_POINT_MASK)){ |
8167 | 474 case(AF_FORMAT_MU_LAW): |
475 to_ulaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK); | |
476 break; | |
477 case(AF_FORMAT_A_LAW): | |
478 to_alaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK); | |
479 break; | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
480 case(AF_FORMAT_F): |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
481 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
|
482 break; |
8167 | 483 default: |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
484 // Change the number of bits |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
485 if(c->bps != l->bps) |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
486 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
|
487 else |
8185 | 488 memcpy(l->audio,c->audio,len*c->bps); |
7568 | 489 break; |
490 } | |
491 } | |
7719
41e8d0916c60
Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents:
7711
diff
changeset
|
492 |
41e8d0916c60
Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents:
7711
diff
changeset
|
493 // Switch from cpu native endian to the correct endianess |
8167 | 494 if((l->format&AF_FORMAT_END_MASK)!=AF_FORMAT_NE) |
495 endian(l->audio,l->audio,len,l->bps); | |
7568 | 496 |
497 // Set output data | |
498 c->audio = l->audio; | |
8167 | 499 c->len = len*l->bps; |
7568 | 500 c->bps = l->bps; |
501 c->format = l->format; | |
502 return c; | |
503 } | |
504 | |
505 // Allocate memory and set function pointers | |
506 static int open(af_instance_t* af){ | |
507 af->control=control; | |
508 af->uninit=uninit; | |
509 af->play=play; | |
510 af->mul.n=1; | |
511 af->mul.d=1; | |
512 af->data=calloc(1,sizeof(af_data_t)); | |
513 if(af->data == NULL) | |
514 return AF_ERROR; | |
515 return AF_OK; | |
516 } | |
517 | |
518 // Description of this filter | |
519 af_info_t af_info_format = { | |
520 "Sample format conversion", | |
521 "format", | |
522 "Anders", | |
523 "", | |
7615 | 524 AF_FLAGS_REENTRANT, |
7568 | 525 open |
526 }; | |
8167 | 527 |
12478 | 528 static inline uint32_t load24bit(void* data, int pos) { |
529 #if WORDS_BIGENDIAN | |
530 return (((uint32_t)((uint8_t*)data)[3*pos])<<24) | | |
531 (((uint32_t)((uint8_t*)data)[3*pos+1])<<16) | | |
532 (((uint32_t)((uint8_t*)data)[3*pos+2])<<8); | |
533 #else | |
534 return (((uint32_t)((uint8_t*)data)[3*pos])<<8) | | |
535 (((uint32_t)((uint8_t*)data)[3*pos+1])<<16) | | |
536 (((uint32_t)((uint8_t*)data)[3*pos+2])<<24); | |
537 #endif | |
538 } | |
539 | |
540 static inline void store24bit(void* data, int pos, uint32_t expanded_value) { | |
541 #if WORDS_BIGENDIAN | |
542 ((uint8_t*)data)[3*pos]=expanded_value>>24; | |
543 ((uint8_t*)data)[3*pos+1]=expanded_value>>16; | |
544 ((uint8_t*)data)[3*pos+2]=expanded_value>>8; | |
545 #else | |
546 ((uint8_t*)data)[3*pos]=expanded_value>>8; | |
547 ((uint8_t*)data)[3*pos+1]=expanded_value>>16; | |
548 ((uint8_t*)data)[3*pos+2]=expanded_value>>24; | |
549 #endif | |
550 } | |
551 | |
8167 | 552 // Function implementations used by play |
553 static void endian(void* in, void* out, int len, int bps) | |
554 { | |
555 register int i; | |
556 switch(bps){ | |
557 case(2):{ | |
558 for(i=0;i<len;i++){ | |
12486 | 559 ((uint16_t*)out)[i]=bswap_16(((uint16_t*)in)[i]); |
8167 | 560 } |
561 break; | |
562 } | |
12478 | 563 case(3):{ |
564 register uint8_t s; | |
565 for(i=0;i<len;i++){ | |
566 s=((uint8_t*)in)[3*i]; | |
567 ((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
|
568 if (in != out) |
dbbc25ea6403
fix endian conversion for (curently unused) case where in buffer != out buffer
reimar
parents:
12478
diff
changeset
|
569 ((uint8_t*)out)[3*i+1]=((uint8_t*)in)[3*i+1]; |
12478 | 570 ((uint8_t*)out)[3*i+2]=s; |
571 } | |
572 break; | |
573 } | |
8167 | 574 case(4):{ |
575 for(i=0;i<len;i++){ | |
12486 | 576 ((uint32_t*)out)[i]=bswap_32(((uint32_t*)in)[i]); |
8167 | 577 } |
578 break; | |
579 } | |
580 } | |
581 } | |
582 | |
583 static void si2us(void* in, void* out, int len, int bps) | |
584 { | |
585 register int i; | |
586 switch(bps){ | |
587 case(1): | |
588 for(i=0;i<len;i++) | |
589 ((uint8_t*)out)[i]=(uint8_t)(SCHAR_MAX+((int)((int8_t*)in)[i])); | |
590 break; | |
591 case(2): | |
592 for(i=0;i<len;i++) | |
593 ((uint16_t*)out)[i]=(uint16_t)(SHRT_MAX+((int)((int16_t*)in)[i])); | |
594 break; | |
12478 | 595 case(3): |
596 for(i=0;i<len;i++) | |
597 store24bit(out, i, (uint32_t)(INT_MAX+(int32_t)load24bit(in, i))); | |
598 break; | |
8167 | 599 case(4): |
600 for(i=0;i<len;i++) | |
601 ((uint32_t*)out)[i]=(uint32_t)(INT_MAX+((int32_t*)in)[i]); | |
602 break; | |
603 } | |
604 } | |
605 | |
606 static void us2si(void* in, void* out, int len, int bps) | |
607 { | |
608 register int i; | |
609 switch(bps){ | |
610 case(1): | |
611 for(i=0;i<len;i++) | |
612 ((int8_t*)out)[i]=(int8_t)(SCHAR_MIN+((int)((uint8_t*)in)[i])); | |
613 break; | |
614 case(2): | |
615 for(i=0;i<len;i++) | |
616 ((int16_t*)out)[i]=(int16_t)(SHRT_MIN+((int)((uint16_t*)in)[i])); | |
617 break; | |
12478 | 618 case(3): |
619 for(i=0;i<len;i++) | |
620 store24bit(out, i, (int32_t)(INT_MIN+(uint32_t)load24bit(in, i))); | |
621 break; | |
8167 | 622 case(4): |
623 for(i=0;i<len;i++) | |
624 ((int32_t*)out)[i]=(int32_t)(INT_MIN+((uint32_t*)in)[i]); | |
625 break; | |
626 } | |
627 } | |
628 | |
629 static void change_bps(void* in, void* out, int len, int inbps, int outbps) | |
630 { | |
631 register int i; | |
632 switch(inbps){ | |
633 case(1): | |
634 switch(outbps){ | |
635 case(2): | |
636 for(i=0;i<len;i++) | |
637 ((uint16_t*)out)[i]=((uint16_t)((uint8_t*)in)[i])<<8; | |
638 break; | |
12478 | 639 case(3): |
640 for(i=0;i<len;i++) | |
641 store24bit(out, i, ((uint32_t)((uint8_t*)in)[i])<<24); | |
642 break; | |
8167 | 643 case(4): |
644 for(i=0;i<len;i++) | |
645 ((uint32_t*)out)[i]=((uint32_t)((uint8_t*)in)[i])<<24; | |
646 break; | |
647 } | |
648 break; | |
649 case(2): | |
650 switch(outbps){ | |
651 case(1): | |
652 for(i=0;i<len;i++) | |
653 ((uint8_t*)out)[i]=(uint8_t)((((uint16_t*)in)[i])>>8); | |
654 break; | |
12478 | 655 case(3): |
656 for(i=0;i<len;i++) | |
657 store24bit(out, i, ((uint32_t)((uint16_t*)in)[i])<<16); | |
658 break; | |
8167 | 659 case(4): |
660 for(i=0;i<len;i++) | |
661 ((uint32_t*)out)[i]=((uint32_t)((uint16_t*)in)[i])<<16; | |
662 break; | |
663 } | |
664 break; | |
12478 | 665 case(3): |
666 switch(outbps){ | |
667 case(1): | |
668 for(i=0;i<len;i++) | |
669 ((uint8_t*)out)[i]=(uint8_t)(load24bit(in, i)>>24); | |
670 break; | |
671 case(2): | |
672 for(i=0;i<len;i++) | |
673 ((uint16_t*)out)[i]=(uint16_t)(load24bit(in, i)>>16); | |
674 break; | |
675 case(4): | |
676 for(i=0;i<len;i++) | |
677 ((uint32_t*)out)[i]=(uint32_t)load24bit(in, i); | |
678 break; | |
679 } | |
680 break; | |
8167 | 681 case(4): |
682 switch(outbps){ | |
683 case(1): | |
684 for(i=0;i<len;i++) | |
685 ((uint8_t*)out)[i]=(uint8_t)((((uint32_t*)in)[i])>>24); | |
686 break; | |
687 case(2): | |
688 for(i=0;i<len;i++) | |
689 ((uint16_t*)out)[i]=(uint16_t)((((uint32_t*)in)[i])>>16); | |
690 break; | |
12478 | 691 case(3): |
692 for(i=0;i<len;i++) | |
693 store24bit(out, i, ((uint32_t*)in)[i]); | |
694 break; | |
8167 | 695 } |
696 break; | |
697 } | |
698 } | |
699 | |
700 static void float2int(void* in, void* out, int len, int bps) | |
701 { | |
702 register int i; | |
703 switch(bps){ | |
704 case(1): | |
705 for(i=0;i<len;i++) | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
706 ((int8_t*)out)[i]=(int8_t)lrintf(SCHAR_MAX*((float*)in)[i]); |
8167 | 707 break; |
708 case(2): | |
709 for(i=0;i<len;i++) | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
710 ((int16_t*)out)[i]=(int16_t)lrintf(SHRT_MAX*((float*)in)[i]); |
8167 | 711 break; |
12478 | 712 case(3): |
713 for(i=0;i<len;i++) | |
714 store24bit(out, i, (int32_t)lrintf(INT_MAX*((float*)in)[i])); | |
715 break; | |
8167 | 716 case(4): |
717 for(i=0;i<len;i++) | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
718 ((int32_t*)out)[i]=(int32_t)lrintf(INT_MAX*((float*)in)[i]); |
8167 | 719 break; |
720 } | |
721 } | |
722 | |
723 static void int2float(void* in, void* out, int len, int bps) | |
724 { | |
725 register int i; | |
726 switch(bps){ | |
727 case(1): | |
728 for(i=0;i<len;i++) | |
729 ((float*)out)[i]=(1.0/SCHAR_MAX)*((float)((int8_t*)in)[i]); | |
730 break; | |
731 case(2): | |
732 for(i=0;i<len;i++) | |
733 ((float*)out)[i]=(1.0/SHRT_MAX)*((float)((int16_t*)in)[i]); | |
734 break; | |
12478 | 735 case(3): |
736 for(i=0;i<len;i++) | |
737 ((float*)out)[i]=(1.0/INT_MAX)*((float)((int32_t)load24bit(in, i))); | |
738 break; | |
8167 | 739 case(4): |
740 for(i=0;i<len;i++) | |
741 ((float*)out)[i]=(1.0/INT_MAX)*((float)((int32_t*)in)[i]); | |
742 break; | |
743 } | |
744 } |