src/audio/SDL_audiocvt.c
changeset 2014 7abe37467fa5
parent 1985 8055185ae4ed
child 2042 3908e1f808e1
     1.1 --- a/src/audio/SDL_audiocvt.c	Fri Sep 01 19:17:05 2006 +0000
     1.2 +++ b/src/audio/SDL_audiocvt.c	Fri Sep 01 19:29:49 2006 +0000
     1.3 @@ -187,35 +187,25 @@
     1.4  
     1.5      case AUDIO_F32:
     1.6          {
     1.7 -            /* !!! FIXME: this convert union is nasty. */
     1.8 -            union
     1.9 -            {
    1.10 -                float f;
    1.11 -                Uint32 ui32;
    1.12 -            } f2i;
    1.13 -            const Uint32 *src = (const Uint32 *) cvt->buf;
    1.14 -            Uint32 *dst = (Uint32 *) cvt->buf;
    1.15 +            const float *src = (const float *) cvt->buf;
    1.16 +            float *dst = (float *) cvt->buf;
    1.17              if (SDL_AUDIO_ISBIGENDIAN(format)) {
    1.18                  for (i = cvt->len_cvt / 8; i; --i, src += 2) {
    1.19                      float src1, src2;
    1.20 -                    f2i.ui32 = SDL_SwapBE32(src[0]);
    1.21 -                    src1 = f2i.f;
    1.22 -                    f2i.ui32 = SDL_SwapBE32(src[1]);
    1.23 -                    src2 = f2i.f;
    1.24 +                    src1 = SDL_SwapFloatBE(src[0]);
    1.25 +                    src2 = SDL_SwapFloatBE(src[1]);
    1.26                      const double added = ((double) src1) + ((double) src2);
    1.27 -                    f2i.f = (float) (added * 0.5);
    1.28 -                    *(dst++) = SDL_SwapBE32(f2i.ui32);
    1.29 +                    src1 = (float) (added * 0.5);
    1.30 +                    *(dst++) = SDL_SwapFloatBE(src1);
    1.31                  }
    1.32              } else {
    1.33                  for (i = cvt->len_cvt / 8; i; --i, src += 2) {
    1.34                      float src1, src2;
    1.35 -                    f2i.ui32 = SDL_SwapLE32(src[0]);
    1.36 -                    src1 = f2i.f;
    1.37 -                    f2i.ui32 = SDL_SwapLE32(src[1]);
    1.38 -                    src2 = f2i.f;
    1.39 +                    src1 = SDL_SwapFloatLE(src[0]);
    1.40 +                    src2 = SDL_SwapFloatLE(src[1]);
    1.41                      const double added = ((double) src1) + ((double) src2);
    1.42 -                    f2i.f = (float) (added * 0.5);
    1.43 -                    *(dst++) = SDL_SwapLE32(f2i.ui32);
    1.44 +                    src1 = (float) (added * 0.5);
    1.45 +                    *(dst++) = SDL_SwapFloatLE(src1);
    1.46                  }
    1.47              }
    1.48          }
    1.49 @@ -577,54 +567,35 @@
    1.50  
    1.51      case AUDIO_F32:
    1.52          {
    1.53 -            union
    1.54 -            {
    1.55 -                float f;
    1.56 -                Uint32 ui32;
    1.57 -            } f2i;              /* !!! FIXME: lame. */
    1.58              float lf, rf, ce;
    1.59 -            const Uint32 *src = (const Uint32 *) cvt->buf + cvt->len_cvt;
    1.60 -            Uint32 *dst = (Uint32 *) cvt->buf + cvt->len_cvt * 3;
    1.61 +            const float *src = (const float *) cvt->buf + cvt->len_cvt;
    1.62 +            float *dst = (float *) cvt->buf + cvt->len_cvt * 3;
    1.63  
    1.64              if (SDL_AUDIO_ISBIGENDIAN(format)) {
    1.65                  for (i = cvt->len_cvt / 8; i; --i) {
    1.66                      dst -= 6;
    1.67                      src -= 2;
    1.68 -                    f2i.ui32 = SDL_SwapBE32(src[0]);
    1.69 -                    lf = f2i.f;
    1.70 -                    f2i.ui32 = SDL_SwapBE32(src[1]);
    1.71 -                    rf = f2i.f;
    1.72 +                    lf = SDL_SwapFloatBE(src[0]);
    1.73 +                    rf = SDL_SwapFloatBE(src[1]);
    1.74                      ce = (lf * 0.5f) + (rf * 0.5f);
    1.75                      dst[0] = src[0];
    1.76                      dst[1] = src[1];
    1.77 -                    f2i.f = (lf - ce);
    1.78 -                    dst[2] = SDL_SwapBE32(f2i.ui32);
    1.79 -                    f2i.f = (rf - ce);
    1.80 -                    dst[3] = SDL_SwapBE32(f2i.ui32);
    1.81 -                    f2i.f = ce;
    1.82 -                    f2i.ui32 = SDL_SwapBE32(f2i.ui32);
    1.83 -                    dst[4] = f2i.ui32;
    1.84 -                    dst[5] = f2i.ui32;
    1.85 +                    dst[2] = SDL_SwapFloatBE(lf - ce);
    1.86 +                    dst[3] = SDL_SwapFloatBE(rf - ce);
    1.87 +                    dst[4] = dst[5] = SDL_SwapFloatBE(ce);
    1.88                  }
    1.89              } else {
    1.90                  for (i = cvt->len_cvt / 8; i; --i) {
    1.91                      dst -= 6;
    1.92                      src -= 2;
    1.93 -                    f2i.ui32 = SDL_SwapLE32(src[0]);
    1.94 -                    lf = f2i.f;
    1.95 -                    f2i.ui32 = SDL_SwapLE32(src[1]);
    1.96 -                    rf = f2i.f;
    1.97 +                    lf = SDL_SwapFloatLE(src[0]);
    1.98 +                    rf = SDL_SwapFloatLE(src[1]);
    1.99                      ce = (lf * 0.5f) + (rf * 0.5f);
   1.100                      dst[0] = src[0];
   1.101                      dst[1] = src[1];
   1.102 -                    f2i.f = (lf - ce);
   1.103 -                    dst[2] = SDL_SwapLE32(f2i.ui32);
   1.104 -                    f2i.f = (rf - ce);
   1.105 -                    dst[3] = SDL_SwapLE32(f2i.ui32);
   1.106 -                    f2i.f = ce;
   1.107 -                    f2i.ui32 = SDL_SwapLE32(f2i.ui32);
   1.108 -                    dst[4] = f2i.ui32;
   1.109 -                    dst[5] = f2i.ui32;
   1.110 +                    dst[2] = SDL_SwapFloatLE(lf - ce);
   1.111 +                    dst[3] = SDL_SwapFloatLE(rf - ce);
   1.112 +                    dst[4] = dst[5] = SDL_SwapFloatLE(ce);
   1.113                  }
   1.114              }
   1.115          }