Mercurial > sdl-ios-xcode
comparison src/audio/SDL_audiocvt.c @ 2014:7abe37467fa5
Replaced unions with calls to SDL_SwapFloat...
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Fri, 01 Sep 2006 19:29:49 +0000 |
parents | 8055185ae4ed |
children | 3908e1f808e1 |
comparison
equal
deleted
inserted
replaced
2013:0615fa58c0be | 2014:7abe37467fa5 |
---|---|
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 const float *src = (const float *) cvt->buf; |
191 union | 191 float *dst = (float *) cvt->buf; |
192 { | |
193 float f; | |
194 Uint32 ui32; | |
195 } f2i; | |
196 const Uint32 *src = (const Uint32 *) cvt->buf; | |
197 Uint32 *dst = (Uint32 *) cvt->buf; | |
198 if (SDL_AUDIO_ISBIGENDIAN(format)) { | 192 if (SDL_AUDIO_ISBIGENDIAN(format)) { |
199 for (i = cvt->len_cvt / 8; i; --i, src += 2) { | 193 for (i = cvt->len_cvt / 8; i; --i, src += 2) { |
200 float src1, src2; | 194 float src1, src2; |
201 f2i.ui32 = SDL_SwapBE32(src[0]); | 195 src1 = SDL_SwapFloatBE(src[0]); |
202 src1 = f2i.f; | 196 src2 = SDL_SwapFloatBE(src[1]); |
203 f2i.ui32 = SDL_SwapBE32(src[1]); | |
204 src2 = f2i.f; | |
205 const double added = ((double) src1) + ((double) src2); | 197 const double added = ((double) src1) + ((double) src2); |
206 f2i.f = (float) (added * 0.5); | 198 src1 = (float) (added * 0.5); |
207 *(dst++) = SDL_SwapBE32(f2i.ui32); | 199 *(dst++) = SDL_SwapFloatBE(src1); |
208 } | 200 } |
209 } else { | 201 } else { |
210 for (i = cvt->len_cvt / 8; i; --i, src += 2) { | 202 for (i = cvt->len_cvt / 8; i; --i, src += 2) { |
211 float src1, src2; | 203 float src1, src2; |
212 f2i.ui32 = SDL_SwapLE32(src[0]); | 204 src1 = SDL_SwapFloatLE(src[0]); |
213 src1 = f2i.f; | 205 src2 = SDL_SwapFloatLE(src[1]); |
214 f2i.ui32 = SDL_SwapLE32(src[1]); | |
215 src2 = f2i.f; | |
216 const double added = ((double) src1) + ((double) src2); | 206 const double added = ((double) src1) + ((double) src2); |
217 f2i.f = (float) (added * 0.5); | 207 src1 = (float) (added * 0.5); |
218 *(dst++) = SDL_SwapLE32(f2i.ui32); | 208 *(dst++) = SDL_SwapFloatLE(src1); |
219 } | 209 } |
220 } | 210 } |
221 } | 211 } |
222 break; | 212 break; |
223 } | 213 } |
575 } | 565 } |
576 break; | 566 break; |
577 | 567 |
578 case AUDIO_F32: | 568 case AUDIO_F32: |
579 { | 569 { |
580 union | |
581 { | |
582 float f; | |
583 Uint32 ui32; | |
584 } f2i; /* !!! FIXME: lame. */ | |
585 float lf, rf, ce; | 570 float lf, rf, ce; |
586 const Uint32 *src = (const Uint32 *) cvt->buf + cvt->len_cvt; | 571 const float *src = (const float *) cvt->buf + cvt->len_cvt; |
587 Uint32 *dst = (Uint32 *) cvt->buf + cvt->len_cvt * 3; | 572 float *dst = (float *) cvt->buf + cvt->len_cvt * 3; |
588 | 573 |
589 if (SDL_AUDIO_ISBIGENDIAN(format)) { | 574 if (SDL_AUDIO_ISBIGENDIAN(format)) { |
590 for (i = cvt->len_cvt / 8; i; --i) { | 575 for (i = cvt->len_cvt / 8; i; --i) { |
591 dst -= 6; | 576 dst -= 6; |
592 src -= 2; | 577 src -= 2; |
593 f2i.ui32 = SDL_SwapBE32(src[0]); | 578 lf = SDL_SwapFloatBE(src[0]); |
594 lf = f2i.f; | 579 rf = SDL_SwapFloatBE(src[1]); |
595 f2i.ui32 = SDL_SwapBE32(src[1]); | |
596 rf = f2i.f; | |
597 ce = (lf * 0.5f) + (rf * 0.5f); | 580 ce = (lf * 0.5f) + (rf * 0.5f); |
598 dst[0] = src[0]; | 581 dst[0] = src[0]; |
599 dst[1] = src[1]; | 582 dst[1] = src[1]; |
600 f2i.f = (lf - ce); | 583 dst[2] = SDL_SwapFloatBE(lf - ce); |
601 dst[2] = SDL_SwapBE32(f2i.ui32); | 584 dst[3] = SDL_SwapFloatBE(rf - ce); |
602 f2i.f = (rf - ce); | 585 dst[4] = dst[5] = SDL_SwapFloatBE(ce); |
603 dst[3] = SDL_SwapBE32(f2i.ui32); | |
604 f2i.f = ce; | |
605 f2i.ui32 = SDL_SwapBE32(f2i.ui32); | |
606 dst[4] = f2i.ui32; | |
607 dst[5] = f2i.ui32; | |
608 } | 586 } |
609 } else { | 587 } else { |
610 for (i = cvt->len_cvt / 8; i; --i) { | 588 for (i = cvt->len_cvt / 8; i; --i) { |
611 dst -= 6; | 589 dst -= 6; |
612 src -= 2; | 590 src -= 2; |
613 f2i.ui32 = SDL_SwapLE32(src[0]); | 591 lf = SDL_SwapFloatLE(src[0]); |
614 lf = f2i.f; | 592 rf = SDL_SwapFloatLE(src[1]); |
615 f2i.ui32 = SDL_SwapLE32(src[1]); | |
616 rf = f2i.f; | |
617 ce = (lf * 0.5f) + (rf * 0.5f); | 593 ce = (lf * 0.5f) + (rf * 0.5f); |
618 dst[0] = src[0]; | 594 dst[0] = src[0]; |
619 dst[1] = src[1]; | 595 dst[1] = src[1]; |
620 f2i.f = (lf - ce); | 596 dst[2] = SDL_SwapFloatLE(lf - ce); |
621 dst[2] = SDL_SwapLE32(f2i.ui32); | 597 dst[3] = SDL_SwapFloatLE(rf - ce); |
622 f2i.f = (rf - ce); | 598 dst[4] = dst[5] = SDL_SwapFloatLE(ce); |
623 dst[3] = SDL_SwapLE32(f2i.ui32); | |
624 f2i.f = ce; | |
625 f2i.ui32 = SDL_SwapLE32(f2i.ui32); | |
626 dst[4] = f2i.ui32; | |
627 dst[5] = f2i.ui32; | |
628 } | 599 } |
629 } | 600 } |
630 } | 601 } |
631 break; | 602 break; |
632 | 603 |