Mercurial > mplayer.hg
annotate libaf/af_format.c @ 14424:b3ab8fa3c3f5
synced to 1.22
author | gabrov |
---|---|
date | Sat, 08 Jan 2005 00:40:30 +0000 |
parents | 1a882e2a419b |
children | 95bb94a930a3 |
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; | |
14272 | 309 |
310 af->play = play; // set default | |
311 | |
312 // look whether only endianess differences are there | |
313 if ((af->data->format & ~AF_FORMAT_END_MASK) == | |
314 (data->format & ~AF_FORMAT_END_MASK)) | |
315 { | |
316 af_msg(AF_MSG_VERBOSE,"[format] Accelerated endianess conversion only\n"); | |
317 af->play = play_swapendian; | |
318 } | |
319 if ((data->format == AF_FORMAT_FLOAT_NE) && | |
320 (af->data->format == AF_FORMAT_S16_NE)) | |
321 { | |
14399
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
322 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
|
323 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
|
324 af_fmt2str(af->data->format,buf2,256)); |
14272 | 325 af->play = play_float_s16; |
326 } | |
327 if ((data->format == AF_FORMAT_S16_NE) && | |
328 (af->data->format == AF_FORMAT_FLOAT_NE)) | |
329 { | |
14399
1a882e2a419b
af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents:
14335
diff
changeset
|
330 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
|
331 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
|
332 af_fmt2str(af->data->format,buf2,256)); |
14272 | 333 af->play = play_s16_float; |
334 } | |
7568 | 335 return AF_OK; |
8167 | 336 } |
7998
d48a06d07afb
Adding commandline options for filters and fixing stupid bug in cfg
anders
parents:
7719
diff
changeset
|
337 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
|
338 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
|
339 if(AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET,&format)) |
8607 | 340 return AF_ERROR; |
341 return AF_OK; | |
8167 | 342 } |
14335
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
343 case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET:{ |
8607 | 344 // Check for errors in configuraton |
345 if(AF_OK != check_format(*(int*)arg)) | |
346 return AF_ERROR; | |
347 | |
348 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
|
349 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
|
350 |
7568 | 351 return AF_OK; |
352 } | |
14335
8380694ba14f
af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents:
14272
diff
changeset
|
353 } |
7568 | 354 return AF_UNKNOWN; |
355 } | |
356 | |
357 // Deallocate memory | |
358 static void uninit(struct af_instance_s* af) | |
359 { | |
360 if(af->data) | |
361 free(af->data); | |
12386 | 362 af->setup = 0; |
7568 | 363 } |
364 | |
14272 | 365 static af_data_t* play_swapendian(struct af_instance_s* af, af_data_t* data) |
366 { | |
367 af_data_t* l = af->data; // Local data | |
368 af_data_t* c = data; // Current working data | |
369 int len = c->len/c->bps; // Lenght in samples of current audio block | |
370 | |
371 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) | |
372 return NULL; | |
373 | |
374 endian(c->audio,l->audio,len,c->bps); | |
375 | |
376 c->audio = l->audio; | |
377 c->format = l->format; | |
378 | |
379 return c; | |
380 } | |
381 | |
382 static af_data_t* play_float_s16(struct af_instance_s* af, af_data_t* data) | |
383 { | |
384 af_data_t* l = af->data; // Local data | |
385 af_data_t* c = data; // Current working data | |
386 int len = c->len/4; // Lenght in samples of current audio block | |
387 | |
388 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) | |
389 return NULL; | |
390 | |
391 float2int(c->audio, l->audio, len, 2); | |
392 | |
393 c->audio = l->audio; | |
394 c->len = len*2; | |
395 c->bps = 2; | |
396 c->format = l->format; | |
397 | |
398 return c; | |
399 } | |
400 | |
401 static af_data_t* play_s16_float(struct af_instance_s* af, af_data_t* data) | |
402 { | |
403 af_data_t* l = af->data; // Local data | |
404 af_data_t* c = data; // Current working data | |
405 int len = c->len/2; // Lenght in samples of current audio block | |
406 | |
407 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) | |
408 return NULL; | |
409 | |
410 int2float(c->audio, l->audio, len, 2); | |
411 | |
412 c->audio = l->audio; | |
413 c->len = len*4; | |
414 c->bps = 4; | |
415 c->format = l->format; | |
416 | |
417 return c; | |
418 } | |
419 | |
7568 | 420 // Filter data through filter |
421 static af_data_t* play(struct af_instance_s* af, af_data_t* data) | |
422 { | |
8167 | 423 af_data_t* l = af->data; // Local data |
424 af_data_t* c = data; // Current working data | |
425 int len = c->len/c->bps; // Lenght in samples of current audio block | |
7568 | 426 |
427 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) | |
428 return NULL; | |
429 | |
8167 | 430 // Change to cpu native endian format |
431 if((c->format&AF_FORMAT_END_MASK)!=AF_FORMAT_NE) | |
432 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
|
433 |
8167 | 434 // Conversion table |
14261
710b223604fa
100l use right mask type when checking for input format
rtognimp
parents:
14256
diff
changeset
|
435 if((c->format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_MU_LAW) { |
8167 | 436 from_ulaw(c->audio, l->audio, len, l->bps, l->format&AF_FORMAT_POINT_MASK); |
437 if(AF_FORMAT_A_LAW == (l->format&AF_FORMAT_SPECIAL_MASK)) | |
438 to_ulaw(l->audio, l->audio, len, 1, AF_FORMAT_SI); | |
439 if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US) | |
440 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
|
441 } else if((c->format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_A_LAW) { |
8167 | 442 from_alaw(c->audio, l->audio, len, l->bps, l->format&AF_FORMAT_POINT_MASK); |
443 if(AF_FORMAT_A_LAW == (l->format&AF_FORMAT_SPECIAL_MASK)) | |
444 to_alaw(l->audio, l->audio, len, 1, AF_FORMAT_SI); | |
445 if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US) | |
446 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
|
447 } else if((c->format & AF_FORMAT_POINT_MASK) == AF_FORMAT_F) { |
8167 | 448 switch(l->format&AF_FORMAT_SPECIAL_MASK){ |
449 case(AF_FORMAT_MU_LAW): | |
450 to_ulaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK); | |
451 break; | |
452 case(AF_FORMAT_A_LAW): | |
453 to_alaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK); | |
7568 | 454 break; |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
455 default: |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
456 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
|
457 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
|
458 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
|
459 break; |
8167 | 460 } |
14261
710b223604fa
100l use right mask type when checking for input format
rtognimp
parents:
14256
diff
changeset
|
461 } else { |
8167 | 462 // Input must be int |
463 | |
464 // Change signed/unsigned | |
465 if((c->format&AF_FORMAT_SIGN_MASK) != (l->format&AF_FORMAT_SIGN_MASK)){ | |
466 if((c->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US) | |
467 us2si(c->audio,c->audio,len,c->bps); | |
468 else | |
469 si2us(c->audio,c->audio,len,c->bps); | |
470 } | |
471 // Convert to special formats | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
472 switch(l->format&(AF_FORMAT_SPECIAL_MASK|AF_FORMAT_POINT_MASK)){ |
8167 | 473 case(AF_FORMAT_MU_LAW): |
474 to_ulaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK); | |
475 break; | |
476 case(AF_FORMAT_A_LAW): | |
477 to_alaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK); | |
478 break; | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
479 case(AF_FORMAT_F): |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
480 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
|
481 break; |
8167 | 482 default: |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
483 // Change the number of bits |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
484 if(c->bps != l->bps) |
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
485 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
|
486 else |
8185 | 487 memcpy(l->audio,c->audio,len*c->bps); |
7568 | 488 break; |
489 } | |
490 } | |
7719
41e8d0916c60
Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents:
7711
diff
changeset
|
491 |
41e8d0916c60
Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents:
7711
diff
changeset
|
492 // Switch from cpu native endian to the correct endianess |
8167 | 493 if((l->format&AF_FORMAT_END_MASK)!=AF_FORMAT_NE) |
494 endian(l->audio,l->audio,len,l->bps); | |
7568 | 495 |
496 // Set output data | |
497 c->audio = l->audio; | |
8167 | 498 c->len = len*l->bps; |
7568 | 499 c->bps = l->bps; |
500 c->format = l->format; | |
501 return c; | |
502 } | |
503 | |
504 // Allocate memory and set function pointers | |
505 static int open(af_instance_t* af){ | |
506 af->control=control; | |
507 af->uninit=uninit; | |
508 af->play=play; | |
509 af->mul.n=1; | |
510 af->mul.d=1; | |
511 af->data=calloc(1,sizeof(af_data_t)); | |
512 if(af->data == NULL) | |
513 return AF_ERROR; | |
514 return AF_OK; | |
515 } | |
516 | |
517 // Description of this filter | |
518 af_info_t af_info_format = { | |
519 "Sample format conversion", | |
520 "format", | |
521 "Anders", | |
522 "", | |
7615 | 523 AF_FLAGS_REENTRANT, |
7568 | 524 open |
525 }; | |
8167 | 526 |
12478 | 527 static inline uint32_t load24bit(void* data, int pos) { |
528 #if WORDS_BIGENDIAN | |
529 return (((uint32_t)((uint8_t*)data)[3*pos])<<24) | | |
530 (((uint32_t)((uint8_t*)data)[3*pos+1])<<16) | | |
531 (((uint32_t)((uint8_t*)data)[3*pos+2])<<8); | |
532 #else | |
533 return (((uint32_t)((uint8_t*)data)[3*pos])<<8) | | |
534 (((uint32_t)((uint8_t*)data)[3*pos+1])<<16) | | |
535 (((uint32_t)((uint8_t*)data)[3*pos+2])<<24); | |
536 #endif | |
537 } | |
538 | |
539 static inline void store24bit(void* data, int pos, uint32_t expanded_value) { | |
540 #if WORDS_BIGENDIAN | |
541 ((uint8_t*)data)[3*pos]=expanded_value>>24; | |
542 ((uint8_t*)data)[3*pos+1]=expanded_value>>16; | |
543 ((uint8_t*)data)[3*pos+2]=expanded_value>>8; | |
544 #else | |
545 ((uint8_t*)data)[3*pos]=expanded_value>>8; | |
546 ((uint8_t*)data)[3*pos+1]=expanded_value>>16; | |
547 ((uint8_t*)data)[3*pos+2]=expanded_value>>24; | |
548 #endif | |
549 } | |
550 | |
8167 | 551 // Function implementations used by play |
552 static void endian(void* in, void* out, int len, int bps) | |
553 { | |
554 register int i; | |
555 switch(bps){ | |
556 case(2):{ | |
557 for(i=0;i<len;i++){ | |
12486 | 558 ((uint16_t*)out)[i]=bswap_16(((uint16_t*)in)[i]); |
8167 | 559 } |
560 break; | |
561 } | |
12478 | 562 case(3):{ |
563 register uint8_t s; | |
564 for(i=0;i<len;i++){ | |
565 s=((uint8_t*)in)[3*i]; | |
566 ((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
|
567 if (in != out) |
dbbc25ea6403
fix endian conversion for (curently unused) case where in buffer != out buffer
reimar
parents:
12478
diff
changeset
|
568 ((uint8_t*)out)[3*i+1]=((uint8_t*)in)[3*i+1]; |
12478 | 569 ((uint8_t*)out)[3*i+2]=s; |
570 } | |
571 break; | |
572 } | |
8167 | 573 case(4):{ |
574 for(i=0;i<len;i++){ | |
12486 | 575 ((uint32_t*)out)[i]=bswap_32(((uint32_t*)in)[i]); |
8167 | 576 } |
577 break; | |
578 } | |
579 } | |
580 } | |
581 | |
582 static void si2us(void* in, void* out, int len, int bps) | |
583 { | |
584 register int i; | |
585 switch(bps){ | |
586 case(1): | |
587 for(i=0;i<len;i++) | |
588 ((uint8_t*)out)[i]=(uint8_t)(SCHAR_MAX+((int)((int8_t*)in)[i])); | |
589 break; | |
590 case(2): | |
591 for(i=0;i<len;i++) | |
592 ((uint16_t*)out)[i]=(uint16_t)(SHRT_MAX+((int)((int16_t*)in)[i])); | |
593 break; | |
12478 | 594 case(3): |
595 for(i=0;i<len;i++) | |
596 store24bit(out, i, (uint32_t)(INT_MAX+(int32_t)load24bit(in, i))); | |
597 break; | |
8167 | 598 case(4): |
599 for(i=0;i<len;i++) | |
600 ((uint32_t*)out)[i]=(uint32_t)(INT_MAX+((int32_t*)in)[i]); | |
601 break; | |
602 } | |
603 } | |
604 | |
605 static void us2si(void* in, void* out, int len, int bps) | |
606 { | |
607 register int i; | |
608 switch(bps){ | |
609 case(1): | |
610 for(i=0;i<len;i++) | |
611 ((int8_t*)out)[i]=(int8_t)(SCHAR_MIN+((int)((uint8_t*)in)[i])); | |
612 break; | |
613 case(2): | |
614 for(i=0;i<len;i++) | |
615 ((int16_t*)out)[i]=(int16_t)(SHRT_MIN+((int)((uint16_t*)in)[i])); | |
616 break; | |
12478 | 617 case(3): |
618 for(i=0;i<len;i++) | |
619 store24bit(out, i, (int32_t)(INT_MIN+(uint32_t)load24bit(in, i))); | |
620 break; | |
8167 | 621 case(4): |
622 for(i=0;i<len;i++) | |
623 ((int32_t*)out)[i]=(int32_t)(INT_MIN+((uint32_t*)in)[i]); | |
624 break; | |
625 } | |
626 } | |
627 | |
628 static void change_bps(void* in, void* out, int len, int inbps, int outbps) | |
629 { | |
630 register int i; | |
631 switch(inbps){ | |
632 case(1): | |
633 switch(outbps){ | |
634 case(2): | |
635 for(i=0;i<len;i++) | |
636 ((uint16_t*)out)[i]=((uint16_t)((uint8_t*)in)[i])<<8; | |
637 break; | |
12478 | 638 case(3): |
639 for(i=0;i<len;i++) | |
640 store24bit(out, i, ((uint32_t)((uint8_t*)in)[i])<<24); | |
641 break; | |
8167 | 642 case(4): |
643 for(i=0;i<len;i++) | |
644 ((uint32_t*)out)[i]=((uint32_t)((uint8_t*)in)[i])<<24; | |
645 break; | |
646 } | |
647 break; | |
648 case(2): | |
649 switch(outbps){ | |
650 case(1): | |
651 for(i=0;i<len;i++) | |
652 ((uint8_t*)out)[i]=(uint8_t)((((uint16_t*)in)[i])>>8); | |
653 break; | |
12478 | 654 case(3): |
655 for(i=0;i<len;i++) | |
656 store24bit(out, i, ((uint32_t)((uint16_t*)in)[i])<<16); | |
657 break; | |
8167 | 658 case(4): |
659 for(i=0;i<len;i++) | |
660 ((uint32_t*)out)[i]=((uint32_t)((uint16_t*)in)[i])<<16; | |
661 break; | |
662 } | |
663 break; | |
12478 | 664 case(3): |
665 switch(outbps){ | |
666 case(1): | |
667 for(i=0;i<len;i++) | |
668 ((uint8_t*)out)[i]=(uint8_t)(load24bit(in, i)>>24); | |
669 break; | |
670 case(2): | |
671 for(i=0;i<len;i++) | |
672 ((uint16_t*)out)[i]=(uint16_t)(load24bit(in, i)>>16); | |
673 break; | |
674 case(4): | |
675 for(i=0;i<len;i++) | |
676 ((uint32_t*)out)[i]=(uint32_t)load24bit(in, i); | |
677 break; | |
678 } | |
679 break; | |
8167 | 680 case(4): |
681 switch(outbps){ | |
682 case(1): | |
683 for(i=0;i<len;i++) | |
684 ((uint8_t*)out)[i]=(uint8_t)((((uint32_t*)in)[i])>>24); | |
685 break; | |
686 case(2): | |
687 for(i=0;i<len;i++) | |
688 ((uint16_t*)out)[i]=(uint16_t)((((uint32_t*)in)[i])>>16); | |
689 break; | |
12478 | 690 case(3): |
691 for(i=0;i<len;i++) | |
692 store24bit(out, i, ((uint32_t*)in)[i]); | |
693 break; | |
8167 | 694 } |
695 break; | |
696 } | |
697 } | |
698 | |
699 static void float2int(void* in, void* out, int len, int bps) | |
700 { | |
701 register int i; | |
702 switch(bps){ | |
703 case(1): | |
704 for(i=0;i<len;i++) | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
705 ((int8_t*)out)[i]=(int8_t)lrintf(SCHAR_MAX*((float*)in)[i]); |
8167 | 706 break; |
707 case(2): | |
708 for(i=0;i<len;i++) | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
709 ((int16_t*)out)[i]=(int16_t)lrintf(SHRT_MAX*((float*)in)[i]); |
8167 | 710 break; |
12478 | 711 case(3): |
712 for(i=0;i<len;i++) | |
713 store24bit(out, i, (int32_t)lrintf(INT_MAX*((float*)in)[i])); | |
714 break; | |
8167 | 715 case(4): |
716 for(i=0;i<len;i++) | |
8180
4ba9aed295f2
Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents:
8167
diff
changeset
|
717 ((int32_t*)out)[i]=(int32_t)lrintf(INT_MAX*((float*)in)[i]); |
8167 | 718 break; |
719 } | |
720 } | |
721 | |
722 static void int2float(void* in, void* out, int len, int bps) | |
723 { | |
724 register int i; | |
725 switch(bps){ | |
726 case(1): | |
727 for(i=0;i<len;i++) | |
728 ((float*)out)[i]=(1.0/SCHAR_MAX)*((float)((int8_t*)in)[i]); | |
729 break; | |
730 case(2): | |
731 for(i=0;i<len;i++) | |
732 ((float*)out)[i]=(1.0/SHRT_MAX)*((float)((int16_t*)in)[i]); | |
733 break; | |
12478 | 734 case(3): |
735 for(i=0;i<len;i++) | |
736 ((float*)out)[i]=(1.0/INT_MAX)*((float)((int32_t)load24bit(in, i))); | |
737 break; | |
8167 | 738 case(4): |
739 for(i=0;i<len;i++) | |
740 ((float*)out)[i]=(1.0/INT_MAX)*((float)((int32_t*)in)[i]); | |
741 break; | |
742 } | |
743 } |