src/audio/SDL_audiocvt.c
changeset 1985 8055185ae4ed
parent 1982 3b4ce57c6215
child 2014 7abe37467fa5
     1.1 --- a/src/audio/SDL_audiocvt.c	Thu Aug 24 12:49:59 2006 +0000
     1.2 +++ b/src/audio/SDL_audiocvt.c	Mon Aug 28 03:17:39 2006 +0000
     1.3 @@ -36,7 +36,7 @@
     1.4  #ifdef DEBUG_CONVERT
     1.5      fprintf(stderr, "Converting to mono\n");
     1.6  #endif
     1.7 -    switch (format & (SDL_AUDIO_MASK_SIGNED|SDL_AUDIO_MASK_BITSIZE)) {
     1.8 +    switch (format & (SDL_AUDIO_MASK_SIGNED | SDL_AUDIO_MASK_BITSIZE)) {
     1.9      case AUDIO_U8:
    1.10          {
    1.11              Uint8 *src, *dst;
    1.12 @@ -170,15 +170,15 @@
    1.13              if (SDL_AUDIO_ISBIGENDIAN(format)) {
    1.14                  for (i = cvt->len_cvt / 8; i; --i, src += 2) {
    1.15                      const Sint64 added =
    1.16 -                                    (((Sint64) (Sint32) SDL_SwapBE32(src[0])) +
    1.17 -                                     ((Sint64) (Sint32) SDL_SwapBE32(src[1])));
    1.18 +                        (((Sint64) (Sint32) SDL_SwapBE32(src[0])) +
    1.19 +                         ((Sint64) (Sint32) SDL_SwapBE32(src[1])));
    1.20                      *(dst++) = SDL_SwapBE32((Uint32) ((Sint32) (added >> 1)));
    1.21                  }
    1.22              } else {
    1.23                  for (i = cvt->len_cvt / 8; i; --i, src += 2) {
    1.24                      const Sint64 added =
    1.25 -                                    (((Sint64) (Sint32) SDL_SwapLE32(src[0])) +
    1.26 -                                     ((Sint64) (Sint32) SDL_SwapLE32(src[1])));
    1.27 +                        (((Sint64) (Sint32) SDL_SwapLE32(src[0])) +
    1.28 +                         ((Sint64) (Sint32) SDL_SwapLE32(src[1])));
    1.29                      *(dst++) = SDL_SwapLE32((Uint32) ((Sint32) (added >> 1)));
    1.30                  }
    1.31              }
    1.32 @@ -188,7 +188,11 @@
    1.33      case AUDIO_F32:
    1.34          {
    1.35              /* !!! FIXME: this convert union is nasty. */
    1.36 -            union { float f; Uint32 ui32; } f2i;
    1.37 +            union
    1.38 +            {
    1.39 +                float f;
    1.40 +                Uint32 ui32;
    1.41 +            } f2i;
    1.42              const Uint32 *src = (const Uint32 *) cvt->buf;
    1.43              Uint32 *dst = (Uint32 *) cvt->buf;
    1.44              if (SDL_AUDIO_ISBIGENDIAN(format)) {
    1.45 @@ -235,7 +239,7 @@
    1.46      fprintf(stderr, "Converting down from 6 channels to stereo\n");
    1.47  #endif
    1.48  
    1.49 -    #define strip_chans_6_to_2(type) \
    1.50 +#define strip_chans_6_to_2(type) \
    1.51      { \
    1.52          const type *src = (const type *) cvt->buf; \
    1.53          type *dst = (type *) cvt->buf; \
    1.54 @@ -249,18 +253,18 @@
    1.55  
    1.56      /* this function only cares about typesize, and data as a block of bits. */
    1.57      switch (SDL_AUDIO_BITSIZE(format)) {
    1.58 -        case 8:
    1.59 -            strip_chans_6_to_2(Uint8);
    1.60 -            break;
    1.61 -        case 16:
    1.62 -            strip_chans_6_to_2(Uint16);
    1.63 -            break;
    1.64 -        case 32:
    1.65 -            strip_chans_6_to_2(Uint32);
    1.66 -            break;
    1.67 +    case 8:
    1.68 +        strip_chans_6_to_2(Uint8);
    1.69 +        break;
    1.70 +    case 16:
    1.71 +        strip_chans_6_to_2(Uint16);
    1.72 +        break;
    1.73 +    case 32:
    1.74 +        strip_chans_6_to_2(Uint32);
    1.75 +        break;
    1.76      }
    1.77  
    1.78 -    #undef strip_chans_6_to_2
    1.79 +#undef strip_chans_6_to_2
    1.80  
    1.81      cvt->len_cvt /= 3;
    1.82      if (cvt->filters[++cvt->filter_index]) {
    1.83 @@ -279,7 +283,7 @@
    1.84      fprintf(stderr, "Converting 6 down to quad\n");
    1.85  #endif
    1.86  
    1.87 -    #define strip_chans_6_to_4(type) \
    1.88 +#define strip_chans_6_to_4(type) \
    1.89      { \
    1.90          const type *src = (const type *) cvt->buf; \
    1.91          type *dst = (type *) cvt->buf; \
    1.92 @@ -295,18 +299,18 @@
    1.93  
    1.94      /* this function only cares about typesize, and data as a block of bits. */
    1.95      switch (SDL_AUDIO_BITSIZE(format)) {
    1.96 -        case 8:
    1.97 -            strip_chans_6_to_4(Uint8);
    1.98 -            break;
    1.99 -        case 16:
   1.100 -            strip_chans_6_to_4(Uint16);
   1.101 -            break;
   1.102 -        case 32:
   1.103 -            strip_chans_6_to_4(Uint32);
   1.104 -            break;
   1.105 +    case 8:
   1.106 +        strip_chans_6_to_4(Uint8);
   1.107 +        break;
   1.108 +    case 16:
   1.109 +        strip_chans_6_to_4(Uint16);
   1.110 +        break;
   1.111 +    case 32:
   1.112 +        strip_chans_6_to_4(Uint32);
   1.113 +        break;
   1.114      }
   1.115  
   1.116 -    #undef strip_chans_6_to_4
   1.117 +#undef strip_chans_6_to_4
   1.118  
   1.119      cvt->len_cvt /= 6;
   1.120      cvt->len_cvt *= 4;
   1.121 @@ -325,7 +329,7 @@
   1.122      fprintf(stderr, "Converting to stereo\n");
   1.123  #endif
   1.124  
   1.125 -    #define dup_chans_1_to_2(type) \
   1.126 +#define dup_chans_1_to_2(type) \
   1.127      { \
   1.128          const type *src = (const type *) (cvt->buf + cvt->len_cvt); \
   1.129          type *dst = (type *) (cvt->buf + cvt->len_cvt * 2); \
   1.130 @@ -338,18 +342,18 @@
   1.131  
   1.132      /* this function only cares about typesize, and data as a block of bits. */
   1.133      switch (SDL_AUDIO_BITSIZE(format)) {
   1.134 -        case 8:
   1.135 -            dup_chans_1_to_2(Uint8);
   1.136 -            break;
   1.137 -        case 16:
   1.138 -            dup_chans_1_to_2(Uint16);
   1.139 -            break;
   1.140 -        case 32:
   1.141 -            dup_chans_1_to_2(Uint32);
   1.142 -            break;
   1.143 +    case 8:
   1.144 +        dup_chans_1_to_2(Uint8);
   1.145 +        break;
   1.146 +    case 16:
   1.147 +        dup_chans_1_to_2(Uint16);
   1.148 +        break;
   1.149 +    case 32:
   1.150 +        dup_chans_1_to_2(Uint32);
   1.151 +        break;
   1.152      }
   1.153  
   1.154 -    #undef dup_chans_1_to_2
   1.155 +#undef dup_chans_1_to_2
   1.156  
   1.157      cvt->len_cvt *= 2;
   1.158      if (cvt->filters[++cvt->filter_index]) {
   1.159 @@ -368,7 +372,7 @@
   1.160      fprintf(stderr, "Converting stereo to surround\n");
   1.161  #endif
   1.162  
   1.163 -    switch (format & (SDL_AUDIO_MASK_SIGNED|SDL_AUDIO_MASK_BITSIZE)) {
   1.164 +    switch (format & (SDL_AUDIO_MASK_SIGNED | SDL_AUDIO_MASK_BITSIZE)) {
   1.165      case AUDIO_U8:
   1.166          {
   1.167              Uint8 *src, *dst, lf, rf, ce;
   1.168 @@ -573,7 +577,11 @@
   1.169  
   1.170      case AUDIO_F32:
   1.171          {
   1.172 -            union { float f; Uint32 ui32; } f2i;  /* !!! FIXME: lame. */
   1.173 +            union
   1.174 +            {
   1.175 +                float f;
   1.176 +                Uint32 ui32;
   1.177 +            } f2i;              /* !!! FIXME: lame. */
   1.178              float lf, rf, ce;
   1.179              const Uint32 *src = (const Uint32 *) cvt->buf + cvt->len_cvt;
   1.180              Uint32 *dst = (Uint32 *) cvt->buf + cvt->len_cvt * 3;
   1.181 @@ -640,7 +648,7 @@
   1.182      fprintf(stderr, "Converting stereo to quad\n");
   1.183  #endif
   1.184  
   1.185 -    switch (format & (SDL_AUDIO_MASK_SIGNED|SDL_AUDIO_MASK_BITSIZE)) {
   1.186 +    switch (format & (SDL_AUDIO_MASK_SIGNED | SDL_AUDIO_MASK_BITSIZE)) {
   1.187      case AUDIO_U8:
   1.188          {
   1.189              Uint8 *src, *dst, lf, rf, ce;
   1.190 @@ -831,7 +839,7 @@
   1.191      fprintf(stderr, "Converting audio rate * 2 (mono)\n");
   1.192  #endif
   1.193  
   1.194 -    #define mul2_mono(type) { \
   1.195 +#define mul2_mono(type) { \
   1.196          const type *src = (const type *) (cvt->buf + cvt->len_cvt); \
   1.197          type *dst = (type *) (cvt->buf + (cvt->len_cvt * 2)); \
   1.198          for (i = cvt->len_cvt / sizeof (type); i; --i) { \
   1.199 @@ -853,7 +861,7 @@
   1.200          break;
   1.201      }
   1.202  
   1.203 -    #undef mul2_mono
   1.204 +#undef mul2_mono
   1.205  
   1.206      cvt->len_cvt *= 2;
   1.207      if (cvt->filters[++cvt->filter_index]) {
   1.208 @@ -872,7 +880,7 @@
   1.209      fprintf(stderr, "Converting audio rate * 2 (stereo)\n");
   1.210  #endif
   1.211  
   1.212 -    #define mul2_stereo(type) { \
   1.213 +#define mul2_stereo(type) { \
   1.214          const type *src = (const type *) (cvt->buf + cvt->len_cvt); \
   1.215          type *dst = (type *) (cvt->buf + (cvt->len_cvt * 2)); \
   1.216          for (i = cvt->len_cvt / (sizeof (type) * 2); i; --i) { \
   1.217 @@ -899,7 +907,7 @@
   1.218          break;
   1.219      }
   1.220  
   1.221 -    #undef mul2_stereo
   1.222 +#undef mul2_stereo
   1.223  
   1.224      cvt->len_cvt *= 2;
   1.225      if (cvt->filters[++cvt->filter_index]) {
   1.226 @@ -917,7 +925,7 @@
   1.227      fprintf(stderr, "Converting audio rate * 2 (quad)\n");
   1.228  #endif
   1.229  
   1.230 -    #define mul2_quad(type) { \
   1.231 +#define mul2_quad(type) { \
   1.232          const type *src = (const type *) (cvt->buf + cvt->len_cvt); \
   1.233          type *dst = (type *) (cvt->buf + (cvt->len_cvt * 2)); \
   1.234          for (i = cvt->len_cvt / (sizeof (type) * 4); i; --i) { \
   1.235 @@ -950,7 +958,7 @@
   1.236          break;
   1.237      }
   1.238  
   1.239 -    #undef mul2_quad
   1.240 +#undef mul2_quad
   1.241  
   1.242      cvt->len_cvt *= 2;
   1.243      if (cvt->filters[++cvt->filter_index]) {
   1.244 @@ -969,7 +977,7 @@
   1.245      fprintf(stderr, "Converting audio rate * 2 (six channels)\n");
   1.246  #endif
   1.247  
   1.248 -    #define mul2_chansix(type) { \
   1.249 +#define mul2_chansix(type) { \
   1.250          const type *src = (const type *) (cvt->buf + cvt->len_cvt); \
   1.251          type *dst = (type *) (cvt->buf + (cvt->len_cvt * 2)); \
   1.252          for (i = cvt->len_cvt / (sizeof (type) * 6); i; --i) { \
   1.253 @@ -1008,7 +1016,7 @@
   1.254          break;
   1.255      }
   1.256  
   1.257 -    #undef mul2_chansix
   1.258 +#undef mul2_chansix
   1.259  
   1.260      cvt->len_cvt *= 2;
   1.261      if (cvt->filters[++cvt->filter_index]) {
   1.262 @@ -1026,7 +1034,7 @@
   1.263      fprintf(stderr, "Converting audio rate / 2 (mono)\n");
   1.264  #endif
   1.265  
   1.266 -    #define div2_mono(type) { \
   1.267 +#define div2_mono(type) { \
   1.268          const type *src = (const type *) cvt->buf; \
   1.269          type *dst = (type *) cvt->buf; \
   1.270          for (i = cvt->len_cvt / (sizeof (type) * 2); i; --i) { \
   1.271 @@ -1048,7 +1056,7 @@
   1.272          break;
   1.273      }
   1.274  
   1.275 -    #undef div2_mono
   1.276 +#undef div2_mono
   1.277  
   1.278      cvt->len_cvt /= 2;
   1.279      if (cvt->filters[++cvt->filter_index]) {
   1.280 @@ -1067,7 +1075,7 @@
   1.281      fprintf(stderr, "Converting audio rate / 2 (stereo)\n");
   1.282  #endif
   1.283  
   1.284 -    #define div2_stereo(type) { \
   1.285 +#define div2_stereo(type) { \
   1.286          const type *src = (const type *) cvt->buf; \
   1.287          type *dst = (type *) cvt->buf; \
   1.288          for (i = cvt->len_cvt / (sizeof (type) * 4); i; --i) { \
   1.289 @@ -1090,7 +1098,7 @@
   1.290          break;
   1.291      }
   1.292  
   1.293 -    #undef div2_stereo
   1.294 +#undef div2_stereo
   1.295  
   1.296      cvt->len_cvt /= 2;
   1.297      if (cvt->filters[++cvt->filter_index]) {
   1.298 @@ -1109,7 +1117,7 @@
   1.299      fprintf(stderr, "Converting audio rate / 2 (quad)\n");
   1.300  #endif
   1.301  
   1.302 -    #define div2_quad(type) { \
   1.303 +#define div2_quad(type) { \
   1.304          const type *src = (const type *) cvt->buf; \
   1.305          type *dst = (type *) cvt->buf; \
   1.306          for (i = cvt->len_cvt / (sizeof (type) * 8); i; --i) { \
   1.307 @@ -1134,7 +1142,7 @@
   1.308          break;
   1.309      }
   1.310  
   1.311 -    #undef div2_quad
   1.312 +#undef div2_quad
   1.313  
   1.314      cvt->len_cvt /= 2;
   1.315      if (cvt->filters[++cvt->filter_index]) {
   1.316 @@ -1152,7 +1160,7 @@
   1.317      fprintf(stderr, "Converting audio rate / 2 (six channels)\n");
   1.318  #endif
   1.319  
   1.320 -    #define div2_chansix(type) { \
   1.321 +#define div2_chansix(type) { \
   1.322          const type *src = (const type *) cvt->buf; \
   1.323          type *dst = (type *) cvt->buf; \
   1.324          for (i = cvt->len_cvt / (sizeof (type) * 12); i; --i) { \
   1.325 @@ -1179,7 +1187,7 @@
   1.326          break;
   1.327      }
   1.328  
   1.329 -    #undef div_chansix
   1.330 +#undef div_chansix
   1.331  
   1.332      cvt->len_cvt /= 2;
   1.333      if (cvt->filters[++cvt->filter_index]) {
   1.334 @@ -1309,7 +1317,7 @@
   1.335       *  processor, platform, compiler, or library here.
   1.336       */
   1.337  
   1.338 -    return NULL;  /* no specialized converter code available. */
   1.339 +    return NULL;                /* no specialized converter code available. */
   1.340  }
   1.341  
   1.342  
   1.343 @@ -1340,7 +1348,7 @@
   1.344              }
   1.345  
   1.346              if (filter == NULL) {
   1.347 -                return -1;  /* Still no matching converter?! */
   1.348 +                return -1;      /* Still no matching converter?! */
   1.349              }
   1.350          }
   1.351  
   1.352 @@ -1354,10 +1362,10 @@
   1.353              cvt->len_ratio /= (src_bitsize / dst_bitsize);
   1.354          }
   1.355  
   1.356 -        return 1;  /* added a converter. */
   1.357 +        return 1;               /* added a converter. */
   1.358      }
   1.359  
   1.360 -    return 0;  /* no conversion necessary. */
   1.361 +    return 0;                   /* no conversion necessary. */
   1.362  }
   1.363  
   1.364  
   1.365 @@ -1379,11 +1387,10 @@
   1.366      if ((SDL_AUDIO_BITSIZE(dst_fmt) > 16) && (!SDL_AUDIO_ISSIGNED(dst_fmt))) {
   1.367          return -1;
   1.368      }
   1.369 -
   1.370 -    #ifdef DEBUG_CONVERT
   1.371 +#ifdef DEBUG_CONVERT
   1.372      printf("Build format %04x->%04x, channels %u->%u, rate %d->%d\n",
   1.373 -		    src_fmt, dst_fmt, src_channels, dst_channels, src_rate, dst_rate);
   1.374 -    #endif
   1.375 +           src_fmt, dst_fmt, src_channels, dst_channels, src_rate, dst_rate);
   1.376 +#endif
   1.377  
   1.378      /* Start off with no conversion necessary */
   1.379  
   1.380 @@ -1397,7 +1404,7 @@
   1.381  
   1.382      /* Convert data types, if necessary. Updates (cvt). */
   1.383      if (SDL_BuildAudioTypeCVT(cvt, src_fmt, dst_fmt) == -1)
   1.384 -        return -1;  /* shouldn't happen, but just in case... */
   1.385 +        return -1;              /* shouldn't happen, but just in case... */
   1.386  
   1.387      /* Channel conversion */
   1.388      if (src_channels != dst_channels) {