src/audio/SDL_audiotypecvt.c
changeset 10575 bb99dede0675
parent 9998 f67cf37e9cd4
child 10608 8661c956c368
equal deleted inserted replaced
<
10574:3cc0fe7f98d7 10575:bb99dede0675
     1 /* DO NOT EDIT!  This file is generated by sdlgenaudiocvt.pl */
       
     2 /*
     1 /*
     3   Simple DirectMedia Layer
     2   Simple DirectMedia Layer
     4   Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
     3   Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
     5 
     4 
     6   This software is provided 'as-is', without any express or implied
     5   This software is provided 'as-is', without any express or implied
    21 */
    20 */
    22 
    21 
    23 #include "../SDL_internal.h"
    22 #include "../SDL_internal.h"
    24 #include "SDL_audio.h"
    23 #include "SDL_audio.h"
    25 #include "SDL_audio_c.h"
    24 #include "SDL_audio_c.h"
    26 
    25 #include "SDL_assert.h"
    27 #ifndef DEBUG_CONVERT
       
    28 #define DEBUG_CONVERT 0
       
    29 #endif
       
    30 
       
    31 
       
    32 /* If you can guarantee your data and need space, you can eliminate code... */
       
    33 
       
    34 /* Just build the arbitrary resamplers if you're saving code space. */
       
    35 #ifndef LESS_RESAMPLERS
       
    36 #define LESS_RESAMPLERS 0
       
    37 #endif
       
    38 
       
    39 /* Don't build any resamplers if you're REALLY saving code space. */
       
    40 #ifndef NO_RESAMPLERS
       
    41 #define NO_RESAMPLERS 0
       
    42 #endif
       
    43 
       
    44 /* Don't build any type converters if you're saving code space. */
       
    45 #ifndef NO_CONVERTERS
       
    46 #define NO_CONVERTERS 0
       
    47 #endif
       
    48 
       
    49 
       
    50 /* *INDENT-OFF* */
       
    51 
    26 
    52 #define DIVBY127 0.0078740157480315f
    27 #define DIVBY127 0.0078740157480315f
    53 #define DIVBY32767 3.05185094759972e-05f
    28 #define DIVBY32767 3.05185094759972e-05f
    54 #define DIVBY2147483647 4.6566128752458e-10f
    29 #define DIVBY2147483647 4.6566128752458e-10f
    55 
    30 
    56 #if !NO_CONVERTERS
    31 void SDLCALL
    57 
    32 SDL_Convert_S8_to_F32(SDL_AudioCVT *cvt, SDL_AudioFormat format)
    58 static void SDLCALL
    33 {
    59 SDL_Convert_U8_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
    34     const Uint8 *src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
    60 {
    35     float *dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
    61     int i;
    36     int i;
    62     const Uint8 *src;
    37 
    63     Sint8 *dst;
    38     LOG_DEBUG_CONVERT("AUDIO_S8", "AUDIO_F32");
       
    39 
       
    40     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
       
    41         *dst = (((float) ((Sint8) *src)) * DIVBY127);
       
    42     }
       
    43 
       
    44     cvt->len_cvt *= 4;
       
    45     if (cvt->filters[++cvt->filter_index]) {
       
    46         cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
       
    47     }
       
    48 }
       
    49 
       
    50 void SDLCALL
       
    51 SDL_Convert_U8_to_F32(SDL_AudioCVT *cvt, SDL_AudioFormat format)
       
    52 {
       
    53     const Uint8 *src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
       
    54     float *dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
       
    55     int i;
       
    56 
       
    57     LOG_DEBUG_CONVERT("AUDIO_U8", "AUDIO_F32");
       
    58 
       
    59     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
       
    60         *dst = ((((float) *src) * DIVBY127) - 1.0f);
       
    61     }
       
    62 
       
    63     cvt->len_cvt *= 4;
       
    64     if (cvt->filters[++cvt->filter_index]) {
       
    65         cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
       
    66     }
       
    67 }
       
    68 
       
    69 void SDLCALL
       
    70 SDL_Convert_S16_to_F32(SDL_AudioCVT *cvt, SDL_AudioFormat format)
       
    71 {
       
    72     const Sint16 *src = ((const Sint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
    73     float *dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
    74     int i;
       
    75 
       
    76     LOG_DEBUG_CONVERT("AUDIO_S16", "AUDIO_F32");
       
    77 
       
    78     for (i = cvt->len_cvt / sizeof (Sint16); i; --i, --src, --dst) {
       
    79         *dst = (((float) *src) * DIVBY32767);
       
    80     }
       
    81 
       
    82     cvt->len_cvt *= 2;
       
    83     if (cvt->filters[++cvt->filter_index]) {
       
    84         cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
       
    85     }
       
    86 }
       
    87 
       
    88 void SDLCALL
       
    89 SDL_Convert_U16_to_F32(SDL_AudioCVT *cvt, SDL_AudioFormat format)
       
    90 {
       
    91     const Uint16 *src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
    92     float *dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
    93     int i;
       
    94 
       
    95     LOG_DEBUG_CONVERT("AUDIO_U16", "AUDIO_F32");
       
    96 
       
    97     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
       
    98         *dst = ((((float) *src) * DIVBY32767) - 1.0f);
       
    99     }
       
   100 
       
   101     cvt->len_cvt *= 2;
       
   102     if (cvt->filters[++cvt->filter_index]) {
       
   103         cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
       
   104     }
       
   105 }
       
   106 
       
   107 void SDLCALL
       
   108 SDL_Convert_S32_to_F32(SDL_AudioCVT *cvt, SDL_AudioFormat format)
       
   109 {
       
   110     const Uint32 *src = (const Uint32 *) cvt->buf;
       
   111     float *dst = (float *) cvt->buf;
       
   112     int i;
       
   113 
       
   114     LOG_DEBUG_CONVERT("AUDIO_S32", "AUDIO_F32");
       
   115 
       
   116     for (i = cvt->len_cvt / sizeof (Sint32); i; --i, ++src, ++dst) {
       
   117         *dst = (((float) *src) * DIVBY2147483647);
       
   118     }
       
   119 
       
   120     if (cvt->filters[++cvt->filter_index]) {
       
   121         cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
       
   122     }
       
   123 }
       
   124 
       
   125 void SDLCALL
       
   126 SDL_Convert_F32_to_S8(SDL_AudioCVT *cvt, SDL_AudioFormat format)
       
   127 {
       
   128     const float *src = (const float *) cvt->buf;
       
   129     Sint8 *dst = (Sint8 *) cvt->buf;
       
   130     int i;
       
   131 
       
   132     LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S8");
       
   133 
       
   134     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
   135         *dst = (Sint8) (*src * 127.0f);
       
   136     }
       
   137 
       
   138     cvt->len_cvt /= 4;
       
   139     if (cvt->filters[++cvt->filter_index]) {
       
   140         cvt->filters[cvt->filter_index](cvt, AUDIO_S8);
       
   141     }
       
   142 }
       
   143 
       
   144 void SDLCALL
       
   145 SDL_Convert_F32_to_U8(SDL_AudioCVT *cvt, SDL_AudioFormat format)
       
   146 {
       
   147     const float *src = (const float *) cvt->buf;
       
   148     Uint8 *dst = (Uint8 *) cvt->buf;
       
   149     int i;
       
   150 
       
   151     LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_U8");
       
   152 
       
   153     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
   154         *dst = (Uint8) ((*src + 1.0f) * 127.0f);
       
   155     }
       
   156 
       
   157     cvt->len_cvt /= 4;
       
   158     if (cvt->filters[++cvt->filter_index]) {
       
   159         cvt->filters[cvt->filter_index](cvt, AUDIO_U8);
       
   160     }
       
   161 }
       
   162 
       
   163 void SDLCALL
       
   164 SDL_Convert_F32_to_S16(SDL_AudioCVT *cvt, SDL_AudioFormat format)
       
   165 {
       
   166     const float *src = (const float *) cvt->buf;
       
   167     Sint16 *dst = (Sint16 *) cvt->buf;
       
   168     int i;
       
   169 
       
   170     LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S16");
       
   171 
       
   172     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
   173         *dst = (Sint16) (*src * 32767.0f);
       
   174     }
       
   175 
       
   176     cvt->len_cvt /= 2;
       
   177     if (cvt->filters[++cvt->filter_index]) {
       
   178         cvt->filters[cvt->filter_index](cvt, AUDIO_S16SYS);
       
   179     }
       
   180 }
       
   181 
       
   182 void SDLCALL
       
   183 SDL_Convert_F32_to_U16(SDL_AudioCVT *cvt, SDL_AudioFormat format)
       
   184 {
       
   185     const float *src = (const float *) cvt->buf;
       
   186     Uint16 *dst = (Uint16 *) cvt->buf;
       
   187     int i;
       
   188 
       
   189     LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_U16");
       
   190 
       
   191     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
   192         *dst = (Uint16) ((*src + 1.0f) * 32767.0f);
       
   193     }
       
   194 
       
   195     cvt->len_cvt /= 2;
       
   196     if (cvt->filters[++cvt->filter_index]) {
       
   197         cvt->filters[cvt->filter_index](cvt, AUDIO_U16SYS);
       
   198     }
       
   199 }
       
   200 
       
   201 void SDLCALL
       
   202 SDL_Convert_F32_to_S32(SDL_AudioCVT *cvt, SDL_AudioFormat format)
       
   203 {
       
   204     const float *src = (const float *) cvt->buf;
       
   205     Sint32 *dst = (Sint32 *) cvt->buf;
       
   206     int i;
       
   207 
       
   208     LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S32");
       
   209 
       
   210     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
   211         *dst = (Sint32) (*src * 2147483647.0);
       
   212     }
       
   213 
       
   214     if (cvt->filters[++cvt->filter_index]) {
       
   215         cvt->filters[cvt->filter_index](cvt, AUDIO_S32SYS);
       
   216     }
       
   217 }
       
   218 
       
   219 void
       
   220 SDL_Upsample_Arbitrary(SDL_AudioCVT *cvt, const int channels)
       
   221 {
       
   222     const int srcsize = cvt->len_cvt - (64 * channels);
       
   223     const int dstsize = (int) (((double)(cvt->len_cvt/(channels*4))) * cvt->rate_incr) * (channels*4);
       
   224     register int eps = 0;
       
   225     float *dst = ((float *) (cvt->buf + dstsize)) - 8;
       
   226     const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 8;
       
   227     const float *target = ((const float *) cvt->buf);
       
   228     const size_t cpy = sizeof (float) * channels;
       
   229     float last_sample[8];
       
   230     float sample[8];
       
   231     int i;
    64 
   232 
    65 #if DEBUG_CONVERT
   233 #if DEBUG_CONVERT
    66     fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S8.\n");
   234     fprintf(stderr, "Upsample arbitrary (x%f), %d channels.\n", cvt->rate_incr, channels);
    67 #endif
   235 #endif
    68 
   236 
    69     src = (const Uint8 *) cvt->buf;
   237     SDL_assert(channels <= 8);
    70     dst = (Sint8 *) cvt->buf;
   238 
    71     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, ++src, ++dst) {
   239     SDL_memcpy(sample, src, cpy);
    72         const Sint8 val = ((*src) ^ 0x80);
   240     SDL_memcpy(last_sample, src, cpy);
    73         *dst = ((Sint8) val);
   241 
    74     }
       
    75 
       
    76     if (cvt->filters[++cvt->filter_index]) {
       
    77         cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
       
    78     }
       
    79 }
       
    80 
       
    81 static void SDLCALL
       
    82 SDL_Convert_U8_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
    83 {
       
    84     int i;
       
    85     const Uint8 *src;
       
    86     Uint16 *dst;
       
    87 
       
    88 #if DEBUG_CONVERT
       
    89     fprintf(stderr, "Converting AUDIO_U8 to AUDIO_U16LSB.\n");
       
    90 #endif
       
    91 
       
    92     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
       
    93     dst = ((Uint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
    94     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
       
    95         const Uint16 val = (((Uint16) *src) << 8);
       
    96         *dst = SDL_SwapLE16(val);
       
    97     }
       
    98 
       
    99     cvt->len_cvt *= 2;
       
   100     if (cvt->filters[++cvt->filter_index]) {
       
   101         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
       
   102     }
       
   103 }
       
   104 
       
   105 static void SDLCALL
       
   106 SDL_Convert_U8_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   107 {
       
   108     int i;
       
   109     const Uint8 *src;
       
   110     Sint16 *dst;
       
   111 
       
   112 #if DEBUG_CONVERT
       
   113     fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S16LSB.\n");
       
   114 #endif
       
   115 
       
   116     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   117     dst = ((Sint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
   118     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
       
   119         const Sint16 val = (((Sint16) ((*src) ^ 0x80)) << 8);
       
   120         *dst = ((Sint16) SDL_SwapLE16(val));
       
   121     }
       
   122 
       
   123     cvt->len_cvt *= 2;
       
   124     if (cvt->filters[++cvt->filter_index]) {
       
   125         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
       
   126     }
       
   127 }
       
   128 
       
   129 static void SDLCALL
       
   130 SDL_Convert_U8_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   131 {
       
   132     int i;
       
   133     const Uint8 *src;
       
   134     Uint16 *dst;
       
   135 
       
   136 #if DEBUG_CONVERT
       
   137     fprintf(stderr, "Converting AUDIO_U8 to AUDIO_U16MSB.\n");
       
   138 #endif
       
   139 
       
   140     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   141     dst = ((Uint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
   142     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
       
   143         const Uint16 val = (((Uint16) *src) << 8);
       
   144         *dst = SDL_SwapBE16(val);
       
   145     }
       
   146 
       
   147     cvt->len_cvt *= 2;
       
   148     if (cvt->filters[++cvt->filter_index]) {
       
   149         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
       
   150     }
       
   151 }
       
   152 
       
   153 static void SDLCALL
       
   154 SDL_Convert_U8_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   155 {
       
   156     int i;
       
   157     const Uint8 *src;
       
   158     Sint16 *dst;
       
   159 
       
   160 #if DEBUG_CONVERT
       
   161     fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S16MSB.\n");
       
   162 #endif
       
   163 
       
   164     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   165     dst = ((Sint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
   166     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
       
   167         const Sint16 val = (((Sint16) ((*src) ^ 0x80)) << 8);
       
   168         *dst = ((Sint16) SDL_SwapBE16(val));
       
   169     }
       
   170 
       
   171     cvt->len_cvt *= 2;
       
   172     if (cvt->filters[++cvt->filter_index]) {
       
   173         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
       
   174     }
       
   175 }
       
   176 
       
   177 static void SDLCALL
       
   178 SDL_Convert_U8_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   179 {
       
   180     int i;
       
   181     const Uint8 *src;
       
   182     Sint32 *dst;
       
   183 
       
   184 #if DEBUG_CONVERT
       
   185     fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S32LSB.\n");
       
   186 #endif
       
   187 
       
   188     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   189     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 4)) - 1;
       
   190     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
       
   191         const Sint32 val = (((Sint32) ((*src) ^ 0x80)) << 24);
       
   192         *dst = ((Sint32) SDL_SwapLE32(val));
       
   193     }
       
   194 
       
   195     cvt->len_cvt *= 4;
       
   196     if (cvt->filters[++cvt->filter_index]) {
       
   197         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
       
   198     }
       
   199 }
       
   200 
       
   201 static void SDLCALL
       
   202 SDL_Convert_U8_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   203 {
       
   204     int i;
       
   205     const Uint8 *src;
       
   206     Sint32 *dst;
       
   207 
       
   208 #if DEBUG_CONVERT
       
   209     fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S32MSB.\n");
       
   210 #endif
       
   211 
       
   212     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   213     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 4)) - 1;
       
   214     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
       
   215         const Sint32 val = (((Sint32) ((*src) ^ 0x80)) << 24);
       
   216         *dst = ((Sint32) SDL_SwapBE32(val));
       
   217     }
       
   218 
       
   219     cvt->len_cvt *= 4;
       
   220     if (cvt->filters[++cvt->filter_index]) {
       
   221         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
       
   222     }
       
   223 }
       
   224 
       
   225 static void SDLCALL
       
   226 SDL_Convert_U8_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   227 {
       
   228     int i;
       
   229     const Uint8 *src;
       
   230     float *dst;
       
   231 
       
   232 #if DEBUG_CONVERT
       
   233     fprintf(stderr, "Converting AUDIO_U8 to AUDIO_F32LSB.\n");
       
   234 #endif
       
   235 
       
   236     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   237     dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
       
   238     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
       
   239         const float val = ((((float) *src) * DIVBY127) - 1.0f);
       
   240         *dst = SDL_SwapFloatLE(val);
       
   241     }
       
   242 
       
   243     cvt->len_cvt *= 4;
       
   244     if (cvt->filters[++cvt->filter_index]) {
       
   245         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
       
   246     }
       
   247 }
       
   248 
       
   249 static void SDLCALL
       
   250 SDL_Convert_U8_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   251 {
       
   252     int i;
       
   253     const Uint8 *src;
       
   254     float *dst;
       
   255 
       
   256 #if DEBUG_CONVERT
       
   257     fprintf(stderr, "Converting AUDIO_U8 to AUDIO_F32MSB.\n");
       
   258 #endif
       
   259 
       
   260     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   261     dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
       
   262     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
       
   263         const float val = ((((float) *src) * DIVBY127) - 1.0f);
       
   264         *dst = SDL_SwapFloatBE(val);
       
   265     }
       
   266 
       
   267     cvt->len_cvt *= 4;
       
   268     if (cvt->filters[++cvt->filter_index]) {
       
   269         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
       
   270     }
       
   271 }
       
   272 
       
   273 static void SDLCALL
       
   274 SDL_Convert_S8_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   275 {
       
   276     int i;
       
   277     const Uint8 *src;
       
   278     Uint8 *dst;
       
   279 
       
   280 #if DEBUG_CONVERT
       
   281     fprintf(stderr, "Converting AUDIO_S8 to AUDIO_U8.\n");
       
   282 #endif
       
   283 
       
   284     src = (const Uint8 *) cvt->buf;
       
   285     dst = (Uint8 *) cvt->buf;
       
   286     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, ++src, ++dst) {
       
   287         const Uint8 val = ((((Sint8) *src)) ^ 0x80);
       
   288         *dst = val;
       
   289     }
       
   290 
       
   291     if (cvt->filters[++cvt->filter_index]) {
       
   292         cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
       
   293     }
       
   294 }
       
   295 
       
   296 static void SDLCALL
       
   297 SDL_Convert_S8_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   298 {
       
   299     int i;
       
   300     const Uint8 *src;
       
   301     Uint16 *dst;
       
   302 
       
   303 #if DEBUG_CONVERT
       
   304     fprintf(stderr, "Converting AUDIO_S8 to AUDIO_U16LSB.\n");
       
   305 #endif
       
   306 
       
   307     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   308     dst = ((Uint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
   309     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
       
   310         const Uint16 val = (((Uint16) ((((Sint8) *src)) ^ 0x80)) << 8);
       
   311         *dst = SDL_SwapLE16(val);
       
   312     }
       
   313 
       
   314     cvt->len_cvt *= 2;
       
   315     if (cvt->filters[++cvt->filter_index]) {
       
   316         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
       
   317     }
       
   318 }
       
   319 
       
   320 static void SDLCALL
       
   321 SDL_Convert_S8_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   322 {
       
   323     int i;
       
   324     const Uint8 *src;
       
   325     Sint16 *dst;
       
   326 
       
   327 #if DEBUG_CONVERT
       
   328     fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S16LSB.\n");
       
   329 #endif
       
   330 
       
   331     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   332     dst = ((Sint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
   333     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
       
   334         const Sint16 val = (((Sint16) ((Sint8) *src)) << 8);
       
   335         *dst = ((Sint16) SDL_SwapLE16(val));
       
   336     }
       
   337 
       
   338     cvt->len_cvt *= 2;
       
   339     if (cvt->filters[++cvt->filter_index]) {
       
   340         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
       
   341     }
       
   342 }
       
   343 
       
   344 static void SDLCALL
       
   345 SDL_Convert_S8_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   346 {
       
   347     int i;
       
   348     const Uint8 *src;
       
   349     Uint16 *dst;
       
   350 
       
   351 #if DEBUG_CONVERT
       
   352     fprintf(stderr, "Converting AUDIO_S8 to AUDIO_U16MSB.\n");
       
   353 #endif
       
   354 
       
   355     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   356     dst = ((Uint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
   357     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
       
   358         const Uint16 val = (((Uint16) ((((Sint8) *src)) ^ 0x80)) << 8);
       
   359         *dst = SDL_SwapBE16(val);
       
   360     }
       
   361 
       
   362     cvt->len_cvt *= 2;
       
   363     if (cvt->filters[++cvt->filter_index]) {
       
   364         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
       
   365     }
       
   366 }
       
   367 
       
   368 static void SDLCALL
       
   369 SDL_Convert_S8_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   370 {
       
   371     int i;
       
   372     const Uint8 *src;
       
   373     Sint16 *dst;
       
   374 
       
   375 #if DEBUG_CONVERT
       
   376     fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S16MSB.\n");
       
   377 #endif
       
   378 
       
   379     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   380     dst = ((Sint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
   381     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
       
   382         const Sint16 val = (((Sint16) ((Sint8) *src)) << 8);
       
   383         *dst = ((Sint16) SDL_SwapBE16(val));
       
   384     }
       
   385 
       
   386     cvt->len_cvt *= 2;
       
   387     if (cvt->filters[++cvt->filter_index]) {
       
   388         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
       
   389     }
       
   390 }
       
   391 
       
   392 static void SDLCALL
       
   393 SDL_Convert_S8_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   394 {
       
   395     int i;
       
   396     const Uint8 *src;
       
   397     Sint32 *dst;
       
   398 
       
   399 #if DEBUG_CONVERT
       
   400     fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S32LSB.\n");
       
   401 #endif
       
   402 
       
   403     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   404     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 4)) - 1;
       
   405     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
       
   406         const Sint32 val = (((Sint32) ((Sint8) *src)) << 24);
       
   407         *dst = ((Sint32) SDL_SwapLE32(val));
       
   408     }
       
   409 
       
   410     cvt->len_cvt *= 4;
       
   411     if (cvt->filters[++cvt->filter_index]) {
       
   412         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
       
   413     }
       
   414 }
       
   415 
       
   416 static void SDLCALL
       
   417 SDL_Convert_S8_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   418 {
       
   419     int i;
       
   420     const Uint8 *src;
       
   421     Sint32 *dst;
       
   422 
       
   423 #if DEBUG_CONVERT
       
   424     fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S32MSB.\n");
       
   425 #endif
       
   426 
       
   427     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   428     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 4)) - 1;
       
   429     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
       
   430         const Sint32 val = (((Sint32) ((Sint8) *src)) << 24);
       
   431         *dst = ((Sint32) SDL_SwapBE32(val));
       
   432     }
       
   433 
       
   434     cvt->len_cvt *= 4;
       
   435     if (cvt->filters[++cvt->filter_index]) {
       
   436         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
       
   437     }
       
   438 }
       
   439 
       
   440 static void SDLCALL
       
   441 SDL_Convert_S8_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   442 {
       
   443     int i;
       
   444     const Uint8 *src;
       
   445     float *dst;
       
   446 
       
   447 #if DEBUG_CONVERT
       
   448     fprintf(stderr, "Converting AUDIO_S8 to AUDIO_F32LSB.\n");
       
   449 #endif
       
   450 
       
   451     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   452     dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
       
   453     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
       
   454         const float val = (((float) ((Sint8) *src)) * DIVBY127);
       
   455         *dst = SDL_SwapFloatLE(val);
       
   456     }
       
   457 
       
   458     cvt->len_cvt *= 4;
       
   459     if (cvt->filters[++cvt->filter_index]) {
       
   460         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
       
   461     }
       
   462 }
       
   463 
       
   464 static void SDLCALL
       
   465 SDL_Convert_S8_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   466 {
       
   467     int i;
       
   468     const Uint8 *src;
       
   469     float *dst;
       
   470 
       
   471 #if DEBUG_CONVERT
       
   472     fprintf(stderr, "Converting AUDIO_S8 to AUDIO_F32MSB.\n");
       
   473 #endif
       
   474 
       
   475     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   476     dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
       
   477     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
       
   478         const float val = (((float) ((Sint8) *src)) * DIVBY127);
       
   479         *dst = SDL_SwapFloatBE(val);
       
   480     }
       
   481 
       
   482     cvt->len_cvt *= 4;
       
   483     if (cvt->filters[++cvt->filter_index]) {
       
   484         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
       
   485     }
       
   486 }
       
   487 
       
   488 static void SDLCALL
       
   489 SDL_Convert_U16LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   490 {
       
   491     int i;
       
   492     const Uint16 *src;
       
   493     Uint8 *dst;
       
   494 
       
   495 #if DEBUG_CONVERT
       
   496     fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_U8.\n");
       
   497 #endif
       
   498 
       
   499     src = (const Uint16 *) cvt->buf;
       
   500     dst = (Uint8 *) cvt->buf;
       
   501     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
   502         const Uint8 val = ((Uint8) (SDL_SwapLE16(*src) >> 8));
       
   503         *dst = val;
       
   504     }
       
   505 
       
   506     cvt->len_cvt /= 2;
       
   507     if (cvt->filters[++cvt->filter_index]) {
       
   508         cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
       
   509     }
       
   510 }
       
   511 
       
   512 static void SDLCALL
       
   513 SDL_Convert_U16LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   514 {
       
   515     int i;
       
   516     const Uint16 *src;
       
   517     Sint8 *dst;
       
   518 
       
   519 #if DEBUG_CONVERT
       
   520     fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S8.\n");
       
   521 #endif
       
   522 
       
   523     src = (const Uint16 *) cvt->buf;
       
   524     dst = (Sint8 *) cvt->buf;
       
   525     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
   526         const Sint8 val = ((Sint8) (((SDL_SwapLE16(*src)) ^ 0x8000) >> 8));
       
   527         *dst = ((Sint8) val);
       
   528     }
       
   529 
       
   530     cvt->len_cvt /= 2;
       
   531     if (cvt->filters[++cvt->filter_index]) {
       
   532         cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
       
   533     }
       
   534 }
       
   535 
       
   536 static void SDLCALL
       
   537 SDL_Convert_U16LSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   538 {
       
   539     int i;
       
   540     const Uint16 *src;
       
   541     Sint16 *dst;
       
   542 
       
   543 #if DEBUG_CONVERT
       
   544     fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S16LSB.\n");
       
   545 #endif
       
   546 
       
   547     src = (const Uint16 *) cvt->buf;
       
   548     dst = (Sint16 *) cvt->buf;
       
   549     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
   550         const Sint16 val = ((SDL_SwapLE16(*src)) ^ 0x8000);
       
   551         *dst = ((Sint16) SDL_SwapLE16(val));
       
   552     }
       
   553 
       
   554     if (cvt->filters[++cvt->filter_index]) {
       
   555         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
       
   556     }
       
   557 }
       
   558 
       
   559 static void SDLCALL
       
   560 SDL_Convert_U16LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   561 {
       
   562     int i;
       
   563     const Uint16 *src;
       
   564     Uint16 *dst;
       
   565 
       
   566 #if DEBUG_CONVERT
       
   567     fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_U16MSB.\n");
       
   568 #endif
       
   569 
       
   570     src = (const Uint16 *) cvt->buf;
       
   571     dst = (Uint16 *) cvt->buf;
       
   572     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
   573         const Uint16 val = SDL_SwapLE16(*src);
       
   574         *dst = SDL_SwapBE16(val);
       
   575     }
       
   576 
       
   577     if (cvt->filters[++cvt->filter_index]) {
       
   578         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
       
   579     }
       
   580 }
       
   581 
       
   582 static void SDLCALL
       
   583 SDL_Convert_U16LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   584 {
       
   585     int i;
       
   586     const Uint16 *src;
       
   587     Sint16 *dst;
       
   588 
       
   589 #if DEBUG_CONVERT
       
   590     fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S16MSB.\n");
       
   591 #endif
       
   592 
       
   593     src = (const Uint16 *) cvt->buf;
       
   594     dst = (Sint16 *) cvt->buf;
       
   595     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
   596         const Sint16 val = ((SDL_SwapLE16(*src)) ^ 0x8000);
       
   597         *dst = ((Sint16) SDL_SwapBE16(val));
       
   598     }
       
   599 
       
   600     if (cvt->filters[++cvt->filter_index]) {
       
   601         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
       
   602     }
       
   603 }
       
   604 
       
   605 static void SDLCALL
       
   606 SDL_Convert_U16LSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   607 {
       
   608     int i;
       
   609     const Uint16 *src;
       
   610     Sint32 *dst;
       
   611 
       
   612 #if DEBUG_CONVERT
       
   613     fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S32LSB.\n");
       
   614 #endif
       
   615 
       
   616     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   617     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
   618     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
       
   619         const Sint32 val = (((Sint32) ((SDL_SwapLE16(*src)) ^ 0x8000)) << 16);
       
   620         *dst = ((Sint32) SDL_SwapLE32(val));
       
   621     }
       
   622 
       
   623     cvt->len_cvt *= 2;
       
   624     if (cvt->filters[++cvt->filter_index]) {
       
   625         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
       
   626     }
       
   627 }
       
   628 
       
   629 static void SDLCALL
       
   630 SDL_Convert_U16LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   631 {
       
   632     int i;
       
   633     const Uint16 *src;
       
   634     Sint32 *dst;
       
   635 
       
   636 #if DEBUG_CONVERT
       
   637     fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S32MSB.\n");
       
   638 #endif
       
   639 
       
   640     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   641     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
   642     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
       
   643         const Sint32 val = (((Sint32) ((SDL_SwapLE16(*src)) ^ 0x8000)) << 16);
       
   644         *dst = ((Sint32) SDL_SwapBE32(val));
       
   645     }
       
   646 
       
   647     cvt->len_cvt *= 2;
       
   648     if (cvt->filters[++cvt->filter_index]) {
       
   649         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
       
   650     }
       
   651 }
       
   652 
       
   653 static void SDLCALL
       
   654 SDL_Convert_U16LSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   655 {
       
   656     int i;
       
   657     const Uint16 *src;
       
   658     float *dst;
       
   659 
       
   660 #if DEBUG_CONVERT
       
   661     fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_F32LSB.\n");
       
   662 #endif
       
   663 
       
   664     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   665     dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
   666     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
       
   667         const float val = ((((float) SDL_SwapLE16(*src)) * DIVBY32767) - 1.0f);
       
   668         *dst = SDL_SwapFloatLE(val);
       
   669     }
       
   670 
       
   671     cvt->len_cvt *= 2;
       
   672     if (cvt->filters[++cvt->filter_index]) {
       
   673         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
       
   674     }
       
   675 }
       
   676 
       
   677 static void SDLCALL
       
   678 SDL_Convert_U16LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   679 {
       
   680     int i;
       
   681     const Uint16 *src;
       
   682     float *dst;
       
   683 
       
   684 #if DEBUG_CONVERT
       
   685     fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_F32MSB.\n");
       
   686 #endif
       
   687 
       
   688     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   689     dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
   690     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
       
   691         const float val = ((((float) SDL_SwapLE16(*src)) * DIVBY32767) - 1.0f);
       
   692         *dst = SDL_SwapFloatBE(val);
       
   693     }
       
   694 
       
   695     cvt->len_cvt *= 2;
       
   696     if (cvt->filters[++cvt->filter_index]) {
       
   697         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
       
   698     }
       
   699 }
       
   700 
       
   701 static void SDLCALL
       
   702 SDL_Convert_S16LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   703 {
       
   704     int i;
       
   705     const Uint16 *src;
       
   706     Uint8 *dst;
       
   707 
       
   708 #if DEBUG_CONVERT
       
   709     fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_U8.\n");
       
   710 #endif
       
   711 
       
   712     src = (const Uint16 *) cvt->buf;
       
   713     dst = (Uint8 *) cvt->buf;
       
   714     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
   715         const Uint8 val = ((Uint8) (((((Sint16) SDL_SwapLE16(*src))) ^ 0x8000) >> 8));
       
   716         *dst = val;
       
   717     }
       
   718 
       
   719     cvt->len_cvt /= 2;
       
   720     if (cvt->filters[++cvt->filter_index]) {
       
   721         cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
       
   722     }
       
   723 }
       
   724 
       
   725 static void SDLCALL
       
   726 SDL_Convert_S16LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   727 {
       
   728     int i;
       
   729     const Uint16 *src;
       
   730     Sint8 *dst;
       
   731 
       
   732 #if DEBUG_CONVERT
       
   733     fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S8.\n");
       
   734 #endif
       
   735 
       
   736     src = (const Uint16 *) cvt->buf;
       
   737     dst = (Sint8 *) cvt->buf;
       
   738     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
   739         const Sint8 val = ((Sint8) (((Sint16) SDL_SwapLE16(*src)) >> 8));
       
   740         *dst = ((Sint8) val);
       
   741     }
       
   742 
       
   743     cvt->len_cvt /= 2;
       
   744     if (cvt->filters[++cvt->filter_index]) {
       
   745         cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
       
   746     }
       
   747 }
       
   748 
       
   749 static void SDLCALL
       
   750 SDL_Convert_S16LSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   751 {
       
   752     int i;
       
   753     const Uint16 *src;
       
   754     Uint16 *dst;
       
   755 
       
   756 #if DEBUG_CONVERT
       
   757     fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_U16LSB.\n");
       
   758 #endif
       
   759 
       
   760     src = (const Uint16 *) cvt->buf;
       
   761     dst = (Uint16 *) cvt->buf;
       
   762     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
   763         const Uint16 val = ((((Sint16) SDL_SwapLE16(*src))) ^ 0x8000);
       
   764         *dst = SDL_SwapLE16(val);
       
   765     }
       
   766 
       
   767     if (cvt->filters[++cvt->filter_index]) {
       
   768         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
       
   769     }
       
   770 }
       
   771 
       
   772 static void SDLCALL
       
   773 SDL_Convert_S16LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   774 {
       
   775     int i;
       
   776     const Uint16 *src;
       
   777     Uint16 *dst;
       
   778 
       
   779 #if DEBUG_CONVERT
       
   780     fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_U16MSB.\n");
       
   781 #endif
       
   782 
       
   783     src = (const Uint16 *) cvt->buf;
       
   784     dst = (Uint16 *) cvt->buf;
       
   785     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
   786         const Uint16 val = ((((Sint16) SDL_SwapLE16(*src))) ^ 0x8000);
       
   787         *dst = SDL_SwapBE16(val);
       
   788     }
       
   789 
       
   790     if (cvt->filters[++cvt->filter_index]) {
       
   791         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
       
   792     }
       
   793 }
       
   794 
       
   795 static void SDLCALL
       
   796 SDL_Convert_S16LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   797 {
       
   798     int i;
       
   799     const Uint16 *src;
       
   800     Sint16 *dst;
       
   801 
       
   802 #if DEBUG_CONVERT
       
   803     fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S16MSB.\n");
       
   804 #endif
       
   805 
       
   806     src = (const Uint16 *) cvt->buf;
       
   807     dst = (Sint16 *) cvt->buf;
       
   808     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
   809         const Sint16 val = ((Sint16) SDL_SwapLE16(*src));
       
   810         *dst = ((Sint16) SDL_SwapBE16(val));
       
   811     }
       
   812 
       
   813     if (cvt->filters[++cvt->filter_index]) {
       
   814         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
       
   815     }
       
   816 }
       
   817 
       
   818 static void SDLCALL
       
   819 SDL_Convert_S16LSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   820 {
       
   821     int i;
       
   822     const Uint16 *src;
       
   823     Sint32 *dst;
       
   824 
       
   825 #if DEBUG_CONVERT
       
   826     fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S32LSB.\n");
       
   827 #endif
       
   828 
       
   829     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   830     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
   831     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
       
   832         const Sint32 val = (((Sint32) ((Sint16) SDL_SwapLE16(*src))) << 16);
       
   833         *dst = ((Sint32) SDL_SwapLE32(val));
       
   834     }
       
   835 
       
   836     cvt->len_cvt *= 2;
       
   837     if (cvt->filters[++cvt->filter_index]) {
       
   838         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
       
   839     }
       
   840 }
       
   841 
       
   842 static void SDLCALL
       
   843 SDL_Convert_S16LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   844 {
       
   845     int i;
       
   846     const Uint16 *src;
       
   847     Sint32 *dst;
       
   848 
       
   849 #if DEBUG_CONVERT
       
   850     fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S32MSB.\n");
       
   851 #endif
       
   852 
       
   853     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   854     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
   855     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
       
   856         const Sint32 val = (((Sint32) ((Sint16) SDL_SwapLE16(*src))) << 16);
       
   857         *dst = ((Sint32) SDL_SwapBE32(val));
       
   858     }
       
   859 
       
   860     cvt->len_cvt *= 2;
       
   861     if (cvt->filters[++cvt->filter_index]) {
       
   862         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
       
   863     }
       
   864 }
       
   865 
       
   866 static void SDLCALL
       
   867 SDL_Convert_S16LSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   868 {
       
   869     int i;
       
   870     const Uint16 *src;
       
   871     float *dst;
       
   872 
       
   873 #if DEBUG_CONVERT
       
   874     fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_F32LSB.\n");
       
   875 #endif
       
   876 
       
   877     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   878     dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
   879     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
       
   880         const float val = (((float) ((Sint16) SDL_SwapLE16(*src))) * DIVBY32767);
       
   881         *dst = SDL_SwapFloatLE(val);
       
   882     }
       
   883 
       
   884     cvt->len_cvt *= 2;
       
   885     if (cvt->filters[++cvt->filter_index]) {
       
   886         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
       
   887     }
       
   888 }
       
   889 
       
   890 static void SDLCALL
       
   891 SDL_Convert_S16LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   892 {
       
   893     int i;
       
   894     const Uint16 *src;
       
   895     float *dst;
       
   896 
       
   897 #if DEBUG_CONVERT
       
   898     fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_F32MSB.\n");
       
   899 #endif
       
   900 
       
   901     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
   902     dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
   903     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
       
   904         const float val = (((float) ((Sint16) SDL_SwapLE16(*src))) * DIVBY32767);
       
   905         *dst = SDL_SwapFloatBE(val);
       
   906     }
       
   907 
       
   908     cvt->len_cvt *= 2;
       
   909     if (cvt->filters[++cvt->filter_index]) {
       
   910         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
       
   911     }
       
   912 }
       
   913 
       
   914 static void SDLCALL
       
   915 SDL_Convert_U16MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   916 {
       
   917     int i;
       
   918     const Uint16 *src;
       
   919     Uint8 *dst;
       
   920 
       
   921 #if DEBUG_CONVERT
       
   922     fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_U8.\n");
       
   923 #endif
       
   924 
       
   925     src = (const Uint16 *) cvt->buf;
       
   926     dst = (Uint8 *) cvt->buf;
       
   927     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
   928         const Uint8 val = ((Uint8) (SDL_SwapBE16(*src) >> 8));
       
   929         *dst = val;
       
   930     }
       
   931 
       
   932     cvt->len_cvt /= 2;
       
   933     if (cvt->filters[++cvt->filter_index]) {
       
   934         cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
       
   935     }
       
   936 }
       
   937 
       
   938 static void SDLCALL
       
   939 SDL_Convert_U16MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   940 {
       
   941     int i;
       
   942     const Uint16 *src;
       
   943     Sint8 *dst;
       
   944 
       
   945 #if DEBUG_CONVERT
       
   946     fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S8.\n");
       
   947 #endif
       
   948 
       
   949     src = (const Uint16 *) cvt->buf;
       
   950     dst = (Sint8 *) cvt->buf;
       
   951     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
   952         const Sint8 val = ((Sint8) (((SDL_SwapBE16(*src)) ^ 0x8000) >> 8));
       
   953         *dst = ((Sint8) val);
       
   954     }
       
   955 
       
   956     cvt->len_cvt /= 2;
       
   957     if (cvt->filters[++cvt->filter_index]) {
       
   958         cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
       
   959     }
       
   960 }
       
   961 
       
   962 static void SDLCALL
       
   963 SDL_Convert_U16MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   964 {
       
   965     int i;
       
   966     const Uint16 *src;
       
   967     Uint16 *dst;
       
   968 
       
   969 #if DEBUG_CONVERT
       
   970     fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_U16LSB.\n");
       
   971 #endif
       
   972 
       
   973     src = (const Uint16 *) cvt->buf;
       
   974     dst = (Uint16 *) cvt->buf;
       
   975     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
   976         const Uint16 val = SDL_SwapBE16(*src);
       
   977         *dst = SDL_SwapLE16(val);
       
   978     }
       
   979 
       
   980     if (cvt->filters[++cvt->filter_index]) {
       
   981         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
       
   982     }
       
   983 }
       
   984 
       
   985 static void SDLCALL
       
   986 SDL_Convert_U16MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
   987 {
       
   988     int i;
       
   989     const Uint16 *src;
       
   990     Sint16 *dst;
       
   991 
       
   992 #if DEBUG_CONVERT
       
   993     fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S16LSB.\n");
       
   994 #endif
       
   995 
       
   996     src = (const Uint16 *) cvt->buf;
       
   997     dst = (Sint16 *) cvt->buf;
       
   998     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
   999         const Sint16 val = ((SDL_SwapBE16(*src)) ^ 0x8000);
       
  1000         *dst = ((Sint16) SDL_SwapLE16(val));
       
  1001     }
       
  1002 
       
  1003     if (cvt->filters[++cvt->filter_index]) {
       
  1004         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
       
  1005     }
       
  1006 }
       
  1007 
       
  1008 static void SDLCALL
       
  1009 SDL_Convert_U16MSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1010 {
       
  1011     int i;
       
  1012     const Uint16 *src;
       
  1013     Sint16 *dst;
       
  1014 
       
  1015 #if DEBUG_CONVERT
       
  1016     fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S16MSB.\n");
       
  1017 #endif
       
  1018 
       
  1019     src = (const Uint16 *) cvt->buf;
       
  1020     dst = (Sint16 *) cvt->buf;
       
  1021     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
  1022         const Sint16 val = ((SDL_SwapBE16(*src)) ^ 0x8000);
       
  1023         *dst = ((Sint16) SDL_SwapBE16(val));
       
  1024     }
       
  1025 
       
  1026     if (cvt->filters[++cvt->filter_index]) {
       
  1027         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
       
  1028     }
       
  1029 }
       
  1030 
       
  1031 static void SDLCALL
       
  1032 SDL_Convert_U16MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1033 {
       
  1034     int i;
       
  1035     const Uint16 *src;
       
  1036     Sint32 *dst;
       
  1037 
       
  1038 #if DEBUG_CONVERT
       
  1039     fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S32LSB.\n");
       
  1040 #endif
       
  1041 
       
  1042     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
  1043     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
  1044     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
       
  1045         const Sint32 val = (((Sint32) ((SDL_SwapBE16(*src)) ^ 0x8000)) << 16);
       
  1046         *dst = ((Sint32) SDL_SwapLE32(val));
       
  1047     }
       
  1048 
       
  1049     cvt->len_cvt *= 2;
       
  1050     if (cvt->filters[++cvt->filter_index]) {
       
  1051         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
       
  1052     }
       
  1053 }
       
  1054 
       
  1055 static void SDLCALL
       
  1056 SDL_Convert_U16MSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1057 {
       
  1058     int i;
       
  1059     const Uint16 *src;
       
  1060     Sint32 *dst;
       
  1061 
       
  1062 #if DEBUG_CONVERT
       
  1063     fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S32MSB.\n");
       
  1064 #endif
       
  1065 
       
  1066     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
  1067     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
  1068     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
       
  1069         const Sint32 val = (((Sint32) ((SDL_SwapBE16(*src)) ^ 0x8000)) << 16);
       
  1070         *dst = ((Sint32) SDL_SwapBE32(val));
       
  1071     }
       
  1072 
       
  1073     cvt->len_cvt *= 2;
       
  1074     if (cvt->filters[++cvt->filter_index]) {
       
  1075         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
       
  1076     }
       
  1077 }
       
  1078 
       
  1079 static void SDLCALL
       
  1080 SDL_Convert_U16MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1081 {
       
  1082     int i;
       
  1083     const Uint16 *src;
       
  1084     float *dst;
       
  1085 
       
  1086 #if DEBUG_CONVERT
       
  1087     fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_F32LSB.\n");
       
  1088 #endif
       
  1089 
       
  1090     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
  1091     dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
  1092     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
       
  1093         const float val = ((((float) SDL_SwapBE16(*src)) * DIVBY32767) - 1.0f);
       
  1094         *dst = SDL_SwapFloatLE(val);
       
  1095     }
       
  1096 
       
  1097     cvt->len_cvt *= 2;
       
  1098     if (cvt->filters[++cvt->filter_index]) {
       
  1099         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
       
  1100     }
       
  1101 }
       
  1102 
       
  1103 static void SDLCALL
       
  1104 SDL_Convert_U16MSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1105 {
       
  1106     int i;
       
  1107     const Uint16 *src;
       
  1108     float *dst;
       
  1109 
       
  1110 #if DEBUG_CONVERT
       
  1111     fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_F32MSB.\n");
       
  1112 #endif
       
  1113 
       
  1114     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
  1115     dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
  1116     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
       
  1117         const float val = ((((float) SDL_SwapBE16(*src)) * DIVBY32767) - 1.0f);
       
  1118         *dst = SDL_SwapFloatBE(val);
       
  1119     }
       
  1120 
       
  1121     cvt->len_cvt *= 2;
       
  1122     if (cvt->filters[++cvt->filter_index]) {
       
  1123         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
       
  1124     }
       
  1125 }
       
  1126 
       
  1127 static void SDLCALL
       
  1128 SDL_Convert_S16MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1129 {
       
  1130     int i;
       
  1131     const Uint16 *src;
       
  1132     Uint8 *dst;
       
  1133 
       
  1134 #if DEBUG_CONVERT
       
  1135     fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_U8.\n");
       
  1136 #endif
       
  1137 
       
  1138     src = (const Uint16 *) cvt->buf;
       
  1139     dst = (Uint8 *) cvt->buf;
       
  1140     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
  1141         const Uint8 val = ((Uint8) (((((Sint16) SDL_SwapBE16(*src))) ^ 0x8000) >> 8));
       
  1142         *dst = val;
       
  1143     }
       
  1144 
       
  1145     cvt->len_cvt /= 2;
       
  1146     if (cvt->filters[++cvt->filter_index]) {
       
  1147         cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
       
  1148     }
       
  1149 }
       
  1150 
       
  1151 static void SDLCALL
       
  1152 SDL_Convert_S16MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1153 {
       
  1154     int i;
       
  1155     const Uint16 *src;
       
  1156     Sint8 *dst;
       
  1157 
       
  1158 #if DEBUG_CONVERT
       
  1159     fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S8.\n");
       
  1160 #endif
       
  1161 
       
  1162     src = (const Uint16 *) cvt->buf;
       
  1163     dst = (Sint8 *) cvt->buf;
       
  1164     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
  1165         const Sint8 val = ((Sint8) (((Sint16) SDL_SwapBE16(*src)) >> 8));
       
  1166         *dst = ((Sint8) val);
       
  1167     }
       
  1168 
       
  1169     cvt->len_cvt /= 2;
       
  1170     if (cvt->filters[++cvt->filter_index]) {
       
  1171         cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
       
  1172     }
       
  1173 }
       
  1174 
       
  1175 static void SDLCALL
       
  1176 SDL_Convert_S16MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1177 {
       
  1178     int i;
       
  1179     const Uint16 *src;
       
  1180     Uint16 *dst;
       
  1181 
       
  1182 #if DEBUG_CONVERT
       
  1183     fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_U16LSB.\n");
       
  1184 #endif
       
  1185 
       
  1186     src = (const Uint16 *) cvt->buf;
       
  1187     dst = (Uint16 *) cvt->buf;
       
  1188     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
  1189         const Uint16 val = ((((Sint16) SDL_SwapBE16(*src))) ^ 0x8000);
       
  1190         *dst = SDL_SwapLE16(val);
       
  1191     }
       
  1192 
       
  1193     if (cvt->filters[++cvt->filter_index]) {
       
  1194         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
       
  1195     }
       
  1196 }
       
  1197 
       
  1198 static void SDLCALL
       
  1199 SDL_Convert_S16MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1200 {
       
  1201     int i;
       
  1202     const Uint16 *src;
       
  1203     Sint16 *dst;
       
  1204 
       
  1205 #if DEBUG_CONVERT
       
  1206     fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S16LSB.\n");
       
  1207 #endif
       
  1208 
       
  1209     src = (const Uint16 *) cvt->buf;
       
  1210     dst = (Sint16 *) cvt->buf;
       
  1211     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
  1212         const Sint16 val = ((Sint16) SDL_SwapBE16(*src));
       
  1213         *dst = ((Sint16) SDL_SwapLE16(val));
       
  1214     }
       
  1215 
       
  1216     if (cvt->filters[++cvt->filter_index]) {
       
  1217         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
       
  1218     }
       
  1219 }
       
  1220 
       
  1221 static void SDLCALL
       
  1222 SDL_Convert_S16MSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1223 {
       
  1224     int i;
       
  1225     const Uint16 *src;
       
  1226     Uint16 *dst;
       
  1227 
       
  1228 #if DEBUG_CONVERT
       
  1229     fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_U16MSB.\n");
       
  1230 #endif
       
  1231 
       
  1232     src = (const Uint16 *) cvt->buf;
       
  1233     dst = (Uint16 *) cvt->buf;
       
  1234     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
       
  1235         const Uint16 val = ((((Sint16) SDL_SwapBE16(*src))) ^ 0x8000);
       
  1236         *dst = SDL_SwapBE16(val);
       
  1237     }
       
  1238 
       
  1239     if (cvt->filters[++cvt->filter_index]) {
       
  1240         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
       
  1241     }
       
  1242 }
       
  1243 
       
  1244 static void SDLCALL
       
  1245 SDL_Convert_S16MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1246 {
       
  1247     int i;
       
  1248     const Uint16 *src;
       
  1249     Sint32 *dst;
       
  1250 
       
  1251 #if DEBUG_CONVERT
       
  1252     fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S32LSB.\n");
       
  1253 #endif
       
  1254 
       
  1255     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
  1256     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
  1257     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
       
  1258         const Sint32 val = (((Sint32) ((Sint16) SDL_SwapBE16(*src))) << 16);
       
  1259         *dst = ((Sint32) SDL_SwapLE32(val));
       
  1260     }
       
  1261 
       
  1262     cvt->len_cvt *= 2;
       
  1263     if (cvt->filters[++cvt->filter_index]) {
       
  1264         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
       
  1265     }
       
  1266 }
       
  1267 
       
  1268 static void SDLCALL
       
  1269 SDL_Convert_S16MSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1270 {
       
  1271     int i;
       
  1272     const Uint16 *src;
       
  1273     Sint32 *dst;
       
  1274 
       
  1275 #if DEBUG_CONVERT
       
  1276     fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S32MSB.\n");
       
  1277 #endif
       
  1278 
       
  1279     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
  1280     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
  1281     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
       
  1282         const Sint32 val = (((Sint32) ((Sint16) SDL_SwapBE16(*src))) << 16);
       
  1283         *dst = ((Sint32) SDL_SwapBE32(val));
       
  1284     }
       
  1285 
       
  1286     cvt->len_cvt *= 2;
       
  1287     if (cvt->filters[++cvt->filter_index]) {
       
  1288         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
       
  1289     }
       
  1290 }
       
  1291 
       
  1292 static void SDLCALL
       
  1293 SDL_Convert_S16MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1294 {
       
  1295     int i;
       
  1296     const Uint16 *src;
       
  1297     float *dst;
       
  1298 
       
  1299 #if DEBUG_CONVERT
       
  1300     fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_F32LSB.\n");
       
  1301 #endif
       
  1302 
       
  1303     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
  1304     dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
  1305     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
       
  1306         const float val = (((float) ((Sint16) SDL_SwapBE16(*src))) * DIVBY32767);
       
  1307         *dst = SDL_SwapFloatLE(val);
       
  1308     }
       
  1309 
       
  1310     cvt->len_cvt *= 2;
       
  1311     if (cvt->filters[++cvt->filter_index]) {
       
  1312         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
       
  1313     }
       
  1314 }
       
  1315 
       
  1316 static void SDLCALL
       
  1317 SDL_Convert_S16MSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1318 {
       
  1319     int i;
       
  1320     const Uint16 *src;
       
  1321     float *dst;
       
  1322 
       
  1323 #if DEBUG_CONVERT
       
  1324     fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_F32MSB.\n");
       
  1325 #endif
       
  1326 
       
  1327     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
  1328     dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
       
  1329     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
       
  1330         const float val = (((float) ((Sint16) SDL_SwapBE16(*src))) * DIVBY32767);
       
  1331         *dst = SDL_SwapFloatBE(val);
       
  1332     }
       
  1333 
       
  1334     cvt->len_cvt *= 2;
       
  1335     if (cvt->filters[++cvt->filter_index]) {
       
  1336         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
       
  1337     }
       
  1338 }
       
  1339 
       
  1340 static void SDLCALL
       
  1341 SDL_Convert_S32LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1342 {
       
  1343     int i;
       
  1344     const Uint32 *src;
       
  1345     Uint8 *dst;
       
  1346 
       
  1347 #if DEBUG_CONVERT
       
  1348     fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_U8.\n");
       
  1349 #endif
       
  1350 
       
  1351     src = (const Uint32 *) cvt->buf;
       
  1352     dst = (Uint8 *) cvt->buf;
       
  1353     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
       
  1354         const Uint8 val = ((Uint8) (((((Sint32) SDL_SwapLE32(*src))) ^ 0x80000000) >> 24));
       
  1355         *dst = val;
       
  1356     }
       
  1357 
       
  1358     cvt->len_cvt /= 4;
       
  1359     if (cvt->filters[++cvt->filter_index]) {
       
  1360         cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
       
  1361     }
       
  1362 }
       
  1363 
       
  1364 static void SDLCALL
       
  1365 SDL_Convert_S32LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1366 {
       
  1367     int i;
       
  1368     const Uint32 *src;
       
  1369     Sint8 *dst;
       
  1370 
       
  1371 #if DEBUG_CONVERT
       
  1372     fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S8.\n");
       
  1373 #endif
       
  1374 
       
  1375     src = (const Uint32 *) cvt->buf;
       
  1376     dst = (Sint8 *) cvt->buf;
       
  1377     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
       
  1378         const Sint8 val = ((Sint8) (((Sint32) SDL_SwapLE32(*src)) >> 24));
       
  1379         *dst = ((Sint8) val);
       
  1380     }
       
  1381 
       
  1382     cvt->len_cvt /= 4;
       
  1383     if (cvt->filters[++cvt->filter_index]) {
       
  1384         cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
       
  1385     }
       
  1386 }
       
  1387 
       
  1388 static void SDLCALL
       
  1389 SDL_Convert_S32LSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1390 {
       
  1391     int i;
       
  1392     const Uint32 *src;
       
  1393     Uint16 *dst;
       
  1394 
       
  1395 #if DEBUG_CONVERT
       
  1396     fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_U16LSB.\n");
       
  1397 #endif
       
  1398 
       
  1399     src = (const Uint32 *) cvt->buf;
       
  1400     dst = (Uint16 *) cvt->buf;
       
  1401     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
       
  1402         const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapLE32(*src))) ^ 0x80000000) >> 16));
       
  1403         *dst = SDL_SwapLE16(val);
       
  1404     }
       
  1405 
       
  1406     cvt->len_cvt /= 2;
       
  1407     if (cvt->filters[++cvt->filter_index]) {
       
  1408         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
       
  1409     }
       
  1410 }
       
  1411 
       
  1412 static void SDLCALL
       
  1413 SDL_Convert_S32LSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1414 {
       
  1415     int i;
       
  1416     const Uint32 *src;
       
  1417     Sint16 *dst;
       
  1418 
       
  1419 #if DEBUG_CONVERT
       
  1420     fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S16LSB.\n");
       
  1421 #endif
       
  1422 
       
  1423     src = (const Uint32 *) cvt->buf;
       
  1424     dst = (Sint16 *) cvt->buf;
       
  1425     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
       
  1426         const Sint16 val = ((Sint16) (((Sint32) SDL_SwapLE32(*src)) >> 16));
       
  1427         *dst = ((Sint16) SDL_SwapLE16(val));
       
  1428     }
       
  1429 
       
  1430     cvt->len_cvt /= 2;
       
  1431     if (cvt->filters[++cvt->filter_index]) {
       
  1432         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
       
  1433     }
       
  1434 }
       
  1435 
       
  1436 static void SDLCALL
       
  1437 SDL_Convert_S32LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1438 {
       
  1439     int i;
       
  1440     const Uint32 *src;
       
  1441     Uint16 *dst;
       
  1442 
       
  1443 #if DEBUG_CONVERT
       
  1444     fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_U16MSB.\n");
       
  1445 #endif
       
  1446 
       
  1447     src = (const Uint32 *) cvt->buf;
       
  1448     dst = (Uint16 *) cvt->buf;
       
  1449     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
       
  1450         const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapLE32(*src))) ^ 0x80000000) >> 16));
       
  1451         *dst = SDL_SwapBE16(val);
       
  1452     }
       
  1453 
       
  1454     cvt->len_cvt /= 2;
       
  1455     if (cvt->filters[++cvt->filter_index]) {
       
  1456         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
       
  1457     }
       
  1458 }
       
  1459 
       
  1460 static void SDLCALL
       
  1461 SDL_Convert_S32LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1462 {
       
  1463     int i;
       
  1464     const Uint32 *src;
       
  1465     Sint16 *dst;
       
  1466 
       
  1467 #if DEBUG_CONVERT
       
  1468     fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S16MSB.\n");
       
  1469 #endif
       
  1470 
       
  1471     src = (const Uint32 *) cvt->buf;
       
  1472     dst = (Sint16 *) cvt->buf;
       
  1473     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
       
  1474         const Sint16 val = ((Sint16) (((Sint32) SDL_SwapLE32(*src)) >> 16));
       
  1475         *dst = ((Sint16) SDL_SwapBE16(val));
       
  1476     }
       
  1477 
       
  1478     cvt->len_cvt /= 2;
       
  1479     if (cvt->filters[++cvt->filter_index]) {
       
  1480         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
       
  1481     }
       
  1482 }
       
  1483 
       
  1484 static void SDLCALL
       
  1485 SDL_Convert_S32LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1486 {
       
  1487     int i;
       
  1488     const Uint32 *src;
       
  1489     Sint32 *dst;
       
  1490 
       
  1491 #if DEBUG_CONVERT
       
  1492     fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S32MSB.\n");
       
  1493 #endif
       
  1494 
       
  1495     src = (const Uint32 *) cvt->buf;
       
  1496     dst = (Sint32 *) cvt->buf;
       
  1497     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
       
  1498         const Sint32 val = ((Sint32) SDL_SwapLE32(*src));
       
  1499         *dst = ((Sint32) SDL_SwapBE32(val));
       
  1500     }
       
  1501 
       
  1502     if (cvt->filters[++cvt->filter_index]) {
       
  1503         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
       
  1504     }
       
  1505 }
       
  1506 
       
  1507 static void SDLCALL
       
  1508 SDL_Convert_S32LSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1509 {
       
  1510     int i;
       
  1511     const Uint32 *src;
       
  1512     float *dst;
       
  1513 
       
  1514 #if DEBUG_CONVERT
       
  1515     fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_F32LSB.\n");
       
  1516 #endif
       
  1517 
       
  1518     src = (const Uint32 *) cvt->buf;
       
  1519     dst = (float *) cvt->buf;
       
  1520     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
       
  1521         const float val = (((float) ((Sint32) SDL_SwapLE32(*src))) * DIVBY2147483647);
       
  1522         *dst = SDL_SwapFloatLE(val);
       
  1523     }
       
  1524 
       
  1525     if (cvt->filters[++cvt->filter_index]) {
       
  1526         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
       
  1527     }
       
  1528 }
       
  1529 
       
  1530 static void SDLCALL
       
  1531 SDL_Convert_S32LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1532 {
       
  1533     int i;
       
  1534     const Uint32 *src;
       
  1535     float *dst;
       
  1536 
       
  1537 #if DEBUG_CONVERT
       
  1538     fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_F32MSB.\n");
       
  1539 #endif
       
  1540 
       
  1541     src = (const Uint32 *) cvt->buf;
       
  1542     dst = (float *) cvt->buf;
       
  1543     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
       
  1544         const float val = (((float) ((Sint32) SDL_SwapLE32(*src))) * DIVBY2147483647);
       
  1545         *dst = SDL_SwapFloatBE(val);
       
  1546     }
       
  1547 
       
  1548     if (cvt->filters[++cvt->filter_index]) {
       
  1549         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
       
  1550     }
       
  1551 }
       
  1552 
       
  1553 static void SDLCALL
       
  1554 SDL_Convert_S32MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1555 {
       
  1556     int i;
       
  1557     const Uint32 *src;
       
  1558     Uint8 *dst;
       
  1559 
       
  1560 #if DEBUG_CONVERT
       
  1561     fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_U8.\n");
       
  1562 #endif
       
  1563 
       
  1564     src = (const Uint32 *) cvt->buf;
       
  1565     dst = (Uint8 *) cvt->buf;
       
  1566     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
       
  1567         const Uint8 val = ((Uint8) (((((Sint32) SDL_SwapBE32(*src))) ^ 0x80000000) >> 24));
       
  1568         *dst = val;
       
  1569     }
       
  1570 
       
  1571     cvt->len_cvt /= 4;
       
  1572     if (cvt->filters[++cvt->filter_index]) {
       
  1573         cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
       
  1574     }
       
  1575 }
       
  1576 
       
  1577 static void SDLCALL
       
  1578 SDL_Convert_S32MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1579 {
       
  1580     int i;
       
  1581     const Uint32 *src;
       
  1582     Sint8 *dst;
       
  1583 
       
  1584 #if DEBUG_CONVERT
       
  1585     fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S8.\n");
       
  1586 #endif
       
  1587 
       
  1588     src = (const Uint32 *) cvt->buf;
       
  1589     dst = (Sint8 *) cvt->buf;
       
  1590     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
       
  1591         const Sint8 val = ((Sint8) (((Sint32) SDL_SwapBE32(*src)) >> 24));
       
  1592         *dst = ((Sint8) val);
       
  1593     }
       
  1594 
       
  1595     cvt->len_cvt /= 4;
       
  1596     if (cvt->filters[++cvt->filter_index]) {
       
  1597         cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
       
  1598     }
       
  1599 }
       
  1600 
       
  1601 static void SDLCALL
       
  1602 SDL_Convert_S32MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1603 {
       
  1604     int i;
       
  1605     const Uint32 *src;
       
  1606     Uint16 *dst;
       
  1607 
       
  1608 #if DEBUG_CONVERT
       
  1609     fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_U16LSB.\n");
       
  1610 #endif
       
  1611 
       
  1612     src = (const Uint32 *) cvt->buf;
       
  1613     dst = (Uint16 *) cvt->buf;
       
  1614     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
       
  1615         const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapBE32(*src))) ^ 0x80000000) >> 16));
       
  1616         *dst = SDL_SwapLE16(val);
       
  1617     }
       
  1618 
       
  1619     cvt->len_cvt /= 2;
       
  1620     if (cvt->filters[++cvt->filter_index]) {
       
  1621         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
       
  1622     }
       
  1623 }
       
  1624 
       
  1625 static void SDLCALL
       
  1626 SDL_Convert_S32MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1627 {
       
  1628     int i;
       
  1629     const Uint32 *src;
       
  1630     Sint16 *dst;
       
  1631 
       
  1632 #if DEBUG_CONVERT
       
  1633     fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S16LSB.\n");
       
  1634 #endif
       
  1635 
       
  1636     src = (const Uint32 *) cvt->buf;
       
  1637     dst = (Sint16 *) cvt->buf;
       
  1638     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
       
  1639         const Sint16 val = ((Sint16) (((Sint32) SDL_SwapBE32(*src)) >> 16));
       
  1640         *dst = ((Sint16) SDL_SwapLE16(val));
       
  1641     }
       
  1642 
       
  1643     cvt->len_cvt /= 2;
       
  1644     if (cvt->filters[++cvt->filter_index]) {
       
  1645         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
       
  1646     }
       
  1647 }
       
  1648 
       
  1649 static void SDLCALL
       
  1650 SDL_Convert_S32MSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1651 {
       
  1652     int i;
       
  1653     const Uint32 *src;
       
  1654     Uint16 *dst;
       
  1655 
       
  1656 #if DEBUG_CONVERT
       
  1657     fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_U16MSB.\n");
       
  1658 #endif
       
  1659 
       
  1660     src = (const Uint32 *) cvt->buf;
       
  1661     dst = (Uint16 *) cvt->buf;
       
  1662     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
       
  1663         const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapBE32(*src))) ^ 0x80000000) >> 16));
       
  1664         *dst = SDL_SwapBE16(val);
       
  1665     }
       
  1666 
       
  1667     cvt->len_cvt /= 2;
       
  1668     if (cvt->filters[++cvt->filter_index]) {
       
  1669         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
       
  1670     }
       
  1671 }
       
  1672 
       
  1673 static void SDLCALL
       
  1674 SDL_Convert_S32MSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1675 {
       
  1676     int i;
       
  1677     const Uint32 *src;
       
  1678     Sint16 *dst;
       
  1679 
       
  1680 #if DEBUG_CONVERT
       
  1681     fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S16MSB.\n");
       
  1682 #endif
       
  1683 
       
  1684     src = (const Uint32 *) cvt->buf;
       
  1685     dst = (Sint16 *) cvt->buf;
       
  1686     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
       
  1687         const Sint16 val = ((Sint16) (((Sint32) SDL_SwapBE32(*src)) >> 16));
       
  1688         *dst = ((Sint16) SDL_SwapBE16(val));
       
  1689     }
       
  1690 
       
  1691     cvt->len_cvt /= 2;
       
  1692     if (cvt->filters[++cvt->filter_index]) {
       
  1693         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
       
  1694     }
       
  1695 }
       
  1696 
       
  1697 static void SDLCALL
       
  1698 SDL_Convert_S32MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1699 {
       
  1700     int i;
       
  1701     const Uint32 *src;
       
  1702     Sint32 *dst;
       
  1703 
       
  1704 #if DEBUG_CONVERT
       
  1705     fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S32LSB.\n");
       
  1706 #endif
       
  1707 
       
  1708     src = (const Uint32 *) cvt->buf;
       
  1709     dst = (Sint32 *) cvt->buf;
       
  1710     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
       
  1711         const Sint32 val = ((Sint32) SDL_SwapBE32(*src));
       
  1712         *dst = ((Sint32) SDL_SwapLE32(val));
       
  1713     }
       
  1714 
       
  1715     if (cvt->filters[++cvt->filter_index]) {
       
  1716         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
       
  1717     }
       
  1718 }
       
  1719 
       
  1720 static void SDLCALL
       
  1721 SDL_Convert_S32MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1722 {
       
  1723     int i;
       
  1724     const Uint32 *src;
       
  1725     float *dst;
       
  1726 
       
  1727 #if DEBUG_CONVERT
       
  1728     fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_F32LSB.\n");
       
  1729 #endif
       
  1730 
       
  1731     src = (const Uint32 *) cvt->buf;
       
  1732     dst = (float *) cvt->buf;
       
  1733     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
       
  1734         const float val = (((float) ((Sint32) SDL_SwapBE32(*src))) * DIVBY2147483647);
       
  1735         *dst = SDL_SwapFloatLE(val);
       
  1736     }
       
  1737 
       
  1738     if (cvt->filters[++cvt->filter_index]) {
       
  1739         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
       
  1740     }
       
  1741 }
       
  1742 
       
  1743 static void SDLCALL
       
  1744 SDL_Convert_S32MSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1745 {
       
  1746     int i;
       
  1747     const Uint32 *src;
       
  1748     float *dst;
       
  1749 
       
  1750 #if DEBUG_CONVERT
       
  1751     fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_F32MSB.\n");
       
  1752 #endif
       
  1753 
       
  1754     src = (const Uint32 *) cvt->buf;
       
  1755     dst = (float *) cvt->buf;
       
  1756     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
       
  1757         const float val = (((float) ((Sint32) SDL_SwapBE32(*src))) * DIVBY2147483647);
       
  1758         *dst = SDL_SwapFloatBE(val);
       
  1759     }
       
  1760 
       
  1761     if (cvt->filters[++cvt->filter_index]) {
       
  1762         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
       
  1763     }
       
  1764 }
       
  1765 
       
  1766 static void SDLCALL
       
  1767 SDL_Convert_F32LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1768 {
       
  1769     int i;
       
  1770     const float *src;
       
  1771     Uint8 *dst;
       
  1772 
       
  1773 #if DEBUG_CONVERT
       
  1774     fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_U8.\n");
       
  1775 #endif
       
  1776 
       
  1777     src = (const float *) cvt->buf;
       
  1778     dst = (Uint8 *) cvt->buf;
       
  1779     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
  1780         const Uint8 val = ((Uint8) ((SDL_SwapFloatLE(*src) + 1.0f) * 127.0f));
       
  1781         *dst = val;
       
  1782     }
       
  1783 
       
  1784     cvt->len_cvt /= 4;
       
  1785     if (cvt->filters[++cvt->filter_index]) {
       
  1786         cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
       
  1787     }
       
  1788 }
       
  1789 
       
  1790 static void SDLCALL
       
  1791 SDL_Convert_F32LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1792 {
       
  1793     int i;
       
  1794     const float *src;
       
  1795     Sint8 *dst;
       
  1796 
       
  1797 #if DEBUG_CONVERT
       
  1798     fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S8.\n");
       
  1799 #endif
       
  1800 
       
  1801     src = (const float *) cvt->buf;
       
  1802     dst = (Sint8 *) cvt->buf;
       
  1803     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
  1804         const Sint8 val = ((Sint8) (SDL_SwapFloatLE(*src) * 127.0f));
       
  1805         *dst = ((Sint8) val);
       
  1806     }
       
  1807 
       
  1808     cvt->len_cvt /= 4;
       
  1809     if (cvt->filters[++cvt->filter_index]) {
       
  1810         cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
       
  1811     }
       
  1812 }
       
  1813 
       
  1814 static void SDLCALL
       
  1815 SDL_Convert_F32LSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1816 {
       
  1817     int i;
       
  1818     const float *src;
       
  1819     Uint16 *dst;
       
  1820 
       
  1821 #if DEBUG_CONVERT
       
  1822     fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_U16LSB.\n");
       
  1823 #endif
       
  1824 
       
  1825     src = (const float *) cvt->buf;
       
  1826     dst = (Uint16 *) cvt->buf;
       
  1827     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
  1828         const Uint16 val = ((Uint16) ((SDL_SwapFloatLE(*src) + 1.0f) * 32767.0f));
       
  1829         *dst = SDL_SwapLE16(val);
       
  1830     }
       
  1831 
       
  1832     cvt->len_cvt /= 2;
       
  1833     if (cvt->filters[++cvt->filter_index]) {
       
  1834         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
       
  1835     }
       
  1836 }
       
  1837 
       
  1838 static void SDLCALL
       
  1839 SDL_Convert_F32LSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1840 {
       
  1841     int i;
       
  1842     const float *src;
       
  1843     Sint16 *dst;
       
  1844 
       
  1845 #if DEBUG_CONVERT
       
  1846     fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S16LSB.\n");
       
  1847 #endif
       
  1848 
       
  1849     src = (const float *) cvt->buf;
       
  1850     dst = (Sint16 *) cvt->buf;
       
  1851     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
  1852         const Sint16 val = ((Sint16) (SDL_SwapFloatLE(*src) * 32767.0f));
       
  1853         *dst = ((Sint16) SDL_SwapLE16(val));
       
  1854     }
       
  1855 
       
  1856     cvt->len_cvt /= 2;
       
  1857     if (cvt->filters[++cvt->filter_index]) {
       
  1858         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
       
  1859     }
       
  1860 }
       
  1861 
       
  1862 static void SDLCALL
       
  1863 SDL_Convert_F32LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1864 {
       
  1865     int i;
       
  1866     const float *src;
       
  1867     Uint16 *dst;
       
  1868 
       
  1869 #if DEBUG_CONVERT
       
  1870     fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_U16MSB.\n");
       
  1871 #endif
       
  1872 
       
  1873     src = (const float *) cvt->buf;
       
  1874     dst = (Uint16 *) cvt->buf;
       
  1875     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
  1876         const Uint16 val = ((Uint16) ((SDL_SwapFloatLE(*src) + 1.0f) * 32767.0f));
       
  1877         *dst = SDL_SwapBE16(val);
       
  1878     }
       
  1879 
       
  1880     cvt->len_cvt /= 2;
       
  1881     if (cvt->filters[++cvt->filter_index]) {
       
  1882         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
       
  1883     }
       
  1884 }
       
  1885 
       
  1886 static void SDLCALL
       
  1887 SDL_Convert_F32LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1888 {
       
  1889     int i;
       
  1890     const float *src;
       
  1891     Sint16 *dst;
       
  1892 
       
  1893 #if DEBUG_CONVERT
       
  1894     fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S16MSB.\n");
       
  1895 #endif
       
  1896 
       
  1897     src = (const float *) cvt->buf;
       
  1898     dst = (Sint16 *) cvt->buf;
       
  1899     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
  1900         const Sint16 val = ((Sint16) (SDL_SwapFloatLE(*src) * 32767.0f));
       
  1901         *dst = ((Sint16) SDL_SwapBE16(val));
       
  1902     }
       
  1903 
       
  1904     cvt->len_cvt /= 2;
       
  1905     if (cvt->filters[++cvt->filter_index]) {
       
  1906         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
       
  1907     }
       
  1908 }
       
  1909 
       
  1910 static void SDLCALL
       
  1911 SDL_Convert_F32LSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1912 {
       
  1913     int i;
       
  1914     const float *src;
       
  1915     Sint32 *dst;
       
  1916 
       
  1917 #if DEBUG_CONVERT
       
  1918     fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S32LSB.\n");
       
  1919 #endif
       
  1920 
       
  1921     src = (const float *) cvt->buf;
       
  1922     dst = (Sint32 *) cvt->buf;
       
  1923     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
  1924         const Sint32 val = ((Sint32) (SDL_SwapFloatLE(*src) * 2147483647.0));
       
  1925         *dst = ((Sint32) SDL_SwapLE32(val));
       
  1926     }
       
  1927 
       
  1928     if (cvt->filters[++cvt->filter_index]) {
       
  1929         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
       
  1930     }
       
  1931 }
       
  1932 
       
  1933 static void SDLCALL
       
  1934 SDL_Convert_F32LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1935 {
       
  1936     int i;
       
  1937     const float *src;
       
  1938     Sint32 *dst;
       
  1939 
       
  1940 #if DEBUG_CONVERT
       
  1941     fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S32MSB.\n");
       
  1942 #endif
       
  1943 
       
  1944     src = (const float *) cvt->buf;
       
  1945     dst = (Sint32 *) cvt->buf;
       
  1946     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
  1947         const Sint32 val = ((Sint32) (SDL_SwapFloatLE(*src) * 2147483647.0));
       
  1948         *dst = ((Sint32) SDL_SwapBE32(val));
       
  1949     }
       
  1950 
       
  1951     if (cvt->filters[++cvt->filter_index]) {
       
  1952         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
       
  1953     }
       
  1954 }
       
  1955 
       
  1956 static void SDLCALL
       
  1957 SDL_Convert_F32LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1958 {
       
  1959     int i;
       
  1960     const float *src;
       
  1961     float *dst;
       
  1962 
       
  1963 #if DEBUG_CONVERT
       
  1964     fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_F32MSB.\n");
       
  1965 #endif
       
  1966 
       
  1967     src = (const float *) cvt->buf;
       
  1968     dst = (float *) cvt->buf;
       
  1969     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
  1970         const float val = SDL_SwapFloatLE(*src);
       
  1971         *dst = SDL_SwapFloatBE(val);
       
  1972     }
       
  1973 
       
  1974     if (cvt->filters[++cvt->filter_index]) {
       
  1975         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
       
  1976     }
       
  1977 }
       
  1978 
       
  1979 static void SDLCALL
       
  1980 SDL_Convert_F32MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  1981 {
       
  1982     int i;
       
  1983     const float *src;
       
  1984     Uint8 *dst;
       
  1985 
       
  1986 #if DEBUG_CONVERT
       
  1987     fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_U8.\n");
       
  1988 #endif
       
  1989 
       
  1990     src = (const float *) cvt->buf;
       
  1991     dst = (Uint8 *) cvt->buf;
       
  1992     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
  1993         const Uint8 val = ((Uint8) ((SDL_SwapFloatBE(*src) + 1.0f) * 127.0f));
       
  1994         *dst = val;
       
  1995     }
       
  1996 
       
  1997     cvt->len_cvt /= 4;
       
  1998     if (cvt->filters[++cvt->filter_index]) {
       
  1999         cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
       
  2000     }
       
  2001 }
       
  2002 
       
  2003 static void SDLCALL
       
  2004 SDL_Convert_F32MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2005 {
       
  2006     int i;
       
  2007     const float *src;
       
  2008     Sint8 *dst;
       
  2009 
       
  2010 #if DEBUG_CONVERT
       
  2011     fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S8.\n");
       
  2012 #endif
       
  2013 
       
  2014     src = (const float *) cvt->buf;
       
  2015     dst = (Sint8 *) cvt->buf;
       
  2016     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
  2017         const Sint8 val = ((Sint8) (SDL_SwapFloatBE(*src) * 127.0f));
       
  2018         *dst = ((Sint8) val);
       
  2019     }
       
  2020 
       
  2021     cvt->len_cvt /= 4;
       
  2022     if (cvt->filters[++cvt->filter_index]) {
       
  2023         cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
       
  2024     }
       
  2025 }
       
  2026 
       
  2027 static void SDLCALL
       
  2028 SDL_Convert_F32MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2029 {
       
  2030     int i;
       
  2031     const float *src;
       
  2032     Uint16 *dst;
       
  2033 
       
  2034 #if DEBUG_CONVERT
       
  2035     fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_U16LSB.\n");
       
  2036 #endif
       
  2037 
       
  2038     src = (const float *) cvt->buf;
       
  2039     dst = (Uint16 *) cvt->buf;
       
  2040     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
  2041         const Uint16 val = ((Uint16) ((SDL_SwapFloatBE(*src) + 1.0f) * 32767.0f));
       
  2042         *dst = SDL_SwapLE16(val);
       
  2043     }
       
  2044 
       
  2045     cvt->len_cvt /= 2;
       
  2046     if (cvt->filters[++cvt->filter_index]) {
       
  2047         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
       
  2048     }
       
  2049 }
       
  2050 
       
  2051 static void SDLCALL
       
  2052 SDL_Convert_F32MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2053 {
       
  2054     int i;
       
  2055     const float *src;
       
  2056     Sint16 *dst;
       
  2057 
       
  2058 #if DEBUG_CONVERT
       
  2059     fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S16LSB.\n");
       
  2060 #endif
       
  2061 
       
  2062     src = (const float *) cvt->buf;
       
  2063     dst = (Sint16 *) cvt->buf;
       
  2064     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
  2065         const Sint16 val = ((Sint16) (SDL_SwapFloatBE(*src) * 32767.0f));
       
  2066         *dst = ((Sint16) SDL_SwapLE16(val));
       
  2067     }
       
  2068 
       
  2069     cvt->len_cvt /= 2;
       
  2070     if (cvt->filters[++cvt->filter_index]) {
       
  2071         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
       
  2072     }
       
  2073 }
       
  2074 
       
  2075 static void SDLCALL
       
  2076 SDL_Convert_F32MSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2077 {
       
  2078     int i;
       
  2079     const float *src;
       
  2080     Uint16 *dst;
       
  2081 
       
  2082 #if DEBUG_CONVERT
       
  2083     fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_U16MSB.\n");
       
  2084 #endif
       
  2085 
       
  2086     src = (const float *) cvt->buf;
       
  2087     dst = (Uint16 *) cvt->buf;
       
  2088     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
  2089         const Uint16 val = ((Uint16) ((SDL_SwapFloatBE(*src) + 1.0f) * 32767.0f));
       
  2090         *dst = SDL_SwapBE16(val);
       
  2091     }
       
  2092 
       
  2093     cvt->len_cvt /= 2;
       
  2094     if (cvt->filters[++cvt->filter_index]) {
       
  2095         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
       
  2096     }
       
  2097 }
       
  2098 
       
  2099 static void SDLCALL
       
  2100 SDL_Convert_F32MSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2101 {
       
  2102     int i;
       
  2103     const float *src;
       
  2104     Sint16 *dst;
       
  2105 
       
  2106 #if DEBUG_CONVERT
       
  2107     fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S16MSB.\n");
       
  2108 #endif
       
  2109 
       
  2110     src = (const float *) cvt->buf;
       
  2111     dst = (Sint16 *) cvt->buf;
       
  2112     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
  2113         const Sint16 val = ((Sint16) (SDL_SwapFloatBE(*src) * 32767.0f));
       
  2114         *dst = ((Sint16) SDL_SwapBE16(val));
       
  2115     }
       
  2116 
       
  2117     cvt->len_cvt /= 2;
       
  2118     if (cvt->filters[++cvt->filter_index]) {
       
  2119         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
       
  2120     }
       
  2121 }
       
  2122 
       
  2123 static void SDLCALL
       
  2124 SDL_Convert_F32MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2125 {
       
  2126     int i;
       
  2127     const float *src;
       
  2128     Sint32 *dst;
       
  2129 
       
  2130 #if DEBUG_CONVERT
       
  2131     fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S32LSB.\n");
       
  2132 #endif
       
  2133 
       
  2134     src = (const float *) cvt->buf;
       
  2135     dst = (Sint32 *) cvt->buf;
       
  2136     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
  2137         const Sint32 val = ((Sint32) (SDL_SwapFloatBE(*src) * 2147483647.0));
       
  2138         *dst = ((Sint32) SDL_SwapLE32(val));
       
  2139     }
       
  2140 
       
  2141     if (cvt->filters[++cvt->filter_index]) {
       
  2142         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
       
  2143     }
       
  2144 }
       
  2145 
       
  2146 static void SDLCALL
       
  2147 SDL_Convert_F32MSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2148 {
       
  2149     int i;
       
  2150     const float *src;
       
  2151     Sint32 *dst;
       
  2152 
       
  2153 #if DEBUG_CONVERT
       
  2154     fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S32MSB.\n");
       
  2155 #endif
       
  2156 
       
  2157     src = (const float *) cvt->buf;
       
  2158     dst = (Sint32 *) cvt->buf;
       
  2159     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
  2160         const Sint32 val = ((Sint32) (SDL_SwapFloatBE(*src) * 2147483647.0));
       
  2161         *dst = ((Sint32) SDL_SwapBE32(val));
       
  2162     }
       
  2163 
       
  2164     if (cvt->filters[++cvt->filter_index]) {
       
  2165         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
       
  2166     }
       
  2167 }
       
  2168 
       
  2169 static void SDLCALL
       
  2170 SDL_Convert_F32MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2171 {
       
  2172     int i;
       
  2173     const float *src;
       
  2174     float *dst;
       
  2175 
       
  2176 #if DEBUG_CONVERT
       
  2177     fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_F32LSB.\n");
       
  2178 #endif
       
  2179 
       
  2180     src = (const float *) cvt->buf;
       
  2181     dst = (float *) cvt->buf;
       
  2182     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
       
  2183         const float val = SDL_SwapFloatBE(*src);
       
  2184         *dst = SDL_SwapFloatLE(val);
       
  2185     }
       
  2186 
       
  2187     if (cvt->filters[++cvt->filter_index]) {
       
  2188         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
       
  2189     }
       
  2190 }
       
  2191 
       
  2192 #endif  /* !NO_CONVERTERS */
       
  2193 
       
  2194 
       
  2195 const SDL_AudioTypeFilters sdl_audio_type_filters[] =
       
  2196 {
       
  2197 #if !NO_CONVERTERS
       
  2198     { AUDIO_U8, AUDIO_S8, SDL_Convert_U8_to_S8 },
       
  2199     { AUDIO_U8, AUDIO_U16LSB, SDL_Convert_U8_to_U16LSB },
       
  2200     { AUDIO_U8, AUDIO_S16LSB, SDL_Convert_U8_to_S16LSB },
       
  2201     { AUDIO_U8, AUDIO_U16MSB, SDL_Convert_U8_to_U16MSB },
       
  2202     { AUDIO_U8, AUDIO_S16MSB, SDL_Convert_U8_to_S16MSB },
       
  2203     { AUDIO_U8, AUDIO_S32LSB, SDL_Convert_U8_to_S32LSB },
       
  2204     { AUDIO_U8, AUDIO_S32MSB, SDL_Convert_U8_to_S32MSB },
       
  2205     { AUDIO_U8, AUDIO_F32LSB, SDL_Convert_U8_to_F32LSB },
       
  2206     { AUDIO_U8, AUDIO_F32MSB, SDL_Convert_U8_to_F32MSB },
       
  2207     { AUDIO_S8, AUDIO_U8, SDL_Convert_S8_to_U8 },
       
  2208     { AUDIO_S8, AUDIO_U16LSB, SDL_Convert_S8_to_U16LSB },
       
  2209     { AUDIO_S8, AUDIO_S16LSB, SDL_Convert_S8_to_S16LSB },
       
  2210     { AUDIO_S8, AUDIO_U16MSB, SDL_Convert_S8_to_U16MSB },
       
  2211     { AUDIO_S8, AUDIO_S16MSB, SDL_Convert_S8_to_S16MSB },
       
  2212     { AUDIO_S8, AUDIO_S32LSB, SDL_Convert_S8_to_S32LSB },
       
  2213     { AUDIO_S8, AUDIO_S32MSB, SDL_Convert_S8_to_S32MSB },
       
  2214     { AUDIO_S8, AUDIO_F32LSB, SDL_Convert_S8_to_F32LSB },
       
  2215     { AUDIO_S8, AUDIO_F32MSB, SDL_Convert_S8_to_F32MSB },
       
  2216     { AUDIO_U16LSB, AUDIO_U8, SDL_Convert_U16LSB_to_U8 },
       
  2217     { AUDIO_U16LSB, AUDIO_S8, SDL_Convert_U16LSB_to_S8 },
       
  2218     { AUDIO_U16LSB, AUDIO_S16LSB, SDL_Convert_U16LSB_to_S16LSB },
       
  2219     { AUDIO_U16LSB, AUDIO_U16MSB, SDL_Convert_U16LSB_to_U16MSB },
       
  2220     { AUDIO_U16LSB, AUDIO_S16MSB, SDL_Convert_U16LSB_to_S16MSB },
       
  2221     { AUDIO_U16LSB, AUDIO_S32LSB, SDL_Convert_U16LSB_to_S32LSB },
       
  2222     { AUDIO_U16LSB, AUDIO_S32MSB, SDL_Convert_U16LSB_to_S32MSB },
       
  2223     { AUDIO_U16LSB, AUDIO_F32LSB, SDL_Convert_U16LSB_to_F32LSB },
       
  2224     { AUDIO_U16LSB, AUDIO_F32MSB, SDL_Convert_U16LSB_to_F32MSB },
       
  2225     { AUDIO_S16LSB, AUDIO_U8, SDL_Convert_S16LSB_to_U8 },
       
  2226     { AUDIO_S16LSB, AUDIO_S8, SDL_Convert_S16LSB_to_S8 },
       
  2227     { AUDIO_S16LSB, AUDIO_U16LSB, SDL_Convert_S16LSB_to_U16LSB },
       
  2228     { AUDIO_S16LSB, AUDIO_U16MSB, SDL_Convert_S16LSB_to_U16MSB },
       
  2229     { AUDIO_S16LSB, AUDIO_S16MSB, SDL_Convert_S16LSB_to_S16MSB },
       
  2230     { AUDIO_S16LSB, AUDIO_S32LSB, SDL_Convert_S16LSB_to_S32LSB },
       
  2231     { AUDIO_S16LSB, AUDIO_S32MSB, SDL_Convert_S16LSB_to_S32MSB },
       
  2232     { AUDIO_S16LSB, AUDIO_F32LSB, SDL_Convert_S16LSB_to_F32LSB },
       
  2233     { AUDIO_S16LSB, AUDIO_F32MSB, SDL_Convert_S16LSB_to_F32MSB },
       
  2234     { AUDIO_U16MSB, AUDIO_U8, SDL_Convert_U16MSB_to_U8 },
       
  2235     { AUDIO_U16MSB, AUDIO_S8, SDL_Convert_U16MSB_to_S8 },
       
  2236     { AUDIO_U16MSB, AUDIO_U16LSB, SDL_Convert_U16MSB_to_U16LSB },
       
  2237     { AUDIO_U16MSB, AUDIO_S16LSB, SDL_Convert_U16MSB_to_S16LSB },
       
  2238     { AUDIO_U16MSB, AUDIO_S16MSB, SDL_Convert_U16MSB_to_S16MSB },
       
  2239     { AUDIO_U16MSB, AUDIO_S32LSB, SDL_Convert_U16MSB_to_S32LSB },
       
  2240     { AUDIO_U16MSB, AUDIO_S32MSB, SDL_Convert_U16MSB_to_S32MSB },
       
  2241     { AUDIO_U16MSB, AUDIO_F32LSB, SDL_Convert_U16MSB_to_F32LSB },
       
  2242     { AUDIO_U16MSB, AUDIO_F32MSB, SDL_Convert_U16MSB_to_F32MSB },
       
  2243     { AUDIO_S16MSB, AUDIO_U8, SDL_Convert_S16MSB_to_U8 },
       
  2244     { AUDIO_S16MSB, AUDIO_S8, SDL_Convert_S16MSB_to_S8 },
       
  2245     { AUDIO_S16MSB, AUDIO_U16LSB, SDL_Convert_S16MSB_to_U16LSB },
       
  2246     { AUDIO_S16MSB, AUDIO_S16LSB, SDL_Convert_S16MSB_to_S16LSB },
       
  2247     { AUDIO_S16MSB, AUDIO_U16MSB, SDL_Convert_S16MSB_to_U16MSB },
       
  2248     { AUDIO_S16MSB, AUDIO_S32LSB, SDL_Convert_S16MSB_to_S32LSB },
       
  2249     { AUDIO_S16MSB, AUDIO_S32MSB, SDL_Convert_S16MSB_to_S32MSB },
       
  2250     { AUDIO_S16MSB, AUDIO_F32LSB, SDL_Convert_S16MSB_to_F32LSB },
       
  2251     { AUDIO_S16MSB, AUDIO_F32MSB, SDL_Convert_S16MSB_to_F32MSB },
       
  2252     { AUDIO_S32LSB, AUDIO_U8, SDL_Convert_S32LSB_to_U8 },
       
  2253     { AUDIO_S32LSB, AUDIO_S8, SDL_Convert_S32LSB_to_S8 },
       
  2254     { AUDIO_S32LSB, AUDIO_U16LSB, SDL_Convert_S32LSB_to_U16LSB },
       
  2255     { AUDIO_S32LSB, AUDIO_S16LSB, SDL_Convert_S32LSB_to_S16LSB },
       
  2256     { AUDIO_S32LSB, AUDIO_U16MSB, SDL_Convert_S32LSB_to_U16MSB },
       
  2257     { AUDIO_S32LSB, AUDIO_S16MSB, SDL_Convert_S32LSB_to_S16MSB },
       
  2258     { AUDIO_S32LSB, AUDIO_S32MSB, SDL_Convert_S32LSB_to_S32MSB },
       
  2259     { AUDIO_S32LSB, AUDIO_F32LSB, SDL_Convert_S32LSB_to_F32LSB },
       
  2260     { AUDIO_S32LSB, AUDIO_F32MSB, SDL_Convert_S32LSB_to_F32MSB },
       
  2261     { AUDIO_S32MSB, AUDIO_U8, SDL_Convert_S32MSB_to_U8 },
       
  2262     { AUDIO_S32MSB, AUDIO_S8, SDL_Convert_S32MSB_to_S8 },
       
  2263     { AUDIO_S32MSB, AUDIO_U16LSB, SDL_Convert_S32MSB_to_U16LSB },
       
  2264     { AUDIO_S32MSB, AUDIO_S16LSB, SDL_Convert_S32MSB_to_S16LSB },
       
  2265     { AUDIO_S32MSB, AUDIO_U16MSB, SDL_Convert_S32MSB_to_U16MSB },
       
  2266     { AUDIO_S32MSB, AUDIO_S16MSB, SDL_Convert_S32MSB_to_S16MSB },
       
  2267     { AUDIO_S32MSB, AUDIO_S32LSB, SDL_Convert_S32MSB_to_S32LSB },
       
  2268     { AUDIO_S32MSB, AUDIO_F32LSB, SDL_Convert_S32MSB_to_F32LSB },
       
  2269     { AUDIO_S32MSB, AUDIO_F32MSB, SDL_Convert_S32MSB_to_F32MSB },
       
  2270     { AUDIO_F32LSB, AUDIO_U8, SDL_Convert_F32LSB_to_U8 },
       
  2271     { AUDIO_F32LSB, AUDIO_S8, SDL_Convert_F32LSB_to_S8 },
       
  2272     { AUDIO_F32LSB, AUDIO_U16LSB, SDL_Convert_F32LSB_to_U16LSB },
       
  2273     { AUDIO_F32LSB, AUDIO_S16LSB, SDL_Convert_F32LSB_to_S16LSB },
       
  2274     { AUDIO_F32LSB, AUDIO_U16MSB, SDL_Convert_F32LSB_to_U16MSB },
       
  2275     { AUDIO_F32LSB, AUDIO_S16MSB, SDL_Convert_F32LSB_to_S16MSB },
       
  2276     { AUDIO_F32LSB, AUDIO_S32LSB, SDL_Convert_F32LSB_to_S32LSB },
       
  2277     { AUDIO_F32LSB, AUDIO_S32MSB, SDL_Convert_F32LSB_to_S32MSB },
       
  2278     { AUDIO_F32LSB, AUDIO_F32MSB, SDL_Convert_F32LSB_to_F32MSB },
       
  2279     { AUDIO_F32MSB, AUDIO_U8, SDL_Convert_F32MSB_to_U8 },
       
  2280     { AUDIO_F32MSB, AUDIO_S8, SDL_Convert_F32MSB_to_S8 },
       
  2281     { AUDIO_F32MSB, AUDIO_U16LSB, SDL_Convert_F32MSB_to_U16LSB },
       
  2282     { AUDIO_F32MSB, AUDIO_S16LSB, SDL_Convert_F32MSB_to_S16LSB },
       
  2283     { AUDIO_F32MSB, AUDIO_U16MSB, SDL_Convert_F32MSB_to_U16MSB },
       
  2284     { AUDIO_F32MSB, AUDIO_S16MSB, SDL_Convert_F32MSB_to_S16MSB },
       
  2285     { AUDIO_F32MSB, AUDIO_S32LSB, SDL_Convert_F32MSB_to_S32LSB },
       
  2286     { AUDIO_F32MSB, AUDIO_S32MSB, SDL_Convert_F32MSB_to_S32MSB },
       
  2287     { AUDIO_F32MSB, AUDIO_F32LSB, SDL_Convert_F32MSB_to_F32LSB },
       
  2288 #endif  /* !NO_CONVERTERS */
       
  2289     { 0, 0, NULL }
       
  2290 };
       
  2291 
       
  2292 
       
  2293 #if !NO_RESAMPLERS
       
  2294 
       
  2295 static void SDLCALL
       
  2296 SDL_Upsample_U8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2297 {
       
  2298 #if DEBUG_CONVERT
       
  2299     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U8, 1 channels.\n", cvt->rate_incr);
       
  2300 #endif
       
  2301 
       
  2302     const int srcsize = cvt->len_cvt - 16;
       
  2303     const int dstsize = (int) (((double)(cvt->len_cvt/1)) * cvt->rate_incr) * 1;
       
  2304     register int eps = 0;
       
  2305     Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 1;
       
  2306     const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
       
  2307     const Uint8 *target = ((const Uint8 *) cvt->buf);
       
  2308     Uint8 sample0 = src[0];
       
  2309     Uint8 last_sample0 = sample0;
       
  2310     while (dst >= target) {
   242     while (dst >= target) {
  2311         dst[0] = sample0;
   243         SDL_memcpy(dst, sample, cpy);
  2312         dst--;
       
  2313         eps += srcsize;
       
  2314         if ((eps << 1) >= dstsize) {
       
  2315             src--;
       
  2316             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
       
  2317             last_sample0 = sample0;
       
  2318             eps -= dstsize;
       
  2319         }
       
  2320     }
       
  2321     cvt->len_cvt = dstsize;
       
  2322     if (cvt->filters[++cvt->filter_index]) {
       
  2323         cvt->filters[cvt->filter_index] (cvt, format);
       
  2324     }
       
  2325 }
       
  2326 
       
  2327 static void SDLCALL
       
  2328 SDL_Downsample_U8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2329 {
       
  2330 #if DEBUG_CONVERT
       
  2331     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 1 channels.\n", cvt->rate_incr);
       
  2332 #endif
       
  2333 
       
  2334     const int srcsize = cvt->len_cvt - 16;
       
  2335     const int dstsize = (int) (((double)(cvt->len_cvt/1)) * cvt->rate_incr) * 1;
       
  2336     register int eps = 0;
       
  2337     Uint8 *dst = (Uint8 *) cvt->buf;
       
  2338     const Uint8 *src = (Uint8 *) cvt->buf;
       
  2339     const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
       
  2340     Uint8 sample0 = src[0];
       
  2341     Uint8 last_sample0 = sample0;
       
  2342     while (dst < target) {
       
  2343         src++;
       
  2344         eps += dstsize;
       
  2345         if ((eps << 1) >= srcsize) {
       
  2346             dst[0] = sample0;
       
  2347             dst++;
       
  2348             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
       
  2349             last_sample0 = sample0;
       
  2350             eps -= srcsize;
       
  2351         }
       
  2352     }
       
  2353     cvt->len_cvt = dstsize;
       
  2354     if (cvt->filters[++cvt->filter_index]) {
       
  2355         cvt->filters[cvt->filter_index] (cvt, format);
       
  2356     }
       
  2357 }
       
  2358 
       
  2359 static void SDLCALL
       
  2360 SDL_Upsample_U8_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2361 {
       
  2362 #if DEBUG_CONVERT
       
  2363     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U8, 2 channels.\n", cvt->rate_incr);
       
  2364 #endif
       
  2365 
       
  2366     const int srcsize = cvt->len_cvt - 32;
       
  2367     const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
       
  2368     register int eps = 0;
       
  2369     Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 2;
       
  2370     const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 2;
       
  2371     const Uint8 *target = ((const Uint8 *) cvt->buf);
       
  2372     Uint8 sample1 = src[1];
       
  2373     Uint8 sample0 = src[0];
       
  2374     Uint8 last_sample1 = sample1;
       
  2375     Uint8 last_sample0 = sample0;
       
  2376     while (dst >= target) {
       
  2377         dst[1] = sample1;
       
  2378         dst[0] = sample0;
       
  2379         dst -= 2;
       
  2380         eps += srcsize;
       
  2381         if ((eps << 1) >= dstsize) {
       
  2382             src -= 2;
       
  2383             sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
       
  2384             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
       
  2385             last_sample1 = sample1;
       
  2386             last_sample0 = sample0;
       
  2387             eps -= dstsize;
       
  2388         }
       
  2389     }
       
  2390     cvt->len_cvt = dstsize;
       
  2391     if (cvt->filters[++cvt->filter_index]) {
       
  2392         cvt->filters[cvt->filter_index] (cvt, format);
       
  2393     }
       
  2394 }
       
  2395 
       
  2396 static void SDLCALL
       
  2397 SDL_Downsample_U8_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2398 {
       
  2399 #if DEBUG_CONVERT
       
  2400     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 2 channels.\n", cvt->rate_incr);
       
  2401 #endif
       
  2402 
       
  2403     const int srcsize = cvt->len_cvt - 32;
       
  2404     const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
       
  2405     register int eps = 0;
       
  2406     Uint8 *dst = (Uint8 *) cvt->buf;
       
  2407     const Uint8 *src = (Uint8 *) cvt->buf;
       
  2408     const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
       
  2409     Uint8 sample0 = src[0];
       
  2410     Uint8 sample1 = src[1];
       
  2411     Uint8 last_sample0 = sample0;
       
  2412     Uint8 last_sample1 = sample1;
       
  2413     while (dst < target) {
       
  2414         src += 2;
       
  2415         eps += dstsize;
       
  2416         if ((eps << 1) >= srcsize) {
       
  2417             dst[0] = sample0;
       
  2418             dst[1] = sample1;
       
  2419             dst += 2;
       
  2420             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
       
  2421             sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
       
  2422             last_sample0 = sample0;
       
  2423             last_sample1 = sample1;
       
  2424             eps -= srcsize;
       
  2425         }
       
  2426     }
       
  2427     cvt->len_cvt = dstsize;
       
  2428     if (cvt->filters[++cvt->filter_index]) {
       
  2429         cvt->filters[cvt->filter_index] (cvt, format);
       
  2430     }
       
  2431 }
       
  2432 
       
  2433 static void SDLCALL
       
  2434 SDL_Upsample_U8_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2435 {
       
  2436 #if DEBUG_CONVERT
       
  2437     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U8, 4 channels.\n", cvt->rate_incr);
       
  2438 #endif
       
  2439 
       
  2440     const int srcsize = cvt->len_cvt - 64;
       
  2441     const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
       
  2442     register int eps = 0;
       
  2443     Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 4;
       
  2444     const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 4;
       
  2445     const Uint8 *target = ((const Uint8 *) cvt->buf);
       
  2446     Uint8 sample3 = src[3];
       
  2447     Uint8 sample2 = src[2];
       
  2448     Uint8 sample1 = src[1];
       
  2449     Uint8 sample0 = src[0];
       
  2450     Uint8 last_sample3 = sample3;
       
  2451     Uint8 last_sample2 = sample2;
       
  2452     Uint8 last_sample1 = sample1;
       
  2453     Uint8 last_sample0 = sample0;
       
  2454     while (dst >= target) {
       
  2455         dst[3] = sample3;
       
  2456         dst[2] = sample2;
       
  2457         dst[1] = sample1;
       
  2458         dst[0] = sample0;
       
  2459         dst -= 4;
       
  2460         eps += srcsize;
       
  2461         if ((eps << 1) >= dstsize) {
       
  2462             src -= 4;
       
  2463             sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
       
  2464             sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
       
  2465             sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
       
  2466             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
       
  2467             last_sample3 = sample3;
       
  2468             last_sample2 = sample2;
       
  2469             last_sample1 = sample1;
       
  2470             last_sample0 = sample0;
       
  2471             eps -= dstsize;
       
  2472         }
       
  2473     }
       
  2474     cvt->len_cvt = dstsize;
       
  2475     if (cvt->filters[++cvt->filter_index]) {
       
  2476         cvt->filters[cvt->filter_index] (cvt, format);
       
  2477     }
       
  2478 }
       
  2479 
       
  2480 static void SDLCALL
       
  2481 SDL_Downsample_U8_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2482 {
       
  2483 #if DEBUG_CONVERT
       
  2484     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 4 channels.\n", cvt->rate_incr);
       
  2485 #endif
       
  2486 
       
  2487     const int srcsize = cvt->len_cvt - 64;
       
  2488     const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
       
  2489     register int eps = 0;
       
  2490     Uint8 *dst = (Uint8 *) cvt->buf;
       
  2491     const Uint8 *src = (Uint8 *) cvt->buf;
       
  2492     const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
       
  2493     Uint8 sample0 = src[0];
       
  2494     Uint8 sample1 = src[1];
       
  2495     Uint8 sample2 = src[2];
       
  2496     Uint8 sample3 = src[3];
       
  2497     Uint8 last_sample0 = sample0;
       
  2498     Uint8 last_sample1 = sample1;
       
  2499     Uint8 last_sample2 = sample2;
       
  2500     Uint8 last_sample3 = sample3;
       
  2501     while (dst < target) {
       
  2502         src += 4;
       
  2503         eps += dstsize;
       
  2504         if ((eps << 1) >= srcsize) {
       
  2505             dst[0] = sample0;
       
  2506             dst[1] = sample1;
       
  2507             dst[2] = sample2;
       
  2508             dst[3] = sample3;
       
  2509             dst += 4;
       
  2510             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
       
  2511             sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
       
  2512             sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
       
  2513             sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
       
  2514             last_sample0 = sample0;
       
  2515             last_sample1 = sample1;
       
  2516             last_sample2 = sample2;
       
  2517             last_sample3 = sample3;
       
  2518             eps -= srcsize;
       
  2519         }
       
  2520     }
       
  2521     cvt->len_cvt = dstsize;
       
  2522     if (cvt->filters[++cvt->filter_index]) {
       
  2523         cvt->filters[cvt->filter_index] (cvt, format);
       
  2524     }
       
  2525 }
       
  2526 
       
  2527 static void SDLCALL
       
  2528 SDL_Upsample_U8_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2529 {
       
  2530 #if DEBUG_CONVERT
       
  2531     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U8, 6 channels.\n", cvt->rate_incr);
       
  2532 #endif
       
  2533 
       
  2534     const int srcsize = cvt->len_cvt - 96;
       
  2535     const int dstsize = (int) (((double)(cvt->len_cvt/6)) * cvt->rate_incr) * 6;
       
  2536     register int eps = 0;
       
  2537     Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 6;
       
  2538     const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 6;
       
  2539     const Uint8 *target = ((const Uint8 *) cvt->buf);
       
  2540     Uint8 sample5 = src[5];
       
  2541     Uint8 sample4 = src[4];
       
  2542     Uint8 sample3 = src[3];
       
  2543     Uint8 sample2 = src[2];
       
  2544     Uint8 sample1 = src[1];
       
  2545     Uint8 sample0 = src[0];
       
  2546     Uint8 last_sample5 = sample5;
       
  2547     Uint8 last_sample4 = sample4;
       
  2548     Uint8 last_sample3 = sample3;
       
  2549     Uint8 last_sample2 = sample2;
       
  2550     Uint8 last_sample1 = sample1;
       
  2551     Uint8 last_sample0 = sample0;
       
  2552     while (dst >= target) {
       
  2553         dst[5] = sample5;
       
  2554         dst[4] = sample4;
       
  2555         dst[3] = sample3;
       
  2556         dst[2] = sample2;
       
  2557         dst[1] = sample1;
       
  2558         dst[0] = sample0;
       
  2559         dst -= 6;
       
  2560         eps += srcsize;
       
  2561         if ((eps << 1) >= dstsize) {
       
  2562             src -= 6;
       
  2563             sample5 = (Uint8) ((((Sint16) src[5]) + ((Sint16) last_sample5)) >> 1);
       
  2564             sample4 = (Uint8) ((((Sint16) src[4]) + ((Sint16) last_sample4)) >> 1);
       
  2565             sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
       
  2566             sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
       
  2567             sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
       
  2568             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
       
  2569             last_sample5 = sample5;
       
  2570             last_sample4 = sample4;
       
  2571             last_sample3 = sample3;
       
  2572             last_sample2 = sample2;
       
  2573             last_sample1 = sample1;
       
  2574             last_sample0 = sample0;
       
  2575             eps -= dstsize;
       
  2576         }
       
  2577     }
       
  2578     cvt->len_cvt = dstsize;
       
  2579     if (cvt->filters[++cvt->filter_index]) {
       
  2580         cvt->filters[cvt->filter_index] (cvt, format);
       
  2581     }
       
  2582 }
       
  2583 
       
  2584 static void SDLCALL
       
  2585 SDL_Downsample_U8_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2586 {
       
  2587 #if DEBUG_CONVERT
       
  2588     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 6 channels.\n", cvt->rate_incr);
       
  2589 #endif
       
  2590 
       
  2591     const int srcsize = cvt->len_cvt - 96;
       
  2592     const int dstsize = (int) (((double)(cvt->len_cvt/6)) * cvt->rate_incr) * 6;
       
  2593     register int eps = 0;
       
  2594     Uint8 *dst = (Uint8 *) cvt->buf;
       
  2595     const Uint8 *src = (Uint8 *) cvt->buf;
       
  2596     const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
       
  2597     Uint8 sample0 = src[0];
       
  2598     Uint8 sample1 = src[1];
       
  2599     Uint8 sample2 = src[2];
       
  2600     Uint8 sample3 = src[3];
       
  2601     Uint8 sample4 = src[4];
       
  2602     Uint8 sample5 = src[5];
       
  2603     Uint8 last_sample0 = sample0;
       
  2604     Uint8 last_sample1 = sample1;
       
  2605     Uint8 last_sample2 = sample2;
       
  2606     Uint8 last_sample3 = sample3;
       
  2607     Uint8 last_sample4 = sample4;
       
  2608     Uint8 last_sample5 = sample5;
       
  2609     while (dst < target) {
       
  2610         src += 6;
       
  2611         eps += dstsize;
       
  2612         if ((eps << 1) >= srcsize) {
       
  2613             dst[0] = sample0;
       
  2614             dst[1] = sample1;
       
  2615             dst[2] = sample2;
       
  2616             dst[3] = sample3;
       
  2617             dst[4] = sample4;
       
  2618             dst[5] = sample5;
       
  2619             dst += 6;
       
  2620             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
       
  2621             sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
       
  2622             sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
       
  2623             sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
       
  2624             sample4 = (Uint8) ((((Sint16) src[4]) + ((Sint16) last_sample4)) >> 1);
       
  2625             sample5 = (Uint8) ((((Sint16) src[5]) + ((Sint16) last_sample5)) >> 1);
       
  2626             last_sample0 = sample0;
       
  2627             last_sample1 = sample1;
       
  2628             last_sample2 = sample2;
       
  2629             last_sample3 = sample3;
       
  2630             last_sample4 = sample4;
       
  2631             last_sample5 = sample5;
       
  2632             eps -= srcsize;
       
  2633         }
       
  2634     }
       
  2635     cvt->len_cvt = dstsize;
       
  2636     if (cvt->filters[++cvt->filter_index]) {
       
  2637         cvt->filters[cvt->filter_index] (cvt, format);
       
  2638     }
       
  2639 }
       
  2640 
       
  2641 static void SDLCALL
       
  2642 SDL_Upsample_U8_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2643 {
       
  2644 #if DEBUG_CONVERT
       
  2645     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U8, 8 channels.\n", cvt->rate_incr);
       
  2646 #endif
       
  2647 
       
  2648     const int srcsize = cvt->len_cvt - 128;
       
  2649     const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
       
  2650     register int eps = 0;
       
  2651     Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 8;
       
  2652     const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 8;
       
  2653     const Uint8 *target = ((const Uint8 *) cvt->buf);
       
  2654     Uint8 sample7 = src[7];
       
  2655     Uint8 sample6 = src[6];
       
  2656     Uint8 sample5 = src[5];
       
  2657     Uint8 sample4 = src[4];
       
  2658     Uint8 sample3 = src[3];
       
  2659     Uint8 sample2 = src[2];
       
  2660     Uint8 sample1 = src[1];
       
  2661     Uint8 sample0 = src[0];
       
  2662     Uint8 last_sample7 = sample7;
       
  2663     Uint8 last_sample6 = sample6;
       
  2664     Uint8 last_sample5 = sample5;
       
  2665     Uint8 last_sample4 = sample4;
       
  2666     Uint8 last_sample3 = sample3;
       
  2667     Uint8 last_sample2 = sample2;
       
  2668     Uint8 last_sample1 = sample1;
       
  2669     Uint8 last_sample0 = sample0;
       
  2670     while (dst >= target) {
       
  2671         dst[7] = sample7;
       
  2672         dst[6] = sample6;
       
  2673         dst[5] = sample5;
       
  2674         dst[4] = sample4;
       
  2675         dst[3] = sample3;
       
  2676         dst[2] = sample2;
       
  2677         dst[1] = sample1;
       
  2678         dst[0] = sample0;
       
  2679         dst -= 8;
   244         dst -= 8;
  2680         eps += srcsize;
   245         eps += srcsize;
  2681         if ((eps << 1) >= dstsize) {
   246         if ((eps << 1) >= dstsize) {
  2682             src -= 8;
   247             src -= 8;
  2683             sample7 = (Uint8) ((((Sint16) src[7]) + ((Sint16) last_sample7)) >> 1);
   248             for (i = 0; i < channels; i++) {
  2684             sample6 = (Uint8) ((((Sint16) src[6]) + ((Sint16) last_sample6)) >> 1);
   249                 sample[i] = (float) ((((double) src[i]) + ((double) last_sample[i])) * 0.5);
  2685             sample5 = (Uint8) ((((Sint16) src[5]) + ((Sint16) last_sample5)) >> 1);
   250             }
  2686             sample4 = (Uint8) ((((Sint16) src[4]) + ((Sint16) last_sample4)) >> 1);
   251             SDL_memcpy(last_sample, sample, cpy);
  2687             sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
       
  2688             sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
       
  2689             sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
       
  2690             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
       
  2691             last_sample7 = sample7;
       
  2692             last_sample6 = sample6;
       
  2693             last_sample5 = sample5;
       
  2694             last_sample4 = sample4;
       
  2695             last_sample3 = sample3;
       
  2696             last_sample2 = sample2;
       
  2697             last_sample1 = sample1;
       
  2698             last_sample0 = sample0;
       
  2699             eps -= dstsize;
   252             eps -= dstsize;
  2700         }
   253         }
  2701     }
   254     }
       
   255 
  2702     cvt->len_cvt = dstsize;
   256     cvt->len_cvt = dstsize;
  2703     if (cvt->filters[++cvt->filter_index]) {
   257     if (cvt->filters[++cvt->filter_index]) {
  2704         cvt->filters[cvt->filter_index] (cvt, format);
   258         cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
  2705     }
   259     }
  2706 }
   260 }
  2707 
   261 
  2708 static void SDLCALL
   262 void
  2709 SDL_Downsample_U8_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   263 SDL_Downsample_Arbitrary(SDL_AudioCVT *cvt, const int channels)
  2710 {
   264 {
       
   265     const int srcsize = cvt->len_cvt - (64 * channels);
       
   266     const int dstsize = (int) (((double)(cvt->len_cvt/(channels*4))) * cvt->rate_incr) * (channels*4);
       
   267     register int eps = 0;
       
   268     float *dst = (float *) cvt->buf;
       
   269     const float *src = (float *) cvt->buf;
       
   270     const float *target = (const float *) (cvt->buf + dstsize);
       
   271     const size_t cpy = sizeof (float) * channels;
       
   272     float last_sample[8];
       
   273     float sample[8];
       
   274     int i;
       
   275 
  2711 #if DEBUG_CONVERT
   276 #if DEBUG_CONVERT
  2712     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 8 channels.\n", cvt->rate_incr);
   277     fprintf(stderr, "Downsample arbitrary (x%f), %d channels.\n", cvt->rate_incr, channels);
  2713 #endif
   278 #endif
  2714 
   279 
  2715     const int srcsize = cvt->len_cvt - 128;
   280     SDL_assert(channels <= 8);
  2716     const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
   281 
  2717     register int eps = 0;
   282     SDL_memcpy(sample, src, cpy);
  2718     Uint8 *dst = (Uint8 *) cvt->buf;
   283     SDL_memcpy(last_sample, src, cpy);
  2719     const Uint8 *src = (Uint8 *) cvt->buf;
   284 
  2720     const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
       
  2721     Uint8 sample0 = src[0];
       
  2722     Uint8 sample1 = src[1];
       
  2723     Uint8 sample2 = src[2];
       
  2724     Uint8 sample3 = src[3];
       
  2725     Uint8 sample4 = src[4];
       
  2726     Uint8 sample5 = src[5];
       
  2727     Uint8 sample6 = src[6];
       
  2728     Uint8 sample7 = src[7];
       
  2729     Uint8 last_sample0 = sample0;
       
  2730     Uint8 last_sample1 = sample1;
       
  2731     Uint8 last_sample2 = sample2;
       
  2732     Uint8 last_sample3 = sample3;
       
  2733     Uint8 last_sample4 = sample4;
       
  2734     Uint8 last_sample5 = sample5;
       
  2735     Uint8 last_sample6 = sample6;
       
  2736     Uint8 last_sample7 = sample7;
       
  2737     while (dst < target) {
   285     while (dst < target) {
  2738         src += 8;
   286         src += 8;
  2739         eps += dstsize;
   287         eps += dstsize;
  2740         if ((eps << 1) >= srcsize) {
   288         if ((eps << 1) >= srcsize) {
  2741             dst[0] = sample0;
   289             SDL_memcpy(dst, sample, cpy);
  2742             dst[1] = sample1;
       
  2743             dst[2] = sample2;
       
  2744             dst[3] = sample3;
       
  2745             dst[4] = sample4;
       
  2746             dst[5] = sample5;
       
  2747             dst[6] = sample6;
       
  2748             dst[7] = sample7;
       
  2749             dst += 8;
   290             dst += 8;
  2750             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
   291             for (i = 0; i < channels; i++) {
  2751             sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
   292                 sample[i] = (float) ((((double) src[i]) + ((double) last_sample[i])) * 0.5);
  2752             sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
   293             }
  2753             sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
   294             SDL_memcpy(last_sample, sample, cpy);
  2754             sample4 = (Uint8) ((((Sint16) src[4]) + ((Sint16) last_sample4)) >> 1);
       
  2755             sample5 = (Uint8) ((((Sint16) src[5]) + ((Sint16) last_sample5)) >> 1);
       
  2756             sample6 = (Uint8) ((((Sint16) src[6]) + ((Sint16) last_sample6)) >> 1);
       
  2757             sample7 = (Uint8) ((((Sint16) src[7]) + ((Sint16) last_sample7)) >> 1);
       
  2758             last_sample0 = sample0;
       
  2759             last_sample1 = sample1;
       
  2760             last_sample2 = sample2;
       
  2761             last_sample3 = sample3;
       
  2762             last_sample4 = sample4;
       
  2763             last_sample5 = sample5;
       
  2764             last_sample6 = sample6;
       
  2765             last_sample7 = sample7;
       
  2766             eps -= srcsize;
   295             eps -= srcsize;
  2767         }
   296         }
  2768     }
   297     }
       
   298 
  2769     cvt->len_cvt = dstsize;
   299     cvt->len_cvt = dstsize;
  2770     if (cvt->filters[++cvt->filter_index]) {
   300     if (cvt->filters[++cvt->filter_index]) {
  2771         cvt->filters[cvt->filter_index] (cvt, format);
   301         cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
  2772     }
   302     }
  2773 }
   303 }
  2774 
   304 
  2775 static void SDLCALL
   305 void
  2776 SDL_Upsample_S8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   306 SDL_Upsample_x2(SDL_AudioCVT *cvt, const int channels)
  2777 {
   307 {
       
   308     const int dstsize = cvt->len_cvt * 2;
       
   309     float *dst = ((float *) (cvt->buf + dstsize)) - (channels * 2);
       
   310     const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - channels;
       
   311     const float *target = ((const float *) cvt->buf);
       
   312     const size_t cpy = sizeof (float) * channels;
       
   313     float last_sample[8];
       
   314     int i;
       
   315 
  2778 #if DEBUG_CONVERT
   316 #if DEBUG_CONVERT
  2779     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S8, 1 channels.\n", cvt->rate_incr);
   317     fprintf(stderr, "Upsample (x2), %d channels.\n", channels);
  2780 #endif
   318 #endif
  2781 
   319 
  2782     const int srcsize = cvt->len_cvt - 16;
   320     SDL_assert(channels <= 8);
  2783     const int dstsize = (int) (((double)(cvt->len_cvt/1)) * cvt->rate_incr) * 1;
   321     SDL_memcpy(last_sample, src, cpy);
  2784     register int eps = 0;
   322 
  2785     Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 1;
       
  2786     const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 1;
       
  2787     const Sint8 *target = ((const Sint8 *) cvt->buf);
       
  2788     Sint8 sample0 = ((Sint8) src[0]);
       
  2789     Sint8 last_sample0 = sample0;
       
  2790     while (dst >= target) {
   323     while (dst >= target) {
  2791         dst[0] = ((Sint8) sample0);
   324         for (i = 0; i < channels; i++) {
  2792         dst--;
   325             dst[i] = (float) ((((double)src[i]) + ((double)last_sample[i])) * 0.5);
  2793         eps += srcsize;
   326         }
  2794         if ((eps << 1) >= dstsize) {
   327         dst -= channels;
  2795             src--;
   328         SDL_memcpy(dst, src, cpy);
  2796             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
   329         SDL_memcpy(last_sample, src, cpy);
  2797             last_sample0 = sample0;
   330         src -= channels;
  2798             eps -= dstsize;
   331         dst -= channels;
  2799         }
   332     }
  2800     }
   333 
  2801     cvt->len_cvt = dstsize;
   334     cvt->len_cvt = dstsize;
  2802     if (cvt->filters[++cvt->filter_index]) {
   335     if (cvt->filters[++cvt->filter_index]) {
  2803         cvt->filters[cvt->filter_index] (cvt, format);
   336         cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
  2804     }
   337     }
  2805 }
   338 }
  2806 
   339 
  2807 static void SDLCALL
   340 void
  2808 SDL_Downsample_S8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   341 SDL_Upsample_x4(SDL_AudioCVT *cvt, const int channels)
  2809 {
   342 {
       
   343     const int dstsize = cvt->len_cvt * 4;
       
   344     float *dst = ((float *) (cvt->buf + dstsize)) - (channels * 4);
       
   345     const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - channels;
       
   346     const float *target = ((const float *) cvt->buf);
       
   347     const size_t cpy = sizeof (float) * channels;
       
   348     float last_sample[8];
       
   349     int i;
       
   350 
  2810 #if DEBUG_CONVERT
   351 #if DEBUG_CONVERT
  2811     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S8, 1 channels.\n", cvt->rate_incr);
   352     fprintf(stderr, "Upsample (x4), %d channels.\n", channels);
  2812 #endif
   353 #endif
  2813 
   354 
  2814     const int srcsize = cvt->len_cvt - 16;
   355     SDL_assert(channels <= 8);
  2815     const int dstsize = (int) (((double)(cvt->len_cvt/1)) * cvt->rate_incr) * 1;
   356     SDL_memcpy(last_sample, src, cpy);
  2816     register int eps = 0;
   357 
  2817     Sint8 *dst = (Sint8 *) cvt->buf;
   358     while (dst >= target) {
  2818     const Sint8 *src = (Sint8 *) cvt->buf;
   359         for (i = 0; i < channels; i++) {
  2819     const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
   360             dst[i] = (float) ((((double) src[i]) + (3.0 * ((double) last_sample[i]))) * 0.25);
  2820     Sint8 sample0 = ((Sint8) src[0]);
   361         }
  2821     Sint8 last_sample0 = sample0;
   362         dst -= channels;
  2822     while (dst < target) {
   363         for (i = 0; i < channels; i++) {
  2823         src++;
   364             dst[i] = (float) ((((double) src[i]) + ((double) last_sample[i])) * 0.25);
  2824         eps += dstsize;
   365         }
  2825         if ((eps << 1) >= srcsize) {
   366         dst -= channels;
  2826             dst[0] = ((Sint8) sample0);
   367         for (i = 0; i < channels; i++) {
  2827             dst++;
   368             dst[i] = (float) (((3.0 * ((double) src[i])) + ((double) last_sample[i])) * 0.25);
  2828             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
   369         }
  2829             last_sample0 = sample0;
   370         dst -= channels;
  2830             eps -= srcsize;
   371         SDL_memcpy(dst, src, cpy);
  2831         }
   372         dst -= channels;
  2832     }
   373         SDL_memcpy(last_sample, src, cpy);
       
   374         src -= channels;
       
   375     }
       
   376 
  2833     cvt->len_cvt = dstsize;
   377     cvt->len_cvt = dstsize;
  2834     if (cvt->filters[++cvt->filter_index]) {
   378     if (cvt->filters[++cvt->filter_index]) {
  2835         cvt->filters[cvt->filter_index] (cvt, format);
   379         cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
  2836     }
   380     }
  2837 }
   381 }
  2838 
   382 
  2839 static void SDLCALL
   383 void
  2840 SDL_Upsample_S8_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   384 SDL_Downsample_Multiple(SDL_AudioCVT *cvt, const int multiple, const int channels)
  2841 {
   385 {
  2842 #if DEBUG_CONVERT
   386     const int dstsize = cvt->len_cvt / multiple;
  2843     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S8, 2 channels.\n", cvt->rate_incr);
       
  2844 #endif
       
  2845 
       
  2846     const int srcsize = cvt->len_cvt - 32;
       
  2847     const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
       
  2848     register int eps = 0;
       
  2849     Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 2;
       
  2850     const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 2;
       
  2851     const Sint8 *target = ((const Sint8 *) cvt->buf);
       
  2852     Sint8 sample1 = ((Sint8) src[1]);
       
  2853     Sint8 sample0 = ((Sint8) src[0]);
       
  2854     Sint8 last_sample1 = sample1;
       
  2855     Sint8 last_sample0 = sample0;
       
  2856     while (dst >= target) {
       
  2857         dst[1] = ((Sint8) sample1);
       
  2858         dst[0] = ((Sint8) sample0);
       
  2859         dst -= 2;
       
  2860         eps += srcsize;
       
  2861         if ((eps << 1) >= dstsize) {
       
  2862             src -= 2;
       
  2863             sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
       
  2864             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
       
  2865             last_sample1 = sample1;
       
  2866             last_sample0 = sample0;
       
  2867             eps -= dstsize;
       
  2868         }
       
  2869     }
       
  2870     cvt->len_cvt = dstsize;
       
  2871     if (cvt->filters[++cvt->filter_index]) {
       
  2872         cvt->filters[cvt->filter_index] (cvt, format);
       
  2873     }
       
  2874 }
       
  2875 
       
  2876 static void SDLCALL
       
  2877 SDL_Downsample_S8_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2878 {
       
  2879 #if DEBUG_CONVERT
       
  2880     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S8, 2 channels.\n", cvt->rate_incr);
       
  2881 #endif
       
  2882 
       
  2883     const int srcsize = cvt->len_cvt - 32;
       
  2884     const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
       
  2885     register int eps = 0;
       
  2886     Sint8 *dst = (Sint8 *) cvt->buf;
       
  2887     const Sint8 *src = (Sint8 *) cvt->buf;
       
  2888     const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
       
  2889     Sint8 sample0 = ((Sint8) src[0]);
       
  2890     Sint8 sample1 = ((Sint8) src[1]);
       
  2891     Sint8 last_sample0 = sample0;
       
  2892     Sint8 last_sample1 = sample1;
       
  2893     while (dst < target) {
       
  2894         src += 2;
       
  2895         eps += dstsize;
       
  2896         if ((eps << 1) >= srcsize) {
       
  2897             dst[0] = ((Sint8) sample0);
       
  2898             dst[1] = ((Sint8) sample1);
       
  2899             dst += 2;
       
  2900             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
       
  2901             sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
       
  2902             last_sample0 = sample0;
       
  2903             last_sample1 = sample1;
       
  2904             eps -= srcsize;
       
  2905         }
       
  2906     }
       
  2907     cvt->len_cvt = dstsize;
       
  2908     if (cvt->filters[++cvt->filter_index]) {
       
  2909         cvt->filters[cvt->filter_index] (cvt, format);
       
  2910     }
       
  2911 }
       
  2912 
       
  2913 static void SDLCALL
       
  2914 SDL_Upsample_S8_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2915 {
       
  2916 #if DEBUG_CONVERT
       
  2917     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S8, 4 channels.\n", cvt->rate_incr);
       
  2918 #endif
       
  2919 
       
  2920     const int srcsize = cvt->len_cvt - 64;
       
  2921     const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
       
  2922     register int eps = 0;
       
  2923     Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 4;
       
  2924     const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 4;
       
  2925     const Sint8 *target = ((const Sint8 *) cvt->buf);
       
  2926     Sint8 sample3 = ((Sint8) src[3]);
       
  2927     Sint8 sample2 = ((Sint8) src[2]);
       
  2928     Sint8 sample1 = ((Sint8) src[1]);
       
  2929     Sint8 sample0 = ((Sint8) src[0]);
       
  2930     Sint8 last_sample3 = sample3;
       
  2931     Sint8 last_sample2 = sample2;
       
  2932     Sint8 last_sample1 = sample1;
       
  2933     Sint8 last_sample0 = sample0;
       
  2934     while (dst >= target) {
       
  2935         dst[3] = ((Sint8) sample3);
       
  2936         dst[2] = ((Sint8) sample2);
       
  2937         dst[1] = ((Sint8) sample1);
       
  2938         dst[0] = ((Sint8) sample0);
       
  2939         dst -= 4;
       
  2940         eps += srcsize;
       
  2941         if ((eps << 1) >= dstsize) {
       
  2942             src -= 4;
       
  2943             sample3 = (Sint8) ((((Sint16) ((Sint8) src[3])) + ((Sint16) last_sample3)) >> 1);
       
  2944             sample2 = (Sint8) ((((Sint16) ((Sint8) src[2])) + ((Sint16) last_sample2)) >> 1);
       
  2945             sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
       
  2946             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
       
  2947             last_sample3 = sample3;
       
  2948             last_sample2 = sample2;
       
  2949             last_sample1 = sample1;
       
  2950             last_sample0 = sample0;
       
  2951             eps -= dstsize;
       
  2952         }
       
  2953     }
       
  2954     cvt->len_cvt = dstsize;
       
  2955     if (cvt->filters[++cvt->filter_index]) {
       
  2956         cvt->filters[cvt->filter_index] (cvt, format);
       
  2957     }
       
  2958 }
       
  2959 
       
  2960 static void SDLCALL
       
  2961 SDL_Downsample_S8_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  2962 {
       
  2963 #if DEBUG_CONVERT
       
  2964     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S8, 4 channels.\n", cvt->rate_incr);
       
  2965 #endif
       
  2966 
       
  2967     const int srcsize = cvt->len_cvt - 64;
       
  2968     const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
       
  2969     register int eps = 0;
       
  2970     Sint8 *dst = (Sint8 *) cvt->buf;
       
  2971     const Sint8 *src = (Sint8 *) cvt->buf;
       
  2972     const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
       
  2973     Sint8 sample0 = ((Sint8) src[0]);
       
  2974     Sint8 sample1 = ((Sint8) src[1]);
       
  2975     Sint8 sample2 = ((Sint8) src[2]);
       
  2976     Sint8 sample3 = ((Sint8) src[3]);
       
  2977     Sint8 last_sample0 = sample0;
       
  2978     Sint8 last_sample1 = sample1;
       
  2979     Sint8 last_sample2 = sample2;
       
  2980     Sint8 last_sample3 = sample3;
       
  2981     while (dst < target) {
       
  2982         src += 4;
       
  2983         eps += dstsize;
       
  2984         if ((eps << 1) >= srcsize) {
       
  2985             dst[0] = ((Sint8) sample0);
       
  2986             dst[1] = ((Sint8) sample1);
       
  2987             dst[2] = ((Sint8) sample2);
       
  2988             dst[3] = ((Sint8) sample3);
       
  2989             dst += 4;
       
  2990             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
       
  2991             sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
       
  2992             sample2 = (Sint8) ((((Sint16) ((Sint8) src[2])) + ((Sint16) last_sample2)) >> 1);
       
  2993             sample3 = (Sint8) ((((Sint16) ((Sint8) src[3])) + ((Sint16) last_sample3)) >> 1);
       
  2994             last_sample0 = sample0;
       
  2995             last_sample1 = sample1;
       
  2996             last_sample2 = sample2;
       
  2997             last_sample3 = sample3;
       
  2998             eps -= srcsize;
       
  2999         }
       
  3000     }
       
  3001     cvt->len_cvt = dstsize;
       
  3002     if (cvt->filters[++cvt->filter_index]) {
       
  3003         cvt->filters[cvt->filter_index] (cvt, format);
       
  3004     }
       
  3005 }
       
  3006 
       
  3007 static void SDLCALL
       
  3008 SDL_Upsample_S8_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  3009 {
       
  3010 #if DEBUG_CONVERT
       
  3011     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S8, 6 channels.\n", cvt->rate_incr);
       
  3012 #endif
       
  3013 
       
  3014     const int srcsize = cvt->len_cvt - 96;
       
  3015     const int dstsize = (int) (((double)(cvt->len_cvt/6)) * cvt->rate_incr) * 6;
       
  3016     register int eps = 0;
       
  3017     Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 6;
       
  3018     const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 6;
       
  3019     const Sint8 *target = ((const Sint8 *) cvt->buf);
       
  3020     Sint8 sample5 = ((Sint8) src[5]);
       
  3021     Sint8 sample4 = ((Sint8) src[4]);
       
  3022     Sint8 sample3 = ((Sint8) src[3]);
       
  3023     Sint8 sample2 = ((Sint8) src[2]);
       
  3024     Sint8 sample1 = ((Sint8) src[1]);
       
  3025     Sint8 sample0 = ((Sint8) src[0]);
       
  3026     Sint8 last_sample5 = sample5;
       
  3027     Sint8 last_sample4 = sample4;
       
  3028     Sint8 last_sample3 = sample3;
       
  3029     Sint8 last_sample2 = sample2;
       
  3030     Sint8 last_sample1 = sample1;
       
  3031     Sint8 last_sample0 = sample0;
       
  3032     while (dst >= target) {
       
  3033         dst[5] = ((Sint8) sample5);
       
  3034         dst[4] = ((Sint8) sample4);
       
  3035         dst[3] = ((Sint8) sample3);
       
  3036         dst[2] = ((Sint8) sample2);
       
  3037         dst[1] = ((Sint8) sample1);
       
  3038         dst[0] = ((Sint8) sample0);
       
  3039         dst -= 6;
       
  3040         eps += srcsize;
       
  3041         if ((eps << 1) >= dstsize) {
       
  3042             src -= 6;
       
  3043             sample5 = (Sint8) ((((Sint16) ((Sint8) src[5])) + ((Sint16) last_sample5)) >> 1);
       
  3044             sample4 = (Sint8) ((((Sint16) ((Sint8) src[4])) + ((Sint16) last_sample4)) >> 1);
       
  3045             sample3 = (Sint8) ((((Sint16) ((Sint8) src[3])) + ((Sint16) last_sample3)) >> 1);
       
  3046             sample2 = (Sint8) ((((Sint16) ((Sint8) src[2])) + ((Sint16) last_sample2)) >> 1);
       
  3047             sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
       
  3048             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
       
  3049             last_sample5 = sample5;
       
  3050             last_sample4 = sample4;
       
  3051             last_sample3 = sample3;
       
  3052             last_sample2 = sample2;
       
  3053             last_sample1 = sample1;
       
  3054             last_sample0 = sample0;
       
  3055             eps -= dstsize;
       
  3056         }
       
  3057     }
       
  3058     cvt->len_cvt = dstsize;
       
  3059     if (cvt->filters[++cvt->filter_index]) {
       
  3060         cvt->filters[cvt->filter_index] (cvt, format);
       
  3061     }
       
  3062 }
       
  3063 
       
  3064 static void SDLCALL
       
  3065 SDL_Downsample_S8_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  3066 {
       
  3067 #if DEBUG_CONVERT
       
  3068     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S8, 6 channels.\n", cvt->rate_incr);
       
  3069 #endif
       
  3070 
       
  3071     const int srcsize = cvt->len_cvt - 96;
       
  3072     const int dstsize = (int) (((double)(cvt->len_cvt/6)) * cvt->rate_incr) * 6;
       
  3073     register int eps = 0;
       
  3074     Sint8 *dst = (Sint8 *) cvt->buf;
       
  3075     const Sint8 *src = (Sint8 *) cvt->buf;
       
  3076     const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
       
  3077     Sint8 sample0 = ((Sint8) src[0]);
       
  3078     Sint8 sample1 = ((Sint8) src[1]);
       
  3079     Sint8 sample2 = ((Sint8) src[2]);
       
  3080     Sint8 sample3 = ((Sint8) src[3]);
       
  3081     Sint8 sample4 = ((Sint8) src[4]);
       
  3082     Sint8 sample5 = ((Sint8) src[5]);
       
  3083     Sint8 last_sample0 = sample0;
       
  3084     Sint8 last_sample1 = sample1;
       
  3085     Sint8 last_sample2 = sample2;
       
  3086     Sint8 last_sample3 = sample3;
       
  3087     Sint8 last_sample4 = sample4;
       
  3088     Sint8 last_sample5 = sample5;
       
  3089     while (dst < target) {
       
  3090         src += 6;
       
  3091         eps += dstsize;
       
  3092         if ((eps << 1) >= srcsize) {
       
  3093             dst[0] = ((Sint8) sample0);
       
  3094             dst[1] = ((Sint8) sample1);
       
  3095             dst[2] = ((Sint8) sample2);
       
  3096             dst[3] = ((Sint8) sample3);
       
  3097             dst[4] = ((Sint8) sample4);
       
  3098             dst[5] = ((Sint8) sample5);
       
  3099             dst += 6;
       
  3100             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
       
  3101             sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
       
  3102             sample2 = (Sint8) ((((Sint16) ((Sint8) src[2])) + ((Sint16) last_sample2)) >> 1);
       
  3103             sample3 = (Sint8) ((((Sint16) ((Sint8) src[3])) + ((Sint16) last_sample3)) >> 1);
       
  3104             sample4 = (Sint8) ((((Sint16) ((Sint8) src[4])) + ((Sint16) last_sample4)) >> 1);
       
  3105             sample5 = (Sint8) ((((Sint16) ((Sint8) src[5])) + ((Sint16) last_sample5)) >> 1);
       
  3106             last_sample0 = sample0;
       
  3107             last_sample1 = sample1;
       
  3108             last_sample2 = sample2;
       
  3109             last_sample3 = sample3;
       
  3110             last_sample4 = sample4;
       
  3111             last_sample5 = sample5;
       
  3112             eps -= srcsize;
       
  3113         }
       
  3114     }
       
  3115     cvt->len_cvt = dstsize;
       
  3116     if (cvt->filters[++cvt->filter_index]) {
       
  3117         cvt->filters[cvt->filter_index] (cvt, format);
       
  3118     }
       
  3119 }
       
  3120 
       
  3121 static void SDLCALL
       
  3122 SDL_Upsample_S8_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  3123 {
       
  3124 #if DEBUG_CONVERT
       
  3125     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S8, 8 channels.\n", cvt->rate_incr);
       
  3126 #endif
       
  3127 
       
  3128     const int srcsize = cvt->len_cvt - 128;
       
  3129     const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
       
  3130     register int eps = 0;
       
  3131     Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 8;
       
  3132     const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 8;
       
  3133     const Sint8 *target = ((const Sint8 *) cvt->buf);
       
  3134     Sint8 sample7 = ((Sint8) src[7]);
       
  3135     Sint8 sample6 = ((Sint8) src[6]);
       
  3136     Sint8 sample5 = ((Sint8) src[5]);
       
  3137     Sint8 sample4 = ((Sint8) src[4]);
       
  3138     Sint8 sample3 = ((Sint8) src[3]);
       
  3139     Sint8 sample2 = ((Sint8) src[2]);
       
  3140     Sint8 sample1 = ((Sint8) src[1]);
       
  3141     Sint8 sample0 = ((Sint8) src[0]);
       
  3142     Sint8 last_sample7 = sample7;
       
  3143     Sint8 last_sample6 = sample6;
       
  3144     Sint8 last_sample5 = sample5;
       
  3145     Sint8 last_sample4 = sample4;
       
  3146     Sint8 last_sample3 = sample3;
       
  3147     Sint8 last_sample2 = sample2;
       
  3148     Sint8 last_sample1 = sample1;
       
  3149     Sint8 last_sample0 = sample0;
       
  3150     while (dst >= target) {
       
  3151         dst[7] = ((Sint8) sample7);
       
  3152         dst[6] = ((Sint8) sample6);
       
  3153         dst[5] = ((Sint8) sample5);
       
  3154         dst[4] = ((Sint8) sample4);
       
  3155         dst[3] = ((Sint8) sample3);
       
  3156         dst[2] = ((Sint8) sample2);
       
  3157         dst[1] = ((Sint8) sample1);
       
  3158         dst[0] = ((Sint8) sample0);
       
  3159         dst -= 8;
       
  3160         eps += srcsize;
       
  3161         if ((eps << 1) >= dstsize) {
       
  3162             src -= 8;
       
  3163             sample7 = (Sint8) ((((Sint16) ((Sint8) src[7])) + ((Sint16) last_sample7)) >> 1);
       
  3164             sample6 = (Sint8) ((((Sint16) ((Sint8) src[6])) + ((Sint16) last_sample6)) >> 1);
       
  3165             sample5 = (Sint8) ((((Sint16) ((Sint8) src[5])) + ((Sint16) last_sample5)) >> 1);
       
  3166             sample4 = (Sint8) ((((Sint16) ((Sint8) src[4])) + ((Sint16) last_sample4)) >> 1);
       
  3167             sample3 = (Sint8) ((((Sint16) ((Sint8) src[3])) + ((Sint16) last_sample3)) >> 1);
       
  3168             sample2 = (Sint8) ((((Sint16) ((Sint8) src[2])) + ((Sint16) last_sample2)) >> 1);
       
  3169             sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
       
  3170             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
       
  3171             last_sample7 = sample7;
       
  3172             last_sample6 = sample6;
       
  3173             last_sample5 = sample5;
       
  3174             last_sample4 = sample4;
       
  3175             last_sample3 = sample3;
       
  3176             last_sample2 = sample2;
       
  3177             last_sample1 = sample1;
       
  3178             last_sample0 = sample0;
       
  3179             eps -= dstsize;
       
  3180         }
       
  3181     }
       
  3182     cvt->len_cvt = dstsize;
       
  3183     if (cvt->filters[++cvt->filter_index]) {
       
  3184         cvt->filters[cvt->filter_index] (cvt, format);
       
  3185     }
       
  3186 }
       
  3187 
       
  3188 static void SDLCALL
       
  3189 SDL_Downsample_S8_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  3190 {
       
  3191 #if DEBUG_CONVERT
       
  3192     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S8, 8 channels.\n", cvt->rate_incr);
       
  3193 #endif
       
  3194 
       
  3195     const int srcsize = cvt->len_cvt - 128;
       
  3196     const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
       
  3197     register int eps = 0;
       
  3198     Sint8 *dst = (Sint8 *) cvt->buf;
       
  3199     const Sint8 *src = (Sint8 *) cvt->buf;
       
  3200     const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
       
  3201     Sint8 sample0 = ((Sint8) src[0]);
       
  3202     Sint8 sample1 = ((Sint8) src[1]);
       
  3203     Sint8 sample2 = ((Sint8) src[2]);
       
  3204     Sint8 sample3 = ((Sint8) src[3]);
       
  3205     Sint8 sample4 = ((Sint8) src[4]);
       
  3206     Sint8 sample5 = ((Sint8) src[5]);
       
  3207     Sint8 sample6 = ((Sint8) src[6]);
       
  3208     Sint8 sample7 = ((Sint8) src[7]);
       
  3209     Sint8 last_sample0 = sample0;
       
  3210     Sint8 last_sample1 = sample1;
       
  3211     Sint8 last_sample2 = sample2;
       
  3212     Sint8 last_sample3 = sample3;
       
  3213     Sint8 last_sample4 = sample4;
       
  3214     Sint8 last_sample5 = sample5;
       
  3215     Sint8 last_sample6 = sample6;
       
  3216     Sint8 last_sample7 = sample7;
       
  3217     while (dst < target) {
       
  3218         src += 8;
       
  3219         eps += dstsize;
       
  3220         if ((eps << 1) >= srcsize) {
       
  3221             dst[0] = ((Sint8) sample0);
       
  3222             dst[1] = ((Sint8) sample1);
       
  3223             dst[2] = ((Sint8) sample2);
       
  3224             dst[3] = ((Sint8) sample3);
       
  3225             dst[4] = ((Sint8) sample4);
       
  3226             dst[5] = ((Sint8) sample5);
       
  3227             dst[6] = ((Sint8) sample6);
       
  3228             dst[7] = ((Sint8) sample7);
       
  3229             dst += 8;
       
  3230             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
       
  3231             sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
       
  3232             sample2 = (Sint8) ((((Sint16) ((Sint8) src[2])) + ((Sint16) last_sample2)) >> 1);
       
  3233             sample3 = (Sint8) ((((Sint16) ((Sint8) src[3])) + ((Sint16) last_sample3)) >> 1);
       
  3234             sample4 = (Sint8) ((((Sint16) ((Sint8) src[4])) + ((Sint16) last_sample4)) >> 1);
       
  3235             sample5 = (Sint8) ((((Sint16) ((Sint8) src[5])) + ((Sint16) last_sample5)) >> 1);
       
  3236             sample6 = (Sint8) ((((Sint16) ((Sint8) src[6])) + ((Sint16) last_sample6)) >> 1);
       
  3237             sample7 = (Sint8) ((((Sint16) ((Sint8) src[7])) + ((Sint16) last_sample7)) >> 1);
       
  3238             last_sample0 = sample0;
       
  3239             last_sample1 = sample1;
       
  3240             last_sample2 = sample2;
       
  3241             last_sample3 = sample3;
       
  3242             last_sample4 = sample4;
       
  3243             last_sample5 = sample5;
       
  3244             last_sample6 = sample6;
       
  3245             last_sample7 = sample7;
       
  3246             eps -= srcsize;
       
  3247         }
       
  3248     }
       
  3249     cvt->len_cvt = dstsize;
       
  3250     if (cvt->filters[++cvt->filter_index]) {
       
  3251         cvt->filters[cvt->filter_index] (cvt, format);
       
  3252     }
       
  3253 }
       
  3254 
       
  3255 static void SDLCALL
       
  3256 SDL_Upsample_U16LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  3257 {
       
  3258 #if DEBUG_CONVERT
       
  3259     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16LSB, 1 channels.\n", cvt->rate_incr);
       
  3260 #endif
       
  3261 
       
  3262     const int srcsize = cvt->len_cvt - 32;
       
  3263     const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
       
  3264     register int eps = 0;
       
  3265     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 1;
       
  3266     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
  3267     const Uint16 *target = ((const Uint16 *) cvt->buf);
       
  3268     Uint16 sample0 = SDL_SwapLE16(src[0]);
       
  3269     Uint16 last_sample0 = sample0;
       
  3270     while (dst >= target) {
       
  3271         dst[0] = SDL_SwapLE16(sample0);
       
  3272         dst--;
       
  3273         eps += srcsize;
       
  3274         if ((eps << 1) >= dstsize) {
       
  3275             src--;
       
  3276             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
       
  3277             last_sample0 = sample0;
       
  3278             eps -= dstsize;
       
  3279         }
       
  3280     }
       
  3281     cvt->len_cvt = dstsize;
       
  3282     if (cvt->filters[++cvt->filter_index]) {
       
  3283         cvt->filters[cvt->filter_index] (cvt, format);
       
  3284     }
       
  3285 }
       
  3286 
       
  3287 static void SDLCALL
       
  3288 SDL_Downsample_U16LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  3289 {
       
  3290 #if DEBUG_CONVERT
       
  3291     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16LSB, 1 channels.\n", cvt->rate_incr);
       
  3292 #endif
       
  3293 
       
  3294     const int srcsize = cvt->len_cvt - 32;
       
  3295     const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
       
  3296     register int eps = 0;
       
  3297     Uint16 *dst = (Uint16 *) cvt->buf;
       
  3298     const Uint16 *src = (Uint16 *) cvt->buf;
       
  3299     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
       
  3300     Uint16 sample0 = SDL_SwapLE16(src[0]);
       
  3301     Uint16 last_sample0 = sample0;
       
  3302     while (dst < target) {
       
  3303         src++;
       
  3304         eps += dstsize;
       
  3305         if ((eps << 1) >= srcsize) {
       
  3306             dst[0] = SDL_SwapLE16(sample0);
       
  3307             dst++;
       
  3308             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
       
  3309             last_sample0 = sample0;
       
  3310             eps -= srcsize;
       
  3311         }
       
  3312     }
       
  3313     cvt->len_cvt = dstsize;
       
  3314     if (cvt->filters[++cvt->filter_index]) {
       
  3315         cvt->filters[cvt->filter_index] (cvt, format);
       
  3316     }
       
  3317 }
       
  3318 
       
  3319 static void SDLCALL
       
  3320 SDL_Upsample_U16LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  3321 {
       
  3322 #if DEBUG_CONVERT
       
  3323     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16LSB, 2 channels.\n", cvt->rate_incr);
       
  3324 #endif
       
  3325 
       
  3326     const int srcsize = cvt->len_cvt - 64;
       
  3327     const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
       
  3328     register int eps = 0;
       
  3329     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 2;
       
  3330     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 2;
       
  3331     const Uint16 *target = ((const Uint16 *) cvt->buf);
       
  3332     Uint16 sample1 = SDL_SwapLE16(src[1]);
       
  3333     Uint16 sample0 = SDL_SwapLE16(src[0]);
       
  3334     Uint16 last_sample1 = sample1;
       
  3335     Uint16 last_sample0 = sample0;
       
  3336     while (dst >= target) {
       
  3337         dst[1] = SDL_SwapLE16(sample1);
       
  3338         dst[0] = SDL_SwapLE16(sample0);
       
  3339         dst -= 2;
       
  3340         eps += srcsize;
       
  3341         if ((eps << 1) >= dstsize) {
       
  3342             src -= 2;
       
  3343             sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
       
  3344             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
       
  3345             last_sample1 = sample1;
       
  3346             last_sample0 = sample0;
       
  3347             eps -= dstsize;
       
  3348         }
       
  3349     }
       
  3350     cvt->len_cvt = dstsize;
       
  3351     if (cvt->filters[++cvt->filter_index]) {
       
  3352         cvt->filters[cvt->filter_index] (cvt, format);
       
  3353     }
       
  3354 }
       
  3355 
       
  3356 static void SDLCALL
       
  3357 SDL_Downsample_U16LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  3358 {
       
  3359 #if DEBUG_CONVERT
       
  3360     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16LSB, 2 channels.\n", cvt->rate_incr);
       
  3361 #endif
       
  3362 
       
  3363     const int srcsize = cvt->len_cvt - 64;
       
  3364     const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
       
  3365     register int eps = 0;
       
  3366     Uint16 *dst = (Uint16 *) cvt->buf;
       
  3367     const Uint16 *src = (Uint16 *) cvt->buf;
       
  3368     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
       
  3369     Uint16 sample0 = SDL_SwapLE16(src[0]);
       
  3370     Uint16 sample1 = SDL_SwapLE16(src[1]);
       
  3371     Uint16 last_sample0 = sample0;
       
  3372     Uint16 last_sample1 = sample1;
       
  3373     while (dst < target) {
       
  3374         src += 2;
       
  3375         eps += dstsize;
       
  3376         if ((eps << 1) >= srcsize) {
       
  3377             dst[0] = SDL_SwapLE16(sample0);
       
  3378             dst[1] = SDL_SwapLE16(sample1);
       
  3379             dst += 2;
       
  3380             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
       
  3381             sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
       
  3382             last_sample0 = sample0;
       
  3383             last_sample1 = sample1;
       
  3384             eps -= srcsize;
       
  3385         }
       
  3386     }
       
  3387     cvt->len_cvt = dstsize;
       
  3388     if (cvt->filters[++cvt->filter_index]) {
       
  3389         cvt->filters[cvt->filter_index] (cvt, format);
       
  3390     }
       
  3391 }
       
  3392 
       
  3393 static void SDLCALL
       
  3394 SDL_Upsample_U16LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  3395 {
       
  3396 #if DEBUG_CONVERT
       
  3397     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16LSB, 4 channels.\n", cvt->rate_incr);
       
  3398 #endif
       
  3399 
       
  3400     const int srcsize = cvt->len_cvt - 128;
       
  3401     const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
       
  3402     register int eps = 0;
       
  3403     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 4;
       
  3404     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 4;
       
  3405     const Uint16 *target = ((const Uint16 *) cvt->buf);
       
  3406     Uint16 sample3 = SDL_SwapLE16(src[3]);
       
  3407     Uint16 sample2 = SDL_SwapLE16(src[2]);
       
  3408     Uint16 sample1 = SDL_SwapLE16(src[1]);
       
  3409     Uint16 sample0 = SDL_SwapLE16(src[0]);
       
  3410     Uint16 last_sample3 = sample3;
       
  3411     Uint16 last_sample2 = sample2;
       
  3412     Uint16 last_sample1 = sample1;
       
  3413     Uint16 last_sample0 = sample0;
       
  3414     while (dst >= target) {
       
  3415         dst[3] = SDL_SwapLE16(sample3);
       
  3416         dst[2] = SDL_SwapLE16(sample2);
       
  3417         dst[1] = SDL_SwapLE16(sample1);
       
  3418         dst[0] = SDL_SwapLE16(sample0);
       
  3419         dst -= 4;
       
  3420         eps += srcsize;
       
  3421         if ((eps << 1) >= dstsize) {
       
  3422             src -= 4;
       
  3423             sample3 = (Uint16) ((((Sint32) SDL_SwapLE16(src[3])) + ((Sint32) last_sample3)) >> 1);
       
  3424             sample2 = (Uint16) ((((Sint32) SDL_SwapLE16(src[2])) + ((Sint32) last_sample2)) >> 1);
       
  3425             sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
       
  3426             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
       
  3427             last_sample3 = sample3;
       
  3428             last_sample2 = sample2;
       
  3429             last_sample1 = sample1;
       
  3430             last_sample0 = sample0;
       
  3431             eps -= dstsize;
       
  3432         }
       
  3433     }
       
  3434     cvt->len_cvt = dstsize;
       
  3435     if (cvt->filters[++cvt->filter_index]) {
       
  3436         cvt->filters[cvt->filter_index] (cvt, format);
       
  3437     }
       
  3438 }
       
  3439 
       
  3440 static void SDLCALL
       
  3441 SDL_Downsample_U16LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  3442 {
       
  3443 #if DEBUG_CONVERT
       
  3444     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16LSB, 4 channels.\n", cvt->rate_incr);
       
  3445 #endif
       
  3446 
       
  3447     const int srcsize = cvt->len_cvt - 128;
       
  3448     const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
       
  3449     register int eps = 0;
       
  3450     Uint16 *dst = (Uint16 *) cvt->buf;
       
  3451     const Uint16 *src = (Uint16 *) cvt->buf;
       
  3452     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
       
  3453     Uint16 sample0 = SDL_SwapLE16(src[0]);
       
  3454     Uint16 sample1 = SDL_SwapLE16(src[1]);
       
  3455     Uint16 sample2 = SDL_SwapLE16(src[2]);
       
  3456     Uint16 sample3 = SDL_SwapLE16(src[3]);
       
  3457     Uint16 last_sample0 = sample0;
       
  3458     Uint16 last_sample1 = sample1;
       
  3459     Uint16 last_sample2 = sample2;
       
  3460     Uint16 last_sample3 = sample3;
       
  3461     while (dst < target) {
       
  3462         src += 4;
       
  3463         eps += dstsize;
       
  3464         if ((eps << 1) >= srcsize) {
       
  3465             dst[0] = SDL_SwapLE16(sample0);
       
  3466             dst[1] = SDL_SwapLE16(sample1);
       
  3467             dst[2] = SDL_SwapLE16(sample2);
       
  3468             dst[3] = SDL_SwapLE16(sample3);
       
  3469             dst += 4;
       
  3470             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
       
  3471             sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
       
  3472             sample2 = (Uint16) ((((Sint32) SDL_SwapLE16(src[2])) + ((Sint32) last_sample2)) >> 1);
       
  3473             sample3 = (Uint16) ((((Sint32) SDL_SwapLE16(src[3])) + ((Sint32) last_sample3)) >> 1);
       
  3474             last_sample0 = sample0;
       
  3475             last_sample1 = sample1;
       
  3476             last_sample2 = sample2;
       
  3477             last_sample3 = sample3;
       
  3478             eps -= srcsize;
       
  3479         }
       
  3480     }
       
  3481     cvt->len_cvt = dstsize;
       
  3482     if (cvt->filters[++cvt->filter_index]) {
       
  3483         cvt->filters[cvt->filter_index] (cvt, format);
       
  3484     }
       
  3485 }
       
  3486 
       
  3487 static void SDLCALL
       
  3488 SDL_Upsample_U16LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  3489 {
       
  3490 #if DEBUG_CONVERT
       
  3491     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16LSB, 6 channels.\n", cvt->rate_incr);
       
  3492 #endif
       
  3493 
       
  3494     const int srcsize = cvt->len_cvt - 192;
       
  3495     const int dstsize = (int) (((double)(cvt->len_cvt/12)) * cvt->rate_incr) * 12;
       
  3496     register int eps = 0;
       
  3497     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 6;
       
  3498     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 6;
       
  3499     const Uint16 *target = ((const Uint16 *) cvt->buf);
       
  3500     Uint16 sample5 = SDL_SwapLE16(src[5]);
       
  3501     Uint16 sample4 = SDL_SwapLE16(src[4]);
       
  3502     Uint16 sample3 = SDL_SwapLE16(src[3]);
       
  3503     Uint16 sample2 = SDL_SwapLE16(src[2]);
       
  3504     Uint16 sample1 = SDL_SwapLE16(src[1]);
       
  3505     Uint16 sample0 = SDL_SwapLE16(src[0]);
       
  3506     Uint16 last_sample5 = sample5;
       
  3507     Uint16 last_sample4 = sample4;
       
  3508     Uint16 last_sample3 = sample3;
       
  3509     Uint16 last_sample2 = sample2;
       
  3510     Uint16 last_sample1 = sample1;
       
  3511     Uint16 last_sample0 = sample0;
       
  3512     while (dst >= target) {
       
  3513         dst[5] = SDL_SwapLE16(sample5);
       
  3514         dst[4] = SDL_SwapLE16(sample4);
       
  3515         dst[3] = SDL_SwapLE16(sample3);
       
  3516         dst[2] = SDL_SwapLE16(sample2);
       
  3517         dst[1] = SDL_SwapLE16(sample1);
       
  3518         dst[0] = SDL_SwapLE16(sample0);
       
  3519         dst -= 6;
       
  3520         eps += srcsize;
       
  3521         if ((eps << 1) >= dstsize) {
       
  3522             src -= 6;
       
  3523             sample5 = (Uint16) ((((Sint32) SDL_SwapLE16(src[5])) + ((Sint32) last_sample5)) >> 1);
       
  3524             sample4 = (Uint16) ((((Sint32) SDL_SwapLE16(src[4])) + ((Sint32) last_sample4)) >> 1);
       
  3525             sample3 = (Uint16) ((((Sint32) SDL_SwapLE16(src[3])) + ((Sint32) last_sample3)) >> 1);
       
  3526             sample2 = (Uint16) ((((Sint32) SDL_SwapLE16(src[2])) + ((Sint32) last_sample2)) >> 1);
       
  3527             sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
       
  3528             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
       
  3529             last_sample5 = sample5;
       
  3530             last_sample4 = sample4;
       
  3531             last_sample3 = sample3;
       
  3532             last_sample2 = sample2;
       
  3533             last_sample1 = sample1;
       
  3534             last_sample0 = sample0;
       
  3535             eps -= dstsize;
       
  3536         }
       
  3537     }
       
  3538     cvt->len_cvt = dstsize;
       
  3539     if (cvt->filters[++cvt->filter_index]) {
       
  3540         cvt->filters[cvt->filter_index] (cvt, format);
       
  3541     }
       
  3542 }
       
  3543 
       
  3544 static void SDLCALL
       
  3545 SDL_Downsample_U16LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  3546 {
       
  3547 #if DEBUG_CONVERT
       
  3548     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16LSB, 6 channels.\n", cvt->rate_incr);
       
  3549 #endif
       
  3550 
       
  3551     const int srcsize = cvt->len_cvt - 192;
       
  3552     const int dstsize = (int) (((double)(cvt->len_cvt/12)) * cvt->rate_incr) * 12;
       
  3553     register int eps = 0;
       
  3554     Uint16 *dst = (Uint16 *) cvt->buf;
       
  3555     const Uint16 *src = (Uint16 *) cvt->buf;
       
  3556     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
       
  3557     Uint16 sample0 = SDL_SwapLE16(src[0]);
       
  3558     Uint16 sample1 = SDL_SwapLE16(src[1]);
       
  3559     Uint16 sample2 = SDL_SwapLE16(src[2]);
       
  3560     Uint16 sample3 = SDL_SwapLE16(src[3]);
       
  3561     Uint16 sample4 = SDL_SwapLE16(src[4]);
       
  3562     Uint16 sample5 = SDL_SwapLE16(src[5]);
       
  3563     Uint16 last_sample0 = sample0;
       
  3564     Uint16 last_sample1 = sample1;
       
  3565     Uint16 last_sample2 = sample2;
       
  3566     Uint16 last_sample3 = sample3;
       
  3567     Uint16 last_sample4 = sample4;
       
  3568     Uint16 last_sample5 = sample5;
       
  3569     while (dst < target) {
       
  3570         src += 6;
       
  3571         eps += dstsize;
       
  3572         if ((eps << 1) >= srcsize) {
       
  3573             dst[0] = SDL_SwapLE16(sample0);
       
  3574             dst[1] = SDL_SwapLE16(sample1);
       
  3575             dst[2] = SDL_SwapLE16(sample2);
       
  3576             dst[3] = SDL_SwapLE16(sample3);
       
  3577             dst[4] = SDL_SwapLE16(sample4);
       
  3578             dst[5] = SDL_SwapLE16(sample5);
       
  3579             dst += 6;
       
  3580             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
       
  3581             sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
       
  3582             sample2 = (Uint16) ((((Sint32) SDL_SwapLE16(src[2])) + ((Sint32) last_sample2)) >> 1);
       
  3583             sample3 = (Uint16) ((((Sint32) SDL_SwapLE16(src[3])) + ((Sint32) last_sample3)) >> 1);
       
  3584             sample4 = (Uint16) ((((Sint32) SDL_SwapLE16(src[4])) + ((Sint32) last_sample4)) >> 1);
       
  3585             sample5 = (Uint16) ((((Sint32) SDL_SwapLE16(src[5])) + ((Sint32) last_sample5)) >> 1);
       
  3586             last_sample0 = sample0;
       
  3587             last_sample1 = sample1;
       
  3588             last_sample2 = sample2;
       
  3589             last_sample3 = sample3;
       
  3590             last_sample4 = sample4;
       
  3591             last_sample5 = sample5;
       
  3592             eps -= srcsize;
       
  3593         }
       
  3594     }
       
  3595     cvt->len_cvt = dstsize;
       
  3596     if (cvt->filters[++cvt->filter_index]) {
       
  3597         cvt->filters[cvt->filter_index] (cvt, format);
       
  3598     }
       
  3599 }
       
  3600 
       
  3601 static void SDLCALL
       
  3602 SDL_Upsample_U16LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  3603 {
       
  3604 #if DEBUG_CONVERT
       
  3605     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16LSB, 8 channels.\n", cvt->rate_incr);
       
  3606 #endif
       
  3607 
       
  3608     const int srcsize = cvt->len_cvt - 256;
       
  3609     const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
       
  3610     register int eps = 0;
       
  3611     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 8;
       
  3612     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 8;
       
  3613     const Uint16 *target = ((const Uint16 *) cvt->buf);
       
  3614     Uint16 sample7 = SDL_SwapLE16(src[7]);
       
  3615     Uint16 sample6 = SDL_SwapLE16(src[6]);
       
  3616     Uint16 sample5 = SDL_SwapLE16(src[5]);
       
  3617     Uint16 sample4 = SDL_SwapLE16(src[4]);
       
  3618     Uint16 sample3 = SDL_SwapLE16(src[3]);
       
  3619     Uint16 sample2 = SDL_SwapLE16(src[2]);
       
  3620     Uint16 sample1 = SDL_SwapLE16(src[1]);
       
  3621     Uint16 sample0 = SDL_SwapLE16(src[0]);
       
  3622     Uint16 last_sample7 = sample7;
       
  3623     Uint16 last_sample6 = sample6;
       
  3624     Uint16 last_sample5 = sample5;
       
  3625     Uint16 last_sample4 = sample4;
       
  3626     Uint16 last_sample3 = sample3;
       
  3627     Uint16 last_sample2 = sample2;
       
  3628     Uint16 last_sample1 = sample1;
       
  3629     Uint16 last_sample0 = sample0;
       
  3630     while (dst >= target) {
       
  3631         dst[7] = SDL_SwapLE16(sample7);
       
  3632         dst[6] = SDL_SwapLE16(sample6);
       
  3633         dst[5] = SDL_SwapLE16(sample5);
       
  3634         dst[4] = SDL_SwapLE16(sample4);
       
  3635         dst[3] = SDL_SwapLE16(sample3);
       
  3636         dst[2] = SDL_SwapLE16(sample2);
       
  3637         dst[1] = SDL_SwapLE16(sample1);
       
  3638         dst[0] = SDL_SwapLE16(sample0);
       
  3639         dst -= 8;
       
  3640         eps += srcsize;
       
  3641         if ((eps << 1) >= dstsize) {
       
  3642             src -= 8;
       
  3643             sample7 = (Uint16) ((((Sint32) SDL_SwapLE16(src[7])) + ((Sint32) last_sample7)) >> 1);
       
  3644             sample6 = (Uint16) ((((Sint32) SDL_SwapLE16(src[6])) + ((Sint32) last_sample6)) >> 1);
       
  3645             sample5 = (Uint16) ((((Sint32) SDL_SwapLE16(src[5])) + ((Sint32) last_sample5)) >> 1);
       
  3646             sample4 = (Uint16) ((((Sint32) SDL_SwapLE16(src[4])) + ((Sint32) last_sample4)) >> 1);
       
  3647             sample3 = (Uint16) ((((Sint32) SDL_SwapLE16(src[3])) + ((Sint32) last_sample3)) >> 1);
       
  3648             sample2 = (Uint16) ((((Sint32) SDL_SwapLE16(src[2])) + ((Sint32) last_sample2)) >> 1);
       
  3649             sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
       
  3650             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
       
  3651             last_sample7 = sample7;
       
  3652             last_sample6 = sample6;
       
  3653             last_sample5 = sample5;
       
  3654             last_sample4 = sample4;
       
  3655             last_sample3 = sample3;
       
  3656             last_sample2 = sample2;
       
  3657             last_sample1 = sample1;
       
  3658             last_sample0 = sample0;
       
  3659             eps -= dstsize;
       
  3660         }
       
  3661     }
       
  3662     cvt->len_cvt = dstsize;
       
  3663     if (cvt->filters[++cvt->filter_index]) {
       
  3664         cvt->filters[cvt->filter_index] (cvt, format);
       
  3665     }
       
  3666 }
       
  3667 
       
  3668 static void SDLCALL
       
  3669 SDL_Downsample_U16LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  3670 {
       
  3671 #if DEBUG_CONVERT
       
  3672     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16LSB, 8 channels.\n", cvt->rate_incr);
       
  3673 #endif
       
  3674 
       
  3675     const int srcsize = cvt->len_cvt - 256;
       
  3676     const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
       
  3677     register int eps = 0;
       
  3678     Uint16 *dst = (Uint16 *) cvt->buf;
       
  3679     const Uint16 *src = (Uint16 *) cvt->buf;
       
  3680     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
       
  3681     Uint16 sample0 = SDL_SwapLE16(src[0]);
       
  3682     Uint16 sample1 = SDL_SwapLE16(src[1]);
       
  3683     Uint16 sample2 = SDL_SwapLE16(src[2]);
       
  3684     Uint16 sample3 = SDL_SwapLE16(src[3]);
       
  3685     Uint16 sample4 = SDL_SwapLE16(src[4]);
       
  3686     Uint16 sample5 = SDL_SwapLE16(src[5]);
       
  3687     Uint16 sample6 = SDL_SwapLE16(src[6]);
       
  3688     Uint16 sample7 = SDL_SwapLE16(src[7]);
       
  3689     Uint16 last_sample0 = sample0;
       
  3690     Uint16 last_sample1 = sample1;
       
  3691     Uint16 last_sample2 = sample2;
       
  3692     Uint16 last_sample3 = sample3;
       
  3693     Uint16 last_sample4 = sample4;
       
  3694     Uint16 last_sample5 = sample5;
       
  3695     Uint16 last_sample6 = sample6;
       
  3696     Uint16 last_sample7 = sample7;
       
  3697     while (dst < target) {
       
  3698         src += 8;
       
  3699         eps += dstsize;
       
  3700         if ((eps << 1) >= srcsize) {
       
  3701             dst[0] = SDL_SwapLE16(sample0);
       
  3702             dst[1] = SDL_SwapLE16(sample1);
       
  3703             dst[2] = SDL_SwapLE16(sample2);
       
  3704             dst[3] = SDL_SwapLE16(sample3);
       
  3705             dst[4] = SDL_SwapLE16(sample4);
       
  3706             dst[5] = SDL_SwapLE16(sample5);
       
  3707             dst[6] = SDL_SwapLE16(sample6);
       
  3708             dst[7] = SDL_SwapLE16(sample7);
       
  3709             dst += 8;
       
  3710             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
       
  3711             sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
       
  3712             sample2 = (Uint16) ((((Sint32) SDL_SwapLE16(src[2])) + ((Sint32) last_sample2)) >> 1);
       
  3713             sample3 = (Uint16) ((((Sint32) SDL_SwapLE16(src[3])) + ((Sint32) last_sample3)) >> 1);
       
  3714             sample4 = (Uint16) ((((Sint32) SDL_SwapLE16(src[4])) + ((Sint32) last_sample4)) >> 1);
       
  3715             sample5 = (Uint16) ((((Sint32) SDL_SwapLE16(src[5])) + ((Sint32) last_sample5)) >> 1);
       
  3716             sample6 = (Uint16) ((((Sint32) SDL_SwapLE16(src[6])) + ((Sint32) last_sample6)) >> 1);
       
  3717             sample7 = (Uint16) ((((Sint32) SDL_SwapLE16(src[7])) + ((Sint32) last_sample7)) >> 1);
       
  3718             last_sample0 = sample0;
       
  3719             last_sample1 = sample1;
       
  3720             last_sample2 = sample2;
       
  3721             last_sample3 = sample3;
       
  3722             last_sample4 = sample4;
       
  3723             last_sample5 = sample5;
       
  3724             last_sample6 = sample6;
       
  3725             last_sample7 = sample7;
       
  3726             eps -= srcsize;
       
  3727         }
       
  3728     }
       
  3729     cvt->len_cvt = dstsize;
       
  3730     if (cvt->filters[++cvt->filter_index]) {
       
  3731         cvt->filters[cvt->filter_index] (cvt, format);
       
  3732     }
       
  3733 }
       
  3734 
       
  3735 static void SDLCALL
       
  3736 SDL_Upsample_S16LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  3737 {
       
  3738 #if DEBUG_CONVERT
       
  3739     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16LSB, 1 channels.\n", cvt->rate_incr);
       
  3740 #endif
       
  3741 
       
  3742     const int srcsize = cvt->len_cvt - 32;
       
  3743     const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
       
  3744     register int eps = 0;
       
  3745     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 1;
       
  3746     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 1;
       
  3747     const Sint16 *target = ((const Sint16 *) cvt->buf);
       
  3748     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
       
  3749     Sint16 last_sample0 = sample0;
       
  3750     while (dst >= target) {
       
  3751         dst[0] = ((Sint16) SDL_SwapLE16(sample0));
       
  3752         dst--;
       
  3753         eps += srcsize;
       
  3754         if ((eps << 1) >= dstsize) {
       
  3755             src--;
       
  3756             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
       
  3757             last_sample0 = sample0;
       
  3758             eps -= dstsize;
       
  3759         }
       
  3760     }
       
  3761     cvt->len_cvt = dstsize;
       
  3762     if (cvt->filters[++cvt->filter_index]) {
       
  3763         cvt->filters[cvt->filter_index] (cvt, format);
       
  3764     }
       
  3765 }
       
  3766 
       
  3767 static void SDLCALL
       
  3768 SDL_Downsample_S16LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  3769 {
       
  3770 #if DEBUG_CONVERT
       
  3771     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16LSB, 1 channels.\n", cvt->rate_incr);
       
  3772 #endif
       
  3773 
       
  3774     const int srcsize = cvt->len_cvt - 32;
       
  3775     const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
       
  3776     register int eps = 0;
       
  3777     Sint16 *dst = (Sint16 *) cvt->buf;
       
  3778     const Sint16 *src = (Sint16 *) cvt->buf;
       
  3779     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
       
  3780     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
       
  3781     Sint16 last_sample0 = sample0;
       
  3782     while (dst < target) {
       
  3783         src++;
       
  3784         eps += dstsize;
       
  3785         if ((eps << 1) >= srcsize) {
       
  3786             dst[0] = ((Sint16) SDL_SwapLE16(sample0));
       
  3787             dst++;
       
  3788             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
       
  3789             last_sample0 = sample0;
       
  3790             eps -= srcsize;
       
  3791         }
       
  3792     }
       
  3793     cvt->len_cvt = dstsize;
       
  3794     if (cvt->filters[++cvt->filter_index]) {
       
  3795         cvt->filters[cvt->filter_index] (cvt, format);
       
  3796     }
       
  3797 }
       
  3798 
       
  3799 static void SDLCALL
       
  3800 SDL_Upsample_S16LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  3801 {
       
  3802 #if DEBUG_CONVERT
       
  3803     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16LSB, 2 channels.\n", cvt->rate_incr);
       
  3804 #endif
       
  3805 
       
  3806     const int srcsize = cvt->len_cvt - 64;
       
  3807     const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
       
  3808     register int eps = 0;
       
  3809     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 2;
       
  3810     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 2;
       
  3811     const Sint16 *target = ((const Sint16 *) cvt->buf);
       
  3812     Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
       
  3813     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
       
  3814     Sint16 last_sample1 = sample1;
       
  3815     Sint16 last_sample0 = sample0;
       
  3816     while (dst >= target) {
       
  3817         dst[1] = ((Sint16) SDL_SwapLE16(sample1));
       
  3818         dst[0] = ((Sint16) SDL_SwapLE16(sample0));
       
  3819         dst -= 2;
       
  3820         eps += srcsize;
       
  3821         if ((eps << 1) >= dstsize) {
       
  3822             src -= 2;
       
  3823             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
       
  3824             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
       
  3825             last_sample1 = sample1;
       
  3826             last_sample0 = sample0;
       
  3827             eps -= dstsize;
       
  3828         }
       
  3829     }
       
  3830     cvt->len_cvt = dstsize;
       
  3831     if (cvt->filters[++cvt->filter_index]) {
       
  3832         cvt->filters[cvt->filter_index] (cvt, format);
       
  3833     }
       
  3834 }
       
  3835 
       
  3836 static void SDLCALL
       
  3837 SDL_Downsample_S16LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  3838 {
       
  3839 #if DEBUG_CONVERT
       
  3840     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16LSB, 2 channels.\n", cvt->rate_incr);
       
  3841 #endif
       
  3842 
       
  3843     const int srcsize = cvt->len_cvt - 64;
       
  3844     const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
       
  3845     register int eps = 0;
       
  3846     Sint16 *dst = (Sint16 *) cvt->buf;
       
  3847     const Sint16 *src = (Sint16 *) cvt->buf;
       
  3848     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
       
  3849     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
       
  3850     Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
       
  3851     Sint16 last_sample0 = sample0;
       
  3852     Sint16 last_sample1 = sample1;
       
  3853     while (dst < target) {
       
  3854         src += 2;
       
  3855         eps += dstsize;
       
  3856         if ((eps << 1) >= srcsize) {
       
  3857             dst[0] = ((Sint16) SDL_SwapLE16(sample0));
       
  3858             dst[1] = ((Sint16) SDL_SwapLE16(sample1));
       
  3859             dst += 2;
       
  3860             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
       
  3861             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
       
  3862             last_sample0 = sample0;
       
  3863             last_sample1 = sample1;
       
  3864             eps -= srcsize;
       
  3865         }
       
  3866     }
       
  3867     cvt->len_cvt = dstsize;
       
  3868     if (cvt->filters[++cvt->filter_index]) {
       
  3869         cvt->filters[cvt->filter_index] (cvt, format);
       
  3870     }
       
  3871 }
       
  3872 
       
  3873 static void SDLCALL
       
  3874 SDL_Upsample_S16LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
       
  3875 {
       
  3876 #if DEBUG_CONVERT
       
  3877     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16LSB, 4 channels.\n", cvt->rate_incr);
       
  3878 #endif
       
  3879