Mercurial > sdl-ios-xcode
comparison src/audio/SDL_audiocvt.c @ 1985:8055185ae4ed
Added source color and alpha modulation support.
Added perl script to generate optimized render copy functions.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 28 Aug 2006 03:17:39 +0000 |
parents | 3b4ce57c6215 |
children | 7abe37467fa5 |
comparison
equal
deleted
inserted
replaced
1984:b910bcabec26 | 1985:8055185ae4ed |
---|---|
34 Sint32 sample; | 34 Sint32 sample; |
35 | 35 |
36 #ifdef DEBUG_CONVERT | 36 #ifdef DEBUG_CONVERT |
37 fprintf(stderr, "Converting to mono\n"); | 37 fprintf(stderr, "Converting to mono\n"); |
38 #endif | 38 #endif |
39 switch (format & (SDL_AUDIO_MASK_SIGNED|SDL_AUDIO_MASK_BITSIZE)) { | 39 switch (format & (SDL_AUDIO_MASK_SIGNED | SDL_AUDIO_MASK_BITSIZE)) { |
40 case AUDIO_U8: | 40 case AUDIO_U8: |
41 { | 41 { |
42 Uint8 *src, *dst; | 42 Uint8 *src, *dst; |
43 | 43 |
44 src = cvt->buf; | 44 src = cvt->buf; |
168 const Uint32 *src = (const Uint32 *) cvt->buf; | 168 const Uint32 *src = (const Uint32 *) cvt->buf; |
169 Uint32 *dst = (Uint32 *) cvt->buf; | 169 Uint32 *dst = (Uint32 *) cvt->buf; |
170 if (SDL_AUDIO_ISBIGENDIAN(format)) { | 170 if (SDL_AUDIO_ISBIGENDIAN(format)) { |
171 for (i = cvt->len_cvt / 8; i; --i, src += 2) { | 171 for (i = cvt->len_cvt / 8; i; --i, src += 2) { |
172 const Sint64 added = | 172 const Sint64 added = |
173 (((Sint64) (Sint32) SDL_SwapBE32(src[0])) + | 173 (((Sint64) (Sint32) SDL_SwapBE32(src[0])) + |
174 ((Sint64) (Sint32) SDL_SwapBE32(src[1]))); | 174 ((Sint64) (Sint32) SDL_SwapBE32(src[1]))); |
175 *(dst++) = SDL_SwapBE32((Uint32) ((Sint32) (added >> 1))); | 175 *(dst++) = SDL_SwapBE32((Uint32) ((Sint32) (added >> 1))); |
176 } | 176 } |
177 } else { | 177 } else { |
178 for (i = cvt->len_cvt / 8; i; --i, src += 2) { | 178 for (i = cvt->len_cvt / 8; i; --i, src += 2) { |
179 const Sint64 added = | 179 const Sint64 added = |
180 (((Sint64) (Sint32) SDL_SwapLE32(src[0])) + | 180 (((Sint64) (Sint32) SDL_SwapLE32(src[0])) + |
181 ((Sint64) (Sint32) SDL_SwapLE32(src[1]))); | 181 ((Sint64) (Sint32) SDL_SwapLE32(src[1]))); |
182 *(dst++) = SDL_SwapLE32((Uint32) ((Sint32) (added >> 1))); | 182 *(dst++) = SDL_SwapLE32((Uint32) ((Sint32) (added >> 1))); |
183 } | 183 } |
184 } | 184 } |
185 } | 185 } |
186 break; | 186 break; |
187 | 187 |
188 case AUDIO_F32: | 188 case AUDIO_F32: |
189 { | 189 { |
190 /* !!! FIXME: this convert union is nasty. */ | 190 /* !!! FIXME: this convert union is nasty. */ |
191 union { float f; Uint32 ui32; } f2i; | 191 union |
192 { | |
193 float f; | |
194 Uint32 ui32; | |
195 } f2i; | |
192 const Uint32 *src = (const Uint32 *) cvt->buf; | 196 const Uint32 *src = (const Uint32 *) cvt->buf; |
193 Uint32 *dst = (Uint32 *) cvt->buf; | 197 Uint32 *dst = (Uint32 *) cvt->buf; |
194 if (SDL_AUDIO_ISBIGENDIAN(format)) { | 198 if (SDL_AUDIO_ISBIGENDIAN(format)) { |
195 for (i = cvt->len_cvt / 8; i; --i, src += 2) { | 199 for (i = cvt->len_cvt / 8; i; --i, src += 2) { |
196 float src1, src2; | 200 float src1, src2; |
233 | 237 |
234 #ifdef DEBUG_CONVERT | 238 #ifdef DEBUG_CONVERT |
235 fprintf(stderr, "Converting down from 6 channels to stereo\n"); | 239 fprintf(stderr, "Converting down from 6 channels to stereo\n"); |
236 #endif | 240 #endif |
237 | 241 |
238 #define strip_chans_6_to_2(type) \ | 242 #define strip_chans_6_to_2(type) \ |
239 { \ | 243 { \ |
240 const type *src = (const type *) cvt->buf; \ | 244 const type *src = (const type *) cvt->buf; \ |
241 type *dst = (type *) cvt->buf; \ | 245 type *dst = (type *) cvt->buf; \ |
242 for (i = cvt->len_cvt / (sizeof (type) * 6); i; --i) { \ | 246 for (i = cvt->len_cvt / (sizeof (type) * 6); i; --i) { \ |
243 dst[0] = src[0]; \ | 247 dst[0] = src[0]; \ |
247 } \ | 251 } \ |
248 } | 252 } |
249 | 253 |
250 /* this function only cares about typesize, and data as a block of bits. */ | 254 /* this function only cares about typesize, and data as a block of bits. */ |
251 switch (SDL_AUDIO_BITSIZE(format)) { | 255 switch (SDL_AUDIO_BITSIZE(format)) { |
252 case 8: | 256 case 8: |
253 strip_chans_6_to_2(Uint8); | 257 strip_chans_6_to_2(Uint8); |
254 break; | 258 break; |
255 case 16: | 259 case 16: |
256 strip_chans_6_to_2(Uint16); | 260 strip_chans_6_to_2(Uint16); |
257 break; | 261 break; |
258 case 32: | 262 case 32: |
259 strip_chans_6_to_2(Uint32); | 263 strip_chans_6_to_2(Uint32); |
260 break; | 264 break; |
261 } | 265 } |
262 | 266 |
263 #undef strip_chans_6_to_2 | 267 #undef strip_chans_6_to_2 |
264 | 268 |
265 cvt->len_cvt /= 3; | 269 cvt->len_cvt /= 3; |
266 if (cvt->filters[++cvt->filter_index]) { | 270 if (cvt->filters[++cvt->filter_index]) { |
267 cvt->filters[cvt->filter_index] (cvt, format); | 271 cvt->filters[cvt->filter_index] (cvt, format); |
268 } | 272 } |
277 | 281 |
278 #ifdef DEBUG_CONVERT | 282 #ifdef DEBUG_CONVERT |
279 fprintf(stderr, "Converting 6 down to quad\n"); | 283 fprintf(stderr, "Converting 6 down to quad\n"); |
280 #endif | 284 #endif |
281 | 285 |
282 #define strip_chans_6_to_4(type) \ | 286 #define strip_chans_6_to_4(type) \ |
283 { \ | 287 { \ |
284 const type *src = (const type *) cvt->buf; \ | 288 const type *src = (const type *) cvt->buf; \ |
285 type *dst = (type *) cvt->buf; \ | 289 type *dst = (type *) cvt->buf; \ |
286 for (i = cvt->len_cvt / (sizeof (type) * 6); i; --i) { \ | 290 for (i = cvt->len_cvt / (sizeof (type) * 6); i; --i) { \ |
287 dst[0] = src[0]; \ | 291 dst[0] = src[0]; \ |
293 } \ | 297 } \ |
294 } | 298 } |
295 | 299 |
296 /* this function only cares about typesize, and data as a block of bits. */ | 300 /* this function only cares about typesize, and data as a block of bits. */ |
297 switch (SDL_AUDIO_BITSIZE(format)) { | 301 switch (SDL_AUDIO_BITSIZE(format)) { |
298 case 8: | 302 case 8: |
299 strip_chans_6_to_4(Uint8); | 303 strip_chans_6_to_4(Uint8); |
300 break; | 304 break; |
301 case 16: | 305 case 16: |
302 strip_chans_6_to_4(Uint16); | 306 strip_chans_6_to_4(Uint16); |
303 break; | 307 break; |
304 case 32: | 308 case 32: |
305 strip_chans_6_to_4(Uint32); | 309 strip_chans_6_to_4(Uint32); |
306 break; | 310 break; |
307 } | 311 } |
308 | 312 |
309 #undef strip_chans_6_to_4 | 313 #undef strip_chans_6_to_4 |
310 | 314 |
311 cvt->len_cvt /= 6; | 315 cvt->len_cvt /= 6; |
312 cvt->len_cvt *= 4; | 316 cvt->len_cvt *= 4; |
313 if (cvt->filters[++cvt->filter_index]) { | 317 if (cvt->filters[++cvt->filter_index]) { |
314 cvt->filters[cvt->filter_index] (cvt, format); | 318 cvt->filters[cvt->filter_index] (cvt, format); |
323 | 327 |
324 #ifdef DEBUG_CONVERT | 328 #ifdef DEBUG_CONVERT |
325 fprintf(stderr, "Converting to stereo\n"); | 329 fprintf(stderr, "Converting to stereo\n"); |
326 #endif | 330 #endif |
327 | 331 |
328 #define dup_chans_1_to_2(type) \ | 332 #define dup_chans_1_to_2(type) \ |
329 { \ | 333 { \ |
330 const type *src = (const type *) (cvt->buf + cvt->len_cvt); \ | 334 const type *src = (const type *) (cvt->buf + cvt->len_cvt); \ |
331 type *dst = (type *) (cvt->buf + cvt->len_cvt * 2); \ | 335 type *dst = (type *) (cvt->buf + cvt->len_cvt * 2); \ |
332 for (i = cvt->len_cvt / 2; i; --i, --src) { \ | 336 for (i = cvt->len_cvt / 2; i; --i, --src) { \ |
333 const type val = *src; \ | 337 const type val = *src; \ |
336 } \ | 340 } \ |
337 } | 341 } |
338 | 342 |
339 /* this function only cares about typesize, and data as a block of bits. */ | 343 /* this function only cares about typesize, and data as a block of bits. */ |
340 switch (SDL_AUDIO_BITSIZE(format)) { | 344 switch (SDL_AUDIO_BITSIZE(format)) { |
341 case 8: | 345 case 8: |
342 dup_chans_1_to_2(Uint8); | 346 dup_chans_1_to_2(Uint8); |
343 break; | 347 break; |
344 case 16: | 348 case 16: |
345 dup_chans_1_to_2(Uint16); | 349 dup_chans_1_to_2(Uint16); |
346 break; | 350 break; |
347 case 32: | 351 case 32: |
348 dup_chans_1_to_2(Uint32); | 352 dup_chans_1_to_2(Uint32); |
349 break; | 353 break; |
350 } | 354 } |
351 | 355 |
352 #undef dup_chans_1_to_2 | 356 #undef dup_chans_1_to_2 |
353 | 357 |
354 cvt->len_cvt *= 2; | 358 cvt->len_cvt *= 2; |
355 if (cvt->filters[++cvt->filter_index]) { | 359 if (cvt->filters[++cvt->filter_index]) { |
356 cvt->filters[cvt->filter_index] (cvt, format); | 360 cvt->filters[cvt->filter_index] (cvt, format); |
357 } | 361 } |
366 | 370 |
367 #ifdef DEBUG_CONVERT | 371 #ifdef DEBUG_CONVERT |
368 fprintf(stderr, "Converting stereo to surround\n"); | 372 fprintf(stderr, "Converting stereo to surround\n"); |
369 #endif | 373 #endif |
370 | 374 |
371 switch (format & (SDL_AUDIO_MASK_SIGNED|SDL_AUDIO_MASK_BITSIZE)) { | 375 switch (format & (SDL_AUDIO_MASK_SIGNED | SDL_AUDIO_MASK_BITSIZE)) { |
372 case AUDIO_U8: | 376 case AUDIO_U8: |
373 { | 377 { |
374 Uint8 *src, *dst, lf, rf, ce; | 378 Uint8 *src, *dst, lf, rf, ce; |
375 | 379 |
376 src = (Uint8 *) (cvt->buf + cvt->len_cvt); | 380 src = (Uint8 *) (cvt->buf + cvt->len_cvt); |
571 } | 575 } |
572 break; | 576 break; |
573 | 577 |
574 case AUDIO_F32: | 578 case AUDIO_F32: |
575 { | 579 { |
576 union { float f; Uint32 ui32; } f2i; /* !!! FIXME: lame. */ | 580 union |
581 { | |
582 float f; | |
583 Uint32 ui32; | |
584 } f2i; /* !!! FIXME: lame. */ | |
577 float lf, rf, ce; | 585 float lf, rf, ce; |
578 const Uint32 *src = (const Uint32 *) cvt->buf + cvt->len_cvt; | 586 const Uint32 *src = (const Uint32 *) cvt->buf + cvt->len_cvt; |
579 Uint32 *dst = (Uint32 *) cvt->buf + cvt->len_cvt * 3; | 587 Uint32 *dst = (Uint32 *) cvt->buf + cvt->len_cvt * 3; |
580 | 588 |
581 if (SDL_AUDIO_ISBIGENDIAN(format)) { | 589 if (SDL_AUDIO_ISBIGENDIAN(format)) { |
638 | 646 |
639 #ifdef DEBUG_CONVERT | 647 #ifdef DEBUG_CONVERT |
640 fprintf(stderr, "Converting stereo to quad\n"); | 648 fprintf(stderr, "Converting stereo to quad\n"); |
641 #endif | 649 #endif |
642 | 650 |
643 switch (format & (SDL_AUDIO_MASK_SIGNED|SDL_AUDIO_MASK_BITSIZE)) { | 651 switch (format & (SDL_AUDIO_MASK_SIGNED | SDL_AUDIO_MASK_BITSIZE)) { |
644 case AUDIO_U8: | 652 case AUDIO_U8: |
645 { | 653 { |
646 Uint8 *src, *dst, lf, rf, ce; | 654 Uint8 *src, *dst, lf, rf, ce; |
647 | 655 |
648 src = (Uint8 *) (cvt->buf + cvt->len_cvt); | 656 src = (Uint8 *) (cvt->buf + cvt->len_cvt); |
829 | 837 |
830 #ifdef DEBUG_CONVERT | 838 #ifdef DEBUG_CONVERT |
831 fprintf(stderr, "Converting audio rate * 2 (mono)\n"); | 839 fprintf(stderr, "Converting audio rate * 2 (mono)\n"); |
832 #endif | 840 #endif |
833 | 841 |
834 #define mul2_mono(type) { \ | 842 #define mul2_mono(type) { \ |
835 const type *src = (const type *) (cvt->buf + cvt->len_cvt); \ | 843 const type *src = (const type *) (cvt->buf + cvt->len_cvt); \ |
836 type *dst = (type *) (cvt->buf + (cvt->len_cvt * 2)); \ | 844 type *dst = (type *) (cvt->buf + (cvt->len_cvt * 2)); \ |
837 for (i = cvt->len_cvt / sizeof (type); i; --i) { \ | 845 for (i = cvt->len_cvt / sizeof (type); i; --i) { \ |
838 src--; \ | 846 src--; \ |
839 dst[-1] = dst[-2] = src[0]; \ | 847 dst[-1] = dst[-2] = src[0]; \ |
851 case 32: | 859 case 32: |
852 mul2_mono(Uint32); | 860 mul2_mono(Uint32); |
853 break; | 861 break; |
854 } | 862 } |
855 | 863 |
856 #undef mul2_mono | 864 #undef mul2_mono |
857 | 865 |
858 cvt->len_cvt *= 2; | 866 cvt->len_cvt *= 2; |
859 if (cvt->filters[++cvt->filter_index]) { | 867 if (cvt->filters[++cvt->filter_index]) { |
860 cvt->filters[cvt->filter_index] (cvt, format); | 868 cvt->filters[cvt->filter_index] (cvt, format); |
861 } | 869 } |
870 | 878 |
871 #ifdef DEBUG_CONVERT | 879 #ifdef DEBUG_CONVERT |
872 fprintf(stderr, "Converting audio rate * 2 (stereo)\n"); | 880 fprintf(stderr, "Converting audio rate * 2 (stereo)\n"); |
873 #endif | 881 #endif |
874 | 882 |
875 #define mul2_stereo(type) { \ | 883 #define mul2_stereo(type) { \ |
876 const type *src = (const type *) (cvt->buf + cvt->len_cvt); \ | 884 const type *src = (const type *) (cvt->buf + cvt->len_cvt); \ |
877 type *dst = (type *) (cvt->buf + (cvt->len_cvt * 2)); \ | 885 type *dst = (type *) (cvt->buf + (cvt->len_cvt * 2)); \ |
878 for (i = cvt->len_cvt / (sizeof (type) * 2); i; --i) { \ | 886 for (i = cvt->len_cvt / (sizeof (type) * 2); i; --i) { \ |
879 const type r = src[-1]; \ | 887 const type r = src[-1]; \ |
880 const type l = src[-2]; \ | 888 const type l = src[-2]; \ |
897 case 32: | 905 case 32: |
898 mul2_stereo(Uint32); | 906 mul2_stereo(Uint32); |
899 break; | 907 break; |
900 } | 908 } |
901 | 909 |
902 #undef mul2_stereo | 910 #undef mul2_stereo |
903 | 911 |
904 cvt->len_cvt *= 2; | 912 cvt->len_cvt *= 2; |
905 if (cvt->filters[++cvt->filter_index]) { | 913 if (cvt->filters[++cvt->filter_index]) { |
906 cvt->filters[cvt->filter_index] (cvt, format); | 914 cvt->filters[cvt->filter_index] (cvt, format); |
907 } | 915 } |
915 | 923 |
916 #ifdef DEBUG_CONVERT | 924 #ifdef DEBUG_CONVERT |
917 fprintf(stderr, "Converting audio rate * 2 (quad)\n"); | 925 fprintf(stderr, "Converting audio rate * 2 (quad)\n"); |
918 #endif | 926 #endif |
919 | 927 |
920 #define mul2_quad(type) { \ | 928 #define mul2_quad(type) { \ |
921 const type *src = (const type *) (cvt->buf + cvt->len_cvt); \ | 929 const type *src = (const type *) (cvt->buf + cvt->len_cvt); \ |
922 type *dst = (type *) (cvt->buf + (cvt->len_cvt * 2)); \ | 930 type *dst = (type *) (cvt->buf + (cvt->len_cvt * 2)); \ |
923 for (i = cvt->len_cvt / (sizeof (type) * 4); i; --i) { \ | 931 for (i = cvt->len_cvt / (sizeof (type) * 4); i; --i) { \ |
924 const type c1 = src[-1]; \ | 932 const type c1 = src[-1]; \ |
925 const type c2 = src[-2]; \ | 933 const type c2 = src[-2]; \ |
948 case 32: | 956 case 32: |
949 mul2_quad(Uint32); | 957 mul2_quad(Uint32); |
950 break; | 958 break; |
951 } | 959 } |
952 | 960 |
953 #undef mul2_quad | 961 #undef mul2_quad |
954 | 962 |
955 cvt->len_cvt *= 2; | 963 cvt->len_cvt *= 2; |
956 if (cvt->filters[++cvt->filter_index]) { | 964 if (cvt->filters[++cvt->filter_index]) { |
957 cvt->filters[cvt->filter_index] (cvt, format); | 965 cvt->filters[cvt->filter_index] (cvt, format); |
958 } | 966 } |
967 | 975 |
968 #ifdef DEBUG_CONVERT | 976 #ifdef DEBUG_CONVERT |
969 fprintf(stderr, "Converting audio rate * 2 (six channels)\n"); | 977 fprintf(stderr, "Converting audio rate * 2 (six channels)\n"); |
970 #endif | 978 #endif |
971 | 979 |
972 #define mul2_chansix(type) { \ | 980 #define mul2_chansix(type) { \ |
973 const type *src = (const type *) (cvt->buf + cvt->len_cvt); \ | 981 const type *src = (const type *) (cvt->buf + cvt->len_cvt); \ |
974 type *dst = (type *) (cvt->buf + (cvt->len_cvt * 2)); \ | 982 type *dst = (type *) (cvt->buf + (cvt->len_cvt * 2)); \ |
975 for (i = cvt->len_cvt / (sizeof (type) * 6); i; --i) { \ | 983 for (i = cvt->len_cvt / (sizeof (type) * 6); i; --i) { \ |
976 const type c1 = src[-1]; \ | 984 const type c1 = src[-1]; \ |
977 const type c2 = src[-2]; \ | 985 const type c2 = src[-2]; \ |
1006 case 32: | 1014 case 32: |
1007 mul2_chansix(Uint32); | 1015 mul2_chansix(Uint32); |
1008 break; | 1016 break; |
1009 } | 1017 } |
1010 | 1018 |
1011 #undef mul2_chansix | 1019 #undef mul2_chansix |
1012 | 1020 |
1013 cvt->len_cvt *= 2; | 1021 cvt->len_cvt *= 2; |
1014 if (cvt->filters[++cvt->filter_index]) { | 1022 if (cvt->filters[++cvt->filter_index]) { |
1015 cvt->filters[cvt->filter_index] (cvt, format); | 1023 cvt->filters[cvt->filter_index] (cvt, format); |
1016 } | 1024 } |
1024 | 1032 |
1025 #ifdef DEBUG_CONVERT | 1033 #ifdef DEBUG_CONVERT |
1026 fprintf(stderr, "Converting audio rate / 2 (mono)\n"); | 1034 fprintf(stderr, "Converting audio rate / 2 (mono)\n"); |
1027 #endif | 1035 #endif |
1028 | 1036 |
1029 #define div2_mono(type) { \ | 1037 #define div2_mono(type) { \ |
1030 const type *src = (const type *) cvt->buf; \ | 1038 const type *src = (const type *) cvt->buf; \ |
1031 type *dst = (type *) cvt->buf; \ | 1039 type *dst = (type *) cvt->buf; \ |
1032 for (i = cvt->len_cvt / (sizeof (type) * 2); i; --i) { \ | 1040 for (i = cvt->len_cvt / (sizeof (type) * 2); i; --i) { \ |
1033 dst[0] = src[0]; \ | 1041 dst[0] = src[0]; \ |
1034 src += 2; \ | 1042 src += 2; \ |
1046 case 32: | 1054 case 32: |
1047 div2_mono(Uint32); | 1055 div2_mono(Uint32); |
1048 break; | 1056 break; |
1049 } | 1057 } |
1050 | 1058 |
1051 #undef div2_mono | 1059 #undef div2_mono |
1052 | 1060 |
1053 cvt->len_cvt /= 2; | 1061 cvt->len_cvt /= 2; |
1054 if (cvt->filters[++cvt->filter_index]) { | 1062 if (cvt->filters[++cvt->filter_index]) { |
1055 cvt->filters[cvt->filter_index] (cvt, format); | 1063 cvt->filters[cvt->filter_index] (cvt, format); |
1056 } | 1064 } |
1065 | 1073 |
1066 #ifdef DEBUG_CONVERT | 1074 #ifdef DEBUG_CONVERT |
1067 fprintf(stderr, "Converting audio rate / 2 (stereo)\n"); | 1075 fprintf(stderr, "Converting audio rate / 2 (stereo)\n"); |
1068 #endif | 1076 #endif |
1069 | 1077 |
1070 #define div2_stereo(type) { \ | 1078 #define div2_stereo(type) { \ |
1071 const type *src = (const type *) cvt->buf; \ | 1079 const type *src = (const type *) cvt->buf; \ |
1072 type *dst = (type *) cvt->buf; \ | 1080 type *dst = (type *) cvt->buf; \ |
1073 for (i = cvt->len_cvt / (sizeof (type) * 4); i; --i) { \ | 1081 for (i = cvt->len_cvt / (sizeof (type) * 4); i; --i) { \ |
1074 dst[0] = src[0]; \ | 1082 dst[0] = src[0]; \ |
1075 dst[1] = src[1]; \ | 1083 dst[1] = src[1]; \ |
1088 case 32: | 1096 case 32: |
1089 div2_stereo(Uint32); | 1097 div2_stereo(Uint32); |
1090 break; | 1098 break; |
1091 } | 1099 } |
1092 | 1100 |
1093 #undef div2_stereo | 1101 #undef div2_stereo |
1094 | 1102 |
1095 cvt->len_cvt /= 2; | 1103 cvt->len_cvt /= 2; |
1096 if (cvt->filters[++cvt->filter_index]) { | 1104 if (cvt->filters[++cvt->filter_index]) { |
1097 cvt->filters[cvt->filter_index] (cvt, format); | 1105 cvt->filters[cvt->filter_index] (cvt, format); |
1098 } | 1106 } |
1107 | 1115 |
1108 #ifdef DEBUG_CONVERT | 1116 #ifdef DEBUG_CONVERT |
1109 fprintf(stderr, "Converting audio rate / 2 (quad)\n"); | 1117 fprintf(stderr, "Converting audio rate / 2 (quad)\n"); |
1110 #endif | 1118 #endif |
1111 | 1119 |
1112 #define div2_quad(type) { \ | 1120 #define div2_quad(type) { \ |
1113 const type *src = (const type *) cvt->buf; \ | 1121 const type *src = (const type *) cvt->buf; \ |
1114 type *dst = (type *) cvt->buf; \ | 1122 type *dst = (type *) cvt->buf; \ |
1115 for (i = cvt->len_cvt / (sizeof (type) * 8); i; --i) { \ | 1123 for (i = cvt->len_cvt / (sizeof (type) * 8); i; --i) { \ |
1116 dst[0] = src[0]; \ | 1124 dst[0] = src[0]; \ |
1117 dst[1] = src[1]; \ | 1125 dst[1] = src[1]; \ |
1132 case 32: | 1140 case 32: |
1133 div2_quad(Uint32); | 1141 div2_quad(Uint32); |
1134 break; | 1142 break; |
1135 } | 1143 } |
1136 | 1144 |
1137 #undef div2_quad | 1145 #undef div2_quad |
1138 | 1146 |
1139 cvt->len_cvt /= 2; | 1147 cvt->len_cvt /= 2; |
1140 if (cvt->filters[++cvt->filter_index]) { | 1148 if (cvt->filters[++cvt->filter_index]) { |
1141 cvt->filters[cvt->filter_index] (cvt, format); | 1149 cvt->filters[cvt->filter_index] (cvt, format); |
1142 } | 1150 } |
1150 | 1158 |
1151 #ifdef DEBUG_CONVERT | 1159 #ifdef DEBUG_CONVERT |
1152 fprintf(stderr, "Converting audio rate / 2 (six channels)\n"); | 1160 fprintf(stderr, "Converting audio rate / 2 (six channels)\n"); |
1153 #endif | 1161 #endif |
1154 | 1162 |
1155 #define div2_chansix(type) { \ | 1163 #define div2_chansix(type) { \ |
1156 const type *src = (const type *) cvt->buf; \ | 1164 const type *src = (const type *) cvt->buf; \ |
1157 type *dst = (type *) cvt->buf; \ | 1165 type *dst = (type *) cvt->buf; \ |
1158 for (i = cvt->len_cvt / (sizeof (type) * 12); i; --i) { \ | 1166 for (i = cvt->len_cvt / (sizeof (type) * 12); i; --i) { \ |
1159 dst[0] = src[0]; \ | 1167 dst[0] = src[0]; \ |
1160 dst[1] = src[1]; \ | 1168 dst[1] = src[1]; \ |
1177 case 32: | 1185 case 32: |
1178 div2_chansix(Uint32); | 1186 div2_chansix(Uint32); |
1179 break; | 1187 break; |
1180 } | 1188 } |
1181 | 1189 |
1182 #undef div_chansix | 1190 #undef div_chansix |
1183 | 1191 |
1184 cvt->len_cvt /= 2; | 1192 cvt->len_cvt /= 2; |
1185 if (cvt->filters[++cvt->filter_index]) { | 1193 if (cvt->filters[++cvt->filter_index]) { |
1186 cvt->filters[cvt->filter_index] (cvt, format); | 1194 cvt->filters[cvt->filter_index] (cvt, format); |
1187 } | 1195 } |
1307 /* | 1315 /* |
1308 * Fill in any future conversions that are specialized to a | 1316 * Fill in any future conversions that are specialized to a |
1309 * processor, platform, compiler, or library here. | 1317 * processor, platform, compiler, or library here. |
1310 */ | 1318 */ |
1311 | 1319 |
1312 return NULL; /* no specialized converter code available. */ | 1320 return NULL; /* no specialized converter code available. */ |
1313 } | 1321 } |
1314 | 1322 |
1315 | 1323 |
1316 /* | 1324 /* |
1317 * Find a converter between two data types. We try to select a hand-tuned | 1325 * Find a converter between two data types. We try to select a hand-tuned |
1338 break; | 1346 break; |
1339 } | 1347 } |
1340 } | 1348 } |
1341 | 1349 |
1342 if (filter == NULL) { | 1350 if (filter == NULL) { |
1343 return -1; /* Still no matching converter?! */ | 1351 return -1; /* Still no matching converter?! */ |
1344 } | 1352 } |
1345 } | 1353 } |
1346 | 1354 |
1347 /* Update (cvt) with filter details... */ | 1355 /* Update (cvt) with filter details... */ |
1348 cvt->filters[cvt->filter_index++] = filter; | 1356 cvt->filters[cvt->filter_index++] = filter; |
1352 cvt->len_ratio *= mult; | 1360 cvt->len_ratio *= mult; |
1353 } else if (src_bitsize > dst_bitsize) { | 1361 } else if (src_bitsize > dst_bitsize) { |
1354 cvt->len_ratio /= (src_bitsize / dst_bitsize); | 1362 cvt->len_ratio /= (src_bitsize / dst_bitsize); |
1355 } | 1363 } |
1356 | 1364 |
1357 return 1; /* added a converter. */ | 1365 return 1; /* added a converter. */ |
1358 } | 1366 } |
1359 | 1367 |
1360 return 0; /* no conversion necessary. */ | 1368 return 0; /* no conversion necessary. */ |
1361 } | 1369 } |
1362 | 1370 |
1363 | 1371 |
1364 | 1372 |
1365 /* Creates a set of audio filters to convert from one format to another. | 1373 /* Creates a set of audio filters to convert from one format to another. |
1377 return -1; | 1385 return -1; |
1378 } | 1386 } |
1379 if ((SDL_AUDIO_BITSIZE(dst_fmt) > 16) && (!SDL_AUDIO_ISSIGNED(dst_fmt))) { | 1387 if ((SDL_AUDIO_BITSIZE(dst_fmt) > 16) && (!SDL_AUDIO_ISSIGNED(dst_fmt))) { |
1380 return -1; | 1388 return -1; |
1381 } | 1389 } |
1382 | 1390 #ifdef DEBUG_CONVERT |
1383 #ifdef DEBUG_CONVERT | |
1384 printf("Build format %04x->%04x, channels %u->%u, rate %d->%d\n", | 1391 printf("Build format %04x->%04x, channels %u->%u, rate %d->%d\n", |
1385 src_fmt, dst_fmt, src_channels, dst_channels, src_rate, dst_rate); | 1392 src_fmt, dst_fmt, src_channels, dst_channels, src_rate, dst_rate); |
1386 #endif | 1393 #endif |
1387 | 1394 |
1388 /* Start off with no conversion necessary */ | 1395 /* Start off with no conversion necessary */ |
1389 | 1396 |
1390 cvt->src_format = src_fmt; | 1397 cvt->src_format = src_fmt; |
1391 cvt->dst_format = dst_fmt; | 1398 cvt->dst_format = dst_fmt; |
1395 cvt->len_mult = 1; | 1402 cvt->len_mult = 1; |
1396 cvt->len_ratio = 1.0; | 1403 cvt->len_ratio = 1.0; |
1397 | 1404 |
1398 /* Convert data types, if necessary. Updates (cvt). */ | 1405 /* Convert data types, if necessary. Updates (cvt). */ |
1399 if (SDL_BuildAudioTypeCVT(cvt, src_fmt, dst_fmt) == -1) | 1406 if (SDL_BuildAudioTypeCVT(cvt, src_fmt, dst_fmt) == -1) |
1400 return -1; /* shouldn't happen, but just in case... */ | 1407 return -1; /* shouldn't happen, but just in case... */ |
1401 | 1408 |
1402 /* Channel conversion */ | 1409 /* Channel conversion */ |
1403 if (src_channels != dst_channels) { | 1410 if (src_channels != dst_channels) { |
1404 if ((src_channels == 1) && (dst_channels > 1)) { | 1411 if ((src_channels == 1) && (dst_channels > 1)) { |
1405 cvt->filters[cvt->filter_index++] = SDL_ConvertStereo; | 1412 cvt->filters[cvt->filter_index++] = SDL_ConvertStereo; |