src/audio/SDL_audiotypecvt.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Sun, 22 Feb 2015 23:21:32 +0100
changeset 9373 679eb3986e37
parent 8857 6ec57a81e5d6
child 9619 b94b6d0bff0f
permissions -rw-r--r--
Emscripten: Fixed out of range joystick device index after joystick disconnect.

After disconnecting a joystick the remaining kept their original device index.
This was not correct because the device index must be a number between 0 and
SDL_NumJoysticks(). It was fixed with ideas from SDL's joystick implementation
for Android. Some range checks were removed as the caller already checks them.
     1 /* DO NOT EDIT!  This file is generated by sdlgenaudiocvt.pl */
     2 /*
     3   Simple DirectMedia Layer
     4   Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
     5 
     6   This software is provided 'as-is', without any express or implied
     7   warranty.  In no event will the authors be held liable for any damages
     8   arising from the use of this software.
     9 
    10   Permission is granted to anyone to use this software for any purpose,
    11   including commercial applications, and to alter it and redistribute it
    12   freely, subject to the following restrictions:
    13 
    14   1. The origin of this software must not be misrepresented; you must not
    15      claim that you wrote the original software. If you use this software
    16      in a product, an acknowledgment in the product documentation would be
    17      appreciated but is not required.
    18   2. Altered source versions must be plainly marked as such, and must not be
    19      misrepresented as being the original software.
    20   3. This notice may not be removed or altered from any source distribution.
    21 */
    22 
    23 #include "../SDL_internal.h"
    24 #include "SDL_audio.h"
    25 #include "SDL_audio_c.h"
    26 
    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 
    52 #define DIVBY127 0.0078740157480315f
    53 #define DIVBY32767 3.05185094759972e-05f
    54 #define DIVBY2147483647 4.6566128752458e-10f
    55 
    56 #if !NO_CONVERTERS
    57 
    58 static void SDLCALL
    59 SDL_Convert_U8_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
    60 {
    61     int i;
    62     const Uint8 *src;
    63     Sint8 *dst;
    64 
    65 #if DEBUG_CONVERT
    66     fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S8.\n");
    67 #endif
    68 
    69     src = (const Uint8 *) cvt->buf;
    70     dst = (Sint8 *) cvt->buf;
    71     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, ++src, ++dst) {
    72         const Sint8 val = ((*src) ^ 0x80);
    73         *dst = ((Sint8) val);
    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) {
  2311         dst[0] = sample0;
  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;
  2680         eps += srcsize;
  2681         if ((eps << 1) >= dstsize) {
  2682             src -= 8;
  2683             sample7 = (Uint8) ((((Sint16) src[7]) + ((Sint16) last_sample7)) >> 1);
  2684             sample6 = (Uint8) ((((Sint16) src[6]) + ((Sint16) last_sample6)) >> 1);
  2685             sample5 = (Uint8) ((((Sint16) src[5]) + ((Sint16) last_sample5)) >> 1);
  2686             sample4 = (Uint8) ((((Sint16) src[4]) + ((Sint16) last_sample4)) >> 1);
  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;
  2700         }
  2701     }
  2702     cvt->len_cvt = dstsize;
  2703     if (cvt->filters[++cvt->filter_index]) {
  2704         cvt->filters[cvt->filter_index] (cvt, format);
  2705     }
  2706 }
  2707 
  2708 static void SDLCALL
  2709 SDL_Downsample_U8_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2710 {
  2711 #if DEBUG_CONVERT
  2712     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 8 channels.\n", cvt->rate_incr);
  2713 #endif
  2714 
  2715     const int srcsize = cvt->len_cvt - 128;
  2716     const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
  2717     register int eps = 0;
  2718     Uint8 *dst = (Uint8 *) cvt->buf;
  2719     const Uint8 *src = (Uint8 *) cvt->buf;
  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) {
  2738         src += 8;
  2739         eps += dstsize;
  2740         if ((eps << 1) >= srcsize) {
  2741             dst[0] = sample0;
  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;
  2750             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
  2751             sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
  2752             sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
  2753             sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
  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;
  2767         }
  2768     }
  2769     cvt->len_cvt = dstsize;
  2770     if (cvt->filters[++cvt->filter_index]) {
  2771         cvt->filters[cvt->filter_index] (cvt, format);
  2772     }
  2773 }
  2774 
  2775 static void SDLCALL
  2776 SDL_Upsample_S8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2777 {
  2778 #if DEBUG_CONVERT
  2779     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S8, 1 channels.\n", cvt->rate_incr);
  2780 #endif
  2781 
  2782     const int srcsize = cvt->len_cvt - 16;
  2783     const int dstsize = (int) (((double)(cvt->len_cvt/1)) * cvt->rate_incr) * 1;
  2784     register int eps = 0;
  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) {
  2791         dst[0] = ((Sint8) sample0);
  2792         dst--;
  2793         eps += srcsize;
  2794         if ((eps << 1) >= dstsize) {
  2795             src--;
  2796             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
  2797             last_sample0 = sample0;
  2798             eps -= dstsize;
  2799         }
  2800     }
  2801     cvt->len_cvt = dstsize;
  2802     if (cvt->filters[++cvt->filter_index]) {
  2803         cvt->filters[cvt->filter_index] (cvt, format);
  2804     }
  2805 }
  2806 
  2807 static void SDLCALL
  2808 SDL_Downsample_S8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2809 {
  2810 #if DEBUG_CONVERT
  2811     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S8, 1 channels.\n", cvt->rate_incr);
  2812 #endif
  2813 
  2814     const int srcsize = cvt->len_cvt - 16;
  2815     const int dstsize = (int) (((double)(cvt->len_cvt/1)) * cvt->rate_incr) * 1;
  2816     register int eps = 0;
  2817     Sint8 *dst = (Sint8 *) cvt->buf;
  2818     const Sint8 *src = (Sint8 *) cvt->buf;
  2819     const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
  2820     Sint8 sample0 = ((Sint8) src[0]);
  2821     Sint8 last_sample0 = sample0;
  2822     while (dst < target) {
  2823         src++;
  2824         eps += dstsize;
  2825         if ((eps << 1) >= srcsize) {
  2826             dst[0] = ((Sint8) sample0);
  2827             dst++;
  2828             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
  2829             last_sample0 = sample0;
  2830             eps -= srcsize;
  2831         }
  2832     }
  2833     cvt->len_cvt = dstsize;
  2834     if (cvt->filters[++cvt->filter_index]) {
  2835         cvt->filters[cvt->filter_index] (cvt, format);
  2836     }
  2837 }
  2838 
  2839 static void SDLCALL
  2840 SDL_Upsample_S8_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2841 {
  2842 #if DEBUG_CONVERT
  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 
  3880     const int srcsize = cvt->len_cvt - 128;
  3881     const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
  3882     register int eps = 0;
  3883     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 4;
  3884     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 4;
  3885     const Sint16 *target = ((const Sint16 *) cvt->buf);
  3886     Sint16 sample3 = ((Sint16) SDL_SwapLE16(src[3]));
  3887     Sint16 sample2 = ((Sint16) SDL_SwapLE16(src[2]));
  3888     Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
  3889     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
  3890     Sint16 last_sample3 = sample3;
  3891     Sint16 last_sample2 = sample2;
  3892     Sint16 last_sample1 = sample1;
  3893     Sint16 last_sample0 = sample0;
  3894     while (dst >= target) {
  3895         dst[3] = ((Sint16) SDL_SwapLE16(sample3));
  3896         dst[2] = ((Sint16) SDL_SwapLE16(sample2));
  3897         dst[1] = ((Sint16) SDL_SwapLE16(sample1));
  3898         dst[0] = ((Sint16) SDL_SwapLE16(sample0));
  3899         dst -= 4;
  3900         eps += srcsize;
  3901         if ((eps << 1) >= dstsize) {
  3902             src -= 4;
  3903             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  3904             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  3905             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  3906             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  3907             last_sample3 = sample3;
  3908             last_sample2 = sample2;
  3909             last_sample1 = sample1;
  3910             last_sample0 = sample0;
  3911             eps -= dstsize;
  3912         }
  3913     }
  3914     cvt->len_cvt = dstsize;
  3915     if (cvt->filters[++cvt->filter_index]) {
  3916         cvt->filters[cvt->filter_index] (cvt, format);
  3917     }
  3918 }
  3919 
  3920 static void SDLCALL
  3921 SDL_Downsample_S16LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3922 {
  3923 #if DEBUG_CONVERT
  3924     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16LSB, 4 channels.\n", cvt->rate_incr);
  3925 #endif
  3926 
  3927     const int srcsize = cvt->len_cvt - 128;
  3928     const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
  3929     register int eps = 0;
  3930     Sint16 *dst = (Sint16 *) cvt->buf;
  3931     const Sint16 *src = (Sint16 *) cvt->buf;
  3932     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
  3933     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
  3934     Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
  3935     Sint16 sample2 = ((Sint16) SDL_SwapLE16(src[2]));
  3936     Sint16 sample3 = ((Sint16) SDL_SwapLE16(src[3]));
  3937     Sint16 last_sample0 = sample0;
  3938     Sint16 last_sample1 = sample1;
  3939     Sint16 last_sample2 = sample2;
  3940     Sint16 last_sample3 = sample3;
  3941     while (dst < target) {
  3942         src += 4;
  3943         eps += dstsize;
  3944         if ((eps << 1) >= srcsize) {
  3945             dst[0] = ((Sint16) SDL_SwapLE16(sample0));
  3946             dst[1] = ((Sint16) SDL_SwapLE16(sample1));
  3947             dst[2] = ((Sint16) SDL_SwapLE16(sample2));
  3948             dst[3] = ((Sint16) SDL_SwapLE16(sample3));
  3949             dst += 4;
  3950             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  3951             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  3952             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  3953             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  3954             last_sample0 = sample0;
  3955             last_sample1 = sample1;
  3956             last_sample2 = sample2;
  3957             last_sample3 = sample3;
  3958             eps -= srcsize;
  3959         }
  3960     }
  3961     cvt->len_cvt = dstsize;
  3962     if (cvt->filters[++cvt->filter_index]) {
  3963         cvt->filters[cvt->filter_index] (cvt, format);
  3964     }
  3965 }
  3966 
  3967 static void SDLCALL
  3968 SDL_Upsample_S16LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3969 {
  3970 #if DEBUG_CONVERT
  3971     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16LSB, 6 channels.\n", cvt->rate_incr);
  3972 #endif
  3973 
  3974     const int srcsize = cvt->len_cvt - 192;
  3975     const int dstsize = (int) (((double)(cvt->len_cvt/12)) * cvt->rate_incr) * 12;
  3976     register int eps = 0;
  3977     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 6;
  3978     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 6;
  3979     const Sint16 *target = ((const Sint16 *) cvt->buf);
  3980     Sint16 sample5 = ((Sint16) SDL_SwapLE16(src[5]));
  3981     Sint16 sample4 = ((Sint16) SDL_SwapLE16(src[4]));
  3982     Sint16 sample3 = ((Sint16) SDL_SwapLE16(src[3]));
  3983     Sint16 sample2 = ((Sint16) SDL_SwapLE16(src[2]));
  3984     Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
  3985     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
  3986     Sint16 last_sample5 = sample5;
  3987     Sint16 last_sample4 = sample4;
  3988     Sint16 last_sample3 = sample3;
  3989     Sint16 last_sample2 = sample2;
  3990     Sint16 last_sample1 = sample1;
  3991     Sint16 last_sample0 = sample0;
  3992     while (dst >= target) {
  3993         dst[5] = ((Sint16) SDL_SwapLE16(sample5));
  3994         dst[4] = ((Sint16) SDL_SwapLE16(sample4));
  3995         dst[3] = ((Sint16) SDL_SwapLE16(sample3));
  3996         dst[2] = ((Sint16) SDL_SwapLE16(sample2));
  3997         dst[1] = ((Sint16) SDL_SwapLE16(sample1));
  3998         dst[0] = ((Sint16) SDL_SwapLE16(sample0));
  3999         dst -= 6;
  4000         eps += srcsize;
  4001         if ((eps << 1) >= dstsize) {
  4002             src -= 6;
  4003             sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
  4004             sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
  4005             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  4006             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  4007             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  4008             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4009             last_sample5 = sample5;
  4010             last_sample4 = sample4;
  4011             last_sample3 = sample3;
  4012             last_sample2 = sample2;
  4013             last_sample1 = sample1;
  4014             last_sample0 = sample0;
  4015             eps -= dstsize;
  4016         }
  4017     }
  4018     cvt->len_cvt = dstsize;
  4019     if (cvt->filters[++cvt->filter_index]) {
  4020         cvt->filters[cvt->filter_index] (cvt, format);
  4021     }
  4022 }
  4023 
  4024 static void SDLCALL
  4025 SDL_Downsample_S16LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4026 {
  4027 #if DEBUG_CONVERT
  4028     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16LSB, 6 channels.\n", cvt->rate_incr);
  4029 #endif
  4030 
  4031     const int srcsize = cvt->len_cvt - 192;
  4032     const int dstsize = (int) (((double)(cvt->len_cvt/12)) * cvt->rate_incr) * 12;
  4033     register int eps = 0;
  4034     Sint16 *dst = (Sint16 *) cvt->buf;
  4035     const Sint16 *src = (Sint16 *) cvt->buf;
  4036     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
  4037     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
  4038     Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
  4039     Sint16 sample2 = ((Sint16) SDL_SwapLE16(src[2]));
  4040     Sint16 sample3 = ((Sint16) SDL_SwapLE16(src[3]));
  4041     Sint16 sample4 = ((Sint16) SDL_SwapLE16(src[4]));
  4042     Sint16 sample5 = ((Sint16) SDL_SwapLE16(src[5]));
  4043     Sint16 last_sample0 = sample0;
  4044     Sint16 last_sample1 = sample1;
  4045     Sint16 last_sample2 = sample2;
  4046     Sint16 last_sample3 = sample3;
  4047     Sint16 last_sample4 = sample4;
  4048     Sint16 last_sample5 = sample5;
  4049     while (dst < target) {
  4050         src += 6;
  4051         eps += dstsize;
  4052         if ((eps << 1) >= srcsize) {
  4053             dst[0] = ((Sint16) SDL_SwapLE16(sample0));
  4054             dst[1] = ((Sint16) SDL_SwapLE16(sample1));
  4055             dst[2] = ((Sint16) SDL_SwapLE16(sample2));
  4056             dst[3] = ((Sint16) SDL_SwapLE16(sample3));
  4057             dst[4] = ((Sint16) SDL_SwapLE16(sample4));
  4058             dst[5] = ((Sint16) SDL_SwapLE16(sample5));
  4059             dst += 6;
  4060             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4061             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  4062             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  4063             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  4064             sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
  4065             sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
  4066             last_sample0 = sample0;
  4067             last_sample1 = sample1;
  4068             last_sample2 = sample2;
  4069             last_sample3 = sample3;
  4070             last_sample4 = sample4;
  4071             last_sample5 = sample5;
  4072             eps -= srcsize;
  4073         }
  4074     }
  4075     cvt->len_cvt = dstsize;
  4076     if (cvt->filters[++cvt->filter_index]) {
  4077         cvt->filters[cvt->filter_index] (cvt, format);
  4078     }
  4079 }
  4080 
  4081 static void SDLCALL
  4082 SDL_Upsample_S16LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4083 {
  4084 #if DEBUG_CONVERT
  4085     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16LSB, 8 channels.\n", cvt->rate_incr);
  4086 #endif
  4087 
  4088     const int srcsize = cvt->len_cvt - 256;
  4089     const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
  4090     register int eps = 0;
  4091     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 8;
  4092     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 8;
  4093     const Sint16 *target = ((const Sint16 *) cvt->buf);
  4094     Sint16 sample7 = ((Sint16) SDL_SwapLE16(src[7]));
  4095     Sint16 sample6 = ((Sint16) SDL_SwapLE16(src[6]));
  4096     Sint16 sample5 = ((Sint16) SDL_SwapLE16(src[5]));
  4097     Sint16 sample4 = ((Sint16) SDL_SwapLE16(src[4]));
  4098     Sint16 sample3 = ((Sint16) SDL_SwapLE16(src[3]));
  4099     Sint16 sample2 = ((Sint16) SDL_SwapLE16(src[2]));
  4100     Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
  4101     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
  4102     Sint16 last_sample7 = sample7;
  4103     Sint16 last_sample6 = sample6;
  4104     Sint16 last_sample5 = sample5;
  4105     Sint16 last_sample4 = sample4;
  4106     Sint16 last_sample3 = sample3;
  4107     Sint16 last_sample2 = sample2;
  4108     Sint16 last_sample1 = sample1;
  4109     Sint16 last_sample0 = sample0;
  4110     while (dst >= target) {
  4111         dst[7] = ((Sint16) SDL_SwapLE16(sample7));
  4112         dst[6] = ((Sint16) SDL_SwapLE16(sample6));
  4113         dst[5] = ((Sint16) SDL_SwapLE16(sample5));
  4114         dst[4] = ((Sint16) SDL_SwapLE16(sample4));
  4115         dst[3] = ((Sint16) SDL_SwapLE16(sample3));
  4116         dst[2] = ((Sint16) SDL_SwapLE16(sample2));
  4117         dst[1] = ((Sint16) SDL_SwapLE16(sample1));
  4118         dst[0] = ((Sint16) SDL_SwapLE16(sample0));
  4119         dst -= 8;
  4120         eps += srcsize;
  4121         if ((eps << 1) >= dstsize) {
  4122             src -= 8;
  4123             sample7 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[7]))) + ((Sint32) last_sample7)) >> 1);
  4124             sample6 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[6]))) + ((Sint32) last_sample6)) >> 1);
  4125             sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
  4126             sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
  4127             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  4128             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  4129             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  4130             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4131             last_sample7 = sample7;
  4132             last_sample6 = sample6;
  4133             last_sample5 = sample5;
  4134             last_sample4 = sample4;
  4135             last_sample3 = sample3;
  4136             last_sample2 = sample2;
  4137             last_sample1 = sample1;
  4138             last_sample0 = sample0;
  4139             eps -= dstsize;
  4140         }
  4141     }
  4142     cvt->len_cvt = dstsize;
  4143     if (cvt->filters[++cvt->filter_index]) {
  4144         cvt->filters[cvt->filter_index] (cvt, format);
  4145     }
  4146 }
  4147 
  4148 static void SDLCALL
  4149 SDL_Downsample_S16LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4150 {
  4151 #if DEBUG_CONVERT
  4152     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16LSB, 8 channels.\n", cvt->rate_incr);
  4153 #endif
  4154 
  4155     const int srcsize = cvt->len_cvt - 256;
  4156     const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
  4157     register int eps = 0;
  4158     Sint16 *dst = (Sint16 *) cvt->buf;
  4159     const Sint16 *src = (Sint16 *) cvt->buf;
  4160     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
  4161     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
  4162     Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
  4163     Sint16 sample2 = ((Sint16) SDL_SwapLE16(src[2]));
  4164     Sint16 sample3 = ((Sint16) SDL_SwapLE16(src[3]));
  4165     Sint16 sample4 = ((Sint16) SDL_SwapLE16(src[4]));
  4166     Sint16 sample5 = ((Sint16) SDL_SwapLE16(src[5]));
  4167     Sint16 sample6 = ((Sint16) SDL_SwapLE16(src[6]));
  4168     Sint16 sample7 = ((Sint16) SDL_SwapLE16(src[7]));
  4169     Sint16 last_sample0 = sample0;
  4170     Sint16 last_sample1 = sample1;
  4171     Sint16 last_sample2 = sample2;
  4172     Sint16 last_sample3 = sample3;
  4173     Sint16 last_sample4 = sample4;
  4174     Sint16 last_sample5 = sample5;
  4175     Sint16 last_sample6 = sample6;
  4176     Sint16 last_sample7 = sample7;
  4177     while (dst < target) {
  4178         src += 8;
  4179         eps += dstsize;
  4180         if ((eps << 1) >= srcsize) {
  4181             dst[0] = ((Sint16) SDL_SwapLE16(sample0));
  4182             dst[1] = ((Sint16) SDL_SwapLE16(sample1));
  4183             dst[2] = ((Sint16) SDL_SwapLE16(sample2));
  4184             dst[3] = ((Sint16) SDL_SwapLE16(sample3));
  4185             dst[4] = ((Sint16) SDL_SwapLE16(sample4));
  4186             dst[5] = ((Sint16) SDL_SwapLE16(sample5));
  4187             dst[6] = ((Sint16) SDL_SwapLE16(sample6));
  4188             dst[7] = ((Sint16) SDL_SwapLE16(sample7));
  4189             dst += 8;
  4190             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4191             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  4192             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  4193             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  4194             sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
  4195             sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
  4196             sample6 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[6]))) + ((Sint32) last_sample6)) >> 1);
  4197             sample7 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[7]))) + ((Sint32) last_sample7)) >> 1);
  4198             last_sample0 = sample0;
  4199             last_sample1 = sample1;
  4200             last_sample2 = sample2;
  4201             last_sample3 = sample3;
  4202             last_sample4 = sample4;
  4203             last_sample5 = sample5;
  4204             last_sample6 = sample6;
  4205             last_sample7 = sample7;
  4206             eps -= srcsize;
  4207         }
  4208     }
  4209     cvt->len_cvt = dstsize;
  4210     if (cvt->filters[++cvt->filter_index]) {
  4211         cvt->filters[cvt->filter_index] (cvt, format);
  4212     }
  4213 }
  4214 
  4215 static void SDLCALL
  4216 SDL_Upsample_U16MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4217 {
  4218 #if DEBUG_CONVERT
  4219     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16MSB, 1 channels.\n", cvt->rate_incr);
  4220 #endif
  4221 
  4222     const int srcsize = cvt->len_cvt - 32;
  4223     const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
  4224     register int eps = 0;
  4225     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 1;
  4226     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
  4227     const Uint16 *target = ((const Uint16 *) cvt->buf);
  4228     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4229     Uint16 last_sample0 = sample0;
  4230     while (dst >= target) {
  4231         dst[0] = SDL_SwapBE16(sample0);
  4232         dst--;
  4233         eps += srcsize;
  4234         if ((eps << 1) >= dstsize) {
  4235             src--;
  4236             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4237             last_sample0 = sample0;
  4238             eps -= dstsize;
  4239         }
  4240     }
  4241     cvt->len_cvt = dstsize;
  4242     if (cvt->filters[++cvt->filter_index]) {
  4243         cvt->filters[cvt->filter_index] (cvt, format);
  4244     }
  4245 }
  4246 
  4247 static void SDLCALL
  4248 SDL_Downsample_U16MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4249 {
  4250 #if DEBUG_CONVERT
  4251     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16MSB, 1 channels.\n", cvt->rate_incr);
  4252 #endif
  4253 
  4254     const int srcsize = cvt->len_cvt - 32;
  4255     const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
  4256     register int eps = 0;
  4257     Uint16 *dst = (Uint16 *) cvt->buf;
  4258     const Uint16 *src = (Uint16 *) cvt->buf;
  4259     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
  4260     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4261     Uint16 last_sample0 = sample0;
  4262     while (dst < target) {
  4263         src++;
  4264         eps += dstsize;
  4265         if ((eps << 1) >= srcsize) {
  4266             dst[0] = SDL_SwapBE16(sample0);
  4267             dst++;
  4268             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4269             last_sample0 = sample0;
  4270             eps -= srcsize;
  4271         }
  4272     }
  4273     cvt->len_cvt = dstsize;
  4274     if (cvt->filters[++cvt->filter_index]) {
  4275         cvt->filters[cvt->filter_index] (cvt, format);
  4276     }
  4277 }
  4278 
  4279 static void SDLCALL
  4280 SDL_Upsample_U16MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4281 {
  4282 #if DEBUG_CONVERT
  4283     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16MSB, 2 channels.\n", cvt->rate_incr);
  4284 #endif
  4285 
  4286     const int srcsize = cvt->len_cvt - 64;
  4287     const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
  4288     register int eps = 0;
  4289     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 2;
  4290     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 2;
  4291     const Uint16 *target = ((const Uint16 *) cvt->buf);
  4292     Uint16 sample1 = SDL_SwapBE16(src[1]);
  4293     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4294     Uint16 last_sample1 = sample1;
  4295     Uint16 last_sample0 = sample0;
  4296     while (dst >= target) {
  4297         dst[1] = SDL_SwapBE16(sample1);
  4298         dst[0] = SDL_SwapBE16(sample0);
  4299         dst -= 2;
  4300         eps += srcsize;
  4301         if ((eps << 1) >= dstsize) {
  4302             src -= 2;
  4303             sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  4304             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4305             last_sample1 = sample1;
  4306             last_sample0 = sample0;
  4307             eps -= dstsize;
  4308         }
  4309     }
  4310     cvt->len_cvt = dstsize;
  4311     if (cvt->filters[++cvt->filter_index]) {
  4312         cvt->filters[cvt->filter_index] (cvt, format);
  4313     }
  4314 }
  4315 
  4316 static void SDLCALL
  4317 SDL_Downsample_U16MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4318 {
  4319 #if DEBUG_CONVERT
  4320     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16MSB, 2 channels.\n", cvt->rate_incr);
  4321 #endif
  4322 
  4323     const int srcsize = cvt->len_cvt - 64;
  4324     const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
  4325     register int eps = 0;
  4326     Uint16 *dst = (Uint16 *) cvt->buf;
  4327     const Uint16 *src = (Uint16 *) cvt->buf;
  4328     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
  4329     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4330     Uint16 sample1 = SDL_SwapBE16(src[1]);
  4331     Uint16 last_sample0 = sample0;
  4332     Uint16 last_sample1 = sample1;
  4333     while (dst < target) {
  4334         src += 2;
  4335         eps += dstsize;
  4336         if ((eps << 1) >= srcsize) {
  4337             dst[0] = SDL_SwapBE16(sample0);
  4338             dst[1] = SDL_SwapBE16(sample1);
  4339             dst += 2;
  4340             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4341             sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  4342             last_sample0 = sample0;
  4343             last_sample1 = sample1;
  4344             eps -= srcsize;
  4345         }
  4346     }
  4347     cvt->len_cvt = dstsize;
  4348     if (cvt->filters[++cvt->filter_index]) {
  4349         cvt->filters[cvt->filter_index] (cvt, format);
  4350     }
  4351 }
  4352 
  4353 static void SDLCALL
  4354 SDL_Upsample_U16MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4355 {
  4356 #if DEBUG_CONVERT
  4357     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16MSB, 4 channels.\n", cvt->rate_incr);
  4358 #endif
  4359 
  4360     const int srcsize = cvt->len_cvt - 128;
  4361     const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
  4362     register int eps = 0;
  4363     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 4;
  4364     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 4;
  4365     const Uint16 *target = ((const Uint16 *) cvt->buf);
  4366     Uint16 sample3 = SDL_SwapBE16(src[3]);
  4367     Uint16 sample2 = SDL_SwapBE16(src[2]);
  4368     Uint16 sample1 = SDL_SwapBE16(src[1]);
  4369     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4370     Uint16 last_sample3 = sample3;
  4371     Uint16 last_sample2 = sample2;
  4372     Uint16 last_sample1 = sample1;
  4373     Uint16 last_sample0 = sample0;
  4374     while (dst >= target) {
  4375         dst[3] = SDL_SwapBE16(sample3);
  4376         dst[2] = SDL_SwapBE16(sample2);
  4377         dst[1] = SDL_SwapBE16(sample1);
  4378         dst[0] = SDL_SwapBE16(sample0);
  4379         dst -= 4;
  4380         eps += srcsize;
  4381         if ((eps << 1) >= dstsize) {
  4382             src -= 4;
  4383             sample3 = (Uint16) ((((Sint32) SDL_SwapBE16(src[3])) + ((Sint32) last_sample3)) >> 1);
  4384             sample2 = (Uint16) ((((Sint32) SDL_SwapBE16(src[2])) + ((Sint32) last_sample2)) >> 1);
  4385             sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  4386             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4387             last_sample3 = sample3;
  4388             last_sample2 = sample2;
  4389             last_sample1 = sample1;
  4390             last_sample0 = sample0;
  4391             eps -= dstsize;
  4392         }
  4393     }
  4394     cvt->len_cvt = dstsize;
  4395     if (cvt->filters[++cvt->filter_index]) {
  4396         cvt->filters[cvt->filter_index] (cvt, format);
  4397     }
  4398 }
  4399 
  4400 static void SDLCALL
  4401 SDL_Downsample_U16MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4402 {
  4403 #if DEBUG_CONVERT
  4404     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16MSB, 4 channels.\n", cvt->rate_incr);
  4405 #endif
  4406 
  4407     const int srcsize = cvt->len_cvt - 128;
  4408     const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
  4409     register int eps = 0;
  4410     Uint16 *dst = (Uint16 *) cvt->buf;
  4411     const Uint16 *src = (Uint16 *) cvt->buf;
  4412     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
  4413     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4414     Uint16 sample1 = SDL_SwapBE16(src[1]);
  4415     Uint16 sample2 = SDL_SwapBE16(src[2]);
  4416     Uint16 sample3 = SDL_SwapBE16(src[3]);
  4417     Uint16 last_sample0 = sample0;
  4418     Uint16 last_sample1 = sample1;
  4419     Uint16 last_sample2 = sample2;
  4420     Uint16 last_sample3 = sample3;
  4421     while (dst < target) {
  4422         src += 4;
  4423         eps += dstsize;
  4424         if ((eps << 1) >= srcsize) {
  4425             dst[0] = SDL_SwapBE16(sample0);
  4426             dst[1] = SDL_SwapBE16(sample1);
  4427             dst[2] = SDL_SwapBE16(sample2);
  4428             dst[3] = SDL_SwapBE16(sample3);
  4429             dst += 4;
  4430             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4431             sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  4432             sample2 = (Uint16) ((((Sint32) SDL_SwapBE16(src[2])) + ((Sint32) last_sample2)) >> 1);
  4433             sample3 = (Uint16) ((((Sint32) SDL_SwapBE16(src[3])) + ((Sint32) last_sample3)) >> 1);
  4434             last_sample0 = sample0;
  4435             last_sample1 = sample1;
  4436             last_sample2 = sample2;
  4437             last_sample3 = sample3;
  4438             eps -= srcsize;
  4439         }
  4440     }
  4441     cvt->len_cvt = dstsize;
  4442     if (cvt->filters[++cvt->filter_index]) {
  4443         cvt->filters[cvt->filter_index] (cvt, format);
  4444     }
  4445 }
  4446 
  4447 static void SDLCALL
  4448 SDL_Upsample_U16MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4449 {
  4450 #if DEBUG_CONVERT
  4451     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16MSB, 6 channels.\n", cvt->rate_incr);
  4452 #endif
  4453 
  4454     const int srcsize = cvt->len_cvt - 192;
  4455     const int dstsize = (int) (((double)(cvt->len_cvt/12)) * cvt->rate_incr) * 12;
  4456     register int eps = 0;
  4457     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 6;
  4458     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 6;
  4459     const Uint16 *target = ((const Uint16 *) cvt->buf);
  4460     Uint16 sample5 = SDL_SwapBE16(src[5]);
  4461     Uint16 sample4 = SDL_SwapBE16(src[4]);
  4462     Uint16 sample3 = SDL_SwapBE16(src[3]);
  4463     Uint16 sample2 = SDL_SwapBE16(src[2]);
  4464     Uint16 sample1 = SDL_SwapBE16(src[1]);
  4465     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4466     Uint16 last_sample5 = sample5;
  4467     Uint16 last_sample4 = sample4;
  4468     Uint16 last_sample3 = sample3;
  4469     Uint16 last_sample2 = sample2;
  4470     Uint16 last_sample1 = sample1;
  4471     Uint16 last_sample0 = sample0;
  4472     while (dst >= target) {
  4473         dst[5] = SDL_SwapBE16(sample5);
  4474         dst[4] = SDL_SwapBE16(sample4);
  4475         dst[3] = SDL_SwapBE16(sample3);
  4476         dst[2] = SDL_SwapBE16(sample2);
  4477         dst[1] = SDL_SwapBE16(sample1);
  4478         dst[0] = SDL_SwapBE16(sample0);
  4479         dst -= 6;
  4480         eps += srcsize;
  4481         if ((eps << 1) >= dstsize) {
  4482             src -= 6;
  4483             sample5 = (Uint16) ((((Sint32) SDL_SwapBE16(src[5])) + ((Sint32) last_sample5)) >> 1);
  4484             sample4 = (Uint16) ((((Sint32) SDL_SwapBE16(src[4])) + ((Sint32) last_sample4)) >> 1);
  4485             sample3 = (Uint16) ((((Sint32) SDL_SwapBE16(src[3])) + ((Sint32) last_sample3)) >> 1);
  4486             sample2 = (Uint16) ((((Sint32) SDL_SwapBE16(src[2])) + ((Sint32) last_sample2)) >> 1);
  4487             sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  4488             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4489             last_sample5 = sample5;
  4490             last_sample4 = sample4;
  4491             last_sample3 = sample3;
  4492             last_sample2 = sample2;
  4493             last_sample1 = sample1;
  4494             last_sample0 = sample0;
  4495             eps -= dstsize;
  4496         }
  4497     }
  4498     cvt->len_cvt = dstsize;
  4499     if (cvt->filters[++cvt->filter_index]) {
  4500         cvt->filters[cvt->filter_index] (cvt, format);
  4501     }
  4502 }
  4503 
  4504 static void SDLCALL
  4505 SDL_Downsample_U16MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4506 {
  4507 #if DEBUG_CONVERT
  4508     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16MSB, 6 channels.\n", cvt->rate_incr);
  4509 #endif
  4510 
  4511     const int srcsize = cvt->len_cvt - 192;
  4512     const int dstsize = (int) (((double)(cvt->len_cvt/12)) * cvt->rate_incr) * 12;
  4513     register int eps = 0;
  4514     Uint16 *dst = (Uint16 *) cvt->buf;
  4515     const Uint16 *src = (Uint16 *) cvt->buf;
  4516     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
  4517     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4518     Uint16 sample1 = SDL_SwapBE16(src[1]);
  4519     Uint16 sample2 = SDL_SwapBE16(src[2]);
  4520     Uint16 sample3 = SDL_SwapBE16(src[3]);
  4521     Uint16 sample4 = SDL_SwapBE16(src[4]);
  4522     Uint16 sample5 = SDL_SwapBE16(src[5]);
  4523     Uint16 last_sample0 = sample0;
  4524     Uint16 last_sample1 = sample1;
  4525     Uint16 last_sample2 = sample2;
  4526     Uint16 last_sample3 = sample3;
  4527     Uint16 last_sample4 = sample4;
  4528     Uint16 last_sample5 = sample5;
  4529     while (dst < target) {
  4530         src += 6;
  4531         eps += dstsize;
  4532         if ((eps << 1) >= srcsize) {
  4533             dst[0] = SDL_SwapBE16(sample0);
  4534             dst[1] = SDL_SwapBE16(sample1);
  4535             dst[2] = SDL_SwapBE16(sample2);
  4536             dst[3] = SDL_SwapBE16(sample3);
  4537             dst[4] = SDL_SwapBE16(sample4);
  4538             dst[5] = SDL_SwapBE16(sample5);
  4539             dst += 6;
  4540             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4541             sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  4542             sample2 = (Uint16) ((((Sint32) SDL_SwapBE16(src[2])) + ((Sint32) last_sample2)) >> 1);
  4543             sample3 = (Uint16) ((((Sint32) SDL_SwapBE16(src[3])) + ((Sint32) last_sample3)) >> 1);
  4544             sample4 = (Uint16) ((((Sint32) SDL_SwapBE16(src[4])) + ((Sint32) last_sample4)) >> 1);
  4545             sample5 = (Uint16) ((((Sint32) SDL_SwapBE16(src[5])) + ((Sint32) last_sample5)) >> 1);
  4546             last_sample0 = sample0;
  4547             last_sample1 = sample1;
  4548             last_sample2 = sample2;
  4549             last_sample3 = sample3;
  4550             last_sample4 = sample4;
  4551             last_sample5 = sample5;
  4552             eps -= srcsize;
  4553         }
  4554     }
  4555     cvt->len_cvt = dstsize;
  4556     if (cvt->filters[++cvt->filter_index]) {
  4557         cvt->filters[cvt->filter_index] (cvt, format);
  4558     }
  4559 }
  4560 
  4561 static void SDLCALL
  4562 SDL_Upsample_U16MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4563 {
  4564 #if DEBUG_CONVERT
  4565     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16MSB, 8 channels.\n", cvt->rate_incr);
  4566 #endif
  4567 
  4568     const int srcsize = cvt->len_cvt - 256;
  4569     const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
  4570     register int eps = 0;
  4571     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 8;
  4572     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 8;
  4573     const Uint16 *target = ((const Uint16 *) cvt->buf);
  4574     Uint16 sample7 = SDL_SwapBE16(src[7]);
  4575     Uint16 sample6 = SDL_SwapBE16(src[6]);
  4576     Uint16 sample5 = SDL_SwapBE16(src[5]);
  4577     Uint16 sample4 = SDL_SwapBE16(src[4]);
  4578     Uint16 sample3 = SDL_SwapBE16(src[3]);
  4579     Uint16 sample2 = SDL_SwapBE16(src[2]);
  4580     Uint16 sample1 = SDL_SwapBE16(src[1]);
  4581     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4582     Uint16 last_sample7 = sample7;
  4583     Uint16 last_sample6 = sample6;
  4584     Uint16 last_sample5 = sample5;
  4585     Uint16 last_sample4 = sample4;
  4586     Uint16 last_sample3 = sample3;
  4587     Uint16 last_sample2 = sample2;
  4588     Uint16 last_sample1 = sample1;
  4589     Uint16 last_sample0 = sample0;
  4590     while (dst >= target) {
  4591         dst[7] = SDL_SwapBE16(sample7);
  4592         dst[6] = SDL_SwapBE16(sample6);
  4593         dst[5] = SDL_SwapBE16(sample5);
  4594         dst[4] = SDL_SwapBE16(sample4);
  4595         dst[3] = SDL_SwapBE16(sample3);
  4596         dst[2] = SDL_SwapBE16(sample2);
  4597         dst[1] = SDL_SwapBE16(sample1);
  4598         dst[0] = SDL_SwapBE16(sample0);
  4599         dst -= 8;
  4600         eps += srcsize;
  4601         if ((eps << 1) >= dstsize) {
  4602             src -= 8;
  4603             sample7 = (Uint16) ((((Sint32) SDL_SwapBE16(src[7])) + ((Sint32) last_sample7)) >> 1);
  4604             sample6 = (Uint16) ((((Sint32) SDL_SwapBE16(src[6])) + ((Sint32) last_sample6)) >> 1);
  4605             sample5 = (Uint16) ((((Sint32) SDL_SwapBE16(src[5])) + ((Sint32) last_sample5)) >> 1);
  4606             sample4 = (Uint16) ((((Sint32) SDL_SwapBE16(src[4])) + ((Sint32) last_sample4)) >> 1);
  4607             sample3 = (Uint16) ((((Sint32) SDL_SwapBE16(src[3])) + ((Sint32) last_sample3)) >> 1);
  4608             sample2 = (Uint16) ((((Sint32) SDL_SwapBE16(src[2])) + ((Sint32) last_sample2)) >> 1);
  4609             sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  4610             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4611             last_sample7 = sample7;
  4612             last_sample6 = sample6;
  4613             last_sample5 = sample5;
  4614             last_sample4 = sample4;
  4615             last_sample3 = sample3;
  4616             last_sample2 = sample2;
  4617             last_sample1 = sample1;
  4618             last_sample0 = sample0;
  4619             eps -= dstsize;
  4620         }
  4621     }
  4622     cvt->len_cvt = dstsize;
  4623     if (cvt->filters[++cvt->filter_index]) {
  4624         cvt->filters[cvt->filter_index] (cvt, format);
  4625     }
  4626 }
  4627 
  4628 static void SDLCALL
  4629 SDL_Downsample_U16MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4630 {
  4631 #if DEBUG_CONVERT
  4632     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16MSB, 8 channels.\n", cvt->rate_incr);
  4633 #endif
  4634 
  4635     const int srcsize = cvt->len_cvt - 256;
  4636     const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
  4637     register int eps = 0;
  4638     Uint16 *dst = (Uint16 *) cvt->buf;
  4639     const Uint16 *src = (Uint16 *) cvt->buf;
  4640     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
  4641     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4642     Uint16 sample1 = SDL_SwapBE16(src[1]);
  4643     Uint16 sample2 = SDL_SwapBE16(src[2]);
  4644     Uint16 sample3 = SDL_SwapBE16(src[3]);
  4645     Uint16 sample4 = SDL_SwapBE16(src[4]);
  4646     Uint16 sample5 = SDL_SwapBE16(src[5]);
  4647     Uint16 sample6 = SDL_SwapBE16(src[6]);
  4648     Uint16 sample7 = SDL_SwapBE16(src[7]);
  4649     Uint16 last_sample0 = sample0;
  4650     Uint16 last_sample1 = sample1;
  4651     Uint16 last_sample2 = sample2;
  4652     Uint16 last_sample3 = sample3;
  4653     Uint16 last_sample4 = sample4;
  4654     Uint16 last_sample5 = sample5;
  4655     Uint16 last_sample6 = sample6;
  4656     Uint16 last_sample7 = sample7;
  4657     while (dst < target) {
  4658         src += 8;
  4659         eps += dstsize;
  4660         if ((eps << 1) >= srcsize) {
  4661             dst[0] = SDL_SwapBE16(sample0);
  4662             dst[1] = SDL_SwapBE16(sample1);
  4663             dst[2] = SDL_SwapBE16(sample2);
  4664             dst[3] = SDL_SwapBE16(sample3);
  4665             dst[4] = SDL_SwapBE16(sample4);
  4666             dst[5] = SDL_SwapBE16(sample5);
  4667             dst[6] = SDL_SwapBE16(sample6);
  4668             dst[7] = SDL_SwapBE16(sample7);
  4669             dst += 8;
  4670             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4671             sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  4672             sample2 = (Uint16) ((((Sint32) SDL_SwapBE16(src[2])) + ((Sint32) last_sample2)) >> 1);
  4673             sample3 = (Uint16) ((((Sint32) SDL_SwapBE16(src[3])) + ((Sint32) last_sample3)) >> 1);
  4674             sample4 = (Uint16) ((((Sint32) SDL_SwapBE16(src[4])) + ((Sint32) last_sample4)) >> 1);
  4675             sample5 = (Uint16) ((((Sint32) SDL_SwapBE16(src[5])) + ((Sint32) last_sample5)) >> 1);
  4676             sample6 = (Uint16) ((((Sint32) SDL_SwapBE16(src[6])) + ((Sint32) last_sample6)) >> 1);
  4677             sample7 = (Uint16) ((((Sint32) SDL_SwapBE16(src[7])) + ((Sint32) last_sample7)) >> 1);
  4678             last_sample0 = sample0;
  4679             last_sample1 = sample1;
  4680             last_sample2 = sample2;
  4681             last_sample3 = sample3;
  4682             last_sample4 = sample4;
  4683             last_sample5 = sample5;
  4684             last_sample6 = sample6;
  4685             last_sample7 = sample7;
  4686             eps -= srcsize;
  4687         }
  4688     }
  4689     cvt->len_cvt = dstsize;
  4690     if (cvt->filters[++cvt->filter_index]) {
  4691         cvt->filters[cvt->filter_index] (cvt, format);
  4692     }
  4693 }
  4694 
  4695 static void SDLCALL
  4696 SDL_Upsample_S16MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4697 {
  4698 #if DEBUG_CONVERT
  4699     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16MSB, 1 channels.\n", cvt->rate_incr);
  4700 #endif
  4701 
  4702     const int srcsize = cvt->len_cvt - 32;
  4703     const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
  4704     register int eps = 0;
  4705     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 1;
  4706     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 1;
  4707     const Sint16 *target = ((const Sint16 *) cvt->buf);
  4708     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  4709     Sint16 last_sample0 = sample0;
  4710     while (dst >= target) {
  4711         dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  4712         dst--;
  4713         eps += srcsize;
  4714         if ((eps << 1) >= dstsize) {
  4715             src--;
  4716             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4717             last_sample0 = sample0;
  4718             eps -= dstsize;
  4719         }
  4720     }
  4721     cvt->len_cvt = dstsize;
  4722     if (cvt->filters[++cvt->filter_index]) {
  4723         cvt->filters[cvt->filter_index] (cvt, format);
  4724     }
  4725 }
  4726 
  4727 static void SDLCALL
  4728 SDL_Downsample_S16MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4729 {
  4730 #if DEBUG_CONVERT
  4731     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16MSB, 1 channels.\n", cvt->rate_incr);
  4732 #endif
  4733 
  4734     const int srcsize = cvt->len_cvt - 32;
  4735     const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
  4736     register int eps = 0;
  4737     Sint16 *dst = (Sint16 *) cvt->buf;
  4738     const Sint16 *src = (Sint16 *) cvt->buf;
  4739     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
  4740     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  4741     Sint16 last_sample0 = sample0;
  4742     while (dst < target) {
  4743         src++;
  4744         eps += dstsize;
  4745         if ((eps << 1) >= srcsize) {
  4746             dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  4747             dst++;
  4748             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4749             last_sample0 = sample0;
  4750             eps -= srcsize;
  4751         }
  4752     }
  4753     cvt->len_cvt = dstsize;
  4754     if (cvt->filters[++cvt->filter_index]) {
  4755         cvt->filters[cvt->filter_index] (cvt, format);
  4756     }
  4757 }
  4758 
  4759 static void SDLCALL
  4760 SDL_Upsample_S16MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4761 {
  4762 #if DEBUG_CONVERT
  4763     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16MSB, 2 channels.\n", cvt->rate_incr);
  4764 #endif
  4765 
  4766     const int srcsize = cvt->len_cvt - 64;
  4767     const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
  4768     register int eps = 0;
  4769     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 2;
  4770     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 2;
  4771     const Sint16 *target = ((const Sint16 *) cvt->buf);
  4772     Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
  4773     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  4774     Sint16 last_sample1 = sample1;
  4775     Sint16 last_sample0 = sample0;
  4776     while (dst >= target) {
  4777         dst[1] = ((Sint16) SDL_SwapBE16(sample1));
  4778         dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  4779         dst -= 2;
  4780         eps += srcsize;
  4781         if ((eps << 1) >= dstsize) {
  4782             src -= 2;
  4783             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  4784             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4785             last_sample1 = sample1;
  4786             last_sample0 = sample0;
  4787             eps -= dstsize;
  4788         }
  4789     }
  4790     cvt->len_cvt = dstsize;
  4791     if (cvt->filters[++cvt->filter_index]) {
  4792         cvt->filters[cvt->filter_index] (cvt, format);
  4793     }
  4794 }
  4795 
  4796 static void SDLCALL
  4797 SDL_Downsample_S16MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4798 {
  4799 #if DEBUG_CONVERT
  4800     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16MSB, 2 channels.\n", cvt->rate_incr);
  4801 #endif
  4802 
  4803     const int srcsize = cvt->len_cvt - 64;
  4804     const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
  4805     register int eps = 0;
  4806     Sint16 *dst = (Sint16 *) cvt->buf;
  4807     const Sint16 *src = (Sint16 *) cvt->buf;
  4808     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
  4809     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  4810     Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
  4811     Sint16 last_sample0 = sample0;
  4812     Sint16 last_sample1 = sample1;
  4813     while (dst < target) {
  4814         src += 2;
  4815         eps += dstsize;
  4816         if ((eps << 1) >= srcsize) {
  4817             dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  4818             dst[1] = ((Sint16) SDL_SwapBE16(sample1));
  4819             dst += 2;
  4820             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4821             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  4822             last_sample0 = sample0;
  4823             last_sample1 = sample1;
  4824             eps -= srcsize;
  4825         }
  4826     }
  4827     cvt->len_cvt = dstsize;
  4828     if (cvt->filters[++cvt->filter_index]) {
  4829         cvt->filters[cvt->filter_index] (cvt, format);
  4830     }
  4831 }
  4832 
  4833 static void SDLCALL
  4834 SDL_Upsample_S16MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4835 {
  4836 #if DEBUG_CONVERT
  4837     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16MSB, 4 channels.\n", cvt->rate_incr);
  4838 #endif
  4839 
  4840     const int srcsize = cvt->len_cvt - 128;
  4841     const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
  4842     register int eps = 0;
  4843     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 4;
  4844     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 4;
  4845     const Sint16 *target = ((const Sint16 *) cvt->buf);
  4846     Sint16 sample3 = ((Sint16) SDL_SwapBE16(src[3]));
  4847     Sint16 sample2 = ((Sint16) SDL_SwapBE16(src[2]));
  4848     Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
  4849     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  4850     Sint16 last_sample3 = sample3;
  4851     Sint16 last_sample2 = sample2;
  4852     Sint16 last_sample1 = sample1;
  4853     Sint16 last_sample0 = sample0;
  4854     while (dst >= target) {
  4855         dst[3] = ((Sint16) SDL_SwapBE16(sample3));
  4856         dst[2] = ((Sint16) SDL_SwapBE16(sample2));
  4857         dst[1] = ((Sint16) SDL_SwapBE16(sample1));
  4858         dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  4859         dst -= 4;
  4860         eps += srcsize;
  4861         if ((eps << 1) >= dstsize) {
  4862             src -= 4;
  4863             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  4864             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  4865             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  4866             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4867             last_sample3 = sample3;
  4868             last_sample2 = sample2;
  4869             last_sample1 = sample1;
  4870             last_sample0 = sample0;
  4871             eps -= dstsize;
  4872         }
  4873     }
  4874     cvt->len_cvt = dstsize;
  4875     if (cvt->filters[++cvt->filter_index]) {
  4876         cvt->filters[cvt->filter_index] (cvt, format);
  4877     }
  4878 }
  4879 
  4880 static void SDLCALL
  4881 SDL_Downsample_S16MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4882 {
  4883 #if DEBUG_CONVERT
  4884     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16MSB, 4 channels.\n", cvt->rate_incr);
  4885 #endif
  4886 
  4887     const int srcsize = cvt->len_cvt - 128;
  4888     const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
  4889     register int eps = 0;
  4890     Sint16 *dst = (Sint16 *) cvt->buf;
  4891     const Sint16 *src = (Sint16 *) cvt->buf;
  4892     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
  4893     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  4894     Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
  4895     Sint16 sample2 = ((Sint16) SDL_SwapBE16(src[2]));
  4896     Sint16 sample3 = ((Sint16) SDL_SwapBE16(src[3]));
  4897     Sint16 last_sample0 = sample0;
  4898     Sint16 last_sample1 = sample1;
  4899     Sint16 last_sample2 = sample2;
  4900     Sint16 last_sample3 = sample3;
  4901     while (dst < target) {
  4902         src += 4;
  4903         eps += dstsize;
  4904         if ((eps << 1) >= srcsize) {
  4905             dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  4906             dst[1] = ((Sint16) SDL_SwapBE16(sample1));
  4907             dst[2] = ((Sint16) SDL_SwapBE16(sample2));
  4908             dst[3] = ((Sint16) SDL_SwapBE16(sample3));
  4909             dst += 4;
  4910             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4911             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  4912             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  4913             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  4914             last_sample0 = sample0;
  4915             last_sample1 = sample1;
  4916             last_sample2 = sample2;
  4917             last_sample3 = sample3;
  4918             eps -= srcsize;
  4919         }
  4920     }
  4921     cvt->len_cvt = dstsize;
  4922     if (cvt->filters[++cvt->filter_index]) {
  4923         cvt->filters[cvt->filter_index] (cvt, format);
  4924     }
  4925 }
  4926 
  4927 static void SDLCALL
  4928 SDL_Upsample_S16MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4929 {
  4930 #if DEBUG_CONVERT
  4931     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16MSB, 6 channels.\n", cvt->rate_incr);
  4932 #endif
  4933 
  4934     const int srcsize = cvt->len_cvt - 192;
  4935     const int dstsize = (int) (((double)(cvt->len_cvt/12)) * cvt->rate_incr) * 12;
  4936     register int eps = 0;
  4937     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 6;
  4938     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 6;
  4939     const Sint16 *target = ((const Sint16 *) cvt->buf);
  4940     Sint16 sample5 = ((Sint16) SDL_SwapBE16(src[5]));
  4941     Sint16 sample4 = ((Sint16) SDL_SwapBE16(src[4]));
  4942     Sint16 sample3 = ((Sint16) SDL_SwapBE16(src[3]));
  4943     Sint16 sample2 = ((Sint16) SDL_SwapBE16(src[2]));
  4944     Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
  4945     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  4946     Sint16 last_sample5 = sample5;
  4947     Sint16 last_sample4 = sample4;
  4948     Sint16 last_sample3 = sample3;
  4949     Sint16 last_sample2 = sample2;
  4950     Sint16 last_sample1 = sample1;
  4951     Sint16 last_sample0 = sample0;
  4952     while (dst >= target) {
  4953         dst[5] = ((Sint16) SDL_SwapBE16(sample5));
  4954         dst[4] = ((Sint16) SDL_SwapBE16(sample4));
  4955         dst[3] = ((Sint16) SDL_SwapBE16(sample3));
  4956         dst[2] = ((Sint16) SDL_SwapBE16(sample2));
  4957         dst[1] = ((Sint16) SDL_SwapBE16(sample1));
  4958         dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  4959         dst -= 6;
  4960         eps += srcsize;
  4961         if ((eps << 1) >= dstsize) {
  4962             src -= 6;
  4963             sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
  4964             sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
  4965             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  4966             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  4967             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  4968             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4969             last_sample5 = sample5;
  4970             last_sample4 = sample4;
  4971             last_sample3 = sample3;
  4972             last_sample2 = sample2;
  4973             last_sample1 = sample1;
  4974             last_sample0 = sample0;
  4975             eps -= dstsize;
  4976         }
  4977     }
  4978     cvt->len_cvt = dstsize;
  4979     if (cvt->filters[++cvt->filter_index]) {
  4980         cvt->filters[cvt->filter_index] (cvt, format);
  4981     }
  4982 }
  4983 
  4984 static void SDLCALL
  4985 SDL_Downsample_S16MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4986 {
  4987 #if DEBUG_CONVERT
  4988     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16MSB, 6 channels.\n", cvt->rate_incr);
  4989 #endif
  4990 
  4991     const int srcsize = cvt->len_cvt - 192;
  4992     const int dstsize = (int) (((double)(cvt->len_cvt/12)) * cvt->rate_incr) * 12;
  4993     register int eps = 0;
  4994     Sint16 *dst = (Sint16 *) cvt->buf;
  4995     const Sint16 *src = (Sint16 *) cvt->buf;
  4996     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
  4997     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  4998     Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
  4999     Sint16 sample2 = ((Sint16) SDL_SwapBE16(src[2]));
  5000     Sint16 sample3 = ((Sint16) SDL_SwapBE16(src[3]));
  5001     Sint16 sample4 = ((Sint16) SDL_SwapBE16(src[4]));
  5002     Sint16 sample5 = ((Sint16) SDL_SwapBE16(src[5]));
  5003     Sint16 last_sample0 = sample0;
  5004     Sint16 last_sample1 = sample1;
  5005     Sint16 last_sample2 = sample2;
  5006     Sint16 last_sample3 = sample3;
  5007     Sint16 last_sample4 = sample4;
  5008     Sint16 last_sample5 = sample5;
  5009     while (dst < target) {
  5010         src += 6;
  5011         eps += dstsize;
  5012         if ((eps << 1) >= srcsize) {
  5013             dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  5014             dst[1] = ((Sint16) SDL_SwapBE16(sample1));
  5015             dst[2] = ((Sint16) SDL_SwapBE16(sample2));
  5016             dst[3] = ((Sint16) SDL_SwapBE16(sample3));
  5017             dst[4] = ((Sint16) SDL_SwapBE16(sample4));
  5018             dst[5] = ((Sint16) SDL_SwapBE16(sample5));
  5019             dst += 6;
  5020             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  5021             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  5022             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  5023             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  5024             sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
  5025             sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
  5026             last_sample0 = sample0;
  5027             last_sample1 = sample1;
  5028             last_sample2 = sample2;
  5029             last_sample3 = sample3;
  5030             last_sample4 = sample4;
  5031             last_sample5 = sample5;
  5032             eps -= srcsize;
  5033         }
  5034     }
  5035     cvt->len_cvt = dstsize;
  5036     if (cvt->filters[++cvt->filter_index]) {
  5037         cvt->filters[cvt->filter_index] (cvt, format);
  5038     }
  5039 }
  5040 
  5041 static void SDLCALL
  5042 SDL_Upsample_S16MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5043 {
  5044 #if DEBUG_CONVERT
  5045     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16MSB, 8 channels.\n", cvt->rate_incr);
  5046 #endif
  5047 
  5048     const int srcsize = cvt->len_cvt - 256;
  5049     const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
  5050     register int eps = 0;
  5051     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 8;
  5052     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 8;
  5053     const Sint16 *target = ((const Sint16 *) cvt->buf);
  5054     Sint16 sample7 = ((Sint16) SDL_SwapBE16(src[7]));
  5055     Sint16 sample6 = ((Sint16) SDL_SwapBE16(src[6]));
  5056     Sint16 sample5 = ((Sint16) SDL_SwapBE16(src[5]));
  5057     Sint16 sample4 = ((Sint16) SDL_SwapBE16(src[4]));
  5058     Sint16 sample3 = ((Sint16) SDL_SwapBE16(src[3]));
  5059     Sint16 sample2 = ((Sint16) SDL_SwapBE16(src[2]));
  5060     Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
  5061     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  5062     Sint16 last_sample7 = sample7;
  5063     Sint16 last_sample6 = sample6;
  5064     Sint16 last_sample5 = sample5;
  5065     Sint16 last_sample4 = sample4;
  5066     Sint16 last_sample3 = sample3;
  5067     Sint16 last_sample2 = sample2;
  5068     Sint16 last_sample1 = sample1;
  5069     Sint16 last_sample0 = sample0;
  5070     while (dst >= target) {
  5071         dst[7] = ((Sint16) SDL_SwapBE16(sample7));
  5072         dst[6] = ((Sint16) SDL_SwapBE16(sample6));
  5073         dst[5] = ((Sint16) SDL_SwapBE16(sample5));
  5074         dst[4] = ((Sint16) SDL_SwapBE16(sample4));
  5075         dst[3] = ((Sint16) SDL_SwapBE16(sample3));
  5076         dst[2] = ((Sint16) SDL_SwapBE16(sample2));
  5077         dst[1] = ((Sint16) SDL_SwapBE16(sample1));
  5078         dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  5079         dst -= 8;
  5080         eps += srcsize;
  5081         if ((eps << 1) >= dstsize) {
  5082             src -= 8;
  5083             sample7 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[7]))) + ((Sint32) last_sample7)) >> 1);
  5084             sample6 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[6]))) + ((Sint32) last_sample6)) >> 1);
  5085             sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
  5086             sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
  5087             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  5088             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  5089             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  5090             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  5091             last_sample7 = sample7;
  5092             last_sample6 = sample6;
  5093             last_sample5 = sample5;
  5094             last_sample4 = sample4;
  5095             last_sample3 = sample3;
  5096             last_sample2 = sample2;
  5097             last_sample1 = sample1;
  5098             last_sample0 = sample0;
  5099             eps -= dstsize;
  5100         }
  5101     }
  5102     cvt->len_cvt = dstsize;
  5103     if (cvt->filters[++cvt->filter_index]) {
  5104         cvt->filters[cvt->filter_index] (cvt, format);
  5105     }
  5106 }
  5107 
  5108 static void SDLCALL
  5109 SDL_Downsample_S16MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5110 {
  5111 #if DEBUG_CONVERT
  5112     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16MSB, 8 channels.\n", cvt->rate_incr);
  5113 #endif
  5114 
  5115     const int srcsize = cvt->len_cvt - 256;
  5116     const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
  5117     register int eps = 0;
  5118     Sint16 *dst = (Sint16 *) cvt->buf;
  5119     const Sint16 *src = (Sint16 *) cvt->buf;
  5120     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
  5121     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  5122     Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
  5123     Sint16 sample2 = ((Sint16) SDL_SwapBE16(src[2]));
  5124     Sint16 sample3 = ((Sint16) SDL_SwapBE16(src[3]));
  5125     Sint16 sample4 = ((Sint16) SDL_SwapBE16(src[4]));
  5126     Sint16 sample5 = ((Sint16) SDL_SwapBE16(src[5]));
  5127     Sint16 sample6 = ((Sint16) SDL_SwapBE16(src[6]));
  5128     Sint16 sample7 = ((Sint16) SDL_SwapBE16(src[7]));
  5129     Sint16 last_sample0 = sample0;
  5130     Sint16 last_sample1 = sample1;
  5131     Sint16 last_sample2 = sample2;
  5132     Sint16 last_sample3 = sample3;
  5133     Sint16 last_sample4 = sample4;
  5134     Sint16 last_sample5 = sample5;
  5135     Sint16 last_sample6 = sample6;
  5136     Sint16 last_sample7 = sample7;
  5137     while (dst < target) {
  5138         src += 8;
  5139         eps += dstsize;
  5140         if ((eps << 1) >= srcsize) {
  5141             dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  5142             dst[1] = ((Sint16) SDL_SwapBE16(sample1));
  5143             dst[2] = ((Sint16) SDL_SwapBE16(sample2));
  5144             dst[3] = ((Sint16) SDL_SwapBE16(sample3));
  5145             dst[4] = ((Sint16) SDL_SwapBE16(sample4));
  5146             dst[5] = ((Sint16) SDL_SwapBE16(sample5));
  5147             dst[6] = ((Sint16) SDL_SwapBE16(sample6));
  5148             dst[7] = ((Sint16) SDL_SwapBE16(sample7));
  5149             dst += 8;
  5150             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  5151             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  5152             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  5153             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  5154             sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
  5155             sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
  5156             sample6 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[6]))) + ((Sint32) last_sample6)) >> 1);
  5157             sample7 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[7]))) + ((Sint32) last_sample7)) >> 1);
  5158             last_sample0 = sample0;
  5159             last_sample1 = sample1;
  5160             last_sample2 = sample2;
  5161             last_sample3 = sample3;
  5162             last_sample4 = sample4;
  5163             last_sample5 = sample5;
  5164             last_sample6 = sample6;
  5165             last_sample7 = sample7;
  5166             eps -= srcsize;
  5167         }
  5168     }
  5169     cvt->len_cvt = dstsize;
  5170     if (cvt->filters[++cvt->filter_index]) {
  5171         cvt->filters[cvt->filter_index] (cvt, format);
  5172     }
  5173 }
  5174 
  5175 static void SDLCALL
  5176 SDL_Upsample_S32LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5177 {
  5178 #if DEBUG_CONVERT
  5179     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32LSB, 1 channels.\n", cvt->rate_incr);
  5180 #endif
  5181 
  5182     const int srcsize = cvt->len_cvt - 64;
  5183     const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
  5184     register int eps = 0;
  5185     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 1;
  5186     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 1;
  5187     const Sint32 *target = ((const Sint32 *) cvt->buf);
  5188     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5189     Sint32 last_sample0 = sample0;
  5190     while (dst >= target) {
  5191         dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5192         dst--;
  5193         eps += srcsize;
  5194         if ((eps << 1) >= dstsize) {
  5195             src--;
  5196             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5197             last_sample0 = sample0;
  5198             eps -= dstsize;
  5199         }
  5200     }
  5201     cvt->len_cvt = dstsize;
  5202     if (cvt->filters[++cvt->filter_index]) {
  5203         cvt->filters[cvt->filter_index] (cvt, format);
  5204     }
  5205 }
  5206 
  5207 static void SDLCALL
  5208 SDL_Downsample_S32LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5209 {
  5210 #if DEBUG_CONVERT
  5211     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32LSB, 1 channels.\n", cvt->rate_incr);
  5212 #endif
  5213 
  5214     const int srcsize = cvt->len_cvt - 64;
  5215     const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
  5216     register int eps = 0;
  5217     Sint32 *dst = (Sint32 *) cvt->buf;
  5218     const Sint32 *src = (Sint32 *) cvt->buf;
  5219     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  5220     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5221     Sint32 last_sample0 = sample0;
  5222     while (dst < target) {
  5223         src++;
  5224         eps += dstsize;
  5225         if ((eps << 1) >= srcsize) {
  5226             dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5227             dst++;
  5228             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5229             last_sample0 = sample0;
  5230             eps -= srcsize;
  5231         }
  5232     }
  5233     cvt->len_cvt = dstsize;
  5234     if (cvt->filters[++cvt->filter_index]) {
  5235         cvt->filters[cvt->filter_index] (cvt, format);
  5236     }
  5237 }
  5238 
  5239 static void SDLCALL
  5240 SDL_Upsample_S32LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5241 {
  5242 #if DEBUG_CONVERT
  5243     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32LSB, 2 channels.\n", cvt->rate_incr);
  5244 #endif
  5245 
  5246     const int srcsize = cvt->len_cvt - 128;
  5247     const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
  5248     register int eps = 0;
  5249     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 2;
  5250     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 2;
  5251     const Sint32 *target = ((const Sint32 *) cvt->buf);
  5252     Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
  5253     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5254     Sint32 last_sample1 = sample1;
  5255     Sint32 last_sample0 = sample0;
  5256     while (dst >= target) {
  5257         dst[1] = ((Sint32) SDL_SwapLE32(sample1));
  5258         dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5259         dst -= 2;
  5260         eps += srcsize;
  5261         if ((eps << 1) >= dstsize) {
  5262             src -= 2;
  5263             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5264             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5265             last_sample1 = sample1;
  5266             last_sample0 = sample0;
  5267             eps -= dstsize;
  5268         }
  5269     }
  5270     cvt->len_cvt = dstsize;
  5271     if (cvt->filters[++cvt->filter_index]) {
  5272         cvt->filters[cvt->filter_index] (cvt, format);
  5273     }
  5274 }
  5275 
  5276 static void SDLCALL
  5277 SDL_Downsample_S32LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5278 {
  5279 #if DEBUG_CONVERT
  5280     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32LSB, 2 channels.\n", cvt->rate_incr);
  5281 #endif
  5282 
  5283     const int srcsize = cvt->len_cvt - 128;
  5284     const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
  5285     register int eps = 0;
  5286     Sint32 *dst = (Sint32 *) cvt->buf;
  5287     const Sint32 *src = (Sint32 *) cvt->buf;
  5288     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  5289     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5290     Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
  5291     Sint32 last_sample0 = sample0;
  5292     Sint32 last_sample1 = sample1;
  5293     while (dst < target) {
  5294         src += 2;
  5295         eps += dstsize;
  5296         if ((eps << 1) >= srcsize) {
  5297             dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5298             dst[1] = ((Sint32) SDL_SwapLE32(sample1));
  5299             dst += 2;
  5300             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5301             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5302             last_sample0 = sample0;
  5303             last_sample1 = sample1;
  5304             eps -= srcsize;
  5305         }
  5306     }
  5307     cvt->len_cvt = dstsize;
  5308     if (cvt->filters[++cvt->filter_index]) {
  5309         cvt->filters[cvt->filter_index] (cvt, format);
  5310     }
  5311 }
  5312 
  5313 static void SDLCALL
  5314 SDL_Upsample_S32LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5315 {
  5316 #if DEBUG_CONVERT
  5317     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32LSB, 4 channels.\n", cvt->rate_incr);
  5318 #endif
  5319 
  5320     const int srcsize = cvt->len_cvt - 256;
  5321     const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
  5322     register int eps = 0;
  5323     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 4;
  5324     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 4;
  5325     const Sint32 *target = ((const Sint32 *) cvt->buf);
  5326     Sint32 sample3 = ((Sint32) SDL_SwapLE32(src[3]));
  5327     Sint32 sample2 = ((Sint32) SDL_SwapLE32(src[2]));
  5328     Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
  5329     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5330     Sint32 last_sample3 = sample3;
  5331     Sint32 last_sample2 = sample2;
  5332     Sint32 last_sample1 = sample1;
  5333     Sint32 last_sample0 = sample0;
  5334     while (dst >= target) {
  5335         dst[3] = ((Sint32) SDL_SwapLE32(sample3));
  5336         dst[2] = ((Sint32) SDL_SwapLE32(sample2));
  5337         dst[1] = ((Sint32) SDL_SwapLE32(sample1));
  5338         dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5339         dst -= 4;
  5340         eps += srcsize;
  5341         if ((eps << 1) >= dstsize) {
  5342             src -= 4;
  5343             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5344             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5345             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5346             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5347             last_sample3 = sample3;
  5348             last_sample2 = sample2;
  5349             last_sample1 = sample1;
  5350             last_sample0 = sample0;
  5351             eps -= dstsize;
  5352         }
  5353     }
  5354     cvt->len_cvt = dstsize;
  5355     if (cvt->filters[++cvt->filter_index]) {
  5356         cvt->filters[cvt->filter_index] (cvt, format);
  5357     }
  5358 }
  5359 
  5360 static void SDLCALL
  5361 SDL_Downsample_S32LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5362 {
  5363 #if DEBUG_CONVERT
  5364     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32LSB, 4 channels.\n", cvt->rate_incr);
  5365 #endif
  5366 
  5367     const int srcsize = cvt->len_cvt - 256;
  5368     const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
  5369     register int eps = 0;
  5370     Sint32 *dst = (Sint32 *) cvt->buf;
  5371     const Sint32 *src = (Sint32 *) cvt->buf;
  5372     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  5373     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5374     Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
  5375     Sint32 sample2 = ((Sint32) SDL_SwapLE32(src[2]));
  5376     Sint32 sample3 = ((Sint32) SDL_SwapLE32(src[3]));
  5377     Sint32 last_sample0 = sample0;
  5378     Sint32 last_sample1 = sample1;
  5379     Sint32 last_sample2 = sample2;
  5380     Sint32 last_sample3 = sample3;
  5381     while (dst < target) {
  5382         src += 4;
  5383         eps += dstsize;
  5384         if ((eps << 1) >= srcsize) {
  5385             dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5386             dst[1] = ((Sint32) SDL_SwapLE32(sample1));
  5387             dst[2] = ((Sint32) SDL_SwapLE32(sample2));
  5388             dst[3] = ((Sint32) SDL_SwapLE32(sample3));
  5389             dst += 4;
  5390             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5391             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5392             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5393             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5394             last_sample0 = sample0;
  5395             last_sample1 = sample1;
  5396             last_sample2 = sample2;
  5397             last_sample3 = sample3;
  5398             eps -= srcsize;
  5399         }
  5400     }
  5401     cvt->len_cvt = dstsize;
  5402     if (cvt->filters[++cvt->filter_index]) {
  5403         cvt->filters[cvt->filter_index] (cvt, format);
  5404     }
  5405 }
  5406 
  5407 static void SDLCALL
  5408 SDL_Upsample_S32LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5409 {
  5410 #if DEBUG_CONVERT
  5411     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32LSB, 6 channels.\n", cvt->rate_incr);
  5412 #endif
  5413 
  5414     const int srcsize = cvt->len_cvt - 384;
  5415     const int dstsize = (int) (((double)(cvt->len_cvt/24)) * cvt->rate_incr) * 24;
  5416     register int eps = 0;
  5417     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 6;
  5418     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 6;
  5419     const Sint32 *target = ((const Sint32 *) cvt->buf);
  5420     Sint32 sample5 = ((Sint32) SDL_SwapLE32(src[5]));
  5421     Sint32 sample4 = ((Sint32) SDL_SwapLE32(src[4]));
  5422     Sint32 sample3 = ((Sint32) SDL_SwapLE32(src[3]));
  5423     Sint32 sample2 = ((Sint32) SDL_SwapLE32(src[2]));
  5424     Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
  5425     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5426     Sint32 last_sample5 = sample5;
  5427     Sint32 last_sample4 = sample4;
  5428     Sint32 last_sample3 = sample3;
  5429     Sint32 last_sample2 = sample2;
  5430     Sint32 last_sample1 = sample1;
  5431     Sint32 last_sample0 = sample0;
  5432     while (dst >= target) {
  5433         dst[5] = ((Sint32) SDL_SwapLE32(sample5));
  5434         dst[4] = ((Sint32) SDL_SwapLE32(sample4));
  5435         dst[3] = ((Sint32) SDL_SwapLE32(sample3));
  5436         dst[2] = ((Sint32) SDL_SwapLE32(sample2));
  5437         dst[1] = ((Sint32) SDL_SwapLE32(sample1));
  5438         dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5439         dst -= 6;
  5440         eps += srcsize;
  5441         if ((eps << 1) >= dstsize) {
  5442             src -= 6;
  5443             sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
  5444             sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
  5445             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5446             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5447             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5448             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5449             last_sample5 = sample5;
  5450             last_sample4 = sample4;
  5451             last_sample3 = sample3;
  5452             last_sample2 = sample2;
  5453             last_sample1 = sample1;
  5454             last_sample0 = sample0;
  5455             eps -= dstsize;
  5456         }
  5457     }
  5458     cvt->len_cvt = dstsize;
  5459     if (cvt->filters[++cvt->filter_index]) {
  5460         cvt->filters[cvt->filter_index] (cvt, format);
  5461     }
  5462 }
  5463 
  5464 static void SDLCALL
  5465 SDL_Downsample_S32LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5466 {
  5467 #if DEBUG_CONVERT
  5468     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32LSB, 6 channels.\n", cvt->rate_incr);
  5469 #endif
  5470 
  5471     const int srcsize = cvt->len_cvt - 384;
  5472     const int dstsize = (int) (((double)(cvt->len_cvt/24)) * cvt->rate_incr) * 24;
  5473     register int eps = 0;
  5474     Sint32 *dst = (Sint32 *) cvt->buf;
  5475     const Sint32 *src = (Sint32 *) cvt->buf;
  5476     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  5477     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5478     Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
  5479     Sint32 sample2 = ((Sint32) SDL_SwapLE32(src[2]));
  5480     Sint32 sample3 = ((Sint32) SDL_SwapLE32(src[3]));
  5481     Sint32 sample4 = ((Sint32) SDL_SwapLE32(src[4]));
  5482     Sint32 sample5 = ((Sint32) SDL_SwapLE32(src[5]));
  5483     Sint32 last_sample0 = sample0;
  5484     Sint32 last_sample1 = sample1;
  5485     Sint32 last_sample2 = sample2;
  5486     Sint32 last_sample3 = sample3;
  5487     Sint32 last_sample4 = sample4;
  5488     Sint32 last_sample5 = sample5;
  5489     while (dst < target) {
  5490         src += 6;
  5491         eps += dstsize;
  5492         if ((eps << 1) >= srcsize) {
  5493             dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5494             dst[1] = ((Sint32) SDL_SwapLE32(sample1));
  5495             dst[2] = ((Sint32) SDL_SwapLE32(sample2));
  5496             dst[3] = ((Sint32) SDL_SwapLE32(sample3));
  5497             dst[4] = ((Sint32) SDL_SwapLE32(sample4));
  5498             dst[5] = ((Sint32) SDL_SwapLE32(sample5));
  5499             dst += 6;
  5500             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5501             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5502             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5503             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5504             sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
  5505             sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
  5506             last_sample0 = sample0;
  5507             last_sample1 = sample1;
  5508             last_sample2 = sample2;
  5509             last_sample3 = sample3;
  5510             last_sample4 = sample4;
  5511             last_sample5 = sample5;
  5512             eps -= srcsize;
  5513         }
  5514     }
  5515     cvt->len_cvt = dstsize;
  5516     if (cvt->filters[++cvt->filter_index]) {
  5517         cvt->filters[cvt->filter_index] (cvt, format);
  5518     }
  5519 }
  5520 
  5521 static void SDLCALL
  5522 SDL_Upsample_S32LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5523 {
  5524 #if DEBUG_CONVERT
  5525     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32LSB, 8 channels.\n", cvt->rate_incr);
  5526 #endif
  5527 
  5528     const int srcsize = cvt->len_cvt - 512;
  5529     const int dstsize = (int) (((double)(cvt->len_cvt/32)) * cvt->rate_incr) * 32;
  5530     register int eps = 0;
  5531     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 8;
  5532     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 8;
  5533     const Sint32 *target = ((const Sint32 *) cvt->buf);
  5534     Sint32 sample7 = ((Sint32) SDL_SwapLE32(src[7]));
  5535     Sint32 sample6 = ((Sint32) SDL_SwapLE32(src[6]));
  5536     Sint32 sample5 = ((Sint32) SDL_SwapLE32(src[5]));
  5537     Sint32 sample4 = ((Sint32) SDL_SwapLE32(src[4]));
  5538     Sint32 sample3 = ((Sint32) SDL_SwapLE32(src[3]));
  5539     Sint32 sample2 = ((Sint32) SDL_SwapLE32(src[2]));
  5540     Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
  5541     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5542     Sint32 last_sample7 = sample7;
  5543     Sint32 last_sample6 = sample6;
  5544     Sint32 last_sample5 = sample5;
  5545     Sint32 last_sample4 = sample4;
  5546     Sint32 last_sample3 = sample3;
  5547     Sint32 last_sample2 = sample2;
  5548     Sint32 last_sample1 = sample1;
  5549     Sint32 last_sample0 = sample0;
  5550     while (dst >= target) {
  5551         dst[7] = ((Sint32) SDL_SwapLE32(sample7));
  5552         dst[6] = ((Sint32) SDL_SwapLE32(sample6));
  5553         dst[5] = ((Sint32) SDL_SwapLE32(sample5));
  5554         dst[4] = ((Sint32) SDL_SwapLE32(sample4));
  5555         dst[3] = ((Sint32) SDL_SwapLE32(sample3));
  5556         dst[2] = ((Sint32) SDL_SwapLE32(sample2));
  5557         dst[1] = ((Sint32) SDL_SwapLE32(sample1));
  5558         dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5559         dst -= 8;
  5560         eps += srcsize;
  5561         if ((eps << 1) >= dstsize) {
  5562             src -= 8;
  5563             sample7 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[7]))) + ((Sint64) last_sample7)) >> 1);
  5564             sample6 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[6]))) + ((Sint64) last_sample6)) >> 1);
  5565             sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
  5566             sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
  5567             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5568             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5569             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5570             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5571             last_sample7 = sample7;
  5572             last_sample6 = sample6;
  5573             last_sample5 = sample5;
  5574             last_sample4 = sample4;
  5575             last_sample3 = sample3;
  5576             last_sample2 = sample2;
  5577             last_sample1 = sample1;
  5578             last_sample0 = sample0;
  5579             eps -= dstsize;
  5580         }
  5581     }
  5582     cvt->len_cvt = dstsize;
  5583     if (cvt->filters[++cvt->filter_index]) {
  5584         cvt->filters[cvt->filter_index] (cvt, format);
  5585     }
  5586 }
  5587 
  5588 static void SDLCALL
  5589 SDL_Downsample_S32LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5590 {
  5591 #if DEBUG_CONVERT
  5592     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32LSB, 8 channels.\n", cvt->rate_incr);
  5593 #endif
  5594 
  5595     const int srcsize = cvt->len_cvt - 512;
  5596     const int dstsize = (int) (((double)(cvt->len_cvt/32)) * cvt->rate_incr) * 32;
  5597     register int eps = 0;
  5598     Sint32 *dst = (Sint32 *) cvt->buf;
  5599     const Sint32 *src = (Sint32 *) cvt->buf;
  5600     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  5601     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5602     Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
  5603     Sint32 sample2 = ((Sint32) SDL_SwapLE32(src[2]));
  5604     Sint32 sample3 = ((Sint32) SDL_SwapLE32(src[3]));
  5605     Sint32 sample4 = ((Sint32) SDL_SwapLE32(src[4]));
  5606     Sint32 sample5 = ((Sint32) SDL_SwapLE32(src[5]));
  5607     Sint32 sample6 = ((Sint32) SDL_SwapLE32(src[6]));
  5608     Sint32 sample7 = ((Sint32) SDL_SwapLE32(src[7]));
  5609     Sint32 last_sample0 = sample0;
  5610     Sint32 last_sample1 = sample1;
  5611     Sint32 last_sample2 = sample2;
  5612     Sint32 last_sample3 = sample3;
  5613     Sint32 last_sample4 = sample4;
  5614     Sint32 last_sample5 = sample5;
  5615     Sint32 last_sample6 = sample6;
  5616     Sint32 last_sample7 = sample7;
  5617     while (dst < target) {
  5618         src += 8;
  5619         eps += dstsize;
  5620         if ((eps << 1) >= srcsize) {
  5621             dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5622             dst[1] = ((Sint32) SDL_SwapLE32(sample1));
  5623             dst[2] = ((Sint32) SDL_SwapLE32(sample2));
  5624             dst[3] = ((Sint32) SDL_SwapLE32(sample3));
  5625             dst[4] = ((Sint32) SDL_SwapLE32(sample4));
  5626             dst[5] = ((Sint32) SDL_SwapLE32(sample5));
  5627             dst[6] = ((Sint32) SDL_SwapLE32(sample6));
  5628             dst[7] = ((Sint32) SDL_SwapLE32(sample7));
  5629             dst += 8;
  5630             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5631             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5632             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5633             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5634             sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
  5635             sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
  5636             sample6 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[6]))) + ((Sint64) last_sample6)) >> 1);
  5637             sample7 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[7]))) + ((Sint64) last_sample7)) >> 1);
  5638             last_sample0 = sample0;
  5639             last_sample1 = sample1;
  5640             last_sample2 = sample2;
  5641             last_sample3 = sample3;
  5642             last_sample4 = sample4;
  5643             last_sample5 = sample5;
  5644             last_sample6 = sample6;
  5645             last_sample7 = sample7;
  5646             eps -= srcsize;
  5647         }
  5648     }
  5649     cvt->len_cvt = dstsize;
  5650     if (cvt->filters[++cvt->filter_index]) {
  5651         cvt->filters[cvt->filter_index] (cvt, format);
  5652     }
  5653 }
  5654 
  5655 static void SDLCALL
  5656 SDL_Upsample_S32MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5657 {
  5658 #if DEBUG_CONVERT
  5659     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32MSB, 1 channels.\n", cvt->rate_incr);
  5660 #endif
  5661 
  5662     const int srcsize = cvt->len_cvt - 64;
  5663     const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
  5664     register int eps = 0;
  5665     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 1;
  5666     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 1;
  5667     const Sint32 *target = ((const Sint32 *) cvt->buf);
  5668     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  5669     Sint32 last_sample0 = sample0;
  5670     while (dst >= target) {
  5671         dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  5672         dst--;
  5673         eps += srcsize;
  5674         if ((eps << 1) >= dstsize) {
  5675             src--;
  5676             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5677             last_sample0 = sample0;
  5678             eps -= dstsize;
  5679         }
  5680     }
  5681     cvt->len_cvt = dstsize;
  5682     if (cvt->filters[++cvt->filter_index]) {
  5683         cvt->filters[cvt->filter_index] (cvt, format);
  5684     }
  5685 }
  5686 
  5687 static void SDLCALL
  5688 SDL_Downsample_S32MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5689 {
  5690 #if DEBUG_CONVERT
  5691     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32MSB, 1 channels.\n", cvt->rate_incr);
  5692 #endif
  5693 
  5694     const int srcsize = cvt->len_cvt - 64;
  5695     const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
  5696     register int eps = 0;
  5697     Sint32 *dst = (Sint32 *) cvt->buf;
  5698     const Sint32 *src = (Sint32 *) cvt->buf;
  5699     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  5700     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  5701     Sint32 last_sample0 = sample0;
  5702     while (dst < target) {
  5703         src++;
  5704         eps += dstsize;
  5705         if ((eps << 1) >= srcsize) {
  5706             dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  5707             dst++;
  5708             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5709             last_sample0 = sample0;
  5710             eps -= srcsize;
  5711         }
  5712     }
  5713     cvt->len_cvt = dstsize;
  5714     if (cvt->filters[++cvt->filter_index]) {
  5715         cvt->filters[cvt->filter_index] (cvt, format);
  5716     }
  5717 }
  5718 
  5719 static void SDLCALL
  5720 SDL_Upsample_S32MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5721 {
  5722 #if DEBUG_CONVERT
  5723     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32MSB, 2 channels.\n", cvt->rate_incr);
  5724 #endif
  5725 
  5726     const int srcsize = cvt->len_cvt - 128;
  5727     const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
  5728     register int eps = 0;
  5729     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 2;
  5730     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 2;
  5731     const Sint32 *target = ((const Sint32 *) cvt->buf);
  5732     Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
  5733     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  5734     Sint32 last_sample1 = sample1;
  5735     Sint32 last_sample0 = sample0;
  5736     while (dst >= target) {
  5737         dst[1] = ((Sint32) SDL_SwapBE32(sample1));
  5738         dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  5739         dst -= 2;
  5740         eps += srcsize;
  5741         if ((eps << 1) >= dstsize) {
  5742             src -= 2;
  5743             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5744             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5745             last_sample1 = sample1;
  5746             last_sample0 = sample0;
  5747             eps -= dstsize;
  5748         }
  5749     }
  5750     cvt->len_cvt = dstsize;
  5751     if (cvt->filters[++cvt->filter_index]) {
  5752         cvt->filters[cvt->filter_index] (cvt, format);
  5753     }
  5754 }
  5755 
  5756 static void SDLCALL
  5757 SDL_Downsample_S32MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5758 {
  5759 #if DEBUG_CONVERT
  5760     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32MSB, 2 channels.\n", cvt->rate_incr);
  5761 #endif
  5762 
  5763     const int srcsize = cvt->len_cvt - 128;
  5764     const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
  5765     register int eps = 0;
  5766     Sint32 *dst = (Sint32 *) cvt->buf;
  5767     const Sint32 *src = (Sint32 *) cvt->buf;
  5768     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  5769     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  5770     Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
  5771     Sint32 last_sample0 = sample0;
  5772     Sint32 last_sample1 = sample1;
  5773     while (dst < target) {
  5774         src += 2;
  5775         eps += dstsize;
  5776         if ((eps << 1) >= srcsize) {
  5777             dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  5778             dst[1] = ((Sint32) SDL_SwapBE32(sample1));
  5779             dst += 2;
  5780             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5781             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5782             last_sample0 = sample0;
  5783             last_sample1 = sample1;
  5784             eps -= srcsize;
  5785         }
  5786     }
  5787     cvt->len_cvt = dstsize;
  5788     if (cvt->filters[++cvt->filter_index]) {
  5789         cvt->filters[cvt->filter_index] (cvt, format);
  5790     }
  5791 }
  5792 
  5793 static void SDLCALL
  5794 SDL_Upsample_S32MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5795 {
  5796 #if DEBUG_CONVERT
  5797     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32MSB, 4 channels.\n", cvt->rate_incr);
  5798 #endif
  5799 
  5800     const int srcsize = cvt->len_cvt - 256;
  5801     const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
  5802     register int eps = 0;
  5803     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 4;
  5804     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 4;
  5805     const Sint32 *target = ((const Sint32 *) cvt->buf);
  5806     Sint32 sample3 = ((Sint32) SDL_SwapBE32(src[3]));
  5807     Sint32 sample2 = ((Sint32) SDL_SwapBE32(src[2]));
  5808     Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
  5809     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  5810     Sint32 last_sample3 = sample3;
  5811     Sint32 last_sample2 = sample2;
  5812     Sint32 last_sample1 = sample1;
  5813     Sint32 last_sample0 = sample0;
  5814     while (dst >= target) {
  5815         dst[3] = ((Sint32) SDL_SwapBE32(sample3));
  5816         dst[2] = ((Sint32) SDL_SwapBE32(sample2));
  5817         dst[1] = ((Sint32) SDL_SwapBE32(sample1));
  5818         dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  5819         dst -= 4;
  5820         eps += srcsize;
  5821         if ((eps << 1) >= dstsize) {
  5822             src -= 4;
  5823             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5824             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5825             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5826             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5827             last_sample3 = sample3;
  5828             last_sample2 = sample2;
  5829             last_sample1 = sample1;
  5830             last_sample0 = sample0;
  5831             eps -= dstsize;
  5832         }
  5833     }
  5834     cvt->len_cvt = dstsize;
  5835     if (cvt->filters[++cvt->filter_index]) {
  5836         cvt->filters[cvt->filter_index] (cvt, format);
  5837     }
  5838 }
  5839 
  5840 static void SDLCALL
  5841 SDL_Downsample_S32MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5842 {
  5843 #if DEBUG_CONVERT
  5844     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32MSB, 4 channels.\n", cvt->rate_incr);
  5845 #endif
  5846 
  5847     const int srcsize = cvt->len_cvt - 256;
  5848     const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
  5849     register int eps = 0;
  5850     Sint32 *dst = (Sint32 *) cvt->buf;
  5851     const Sint32 *src = (Sint32 *) cvt->buf;
  5852     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  5853     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  5854     Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
  5855     Sint32 sample2 = ((Sint32) SDL_SwapBE32(src[2]));
  5856     Sint32 sample3 = ((Sint32) SDL_SwapBE32(src[3]));
  5857     Sint32 last_sample0 = sample0;
  5858     Sint32 last_sample1 = sample1;
  5859     Sint32 last_sample2 = sample2;
  5860     Sint32 last_sample3 = sample3;
  5861     while (dst < target) {
  5862         src += 4;
  5863         eps += dstsize;
  5864         if ((eps << 1) >= srcsize) {
  5865             dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  5866             dst[1] = ((Sint32) SDL_SwapBE32(sample1));
  5867             dst[2] = ((Sint32) SDL_SwapBE32(sample2));
  5868             dst[3] = ((Sint32) SDL_SwapBE32(sample3));
  5869             dst += 4;
  5870             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5871             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5872             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5873             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5874             last_sample0 = sample0;
  5875             last_sample1 = sample1;
  5876             last_sample2 = sample2;
  5877             last_sample3 = sample3;
  5878             eps -= srcsize;
  5879         }
  5880     }
  5881     cvt->len_cvt = dstsize;
  5882     if (cvt->filters[++cvt->filter_index]) {
  5883         cvt->filters[cvt->filter_index] (cvt, format);
  5884     }
  5885 }
  5886 
  5887 static void SDLCALL
  5888 SDL_Upsample_S32MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5889 {
  5890 #if DEBUG_CONVERT
  5891     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32MSB, 6 channels.\n", cvt->rate_incr);
  5892 #endif
  5893 
  5894     const int srcsize = cvt->len_cvt - 384;
  5895     const int dstsize = (int) (((double)(cvt->len_cvt/24)) * cvt->rate_incr) * 24;
  5896     register int eps = 0;
  5897     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 6;
  5898     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 6;
  5899     const Sint32 *target = ((const Sint32 *) cvt->buf);
  5900     Sint32 sample5 = ((Sint32) SDL_SwapBE32(src[5]));
  5901     Sint32 sample4 = ((Sint32) SDL_SwapBE32(src[4]));
  5902     Sint32 sample3 = ((Sint32) SDL_SwapBE32(src[3]));
  5903     Sint32 sample2 = ((Sint32) SDL_SwapBE32(src[2]));
  5904     Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
  5905     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  5906     Sint32 last_sample5 = sample5;
  5907     Sint32 last_sample4 = sample4;
  5908     Sint32 last_sample3 = sample3;
  5909     Sint32 last_sample2 = sample2;
  5910     Sint32 last_sample1 = sample1;
  5911     Sint32 last_sample0 = sample0;
  5912     while (dst >= target) {
  5913         dst[5] = ((Sint32) SDL_SwapBE32(sample5));
  5914         dst[4] = ((Sint32) SDL_SwapBE32(sample4));
  5915         dst[3] = ((Sint32) SDL_SwapBE32(sample3));
  5916         dst[2] = ((Sint32) SDL_SwapBE32(sample2));
  5917         dst[1] = ((Sint32) SDL_SwapBE32(sample1));
  5918         dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  5919         dst -= 6;
  5920         eps += srcsize;
  5921         if ((eps << 1) >= dstsize) {
  5922             src -= 6;
  5923             sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
  5924             sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
  5925             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5926             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5927             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5928             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5929             last_sample5 = sample5;
  5930             last_sample4 = sample4;
  5931             last_sample3 = sample3;
  5932             last_sample2 = sample2;
  5933             last_sample1 = sample1;
  5934             last_sample0 = sample0;
  5935             eps -= dstsize;
  5936         }
  5937     }
  5938     cvt->len_cvt = dstsize;
  5939     if (cvt->filters[++cvt->filter_index]) {
  5940         cvt->filters[cvt->filter_index] (cvt, format);
  5941     }
  5942 }
  5943 
  5944 static void SDLCALL
  5945 SDL_Downsample_S32MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5946 {
  5947 #if DEBUG_CONVERT
  5948     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32MSB, 6 channels.\n", cvt->rate_incr);
  5949 #endif
  5950 
  5951     const int srcsize = cvt->len_cvt - 384;
  5952     const int dstsize = (int) (((double)(cvt->len_cvt/24)) * cvt->rate_incr) * 24;
  5953     register int eps = 0;
  5954     Sint32 *dst = (Sint32 *) cvt->buf;
  5955     const Sint32 *src = (Sint32 *) cvt->buf;
  5956     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  5957     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  5958     Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
  5959     Sint32 sample2 = ((Sint32) SDL_SwapBE32(src[2]));
  5960     Sint32 sample3 = ((Sint32) SDL_SwapBE32(src[3]));
  5961     Sint32 sample4 = ((Sint32) SDL_SwapBE32(src[4]));
  5962     Sint32 sample5 = ((Sint32) SDL_SwapBE32(src[5]));
  5963     Sint32 last_sample0 = sample0;
  5964     Sint32 last_sample1 = sample1;
  5965     Sint32 last_sample2 = sample2;
  5966     Sint32 last_sample3 = sample3;
  5967     Sint32 last_sample4 = sample4;
  5968     Sint32 last_sample5 = sample5;
  5969     while (dst < target) {
  5970         src += 6;
  5971         eps += dstsize;
  5972         if ((eps << 1) >= srcsize) {
  5973             dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  5974             dst[1] = ((Sint32) SDL_SwapBE32(sample1));
  5975             dst[2] = ((Sint32) SDL_SwapBE32(sample2));
  5976             dst[3] = ((Sint32) SDL_SwapBE32(sample3));
  5977             dst[4] = ((Sint32) SDL_SwapBE32(sample4));
  5978             dst[5] = ((Sint32) SDL_SwapBE32(sample5));
  5979             dst += 6;
  5980             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5981             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5982             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5983             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5984             sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
  5985             sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
  5986             last_sample0 = sample0;
  5987             last_sample1 = sample1;
  5988             last_sample2 = sample2;
  5989             last_sample3 = sample3;
  5990             last_sample4 = sample4;
  5991             last_sample5 = sample5;
  5992             eps -= srcsize;
  5993         }
  5994     }
  5995     cvt->len_cvt = dstsize;
  5996     if (cvt->filters[++cvt->filter_index]) {
  5997         cvt->filters[cvt->filter_index] (cvt, format);
  5998     }
  5999 }
  6000 
  6001 static void SDLCALL
  6002 SDL_Upsample_S32MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6003 {
  6004 #if DEBUG_CONVERT
  6005     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32MSB, 8 channels.\n", cvt->rate_incr);
  6006 #endif
  6007 
  6008     const int srcsize = cvt->len_cvt - 512;
  6009     const int dstsize = (int) (((double)(cvt->len_cvt/32)) * cvt->rate_incr) * 32;
  6010     register int eps = 0;
  6011     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 8;
  6012     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 8;
  6013     const Sint32 *target = ((const Sint32 *) cvt->buf);
  6014     Sint32 sample7 = ((Sint32) SDL_SwapBE32(src[7]));
  6015     Sint32 sample6 = ((Sint32) SDL_SwapBE32(src[6]));
  6016     Sint32 sample5 = ((Sint32) SDL_SwapBE32(src[5]));
  6017     Sint32 sample4 = ((Sint32) SDL_SwapBE32(src[4]));
  6018     Sint32 sample3 = ((Sint32) SDL_SwapBE32(src[3]));
  6019     Sint32 sample2 = ((Sint32) SDL_SwapBE32(src[2]));
  6020     Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
  6021     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  6022     Sint32 last_sample7 = sample7;
  6023     Sint32 last_sample6 = sample6;
  6024     Sint32 last_sample5 = sample5;
  6025     Sint32 last_sample4 = sample4;
  6026     Sint32 last_sample3 = sample3;
  6027     Sint32 last_sample2 = sample2;
  6028     Sint32 last_sample1 = sample1;
  6029     Sint32 last_sample0 = sample0;
  6030     while (dst >= target) {
  6031         dst[7] = ((Sint32) SDL_SwapBE32(sample7));
  6032         dst[6] = ((Sint32) SDL_SwapBE32(sample6));
  6033         dst[5] = ((Sint32) SDL_SwapBE32(sample5));
  6034         dst[4] = ((Sint32) SDL_SwapBE32(sample4));
  6035         dst[3] = ((Sint32) SDL_SwapBE32(sample3));
  6036         dst[2] = ((Sint32) SDL_SwapBE32(sample2));
  6037         dst[1] = ((Sint32) SDL_SwapBE32(sample1));
  6038         dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  6039         dst -= 8;
  6040         eps += srcsize;
  6041         if ((eps << 1) >= dstsize) {
  6042             src -= 8;
  6043             sample7 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[7]))) + ((Sint64) last_sample7)) >> 1);
  6044             sample6 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[6]))) + ((Sint64) last_sample6)) >> 1);
  6045             sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
  6046             sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
  6047             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  6048             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  6049             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  6050             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  6051             last_sample7 = sample7;
  6052             last_sample6 = sample6;
  6053             last_sample5 = sample5;
  6054             last_sample4 = sample4;
  6055             last_sample3 = sample3;
  6056             last_sample2 = sample2;
  6057             last_sample1 = sample1;
  6058             last_sample0 = sample0;
  6059             eps -= dstsize;
  6060         }
  6061     }
  6062     cvt->len_cvt = dstsize;
  6063     if (cvt->filters[++cvt->filter_index]) {
  6064         cvt->filters[cvt->filter_index] (cvt, format);
  6065     }
  6066 }
  6067 
  6068 static void SDLCALL
  6069 SDL_Downsample_S32MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6070 {
  6071 #if DEBUG_CONVERT
  6072     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32MSB, 8 channels.\n", cvt->rate_incr);
  6073 #endif
  6074 
  6075     const int srcsize = cvt->len_cvt - 512;
  6076     const int dstsize = (int) (((double)(cvt->len_cvt/32)) * cvt->rate_incr) * 32;
  6077     register int eps = 0;
  6078     Sint32 *dst = (Sint32 *) cvt->buf;
  6079     const Sint32 *src = (Sint32 *) cvt->buf;
  6080     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  6081     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  6082     Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
  6083     Sint32 sample2 = ((Sint32) SDL_SwapBE32(src[2]));
  6084     Sint32 sample3 = ((Sint32) SDL_SwapBE32(src[3]));
  6085     Sint32 sample4 = ((Sint32) SDL_SwapBE32(src[4]));
  6086     Sint32 sample5 = ((Sint32) SDL_SwapBE32(src[5]));
  6087     Sint32 sample6 = ((Sint32) SDL_SwapBE32(src[6]));
  6088     Sint32 sample7 = ((Sint32) SDL_SwapBE32(src[7]));
  6089     Sint32 last_sample0 = sample0;
  6090     Sint32 last_sample1 = sample1;
  6091     Sint32 last_sample2 = sample2;
  6092     Sint32 last_sample3 = sample3;
  6093     Sint32 last_sample4 = sample4;
  6094     Sint32 last_sample5 = sample5;
  6095     Sint32 last_sample6 = sample6;
  6096     Sint32 last_sample7 = sample7;
  6097     while (dst < target) {
  6098         src += 8;
  6099         eps += dstsize;
  6100         if ((eps << 1) >= srcsize) {
  6101             dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  6102             dst[1] = ((Sint32) SDL_SwapBE32(sample1));
  6103             dst[2] = ((Sint32) SDL_SwapBE32(sample2));
  6104             dst[3] = ((Sint32) SDL_SwapBE32(sample3));
  6105             dst[4] = ((Sint32) SDL_SwapBE32(sample4));
  6106             dst[5] = ((Sint32) SDL_SwapBE32(sample5));
  6107             dst[6] = ((Sint32) SDL_SwapBE32(sample6));
  6108             dst[7] = ((Sint32) SDL_SwapBE32(sample7));
  6109             dst += 8;
  6110             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  6111             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  6112             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  6113             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  6114             sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
  6115             sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
  6116             sample6 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[6]))) + ((Sint64) last_sample6)) >> 1);
  6117             sample7 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[7]))) + ((Sint64) last_sample7)) >> 1);
  6118             last_sample0 = sample0;
  6119             last_sample1 = sample1;
  6120             last_sample2 = sample2;
  6121             last_sample3 = sample3;
  6122             last_sample4 = sample4;
  6123             last_sample5 = sample5;
  6124             last_sample6 = sample6;
  6125             last_sample7 = sample7;
  6126             eps -= srcsize;
  6127         }
  6128     }
  6129     cvt->len_cvt = dstsize;
  6130     if (cvt->filters[++cvt->filter_index]) {
  6131         cvt->filters[cvt->filter_index] (cvt, format);
  6132     }
  6133 }
  6134 
  6135 static void SDLCALL
  6136 SDL_Upsample_F32LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6137 {
  6138 #if DEBUG_CONVERT
  6139     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_F32LSB, 1 channels.\n", cvt->rate_incr);
  6140 #endif
  6141 
  6142     const int srcsize = cvt->len_cvt - 64;
  6143     const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
  6144     register int eps = 0;
  6145     float *dst = ((float *) (cvt->buf + dstsize)) - 1;
  6146     const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 1;
  6147     const float *target = ((const float *) cvt->buf);
  6148     float sample0 = SDL_SwapFloatLE(src[0]);
  6149     float last_sample0 = sample0;
  6150     while (dst >= target) {
  6151         dst[0] = SDL_SwapFloatLE(sample0);
  6152         dst--;
  6153         eps += srcsize;
  6154         if ((eps << 1) >= dstsize) {
  6155             src--;
  6156             sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
  6157             last_sample0 = sample0;
  6158             eps -= dstsize;
  6159         }
  6160     }
  6161     cvt->len_cvt = dstsize;
  6162     if (cvt->filters[++cvt->filter_index]) {
  6163         cvt->filters[cvt->filter_index] (cvt, format);
  6164     }
  6165 }
  6166 
  6167 static void SDLCALL
  6168 SDL_Downsample_F32LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6169 {
  6170 #if DEBUG_CONVERT
  6171     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_F32LSB, 1 channels.\n", cvt->rate_incr);
  6172 #endif
  6173 
  6174     const int srcsize = cvt->len_cvt - 64;
  6175     const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
  6176     register int eps = 0;
  6177     float *dst = (float *) cvt->buf;
  6178     const float *src = (float *) cvt->buf;
  6179     const float *target = (const float *) (cvt->buf + dstsize);
  6180     float sample0 = SDL_SwapFloatLE(src[0]);
  6181     float last_sample0 = sample0;
  6182     while (dst < target) {
  6183         src++;
  6184         eps += dstsize;
  6185         if ((eps << 1) >= srcsize) {
  6186             dst[0] = SDL_SwapFloatLE(sample0);
  6187             dst++;
  6188             sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
  6189             last_sample0 = sample0;
  6190             eps -= srcsize;
  6191         }
  6192     }
  6193     cvt->len_cvt = dstsize;
  6194     if (cvt->filters[++cvt->filter_index]) {
  6195         cvt->filters[cvt->filter_index] (cvt, format);
  6196     }
  6197 }
  6198 
  6199 static void SDLCALL
  6200 SDL_Upsample_F32LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6201 {
  6202 #if DEBUG_CONVERT
  6203     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_F32LSB, 2 channels.\n", cvt->rate_incr);
  6204 #endif
  6205 
  6206     const int srcsize = cvt->len_cvt - 128;
  6207     const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
  6208     register int eps = 0;
  6209     float *dst = ((float *) (cvt->buf + dstsize)) - 2;
  6210     const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 2;
  6211     const float *target = ((const float *) cvt->buf);
  6212     float sample1 = SDL_SwapFloatLE(src[1]);
  6213     float sample0 = SDL_SwapFloatLE(src[0]);
  6214     float last_sample1 = sample1;
  6215     float last_sample0 = sample0;
  6216     while (dst >= target) {
  6217         dst[1] = SDL_SwapFloatLE(sample1);
  6218         dst[0] = SDL_SwapFloatLE(sample0);
  6219         dst -= 2;
  6220         eps += srcsize;
  6221         if ((eps << 1) >= dstsize) {
  6222             src -= 2;
  6223             sample1 = (float) ((((double) SDL_SwapFloatLE(src[1])) + ((double) last_sample1)) * 0.5);
  6224             sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
  6225             last_sample1 = sample1;
  6226             last_sample0 = sample0;
  6227             eps -= dstsize;
  6228         }
  6229     }
  6230     cvt->len_cvt = dstsize;
  6231     if (cvt->filters[++cvt->filter_index]) {
  6232         cvt->filters[cvt->filter_index] (cvt, format);
  6233     }
  6234 }
  6235 
  6236 static void SDLCALL
  6237 SDL_Downsample_F32LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6238 {
  6239 #if DEBUG_CONVERT
  6240     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_F32LSB, 2 channels.\n", cvt->rate_incr);
  6241 #endif
  6242 
  6243     const int srcsize = cvt->len_cvt - 128;
  6244     const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
  6245     register int eps = 0;
  6246     float *dst = (float *) cvt->buf;
  6247     const float *src = (float *) cvt->buf;
  6248     const float *target = (const float *) (cvt->buf + dstsize);
  6249     float sample0 = SDL_SwapFloatLE(src[0]);
  6250     float sample1 = SDL_SwapFloatLE(src[1]);
  6251     float last_sample0 = sample0;
  6252     float last_sample1 = sample1;
  6253     while (dst < target) {
  6254         src += 2;
  6255         eps += dstsize;
  6256         if ((eps << 1) >= srcsize) {
  6257             dst[0] = SDL_SwapFloatLE(sample0);
  6258             dst[1] = SDL_SwapFloatLE(sample1);
  6259             dst += 2;
  6260             sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
  6261             sample1 = (float) ((((double) SDL_SwapFloatLE(src[1])) + ((double) last_sample1)) * 0.5);
  6262             last_sample0 = sample0;
  6263             last_sample1 = sample1;
  6264             eps -= srcsize;
  6265         }
  6266     }
  6267     cvt->len_cvt = dstsize;
  6268     if (cvt->filters[++cvt->filter_index]) {
  6269         cvt->filters[cvt->filter_index] (cvt, format);
  6270     }
  6271 }
  6272 
  6273 static void SDLCALL
  6274 SDL_Upsample_F32LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6275 {
  6276 #if DEBUG_CONVERT
  6277     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_F32LSB, 4 channels.\n", cvt->rate_incr);
  6278 #endif
  6279 
  6280     const int srcsize = cvt->len_cvt - 256;
  6281     const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
  6282     register int eps = 0;
  6283     float *dst = ((float *) (cvt->buf + dstsize)) - 4;
  6284     const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 4;
  6285     const float *target = ((const float *) cvt->buf);
  6286     float sample3 = SDL_SwapFloatLE(src[3]);
  6287     float sample2 = SDL_SwapFloatLE(src[2]);
  6288     float sample1 = SDL_SwapFloatLE(src[1]);
  6289     float sample0 = SDL_SwapFloatLE(src[0]);
  6290     float last_sample3 = sample3;
  6291     float last_sample2 = sample2;
  6292     float last_sample1 = sample1;
  6293     float last_sample0 = sample0;
  6294     while (dst >= target) {
  6295         dst[3] = SDL_SwapFloatLE(sample3);
  6296         dst[2] = SDL_SwapFloatLE(sample2);
  6297         dst[1] = SDL_SwapFloatLE(sample1);
  6298         dst[0] = SDL_SwapFloatLE(sample0);
  6299         dst -= 4;
  6300         eps += srcsize;
  6301         if ((eps << 1) >= dstsize) {
  6302             src -= 4;
  6303             sample3 = (float) ((((double) SDL_SwapFloatLE(src[3])) + ((double) last_sample3)) * 0.5);
  6304             sample2 = (float) ((((double) SDL_SwapFloatLE(src[2])) + ((double) last_sample2)) * 0.5);
  6305             sample1 = (float) ((((double) SDL_SwapFloatLE(src[1])) + ((double) last_sample1)) * 0.5);
  6306             sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
  6307             last_sample3 = sample3;
  6308             last_sample2 = sample2;
  6309             last_sample1 = sample1;
  6310             last_sample0 = sample0;
  6311             eps -= dstsize;
  6312         }
  6313     }
  6314     cvt->len_cvt = dstsize;
  6315     if (cvt->filters[++cvt->filter_index]) {
  6316         cvt->filters[cvt->filter_index] (cvt, format);
  6317     }
  6318 }
  6319 
  6320 static void SDLCALL
  6321 SDL_Downsample_F32LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6322 {
  6323 #if DEBUG_CONVERT
  6324     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_F32LSB, 4 channels.\n", cvt->rate_incr);
  6325 #endif
  6326 
  6327     const int srcsize = cvt->len_cvt - 256;
  6328     const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
  6329     register int eps = 0;
  6330     float *dst = (float *) cvt->buf;
  6331     const float *src = (float *) cvt->buf;
  6332     const float *target = (const float *) (cvt->buf + dstsize);
  6333     float sample0 = SDL_SwapFloatLE(src[0]);
  6334     float sample1 = SDL_SwapFloatLE(src[1]);
  6335     float sample2 = SDL_SwapFloatLE(src[2]);
  6336     float sample3 = SDL_SwapFloatLE(src[3]);
  6337     float last_sample0 = sample0;
  6338     float last_sample1 = sample1;
  6339     float last_sample2 = sample2;
  6340     float last_sample3 = sample3;
  6341     while (dst < target) {
  6342         src += 4;
  6343         eps += dstsize;
  6344         if ((eps << 1) >= srcsize) {
  6345             dst[0] = SDL_SwapFloatLE(sample0);
  6346             dst[1] = SDL_SwapFloatLE(sample1);
  6347             dst[2] = SDL_SwapFloatLE(sample2);
  6348             dst[3] = SDL_SwapFloatLE(sample3);
  6349             dst += 4;
  6350             sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
  6351             sample1 = (float) ((((double) SDL_SwapFloatLE(src[1])) + ((double) last_sample1)) * 0.5);
  6352             sample2 = (float) ((((double) SDL_SwapFloatLE(src[2])) + ((double) last_sample2)) * 0.5);
  6353             sample3 = (float) ((((double) SDL_SwapFloatLE(src[3])) + ((double) last_sample3)) * 0.5);
  6354             last_sample0 = sample0;
  6355             last_sample1 = sample1;
  6356             last_sample2 = sample2;
  6357             last_sample3 = sample3;
  6358             eps -= srcsize;
  6359         }
  6360     }
  6361     cvt->len_cvt = dstsize;
  6362     if (cvt->filters[++cvt->filter_index]) {
  6363         cvt->filters[cvt->filter_index] (cvt, format);
  6364     }
  6365 }
  6366 
  6367 static void SDLCALL
  6368 SDL_Upsample_F32LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6369 {
  6370 #if DEBUG_CONVERT
  6371     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_F32LSB, 6 channels.\n", cvt->rate_incr);
  6372 #endif
  6373 
  6374     const int srcsize = cvt->len_cvt - 384;
  6375     const int dstsize = (int) (((double)(cvt->len_cvt/24)) * cvt->rate_incr) * 24;
  6376     register int eps = 0;
  6377     float *dst = ((float *) (cvt->buf + dstsize)) - 6;
  6378     const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 6;
  6379     const float *target = ((const float *) cvt->buf);
  6380     float sample5 = SDL_SwapFloatLE(src[5]);
  6381     float sample4 = SDL_SwapFloatLE(src[4]);
  6382     float sample3 = SDL_SwapFloatLE(src[3]);
  6383     float sample2 = SDL_SwapFloatLE(src[2]);
  6384     float sample1 = SDL_SwapFloatLE(src[1]);
  6385     float sample0 = SDL_SwapFloatLE(src[0]);
  6386     float last_sample5 = sample5;
  6387     float last_sample4 = sample4;
  6388     float last_sample3 = sample3;
  6389     float last_sample2 = sample2;
  6390     float last_sample1 = sample1;
  6391     float last_sample0 = sample0;
  6392     while (dst >= target) {
  6393         dst[5] = SDL_SwapFloatLE(sample5);
  6394         dst[4] = SDL_SwapFloatLE(sample4);
  6395         dst[3] = SDL_SwapFloatLE(sample3);
  6396         dst[2] = SDL_SwapFloatLE(sample2);
  6397         dst[1] = SDL_SwapFloatLE(sample1);
  6398         dst[0] = SDL_SwapFloatLE(sample0);
  6399         dst -= 6;
  6400         eps += srcsize;
  6401         if ((eps << 1) >= dstsize) {
  6402             src -= 6;
  6403             sample5 = (float) ((((double) SDL_SwapFloatLE(src[5])) + ((double) last_sample5)) * 0.5);
  6404             sample4 = (float) ((((double) SDL_SwapFloatLE(src[4])) + ((double) last_sample4)) * 0.5);
  6405             sample3 = (float) ((((double) SDL_SwapFloatLE(src[3])) + ((double) last_sample3)) * 0.5);
  6406             sample2 = (float) ((((double) SDL_SwapFloatLE(src[2])) + ((double) last_sample2)) * 0.5);
  6407             sample1 = (float) ((((double) SDL_SwapFloatLE(src[1])) + ((double) last_sample1)) * 0.5);
  6408             sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
  6409             last_sample5 = sample5;
  6410             last_sample4 = sample4;
  6411             last_sample3 = sample3;
  6412             last_sample2 = sample2;
  6413             last_sample1 = sample1;
  6414             last_sample0 = sample0;
  6415             eps -= dstsize;
  6416         }
  6417     }
  6418     cvt->len_cvt = dstsize;
  6419     if (cvt->filters[++cvt->filter_index]) {
  6420         cvt->filters[cvt->filter_index] (cvt, format);
  6421     }
  6422 }
  6423 
  6424 static void SDLCALL
  6425 SDL_Downsample_F32LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6426 {
  6427 #if DEBUG_CONVERT
  6428     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_F32LSB, 6 channels.\n", cvt->rate_incr);
  6429 #endif
  6430 
  6431     const int srcsize = cvt->len_cvt - 384;
  6432     const int dstsize = (int) (((double)(cvt->len_cvt/24)) * cvt->rate_incr) * 24;
  6433     register int eps = 0;
  6434     float *dst = (float *) cvt->buf;
  6435     const float *src = (float *) cvt->buf;
  6436     const float *target = (const float *) (cvt->buf + dstsize);
  6437     float sample0 = SDL_SwapFloatLE(src[0]);
  6438     float sample1 = SDL_SwapFloatLE(src[1]);
  6439     float sample2 = SDL_SwapFloatLE(src[2]);