src/audio/SDL_audiotypecvt.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 12 Jan 2009 08:46:28 +0000
changeset 3032 77c3e67f0740
parent 3021 f3dcf04412cf
child 3602 bfa8d34ce03a
permissions -rw-r--r--
Fixed Visual C++ build
     1 /* DO NOT EDIT!  This file is generated by sdlgenaudiocvt.pl */
     2 /*
     3     SDL - Simple DirectMedia Layer
     4     Copyright (C) 1997-2009 Sam Lantinga
     5 
     6     This library is free software; you can redistribute it and/or
     7     modify it under the terms of the GNU Lesser General Public
     8     License as published by the Free Software Foundation; either
     9     version 2.1 of the License, or (at your option) any later version.
    10 
    11     This library is distributed in the hope that it will be useful,
    12     but WITHOUT ANY WARRANTY; without even the implied warranty of
    13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    14     Lesser General Public License for more details.
    15 
    16     You should have received a copy of the GNU Lesser General Public
    17     License along with this library; if not, write to the Free Software
    18     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    19 
    20     Sam Lantinga
    21     slouken@libsdl.org
    22 */
    23 
    24 #include "SDL_config.h"
    25 #include "SDL_audio.h"
    26 #include "SDL_audio_c.h"
    27 
    28 #ifndef DEBUG_CONVERT
    29 #define DEBUG_CONVERT 0
    30 #endif
    31 
    32 
    33 /* If you can guarantee your data and need space, you can eliminate code... */
    34 
    35 /* Just build the arbitrary resamplers if you're saving code space. */
    36 #ifndef LESS_RESAMPLERS
    37 #define LESS_RESAMPLERS 0
    38 #endif
    39 
    40 /* Don't build any resamplers if you're REALLY saving code space. */
    41 #ifndef NO_RESAMPLERS
    42 #define NO_RESAMPLERS 0
    43 #endif
    44 
    45 /* Don't build any type converters if you're saving code space. */
    46 #ifndef NO_CONVERTERS
    47 #define NO_CONVERTERS 0
    48 #endif
    49 
    50 
    51 /* *INDENT-OFF* */
    52 
    53 #define DIVBY127 0.0078740157480315f
    54 #define DIVBY32767 3.05185094759972e-05f
    55 #define DIVBY2147483647 4.6566128752458e-10f
    56 
    57 #if !NO_CONVERTERS
    58 
    59 static void SDLCALL
    60 SDL_Convert_U8_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
    61 {
    62     int i;
    63     const Uint8 *src;
    64     Sint8 *dst;
    65 
    66 #if DEBUG_CONVERT
    67     fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S8.\n");
    68 #endif
    69 
    70     src = (const Uint8 *) cvt->buf;
    71     dst = (Sint8 *) cvt->buf;
    72     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, ++src, ++dst) {
    73         const Sint8 val = ((*src) ^ 0x80);
    74         *dst = ((Sint8) val);
    75     }
    76 
    77     if (cvt->filters[++cvt->filter_index]) {
    78         cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
    79     }
    80 }
    81 
    82 static void SDLCALL
    83 SDL_Convert_U8_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
    84 {
    85     int i;
    86     const Uint8 *src;
    87     Uint16 *dst;
    88 
    89 #if DEBUG_CONVERT
    90     fprintf(stderr, "Converting AUDIO_U8 to AUDIO_U16LSB.\n");
    91 #endif
    92 
    93     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
    94     dst = ((Uint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
    95     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
    96         const Uint16 val = (((Uint16) *src) << 8);
    97         *dst = SDL_SwapLE16(val);
    98     }
    99 
   100     cvt->len_cvt *= 2;
   101     if (cvt->filters[++cvt->filter_index]) {
   102         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
   103     }
   104 }
   105 
   106 static void SDLCALL
   107 SDL_Convert_U8_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   108 {
   109     int i;
   110     const Uint8 *src;
   111     Sint16 *dst;
   112 
   113 #if DEBUG_CONVERT
   114     fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S16LSB.\n");
   115 #endif
   116 
   117     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
   118     dst = ((Sint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
   119     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
   120         const Sint16 val = (((Sint16) ((*src) ^ 0x80)) << 8);
   121         *dst = ((Sint16) SDL_SwapLE16(val));
   122     }
   123 
   124     cvt->len_cvt *= 2;
   125     if (cvt->filters[++cvt->filter_index]) {
   126         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
   127     }
   128 }
   129 
   130 static void SDLCALL
   131 SDL_Convert_U8_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   132 {
   133     int i;
   134     const Uint8 *src;
   135     Uint16 *dst;
   136 
   137 #if DEBUG_CONVERT
   138     fprintf(stderr, "Converting AUDIO_U8 to AUDIO_U16MSB.\n");
   139 #endif
   140 
   141     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
   142     dst = ((Uint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
   143     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
   144         const Uint16 val = (((Uint16) *src) << 8);
   145         *dst = SDL_SwapBE16(val);
   146     }
   147 
   148     cvt->len_cvt *= 2;
   149     if (cvt->filters[++cvt->filter_index]) {
   150         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
   151     }
   152 }
   153 
   154 static void SDLCALL
   155 SDL_Convert_U8_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   156 {
   157     int i;
   158     const Uint8 *src;
   159     Sint16 *dst;
   160 
   161 #if DEBUG_CONVERT
   162     fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S16MSB.\n");
   163 #endif
   164 
   165     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
   166     dst = ((Sint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
   167     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
   168         const Sint16 val = (((Sint16) ((*src) ^ 0x80)) << 8);
   169         *dst = ((Sint16) SDL_SwapBE16(val));
   170     }
   171 
   172     cvt->len_cvt *= 2;
   173     if (cvt->filters[++cvt->filter_index]) {
   174         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
   175     }
   176 }
   177 
   178 static void SDLCALL
   179 SDL_Convert_U8_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   180 {
   181     int i;
   182     const Uint8 *src;
   183     Sint32 *dst;
   184 
   185 #if DEBUG_CONVERT
   186     fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S32LSB.\n");
   187 #endif
   188 
   189     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
   190     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 4)) - 1;
   191     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
   192         const Sint32 val = (((Sint32) ((*src) ^ 0x80)) << 24);
   193         *dst = ((Sint32) SDL_SwapLE32(val));
   194     }
   195 
   196     cvt->len_cvt *= 4;
   197     if (cvt->filters[++cvt->filter_index]) {
   198         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
   199     }
   200 }
   201 
   202 static void SDLCALL
   203 SDL_Convert_U8_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   204 {
   205     int i;
   206     const Uint8 *src;
   207     Sint32 *dst;
   208 
   209 #if DEBUG_CONVERT
   210     fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S32MSB.\n");
   211 #endif
   212 
   213     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
   214     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 4)) - 1;
   215     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
   216         const Sint32 val = (((Sint32) ((*src) ^ 0x80)) << 24);
   217         *dst = ((Sint32) SDL_SwapBE32(val));
   218     }
   219 
   220     cvt->len_cvt *= 4;
   221     if (cvt->filters[++cvt->filter_index]) {
   222         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
   223     }
   224 }
   225 
   226 static void SDLCALL
   227 SDL_Convert_U8_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   228 {
   229     int i;
   230     const Uint8 *src;
   231     float *dst;
   232 
   233 #if DEBUG_CONVERT
   234     fprintf(stderr, "Converting AUDIO_U8 to AUDIO_F32LSB.\n");
   235 #endif
   236 
   237     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
   238     dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
   239     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
   240         const float val = ((((float) *src) * DIVBY127) - 1.0f);
   241         *dst = SDL_SwapFloatLE(val);
   242     }
   243 
   244     cvt->len_cvt *= 4;
   245     if (cvt->filters[++cvt->filter_index]) {
   246         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
   247     }
   248 }
   249 
   250 static void SDLCALL
   251 SDL_Convert_U8_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   252 {
   253     int i;
   254     const Uint8 *src;
   255     float *dst;
   256 
   257 #if DEBUG_CONVERT
   258     fprintf(stderr, "Converting AUDIO_U8 to AUDIO_F32MSB.\n");
   259 #endif
   260 
   261     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
   262     dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
   263     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
   264         const float val = ((((float) *src) * DIVBY127) - 1.0f);
   265         *dst = SDL_SwapFloatBE(val);
   266     }
   267 
   268     cvt->len_cvt *= 4;
   269     if (cvt->filters[++cvt->filter_index]) {
   270         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
   271     }
   272 }
   273 
   274 static void SDLCALL
   275 SDL_Convert_S8_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   276 {
   277     int i;
   278     const Uint8 *src;
   279     Uint8 *dst;
   280 
   281 #if DEBUG_CONVERT
   282     fprintf(stderr, "Converting AUDIO_S8 to AUDIO_U8.\n");
   283 #endif
   284 
   285     src = (const Uint8 *) cvt->buf;
   286     dst = (Uint8 *) cvt->buf;
   287     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, ++src, ++dst) {
   288         const Uint8 val = ((((Sint8) *src)) ^ 0x80);
   289         *dst = val;
   290     }
   291 
   292     if (cvt->filters[++cvt->filter_index]) {
   293         cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
   294     }
   295 }
   296 
   297 static void SDLCALL
   298 SDL_Convert_S8_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   299 {
   300     int i;
   301     const Uint8 *src;
   302     Uint16 *dst;
   303 
   304 #if DEBUG_CONVERT
   305     fprintf(stderr, "Converting AUDIO_S8 to AUDIO_U16LSB.\n");
   306 #endif
   307 
   308     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
   309     dst = ((Uint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
   310     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
   311         const Uint16 val = (((Uint16) ((((Sint8) *src)) ^ 0x80)) << 8);
   312         *dst = SDL_SwapLE16(val);
   313     }
   314 
   315     cvt->len_cvt *= 2;
   316     if (cvt->filters[++cvt->filter_index]) {
   317         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
   318     }
   319 }
   320 
   321 static void SDLCALL
   322 SDL_Convert_S8_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   323 {
   324     int i;
   325     const Uint8 *src;
   326     Sint16 *dst;
   327 
   328 #if DEBUG_CONVERT
   329     fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S16LSB.\n");
   330 #endif
   331 
   332     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
   333     dst = ((Sint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
   334     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
   335         const Sint16 val = (((Sint16) ((Sint8) *src)) << 8);
   336         *dst = ((Sint16) SDL_SwapLE16(val));
   337     }
   338 
   339     cvt->len_cvt *= 2;
   340     if (cvt->filters[++cvt->filter_index]) {
   341         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
   342     }
   343 }
   344 
   345 static void SDLCALL
   346 SDL_Convert_S8_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   347 {
   348     int i;
   349     const Uint8 *src;
   350     Uint16 *dst;
   351 
   352 #if DEBUG_CONVERT
   353     fprintf(stderr, "Converting AUDIO_S8 to AUDIO_U16MSB.\n");
   354 #endif
   355 
   356     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
   357     dst = ((Uint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
   358     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
   359         const Uint16 val = (((Uint16) ((((Sint8) *src)) ^ 0x80)) << 8);
   360         *dst = SDL_SwapBE16(val);
   361     }
   362 
   363     cvt->len_cvt *= 2;
   364     if (cvt->filters[++cvt->filter_index]) {
   365         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
   366     }
   367 }
   368 
   369 static void SDLCALL
   370 SDL_Convert_S8_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   371 {
   372     int i;
   373     const Uint8 *src;
   374     Sint16 *dst;
   375 
   376 #if DEBUG_CONVERT
   377     fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S16MSB.\n");
   378 #endif
   379 
   380     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
   381     dst = ((Sint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
   382     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
   383         const Sint16 val = (((Sint16) ((Sint8) *src)) << 8);
   384         *dst = ((Sint16) SDL_SwapBE16(val));
   385     }
   386 
   387     cvt->len_cvt *= 2;
   388     if (cvt->filters[++cvt->filter_index]) {
   389         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
   390     }
   391 }
   392 
   393 static void SDLCALL
   394 SDL_Convert_S8_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   395 {
   396     int i;
   397     const Uint8 *src;
   398     Sint32 *dst;
   399 
   400 #if DEBUG_CONVERT
   401     fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S32LSB.\n");
   402 #endif
   403 
   404     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
   405     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 4)) - 1;
   406     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
   407         const Sint32 val = (((Sint32) ((Sint8) *src)) << 24);
   408         *dst = ((Sint32) SDL_SwapLE32(val));
   409     }
   410 
   411     cvt->len_cvt *= 4;
   412     if (cvt->filters[++cvt->filter_index]) {
   413         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
   414     }
   415 }
   416 
   417 static void SDLCALL
   418 SDL_Convert_S8_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   419 {
   420     int i;
   421     const Uint8 *src;
   422     Sint32 *dst;
   423 
   424 #if DEBUG_CONVERT
   425     fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S32MSB.\n");
   426 #endif
   427 
   428     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
   429     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 4)) - 1;
   430     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
   431         const Sint32 val = (((Sint32) ((Sint8) *src)) << 24);
   432         *dst = ((Sint32) SDL_SwapBE32(val));
   433     }
   434 
   435     cvt->len_cvt *= 4;
   436     if (cvt->filters[++cvt->filter_index]) {
   437         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
   438     }
   439 }
   440 
   441 static void SDLCALL
   442 SDL_Convert_S8_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   443 {
   444     int i;
   445     const Uint8 *src;
   446     float *dst;
   447 
   448 #if DEBUG_CONVERT
   449     fprintf(stderr, "Converting AUDIO_S8 to AUDIO_F32LSB.\n");
   450 #endif
   451 
   452     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
   453     dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
   454     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
   455         const float val = (((float) ((Sint8) *src)) * DIVBY127);
   456         *dst = SDL_SwapFloatLE(val);
   457     }
   458 
   459     cvt->len_cvt *= 4;
   460     if (cvt->filters[++cvt->filter_index]) {
   461         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
   462     }
   463 }
   464 
   465 static void SDLCALL
   466 SDL_Convert_S8_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   467 {
   468     int i;
   469     const Uint8 *src;
   470     float *dst;
   471 
   472 #if DEBUG_CONVERT
   473     fprintf(stderr, "Converting AUDIO_S8 to AUDIO_F32MSB.\n");
   474 #endif
   475 
   476     src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
   477     dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
   478     for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
   479         const float val = (((float) ((Sint8) *src)) * DIVBY127);
   480         *dst = SDL_SwapFloatBE(val);
   481     }
   482 
   483     cvt->len_cvt *= 4;
   484     if (cvt->filters[++cvt->filter_index]) {
   485         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
   486     }
   487 }
   488 
   489 static void SDLCALL
   490 SDL_Convert_U16LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   491 {
   492     int i;
   493     const Uint16 *src;
   494     Uint8 *dst;
   495 
   496 #if DEBUG_CONVERT
   497     fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_U8.\n");
   498 #endif
   499 
   500     src = (const Uint16 *) cvt->buf;
   501     dst = (Uint8 *) cvt->buf;
   502     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
   503         const Uint8 val = ((Uint8) (SDL_SwapLE16(*src) >> 8));
   504         *dst = val;
   505     }
   506 
   507     cvt->len_cvt /= 2;
   508     if (cvt->filters[++cvt->filter_index]) {
   509         cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
   510     }
   511 }
   512 
   513 static void SDLCALL
   514 SDL_Convert_U16LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   515 {
   516     int i;
   517     const Uint16 *src;
   518     Sint8 *dst;
   519 
   520 #if DEBUG_CONVERT
   521     fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S8.\n");
   522 #endif
   523 
   524     src = (const Uint16 *) cvt->buf;
   525     dst = (Sint8 *) cvt->buf;
   526     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
   527         const Sint8 val = ((Sint8) (((SDL_SwapLE16(*src)) ^ 0x8000) >> 8));
   528         *dst = ((Sint8) val);
   529     }
   530 
   531     cvt->len_cvt /= 2;
   532     if (cvt->filters[++cvt->filter_index]) {
   533         cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
   534     }
   535 }
   536 
   537 static void SDLCALL
   538 SDL_Convert_U16LSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   539 {
   540     int i;
   541     const Uint16 *src;
   542     Sint16 *dst;
   543 
   544 #if DEBUG_CONVERT
   545     fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S16LSB.\n");
   546 #endif
   547 
   548     src = (const Uint16 *) cvt->buf;
   549     dst = (Sint16 *) cvt->buf;
   550     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
   551         const Sint16 val = ((SDL_SwapLE16(*src)) ^ 0x8000);
   552         *dst = ((Sint16) SDL_SwapLE16(val));
   553     }
   554 
   555     if (cvt->filters[++cvt->filter_index]) {
   556         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
   557     }
   558 }
   559 
   560 static void SDLCALL
   561 SDL_Convert_U16LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   562 {
   563     int i;
   564     const Uint16 *src;
   565     Uint16 *dst;
   566 
   567 #if DEBUG_CONVERT
   568     fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_U16MSB.\n");
   569 #endif
   570 
   571     src = (const Uint16 *) cvt->buf;
   572     dst = (Uint16 *) cvt->buf;
   573     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
   574         const Uint16 val = SDL_SwapLE16(*src);
   575         *dst = SDL_SwapBE16(val);
   576     }
   577 
   578     if (cvt->filters[++cvt->filter_index]) {
   579         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
   580     }
   581 }
   582 
   583 static void SDLCALL
   584 SDL_Convert_U16LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   585 {
   586     int i;
   587     const Uint16 *src;
   588     Sint16 *dst;
   589 
   590 #if DEBUG_CONVERT
   591     fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S16MSB.\n");
   592 #endif
   593 
   594     src = (const Uint16 *) cvt->buf;
   595     dst = (Sint16 *) cvt->buf;
   596     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
   597         const Sint16 val = ((SDL_SwapLE16(*src)) ^ 0x8000);
   598         *dst = ((Sint16) SDL_SwapBE16(val));
   599     }
   600 
   601     if (cvt->filters[++cvt->filter_index]) {
   602         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
   603     }
   604 }
   605 
   606 static void SDLCALL
   607 SDL_Convert_U16LSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   608 {
   609     int i;
   610     const Uint16 *src;
   611     Sint32 *dst;
   612 
   613 #if DEBUG_CONVERT
   614     fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S32LSB.\n");
   615 #endif
   616 
   617     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
   618     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
   619     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
   620         const Sint32 val = (((Sint32) ((SDL_SwapLE16(*src)) ^ 0x8000)) << 16);
   621         *dst = ((Sint32) SDL_SwapLE32(val));
   622     }
   623 
   624     cvt->len_cvt *= 2;
   625     if (cvt->filters[++cvt->filter_index]) {
   626         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
   627     }
   628 }
   629 
   630 static void SDLCALL
   631 SDL_Convert_U16LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   632 {
   633     int i;
   634     const Uint16 *src;
   635     Sint32 *dst;
   636 
   637 #if DEBUG_CONVERT
   638     fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S32MSB.\n");
   639 #endif
   640 
   641     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
   642     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
   643     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
   644         const Sint32 val = (((Sint32) ((SDL_SwapLE16(*src)) ^ 0x8000)) << 16);
   645         *dst = ((Sint32) SDL_SwapBE32(val));
   646     }
   647 
   648     cvt->len_cvt *= 2;
   649     if (cvt->filters[++cvt->filter_index]) {
   650         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
   651     }
   652 }
   653 
   654 static void SDLCALL
   655 SDL_Convert_U16LSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   656 {
   657     int i;
   658     const Uint16 *src;
   659     float *dst;
   660 
   661 #if DEBUG_CONVERT
   662     fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_F32LSB.\n");
   663 #endif
   664 
   665     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
   666     dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
   667     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
   668         const float val = ((((float) SDL_SwapLE16(*src)) * DIVBY32767) - 1.0f);
   669         *dst = SDL_SwapFloatLE(val);
   670     }
   671 
   672     cvt->len_cvt *= 2;
   673     if (cvt->filters[++cvt->filter_index]) {
   674         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
   675     }
   676 }
   677 
   678 static void SDLCALL
   679 SDL_Convert_U16LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   680 {
   681     int i;
   682     const Uint16 *src;
   683     float *dst;
   684 
   685 #if DEBUG_CONVERT
   686     fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_F32MSB.\n");
   687 #endif
   688 
   689     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
   690     dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
   691     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
   692         const float val = ((((float) SDL_SwapLE16(*src)) * DIVBY32767) - 1.0f);
   693         *dst = SDL_SwapFloatBE(val);
   694     }
   695 
   696     cvt->len_cvt *= 2;
   697     if (cvt->filters[++cvt->filter_index]) {
   698         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
   699     }
   700 }
   701 
   702 static void SDLCALL
   703 SDL_Convert_S16LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   704 {
   705     int i;
   706     const Uint16 *src;
   707     Uint8 *dst;
   708 
   709 #if DEBUG_CONVERT
   710     fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_U8.\n");
   711 #endif
   712 
   713     src = (const Uint16 *) cvt->buf;
   714     dst = (Uint8 *) cvt->buf;
   715     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
   716         const Uint8 val = ((Uint8) (((((Sint16) SDL_SwapLE16(*src))) ^ 0x8000) >> 8));
   717         *dst = val;
   718     }
   719 
   720     cvt->len_cvt /= 2;
   721     if (cvt->filters[++cvt->filter_index]) {
   722         cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
   723     }
   724 }
   725 
   726 static void SDLCALL
   727 SDL_Convert_S16LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   728 {
   729     int i;
   730     const Uint16 *src;
   731     Sint8 *dst;
   732 
   733 #if DEBUG_CONVERT
   734     fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S8.\n");
   735 #endif
   736 
   737     src = (const Uint16 *) cvt->buf;
   738     dst = (Sint8 *) cvt->buf;
   739     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
   740         const Sint8 val = ((Sint8) (((Sint16) SDL_SwapLE16(*src)) >> 8));
   741         *dst = ((Sint8) val);
   742     }
   743 
   744     cvt->len_cvt /= 2;
   745     if (cvt->filters[++cvt->filter_index]) {
   746         cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
   747     }
   748 }
   749 
   750 static void SDLCALL
   751 SDL_Convert_S16LSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   752 {
   753     int i;
   754     const Uint16 *src;
   755     Uint16 *dst;
   756 
   757 #if DEBUG_CONVERT
   758     fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_U16LSB.\n");
   759 #endif
   760 
   761     src = (const Uint16 *) cvt->buf;
   762     dst = (Uint16 *) cvt->buf;
   763     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
   764         const Uint16 val = ((((Sint16) SDL_SwapLE16(*src))) ^ 0x8000);
   765         *dst = SDL_SwapLE16(val);
   766     }
   767 
   768     if (cvt->filters[++cvt->filter_index]) {
   769         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
   770     }
   771 }
   772 
   773 static void SDLCALL
   774 SDL_Convert_S16LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   775 {
   776     int i;
   777     const Uint16 *src;
   778     Uint16 *dst;
   779 
   780 #if DEBUG_CONVERT
   781     fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_U16MSB.\n");
   782 #endif
   783 
   784     src = (const Uint16 *) cvt->buf;
   785     dst = (Uint16 *) cvt->buf;
   786     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
   787         const Uint16 val = ((((Sint16) SDL_SwapLE16(*src))) ^ 0x8000);
   788         *dst = SDL_SwapBE16(val);
   789     }
   790 
   791     if (cvt->filters[++cvt->filter_index]) {
   792         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
   793     }
   794 }
   795 
   796 static void SDLCALL
   797 SDL_Convert_S16LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   798 {
   799     int i;
   800     const Uint16 *src;
   801     Sint16 *dst;
   802 
   803 #if DEBUG_CONVERT
   804     fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S16MSB.\n");
   805 #endif
   806 
   807     src = (const Uint16 *) cvt->buf;
   808     dst = (Sint16 *) cvt->buf;
   809     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
   810         const Sint16 val = ((Sint16) SDL_SwapLE16(*src));
   811         *dst = ((Sint16) SDL_SwapBE16(val));
   812     }
   813 
   814     if (cvt->filters[++cvt->filter_index]) {
   815         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
   816     }
   817 }
   818 
   819 static void SDLCALL
   820 SDL_Convert_S16LSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   821 {
   822     int i;
   823     const Uint16 *src;
   824     Sint32 *dst;
   825 
   826 #if DEBUG_CONVERT
   827     fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S32LSB.\n");
   828 #endif
   829 
   830     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
   831     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
   832     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
   833         const Sint32 val = (((Sint32) ((Sint16) SDL_SwapLE16(*src))) << 16);
   834         *dst = ((Sint32) SDL_SwapLE32(val));
   835     }
   836 
   837     cvt->len_cvt *= 2;
   838     if (cvt->filters[++cvt->filter_index]) {
   839         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
   840     }
   841 }
   842 
   843 static void SDLCALL
   844 SDL_Convert_S16LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   845 {
   846     int i;
   847     const Uint16 *src;
   848     Sint32 *dst;
   849 
   850 #if DEBUG_CONVERT
   851     fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S32MSB.\n");
   852 #endif
   853 
   854     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
   855     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
   856     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
   857         const Sint32 val = (((Sint32) ((Sint16) SDL_SwapLE16(*src))) << 16);
   858         *dst = ((Sint32) SDL_SwapBE32(val));
   859     }
   860 
   861     cvt->len_cvt *= 2;
   862     if (cvt->filters[++cvt->filter_index]) {
   863         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
   864     }
   865 }
   866 
   867 static void SDLCALL
   868 SDL_Convert_S16LSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   869 {
   870     int i;
   871     const Uint16 *src;
   872     float *dst;
   873 
   874 #if DEBUG_CONVERT
   875     fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_F32LSB.\n");
   876 #endif
   877 
   878     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
   879     dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
   880     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
   881         const float val = (((float) ((Sint16) SDL_SwapLE16(*src))) * DIVBY32767);
   882         *dst = SDL_SwapFloatLE(val);
   883     }
   884 
   885     cvt->len_cvt *= 2;
   886     if (cvt->filters[++cvt->filter_index]) {
   887         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
   888     }
   889 }
   890 
   891 static void SDLCALL
   892 SDL_Convert_S16LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   893 {
   894     int i;
   895     const Uint16 *src;
   896     float *dst;
   897 
   898 #if DEBUG_CONVERT
   899     fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_F32MSB.\n");
   900 #endif
   901 
   902     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
   903     dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
   904     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
   905         const float val = (((float) ((Sint16) SDL_SwapLE16(*src))) * DIVBY32767);
   906         *dst = SDL_SwapFloatBE(val);
   907     }
   908 
   909     cvt->len_cvt *= 2;
   910     if (cvt->filters[++cvt->filter_index]) {
   911         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
   912     }
   913 }
   914 
   915 static void SDLCALL
   916 SDL_Convert_U16MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   917 {
   918     int i;
   919     const Uint16 *src;
   920     Uint8 *dst;
   921 
   922 #if DEBUG_CONVERT
   923     fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_U8.\n");
   924 #endif
   925 
   926     src = (const Uint16 *) cvt->buf;
   927     dst = (Uint8 *) cvt->buf;
   928     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
   929         const Uint8 val = ((Uint8) (SDL_SwapBE16(*src) >> 8));
   930         *dst = val;
   931     }
   932 
   933     cvt->len_cvt /= 2;
   934     if (cvt->filters[++cvt->filter_index]) {
   935         cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
   936     }
   937 }
   938 
   939 static void SDLCALL
   940 SDL_Convert_U16MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   941 {
   942     int i;
   943     const Uint16 *src;
   944     Sint8 *dst;
   945 
   946 #if DEBUG_CONVERT
   947     fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S8.\n");
   948 #endif
   949 
   950     src = (const Uint16 *) cvt->buf;
   951     dst = (Sint8 *) cvt->buf;
   952     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
   953         const Sint8 val = ((Sint8) (((SDL_SwapBE16(*src)) ^ 0x8000) >> 8));
   954         *dst = ((Sint8) val);
   955     }
   956 
   957     cvt->len_cvt /= 2;
   958     if (cvt->filters[++cvt->filter_index]) {
   959         cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
   960     }
   961 }
   962 
   963 static void SDLCALL
   964 SDL_Convert_U16MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   965 {
   966     int i;
   967     const Uint16 *src;
   968     Uint16 *dst;
   969 
   970 #if DEBUG_CONVERT
   971     fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_U16LSB.\n");
   972 #endif
   973 
   974     src = (const Uint16 *) cvt->buf;
   975     dst = (Uint16 *) cvt->buf;
   976     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
   977         const Uint16 val = SDL_SwapBE16(*src);
   978         *dst = SDL_SwapLE16(val);
   979     }
   980 
   981     if (cvt->filters[++cvt->filter_index]) {
   982         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
   983     }
   984 }
   985 
   986 static void SDLCALL
   987 SDL_Convert_U16MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
   988 {
   989     int i;
   990     const Uint16 *src;
   991     Sint16 *dst;
   992 
   993 #if DEBUG_CONVERT
   994     fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S16LSB.\n");
   995 #endif
   996 
   997     src = (const Uint16 *) cvt->buf;
   998     dst = (Sint16 *) cvt->buf;
   999     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
  1000         const Sint16 val = ((SDL_SwapBE16(*src)) ^ 0x8000);
  1001         *dst = ((Sint16) SDL_SwapLE16(val));
  1002     }
  1003 
  1004     if (cvt->filters[++cvt->filter_index]) {
  1005         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
  1006     }
  1007 }
  1008 
  1009 static void SDLCALL
  1010 SDL_Convert_U16MSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1011 {
  1012     int i;
  1013     const Uint16 *src;
  1014     Sint16 *dst;
  1015 
  1016 #if DEBUG_CONVERT
  1017     fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S16MSB.\n");
  1018 #endif
  1019 
  1020     src = (const Uint16 *) cvt->buf;
  1021     dst = (Sint16 *) cvt->buf;
  1022     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
  1023         const Sint16 val = ((SDL_SwapBE16(*src)) ^ 0x8000);
  1024         *dst = ((Sint16) SDL_SwapBE16(val));
  1025     }
  1026 
  1027     if (cvt->filters[++cvt->filter_index]) {
  1028         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
  1029     }
  1030 }
  1031 
  1032 static void SDLCALL
  1033 SDL_Convert_U16MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1034 {
  1035     int i;
  1036     const Uint16 *src;
  1037     Sint32 *dst;
  1038 
  1039 #if DEBUG_CONVERT
  1040     fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S32LSB.\n");
  1041 #endif
  1042 
  1043     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
  1044     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
  1045     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
  1046         const Sint32 val = (((Sint32) ((SDL_SwapBE16(*src)) ^ 0x8000)) << 16);
  1047         *dst = ((Sint32) SDL_SwapLE32(val));
  1048     }
  1049 
  1050     cvt->len_cvt *= 2;
  1051     if (cvt->filters[++cvt->filter_index]) {
  1052         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
  1053     }
  1054 }
  1055 
  1056 static void SDLCALL
  1057 SDL_Convert_U16MSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1058 {
  1059     int i;
  1060     const Uint16 *src;
  1061     Sint32 *dst;
  1062 
  1063 #if DEBUG_CONVERT
  1064     fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S32MSB.\n");
  1065 #endif
  1066 
  1067     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
  1068     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
  1069     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
  1070         const Sint32 val = (((Sint32) ((SDL_SwapBE16(*src)) ^ 0x8000)) << 16);
  1071         *dst = ((Sint32) SDL_SwapBE32(val));
  1072     }
  1073 
  1074     cvt->len_cvt *= 2;
  1075     if (cvt->filters[++cvt->filter_index]) {
  1076         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
  1077     }
  1078 }
  1079 
  1080 static void SDLCALL
  1081 SDL_Convert_U16MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1082 {
  1083     int i;
  1084     const Uint16 *src;
  1085     float *dst;
  1086 
  1087 #if DEBUG_CONVERT
  1088     fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_F32LSB.\n");
  1089 #endif
  1090 
  1091     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
  1092     dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
  1093     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
  1094         const float val = ((((float) SDL_SwapBE16(*src)) * DIVBY32767) - 1.0f);
  1095         *dst = SDL_SwapFloatLE(val);
  1096     }
  1097 
  1098     cvt->len_cvt *= 2;
  1099     if (cvt->filters[++cvt->filter_index]) {
  1100         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
  1101     }
  1102 }
  1103 
  1104 static void SDLCALL
  1105 SDL_Convert_U16MSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1106 {
  1107     int i;
  1108     const Uint16 *src;
  1109     float *dst;
  1110 
  1111 #if DEBUG_CONVERT
  1112     fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_F32MSB.\n");
  1113 #endif
  1114 
  1115     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
  1116     dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
  1117     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
  1118         const float val = ((((float) SDL_SwapBE16(*src)) * DIVBY32767) - 1.0f);
  1119         *dst = SDL_SwapFloatBE(val);
  1120     }
  1121 
  1122     cvt->len_cvt *= 2;
  1123     if (cvt->filters[++cvt->filter_index]) {
  1124         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
  1125     }
  1126 }
  1127 
  1128 static void SDLCALL
  1129 SDL_Convert_S16MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1130 {
  1131     int i;
  1132     const Uint16 *src;
  1133     Uint8 *dst;
  1134 
  1135 #if DEBUG_CONVERT
  1136     fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_U8.\n");
  1137 #endif
  1138 
  1139     src = (const Uint16 *) cvt->buf;
  1140     dst = (Uint8 *) cvt->buf;
  1141     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
  1142         const Uint8 val = ((Uint8) (((((Sint16) SDL_SwapBE16(*src))) ^ 0x8000) >> 8));
  1143         *dst = val;
  1144     }
  1145 
  1146     cvt->len_cvt /= 2;
  1147     if (cvt->filters[++cvt->filter_index]) {
  1148         cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
  1149     }
  1150 }
  1151 
  1152 static void SDLCALL
  1153 SDL_Convert_S16MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1154 {
  1155     int i;
  1156     const Uint16 *src;
  1157     Sint8 *dst;
  1158 
  1159 #if DEBUG_CONVERT
  1160     fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S8.\n");
  1161 #endif
  1162 
  1163     src = (const Uint16 *) cvt->buf;
  1164     dst = (Sint8 *) cvt->buf;
  1165     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
  1166         const Sint8 val = ((Sint8) (((Sint16) SDL_SwapBE16(*src)) >> 8));
  1167         *dst = ((Sint8) val);
  1168     }
  1169 
  1170     cvt->len_cvt /= 2;
  1171     if (cvt->filters[++cvt->filter_index]) {
  1172         cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
  1173     }
  1174 }
  1175 
  1176 static void SDLCALL
  1177 SDL_Convert_S16MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1178 {
  1179     int i;
  1180     const Uint16 *src;
  1181     Uint16 *dst;
  1182 
  1183 #if DEBUG_CONVERT
  1184     fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_U16LSB.\n");
  1185 #endif
  1186 
  1187     src = (const Uint16 *) cvt->buf;
  1188     dst = (Uint16 *) cvt->buf;
  1189     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
  1190         const Uint16 val = ((((Sint16) SDL_SwapBE16(*src))) ^ 0x8000);
  1191         *dst = SDL_SwapLE16(val);
  1192     }
  1193 
  1194     if (cvt->filters[++cvt->filter_index]) {
  1195         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
  1196     }
  1197 }
  1198 
  1199 static void SDLCALL
  1200 SDL_Convert_S16MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1201 {
  1202     int i;
  1203     const Uint16 *src;
  1204     Sint16 *dst;
  1205 
  1206 #if DEBUG_CONVERT
  1207     fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S16LSB.\n");
  1208 #endif
  1209 
  1210     src = (const Uint16 *) cvt->buf;
  1211     dst = (Sint16 *) cvt->buf;
  1212     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
  1213         const Sint16 val = ((Sint16) SDL_SwapBE16(*src));
  1214         *dst = ((Sint16) SDL_SwapLE16(val));
  1215     }
  1216 
  1217     if (cvt->filters[++cvt->filter_index]) {
  1218         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
  1219     }
  1220 }
  1221 
  1222 static void SDLCALL
  1223 SDL_Convert_S16MSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1224 {
  1225     int i;
  1226     const Uint16 *src;
  1227     Uint16 *dst;
  1228 
  1229 #if DEBUG_CONVERT
  1230     fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_U16MSB.\n");
  1231 #endif
  1232 
  1233     src = (const Uint16 *) cvt->buf;
  1234     dst = (Uint16 *) cvt->buf;
  1235     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
  1236         const Uint16 val = ((((Sint16) SDL_SwapBE16(*src))) ^ 0x8000);
  1237         *dst = SDL_SwapBE16(val);
  1238     }
  1239 
  1240     if (cvt->filters[++cvt->filter_index]) {
  1241         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
  1242     }
  1243 }
  1244 
  1245 static void SDLCALL
  1246 SDL_Convert_S16MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1247 {
  1248     int i;
  1249     const Uint16 *src;
  1250     Sint32 *dst;
  1251 
  1252 #if DEBUG_CONVERT
  1253     fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S32LSB.\n");
  1254 #endif
  1255 
  1256     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
  1257     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
  1258     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
  1259         const Sint32 val = (((Sint32) ((Sint16) SDL_SwapBE16(*src))) << 16);
  1260         *dst = ((Sint32) SDL_SwapLE32(val));
  1261     }
  1262 
  1263     cvt->len_cvt *= 2;
  1264     if (cvt->filters[++cvt->filter_index]) {
  1265         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
  1266     }
  1267 }
  1268 
  1269 static void SDLCALL
  1270 SDL_Convert_S16MSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1271 {
  1272     int i;
  1273     const Uint16 *src;
  1274     Sint32 *dst;
  1275 
  1276 #if DEBUG_CONVERT
  1277     fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S32MSB.\n");
  1278 #endif
  1279 
  1280     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
  1281     dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
  1282     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
  1283         const Sint32 val = (((Sint32) ((Sint16) SDL_SwapBE16(*src))) << 16);
  1284         *dst = ((Sint32) SDL_SwapBE32(val));
  1285     }
  1286 
  1287     cvt->len_cvt *= 2;
  1288     if (cvt->filters[++cvt->filter_index]) {
  1289         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
  1290     }
  1291 }
  1292 
  1293 static void SDLCALL
  1294 SDL_Convert_S16MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1295 {
  1296     int i;
  1297     const Uint16 *src;
  1298     float *dst;
  1299 
  1300 #if DEBUG_CONVERT
  1301     fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_F32LSB.\n");
  1302 #endif
  1303 
  1304     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
  1305     dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
  1306     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
  1307         const float val = (((float) ((Sint16) SDL_SwapBE16(*src))) * DIVBY32767);
  1308         *dst = SDL_SwapFloatLE(val);
  1309     }
  1310 
  1311     cvt->len_cvt *= 2;
  1312     if (cvt->filters[++cvt->filter_index]) {
  1313         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
  1314     }
  1315 }
  1316 
  1317 static void SDLCALL
  1318 SDL_Convert_S16MSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1319 {
  1320     int i;
  1321     const Uint16 *src;
  1322     float *dst;
  1323 
  1324 #if DEBUG_CONVERT
  1325     fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_F32MSB.\n");
  1326 #endif
  1327 
  1328     src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
  1329     dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
  1330     for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
  1331         const float val = (((float) ((Sint16) SDL_SwapBE16(*src))) * DIVBY32767);
  1332         *dst = SDL_SwapFloatBE(val);
  1333     }
  1334 
  1335     cvt->len_cvt *= 2;
  1336     if (cvt->filters[++cvt->filter_index]) {
  1337         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
  1338     }
  1339 }
  1340 
  1341 static void SDLCALL
  1342 SDL_Convert_S32LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1343 {
  1344     int i;
  1345     const Uint32 *src;
  1346     Uint8 *dst;
  1347 
  1348 #if DEBUG_CONVERT
  1349     fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_U8.\n");
  1350 #endif
  1351 
  1352     src = (const Uint32 *) cvt->buf;
  1353     dst = (Uint8 *) cvt->buf;
  1354     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
  1355         const Uint8 val = ((Uint8) (((((Sint32) SDL_SwapLE32(*src))) ^ 0x80000000) >> 24));
  1356         *dst = val;
  1357     }
  1358 
  1359     cvt->len_cvt /= 4;
  1360     if (cvt->filters[++cvt->filter_index]) {
  1361         cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
  1362     }
  1363 }
  1364 
  1365 static void SDLCALL
  1366 SDL_Convert_S32LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1367 {
  1368     int i;
  1369     const Uint32 *src;
  1370     Sint8 *dst;
  1371 
  1372 #if DEBUG_CONVERT
  1373     fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S8.\n");
  1374 #endif
  1375 
  1376     src = (const Uint32 *) cvt->buf;
  1377     dst = (Sint8 *) cvt->buf;
  1378     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
  1379         const Sint8 val = ((Sint8) (((Sint32) SDL_SwapLE32(*src)) >> 24));
  1380         *dst = ((Sint8) val);
  1381     }
  1382 
  1383     cvt->len_cvt /= 4;
  1384     if (cvt->filters[++cvt->filter_index]) {
  1385         cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
  1386     }
  1387 }
  1388 
  1389 static void SDLCALL
  1390 SDL_Convert_S32LSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1391 {
  1392     int i;
  1393     const Uint32 *src;
  1394     Uint16 *dst;
  1395 
  1396 #if DEBUG_CONVERT
  1397     fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_U16LSB.\n");
  1398 #endif
  1399 
  1400     src = (const Uint32 *) cvt->buf;
  1401     dst = (Uint16 *) cvt->buf;
  1402     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
  1403         const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapLE32(*src))) ^ 0x80000000) >> 16));
  1404         *dst = SDL_SwapLE16(val);
  1405     }
  1406 
  1407     cvt->len_cvt /= 2;
  1408     if (cvt->filters[++cvt->filter_index]) {
  1409         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
  1410     }
  1411 }
  1412 
  1413 static void SDLCALL
  1414 SDL_Convert_S32LSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1415 {
  1416     int i;
  1417     const Uint32 *src;
  1418     Sint16 *dst;
  1419 
  1420 #if DEBUG_CONVERT
  1421     fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S16LSB.\n");
  1422 #endif
  1423 
  1424     src = (const Uint32 *) cvt->buf;
  1425     dst = (Sint16 *) cvt->buf;
  1426     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
  1427         const Sint16 val = ((Sint16) (((Sint32) SDL_SwapLE32(*src)) >> 16));
  1428         *dst = ((Sint16) SDL_SwapLE16(val));
  1429     }
  1430 
  1431     cvt->len_cvt /= 2;
  1432     if (cvt->filters[++cvt->filter_index]) {
  1433         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
  1434     }
  1435 }
  1436 
  1437 static void SDLCALL
  1438 SDL_Convert_S32LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1439 {
  1440     int i;
  1441     const Uint32 *src;
  1442     Uint16 *dst;
  1443 
  1444 #if DEBUG_CONVERT
  1445     fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_U16MSB.\n");
  1446 #endif
  1447 
  1448     src = (const Uint32 *) cvt->buf;
  1449     dst = (Uint16 *) cvt->buf;
  1450     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
  1451         const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapLE32(*src))) ^ 0x80000000) >> 16));
  1452         *dst = SDL_SwapBE16(val);
  1453     }
  1454 
  1455     cvt->len_cvt /= 2;
  1456     if (cvt->filters[++cvt->filter_index]) {
  1457         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
  1458     }
  1459 }
  1460 
  1461 static void SDLCALL
  1462 SDL_Convert_S32LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1463 {
  1464     int i;
  1465     const Uint32 *src;
  1466     Sint16 *dst;
  1467 
  1468 #if DEBUG_CONVERT
  1469     fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S16MSB.\n");
  1470 #endif
  1471 
  1472     src = (const Uint32 *) cvt->buf;
  1473     dst = (Sint16 *) cvt->buf;
  1474     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
  1475         const Sint16 val = ((Sint16) (((Sint32) SDL_SwapLE32(*src)) >> 16));
  1476         *dst = ((Sint16) SDL_SwapBE16(val));
  1477     }
  1478 
  1479     cvt->len_cvt /= 2;
  1480     if (cvt->filters[++cvt->filter_index]) {
  1481         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
  1482     }
  1483 }
  1484 
  1485 static void SDLCALL
  1486 SDL_Convert_S32LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1487 {
  1488     int i;
  1489     const Uint32 *src;
  1490     Sint32 *dst;
  1491 
  1492 #if DEBUG_CONVERT
  1493     fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S32MSB.\n");
  1494 #endif
  1495 
  1496     src = (const Uint32 *) cvt->buf;
  1497     dst = (Sint32 *) cvt->buf;
  1498     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
  1499         const Sint32 val = ((Sint32) SDL_SwapLE32(*src));
  1500         *dst = ((Sint32) SDL_SwapBE32(val));
  1501     }
  1502 
  1503     if (cvt->filters[++cvt->filter_index]) {
  1504         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
  1505     }
  1506 }
  1507 
  1508 static void SDLCALL
  1509 SDL_Convert_S32LSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1510 {
  1511     int i;
  1512     const Uint32 *src;
  1513     float *dst;
  1514 
  1515 #if DEBUG_CONVERT
  1516     fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_F32LSB.\n");
  1517 #endif
  1518 
  1519     src = (const Uint32 *) cvt->buf;
  1520     dst = (float *) cvt->buf;
  1521     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
  1522         const float val = (((float) ((Sint32) SDL_SwapLE32(*src))) * DIVBY2147483647);
  1523         *dst = SDL_SwapFloatLE(val);
  1524     }
  1525 
  1526     if (cvt->filters[++cvt->filter_index]) {
  1527         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
  1528     }
  1529 }
  1530 
  1531 static void SDLCALL
  1532 SDL_Convert_S32LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1533 {
  1534     int i;
  1535     const Uint32 *src;
  1536     float *dst;
  1537 
  1538 #if DEBUG_CONVERT
  1539     fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_F32MSB.\n");
  1540 #endif
  1541 
  1542     src = (const Uint32 *) cvt->buf;
  1543     dst = (float *) cvt->buf;
  1544     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
  1545         const float val = (((float) ((Sint32) SDL_SwapLE32(*src))) * DIVBY2147483647);
  1546         *dst = SDL_SwapFloatBE(val);
  1547     }
  1548 
  1549     if (cvt->filters[++cvt->filter_index]) {
  1550         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
  1551     }
  1552 }
  1553 
  1554 static void SDLCALL
  1555 SDL_Convert_S32MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1556 {
  1557     int i;
  1558     const Uint32 *src;
  1559     Uint8 *dst;
  1560 
  1561 #if DEBUG_CONVERT
  1562     fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_U8.\n");
  1563 #endif
  1564 
  1565     src = (const Uint32 *) cvt->buf;
  1566     dst = (Uint8 *) cvt->buf;
  1567     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
  1568         const Uint8 val = ((Uint8) (((((Sint32) SDL_SwapBE32(*src))) ^ 0x80000000) >> 24));
  1569         *dst = val;
  1570     }
  1571 
  1572     cvt->len_cvt /= 4;
  1573     if (cvt->filters[++cvt->filter_index]) {
  1574         cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
  1575     }
  1576 }
  1577 
  1578 static void SDLCALL
  1579 SDL_Convert_S32MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1580 {
  1581     int i;
  1582     const Uint32 *src;
  1583     Sint8 *dst;
  1584 
  1585 #if DEBUG_CONVERT
  1586     fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S8.\n");
  1587 #endif
  1588 
  1589     src = (const Uint32 *) cvt->buf;
  1590     dst = (Sint8 *) cvt->buf;
  1591     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
  1592         const Sint8 val = ((Sint8) (((Sint32) SDL_SwapBE32(*src)) >> 24));
  1593         *dst = ((Sint8) val);
  1594     }
  1595 
  1596     cvt->len_cvt /= 4;
  1597     if (cvt->filters[++cvt->filter_index]) {
  1598         cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
  1599     }
  1600 }
  1601 
  1602 static void SDLCALL
  1603 SDL_Convert_S32MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1604 {
  1605     int i;
  1606     const Uint32 *src;
  1607     Uint16 *dst;
  1608 
  1609 #if DEBUG_CONVERT
  1610     fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_U16LSB.\n");
  1611 #endif
  1612 
  1613     src = (const Uint32 *) cvt->buf;
  1614     dst = (Uint16 *) cvt->buf;
  1615     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
  1616         const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapBE32(*src))) ^ 0x80000000) >> 16));
  1617         *dst = SDL_SwapLE16(val);
  1618     }
  1619 
  1620     cvt->len_cvt /= 2;
  1621     if (cvt->filters[++cvt->filter_index]) {
  1622         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
  1623     }
  1624 }
  1625 
  1626 static void SDLCALL
  1627 SDL_Convert_S32MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1628 {
  1629     int i;
  1630     const Uint32 *src;
  1631     Sint16 *dst;
  1632 
  1633 #if DEBUG_CONVERT
  1634     fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S16LSB.\n");
  1635 #endif
  1636 
  1637     src = (const Uint32 *) cvt->buf;
  1638     dst = (Sint16 *) cvt->buf;
  1639     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
  1640         const Sint16 val = ((Sint16) (((Sint32) SDL_SwapBE32(*src)) >> 16));
  1641         *dst = ((Sint16) SDL_SwapLE16(val));
  1642     }
  1643 
  1644     cvt->len_cvt /= 2;
  1645     if (cvt->filters[++cvt->filter_index]) {
  1646         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
  1647     }
  1648 }
  1649 
  1650 static void SDLCALL
  1651 SDL_Convert_S32MSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1652 {
  1653     int i;
  1654     const Uint32 *src;
  1655     Uint16 *dst;
  1656 
  1657 #if DEBUG_CONVERT
  1658     fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_U16MSB.\n");
  1659 #endif
  1660 
  1661     src = (const Uint32 *) cvt->buf;
  1662     dst = (Uint16 *) cvt->buf;
  1663     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
  1664         const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapBE32(*src))) ^ 0x80000000) >> 16));
  1665         *dst = SDL_SwapBE16(val);
  1666     }
  1667 
  1668     cvt->len_cvt /= 2;
  1669     if (cvt->filters[++cvt->filter_index]) {
  1670         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
  1671     }
  1672 }
  1673 
  1674 static void SDLCALL
  1675 SDL_Convert_S32MSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1676 {
  1677     int i;
  1678     const Uint32 *src;
  1679     Sint16 *dst;
  1680 
  1681 #if DEBUG_CONVERT
  1682     fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S16MSB.\n");
  1683 #endif
  1684 
  1685     src = (const Uint32 *) cvt->buf;
  1686     dst = (Sint16 *) cvt->buf;
  1687     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
  1688         const Sint16 val = ((Sint16) (((Sint32) SDL_SwapBE32(*src)) >> 16));
  1689         *dst = ((Sint16) SDL_SwapBE16(val));
  1690     }
  1691 
  1692     cvt->len_cvt /= 2;
  1693     if (cvt->filters[++cvt->filter_index]) {
  1694         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
  1695     }
  1696 }
  1697 
  1698 static void SDLCALL
  1699 SDL_Convert_S32MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1700 {
  1701     int i;
  1702     const Uint32 *src;
  1703     Sint32 *dst;
  1704 
  1705 #if DEBUG_CONVERT
  1706     fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S32LSB.\n");
  1707 #endif
  1708 
  1709     src = (const Uint32 *) cvt->buf;
  1710     dst = (Sint32 *) cvt->buf;
  1711     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
  1712         const Sint32 val = ((Sint32) SDL_SwapBE32(*src));
  1713         *dst = ((Sint32) SDL_SwapLE32(val));
  1714     }
  1715 
  1716     if (cvt->filters[++cvt->filter_index]) {
  1717         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
  1718     }
  1719 }
  1720 
  1721 static void SDLCALL
  1722 SDL_Convert_S32MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1723 {
  1724     int i;
  1725     const Uint32 *src;
  1726     float *dst;
  1727 
  1728 #if DEBUG_CONVERT
  1729     fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_F32LSB.\n");
  1730 #endif
  1731 
  1732     src = (const Uint32 *) cvt->buf;
  1733     dst = (float *) cvt->buf;
  1734     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
  1735         const float val = (((float) ((Sint32) SDL_SwapBE32(*src))) * DIVBY2147483647);
  1736         *dst = SDL_SwapFloatLE(val);
  1737     }
  1738 
  1739     if (cvt->filters[++cvt->filter_index]) {
  1740         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
  1741     }
  1742 }
  1743 
  1744 static void SDLCALL
  1745 SDL_Convert_S32MSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1746 {
  1747     int i;
  1748     const Uint32 *src;
  1749     float *dst;
  1750 
  1751 #if DEBUG_CONVERT
  1752     fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_F32MSB.\n");
  1753 #endif
  1754 
  1755     src = (const Uint32 *) cvt->buf;
  1756     dst = (float *) cvt->buf;
  1757     for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
  1758         const float val = (((float) ((Sint32) SDL_SwapBE32(*src))) * DIVBY2147483647);
  1759         *dst = SDL_SwapFloatBE(val);
  1760     }
  1761 
  1762     if (cvt->filters[++cvt->filter_index]) {
  1763         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
  1764     }
  1765 }
  1766 
  1767 static void SDLCALL
  1768 SDL_Convert_F32LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1769 {
  1770     int i;
  1771     const float *src;
  1772     Uint8 *dst;
  1773 
  1774 #if DEBUG_CONVERT
  1775     fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_U8.\n");
  1776 #endif
  1777 
  1778     src = (const float *) cvt->buf;
  1779     dst = (Uint8 *) cvt->buf;
  1780     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
  1781         const Uint8 val = ((Uint8) ((SDL_SwapFloatLE(*src) + 1.0f) * 127.0f));
  1782         *dst = val;
  1783     }
  1784 
  1785     cvt->len_cvt /= 4;
  1786     if (cvt->filters[++cvt->filter_index]) {
  1787         cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
  1788     }
  1789 }
  1790 
  1791 static void SDLCALL
  1792 SDL_Convert_F32LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1793 {
  1794     int i;
  1795     const float *src;
  1796     Sint8 *dst;
  1797 
  1798 #if DEBUG_CONVERT
  1799     fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S8.\n");
  1800 #endif
  1801 
  1802     src = (const float *) cvt->buf;
  1803     dst = (Sint8 *) cvt->buf;
  1804     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
  1805         const Sint8 val = ((Sint8) (SDL_SwapFloatLE(*src) * 127.0f));
  1806         *dst = ((Sint8) val);
  1807     }
  1808 
  1809     cvt->len_cvt /= 4;
  1810     if (cvt->filters[++cvt->filter_index]) {
  1811         cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
  1812     }
  1813 }
  1814 
  1815 static void SDLCALL
  1816 SDL_Convert_F32LSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1817 {
  1818     int i;
  1819     const float *src;
  1820     Uint16 *dst;
  1821 
  1822 #if DEBUG_CONVERT
  1823     fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_U16LSB.\n");
  1824 #endif
  1825 
  1826     src = (const float *) cvt->buf;
  1827     dst = (Uint16 *) cvt->buf;
  1828     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
  1829         const Uint16 val = ((Uint16) ((SDL_SwapFloatLE(*src) + 1.0f) * 32767.0f));
  1830         *dst = SDL_SwapLE16(val);
  1831     }
  1832 
  1833     cvt->len_cvt /= 2;
  1834     if (cvt->filters[++cvt->filter_index]) {
  1835         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
  1836     }
  1837 }
  1838 
  1839 static void SDLCALL
  1840 SDL_Convert_F32LSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1841 {
  1842     int i;
  1843     const float *src;
  1844     Sint16 *dst;
  1845 
  1846 #if DEBUG_CONVERT
  1847     fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S16LSB.\n");
  1848 #endif
  1849 
  1850     src = (const float *) cvt->buf;
  1851     dst = (Sint16 *) cvt->buf;
  1852     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
  1853         const Sint16 val = ((Sint16) (SDL_SwapFloatLE(*src) * 32767.0f));
  1854         *dst = ((Sint16) SDL_SwapLE16(val));
  1855     }
  1856 
  1857     cvt->len_cvt /= 2;
  1858     if (cvt->filters[++cvt->filter_index]) {
  1859         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
  1860     }
  1861 }
  1862 
  1863 static void SDLCALL
  1864 SDL_Convert_F32LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1865 {
  1866     int i;
  1867     const float *src;
  1868     Uint16 *dst;
  1869 
  1870 #if DEBUG_CONVERT
  1871     fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_U16MSB.\n");
  1872 #endif
  1873 
  1874     src = (const float *) cvt->buf;
  1875     dst = (Uint16 *) cvt->buf;
  1876     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
  1877         const Uint16 val = ((Uint16) ((SDL_SwapFloatLE(*src) + 1.0f) * 32767.0f));
  1878         *dst = SDL_SwapBE16(val);
  1879     }
  1880 
  1881     cvt->len_cvt /= 2;
  1882     if (cvt->filters[++cvt->filter_index]) {
  1883         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
  1884     }
  1885 }
  1886 
  1887 static void SDLCALL
  1888 SDL_Convert_F32LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1889 {
  1890     int i;
  1891     const float *src;
  1892     Sint16 *dst;
  1893 
  1894 #if DEBUG_CONVERT
  1895     fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S16MSB.\n");
  1896 #endif
  1897 
  1898     src = (const float *) cvt->buf;
  1899     dst = (Sint16 *) cvt->buf;
  1900     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
  1901         const Sint16 val = ((Sint16) (SDL_SwapFloatLE(*src) * 32767.0f));
  1902         *dst = ((Sint16) SDL_SwapBE16(val));
  1903     }
  1904 
  1905     cvt->len_cvt /= 2;
  1906     if (cvt->filters[++cvt->filter_index]) {
  1907         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
  1908     }
  1909 }
  1910 
  1911 static void SDLCALL
  1912 SDL_Convert_F32LSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1913 {
  1914     int i;
  1915     const float *src;
  1916     Sint32 *dst;
  1917 
  1918 #if DEBUG_CONVERT
  1919     fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S32LSB.\n");
  1920 #endif
  1921 
  1922     src = (const float *) cvt->buf;
  1923     dst = (Sint32 *) cvt->buf;
  1924     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
  1925         const Sint32 val = ((Sint32) (SDL_SwapFloatLE(*src) * 2147483647.0));
  1926         *dst = ((Sint32) SDL_SwapLE32(val));
  1927     }
  1928 
  1929     if (cvt->filters[++cvt->filter_index]) {
  1930         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
  1931     }
  1932 }
  1933 
  1934 static void SDLCALL
  1935 SDL_Convert_F32LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1936 {
  1937     int i;
  1938     const float *src;
  1939     Sint32 *dst;
  1940 
  1941 #if DEBUG_CONVERT
  1942     fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S32MSB.\n");
  1943 #endif
  1944 
  1945     src = (const float *) cvt->buf;
  1946     dst = (Sint32 *) cvt->buf;
  1947     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
  1948         const Sint32 val = ((Sint32) (SDL_SwapFloatLE(*src) * 2147483647.0));
  1949         *dst = ((Sint32) SDL_SwapBE32(val));
  1950     }
  1951 
  1952     if (cvt->filters[++cvt->filter_index]) {
  1953         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
  1954     }
  1955 }
  1956 
  1957 static void SDLCALL
  1958 SDL_Convert_F32LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1959 {
  1960     int i;
  1961     const float *src;
  1962     float *dst;
  1963 
  1964 #if DEBUG_CONVERT
  1965     fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_F32MSB.\n");
  1966 #endif
  1967 
  1968     src = (const float *) cvt->buf;
  1969     dst = (float *) cvt->buf;
  1970     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
  1971         const float val = SDL_SwapFloatLE(*src);
  1972         *dst = SDL_SwapFloatBE(val);
  1973     }
  1974 
  1975     if (cvt->filters[++cvt->filter_index]) {
  1976         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
  1977     }
  1978 }
  1979 
  1980 static void SDLCALL
  1981 SDL_Convert_F32MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  1982 {
  1983     int i;
  1984     const float *src;
  1985     Uint8 *dst;
  1986 
  1987 #if DEBUG_CONVERT
  1988     fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_U8.\n");
  1989 #endif
  1990 
  1991     src = (const float *) cvt->buf;
  1992     dst = (Uint8 *) cvt->buf;
  1993     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
  1994         const Uint8 val = ((Uint8) ((SDL_SwapFloatBE(*src) + 1.0f) * 127.0f));
  1995         *dst = val;
  1996     }
  1997 
  1998     cvt->len_cvt /= 4;
  1999     if (cvt->filters[++cvt->filter_index]) {
  2000         cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
  2001     }
  2002 }
  2003 
  2004 static void SDLCALL
  2005 SDL_Convert_F32MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2006 {
  2007     int i;
  2008     const float *src;
  2009     Sint8 *dst;
  2010 
  2011 #if DEBUG_CONVERT
  2012     fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S8.\n");
  2013 #endif
  2014 
  2015     src = (const float *) cvt->buf;
  2016     dst = (Sint8 *) cvt->buf;
  2017     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
  2018         const Sint8 val = ((Sint8) (SDL_SwapFloatBE(*src) * 127.0f));
  2019         *dst = ((Sint8) val);
  2020     }
  2021 
  2022     cvt->len_cvt /= 4;
  2023     if (cvt->filters[++cvt->filter_index]) {
  2024         cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
  2025     }
  2026 }
  2027 
  2028 static void SDLCALL
  2029 SDL_Convert_F32MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2030 {
  2031     int i;
  2032     const float *src;
  2033     Uint16 *dst;
  2034 
  2035 #if DEBUG_CONVERT
  2036     fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_U16LSB.\n");
  2037 #endif
  2038 
  2039     src = (const float *) cvt->buf;
  2040     dst = (Uint16 *) cvt->buf;
  2041     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
  2042         const Uint16 val = ((Uint16) ((SDL_SwapFloatBE(*src) + 1.0f) * 32767.0f));
  2043         *dst = SDL_SwapLE16(val);
  2044     }
  2045 
  2046     cvt->len_cvt /= 2;
  2047     if (cvt->filters[++cvt->filter_index]) {
  2048         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
  2049     }
  2050 }
  2051 
  2052 static void SDLCALL
  2053 SDL_Convert_F32MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2054 {
  2055     int i;
  2056     const float *src;
  2057     Sint16 *dst;
  2058 
  2059 #if DEBUG_CONVERT
  2060     fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S16LSB.\n");
  2061 #endif
  2062 
  2063     src = (const float *) cvt->buf;
  2064     dst = (Sint16 *) cvt->buf;
  2065     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
  2066         const Sint16 val = ((Sint16) (SDL_SwapFloatBE(*src) * 32767.0f));
  2067         *dst = ((Sint16) SDL_SwapLE16(val));
  2068     }
  2069 
  2070     cvt->len_cvt /= 2;
  2071     if (cvt->filters[++cvt->filter_index]) {
  2072         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
  2073     }
  2074 }
  2075 
  2076 static void SDLCALL
  2077 SDL_Convert_F32MSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2078 {
  2079     int i;
  2080     const float *src;
  2081     Uint16 *dst;
  2082 
  2083 #if DEBUG_CONVERT
  2084     fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_U16MSB.\n");
  2085 #endif
  2086 
  2087     src = (const float *) cvt->buf;
  2088     dst = (Uint16 *) cvt->buf;
  2089     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
  2090         const Uint16 val = ((Uint16) ((SDL_SwapFloatBE(*src) + 1.0f) * 32767.0f));
  2091         *dst = SDL_SwapBE16(val);
  2092     }
  2093 
  2094     cvt->len_cvt /= 2;
  2095     if (cvt->filters[++cvt->filter_index]) {
  2096         cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
  2097     }
  2098 }
  2099 
  2100 static void SDLCALL
  2101 SDL_Convert_F32MSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2102 {
  2103     int i;
  2104     const float *src;
  2105     Sint16 *dst;
  2106 
  2107 #if DEBUG_CONVERT
  2108     fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S16MSB.\n");
  2109 #endif
  2110 
  2111     src = (const float *) cvt->buf;
  2112     dst = (Sint16 *) cvt->buf;
  2113     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
  2114         const Sint16 val = ((Sint16) (SDL_SwapFloatBE(*src) * 32767.0f));
  2115         *dst = ((Sint16) SDL_SwapBE16(val));
  2116     }
  2117 
  2118     cvt->len_cvt /= 2;
  2119     if (cvt->filters[++cvt->filter_index]) {
  2120         cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
  2121     }
  2122 }
  2123 
  2124 static void SDLCALL
  2125 SDL_Convert_F32MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2126 {
  2127     int i;
  2128     const float *src;
  2129     Sint32 *dst;
  2130 
  2131 #if DEBUG_CONVERT
  2132     fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S32LSB.\n");
  2133 #endif
  2134 
  2135     src = (const float *) cvt->buf;
  2136     dst = (Sint32 *) cvt->buf;
  2137     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
  2138         const Sint32 val = ((Sint32) (SDL_SwapFloatBE(*src) * 2147483647.0));
  2139         *dst = ((Sint32) SDL_SwapLE32(val));
  2140     }
  2141 
  2142     if (cvt->filters[++cvt->filter_index]) {
  2143         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
  2144     }
  2145 }
  2146 
  2147 static void SDLCALL
  2148 SDL_Convert_F32MSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2149 {
  2150     int i;
  2151     const float *src;
  2152     Sint32 *dst;
  2153 
  2154 #if DEBUG_CONVERT
  2155     fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S32MSB.\n");
  2156 #endif
  2157 
  2158     src = (const float *) cvt->buf;
  2159     dst = (Sint32 *) cvt->buf;
  2160     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
  2161         const Sint32 val = ((Sint32) (SDL_SwapFloatBE(*src) * 2147483647.0));
  2162         *dst = ((Sint32) SDL_SwapBE32(val));
  2163     }
  2164 
  2165     if (cvt->filters[++cvt->filter_index]) {
  2166         cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
  2167     }
  2168 }
  2169 
  2170 static void SDLCALL
  2171 SDL_Convert_F32MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2172 {
  2173     int i;
  2174     const float *src;
  2175     float *dst;
  2176 
  2177 #if DEBUG_CONVERT
  2178     fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_F32LSB.\n");
  2179 #endif
  2180 
  2181     src = (const float *) cvt->buf;
  2182     dst = (float *) cvt->buf;
  2183     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
  2184         const float val = SDL_SwapFloatBE(*src);
  2185         *dst = SDL_SwapFloatLE(val);
  2186     }
  2187 
  2188     if (cvt->filters[++cvt->filter_index]) {
  2189         cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
  2190     }
  2191 }
  2192 
  2193 #endif  /* !NO_CONVERTERS */
  2194 
  2195 
  2196 const SDL_AudioTypeFilters sdl_audio_type_filters[] =
  2197 {
  2198 #if !NO_CONVERTERS
  2199     { AUDIO_U8, AUDIO_S8, SDL_Convert_U8_to_S8 },
  2200     { AUDIO_U8, AUDIO_U16LSB, SDL_Convert_U8_to_U16LSB },
  2201     { AUDIO_U8, AUDIO_S16LSB, SDL_Convert_U8_to_S16LSB },
  2202     { AUDIO_U8, AUDIO_U16MSB, SDL_Convert_U8_to_U16MSB },
  2203     { AUDIO_U8, AUDIO_S16MSB, SDL_Convert_U8_to_S16MSB },
  2204     { AUDIO_U8, AUDIO_S32LSB, SDL_Convert_U8_to_S32LSB },
  2205     { AUDIO_U8, AUDIO_S32MSB, SDL_Convert_U8_to_S32MSB },
  2206     { AUDIO_U8, AUDIO_F32LSB, SDL_Convert_U8_to_F32LSB },
  2207     { AUDIO_U8, AUDIO_F32MSB, SDL_Convert_U8_to_F32MSB },
  2208     { AUDIO_S8, AUDIO_U8, SDL_Convert_S8_to_U8 },
  2209     { AUDIO_S8, AUDIO_U16LSB, SDL_Convert_S8_to_U16LSB },
  2210     { AUDIO_S8, AUDIO_S16LSB, SDL_Convert_S8_to_S16LSB },
  2211     { AUDIO_S8, AUDIO_U16MSB, SDL_Convert_S8_to_U16MSB },
  2212     { AUDIO_S8, AUDIO_S16MSB, SDL_Convert_S8_to_S16MSB },
  2213     { AUDIO_S8, AUDIO_S32LSB, SDL_Convert_S8_to_S32LSB },
  2214     { AUDIO_S8, AUDIO_S32MSB, SDL_Convert_S8_to_S32MSB },
  2215     { AUDIO_S8, AUDIO_F32LSB, SDL_Convert_S8_to_F32LSB },
  2216     { AUDIO_S8, AUDIO_F32MSB, SDL_Convert_S8_to_F32MSB },
  2217     { AUDIO_U16LSB, AUDIO_U8, SDL_Convert_U16LSB_to_U8 },
  2218     { AUDIO_U16LSB, AUDIO_S8, SDL_Convert_U16LSB_to_S8 },
  2219     { AUDIO_U16LSB, AUDIO_S16LSB, SDL_Convert_U16LSB_to_S16LSB },
  2220     { AUDIO_U16LSB, AUDIO_U16MSB, SDL_Convert_U16LSB_to_U16MSB },
  2221     { AUDIO_U16LSB, AUDIO_S16MSB, SDL_Convert_U16LSB_to_S16MSB },
  2222     { AUDIO_U16LSB, AUDIO_S32LSB, SDL_Convert_U16LSB_to_S32LSB },
  2223     { AUDIO_U16LSB, AUDIO_S32MSB, SDL_Convert_U16LSB_to_S32MSB },
  2224     { AUDIO_U16LSB, AUDIO_F32LSB, SDL_Convert_U16LSB_to_F32LSB },
  2225     { AUDIO_U16LSB, AUDIO_F32MSB, SDL_Convert_U16LSB_to_F32MSB },
  2226     { AUDIO_S16LSB, AUDIO_U8, SDL_Convert_S16LSB_to_U8 },
  2227     { AUDIO_S16LSB, AUDIO_S8, SDL_Convert_S16LSB_to_S8 },
  2228     { AUDIO_S16LSB, AUDIO_U16LSB, SDL_Convert_S16LSB_to_U16LSB },
  2229     { AUDIO_S16LSB, AUDIO_U16MSB, SDL_Convert_S16LSB_to_U16MSB },
  2230     { AUDIO_S16LSB, AUDIO_S16MSB, SDL_Convert_S16LSB_to_S16MSB },
  2231     { AUDIO_S16LSB, AUDIO_S32LSB, SDL_Convert_S16LSB_to_S32LSB },
  2232     { AUDIO_S16LSB, AUDIO_S32MSB, SDL_Convert_S16LSB_to_S32MSB },
  2233     { AUDIO_S16LSB, AUDIO_F32LSB, SDL_Convert_S16LSB_to_F32LSB },
  2234     { AUDIO_S16LSB, AUDIO_F32MSB, SDL_Convert_S16LSB_to_F32MSB },
  2235     { AUDIO_U16MSB, AUDIO_U8, SDL_Convert_U16MSB_to_U8 },
  2236     { AUDIO_U16MSB, AUDIO_S8, SDL_Convert_U16MSB_to_S8 },
  2237     { AUDIO_U16MSB, AUDIO_U16LSB, SDL_Convert_U16MSB_to_U16LSB },
  2238     { AUDIO_U16MSB, AUDIO_S16LSB, SDL_Convert_U16MSB_to_S16LSB },
  2239     { AUDIO_U16MSB, AUDIO_S16MSB, SDL_Convert_U16MSB_to_S16MSB },
  2240     { AUDIO_U16MSB, AUDIO_S32LSB, SDL_Convert_U16MSB_to_S32LSB },
  2241     { AUDIO_U16MSB, AUDIO_S32MSB, SDL_Convert_U16MSB_to_S32MSB },
  2242     { AUDIO_U16MSB, AUDIO_F32LSB, SDL_Convert_U16MSB_to_F32LSB },
  2243     { AUDIO_U16MSB, AUDIO_F32MSB, SDL_Convert_U16MSB_to_F32MSB },
  2244     { AUDIO_S16MSB, AUDIO_U8, SDL_Convert_S16MSB_to_U8 },
  2245     { AUDIO_S16MSB, AUDIO_S8, SDL_Convert_S16MSB_to_S8 },
  2246     { AUDIO_S16MSB, AUDIO_U16LSB, SDL_Convert_S16MSB_to_U16LSB },
  2247     { AUDIO_S16MSB, AUDIO_S16LSB, SDL_Convert_S16MSB_to_S16LSB },
  2248     { AUDIO_S16MSB, AUDIO_U16MSB, SDL_Convert_S16MSB_to_U16MSB },
  2249     { AUDIO_S16MSB, AUDIO_S32LSB, SDL_Convert_S16MSB_to_S32LSB },
  2250     { AUDIO_S16MSB, AUDIO_S32MSB, SDL_Convert_S16MSB_to_S32MSB },
  2251     { AUDIO_S16MSB, AUDIO_F32LSB, SDL_Convert_S16MSB_to_F32LSB },
  2252     { AUDIO_S16MSB, AUDIO_F32MSB, SDL_Convert_S16MSB_to_F32MSB },
  2253     { AUDIO_S32LSB, AUDIO_U8, SDL_Convert_S32LSB_to_U8 },
  2254     { AUDIO_S32LSB, AUDIO_S8, SDL_Convert_S32LSB_to_S8 },
  2255     { AUDIO_S32LSB, AUDIO_U16LSB, SDL_Convert_S32LSB_to_U16LSB },
  2256     { AUDIO_S32LSB, AUDIO_S16LSB, SDL_Convert_S32LSB_to_S16LSB },
  2257     { AUDIO_S32LSB, AUDIO_U16MSB, SDL_Convert_S32LSB_to_U16MSB },
  2258     { AUDIO_S32LSB, AUDIO_S16MSB, SDL_Convert_S32LSB_to_S16MSB },
  2259     { AUDIO_S32LSB, AUDIO_S32MSB, SDL_Convert_S32LSB_to_S32MSB },
  2260     { AUDIO_S32LSB, AUDIO_F32LSB, SDL_Convert_S32LSB_to_F32LSB },
  2261     { AUDIO_S32LSB, AUDIO_F32MSB, SDL_Convert_S32LSB_to_F32MSB },
  2262     { AUDIO_S32MSB, AUDIO_U8, SDL_Convert_S32MSB_to_U8 },
  2263     { AUDIO_S32MSB, AUDIO_S8, SDL_Convert_S32MSB_to_S8 },
  2264     { AUDIO_S32MSB, AUDIO_U16LSB, SDL_Convert_S32MSB_to_U16LSB },
  2265     { AUDIO_S32MSB, AUDIO_S16LSB, SDL_Convert_S32MSB_to_S16LSB },
  2266     { AUDIO_S32MSB, AUDIO_U16MSB, SDL_Convert_S32MSB_to_U16MSB },
  2267     { AUDIO_S32MSB, AUDIO_S16MSB, SDL_Convert_S32MSB_to_S16MSB },
  2268     { AUDIO_S32MSB, AUDIO_S32LSB, SDL_Convert_S32MSB_to_S32LSB },
  2269     { AUDIO_S32MSB, AUDIO_F32LSB, SDL_Convert_S32MSB_to_F32LSB },
  2270     { AUDIO_S32MSB, AUDIO_F32MSB, SDL_Convert_S32MSB_to_F32MSB },
  2271     { AUDIO_F32LSB, AUDIO_U8, SDL_Convert_F32LSB_to_U8 },
  2272     { AUDIO_F32LSB, AUDIO_S8, SDL_Convert_F32LSB_to_S8 },
  2273     { AUDIO_F32LSB, AUDIO_U16LSB, SDL_Convert_F32LSB_to_U16LSB },
  2274     { AUDIO_F32LSB, AUDIO_S16LSB, SDL_Convert_F32LSB_to_S16LSB },
  2275     { AUDIO_F32LSB, AUDIO_U16MSB, SDL_Convert_F32LSB_to_U16MSB },
  2276     { AUDIO_F32LSB, AUDIO_S16MSB, SDL_Convert_F32LSB_to_S16MSB },
  2277     { AUDIO_F32LSB, AUDIO_S32LSB, SDL_Convert_F32LSB_to_S32LSB },
  2278     { AUDIO_F32LSB, AUDIO_S32MSB, SDL_Convert_F32LSB_to_S32MSB },
  2279     { AUDIO_F32LSB, AUDIO_F32MSB, SDL_Convert_F32LSB_to_F32MSB },
  2280     { AUDIO_F32MSB, AUDIO_U8, SDL_Convert_F32MSB_to_U8 },
  2281     { AUDIO_F32MSB, AUDIO_S8, SDL_Convert_F32MSB_to_S8 },
  2282     { AUDIO_F32MSB, AUDIO_U16LSB, SDL_Convert_F32MSB_to_U16LSB },
  2283     { AUDIO_F32MSB, AUDIO_S16LSB, SDL_Convert_F32MSB_to_S16LSB },
  2284     { AUDIO_F32MSB, AUDIO_U16MSB, SDL_Convert_F32MSB_to_U16MSB },
  2285     { AUDIO_F32MSB, AUDIO_S16MSB, SDL_Convert_F32MSB_to_S16MSB },
  2286     { AUDIO_F32MSB, AUDIO_S32LSB, SDL_Convert_F32MSB_to_S32LSB },
  2287     { AUDIO_F32MSB, AUDIO_S32MSB, SDL_Convert_F32MSB_to_S32MSB },
  2288     { AUDIO_F32MSB, AUDIO_F32LSB, SDL_Convert_F32MSB_to_F32LSB },
  2289 #endif  /* !NO_CONVERTERS */
  2290     { 0, 0, NULL }
  2291 };
  2292 
  2293 
  2294 #if !NO_RESAMPLERS
  2295 
  2296 static void SDLCALL
  2297 SDL_Upsample_U8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2298 {
  2299 #if DEBUG_CONVERT
  2300     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U8, 1 channels.\n", cvt->rate_incr);
  2301 #endif
  2302 
  2303     const int srcsize = cvt->len_cvt - 16;
  2304     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  2305     register int eps = 0;
  2306     Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 1;
  2307     const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
  2308     const Uint8 *target = ((const Uint8 *) cvt->buf) - 1;
  2309     Uint8 sample0 = src[0];
  2310     Uint8 last_sample0 = sample0;
  2311     while (dst != target) {
  2312         dst[0] = sample0;
  2313         dst--;
  2314         eps += srcsize;
  2315         if ((eps << 1) >= dstsize) {
  2316             src--;
  2317             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
  2318             last_sample0 = sample0;
  2319             eps -= dstsize;
  2320         }
  2321     }
  2322     cvt->len_cvt = dstsize;
  2323     if (cvt->filters[++cvt->filter_index]) {
  2324         cvt->filters[cvt->filter_index] (cvt, format);
  2325     }
  2326 }
  2327 
  2328 static void SDLCALL
  2329 SDL_Downsample_U8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2330 {
  2331 #if DEBUG_CONVERT
  2332     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 1 channels.\n", cvt->rate_incr);
  2333 #endif
  2334 
  2335     const int srcsize = cvt->len_cvt - 16;
  2336     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  2337     register int eps = 0;
  2338     Uint8 *dst = (Uint8 *) cvt->buf;
  2339     const Uint8 *src = (Uint8 *) cvt->buf;
  2340     const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
  2341     Uint8 sample0 = src[0];
  2342     Uint8 last_sample0 = sample0;
  2343     while (dst != target) {
  2344         src++;
  2345         eps += dstsize;
  2346         if ((eps << 1) >= srcsize) {
  2347             dst[0] = sample0;
  2348             dst++;
  2349             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
  2350             last_sample0 = sample0;
  2351             eps -= srcsize;
  2352         }
  2353     }
  2354     cvt->len_cvt = dstsize;
  2355     if (cvt->filters[++cvt->filter_index]) {
  2356         cvt->filters[cvt->filter_index] (cvt, format);
  2357     }
  2358 }
  2359 
  2360 static void SDLCALL
  2361 SDL_Upsample_U8_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2362 {
  2363 #if DEBUG_CONVERT
  2364     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U8, 2 channels.\n", cvt->rate_incr);
  2365 #endif
  2366 
  2367     const int srcsize = cvt->len_cvt - 32;
  2368     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  2369     register int eps = 0;
  2370     Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 2;
  2371     const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 2;
  2372     const Uint8 *target = ((const Uint8 *) cvt->buf) - 2;
  2373     Uint8 sample1 = src[1];
  2374     Uint8 sample0 = src[0];
  2375     Uint8 last_sample1 = sample1;
  2376     Uint8 last_sample0 = sample0;
  2377     while (dst != target) {
  2378         dst[1] = sample1;
  2379         dst[0] = sample0;
  2380         dst -= 2;
  2381         eps += srcsize;
  2382         if ((eps << 1) >= dstsize) {
  2383             src -= 2;
  2384             sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
  2385             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
  2386             last_sample1 = sample1;
  2387             last_sample0 = sample0;
  2388             eps -= dstsize;
  2389         }
  2390     }
  2391     cvt->len_cvt = dstsize;
  2392     if (cvt->filters[++cvt->filter_index]) {
  2393         cvt->filters[cvt->filter_index] (cvt, format);
  2394     }
  2395 }
  2396 
  2397 static void SDLCALL
  2398 SDL_Downsample_U8_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2399 {
  2400 #if DEBUG_CONVERT
  2401     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 2 channels.\n", cvt->rate_incr);
  2402 #endif
  2403 
  2404     const int srcsize = cvt->len_cvt - 32;
  2405     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  2406     register int eps = 0;
  2407     Uint8 *dst = (Uint8 *) cvt->buf;
  2408     const Uint8 *src = (Uint8 *) cvt->buf;
  2409     const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
  2410     Uint8 sample0 = src[0];
  2411     Uint8 sample1 = src[1];
  2412     Uint8 last_sample0 = sample0;
  2413     Uint8 last_sample1 = sample1;
  2414     while (dst != target) {
  2415         src += 2;
  2416         eps += dstsize;
  2417         if ((eps << 1) >= srcsize) {
  2418             dst[0] = sample0;
  2419             dst[1] = sample1;
  2420             dst += 2;
  2421             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
  2422             sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
  2423             last_sample0 = sample0;
  2424             last_sample1 = sample1;
  2425             eps -= srcsize;
  2426         }
  2427     }
  2428     cvt->len_cvt = dstsize;
  2429     if (cvt->filters[++cvt->filter_index]) {
  2430         cvt->filters[cvt->filter_index] (cvt, format);
  2431     }
  2432 }
  2433 
  2434 static void SDLCALL
  2435 SDL_Upsample_U8_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2436 {
  2437 #if DEBUG_CONVERT
  2438     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U8, 4 channels.\n", cvt->rate_incr);
  2439 #endif
  2440 
  2441     const int srcsize = cvt->len_cvt - 64;
  2442     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  2443     register int eps = 0;
  2444     Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 4;
  2445     const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 4;
  2446     const Uint8 *target = ((const Uint8 *) cvt->buf) - 4;
  2447     Uint8 sample3 = src[3];
  2448     Uint8 sample2 = src[2];
  2449     Uint8 sample1 = src[1];
  2450     Uint8 sample0 = src[0];
  2451     Uint8 last_sample3 = sample3;
  2452     Uint8 last_sample2 = sample2;
  2453     Uint8 last_sample1 = sample1;
  2454     Uint8 last_sample0 = sample0;
  2455     while (dst != target) {
  2456         dst[3] = sample3;
  2457         dst[2] = sample2;
  2458         dst[1] = sample1;
  2459         dst[0] = sample0;
  2460         dst -= 4;
  2461         eps += srcsize;
  2462         if ((eps << 1) >= dstsize) {
  2463             src -= 4;
  2464             sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
  2465             sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
  2466             sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
  2467             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
  2468             last_sample3 = sample3;
  2469             last_sample2 = sample2;
  2470             last_sample1 = sample1;
  2471             last_sample0 = sample0;
  2472             eps -= dstsize;
  2473         }
  2474     }
  2475     cvt->len_cvt = dstsize;
  2476     if (cvt->filters[++cvt->filter_index]) {
  2477         cvt->filters[cvt->filter_index] (cvt, format);
  2478     }
  2479 }
  2480 
  2481 static void SDLCALL
  2482 SDL_Downsample_U8_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2483 {
  2484 #if DEBUG_CONVERT
  2485     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 4 channels.\n", cvt->rate_incr);
  2486 #endif
  2487 
  2488     const int srcsize = cvt->len_cvt - 64;
  2489     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  2490     register int eps = 0;
  2491     Uint8 *dst = (Uint8 *) cvt->buf;
  2492     const Uint8 *src = (Uint8 *) cvt->buf;
  2493     const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
  2494     Uint8 sample0 = src[0];
  2495     Uint8 sample1 = src[1];
  2496     Uint8 sample2 = src[2];
  2497     Uint8 sample3 = src[3];
  2498     Uint8 last_sample0 = sample0;
  2499     Uint8 last_sample1 = sample1;
  2500     Uint8 last_sample2 = sample2;
  2501     Uint8 last_sample3 = sample3;
  2502     while (dst != target) {
  2503         src += 4;
  2504         eps += dstsize;
  2505         if ((eps << 1) >= srcsize) {
  2506             dst[0] = sample0;
  2507             dst[1] = sample1;
  2508             dst[2] = sample2;
  2509             dst[3] = sample3;
  2510             dst += 4;
  2511             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
  2512             sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
  2513             sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
  2514             sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
  2515             last_sample0 = sample0;
  2516             last_sample1 = sample1;
  2517             last_sample2 = sample2;
  2518             last_sample3 = sample3;
  2519             eps -= srcsize;
  2520         }
  2521     }
  2522     cvt->len_cvt = dstsize;
  2523     if (cvt->filters[++cvt->filter_index]) {
  2524         cvt->filters[cvt->filter_index] (cvt, format);
  2525     }
  2526 }
  2527 
  2528 static void SDLCALL
  2529 SDL_Upsample_U8_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2530 {
  2531 #if DEBUG_CONVERT
  2532     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U8, 6 channels.\n", cvt->rate_incr);
  2533 #endif
  2534 
  2535     const int srcsize = cvt->len_cvt - 96;
  2536     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  2537     register int eps = 0;
  2538     Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 6;
  2539     const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 6;
  2540     const Uint8 *target = ((const Uint8 *) cvt->buf) - 6;
  2541     Uint8 sample5 = src[5];
  2542     Uint8 sample4 = src[4];
  2543     Uint8 sample3 = src[3];
  2544     Uint8 sample2 = src[2];
  2545     Uint8 sample1 = src[1];
  2546     Uint8 sample0 = src[0];
  2547     Uint8 last_sample5 = sample5;
  2548     Uint8 last_sample4 = sample4;
  2549     Uint8 last_sample3 = sample3;
  2550     Uint8 last_sample2 = sample2;
  2551     Uint8 last_sample1 = sample1;
  2552     Uint8 last_sample0 = sample0;
  2553     while (dst != target) {
  2554         dst[5] = sample5;
  2555         dst[4] = sample4;
  2556         dst[3] = sample3;
  2557         dst[2] = sample2;
  2558         dst[1] = sample1;
  2559         dst[0] = sample0;
  2560         dst -= 6;
  2561         eps += srcsize;
  2562         if ((eps << 1) >= dstsize) {
  2563             src -= 6;
  2564             sample5 = (Uint8) ((((Sint16) src[5]) + ((Sint16) last_sample5)) >> 1);
  2565             sample4 = (Uint8) ((((Sint16) src[4]) + ((Sint16) last_sample4)) >> 1);
  2566             sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
  2567             sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
  2568             sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
  2569             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
  2570             last_sample5 = sample5;
  2571             last_sample4 = sample4;
  2572             last_sample3 = sample3;
  2573             last_sample2 = sample2;
  2574             last_sample1 = sample1;
  2575             last_sample0 = sample0;
  2576             eps -= dstsize;
  2577         }
  2578     }
  2579     cvt->len_cvt = dstsize;
  2580     if (cvt->filters[++cvt->filter_index]) {
  2581         cvt->filters[cvt->filter_index] (cvt, format);
  2582     }
  2583 }
  2584 
  2585 static void SDLCALL
  2586 SDL_Downsample_U8_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2587 {
  2588 #if DEBUG_CONVERT
  2589     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 6 channels.\n", cvt->rate_incr);
  2590 #endif
  2591 
  2592     const int srcsize = cvt->len_cvt - 96;
  2593     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  2594     register int eps = 0;
  2595     Uint8 *dst = (Uint8 *) cvt->buf;
  2596     const Uint8 *src = (Uint8 *) cvt->buf;
  2597     const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
  2598     Uint8 sample0 = src[0];
  2599     Uint8 sample1 = src[1];
  2600     Uint8 sample2 = src[2];
  2601     Uint8 sample3 = src[3];
  2602     Uint8 sample4 = src[4];
  2603     Uint8 sample5 = src[5];
  2604     Uint8 last_sample0 = sample0;
  2605     Uint8 last_sample1 = sample1;
  2606     Uint8 last_sample2 = sample2;
  2607     Uint8 last_sample3 = sample3;
  2608     Uint8 last_sample4 = sample4;
  2609     Uint8 last_sample5 = sample5;
  2610     while (dst != target) {
  2611         src += 6;
  2612         eps += dstsize;
  2613         if ((eps << 1) >= srcsize) {
  2614             dst[0] = sample0;
  2615             dst[1] = sample1;
  2616             dst[2] = sample2;
  2617             dst[3] = sample3;
  2618             dst[4] = sample4;
  2619             dst[5] = sample5;
  2620             dst += 6;
  2621             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
  2622             sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
  2623             sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
  2624             sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
  2625             sample4 = (Uint8) ((((Sint16) src[4]) + ((Sint16) last_sample4)) >> 1);
  2626             sample5 = (Uint8) ((((Sint16) src[5]) + ((Sint16) last_sample5)) >> 1);
  2627             last_sample0 = sample0;
  2628             last_sample1 = sample1;
  2629             last_sample2 = sample2;
  2630             last_sample3 = sample3;
  2631             last_sample4 = sample4;
  2632             last_sample5 = sample5;
  2633             eps -= srcsize;
  2634         }
  2635     }
  2636     cvt->len_cvt = dstsize;
  2637     if (cvt->filters[++cvt->filter_index]) {
  2638         cvt->filters[cvt->filter_index] (cvt, format);
  2639     }
  2640 }
  2641 
  2642 static void SDLCALL
  2643 SDL_Upsample_U8_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2644 {
  2645 #if DEBUG_CONVERT
  2646     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U8, 8 channels.\n", cvt->rate_incr);
  2647 #endif
  2648 
  2649     const int srcsize = cvt->len_cvt - 128;
  2650     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  2651     register int eps = 0;
  2652     Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 8;
  2653     const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 8;
  2654     const Uint8 *target = ((const Uint8 *) cvt->buf) - 8;
  2655     Uint8 sample7 = src[7];
  2656     Uint8 sample6 = src[6];
  2657     Uint8 sample5 = src[5];
  2658     Uint8 sample4 = src[4];
  2659     Uint8 sample3 = src[3];
  2660     Uint8 sample2 = src[2];
  2661     Uint8 sample1 = src[1];
  2662     Uint8 sample0 = src[0];
  2663     Uint8 last_sample7 = sample7;
  2664     Uint8 last_sample6 = sample6;
  2665     Uint8 last_sample5 = sample5;
  2666     Uint8 last_sample4 = sample4;
  2667     Uint8 last_sample3 = sample3;
  2668     Uint8 last_sample2 = sample2;
  2669     Uint8 last_sample1 = sample1;
  2670     Uint8 last_sample0 = sample0;
  2671     while (dst != target) {
  2672         dst[7] = sample7;
  2673         dst[6] = sample6;
  2674         dst[5] = sample5;
  2675         dst[4] = sample4;
  2676         dst[3] = sample3;
  2677         dst[2] = sample2;
  2678         dst[1] = sample1;
  2679         dst[0] = sample0;
  2680         dst -= 8;
  2681         eps += srcsize;
  2682         if ((eps << 1) >= dstsize) {
  2683             src -= 8;
  2684             sample7 = (Uint8) ((((Sint16) src[7]) + ((Sint16) last_sample7)) >> 1);
  2685             sample6 = (Uint8) ((((Sint16) src[6]) + ((Sint16) last_sample6)) >> 1);
  2686             sample5 = (Uint8) ((((Sint16) src[5]) + ((Sint16) last_sample5)) >> 1);
  2687             sample4 = (Uint8) ((((Sint16) src[4]) + ((Sint16) last_sample4)) >> 1);
  2688             sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
  2689             sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
  2690             sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
  2691             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
  2692             last_sample7 = sample7;
  2693             last_sample6 = sample6;
  2694             last_sample5 = sample5;
  2695             last_sample4 = sample4;
  2696             last_sample3 = sample3;
  2697             last_sample2 = sample2;
  2698             last_sample1 = sample1;
  2699             last_sample0 = sample0;
  2700             eps -= dstsize;
  2701         }
  2702     }
  2703     cvt->len_cvt = dstsize;
  2704     if (cvt->filters[++cvt->filter_index]) {
  2705         cvt->filters[cvt->filter_index] (cvt, format);
  2706     }
  2707 }
  2708 
  2709 static void SDLCALL
  2710 SDL_Downsample_U8_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2711 {
  2712 #if DEBUG_CONVERT
  2713     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 8 channels.\n", cvt->rate_incr);
  2714 #endif
  2715 
  2716     const int srcsize = cvt->len_cvt - 128;
  2717     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  2718     register int eps = 0;
  2719     Uint8 *dst = (Uint8 *) cvt->buf;
  2720     const Uint8 *src = (Uint8 *) cvt->buf;
  2721     const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
  2722     Uint8 sample0 = src[0];
  2723     Uint8 sample1 = src[1];
  2724     Uint8 sample2 = src[2];
  2725     Uint8 sample3 = src[3];
  2726     Uint8 sample4 = src[4];
  2727     Uint8 sample5 = src[5];
  2728     Uint8 sample6 = src[6];
  2729     Uint8 sample7 = src[7];
  2730     Uint8 last_sample0 = sample0;
  2731     Uint8 last_sample1 = sample1;
  2732     Uint8 last_sample2 = sample2;
  2733     Uint8 last_sample3 = sample3;
  2734     Uint8 last_sample4 = sample4;
  2735     Uint8 last_sample5 = sample5;
  2736     Uint8 last_sample6 = sample6;
  2737     Uint8 last_sample7 = sample7;
  2738     while (dst != target) {
  2739         src += 8;
  2740         eps += dstsize;
  2741         if ((eps << 1) >= srcsize) {
  2742             dst[0] = sample0;
  2743             dst[1] = sample1;
  2744             dst[2] = sample2;
  2745             dst[3] = sample3;
  2746             dst[4] = sample4;
  2747             dst[5] = sample5;
  2748             dst[6] = sample6;
  2749             dst[7] = sample7;
  2750             dst += 8;
  2751             sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
  2752             sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
  2753             sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
  2754             sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
  2755             sample4 = (Uint8) ((((Sint16) src[4]) + ((Sint16) last_sample4)) >> 1);
  2756             sample5 = (Uint8) ((((Sint16) src[5]) + ((Sint16) last_sample5)) >> 1);
  2757             sample6 = (Uint8) ((((Sint16) src[6]) + ((Sint16) last_sample6)) >> 1);
  2758             sample7 = (Uint8) ((((Sint16) src[7]) + ((Sint16) last_sample7)) >> 1);
  2759             last_sample0 = sample0;
  2760             last_sample1 = sample1;
  2761             last_sample2 = sample2;
  2762             last_sample3 = sample3;
  2763             last_sample4 = sample4;
  2764             last_sample5 = sample5;
  2765             last_sample6 = sample6;
  2766             last_sample7 = sample7;
  2767             eps -= srcsize;
  2768         }
  2769     }
  2770     cvt->len_cvt = dstsize;
  2771     if (cvt->filters[++cvt->filter_index]) {
  2772         cvt->filters[cvt->filter_index] (cvt, format);
  2773     }
  2774 }
  2775 
  2776 static void SDLCALL
  2777 SDL_Upsample_S8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2778 {
  2779 #if DEBUG_CONVERT
  2780     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S8, 1 channels.\n", cvt->rate_incr);
  2781 #endif
  2782 
  2783     const int srcsize = cvt->len_cvt - 16;
  2784     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  2785     register int eps = 0;
  2786     Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 1;
  2787     const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 1;
  2788     const Sint8 *target = ((const Sint8 *) cvt->buf) - 1;
  2789     Sint8 sample0 = ((Sint8) src[0]);
  2790     Sint8 last_sample0 = sample0;
  2791     while (dst != target) {
  2792         dst[0] = ((Sint8) sample0);
  2793         dst--;
  2794         eps += srcsize;
  2795         if ((eps << 1) >= dstsize) {
  2796             src--;
  2797             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
  2798             last_sample0 = sample0;
  2799             eps -= dstsize;
  2800         }
  2801     }
  2802     cvt->len_cvt = dstsize;
  2803     if (cvt->filters[++cvt->filter_index]) {
  2804         cvt->filters[cvt->filter_index] (cvt, format);
  2805     }
  2806 }
  2807 
  2808 static void SDLCALL
  2809 SDL_Downsample_S8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2810 {
  2811 #if DEBUG_CONVERT
  2812     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S8, 1 channels.\n", cvt->rate_incr);
  2813 #endif
  2814 
  2815     const int srcsize = cvt->len_cvt - 16;
  2816     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  2817     register int eps = 0;
  2818     Sint8 *dst = (Sint8 *) cvt->buf;
  2819     const Sint8 *src = (Sint8 *) cvt->buf;
  2820     const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
  2821     Sint8 sample0 = ((Sint8) src[0]);
  2822     Sint8 last_sample0 = sample0;
  2823     while (dst != target) {
  2824         src++;
  2825         eps += dstsize;
  2826         if ((eps << 1) >= srcsize) {
  2827             dst[0] = ((Sint8) sample0);
  2828             dst++;
  2829             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
  2830             last_sample0 = sample0;
  2831             eps -= srcsize;
  2832         }
  2833     }
  2834     cvt->len_cvt = dstsize;
  2835     if (cvt->filters[++cvt->filter_index]) {
  2836         cvt->filters[cvt->filter_index] (cvt, format);
  2837     }
  2838 }
  2839 
  2840 static void SDLCALL
  2841 SDL_Upsample_S8_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2842 {
  2843 #if DEBUG_CONVERT
  2844     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S8, 2 channels.\n", cvt->rate_incr);
  2845 #endif
  2846 
  2847     const int srcsize = cvt->len_cvt - 32;
  2848     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  2849     register int eps = 0;
  2850     Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 2;
  2851     const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 2;
  2852     const Sint8 *target = ((const Sint8 *) cvt->buf) - 2;
  2853     Sint8 sample1 = ((Sint8) src[1]);
  2854     Sint8 sample0 = ((Sint8) src[0]);
  2855     Sint8 last_sample1 = sample1;
  2856     Sint8 last_sample0 = sample0;
  2857     while (dst != target) {
  2858         dst[1] = ((Sint8) sample1);
  2859         dst[0] = ((Sint8) sample0);
  2860         dst -= 2;
  2861         eps += srcsize;
  2862         if ((eps << 1) >= dstsize) {
  2863             src -= 2;
  2864             sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
  2865             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
  2866             last_sample1 = sample1;
  2867             last_sample0 = sample0;
  2868             eps -= dstsize;
  2869         }
  2870     }
  2871     cvt->len_cvt = dstsize;
  2872     if (cvt->filters[++cvt->filter_index]) {
  2873         cvt->filters[cvt->filter_index] (cvt, format);
  2874     }
  2875 }
  2876 
  2877 static void SDLCALL
  2878 SDL_Downsample_S8_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2879 {
  2880 #if DEBUG_CONVERT
  2881     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S8, 2 channels.\n", cvt->rate_incr);
  2882 #endif
  2883 
  2884     const int srcsize = cvt->len_cvt - 32;
  2885     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  2886     register int eps = 0;
  2887     Sint8 *dst = (Sint8 *) cvt->buf;
  2888     const Sint8 *src = (Sint8 *) cvt->buf;
  2889     const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
  2890     Sint8 sample0 = ((Sint8) src[0]);
  2891     Sint8 sample1 = ((Sint8) src[1]);
  2892     Sint8 last_sample0 = sample0;
  2893     Sint8 last_sample1 = sample1;
  2894     while (dst != target) {
  2895         src += 2;
  2896         eps += dstsize;
  2897         if ((eps << 1) >= srcsize) {
  2898             dst[0] = ((Sint8) sample0);
  2899             dst[1] = ((Sint8) sample1);
  2900             dst += 2;
  2901             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
  2902             sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
  2903             last_sample0 = sample0;
  2904             last_sample1 = sample1;
  2905             eps -= srcsize;
  2906         }
  2907     }
  2908     cvt->len_cvt = dstsize;
  2909     if (cvt->filters[++cvt->filter_index]) {
  2910         cvt->filters[cvt->filter_index] (cvt, format);
  2911     }
  2912 }
  2913 
  2914 static void SDLCALL
  2915 SDL_Upsample_S8_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2916 {
  2917 #if DEBUG_CONVERT
  2918     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S8, 4 channels.\n", cvt->rate_incr);
  2919 #endif
  2920 
  2921     const int srcsize = cvt->len_cvt - 64;
  2922     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  2923     register int eps = 0;
  2924     Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 4;
  2925     const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 4;
  2926     const Sint8 *target = ((const Sint8 *) cvt->buf) - 4;
  2927     Sint8 sample3 = ((Sint8) src[3]);
  2928     Sint8 sample2 = ((Sint8) src[2]);
  2929     Sint8 sample1 = ((Sint8) src[1]);
  2930     Sint8 sample0 = ((Sint8) src[0]);
  2931     Sint8 last_sample3 = sample3;
  2932     Sint8 last_sample2 = sample2;
  2933     Sint8 last_sample1 = sample1;
  2934     Sint8 last_sample0 = sample0;
  2935     while (dst != target) {
  2936         dst[3] = ((Sint8) sample3);
  2937         dst[2] = ((Sint8) sample2);
  2938         dst[1] = ((Sint8) sample1);
  2939         dst[0] = ((Sint8) sample0);
  2940         dst -= 4;
  2941         eps += srcsize;
  2942         if ((eps << 1) >= dstsize) {
  2943             src -= 4;
  2944             sample3 = (Sint8) ((((Sint16) ((Sint8) src[3])) + ((Sint16) last_sample3)) >> 1);
  2945             sample2 = (Sint8) ((((Sint16) ((Sint8) src[2])) + ((Sint16) last_sample2)) >> 1);
  2946             sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
  2947             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
  2948             last_sample3 = sample3;
  2949             last_sample2 = sample2;
  2950             last_sample1 = sample1;
  2951             last_sample0 = sample0;
  2952             eps -= dstsize;
  2953         }
  2954     }
  2955     cvt->len_cvt = dstsize;
  2956     if (cvt->filters[++cvt->filter_index]) {
  2957         cvt->filters[cvt->filter_index] (cvt, format);
  2958     }
  2959 }
  2960 
  2961 static void SDLCALL
  2962 SDL_Downsample_S8_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  2963 {
  2964 #if DEBUG_CONVERT
  2965     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S8, 4 channels.\n", cvt->rate_incr);
  2966 #endif
  2967 
  2968     const int srcsize = cvt->len_cvt - 64;
  2969     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  2970     register int eps = 0;
  2971     Sint8 *dst = (Sint8 *) cvt->buf;
  2972     const Sint8 *src = (Sint8 *) cvt->buf;
  2973     const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
  2974     Sint8 sample0 = ((Sint8) src[0]);
  2975     Sint8 sample1 = ((Sint8) src[1]);
  2976     Sint8 sample2 = ((Sint8) src[2]);
  2977     Sint8 sample3 = ((Sint8) src[3]);
  2978     Sint8 last_sample0 = sample0;
  2979     Sint8 last_sample1 = sample1;
  2980     Sint8 last_sample2 = sample2;
  2981     Sint8 last_sample3 = sample3;
  2982     while (dst != target) {
  2983         src += 4;
  2984         eps += dstsize;
  2985         if ((eps << 1) >= srcsize) {
  2986             dst[0] = ((Sint8) sample0);
  2987             dst[1] = ((Sint8) sample1);
  2988             dst[2] = ((Sint8) sample2);
  2989             dst[3] = ((Sint8) sample3);
  2990             dst += 4;
  2991             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
  2992             sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
  2993             sample2 = (Sint8) ((((Sint16) ((Sint8) src[2])) + ((Sint16) last_sample2)) >> 1);
  2994             sample3 = (Sint8) ((((Sint16) ((Sint8) src[3])) + ((Sint16) last_sample3)) >> 1);
  2995             last_sample0 = sample0;
  2996             last_sample1 = sample1;
  2997             last_sample2 = sample2;
  2998             last_sample3 = sample3;
  2999             eps -= srcsize;
  3000         }
  3001     }
  3002     cvt->len_cvt = dstsize;
  3003     if (cvt->filters[++cvt->filter_index]) {
  3004         cvt->filters[cvt->filter_index] (cvt, format);
  3005     }
  3006 }
  3007 
  3008 static void SDLCALL
  3009 SDL_Upsample_S8_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3010 {
  3011 #if DEBUG_CONVERT
  3012     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S8, 6 channels.\n", cvt->rate_incr);
  3013 #endif
  3014 
  3015     const int srcsize = cvt->len_cvt - 96;
  3016     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3017     register int eps = 0;
  3018     Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 6;
  3019     const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 6;
  3020     const Sint8 *target = ((const Sint8 *) cvt->buf) - 6;
  3021     Sint8 sample5 = ((Sint8) src[5]);
  3022     Sint8 sample4 = ((Sint8) src[4]);
  3023     Sint8 sample3 = ((Sint8) src[3]);
  3024     Sint8 sample2 = ((Sint8) src[2]);
  3025     Sint8 sample1 = ((Sint8) src[1]);
  3026     Sint8 sample0 = ((Sint8) src[0]);
  3027     Sint8 last_sample5 = sample5;
  3028     Sint8 last_sample4 = sample4;
  3029     Sint8 last_sample3 = sample3;
  3030     Sint8 last_sample2 = sample2;
  3031     Sint8 last_sample1 = sample1;
  3032     Sint8 last_sample0 = sample0;
  3033     while (dst != target) {
  3034         dst[5] = ((Sint8) sample5);
  3035         dst[4] = ((Sint8) sample4);
  3036         dst[3] = ((Sint8) sample3);
  3037         dst[2] = ((Sint8) sample2);
  3038         dst[1] = ((Sint8) sample1);
  3039         dst[0] = ((Sint8) sample0);
  3040         dst -= 6;
  3041         eps += srcsize;
  3042         if ((eps << 1) >= dstsize) {
  3043             src -= 6;
  3044             sample5 = (Sint8) ((((Sint16) ((Sint8) src[5])) + ((Sint16) last_sample5)) >> 1);
  3045             sample4 = (Sint8) ((((Sint16) ((Sint8) src[4])) + ((Sint16) last_sample4)) >> 1);
  3046             sample3 = (Sint8) ((((Sint16) ((Sint8) src[3])) + ((Sint16) last_sample3)) >> 1);
  3047             sample2 = (Sint8) ((((Sint16) ((Sint8) src[2])) + ((Sint16) last_sample2)) >> 1);
  3048             sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
  3049             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
  3050             last_sample5 = sample5;
  3051             last_sample4 = sample4;
  3052             last_sample3 = sample3;
  3053             last_sample2 = sample2;
  3054             last_sample1 = sample1;
  3055             last_sample0 = sample0;
  3056             eps -= dstsize;
  3057         }
  3058     }
  3059     cvt->len_cvt = dstsize;
  3060     if (cvt->filters[++cvt->filter_index]) {
  3061         cvt->filters[cvt->filter_index] (cvt, format);
  3062     }
  3063 }
  3064 
  3065 static void SDLCALL
  3066 SDL_Downsample_S8_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3067 {
  3068 #if DEBUG_CONVERT
  3069     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S8, 6 channels.\n", cvt->rate_incr);
  3070 #endif
  3071 
  3072     const int srcsize = cvt->len_cvt - 96;
  3073     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3074     register int eps = 0;
  3075     Sint8 *dst = (Sint8 *) cvt->buf;
  3076     const Sint8 *src = (Sint8 *) cvt->buf;
  3077     const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
  3078     Sint8 sample0 = ((Sint8) src[0]);
  3079     Sint8 sample1 = ((Sint8) src[1]);
  3080     Sint8 sample2 = ((Sint8) src[2]);
  3081     Sint8 sample3 = ((Sint8) src[3]);
  3082     Sint8 sample4 = ((Sint8) src[4]);
  3083     Sint8 sample5 = ((Sint8) src[5]);
  3084     Sint8 last_sample0 = sample0;
  3085     Sint8 last_sample1 = sample1;
  3086     Sint8 last_sample2 = sample2;
  3087     Sint8 last_sample3 = sample3;
  3088     Sint8 last_sample4 = sample4;
  3089     Sint8 last_sample5 = sample5;
  3090     while (dst != target) {
  3091         src += 6;
  3092         eps += dstsize;
  3093         if ((eps << 1) >= srcsize) {
  3094             dst[0] = ((Sint8) sample0);
  3095             dst[1] = ((Sint8) sample1);
  3096             dst[2] = ((Sint8) sample2);
  3097             dst[3] = ((Sint8) sample3);
  3098             dst[4] = ((Sint8) sample4);
  3099             dst[5] = ((Sint8) sample5);
  3100             dst += 6;
  3101             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
  3102             sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
  3103             sample2 = (Sint8) ((((Sint16) ((Sint8) src[2])) + ((Sint16) last_sample2)) >> 1);
  3104             sample3 = (Sint8) ((((Sint16) ((Sint8) src[3])) + ((Sint16) last_sample3)) >> 1);
  3105             sample4 = (Sint8) ((((Sint16) ((Sint8) src[4])) + ((Sint16) last_sample4)) >> 1);
  3106             sample5 = (Sint8) ((((Sint16) ((Sint8) src[5])) + ((Sint16) last_sample5)) >> 1);
  3107             last_sample0 = sample0;
  3108             last_sample1 = sample1;
  3109             last_sample2 = sample2;
  3110             last_sample3 = sample3;
  3111             last_sample4 = sample4;
  3112             last_sample5 = sample5;
  3113             eps -= srcsize;
  3114         }
  3115     }
  3116     cvt->len_cvt = dstsize;
  3117     if (cvt->filters[++cvt->filter_index]) {
  3118         cvt->filters[cvt->filter_index] (cvt, format);
  3119     }
  3120 }
  3121 
  3122 static void SDLCALL
  3123 SDL_Upsample_S8_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3124 {
  3125 #if DEBUG_CONVERT
  3126     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S8, 8 channels.\n", cvt->rate_incr);
  3127 #endif
  3128 
  3129     const int srcsize = cvt->len_cvt - 128;
  3130     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3131     register int eps = 0;
  3132     Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 8;
  3133     const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 8;
  3134     const Sint8 *target = ((const Sint8 *) cvt->buf) - 8;
  3135     Sint8 sample7 = ((Sint8) src[7]);
  3136     Sint8 sample6 = ((Sint8) src[6]);
  3137     Sint8 sample5 = ((Sint8) src[5]);
  3138     Sint8 sample4 = ((Sint8) src[4]);
  3139     Sint8 sample3 = ((Sint8) src[3]);
  3140     Sint8 sample2 = ((Sint8) src[2]);
  3141     Sint8 sample1 = ((Sint8) src[1]);
  3142     Sint8 sample0 = ((Sint8) src[0]);
  3143     Sint8 last_sample7 = sample7;
  3144     Sint8 last_sample6 = sample6;
  3145     Sint8 last_sample5 = sample5;
  3146     Sint8 last_sample4 = sample4;
  3147     Sint8 last_sample3 = sample3;
  3148     Sint8 last_sample2 = sample2;
  3149     Sint8 last_sample1 = sample1;
  3150     Sint8 last_sample0 = sample0;
  3151     while (dst != target) {
  3152         dst[7] = ((Sint8) sample7);
  3153         dst[6] = ((Sint8) sample6);
  3154         dst[5] = ((Sint8) sample5);
  3155         dst[4] = ((Sint8) sample4);
  3156         dst[3] = ((Sint8) sample3);
  3157         dst[2] = ((Sint8) sample2);
  3158         dst[1] = ((Sint8) sample1);
  3159         dst[0] = ((Sint8) sample0);
  3160         dst -= 8;
  3161         eps += srcsize;
  3162         if ((eps << 1) >= dstsize) {
  3163             src -= 8;
  3164             sample7 = (Sint8) ((((Sint16) ((Sint8) src[7])) + ((Sint16) last_sample7)) >> 1);
  3165             sample6 = (Sint8) ((((Sint16) ((Sint8) src[6])) + ((Sint16) last_sample6)) >> 1);
  3166             sample5 = (Sint8) ((((Sint16) ((Sint8) src[5])) + ((Sint16) last_sample5)) >> 1);
  3167             sample4 = (Sint8) ((((Sint16) ((Sint8) src[4])) + ((Sint16) last_sample4)) >> 1);
  3168             sample3 = (Sint8) ((((Sint16) ((Sint8) src[3])) + ((Sint16) last_sample3)) >> 1);
  3169             sample2 = (Sint8) ((((Sint16) ((Sint8) src[2])) + ((Sint16) last_sample2)) >> 1);
  3170             sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
  3171             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
  3172             last_sample7 = sample7;
  3173             last_sample6 = sample6;
  3174             last_sample5 = sample5;
  3175             last_sample4 = sample4;
  3176             last_sample3 = sample3;
  3177             last_sample2 = sample2;
  3178             last_sample1 = sample1;
  3179             last_sample0 = sample0;
  3180             eps -= dstsize;
  3181         }
  3182     }
  3183     cvt->len_cvt = dstsize;
  3184     if (cvt->filters[++cvt->filter_index]) {
  3185         cvt->filters[cvt->filter_index] (cvt, format);
  3186     }
  3187 }
  3188 
  3189 static void SDLCALL
  3190 SDL_Downsample_S8_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3191 {
  3192 #if DEBUG_CONVERT
  3193     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S8, 8 channels.\n", cvt->rate_incr);
  3194 #endif
  3195 
  3196     const int srcsize = cvt->len_cvt - 128;
  3197     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3198     register int eps = 0;
  3199     Sint8 *dst = (Sint8 *) cvt->buf;
  3200     const Sint8 *src = (Sint8 *) cvt->buf;
  3201     const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
  3202     Sint8 sample0 = ((Sint8) src[0]);
  3203     Sint8 sample1 = ((Sint8) src[1]);
  3204     Sint8 sample2 = ((Sint8) src[2]);
  3205     Sint8 sample3 = ((Sint8) src[3]);
  3206     Sint8 sample4 = ((Sint8) src[4]);
  3207     Sint8 sample5 = ((Sint8) src[5]);
  3208     Sint8 sample6 = ((Sint8) src[6]);
  3209     Sint8 sample7 = ((Sint8) src[7]);
  3210     Sint8 last_sample0 = sample0;
  3211     Sint8 last_sample1 = sample1;
  3212     Sint8 last_sample2 = sample2;
  3213     Sint8 last_sample3 = sample3;
  3214     Sint8 last_sample4 = sample4;
  3215     Sint8 last_sample5 = sample5;
  3216     Sint8 last_sample6 = sample6;
  3217     Sint8 last_sample7 = sample7;
  3218     while (dst != target) {
  3219         src += 8;
  3220         eps += dstsize;
  3221         if ((eps << 1) >= srcsize) {
  3222             dst[0] = ((Sint8) sample0);
  3223             dst[1] = ((Sint8) sample1);
  3224             dst[2] = ((Sint8) sample2);
  3225             dst[3] = ((Sint8) sample3);
  3226             dst[4] = ((Sint8) sample4);
  3227             dst[5] = ((Sint8) sample5);
  3228             dst[6] = ((Sint8) sample6);
  3229             dst[7] = ((Sint8) sample7);
  3230             dst += 8;
  3231             sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
  3232             sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
  3233             sample2 = (Sint8) ((((Sint16) ((Sint8) src[2])) + ((Sint16) last_sample2)) >> 1);
  3234             sample3 = (Sint8) ((((Sint16) ((Sint8) src[3])) + ((Sint16) last_sample3)) >> 1);
  3235             sample4 = (Sint8) ((((Sint16) ((Sint8) src[4])) + ((Sint16) last_sample4)) >> 1);
  3236             sample5 = (Sint8) ((((Sint16) ((Sint8) src[5])) + ((Sint16) last_sample5)) >> 1);
  3237             sample6 = (Sint8) ((((Sint16) ((Sint8) src[6])) + ((Sint16) last_sample6)) >> 1);
  3238             sample7 = (Sint8) ((((Sint16) ((Sint8) src[7])) + ((Sint16) last_sample7)) >> 1);
  3239             last_sample0 = sample0;
  3240             last_sample1 = sample1;
  3241             last_sample2 = sample2;
  3242             last_sample3 = sample3;
  3243             last_sample4 = sample4;
  3244             last_sample5 = sample5;
  3245             last_sample6 = sample6;
  3246             last_sample7 = sample7;
  3247             eps -= srcsize;
  3248         }
  3249     }
  3250     cvt->len_cvt = dstsize;
  3251     if (cvt->filters[++cvt->filter_index]) {
  3252         cvt->filters[cvt->filter_index] (cvt, format);
  3253     }
  3254 }
  3255 
  3256 static void SDLCALL
  3257 SDL_Upsample_U16LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3258 {
  3259 #if DEBUG_CONVERT
  3260     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16LSB, 1 channels.\n", cvt->rate_incr);
  3261 #endif
  3262 
  3263     const int srcsize = cvt->len_cvt - 32;
  3264     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3265     register int eps = 0;
  3266     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 1;
  3267     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
  3268     const Uint16 *target = ((const Uint16 *) cvt->buf) - 1;
  3269     Uint16 sample0 = SDL_SwapLE16(src[0]);
  3270     Uint16 last_sample0 = sample0;
  3271     while (dst != target) {
  3272         dst[0] = SDL_SwapLE16(sample0);
  3273         dst--;
  3274         eps += srcsize;
  3275         if ((eps << 1) >= dstsize) {
  3276             src--;
  3277             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  3278             last_sample0 = sample0;
  3279             eps -= dstsize;
  3280         }
  3281     }
  3282     cvt->len_cvt = dstsize;
  3283     if (cvt->filters[++cvt->filter_index]) {
  3284         cvt->filters[cvt->filter_index] (cvt, format);
  3285     }
  3286 }
  3287 
  3288 static void SDLCALL
  3289 SDL_Downsample_U16LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3290 {
  3291 #if DEBUG_CONVERT
  3292     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16LSB, 1 channels.\n", cvt->rate_incr);
  3293 #endif
  3294 
  3295     const int srcsize = cvt->len_cvt - 32;
  3296     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3297     register int eps = 0;
  3298     Uint16 *dst = (Uint16 *) cvt->buf;
  3299     const Uint16 *src = (Uint16 *) cvt->buf;
  3300     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
  3301     Uint16 sample0 = SDL_SwapLE16(src[0]);
  3302     Uint16 last_sample0 = sample0;
  3303     while (dst != target) {
  3304         src++;
  3305         eps += dstsize;
  3306         if ((eps << 1) >= srcsize) {
  3307             dst[0] = SDL_SwapLE16(sample0);
  3308             dst++;
  3309             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  3310             last_sample0 = sample0;
  3311             eps -= srcsize;
  3312         }
  3313     }
  3314     cvt->len_cvt = dstsize;
  3315     if (cvt->filters[++cvt->filter_index]) {
  3316         cvt->filters[cvt->filter_index] (cvt, format);
  3317     }
  3318 }
  3319 
  3320 static void SDLCALL
  3321 SDL_Upsample_U16LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3322 {
  3323 #if DEBUG_CONVERT
  3324     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16LSB, 2 channels.\n", cvt->rate_incr);
  3325 #endif
  3326 
  3327     const int srcsize = cvt->len_cvt - 64;
  3328     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3329     register int eps = 0;
  3330     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 2;
  3331     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 2;
  3332     const Uint16 *target = ((const Uint16 *) cvt->buf) - 2;
  3333     Uint16 sample1 = SDL_SwapLE16(src[1]);
  3334     Uint16 sample0 = SDL_SwapLE16(src[0]);
  3335     Uint16 last_sample1 = sample1;
  3336     Uint16 last_sample0 = sample0;
  3337     while (dst != target) {
  3338         dst[1] = SDL_SwapLE16(sample1);
  3339         dst[0] = SDL_SwapLE16(sample0);
  3340         dst -= 2;
  3341         eps += srcsize;
  3342         if ((eps << 1) >= dstsize) {
  3343             src -= 2;
  3344             sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  3345             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  3346             last_sample1 = sample1;
  3347             last_sample0 = sample0;
  3348             eps -= dstsize;
  3349         }
  3350     }
  3351     cvt->len_cvt = dstsize;
  3352     if (cvt->filters[++cvt->filter_index]) {
  3353         cvt->filters[cvt->filter_index] (cvt, format);
  3354     }
  3355 }
  3356 
  3357 static void SDLCALL
  3358 SDL_Downsample_U16LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3359 {
  3360 #if DEBUG_CONVERT
  3361     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16LSB, 2 channels.\n", cvt->rate_incr);
  3362 #endif
  3363 
  3364     const int srcsize = cvt->len_cvt - 64;
  3365     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3366     register int eps = 0;
  3367     Uint16 *dst = (Uint16 *) cvt->buf;
  3368     const Uint16 *src = (Uint16 *) cvt->buf;
  3369     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
  3370     Uint16 sample0 = SDL_SwapLE16(src[0]);
  3371     Uint16 sample1 = SDL_SwapLE16(src[1]);
  3372     Uint16 last_sample0 = sample0;
  3373     Uint16 last_sample1 = sample1;
  3374     while (dst != target) {
  3375         src += 2;
  3376         eps += dstsize;
  3377         if ((eps << 1) >= srcsize) {
  3378             dst[0] = SDL_SwapLE16(sample0);
  3379             dst[1] = SDL_SwapLE16(sample1);
  3380             dst += 2;
  3381             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  3382             sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  3383             last_sample0 = sample0;
  3384             last_sample1 = sample1;
  3385             eps -= srcsize;
  3386         }
  3387     }
  3388     cvt->len_cvt = dstsize;
  3389     if (cvt->filters[++cvt->filter_index]) {
  3390         cvt->filters[cvt->filter_index] (cvt, format);
  3391     }
  3392 }
  3393 
  3394 static void SDLCALL
  3395 SDL_Upsample_U16LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3396 {
  3397 #if DEBUG_CONVERT
  3398     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16LSB, 4 channels.\n", cvt->rate_incr);
  3399 #endif
  3400 
  3401     const int srcsize = cvt->len_cvt - 128;
  3402     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3403     register int eps = 0;
  3404     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 4;
  3405     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 4;
  3406     const Uint16 *target = ((const Uint16 *) cvt->buf) - 4;
  3407     Uint16 sample3 = SDL_SwapLE16(src[3]);
  3408     Uint16 sample2 = SDL_SwapLE16(src[2]);
  3409     Uint16 sample1 = SDL_SwapLE16(src[1]);
  3410     Uint16 sample0 = SDL_SwapLE16(src[0]);
  3411     Uint16 last_sample3 = sample3;
  3412     Uint16 last_sample2 = sample2;
  3413     Uint16 last_sample1 = sample1;
  3414     Uint16 last_sample0 = sample0;
  3415     while (dst != target) {
  3416         dst[3] = SDL_SwapLE16(sample3);
  3417         dst[2] = SDL_SwapLE16(sample2);
  3418         dst[1] = SDL_SwapLE16(sample1);
  3419         dst[0] = SDL_SwapLE16(sample0);
  3420         dst -= 4;
  3421         eps += srcsize;
  3422         if ((eps << 1) >= dstsize) {
  3423             src -= 4;
  3424             sample3 = (Uint16) ((((Sint32) SDL_SwapLE16(src[3])) + ((Sint32) last_sample3)) >> 1);
  3425             sample2 = (Uint16) ((((Sint32) SDL_SwapLE16(src[2])) + ((Sint32) last_sample2)) >> 1);
  3426             sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  3427             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  3428             last_sample3 = sample3;
  3429             last_sample2 = sample2;
  3430             last_sample1 = sample1;
  3431             last_sample0 = sample0;
  3432             eps -= dstsize;
  3433         }
  3434     }
  3435     cvt->len_cvt = dstsize;
  3436     if (cvt->filters[++cvt->filter_index]) {
  3437         cvt->filters[cvt->filter_index] (cvt, format);
  3438     }
  3439 }
  3440 
  3441 static void SDLCALL
  3442 SDL_Downsample_U16LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3443 {
  3444 #if DEBUG_CONVERT
  3445     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16LSB, 4 channels.\n", cvt->rate_incr);
  3446 #endif
  3447 
  3448     const int srcsize = cvt->len_cvt - 128;
  3449     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3450     register int eps = 0;
  3451     Uint16 *dst = (Uint16 *) cvt->buf;
  3452     const Uint16 *src = (Uint16 *) cvt->buf;
  3453     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
  3454     Uint16 sample0 = SDL_SwapLE16(src[0]);
  3455     Uint16 sample1 = SDL_SwapLE16(src[1]);
  3456     Uint16 sample2 = SDL_SwapLE16(src[2]);
  3457     Uint16 sample3 = SDL_SwapLE16(src[3]);
  3458     Uint16 last_sample0 = sample0;
  3459     Uint16 last_sample1 = sample1;
  3460     Uint16 last_sample2 = sample2;
  3461     Uint16 last_sample3 = sample3;
  3462     while (dst != target) {
  3463         src += 4;
  3464         eps += dstsize;
  3465         if ((eps << 1) >= srcsize) {
  3466             dst[0] = SDL_SwapLE16(sample0);
  3467             dst[1] = SDL_SwapLE16(sample1);
  3468             dst[2] = SDL_SwapLE16(sample2);
  3469             dst[3] = SDL_SwapLE16(sample3);
  3470             dst += 4;
  3471             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  3472             sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  3473             sample2 = (Uint16) ((((Sint32) SDL_SwapLE16(src[2])) + ((Sint32) last_sample2)) >> 1);
  3474             sample3 = (Uint16) ((((Sint32) SDL_SwapLE16(src[3])) + ((Sint32) last_sample3)) >> 1);
  3475             last_sample0 = sample0;
  3476             last_sample1 = sample1;
  3477             last_sample2 = sample2;
  3478             last_sample3 = sample3;
  3479             eps -= srcsize;
  3480         }
  3481     }
  3482     cvt->len_cvt = dstsize;
  3483     if (cvt->filters[++cvt->filter_index]) {
  3484         cvt->filters[cvt->filter_index] (cvt, format);
  3485     }
  3486 }
  3487 
  3488 static void SDLCALL
  3489 SDL_Upsample_U16LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3490 {
  3491 #if DEBUG_CONVERT
  3492     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16LSB, 6 channels.\n", cvt->rate_incr);
  3493 #endif
  3494 
  3495     const int srcsize = cvt->len_cvt - 192;
  3496     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3497     register int eps = 0;
  3498     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 6;
  3499     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 6;
  3500     const Uint16 *target = ((const Uint16 *) cvt->buf) - 6;
  3501     Uint16 sample5 = SDL_SwapLE16(src[5]);
  3502     Uint16 sample4 = SDL_SwapLE16(src[4]);
  3503     Uint16 sample3 = SDL_SwapLE16(src[3]);
  3504     Uint16 sample2 = SDL_SwapLE16(src[2]);
  3505     Uint16 sample1 = SDL_SwapLE16(src[1]);
  3506     Uint16 sample0 = SDL_SwapLE16(src[0]);
  3507     Uint16 last_sample5 = sample5;
  3508     Uint16 last_sample4 = sample4;
  3509     Uint16 last_sample3 = sample3;
  3510     Uint16 last_sample2 = sample2;
  3511     Uint16 last_sample1 = sample1;
  3512     Uint16 last_sample0 = sample0;
  3513     while (dst != target) {
  3514         dst[5] = SDL_SwapLE16(sample5);
  3515         dst[4] = SDL_SwapLE16(sample4);
  3516         dst[3] = SDL_SwapLE16(sample3);
  3517         dst[2] = SDL_SwapLE16(sample2);
  3518         dst[1] = SDL_SwapLE16(sample1);
  3519         dst[0] = SDL_SwapLE16(sample0);
  3520         dst -= 6;
  3521         eps += srcsize;
  3522         if ((eps << 1) >= dstsize) {
  3523             src -= 6;
  3524             sample5 = (Uint16) ((((Sint32) SDL_SwapLE16(src[5])) + ((Sint32) last_sample5)) >> 1);
  3525             sample4 = (Uint16) ((((Sint32) SDL_SwapLE16(src[4])) + ((Sint32) last_sample4)) >> 1);
  3526             sample3 = (Uint16) ((((Sint32) SDL_SwapLE16(src[3])) + ((Sint32) last_sample3)) >> 1);
  3527             sample2 = (Uint16) ((((Sint32) SDL_SwapLE16(src[2])) + ((Sint32) last_sample2)) >> 1);
  3528             sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  3529             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  3530             last_sample5 = sample5;
  3531             last_sample4 = sample4;
  3532             last_sample3 = sample3;
  3533             last_sample2 = sample2;
  3534             last_sample1 = sample1;
  3535             last_sample0 = sample0;
  3536             eps -= dstsize;
  3537         }
  3538     }
  3539     cvt->len_cvt = dstsize;
  3540     if (cvt->filters[++cvt->filter_index]) {
  3541         cvt->filters[cvt->filter_index] (cvt, format);
  3542     }
  3543 }
  3544 
  3545 static void SDLCALL
  3546 SDL_Downsample_U16LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3547 {
  3548 #if DEBUG_CONVERT
  3549     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16LSB, 6 channels.\n", cvt->rate_incr);
  3550 #endif
  3551 
  3552     const int srcsize = cvt->len_cvt - 192;
  3553     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3554     register int eps = 0;
  3555     Uint16 *dst = (Uint16 *) cvt->buf;
  3556     const Uint16 *src = (Uint16 *) cvt->buf;
  3557     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
  3558     Uint16 sample0 = SDL_SwapLE16(src[0]);
  3559     Uint16 sample1 = SDL_SwapLE16(src[1]);
  3560     Uint16 sample2 = SDL_SwapLE16(src[2]);
  3561     Uint16 sample3 = SDL_SwapLE16(src[3]);
  3562     Uint16 sample4 = SDL_SwapLE16(src[4]);
  3563     Uint16 sample5 = SDL_SwapLE16(src[5]);
  3564     Uint16 last_sample0 = sample0;
  3565     Uint16 last_sample1 = sample1;
  3566     Uint16 last_sample2 = sample2;
  3567     Uint16 last_sample3 = sample3;
  3568     Uint16 last_sample4 = sample4;
  3569     Uint16 last_sample5 = sample5;
  3570     while (dst != target) {
  3571         src += 6;
  3572         eps += dstsize;
  3573         if ((eps << 1) >= srcsize) {
  3574             dst[0] = SDL_SwapLE16(sample0);
  3575             dst[1] = SDL_SwapLE16(sample1);
  3576             dst[2] = SDL_SwapLE16(sample2);
  3577             dst[3] = SDL_SwapLE16(sample3);
  3578             dst[4] = SDL_SwapLE16(sample4);
  3579             dst[5] = SDL_SwapLE16(sample5);
  3580             dst += 6;
  3581             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  3582             sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  3583             sample2 = (Uint16) ((((Sint32) SDL_SwapLE16(src[2])) + ((Sint32) last_sample2)) >> 1);
  3584             sample3 = (Uint16) ((((Sint32) SDL_SwapLE16(src[3])) + ((Sint32) last_sample3)) >> 1);
  3585             sample4 = (Uint16) ((((Sint32) SDL_SwapLE16(src[4])) + ((Sint32) last_sample4)) >> 1);
  3586             sample5 = (Uint16) ((((Sint32) SDL_SwapLE16(src[5])) + ((Sint32) last_sample5)) >> 1);
  3587             last_sample0 = sample0;
  3588             last_sample1 = sample1;
  3589             last_sample2 = sample2;
  3590             last_sample3 = sample3;
  3591             last_sample4 = sample4;
  3592             last_sample5 = sample5;
  3593             eps -= srcsize;
  3594         }
  3595     }
  3596     cvt->len_cvt = dstsize;
  3597     if (cvt->filters[++cvt->filter_index]) {
  3598         cvt->filters[cvt->filter_index] (cvt, format);
  3599     }
  3600 }
  3601 
  3602 static void SDLCALL
  3603 SDL_Upsample_U16LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3604 {
  3605 #if DEBUG_CONVERT
  3606     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16LSB, 8 channels.\n", cvt->rate_incr);
  3607 #endif
  3608 
  3609     const int srcsize = cvt->len_cvt - 256;
  3610     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3611     register int eps = 0;
  3612     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 8;
  3613     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 8;
  3614     const Uint16 *target = ((const Uint16 *) cvt->buf) - 8;
  3615     Uint16 sample7 = SDL_SwapLE16(src[7]);
  3616     Uint16 sample6 = SDL_SwapLE16(src[6]);
  3617     Uint16 sample5 = SDL_SwapLE16(src[5]);
  3618     Uint16 sample4 = SDL_SwapLE16(src[4]);
  3619     Uint16 sample3 = SDL_SwapLE16(src[3]);
  3620     Uint16 sample2 = SDL_SwapLE16(src[2]);
  3621     Uint16 sample1 = SDL_SwapLE16(src[1]);
  3622     Uint16 sample0 = SDL_SwapLE16(src[0]);
  3623     Uint16 last_sample7 = sample7;
  3624     Uint16 last_sample6 = sample6;
  3625     Uint16 last_sample5 = sample5;
  3626     Uint16 last_sample4 = sample4;
  3627     Uint16 last_sample3 = sample3;
  3628     Uint16 last_sample2 = sample2;
  3629     Uint16 last_sample1 = sample1;
  3630     Uint16 last_sample0 = sample0;
  3631     while (dst != target) {
  3632         dst[7] = SDL_SwapLE16(sample7);
  3633         dst[6] = SDL_SwapLE16(sample6);
  3634         dst[5] = SDL_SwapLE16(sample5);
  3635         dst[4] = SDL_SwapLE16(sample4);
  3636         dst[3] = SDL_SwapLE16(sample3);
  3637         dst[2] = SDL_SwapLE16(sample2);
  3638         dst[1] = SDL_SwapLE16(sample1);
  3639         dst[0] = SDL_SwapLE16(sample0);
  3640         dst -= 8;
  3641         eps += srcsize;
  3642         if ((eps << 1) >= dstsize) {
  3643             src -= 8;
  3644             sample7 = (Uint16) ((((Sint32) SDL_SwapLE16(src[7])) + ((Sint32) last_sample7)) >> 1);
  3645             sample6 = (Uint16) ((((Sint32) SDL_SwapLE16(src[6])) + ((Sint32) last_sample6)) >> 1);
  3646             sample5 = (Uint16) ((((Sint32) SDL_SwapLE16(src[5])) + ((Sint32) last_sample5)) >> 1);
  3647             sample4 = (Uint16) ((((Sint32) SDL_SwapLE16(src[4])) + ((Sint32) last_sample4)) >> 1);
  3648             sample3 = (Uint16) ((((Sint32) SDL_SwapLE16(src[3])) + ((Sint32) last_sample3)) >> 1);
  3649             sample2 = (Uint16) ((((Sint32) SDL_SwapLE16(src[2])) + ((Sint32) last_sample2)) >> 1);
  3650             sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  3651             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  3652             last_sample7 = sample7;
  3653             last_sample6 = sample6;
  3654             last_sample5 = sample5;
  3655             last_sample4 = sample4;
  3656             last_sample3 = sample3;
  3657             last_sample2 = sample2;
  3658             last_sample1 = sample1;
  3659             last_sample0 = sample0;
  3660             eps -= dstsize;
  3661         }
  3662     }
  3663     cvt->len_cvt = dstsize;
  3664     if (cvt->filters[++cvt->filter_index]) {
  3665         cvt->filters[cvt->filter_index] (cvt, format);
  3666     }
  3667 }
  3668 
  3669 static void SDLCALL
  3670 SDL_Downsample_U16LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3671 {
  3672 #if DEBUG_CONVERT
  3673     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16LSB, 8 channels.\n", cvt->rate_incr);
  3674 #endif
  3675 
  3676     const int srcsize = cvt->len_cvt - 256;
  3677     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3678     register int eps = 0;
  3679     Uint16 *dst = (Uint16 *) cvt->buf;
  3680     const Uint16 *src = (Uint16 *) cvt->buf;
  3681     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
  3682     Uint16 sample0 = SDL_SwapLE16(src[0]);
  3683     Uint16 sample1 = SDL_SwapLE16(src[1]);
  3684     Uint16 sample2 = SDL_SwapLE16(src[2]);
  3685     Uint16 sample3 = SDL_SwapLE16(src[3]);
  3686     Uint16 sample4 = SDL_SwapLE16(src[4]);
  3687     Uint16 sample5 = SDL_SwapLE16(src[5]);
  3688     Uint16 sample6 = SDL_SwapLE16(src[6]);
  3689     Uint16 sample7 = SDL_SwapLE16(src[7]);
  3690     Uint16 last_sample0 = sample0;
  3691     Uint16 last_sample1 = sample1;
  3692     Uint16 last_sample2 = sample2;
  3693     Uint16 last_sample3 = sample3;
  3694     Uint16 last_sample4 = sample4;
  3695     Uint16 last_sample5 = sample5;
  3696     Uint16 last_sample6 = sample6;
  3697     Uint16 last_sample7 = sample7;
  3698     while (dst != target) {
  3699         src += 8;
  3700         eps += dstsize;
  3701         if ((eps << 1) >= srcsize) {
  3702             dst[0] = SDL_SwapLE16(sample0);
  3703             dst[1] = SDL_SwapLE16(sample1);
  3704             dst[2] = SDL_SwapLE16(sample2);
  3705             dst[3] = SDL_SwapLE16(sample3);
  3706             dst[4] = SDL_SwapLE16(sample4);
  3707             dst[5] = SDL_SwapLE16(sample5);
  3708             dst[6] = SDL_SwapLE16(sample6);
  3709             dst[7] = SDL_SwapLE16(sample7);
  3710             dst += 8;
  3711             sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  3712             sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  3713             sample2 = (Uint16) ((((Sint32) SDL_SwapLE16(src[2])) + ((Sint32) last_sample2)) >> 1);
  3714             sample3 = (Uint16) ((((Sint32) SDL_SwapLE16(src[3])) + ((Sint32) last_sample3)) >> 1);
  3715             sample4 = (Uint16) ((((Sint32) SDL_SwapLE16(src[4])) + ((Sint32) last_sample4)) >> 1);
  3716             sample5 = (Uint16) ((((Sint32) SDL_SwapLE16(src[5])) + ((Sint32) last_sample5)) >> 1);
  3717             sample6 = (Uint16) ((((Sint32) SDL_SwapLE16(src[6])) + ((Sint32) last_sample6)) >> 1);
  3718             sample7 = (Uint16) ((((Sint32) SDL_SwapLE16(src[7])) + ((Sint32) last_sample7)) >> 1);
  3719             last_sample0 = sample0;
  3720             last_sample1 = sample1;
  3721             last_sample2 = sample2;
  3722             last_sample3 = sample3;
  3723             last_sample4 = sample4;
  3724             last_sample5 = sample5;
  3725             last_sample6 = sample6;
  3726             last_sample7 = sample7;
  3727             eps -= srcsize;
  3728         }
  3729     }
  3730     cvt->len_cvt = dstsize;
  3731     if (cvt->filters[++cvt->filter_index]) {
  3732         cvt->filters[cvt->filter_index] (cvt, format);
  3733     }
  3734 }
  3735 
  3736 static void SDLCALL
  3737 SDL_Upsample_S16LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3738 {
  3739 #if DEBUG_CONVERT
  3740     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16LSB, 1 channels.\n", cvt->rate_incr);
  3741 #endif
  3742 
  3743     const int srcsize = cvt->len_cvt - 32;
  3744     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3745     register int eps = 0;
  3746     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 1;
  3747     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 1;
  3748     const Sint16 *target = ((const Sint16 *) cvt->buf) - 1;
  3749     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
  3750     Sint16 last_sample0 = sample0;
  3751     while (dst != target) {
  3752         dst[0] = ((Sint16) SDL_SwapLE16(sample0));
  3753         dst--;
  3754         eps += srcsize;
  3755         if ((eps << 1) >= dstsize) {
  3756             src--;
  3757             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  3758             last_sample0 = sample0;
  3759             eps -= dstsize;
  3760         }
  3761     }
  3762     cvt->len_cvt = dstsize;
  3763     if (cvt->filters[++cvt->filter_index]) {
  3764         cvt->filters[cvt->filter_index] (cvt, format);
  3765     }
  3766 }
  3767 
  3768 static void SDLCALL
  3769 SDL_Downsample_S16LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3770 {
  3771 #if DEBUG_CONVERT
  3772     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16LSB, 1 channels.\n", cvt->rate_incr);
  3773 #endif
  3774 
  3775     const int srcsize = cvt->len_cvt - 32;
  3776     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3777     register int eps = 0;
  3778     Sint16 *dst = (Sint16 *) cvt->buf;
  3779     const Sint16 *src = (Sint16 *) cvt->buf;
  3780     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
  3781     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
  3782     Sint16 last_sample0 = sample0;
  3783     while (dst != target) {
  3784         src++;
  3785         eps += dstsize;
  3786         if ((eps << 1) >= srcsize) {
  3787             dst[0] = ((Sint16) SDL_SwapLE16(sample0));
  3788             dst++;
  3789             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  3790             last_sample0 = sample0;
  3791             eps -= srcsize;
  3792         }
  3793     }
  3794     cvt->len_cvt = dstsize;
  3795     if (cvt->filters[++cvt->filter_index]) {
  3796         cvt->filters[cvt->filter_index] (cvt, format);
  3797     }
  3798 }
  3799 
  3800 static void SDLCALL
  3801 SDL_Upsample_S16LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3802 {
  3803 #if DEBUG_CONVERT
  3804     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16LSB, 2 channels.\n", cvt->rate_incr);
  3805 #endif
  3806 
  3807     const int srcsize = cvt->len_cvt - 64;
  3808     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3809     register int eps = 0;
  3810     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 2;
  3811     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 2;
  3812     const Sint16 *target = ((const Sint16 *) cvt->buf) - 2;
  3813     Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
  3814     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
  3815     Sint16 last_sample1 = sample1;
  3816     Sint16 last_sample0 = sample0;
  3817     while (dst != target) {
  3818         dst[1] = ((Sint16) SDL_SwapLE16(sample1));
  3819         dst[0] = ((Sint16) SDL_SwapLE16(sample0));
  3820         dst -= 2;
  3821         eps += srcsize;
  3822         if ((eps << 1) >= dstsize) {
  3823             src -= 2;
  3824             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  3825             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  3826             last_sample1 = sample1;
  3827             last_sample0 = sample0;
  3828             eps -= dstsize;
  3829         }
  3830     }
  3831     cvt->len_cvt = dstsize;
  3832     if (cvt->filters[++cvt->filter_index]) {
  3833         cvt->filters[cvt->filter_index] (cvt, format);
  3834     }
  3835 }
  3836 
  3837 static void SDLCALL
  3838 SDL_Downsample_S16LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3839 {
  3840 #if DEBUG_CONVERT
  3841     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16LSB, 2 channels.\n", cvt->rate_incr);
  3842 #endif
  3843 
  3844     const int srcsize = cvt->len_cvt - 64;
  3845     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3846     register int eps = 0;
  3847     Sint16 *dst = (Sint16 *) cvt->buf;
  3848     const Sint16 *src = (Sint16 *) cvt->buf;
  3849     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
  3850     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
  3851     Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
  3852     Sint16 last_sample0 = sample0;
  3853     Sint16 last_sample1 = sample1;
  3854     while (dst != target) {
  3855         src += 2;
  3856         eps += dstsize;
  3857         if ((eps << 1) >= srcsize) {
  3858             dst[0] = ((Sint16) SDL_SwapLE16(sample0));
  3859             dst[1] = ((Sint16) SDL_SwapLE16(sample1));
  3860             dst += 2;
  3861             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  3862             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  3863             last_sample0 = sample0;
  3864             last_sample1 = sample1;
  3865             eps -= srcsize;
  3866         }
  3867     }
  3868     cvt->len_cvt = dstsize;
  3869     if (cvt->filters[++cvt->filter_index]) {
  3870         cvt->filters[cvt->filter_index] (cvt, format);
  3871     }
  3872 }
  3873 
  3874 static void SDLCALL
  3875 SDL_Upsample_S16LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3876 {
  3877 #if DEBUG_CONVERT
  3878     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16LSB, 4 channels.\n", cvt->rate_incr);
  3879 #endif
  3880 
  3881     const int srcsize = cvt->len_cvt - 128;
  3882     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3883     register int eps = 0;
  3884     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 4;
  3885     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 4;
  3886     const Sint16 *target = ((const Sint16 *) cvt->buf) - 4;
  3887     Sint16 sample3 = ((Sint16) SDL_SwapLE16(src[3]));
  3888     Sint16 sample2 = ((Sint16) SDL_SwapLE16(src[2]));
  3889     Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
  3890     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
  3891     Sint16 last_sample3 = sample3;
  3892     Sint16 last_sample2 = sample2;
  3893     Sint16 last_sample1 = sample1;
  3894     Sint16 last_sample0 = sample0;
  3895     while (dst != target) {
  3896         dst[3] = ((Sint16) SDL_SwapLE16(sample3));
  3897         dst[2] = ((Sint16) SDL_SwapLE16(sample2));
  3898         dst[1] = ((Sint16) SDL_SwapLE16(sample1));
  3899         dst[0] = ((Sint16) SDL_SwapLE16(sample0));
  3900         dst -= 4;
  3901         eps += srcsize;
  3902         if ((eps << 1) >= dstsize) {
  3903             src -= 4;
  3904             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  3905             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  3906             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  3907             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  3908             last_sample3 = sample3;
  3909             last_sample2 = sample2;
  3910             last_sample1 = sample1;
  3911             last_sample0 = sample0;
  3912             eps -= dstsize;
  3913         }
  3914     }
  3915     cvt->len_cvt = dstsize;
  3916     if (cvt->filters[++cvt->filter_index]) {
  3917         cvt->filters[cvt->filter_index] (cvt, format);
  3918     }
  3919 }
  3920 
  3921 static void SDLCALL
  3922 SDL_Downsample_S16LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3923 {
  3924 #if DEBUG_CONVERT
  3925     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16LSB, 4 channels.\n", cvt->rate_incr);
  3926 #endif
  3927 
  3928     const int srcsize = cvt->len_cvt - 128;
  3929     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3930     register int eps = 0;
  3931     Sint16 *dst = (Sint16 *) cvt->buf;
  3932     const Sint16 *src = (Sint16 *) cvt->buf;
  3933     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
  3934     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
  3935     Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
  3936     Sint16 sample2 = ((Sint16) SDL_SwapLE16(src[2]));
  3937     Sint16 sample3 = ((Sint16) SDL_SwapLE16(src[3]));
  3938     Sint16 last_sample0 = sample0;
  3939     Sint16 last_sample1 = sample1;
  3940     Sint16 last_sample2 = sample2;
  3941     Sint16 last_sample3 = sample3;
  3942     while (dst != target) {
  3943         src += 4;
  3944         eps += dstsize;
  3945         if ((eps << 1) >= srcsize) {
  3946             dst[0] = ((Sint16) SDL_SwapLE16(sample0));
  3947             dst[1] = ((Sint16) SDL_SwapLE16(sample1));
  3948             dst[2] = ((Sint16) SDL_SwapLE16(sample2));
  3949             dst[3] = ((Sint16) SDL_SwapLE16(sample3));
  3950             dst += 4;
  3951             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  3952             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  3953             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  3954             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  3955             last_sample0 = sample0;
  3956             last_sample1 = sample1;
  3957             last_sample2 = sample2;
  3958             last_sample3 = sample3;
  3959             eps -= srcsize;
  3960         }
  3961     }
  3962     cvt->len_cvt = dstsize;
  3963     if (cvt->filters[++cvt->filter_index]) {
  3964         cvt->filters[cvt->filter_index] (cvt, format);
  3965     }
  3966 }
  3967 
  3968 static void SDLCALL
  3969 SDL_Upsample_S16LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  3970 {
  3971 #if DEBUG_CONVERT
  3972     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16LSB, 6 channels.\n", cvt->rate_incr);
  3973 #endif
  3974 
  3975     const int srcsize = cvt->len_cvt - 192;
  3976     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  3977     register int eps = 0;
  3978     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 6;
  3979     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 6;
  3980     const Sint16 *target = ((const Sint16 *) cvt->buf) - 6;
  3981     Sint16 sample5 = ((Sint16) SDL_SwapLE16(src[5]));
  3982     Sint16 sample4 = ((Sint16) SDL_SwapLE16(src[4]));
  3983     Sint16 sample3 = ((Sint16) SDL_SwapLE16(src[3]));
  3984     Sint16 sample2 = ((Sint16) SDL_SwapLE16(src[2]));
  3985     Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
  3986     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
  3987     Sint16 last_sample5 = sample5;
  3988     Sint16 last_sample4 = sample4;
  3989     Sint16 last_sample3 = sample3;
  3990     Sint16 last_sample2 = sample2;
  3991     Sint16 last_sample1 = sample1;
  3992     Sint16 last_sample0 = sample0;
  3993     while (dst != target) {
  3994         dst[5] = ((Sint16) SDL_SwapLE16(sample5));
  3995         dst[4] = ((Sint16) SDL_SwapLE16(sample4));
  3996         dst[3] = ((Sint16) SDL_SwapLE16(sample3));
  3997         dst[2] = ((Sint16) SDL_SwapLE16(sample2));
  3998         dst[1] = ((Sint16) SDL_SwapLE16(sample1));
  3999         dst[0] = ((Sint16) SDL_SwapLE16(sample0));
  4000         dst -= 6;
  4001         eps += srcsize;
  4002         if ((eps << 1) >= dstsize) {
  4003             src -= 6;
  4004             sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
  4005             sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
  4006             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  4007             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  4008             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  4009             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4010             last_sample5 = sample5;
  4011             last_sample4 = sample4;
  4012             last_sample3 = sample3;
  4013             last_sample2 = sample2;
  4014             last_sample1 = sample1;
  4015             last_sample0 = sample0;
  4016             eps -= dstsize;
  4017         }
  4018     }
  4019     cvt->len_cvt = dstsize;
  4020     if (cvt->filters[++cvt->filter_index]) {
  4021         cvt->filters[cvt->filter_index] (cvt, format);
  4022     }
  4023 }
  4024 
  4025 static void SDLCALL
  4026 SDL_Downsample_S16LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4027 {
  4028 #if DEBUG_CONVERT
  4029     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16LSB, 6 channels.\n", cvt->rate_incr);
  4030 #endif
  4031 
  4032     const int srcsize = cvt->len_cvt - 192;
  4033     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4034     register int eps = 0;
  4035     Sint16 *dst = (Sint16 *) cvt->buf;
  4036     const Sint16 *src = (Sint16 *) cvt->buf;
  4037     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
  4038     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
  4039     Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
  4040     Sint16 sample2 = ((Sint16) SDL_SwapLE16(src[2]));
  4041     Sint16 sample3 = ((Sint16) SDL_SwapLE16(src[3]));
  4042     Sint16 sample4 = ((Sint16) SDL_SwapLE16(src[4]));
  4043     Sint16 sample5 = ((Sint16) SDL_SwapLE16(src[5]));
  4044     Sint16 last_sample0 = sample0;
  4045     Sint16 last_sample1 = sample1;
  4046     Sint16 last_sample2 = sample2;
  4047     Sint16 last_sample3 = sample3;
  4048     Sint16 last_sample4 = sample4;
  4049     Sint16 last_sample5 = sample5;
  4050     while (dst != target) {
  4051         src += 6;
  4052         eps += dstsize;
  4053         if ((eps << 1) >= srcsize) {
  4054             dst[0] = ((Sint16) SDL_SwapLE16(sample0));
  4055             dst[1] = ((Sint16) SDL_SwapLE16(sample1));
  4056             dst[2] = ((Sint16) SDL_SwapLE16(sample2));
  4057             dst[3] = ((Sint16) SDL_SwapLE16(sample3));
  4058             dst[4] = ((Sint16) SDL_SwapLE16(sample4));
  4059             dst[5] = ((Sint16) SDL_SwapLE16(sample5));
  4060             dst += 6;
  4061             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4062             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  4063             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  4064             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  4065             sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
  4066             sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
  4067             last_sample0 = sample0;
  4068             last_sample1 = sample1;
  4069             last_sample2 = sample2;
  4070             last_sample3 = sample3;
  4071             last_sample4 = sample4;
  4072             last_sample5 = sample5;
  4073             eps -= srcsize;
  4074         }
  4075     }
  4076     cvt->len_cvt = dstsize;
  4077     if (cvt->filters[++cvt->filter_index]) {
  4078         cvt->filters[cvt->filter_index] (cvt, format);
  4079     }
  4080 }
  4081 
  4082 static void SDLCALL
  4083 SDL_Upsample_S16LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4084 {
  4085 #if DEBUG_CONVERT
  4086     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16LSB, 8 channels.\n", cvt->rate_incr);
  4087 #endif
  4088 
  4089     const int srcsize = cvt->len_cvt - 256;
  4090     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4091     register int eps = 0;
  4092     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 8;
  4093     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 8;
  4094     const Sint16 *target = ((const Sint16 *) cvt->buf) - 8;
  4095     Sint16 sample7 = ((Sint16) SDL_SwapLE16(src[7]));
  4096     Sint16 sample6 = ((Sint16) SDL_SwapLE16(src[6]));
  4097     Sint16 sample5 = ((Sint16) SDL_SwapLE16(src[5]));
  4098     Sint16 sample4 = ((Sint16) SDL_SwapLE16(src[4]));
  4099     Sint16 sample3 = ((Sint16) SDL_SwapLE16(src[3]));
  4100     Sint16 sample2 = ((Sint16) SDL_SwapLE16(src[2]));
  4101     Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
  4102     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
  4103     Sint16 last_sample7 = sample7;
  4104     Sint16 last_sample6 = sample6;
  4105     Sint16 last_sample5 = sample5;
  4106     Sint16 last_sample4 = sample4;
  4107     Sint16 last_sample3 = sample3;
  4108     Sint16 last_sample2 = sample2;
  4109     Sint16 last_sample1 = sample1;
  4110     Sint16 last_sample0 = sample0;
  4111     while (dst != target) {
  4112         dst[7] = ((Sint16) SDL_SwapLE16(sample7));
  4113         dst[6] = ((Sint16) SDL_SwapLE16(sample6));
  4114         dst[5] = ((Sint16) SDL_SwapLE16(sample5));
  4115         dst[4] = ((Sint16) SDL_SwapLE16(sample4));
  4116         dst[3] = ((Sint16) SDL_SwapLE16(sample3));
  4117         dst[2] = ((Sint16) SDL_SwapLE16(sample2));
  4118         dst[1] = ((Sint16) SDL_SwapLE16(sample1));
  4119         dst[0] = ((Sint16) SDL_SwapLE16(sample0));
  4120         dst -= 8;
  4121         eps += srcsize;
  4122         if ((eps << 1) >= dstsize) {
  4123             src -= 8;
  4124             sample7 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[7]))) + ((Sint32) last_sample7)) >> 1);
  4125             sample6 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[6]))) + ((Sint32) last_sample6)) >> 1);
  4126             sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
  4127             sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
  4128             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  4129             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  4130             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  4131             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4132             last_sample7 = sample7;
  4133             last_sample6 = sample6;
  4134             last_sample5 = sample5;
  4135             last_sample4 = sample4;
  4136             last_sample3 = sample3;
  4137             last_sample2 = sample2;
  4138             last_sample1 = sample1;
  4139             last_sample0 = sample0;
  4140             eps -= dstsize;
  4141         }
  4142     }
  4143     cvt->len_cvt = dstsize;
  4144     if (cvt->filters[++cvt->filter_index]) {
  4145         cvt->filters[cvt->filter_index] (cvt, format);
  4146     }
  4147 }
  4148 
  4149 static void SDLCALL
  4150 SDL_Downsample_S16LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4151 {
  4152 #if DEBUG_CONVERT
  4153     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16LSB, 8 channels.\n", cvt->rate_incr);
  4154 #endif
  4155 
  4156     const int srcsize = cvt->len_cvt - 256;
  4157     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4158     register int eps = 0;
  4159     Sint16 *dst = (Sint16 *) cvt->buf;
  4160     const Sint16 *src = (Sint16 *) cvt->buf;
  4161     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
  4162     Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
  4163     Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
  4164     Sint16 sample2 = ((Sint16) SDL_SwapLE16(src[2]));
  4165     Sint16 sample3 = ((Sint16) SDL_SwapLE16(src[3]));
  4166     Sint16 sample4 = ((Sint16) SDL_SwapLE16(src[4]));
  4167     Sint16 sample5 = ((Sint16) SDL_SwapLE16(src[5]));
  4168     Sint16 sample6 = ((Sint16) SDL_SwapLE16(src[6]));
  4169     Sint16 sample7 = ((Sint16) SDL_SwapLE16(src[7]));
  4170     Sint16 last_sample0 = sample0;
  4171     Sint16 last_sample1 = sample1;
  4172     Sint16 last_sample2 = sample2;
  4173     Sint16 last_sample3 = sample3;
  4174     Sint16 last_sample4 = sample4;
  4175     Sint16 last_sample5 = sample5;
  4176     Sint16 last_sample6 = sample6;
  4177     Sint16 last_sample7 = sample7;
  4178     while (dst != target) {
  4179         src += 8;
  4180         eps += dstsize;
  4181         if ((eps << 1) >= srcsize) {
  4182             dst[0] = ((Sint16) SDL_SwapLE16(sample0));
  4183             dst[1] = ((Sint16) SDL_SwapLE16(sample1));
  4184             dst[2] = ((Sint16) SDL_SwapLE16(sample2));
  4185             dst[3] = ((Sint16) SDL_SwapLE16(sample3));
  4186             dst[4] = ((Sint16) SDL_SwapLE16(sample4));
  4187             dst[5] = ((Sint16) SDL_SwapLE16(sample5));
  4188             dst[6] = ((Sint16) SDL_SwapLE16(sample6));
  4189             dst[7] = ((Sint16) SDL_SwapLE16(sample7));
  4190             dst += 8;
  4191             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4192             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  4193             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  4194             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  4195             sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
  4196             sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
  4197             sample6 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[6]))) + ((Sint32) last_sample6)) >> 1);
  4198             sample7 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[7]))) + ((Sint32) last_sample7)) >> 1);
  4199             last_sample0 = sample0;
  4200             last_sample1 = sample1;
  4201             last_sample2 = sample2;
  4202             last_sample3 = sample3;
  4203             last_sample4 = sample4;
  4204             last_sample5 = sample5;
  4205             last_sample6 = sample6;
  4206             last_sample7 = sample7;
  4207             eps -= srcsize;
  4208         }
  4209     }
  4210     cvt->len_cvt = dstsize;
  4211     if (cvt->filters[++cvt->filter_index]) {
  4212         cvt->filters[cvt->filter_index] (cvt, format);
  4213     }
  4214 }
  4215 
  4216 static void SDLCALL
  4217 SDL_Upsample_U16MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4218 {
  4219 #if DEBUG_CONVERT
  4220     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16MSB, 1 channels.\n", cvt->rate_incr);
  4221 #endif
  4222 
  4223     const int srcsize = cvt->len_cvt - 32;
  4224     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4225     register int eps = 0;
  4226     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 1;
  4227     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
  4228     const Uint16 *target = ((const Uint16 *) cvt->buf) - 1;
  4229     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4230     Uint16 last_sample0 = sample0;
  4231     while (dst != target) {
  4232         dst[0] = SDL_SwapBE16(sample0);
  4233         dst--;
  4234         eps += srcsize;
  4235         if ((eps << 1) >= dstsize) {
  4236             src--;
  4237             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4238             last_sample0 = sample0;
  4239             eps -= dstsize;
  4240         }
  4241     }
  4242     cvt->len_cvt = dstsize;
  4243     if (cvt->filters[++cvt->filter_index]) {
  4244         cvt->filters[cvt->filter_index] (cvt, format);
  4245     }
  4246 }
  4247 
  4248 static void SDLCALL
  4249 SDL_Downsample_U16MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4250 {
  4251 #if DEBUG_CONVERT
  4252     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16MSB, 1 channels.\n", cvt->rate_incr);
  4253 #endif
  4254 
  4255     const int srcsize = cvt->len_cvt - 32;
  4256     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4257     register int eps = 0;
  4258     Uint16 *dst = (Uint16 *) cvt->buf;
  4259     const Uint16 *src = (Uint16 *) cvt->buf;
  4260     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
  4261     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4262     Uint16 last_sample0 = sample0;
  4263     while (dst != target) {
  4264         src++;
  4265         eps += dstsize;
  4266         if ((eps << 1) >= srcsize) {
  4267             dst[0] = SDL_SwapBE16(sample0);
  4268             dst++;
  4269             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4270             last_sample0 = sample0;
  4271             eps -= srcsize;
  4272         }
  4273     }
  4274     cvt->len_cvt = dstsize;
  4275     if (cvt->filters[++cvt->filter_index]) {
  4276         cvt->filters[cvt->filter_index] (cvt, format);
  4277     }
  4278 }
  4279 
  4280 static void SDLCALL
  4281 SDL_Upsample_U16MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4282 {
  4283 #if DEBUG_CONVERT
  4284     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16MSB, 2 channels.\n", cvt->rate_incr);
  4285 #endif
  4286 
  4287     const int srcsize = cvt->len_cvt - 64;
  4288     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4289     register int eps = 0;
  4290     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 2;
  4291     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 2;
  4292     const Uint16 *target = ((const Uint16 *) cvt->buf) - 2;
  4293     Uint16 sample1 = SDL_SwapBE16(src[1]);
  4294     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4295     Uint16 last_sample1 = sample1;
  4296     Uint16 last_sample0 = sample0;
  4297     while (dst != target) {
  4298         dst[1] = SDL_SwapBE16(sample1);
  4299         dst[0] = SDL_SwapBE16(sample0);
  4300         dst -= 2;
  4301         eps += srcsize;
  4302         if ((eps << 1) >= dstsize) {
  4303             src -= 2;
  4304             sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  4305             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4306             last_sample1 = sample1;
  4307             last_sample0 = sample0;
  4308             eps -= dstsize;
  4309         }
  4310     }
  4311     cvt->len_cvt = dstsize;
  4312     if (cvt->filters[++cvt->filter_index]) {
  4313         cvt->filters[cvt->filter_index] (cvt, format);
  4314     }
  4315 }
  4316 
  4317 static void SDLCALL
  4318 SDL_Downsample_U16MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4319 {
  4320 #if DEBUG_CONVERT
  4321     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16MSB, 2 channels.\n", cvt->rate_incr);
  4322 #endif
  4323 
  4324     const int srcsize = cvt->len_cvt - 64;
  4325     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4326     register int eps = 0;
  4327     Uint16 *dst = (Uint16 *) cvt->buf;
  4328     const Uint16 *src = (Uint16 *) cvt->buf;
  4329     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
  4330     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4331     Uint16 sample1 = SDL_SwapBE16(src[1]);
  4332     Uint16 last_sample0 = sample0;
  4333     Uint16 last_sample1 = sample1;
  4334     while (dst != target) {
  4335         src += 2;
  4336         eps += dstsize;
  4337         if ((eps << 1) >= srcsize) {
  4338             dst[0] = SDL_SwapBE16(sample0);
  4339             dst[1] = SDL_SwapBE16(sample1);
  4340             dst += 2;
  4341             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4342             sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  4343             last_sample0 = sample0;
  4344             last_sample1 = sample1;
  4345             eps -= srcsize;
  4346         }
  4347     }
  4348     cvt->len_cvt = dstsize;
  4349     if (cvt->filters[++cvt->filter_index]) {
  4350         cvt->filters[cvt->filter_index] (cvt, format);
  4351     }
  4352 }
  4353 
  4354 static void SDLCALL
  4355 SDL_Upsample_U16MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4356 {
  4357 #if DEBUG_CONVERT
  4358     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16MSB, 4 channels.\n", cvt->rate_incr);
  4359 #endif
  4360 
  4361     const int srcsize = cvt->len_cvt - 128;
  4362     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4363     register int eps = 0;
  4364     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 4;
  4365     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 4;
  4366     const Uint16 *target = ((const Uint16 *) cvt->buf) - 4;
  4367     Uint16 sample3 = SDL_SwapBE16(src[3]);
  4368     Uint16 sample2 = SDL_SwapBE16(src[2]);
  4369     Uint16 sample1 = SDL_SwapBE16(src[1]);
  4370     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4371     Uint16 last_sample3 = sample3;
  4372     Uint16 last_sample2 = sample2;
  4373     Uint16 last_sample1 = sample1;
  4374     Uint16 last_sample0 = sample0;
  4375     while (dst != target) {
  4376         dst[3] = SDL_SwapBE16(sample3);
  4377         dst[2] = SDL_SwapBE16(sample2);
  4378         dst[1] = SDL_SwapBE16(sample1);
  4379         dst[0] = SDL_SwapBE16(sample0);
  4380         dst -= 4;
  4381         eps += srcsize;
  4382         if ((eps << 1) >= dstsize) {
  4383             src -= 4;
  4384             sample3 = (Uint16) ((((Sint32) SDL_SwapBE16(src[3])) + ((Sint32) last_sample3)) >> 1);
  4385             sample2 = (Uint16) ((((Sint32) SDL_SwapBE16(src[2])) + ((Sint32) last_sample2)) >> 1);
  4386             sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  4387             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4388             last_sample3 = sample3;
  4389             last_sample2 = sample2;
  4390             last_sample1 = sample1;
  4391             last_sample0 = sample0;
  4392             eps -= dstsize;
  4393         }
  4394     }
  4395     cvt->len_cvt = dstsize;
  4396     if (cvt->filters[++cvt->filter_index]) {
  4397         cvt->filters[cvt->filter_index] (cvt, format);
  4398     }
  4399 }
  4400 
  4401 static void SDLCALL
  4402 SDL_Downsample_U16MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4403 {
  4404 #if DEBUG_CONVERT
  4405     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16MSB, 4 channels.\n", cvt->rate_incr);
  4406 #endif
  4407 
  4408     const int srcsize = cvt->len_cvt - 128;
  4409     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4410     register int eps = 0;
  4411     Uint16 *dst = (Uint16 *) cvt->buf;
  4412     const Uint16 *src = (Uint16 *) cvt->buf;
  4413     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
  4414     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4415     Uint16 sample1 = SDL_SwapBE16(src[1]);
  4416     Uint16 sample2 = SDL_SwapBE16(src[2]);
  4417     Uint16 sample3 = SDL_SwapBE16(src[3]);
  4418     Uint16 last_sample0 = sample0;
  4419     Uint16 last_sample1 = sample1;
  4420     Uint16 last_sample2 = sample2;
  4421     Uint16 last_sample3 = sample3;
  4422     while (dst != target) {
  4423         src += 4;
  4424         eps += dstsize;
  4425         if ((eps << 1) >= srcsize) {
  4426             dst[0] = SDL_SwapBE16(sample0);
  4427             dst[1] = SDL_SwapBE16(sample1);
  4428             dst[2] = SDL_SwapBE16(sample2);
  4429             dst[3] = SDL_SwapBE16(sample3);
  4430             dst += 4;
  4431             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4432             sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  4433             sample2 = (Uint16) ((((Sint32) SDL_SwapBE16(src[2])) + ((Sint32) last_sample2)) >> 1);
  4434             sample3 = (Uint16) ((((Sint32) SDL_SwapBE16(src[3])) + ((Sint32) last_sample3)) >> 1);
  4435             last_sample0 = sample0;
  4436             last_sample1 = sample1;
  4437             last_sample2 = sample2;
  4438             last_sample3 = sample3;
  4439             eps -= srcsize;
  4440         }
  4441     }
  4442     cvt->len_cvt = dstsize;
  4443     if (cvt->filters[++cvt->filter_index]) {
  4444         cvt->filters[cvt->filter_index] (cvt, format);
  4445     }
  4446 }
  4447 
  4448 static void SDLCALL
  4449 SDL_Upsample_U16MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4450 {
  4451 #if DEBUG_CONVERT
  4452     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16MSB, 6 channels.\n", cvt->rate_incr);
  4453 #endif
  4454 
  4455     const int srcsize = cvt->len_cvt - 192;
  4456     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4457     register int eps = 0;
  4458     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 6;
  4459     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 6;
  4460     const Uint16 *target = ((const Uint16 *) cvt->buf) - 6;
  4461     Uint16 sample5 = SDL_SwapBE16(src[5]);
  4462     Uint16 sample4 = SDL_SwapBE16(src[4]);
  4463     Uint16 sample3 = SDL_SwapBE16(src[3]);
  4464     Uint16 sample2 = SDL_SwapBE16(src[2]);
  4465     Uint16 sample1 = SDL_SwapBE16(src[1]);
  4466     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4467     Uint16 last_sample5 = sample5;
  4468     Uint16 last_sample4 = sample4;
  4469     Uint16 last_sample3 = sample3;
  4470     Uint16 last_sample2 = sample2;
  4471     Uint16 last_sample1 = sample1;
  4472     Uint16 last_sample0 = sample0;
  4473     while (dst != target) {
  4474         dst[5] = SDL_SwapBE16(sample5);
  4475         dst[4] = SDL_SwapBE16(sample4);
  4476         dst[3] = SDL_SwapBE16(sample3);
  4477         dst[2] = SDL_SwapBE16(sample2);
  4478         dst[1] = SDL_SwapBE16(sample1);
  4479         dst[0] = SDL_SwapBE16(sample0);
  4480         dst -= 6;
  4481         eps += srcsize;
  4482         if ((eps << 1) >= dstsize) {
  4483             src -= 6;
  4484             sample5 = (Uint16) ((((Sint32) SDL_SwapBE16(src[5])) + ((Sint32) last_sample5)) >> 1);
  4485             sample4 = (Uint16) ((((Sint32) SDL_SwapBE16(src[4])) + ((Sint32) last_sample4)) >> 1);
  4486             sample3 = (Uint16) ((((Sint32) SDL_SwapBE16(src[3])) + ((Sint32) last_sample3)) >> 1);
  4487             sample2 = (Uint16) ((((Sint32) SDL_SwapBE16(src[2])) + ((Sint32) last_sample2)) >> 1);
  4488             sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  4489             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4490             last_sample5 = sample5;
  4491             last_sample4 = sample4;
  4492             last_sample3 = sample3;
  4493             last_sample2 = sample2;
  4494             last_sample1 = sample1;
  4495             last_sample0 = sample0;
  4496             eps -= dstsize;
  4497         }
  4498     }
  4499     cvt->len_cvt = dstsize;
  4500     if (cvt->filters[++cvt->filter_index]) {
  4501         cvt->filters[cvt->filter_index] (cvt, format);
  4502     }
  4503 }
  4504 
  4505 static void SDLCALL
  4506 SDL_Downsample_U16MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4507 {
  4508 #if DEBUG_CONVERT
  4509     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16MSB, 6 channels.\n", cvt->rate_incr);
  4510 #endif
  4511 
  4512     const int srcsize = cvt->len_cvt - 192;
  4513     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4514     register int eps = 0;
  4515     Uint16 *dst = (Uint16 *) cvt->buf;
  4516     const Uint16 *src = (Uint16 *) cvt->buf;
  4517     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
  4518     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4519     Uint16 sample1 = SDL_SwapBE16(src[1]);
  4520     Uint16 sample2 = SDL_SwapBE16(src[2]);
  4521     Uint16 sample3 = SDL_SwapBE16(src[3]);
  4522     Uint16 sample4 = SDL_SwapBE16(src[4]);
  4523     Uint16 sample5 = SDL_SwapBE16(src[5]);
  4524     Uint16 last_sample0 = sample0;
  4525     Uint16 last_sample1 = sample1;
  4526     Uint16 last_sample2 = sample2;
  4527     Uint16 last_sample3 = sample3;
  4528     Uint16 last_sample4 = sample4;
  4529     Uint16 last_sample5 = sample5;
  4530     while (dst != target) {
  4531         src += 6;
  4532         eps += dstsize;
  4533         if ((eps << 1) >= srcsize) {
  4534             dst[0] = SDL_SwapBE16(sample0);
  4535             dst[1] = SDL_SwapBE16(sample1);
  4536             dst[2] = SDL_SwapBE16(sample2);
  4537             dst[3] = SDL_SwapBE16(sample3);
  4538             dst[4] = SDL_SwapBE16(sample4);
  4539             dst[5] = SDL_SwapBE16(sample5);
  4540             dst += 6;
  4541             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4542             sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  4543             sample2 = (Uint16) ((((Sint32) SDL_SwapBE16(src[2])) + ((Sint32) last_sample2)) >> 1);
  4544             sample3 = (Uint16) ((((Sint32) SDL_SwapBE16(src[3])) + ((Sint32) last_sample3)) >> 1);
  4545             sample4 = (Uint16) ((((Sint32) SDL_SwapBE16(src[4])) + ((Sint32) last_sample4)) >> 1);
  4546             sample5 = (Uint16) ((((Sint32) SDL_SwapBE16(src[5])) + ((Sint32) last_sample5)) >> 1);
  4547             last_sample0 = sample0;
  4548             last_sample1 = sample1;
  4549             last_sample2 = sample2;
  4550             last_sample3 = sample3;
  4551             last_sample4 = sample4;
  4552             last_sample5 = sample5;
  4553             eps -= srcsize;
  4554         }
  4555     }
  4556     cvt->len_cvt = dstsize;
  4557     if (cvt->filters[++cvt->filter_index]) {
  4558         cvt->filters[cvt->filter_index] (cvt, format);
  4559     }
  4560 }
  4561 
  4562 static void SDLCALL
  4563 SDL_Upsample_U16MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4564 {
  4565 #if DEBUG_CONVERT
  4566     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16MSB, 8 channels.\n", cvt->rate_incr);
  4567 #endif
  4568 
  4569     const int srcsize = cvt->len_cvt - 256;
  4570     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4571     register int eps = 0;
  4572     Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 8;
  4573     const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 8;
  4574     const Uint16 *target = ((const Uint16 *) cvt->buf) - 8;
  4575     Uint16 sample7 = SDL_SwapBE16(src[7]);
  4576     Uint16 sample6 = SDL_SwapBE16(src[6]);
  4577     Uint16 sample5 = SDL_SwapBE16(src[5]);
  4578     Uint16 sample4 = SDL_SwapBE16(src[4]);
  4579     Uint16 sample3 = SDL_SwapBE16(src[3]);
  4580     Uint16 sample2 = SDL_SwapBE16(src[2]);
  4581     Uint16 sample1 = SDL_SwapBE16(src[1]);
  4582     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4583     Uint16 last_sample7 = sample7;
  4584     Uint16 last_sample6 = sample6;
  4585     Uint16 last_sample5 = sample5;
  4586     Uint16 last_sample4 = sample4;
  4587     Uint16 last_sample3 = sample3;
  4588     Uint16 last_sample2 = sample2;
  4589     Uint16 last_sample1 = sample1;
  4590     Uint16 last_sample0 = sample0;
  4591     while (dst != target) {
  4592         dst[7] = SDL_SwapBE16(sample7);
  4593         dst[6] = SDL_SwapBE16(sample6);
  4594         dst[5] = SDL_SwapBE16(sample5);
  4595         dst[4] = SDL_SwapBE16(sample4);
  4596         dst[3] = SDL_SwapBE16(sample3);
  4597         dst[2] = SDL_SwapBE16(sample2);
  4598         dst[1] = SDL_SwapBE16(sample1);
  4599         dst[0] = SDL_SwapBE16(sample0);
  4600         dst -= 8;
  4601         eps += srcsize;
  4602         if ((eps << 1) >= dstsize) {
  4603             src -= 8;
  4604             sample7 = (Uint16) ((((Sint32) SDL_SwapBE16(src[7])) + ((Sint32) last_sample7)) >> 1);
  4605             sample6 = (Uint16) ((((Sint32) SDL_SwapBE16(src[6])) + ((Sint32) last_sample6)) >> 1);
  4606             sample5 = (Uint16) ((((Sint32) SDL_SwapBE16(src[5])) + ((Sint32) last_sample5)) >> 1);
  4607             sample4 = (Uint16) ((((Sint32) SDL_SwapBE16(src[4])) + ((Sint32) last_sample4)) >> 1);
  4608             sample3 = (Uint16) ((((Sint32) SDL_SwapBE16(src[3])) + ((Sint32) last_sample3)) >> 1);
  4609             sample2 = (Uint16) ((((Sint32) SDL_SwapBE16(src[2])) + ((Sint32) last_sample2)) >> 1);
  4610             sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  4611             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4612             last_sample7 = sample7;
  4613             last_sample6 = sample6;
  4614             last_sample5 = sample5;
  4615             last_sample4 = sample4;
  4616             last_sample3 = sample3;
  4617             last_sample2 = sample2;
  4618             last_sample1 = sample1;
  4619             last_sample0 = sample0;
  4620             eps -= dstsize;
  4621         }
  4622     }
  4623     cvt->len_cvt = dstsize;
  4624     if (cvt->filters[++cvt->filter_index]) {
  4625         cvt->filters[cvt->filter_index] (cvt, format);
  4626     }
  4627 }
  4628 
  4629 static void SDLCALL
  4630 SDL_Downsample_U16MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4631 {
  4632 #if DEBUG_CONVERT
  4633     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16MSB, 8 channels.\n", cvt->rate_incr);
  4634 #endif
  4635 
  4636     const int srcsize = cvt->len_cvt - 256;
  4637     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4638     register int eps = 0;
  4639     Uint16 *dst = (Uint16 *) cvt->buf;
  4640     const Uint16 *src = (Uint16 *) cvt->buf;
  4641     const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
  4642     Uint16 sample0 = SDL_SwapBE16(src[0]);
  4643     Uint16 sample1 = SDL_SwapBE16(src[1]);
  4644     Uint16 sample2 = SDL_SwapBE16(src[2]);
  4645     Uint16 sample3 = SDL_SwapBE16(src[3]);
  4646     Uint16 sample4 = SDL_SwapBE16(src[4]);
  4647     Uint16 sample5 = SDL_SwapBE16(src[5]);
  4648     Uint16 sample6 = SDL_SwapBE16(src[6]);
  4649     Uint16 sample7 = SDL_SwapBE16(src[7]);
  4650     Uint16 last_sample0 = sample0;
  4651     Uint16 last_sample1 = sample1;
  4652     Uint16 last_sample2 = sample2;
  4653     Uint16 last_sample3 = sample3;
  4654     Uint16 last_sample4 = sample4;
  4655     Uint16 last_sample5 = sample5;
  4656     Uint16 last_sample6 = sample6;
  4657     Uint16 last_sample7 = sample7;
  4658     while (dst != target) {
  4659         src += 8;
  4660         eps += dstsize;
  4661         if ((eps << 1) >= srcsize) {
  4662             dst[0] = SDL_SwapBE16(sample0);
  4663             dst[1] = SDL_SwapBE16(sample1);
  4664             dst[2] = SDL_SwapBE16(sample2);
  4665             dst[3] = SDL_SwapBE16(sample3);
  4666             dst[4] = SDL_SwapBE16(sample4);
  4667             dst[5] = SDL_SwapBE16(sample5);
  4668             dst[6] = SDL_SwapBE16(sample6);
  4669             dst[7] = SDL_SwapBE16(sample7);
  4670             dst += 8;
  4671             sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
  4672             sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
  4673             sample2 = (Uint16) ((((Sint32) SDL_SwapBE16(src[2])) + ((Sint32) last_sample2)) >> 1);
  4674             sample3 = (Uint16) ((((Sint32) SDL_SwapBE16(src[3])) + ((Sint32) last_sample3)) >> 1);
  4675             sample4 = (Uint16) ((((Sint32) SDL_SwapBE16(src[4])) + ((Sint32) last_sample4)) >> 1);
  4676             sample5 = (Uint16) ((((Sint32) SDL_SwapBE16(src[5])) + ((Sint32) last_sample5)) >> 1);
  4677             sample6 = (Uint16) ((((Sint32) SDL_SwapBE16(src[6])) + ((Sint32) last_sample6)) >> 1);
  4678             sample7 = (Uint16) ((((Sint32) SDL_SwapBE16(src[7])) + ((Sint32) last_sample7)) >> 1);
  4679             last_sample0 = sample0;
  4680             last_sample1 = sample1;
  4681             last_sample2 = sample2;
  4682             last_sample3 = sample3;
  4683             last_sample4 = sample4;
  4684             last_sample5 = sample5;
  4685             last_sample6 = sample6;
  4686             last_sample7 = sample7;
  4687             eps -= srcsize;
  4688         }
  4689     }
  4690     cvt->len_cvt = dstsize;
  4691     if (cvt->filters[++cvt->filter_index]) {
  4692         cvt->filters[cvt->filter_index] (cvt, format);
  4693     }
  4694 }
  4695 
  4696 static void SDLCALL
  4697 SDL_Upsample_S16MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4698 {
  4699 #if DEBUG_CONVERT
  4700     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16MSB, 1 channels.\n", cvt->rate_incr);
  4701 #endif
  4702 
  4703     const int srcsize = cvt->len_cvt - 32;
  4704     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4705     register int eps = 0;
  4706     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 1;
  4707     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 1;
  4708     const Sint16 *target = ((const Sint16 *) cvt->buf) - 1;
  4709     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  4710     Sint16 last_sample0 = sample0;
  4711     while (dst != target) {
  4712         dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  4713         dst--;
  4714         eps += srcsize;
  4715         if ((eps << 1) >= dstsize) {
  4716             src--;
  4717             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4718             last_sample0 = sample0;
  4719             eps -= dstsize;
  4720         }
  4721     }
  4722     cvt->len_cvt = dstsize;
  4723     if (cvt->filters[++cvt->filter_index]) {
  4724         cvt->filters[cvt->filter_index] (cvt, format);
  4725     }
  4726 }
  4727 
  4728 static void SDLCALL
  4729 SDL_Downsample_S16MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4730 {
  4731 #if DEBUG_CONVERT
  4732     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16MSB, 1 channels.\n", cvt->rate_incr);
  4733 #endif
  4734 
  4735     const int srcsize = cvt->len_cvt - 32;
  4736     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4737     register int eps = 0;
  4738     Sint16 *dst = (Sint16 *) cvt->buf;
  4739     const Sint16 *src = (Sint16 *) cvt->buf;
  4740     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
  4741     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  4742     Sint16 last_sample0 = sample0;
  4743     while (dst != target) {
  4744         src++;
  4745         eps += dstsize;
  4746         if ((eps << 1) >= srcsize) {
  4747             dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  4748             dst++;
  4749             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4750             last_sample0 = sample0;
  4751             eps -= srcsize;
  4752         }
  4753     }
  4754     cvt->len_cvt = dstsize;
  4755     if (cvt->filters[++cvt->filter_index]) {
  4756         cvt->filters[cvt->filter_index] (cvt, format);
  4757     }
  4758 }
  4759 
  4760 static void SDLCALL
  4761 SDL_Upsample_S16MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4762 {
  4763 #if DEBUG_CONVERT
  4764     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16MSB, 2 channels.\n", cvt->rate_incr);
  4765 #endif
  4766 
  4767     const int srcsize = cvt->len_cvt - 64;
  4768     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4769     register int eps = 0;
  4770     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 2;
  4771     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 2;
  4772     const Sint16 *target = ((const Sint16 *) cvt->buf) - 2;
  4773     Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
  4774     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  4775     Sint16 last_sample1 = sample1;
  4776     Sint16 last_sample0 = sample0;
  4777     while (dst != target) {
  4778         dst[1] = ((Sint16) SDL_SwapBE16(sample1));
  4779         dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  4780         dst -= 2;
  4781         eps += srcsize;
  4782         if ((eps << 1) >= dstsize) {
  4783             src -= 2;
  4784             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  4785             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4786             last_sample1 = sample1;
  4787             last_sample0 = sample0;
  4788             eps -= dstsize;
  4789         }
  4790     }
  4791     cvt->len_cvt = dstsize;
  4792     if (cvt->filters[++cvt->filter_index]) {
  4793         cvt->filters[cvt->filter_index] (cvt, format);
  4794     }
  4795 }
  4796 
  4797 static void SDLCALL
  4798 SDL_Downsample_S16MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4799 {
  4800 #if DEBUG_CONVERT
  4801     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16MSB, 2 channels.\n", cvt->rate_incr);
  4802 #endif
  4803 
  4804     const int srcsize = cvt->len_cvt - 64;
  4805     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4806     register int eps = 0;
  4807     Sint16 *dst = (Sint16 *) cvt->buf;
  4808     const Sint16 *src = (Sint16 *) cvt->buf;
  4809     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
  4810     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  4811     Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
  4812     Sint16 last_sample0 = sample0;
  4813     Sint16 last_sample1 = sample1;
  4814     while (dst != target) {
  4815         src += 2;
  4816         eps += dstsize;
  4817         if ((eps << 1) >= srcsize) {
  4818             dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  4819             dst[1] = ((Sint16) SDL_SwapBE16(sample1));
  4820             dst += 2;
  4821             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4822             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  4823             last_sample0 = sample0;
  4824             last_sample1 = sample1;
  4825             eps -= srcsize;
  4826         }
  4827     }
  4828     cvt->len_cvt = dstsize;
  4829     if (cvt->filters[++cvt->filter_index]) {
  4830         cvt->filters[cvt->filter_index] (cvt, format);
  4831     }
  4832 }
  4833 
  4834 static void SDLCALL
  4835 SDL_Upsample_S16MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4836 {
  4837 #if DEBUG_CONVERT
  4838     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16MSB, 4 channels.\n", cvt->rate_incr);
  4839 #endif
  4840 
  4841     const int srcsize = cvt->len_cvt - 128;
  4842     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4843     register int eps = 0;
  4844     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 4;
  4845     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 4;
  4846     const Sint16 *target = ((const Sint16 *) cvt->buf) - 4;
  4847     Sint16 sample3 = ((Sint16) SDL_SwapBE16(src[3]));
  4848     Sint16 sample2 = ((Sint16) SDL_SwapBE16(src[2]));
  4849     Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
  4850     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  4851     Sint16 last_sample3 = sample3;
  4852     Sint16 last_sample2 = sample2;
  4853     Sint16 last_sample1 = sample1;
  4854     Sint16 last_sample0 = sample0;
  4855     while (dst != target) {
  4856         dst[3] = ((Sint16) SDL_SwapBE16(sample3));
  4857         dst[2] = ((Sint16) SDL_SwapBE16(sample2));
  4858         dst[1] = ((Sint16) SDL_SwapBE16(sample1));
  4859         dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  4860         dst -= 4;
  4861         eps += srcsize;
  4862         if ((eps << 1) >= dstsize) {
  4863             src -= 4;
  4864             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  4865             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  4866             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  4867             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4868             last_sample3 = sample3;
  4869             last_sample2 = sample2;
  4870             last_sample1 = sample1;
  4871             last_sample0 = sample0;
  4872             eps -= dstsize;
  4873         }
  4874     }
  4875     cvt->len_cvt = dstsize;
  4876     if (cvt->filters[++cvt->filter_index]) {
  4877         cvt->filters[cvt->filter_index] (cvt, format);
  4878     }
  4879 }
  4880 
  4881 static void SDLCALL
  4882 SDL_Downsample_S16MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4883 {
  4884 #if DEBUG_CONVERT
  4885     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16MSB, 4 channels.\n", cvt->rate_incr);
  4886 #endif
  4887 
  4888     const int srcsize = cvt->len_cvt - 128;
  4889     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4890     register int eps = 0;
  4891     Sint16 *dst = (Sint16 *) cvt->buf;
  4892     const Sint16 *src = (Sint16 *) cvt->buf;
  4893     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
  4894     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  4895     Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
  4896     Sint16 sample2 = ((Sint16) SDL_SwapBE16(src[2]));
  4897     Sint16 sample3 = ((Sint16) SDL_SwapBE16(src[3]));
  4898     Sint16 last_sample0 = sample0;
  4899     Sint16 last_sample1 = sample1;
  4900     Sint16 last_sample2 = sample2;
  4901     Sint16 last_sample3 = sample3;
  4902     while (dst != target) {
  4903         src += 4;
  4904         eps += dstsize;
  4905         if ((eps << 1) >= srcsize) {
  4906             dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  4907             dst[1] = ((Sint16) SDL_SwapBE16(sample1));
  4908             dst[2] = ((Sint16) SDL_SwapBE16(sample2));
  4909             dst[3] = ((Sint16) SDL_SwapBE16(sample3));
  4910             dst += 4;
  4911             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4912             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  4913             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  4914             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  4915             last_sample0 = sample0;
  4916             last_sample1 = sample1;
  4917             last_sample2 = sample2;
  4918             last_sample3 = sample3;
  4919             eps -= srcsize;
  4920         }
  4921     }
  4922     cvt->len_cvt = dstsize;
  4923     if (cvt->filters[++cvt->filter_index]) {
  4924         cvt->filters[cvt->filter_index] (cvt, format);
  4925     }
  4926 }
  4927 
  4928 static void SDLCALL
  4929 SDL_Upsample_S16MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4930 {
  4931 #if DEBUG_CONVERT
  4932     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16MSB, 6 channels.\n", cvt->rate_incr);
  4933 #endif
  4934 
  4935     const int srcsize = cvt->len_cvt - 192;
  4936     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4937     register int eps = 0;
  4938     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 6;
  4939     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 6;
  4940     const Sint16 *target = ((const Sint16 *) cvt->buf) - 6;
  4941     Sint16 sample5 = ((Sint16) SDL_SwapBE16(src[5]));
  4942     Sint16 sample4 = ((Sint16) SDL_SwapBE16(src[4]));
  4943     Sint16 sample3 = ((Sint16) SDL_SwapBE16(src[3]));
  4944     Sint16 sample2 = ((Sint16) SDL_SwapBE16(src[2]));
  4945     Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
  4946     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  4947     Sint16 last_sample5 = sample5;
  4948     Sint16 last_sample4 = sample4;
  4949     Sint16 last_sample3 = sample3;
  4950     Sint16 last_sample2 = sample2;
  4951     Sint16 last_sample1 = sample1;
  4952     Sint16 last_sample0 = sample0;
  4953     while (dst != target) {
  4954         dst[5] = ((Sint16) SDL_SwapBE16(sample5));
  4955         dst[4] = ((Sint16) SDL_SwapBE16(sample4));
  4956         dst[3] = ((Sint16) SDL_SwapBE16(sample3));
  4957         dst[2] = ((Sint16) SDL_SwapBE16(sample2));
  4958         dst[1] = ((Sint16) SDL_SwapBE16(sample1));
  4959         dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  4960         dst -= 6;
  4961         eps += srcsize;
  4962         if ((eps << 1) >= dstsize) {
  4963             src -= 6;
  4964             sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
  4965             sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
  4966             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  4967             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  4968             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  4969             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  4970             last_sample5 = sample5;
  4971             last_sample4 = sample4;
  4972             last_sample3 = sample3;
  4973             last_sample2 = sample2;
  4974             last_sample1 = sample1;
  4975             last_sample0 = sample0;
  4976             eps -= dstsize;
  4977         }
  4978     }
  4979     cvt->len_cvt = dstsize;
  4980     if (cvt->filters[++cvt->filter_index]) {
  4981         cvt->filters[cvt->filter_index] (cvt, format);
  4982     }
  4983 }
  4984 
  4985 static void SDLCALL
  4986 SDL_Downsample_S16MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  4987 {
  4988 #if DEBUG_CONVERT
  4989     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16MSB, 6 channels.\n", cvt->rate_incr);
  4990 #endif
  4991 
  4992     const int srcsize = cvt->len_cvt - 192;
  4993     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  4994     register int eps = 0;
  4995     Sint16 *dst = (Sint16 *) cvt->buf;
  4996     const Sint16 *src = (Sint16 *) cvt->buf;
  4997     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
  4998     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  4999     Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
  5000     Sint16 sample2 = ((Sint16) SDL_SwapBE16(src[2]));
  5001     Sint16 sample3 = ((Sint16) SDL_SwapBE16(src[3]));
  5002     Sint16 sample4 = ((Sint16) SDL_SwapBE16(src[4]));
  5003     Sint16 sample5 = ((Sint16) SDL_SwapBE16(src[5]));
  5004     Sint16 last_sample0 = sample0;
  5005     Sint16 last_sample1 = sample1;
  5006     Sint16 last_sample2 = sample2;
  5007     Sint16 last_sample3 = sample3;
  5008     Sint16 last_sample4 = sample4;
  5009     Sint16 last_sample5 = sample5;
  5010     while (dst != target) {
  5011         src += 6;
  5012         eps += dstsize;
  5013         if ((eps << 1) >= srcsize) {
  5014             dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  5015             dst[1] = ((Sint16) SDL_SwapBE16(sample1));
  5016             dst[2] = ((Sint16) SDL_SwapBE16(sample2));
  5017             dst[3] = ((Sint16) SDL_SwapBE16(sample3));
  5018             dst[4] = ((Sint16) SDL_SwapBE16(sample4));
  5019             dst[5] = ((Sint16) SDL_SwapBE16(sample5));
  5020             dst += 6;
  5021             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  5022             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  5023             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  5024             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  5025             sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
  5026             sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
  5027             last_sample0 = sample0;
  5028             last_sample1 = sample1;
  5029             last_sample2 = sample2;
  5030             last_sample3 = sample3;
  5031             last_sample4 = sample4;
  5032             last_sample5 = sample5;
  5033             eps -= srcsize;
  5034         }
  5035     }
  5036     cvt->len_cvt = dstsize;
  5037     if (cvt->filters[++cvt->filter_index]) {
  5038         cvt->filters[cvt->filter_index] (cvt, format);
  5039     }
  5040 }
  5041 
  5042 static void SDLCALL
  5043 SDL_Upsample_S16MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5044 {
  5045 #if DEBUG_CONVERT
  5046     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16MSB, 8 channels.\n", cvt->rate_incr);
  5047 #endif
  5048 
  5049     const int srcsize = cvt->len_cvt - 256;
  5050     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5051     register int eps = 0;
  5052     Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 8;
  5053     const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 8;
  5054     const Sint16 *target = ((const Sint16 *) cvt->buf) - 8;
  5055     Sint16 sample7 = ((Sint16) SDL_SwapBE16(src[7]));
  5056     Sint16 sample6 = ((Sint16) SDL_SwapBE16(src[6]));
  5057     Sint16 sample5 = ((Sint16) SDL_SwapBE16(src[5]));
  5058     Sint16 sample4 = ((Sint16) SDL_SwapBE16(src[4]));
  5059     Sint16 sample3 = ((Sint16) SDL_SwapBE16(src[3]));
  5060     Sint16 sample2 = ((Sint16) SDL_SwapBE16(src[2]));
  5061     Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
  5062     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  5063     Sint16 last_sample7 = sample7;
  5064     Sint16 last_sample6 = sample6;
  5065     Sint16 last_sample5 = sample5;
  5066     Sint16 last_sample4 = sample4;
  5067     Sint16 last_sample3 = sample3;
  5068     Sint16 last_sample2 = sample2;
  5069     Sint16 last_sample1 = sample1;
  5070     Sint16 last_sample0 = sample0;
  5071     while (dst != target) {
  5072         dst[7] = ((Sint16) SDL_SwapBE16(sample7));
  5073         dst[6] = ((Sint16) SDL_SwapBE16(sample6));
  5074         dst[5] = ((Sint16) SDL_SwapBE16(sample5));
  5075         dst[4] = ((Sint16) SDL_SwapBE16(sample4));
  5076         dst[3] = ((Sint16) SDL_SwapBE16(sample3));
  5077         dst[2] = ((Sint16) SDL_SwapBE16(sample2));
  5078         dst[1] = ((Sint16) SDL_SwapBE16(sample1));
  5079         dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  5080         dst -= 8;
  5081         eps += srcsize;
  5082         if ((eps << 1) >= dstsize) {
  5083             src -= 8;
  5084             sample7 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[7]))) + ((Sint32) last_sample7)) >> 1);
  5085             sample6 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[6]))) + ((Sint32) last_sample6)) >> 1);
  5086             sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
  5087             sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
  5088             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  5089             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  5090             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  5091             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  5092             last_sample7 = sample7;
  5093             last_sample6 = sample6;
  5094             last_sample5 = sample5;
  5095             last_sample4 = sample4;
  5096             last_sample3 = sample3;
  5097             last_sample2 = sample2;
  5098             last_sample1 = sample1;
  5099             last_sample0 = sample0;
  5100             eps -= dstsize;
  5101         }
  5102     }
  5103     cvt->len_cvt = dstsize;
  5104     if (cvt->filters[++cvt->filter_index]) {
  5105         cvt->filters[cvt->filter_index] (cvt, format);
  5106     }
  5107 }
  5108 
  5109 static void SDLCALL
  5110 SDL_Downsample_S16MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5111 {
  5112 #if DEBUG_CONVERT
  5113     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16MSB, 8 channels.\n", cvt->rate_incr);
  5114 #endif
  5115 
  5116     const int srcsize = cvt->len_cvt - 256;
  5117     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5118     register int eps = 0;
  5119     Sint16 *dst = (Sint16 *) cvt->buf;
  5120     const Sint16 *src = (Sint16 *) cvt->buf;
  5121     const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
  5122     Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
  5123     Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
  5124     Sint16 sample2 = ((Sint16) SDL_SwapBE16(src[2]));
  5125     Sint16 sample3 = ((Sint16) SDL_SwapBE16(src[3]));
  5126     Sint16 sample4 = ((Sint16) SDL_SwapBE16(src[4]));
  5127     Sint16 sample5 = ((Sint16) SDL_SwapBE16(src[5]));
  5128     Sint16 sample6 = ((Sint16) SDL_SwapBE16(src[6]));
  5129     Sint16 sample7 = ((Sint16) SDL_SwapBE16(src[7]));
  5130     Sint16 last_sample0 = sample0;
  5131     Sint16 last_sample1 = sample1;
  5132     Sint16 last_sample2 = sample2;
  5133     Sint16 last_sample3 = sample3;
  5134     Sint16 last_sample4 = sample4;
  5135     Sint16 last_sample5 = sample5;
  5136     Sint16 last_sample6 = sample6;
  5137     Sint16 last_sample7 = sample7;
  5138     while (dst != target) {
  5139         src += 8;
  5140         eps += dstsize;
  5141         if ((eps << 1) >= srcsize) {
  5142             dst[0] = ((Sint16) SDL_SwapBE16(sample0));
  5143             dst[1] = ((Sint16) SDL_SwapBE16(sample1));
  5144             dst[2] = ((Sint16) SDL_SwapBE16(sample2));
  5145             dst[3] = ((Sint16) SDL_SwapBE16(sample3));
  5146             dst[4] = ((Sint16) SDL_SwapBE16(sample4));
  5147             dst[5] = ((Sint16) SDL_SwapBE16(sample5));
  5148             dst[6] = ((Sint16) SDL_SwapBE16(sample6));
  5149             dst[7] = ((Sint16) SDL_SwapBE16(sample7));
  5150             dst += 8;
  5151             sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
  5152             sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
  5153             sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
  5154             sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
  5155             sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
  5156             sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
  5157             sample6 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[6]))) + ((Sint32) last_sample6)) >> 1);
  5158             sample7 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[7]))) + ((Sint32) last_sample7)) >> 1);
  5159             last_sample0 = sample0;
  5160             last_sample1 = sample1;
  5161             last_sample2 = sample2;
  5162             last_sample3 = sample3;
  5163             last_sample4 = sample4;
  5164             last_sample5 = sample5;
  5165             last_sample6 = sample6;
  5166             last_sample7 = sample7;
  5167             eps -= srcsize;
  5168         }
  5169     }
  5170     cvt->len_cvt = dstsize;
  5171     if (cvt->filters[++cvt->filter_index]) {
  5172         cvt->filters[cvt->filter_index] (cvt, format);
  5173     }
  5174 }
  5175 
  5176 static void SDLCALL
  5177 SDL_Upsample_S32LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5178 {
  5179 #if DEBUG_CONVERT
  5180     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32LSB, 1 channels.\n", cvt->rate_incr);
  5181 #endif
  5182 
  5183     const int srcsize = cvt->len_cvt - 64;
  5184     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5185     register int eps = 0;
  5186     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 1;
  5187     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 1;
  5188     const Sint32 *target = ((const Sint32 *) cvt->buf) - 1;
  5189     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5190     Sint32 last_sample0 = sample0;
  5191     while (dst != target) {
  5192         dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5193         dst--;
  5194         eps += srcsize;
  5195         if ((eps << 1) >= dstsize) {
  5196             src--;
  5197             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5198             last_sample0 = sample0;
  5199             eps -= dstsize;
  5200         }
  5201     }
  5202     cvt->len_cvt = dstsize;
  5203     if (cvt->filters[++cvt->filter_index]) {
  5204         cvt->filters[cvt->filter_index] (cvt, format);
  5205     }
  5206 }
  5207 
  5208 static void SDLCALL
  5209 SDL_Downsample_S32LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5210 {
  5211 #if DEBUG_CONVERT
  5212     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32LSB, 1 channels.\n", cvt->rate_incr);
  5213 #endif
  5214 
  5215     const int srcsize = cvt->len_cvt - 64;
  5216     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5217     register int eps = 0;
  5218     Sint32 *dst = (Sint32 *) cvt->buf;
  5219     const Sint32 *src = (Sint32 *) cvt->buf;
  5220     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  5221     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5222     Sint32 last_sample0 = sample0;
  5223     while (dst != target) {
  5224         src++;
  5225         eps += dstsize;
  5226         if ((eps << 1) >= srcsize) {
  5227             dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5228             dst++;
  5229             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5230             last_sample0 = sample0;
  5231             eps -= srcsize;
  5232         }
  5233     }
  5234     cvt->len_cvt = dstsize;
  5235     if (cvt->filters[++cvt->filter_index]) {
  5236         cvt->filters[cvt->filter_index] (cvt, format);
  5237     }
  5238 }
  5239 
  5240 static void SDLCALL
  5241 SDL_Upsample_S32LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5242 {
  5243 #if DEBUG_CONVERT
  5244     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32LSB, 2 channels.\n", cvt->rate_incr);
  5245 #endif
  5246 
  5247     const int srcsize = cvt->len_cvt - 128;
  5248     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5249     register int eps = 0;
  5250     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 2;
  5251     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 2;
  5252     const Sint32 *target = ((const Sint32 *) cvt->buf) - 2;
  5253     Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
  5254     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5255     Sint32 last_sample1 = sample1;
  5256     Sint32 last_sample0 = sample0;
  5257     while (dst != target) {
  5258         dst[1] = ((Sint32) SDL_SwapLE32(sample1));
  5259         dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5260         dst -= 2;
  5261         eps += srcsize;
  5262         if ((eps << 1) >= dstsize) {
  5263             src -= 2;
  5264             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5265             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5266             last_sample1 = sample1;
  5267             last_sample0 = sample0;
  5268             eps -= dstsize;
  5269         }
  5270     }
  5271     cvt->len_cvt = dstsize;
  5272     if (cvt->filters[++cvt->filter_index]) {
  5273         cvt->filters[cvt->filter_index] (cvt, format);
  5274     }
  5275 }
  5276 
  5277 static void SDLCALL
  5278 SDL_Downsample_S32LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5279 {
  5280 #if DEBUG_CONVERT
  5281     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32LSB, 2 channels.\n", cvt->rate_incr);
  5282 #endif
  5283 
  5284     const int srcsize = cvt->len_cvt - 128;
  5285     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5286     register int eps = 0;
  5287     Sint32 *dst = (Sint32 *) cvt->buf;
  5288     const Sint32 *src = (Sint32 *) cvt->buf;
  5289     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  5290     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5291     Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
  5292     Sint32 last_sample0 = sample0;
  5293     Sint32 last_sample1 = sample1;
  5294     while (dst != target) {
  5295         src += 2;
  5296         eps += dstsize;
  5297         if ((eps << 1) >= srcsize) {
  5298             dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5299             dst[1] = ((Sint32) SDL_SwapLE32(sample1));
  5300             dst += 2;
  5301             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5302             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5303             last_sample0 = sample0;
  5304             last_sample1 = sample1;
  5305             eps -= srcsize;
  5306         }
  5307     }
  5308     cvt->len_cvt = dstsize;
  5309     if (cvt->filters[++cvt->filter_index]) {
  5310         cvt->filters[cvt->filter_index] (cvt, format);
  5311     }
  5312 }
  5313 
  5314 static void SDLCALL
  5315 SDL_Upsample_S32LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5316 {
  5317 #if DEBUG_CONVERT
  5318     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32LSB, 4 channels.\n", cvt->rate_incr);
  5319 #endif
  5320 
  5321     const int srcsize = cvt->len_cvt - 256;
  5322     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5323     register int eps = 0;
  5324     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 4;
  5325     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 4;
  5326     const Sint32 *target = ((const Sint32 *) cvt->buf) - 4;
  5327     Sint32 sample3 = ((Sint32) SDL_SwapLE32(src[3]));
  5328     Sint32 sample2 = ((Sint32) SDL_SwapLE32(src[2]));
  5329     Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
  5330     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5331     Sint32 last_sample3 = sample3;
  5332     Sint32 last_sample2 = sample2;
  5333     Sint32 last_sample1 = sample1;
  5334     Sint32 last_sample0 = sample0;
  5335     while (dst != target) {
  5336         dst[3] = ((Sint32) SDL_SwapLE32(sample3));
  5337         dst[2] = ((Sint32) SDL_SwapLE32(sample2));
  5338         dst[1] = ((Sint32) SDL_SwapLE32(sample1));
  5339         dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5340         dst -= 4;
  5341         eps += srcsize;
  5342         if ((eps << 1) >= dstsize) {
  5343             src -= 4;
  5344             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5345             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5346             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5347             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5348             last_sample3 = sample3;
  5349             last_sample2 = sample2;
  5350             last_sample1 = sample1;
  5351             last_sample0 = sample0;
  5352             eps -= dstsize;
  5353         }
  5354     }
  5355     cvt->len_cvt = dstsize;
  5356     if (cvt->filters[++cvt->filter_index]) {
  5357         cvt->filters[cvt->filter_index] (cvt, format);
  5358     }
  5359 }
  5360 
  5361 static void SDLCALL
  5362 SDL_Downsample_S32LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5363 {
  5364 #if DEBUG_CONVERT
  5365     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32LSB, 4 channels.\n", cvt->rate_incr);
  5366 #endif
  5367 
  5368     const int srcsize = cvt->len_cvt - 256;
  5369     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5370     register int eps = 0;
  5371     Sint32 *dst = (Sint32 *) cvt->buf;
  5372     const Sint32 *src = (Sint32 *) cvt->buf;
  5373     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  5374     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5375     Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
  5376     Sint32 sample2 = ((Sint32) SDL_SwapLE32(src[2]));
  5377     Sint32 sample3 = ((Sint32) SDL_SwapLE32(src[3]));
  5378     Sint32 last_sample0 = sample0;
  5379     Sint32 last_sample1 = sample1;
  5380     Sint32 last_sample2 = sample2;
  5381     Sint32 last_sample3 = sample3;
  5382     while (dst != target) {
  5383         src += 4;
  5384         eps += dstsize;
  5385         if ((eps << 1) >= srcsize) {
  5386             dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5387             dst[1] = ((Sint32) SDL_SwapLE32(sample1));
  5388             dst[2] = ((Sint32) SDL_SwapLE32(sample2));
  5389             dst[3] = ((Sint32) SDL_SwapLE32(sample3));
  5390             dst += 4;
  5391             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5392             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5393             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5394             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5395             last_sample0 = sample0;
  5396             last_sample1 = sample1;
  5397             last_sample2 = sample2;
  5398             last_sample3 = sample3;
  5399             eps -= srcsize;
  5400         }
  5401     }
  5402     cvt->len_cvt = dstsize;
  5403     if (cvt->filters[++cvt->filter_index]) {
  5404         cvt->filters[cvt->filter_index] (cvt, format);
  5405     }
  5406 }
  5407 
  5408 static void SDLCALL
  5409 SDL_Upsample_S32LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5410 {
  5411 #if DEBUG_CONVERT
  5412     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32LSB, 6 channels.\n", cvt->rate_incr);
  5413 #endif
  5414 
  5415     const int srcsize = cvt->len_cvt - 384;
  5416     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5417     register int eps = 0;
  5418     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 6;
  5419     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 6;
  5420     const Sint32 *target = ((const Sint32 *) cvt->buf) - 6;
  5421     Sint32 sample5 = ((Sint32) SDL_SwapLE32(src[5]));
  5422     Sint32 sample4 = ((Sint32) SDL_SwapLE32(src[4]));
  5423     Sint32 sample3 = ((Sint32) SDL_SwapLE32(src[3]));
  5424     Sint32 sample2 = ((Sint32) SDL_SwapLE32(src[2]));
  5425     Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
  5426     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5427     Sint32 last_sample5 = sample5;
  5428     Sint32 last_sample4 = sample4;
  5429     Sint32 last_sample3 = sample3;
  5430     Sint32 last_sample2 = sample2;
  5431     Sint32 last_sample1 = sample1;
  5432     Sint32 last_sample0 = sample0;
  5433     while (dst != target) {
  5434         dst[5] = ((Sint32) SDL_SwapLE32(sample5));
  5435         dst[4] = ((Sint32) SDL_SwapLE32(sample4));
  5436         dst[3] = ((Sint32) SDL_SwapLE32(sample3));
  5437         dst[2] = ((Sint32) SDL_SwapLE32(sample2));
  5438         dst[1] = ((Sint32) SDL_SwapLE32(sample1));
  5439         dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5440         dst -= 6;
  5441         eps += srcsize;
  5442         if ((eps << 1) >= dstsize) {
  5443             src -= 6;
  5444             sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
  5445             sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
  5446             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5447             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5448             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5449             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5450             last_sample5 = sample5;
  5451             last_sample4 = sample4;
  5452             last_sample3 = sample3;
  5453             last_sample2 = sample2;
  5454             last_sample1 = sample1;
  5455             last_sample0 = sample0;
  5456             eps -= dstsize;
  5457         }
  5458     }
  5459     cvt->len_cvt = dstsize;
  5460     if (cvt->filters[++cvt->filter_index]) {
  5461         cvt->filters[cvt->filter_index] (cvt, format);
  5462     }
  5463 }
  5464 
  5465 static void SDLCALL
  5466 SDL_Downsample_S32LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5467 {
  5468 #if DEBUG_CONVERT
  5469     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32LSB, 6 channels.\n", cvt->rate_incr);
  5470 #endif
  5471 
  5472     const int srcsize = cvt->len_cvt - 384;
  5473     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5474     register int eps = 0;
  5475     Sint32 *dst = (Sint32 *) cvt->buf;
  5476     const Sint32 *src = (Sint32 *) cvt->buf;
  5477     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  5478     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5479     Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
  5480     Sint32 sample2 = ((Sint32) SDL_SwapLE32(src[2]));
  5481     Sint32 sample3 = ((Sint32) SDL_SwapLE32(src[3]));
  5482     Sint32 sample4 = ((Sint32) SDL_SwapLE32(src[4]));
  5483     Sint32 sample5 = ((Sint32) SDL_SwapLE32(src[5]));
  5484     Sint32 last_sample0 = sample0;
  5485     Sint32 last_sample1 = sample1;
  5486     Sint32 last_sample2 = sample2;
  5487     Sint32 last_sample3 = sample3;
  5488     Sint32 last_sample4 = sample4;
  5489     Sint32 last_sample5 = sample5;
  5490     while (dst != target) {
  5491         src += 6;
  5492         eps += dstsize;
  5493         if ((eps << 1) >= srcsize) {
  5494             dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5495             dst[1] = ((Sint32) SDL_SwapLE32(sample1));
  5496             dst[2] = ((Sint32) SDL_SwapLE32(sample2));
  5497             dst[3] = ((Sint32) SDL_SwapLE32(sample3));
  5498             dst[4] = ((Sint32) SDL_SwapLE32(sample4));
  5499             dst[5] = ((Sint32) SDL_SwapLE32(sample5));
  5500             dst += 6;
  5501             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5502             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5503             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5504             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5505             sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
  5506             sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
  5507             last_sample0 = sample0;
  5508             last_sample1 = sample1;
  5509             last_sample2 = sample2;
  5510             last_sample3 = sample3;
  5511             last_sample4 = sample4;
  5512             last_sample5 = sample5;
  5513             eps -= srcsize;
  5514         }
  5515     }
  5516     cvt->len_cvt = dstsize;
  5517     if (cvt->filters[++cvt->filter_index]) {
  5518         cvt->filters[cvt->filter_index] (cvt, format);
  5519     }
  5520 }
  5521 
  5522 static void SDLCALL
  5523 SDL_Upsample_S32LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5524 {
  5525 #if DEBUG_CONVERT
  5526     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32LSB, 8 channels.\n", cvt->rate_incr);
  5527 #endif
  5528 
  5529     const int srcsize = cvt->len_cvt - 512;
  5530     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5531     register int eps = 0;
  5532     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 8;
  5533     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 8;
  5534     const Sint32 *target = ((const Sint32 *) cvt->buf) - 8;
  5535     Sint32 sample7 = ((Sint32) SDL_SwapLE32(src[7]));
  5536     Sint32 sample6 = ((Sint32) SDL_SwapLE32(src[6]));
  5537     Sint32 sample5 = ((Sint32) SDL_SwapLE32(src[5]));
  5538     Sint32 sample4 = ((Sint32) SDL_SwapLE32(src[4]));
  5539     Sint32 sample3 = ((Sint32) SDL_SwapLE32(src[3]));
  5540     Sint32 sample2 = ((Sint32) SDL_SwapLE32(src[2]));
  5541     Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
  5542     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5543     Sint32 last_sample7 = sample7;
  5544     Sint32 last_sample6 = sample6;
  5545     Sint32 last_sample5 = sample5;
  5546     Sint32 last_sample4 = sample4;
  5547     Sint32 last_sample3 = sample3;
  5548     Sint32 last_sample2 = sample2;
  5549     Sint32 last_sample1 = sample1;
  5550     Sint32 last_sample0 = sample0;
  5551     while (dst != target) {
  5552         dst[7] = ((Sint32) SDL_SwapLE32(sample7));
  5553         dst[6] = ((Sint32) SDL_SwapLE32(sample6));
  5554         dst[5] = ((Sint32) SDL_SwapLE32(sample5));
  5555         dst[4] = ((Sint32) SDL_SwapLE32(sample4));
  5556         dst[3] = ((Sint32) SDL_SwapLE32(sample3));
  5557         dst[2] = ((Sint32) SDL_SwapLE32(sample2));
  5558         dst[1] = ((Sint32) SDL_SwapLE32(sample1));
  5559         dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5560         dst -= 8;
  5561         eps += srcsize;
  5562         if ((eps << 1) >= dstsize) {
  5563             src -= 8;
  5564             sample7 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[7]))) + ((Sint64) last_sample7)) >> 1);
  5565             sample6 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[6]))) + ((Sint64) last_sample6)) >> 1);
  5566             sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
  5567             sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
  5568             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5569             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5570             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5571             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5572             last_sample7 = sample7;
  5573             last_sample6 = sample6;
  5574             last_sample5 = sample5;
  5575             last_sample4 = sample4;
  5576             last_sample3 = sample3;
  5577             last_sample2 = sample2;
  5578             last_sample1 = sample1;
  5579             last_sample0 = sample0;
  5580             eps -= dstsize;
  5581         }
  5582     }
  5583     cvt->len_cvt = dstsize;
  5584     if (cvt->filters[++cvt->filter_index]) {
  5585         cvt->filters[cvt->filter_index] (cvt, format);
  5586     }
  5587 }
  5588 
  5589 static void SDLCALL
  5590 SDL_Downsample_S32LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5591 {
  5592 #if DEBUG_CONVERT
  5593     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32LSB, 8 channels.\n", cvt->rate_incr);
  5594 #endif
  5595 
  5596     const int srcsize = cvt->len_cvt - 512;
  5597     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5598     register int eps = 0;
  5599     Sint32 *dst = (Sint32 *) cvt->buf;
  5600     const Sint32 *src = (Sint32 *) cvt->buf;
  5601     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  5602     Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
  5603     Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
  5604     Sint32 sample2 = ((Sint32) SDL_SwapLE32(src[2]));
  5605     Sint32 sample3 = ((Sint32) SDL_SwapLE32(src[3]));
  5606     Sint32 sample4 = ((Sint32) SDL_SwapLE32(src[4]));
  5607     Sint32 sample5 = ((Sint32) SDL_SwapLE32(src[5]));
  5608     Sint32 sample6 = ((Sint32) SDL_SwapLE32(src[6]));
  5609     Sint32 sample7 = ((Sint32) SDL_SwapLE32(src[7]));
  5610     Sint32 last_sample0 = sample0;
  5611     Sint32 last_sample1 = sample1;
  5612     Sint32 last_sample2 = sample2;
  5613     Sint32 last_sample3 = sample3;
  5614     Sint32 last_sample4 = sample4;
  5615     Sint32 last_sample5 = sample5;
  5616     Sint32 last_sample6 = sample6;
  5617     Sint32 last_sample7 = sample7;
  5618     while (dst != target) {
  5619         src += 8;
  5620         eps += dstsize;
  5621         if ((eps << 1) >= srcsize) {
  5622             dst[0] = ((Sint32) SDL_SwapLE32(sample0));
  5623             dst[1] = ((Sint32) SDL_SwapLE32(sample1));
  5624             dst[2] = ((Sint32) SDL_SwapLE32(sample2));
  5625             dst[3] = ((Sint32) SDL_SwapLE32(sample3));
  5626             dst[4] = ((Sint32) SDL_SwapLE32(sample4));
  5627             dst[5] = ((Sint32) SDL_SwapLE32(sample5));
  5628             dst[6] = ((Sint32) SDL_SwapLE32(sample6));
  5629             dst[7] = ((Sint32) SDL_SwapLE32(sample7));
  5630             dst += 8;
  5631             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5632             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5633             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5634             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5635             sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
  5636             sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
  5637             sample6 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[6]))) + ((Sint64) last_sample6)) >> 1);
  5638             sample7 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[7]))) + ((Sint64) last_sample7)) >> 1);
  5639             last_sample0 = sample0;
  5640             last_sample1 = sample1;
  5641             last_sample2 = sample2;
  5642             last_sample3 = sample3;
  5643             last_sample4 = sample4;
  5644             last_sample5 = sample5;
  5645             last_sample6 = sample6;
  5646             last_sample7 = sample7;
  5647             eps -= srcsize;
  5648         }
  5649     }
  5650     cvt->len_cvt = dstsize;
  5651     if (cvt->filters[++cvt->filter_index]) {
  5652         cvt->filters[cvt->filter_index] (cvt, format);
  5653     }
  5654 }
  5655 
  5656 static void SDLCALL
  5657 SDL_Upsample_S32MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5658 {
  5659 #if DEBUG_CONVERT
  5660     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32MSB, 1 channels.\n", cvt->rate_incr);
  5661 #endif
  5662 
  5663     const int srcsize = cvt->len_cvt - 64;
  5664     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5665     register int eps = 0;
  5666     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 1;
  5667     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 1;
  5668     const Sint32 *target = ((const Sint32 *) cvt->buf) - 1;
  5669     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  5670     Sint32 last_sample0 = sample0;
  5671     while (dst != target) {
  5672         dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  5673         dst--;
  5674         eps += srcsize;
  5675         if ((eps << 1) >= dstsize) {
  5676             src--;
  5677             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5678             last_sample0 = sample0;
  5679             eps -= dstsize;
  5680         }
  5681     }
  5682     cvt->len_cvt = dstsize;
  5683     if (cvt->filters[++cvt->filter_index]) {
  5684         cvt->filters[cvt->filter_index] (cvt, format);
  5685     }
  5686 }
  5687 
  5688 static void SDLCALL
  5689 SDL_Downsample_S32MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5690 {
  5691 #if DEBUG_CONVERT
  5692     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32MSB, 1 channels.\n", cvt->rate_incr);
  5693 #endif
  5694 
  5695     const int srcsize = cvt->len_cvt - 64;
  5696     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5697     register int eps = 0;
  5698     Sint32 *dst = (Sint32 *) cvt->buf;
  5699     const Sint32 *src = (Sint32 *) cvt->buf;
  5700     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  5701     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  5702     Sint32 last_sample0 = sample0;
  5703     while (dst != target) {
  5704         src++;
  5705         eps += dstsize;
  5706         if ((eps << 1) >= srcsize) {
  5707             dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  5708             dst++;
  5709             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5710             last_sample0 = sample0;
  5711             eps -= srcsize;
  5712         }
  5713     }
  5714     cvt->len_cvt = dstsize;
  5715     if (cvt->filters[++cvt->filter_index]) {
  5716         cvt->filters[cvt->filter_index] (cvt, format);
  5717     }
  5718 }
  5719 
  5720 static void SDLCALL
  5721 SDL_Upsample_S32MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5722 {
  5723 #if DEBUG_CONVERT
  5724     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32MSB, 2 channels.\n", cvt->rate_incr);
  5725 #endif
  5726 
  5727     const int srcsize = cvt->len_cvt - 128;
  5728     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5729     register int eps = 0;
  5730     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 2;
  5731     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 2;
  5732     const Sint32 *target = ((const Sint32 *) cvt->buf) - 2;
  5733     Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
  5734     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  5735     Sint32 last_sample1 = sample1;
  5736     Sint32 last_sample0 = sample0;
  5737     while (dst != target) {
  5738         dst[1] = ((Sint32) SDL_SwapBE32(sample1));
  5739         dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  5740         dst -= 2;
  5741         eps += srcsize;
  5742         if ((eps << 1) >= dstsize) {
  5743             src -= 2;
  5744             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5745             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5746             last_sample1 = sample1;
  5747             last_sample0 = sample0;
  5748             eps -= dstsize;
  5749         }
  5750     }
  5751     cvt->len_cvt = dstsize;
  5752     if (cvt->filters[++cvt->filter_index]) {
  5753         cvt->filters[cvt->filter_index] (cvt, format);
  5754     }
  5755 }
  5756 
  5757 static void SDLCALL
  5758 SDL_Downsample_S32MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5759 {
  5760 #if DEBUG_CONVERT
  5761     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32MSB, 2 channels.\n", cvt->rate_incr);
  5762 #endif
  5763 
  5764     const int srcsize = cvt->len_cvt - 128;
  5765     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5766     register int eps = 0;
  5767     Sint32 *dst = (Sint32 *) cvt->buf;
  5768     const Sint32 *src = (Sint32 *) cvt->buf;
  5769     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  5770     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  5771     Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
  5772     Sint32 last_sample0 = sample0;
  5773     Sint32 last_sample1 = sample1;
  5774     while (dst != target) {
  5775         src += 2;
  5776         eps += dstsize;
  5777         if ((eps << 1) >= srcsize) {
  5778             dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  5779             dst[1] = ((Sint32) SDL_SwapBE32(sample1));
  5780             dst += 2;
  5781             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5782             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5783             last_sample0 = sample0;
  5784             last_sample1 = sample1;
  5785             eps -= srcsize;
  5786         }
  5787     }
  5788     cvt->len_cvt = dstsize;
  5789     if (cvt->filters[++cvt->filter_index]) {
  5790         cvt->filters[cvt->filter_index] (cvt, format);
  5791     }
  5792 }
  5793 
  5794 static void SDLCALL
  5795 SDL_Upsample_S32MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5796 {
  5797 #if DEBUG_CONVERT
  5798     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32MSB, 4 channels.\n", cvt->rate_incr);
  5799 #endif
  5800 
  5801     const int srcsize = cvt->len_cvt - 256;
  5802     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5803     register int eps = 0;
  5804     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 4;
  5805     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 4;
  5806     const Sint32 *target = ((const Sint32 *) cvt->buf) - 4;
  5807     Sint32 sample3 = ((Sint32) SDL_SwapBE32(src[3]));
  5808     Sint32 sample2 = ((Sint32) SDL_SwapBE32(src[2]));
  5809     Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
  5810     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  5811     Sint32 last_sample3 = sample3;
  5812     Sint32 last_sample2 = sample2;
  5813     Sint32 last_sample1 = sample1;
  5814     Sint32 last_sample0 = sample0;
  5815     while (dst != target) {
  5816         dst[3] = ((Sint32) SDL_SwapBE32(sample3));
  5817         dst[2] = ((Sint32) SDL_SwapBE32(sample2));
  5818         dst[1] = ((Sint32) SDL_SwapBE32(sample1));
  5819         dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  5820         dst -= 4;
  5821         eps += srcsize;
  5822         if ((eps << 1) >= dstsize) {
  5823             src -= 4;
  5824             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5825             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5826             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5827             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5828             last_sample3 = sample3;
  5829             last_sample2 = sample2;
  5830             last_sample1 = sample1;
  5831             last_sample0 = sample0;
  5832             eps -= dstsize;
  5833         }
  5834     }
  5835     cvt->len_cvt = dstsize;
  5836     if (cvt->filters[++cvt->filter_index]) {
  5837         cvt->filters[cvt->filter_index] (cvt, format);
  5838     }
  5839 }
  5840 
  5841 static void SDLCALL
  5842 SDL_Downsample_S32MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5843 {
  5844 #if DEBUG_CONVERT
  5845     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32MSB, 4 channels.\n", cvt->rate_incr);
  5846 #endif
  5847 
  5848     const int srcsize = cvt->len_cvt - 256;
  5849     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5850     register int eps = 0;
  5851     Sint32 *dst = (Sint32 *) cvt->buf;
  5852     const Sint32 *src = (Sint32 *) cvt->buf;
  5853     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  5854     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  5855     Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
  5856     Sint32 sample2 = ((Sint32) SDL_SwapBE32(src[2]));
  5857     Sint32 sample3 = ((Sint32) SDL_SwapBE32(src[3]));
  5858     Sint32 last_sample0 = sample0;
  5859     Sint32 last_sample1 = sample1;
  5860     Sint32 last_sample2 = sample2;
  5861     Sint32 last_sample3 = sample3;
  5862     while (dst != target) {
  5863         src += 4;
  5864         eps += dstsize;
  5865         if ((eps << 1) >= srcsize) {
  5866             dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  5867             dst[1] = ((Sint32) SDL_SwapBE32(sample1));
  5868             dst[2] = ((Sint32) SDL_SwapBE32(sample2));
  5869             dst[3] = ((Sint32) SDL_SwapBE32(sample3));
  5870             dst += 4;
  5871             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5872             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5873             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5874             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5875             last_sample0 = sample0;
  5876             last_sample1 = sample1;
  5877             last_sample2 = sample2;
  5878             last_sample3 = sample3;
  5879             eps -= srcsize;
  5880         }
  5881     }
  5882     cvt->len_cvt = dstsize;
  5883     if (cvt->filters[++cvt->filter_index]) {
  5884         cvt->filters[cvt->filter_index] (cvt, format);
  5885     }
  5886 }
  5887 
  5888 static void SDLCALL
  5889 SDL_Upsample_S32MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5890 {
  5891 #if DEBUG_CONVERT
  5892     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32MSB, 6 channels.\n", cvt->rate_incr);
  5893 #endif
  5894 
  5895     const int srcsize = cvt->len_cvt - 384;
  5896     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5897     register int eps = 0;
  5898     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 6;
  5899     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 6;
  5900     const Sint32 *target = ((const Sint32 *) cvt->buf) - 6;
  5901     Sint32 sample5 = ((Sint32) SDL_SwapBE32(src[5]));
  5902     Sint32 sample4 = ((Sint32) SDL_SwapBE32(src[4]));
  5903     Sint32 sample3 = ((Sint32) SDL_SwapBE32(src[3]));
  5904     Sint32 sample2 = ((Sint32) SDL_SwapBE32(src[2]));
  5905     Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
  5906     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  5907     Sint32 last_sample5 = sample5;
  5908     Sint32 last_sample4 = sample4;
  5909     Sint32 last_sample3 = sample3;
  5910     Sint32 last_sample2 = sample2;
  5911     Sint32 last_sample1 = sample1;
  5912     Sint32 last_sample0 = sample0;
  5913     while (dst != target) {
  5914         dst[5] = ((Sint32) SDL_SwapBE32(sample5));
  5915         dst[4] = ((Sint32) SDL_SwapBE32(sample4));
  5916         dst[3] = ((Sint32) SDL_SwapBE32(sample3));
  5917         dst[2] = ((Sint32) SDL_SwapBE32(sample2));
  5918         dst[1] = ((Sint32) SDL_SwapBE32(sample1));
  5919         dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  5920         dst -= 6;
  5921         eps += srcsize;
  5922         if ((eps << 1) >= dstsize) {
  5923             src -= 6;
  5924             sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
  5925             sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
  5926             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5927             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5928             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5929             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5930             last_sample5 = sample5;
  5931             last_sample4 = sample4;
  5932             last_sample3 = sample3;
  5933             last_sample2 = sample2;
  5934             last_sample1 = sample1;
  5935             last_sample0 = sample0;
  5936             eps -= dstsize;
  5937         }
  5938     }
  5939     cvt->len_cvt = dstsize;
  5940     if (cvt->filters[++cvt->filter_index]) {
  5941         cvt->filters[cvt->filter_index] (cvt, format);
  5942     }
  5943 }
  5944 
  5945 static void SDLCALL
  5946 SDL_Downsample_S32MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  5947 {
  5948 #if DEBUG_CONVERT
  5949     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32MSB, 6 channels.\n", cvt->rate_incr);
  5950 #endif
  5951 
  5952     const int srcsize = cvt->len_cvt - 384;
  5953     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  5954     register int eps = 0;
  5955     Sint32 *dst = (Sint32 *) cvt->buf;
  5956     const Sint32 *src = (Sint32 *) cvt->buf;
  5957     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  5958     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  5959     Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
  5960     Sint32 sample2 = ((Sint32) SDL_SwapBE32(src[2]));
  5961     Sint32 sample3 = ((Sint32) SDL_SwapBE32(src[3]));
  5962     Sint32 sample4 = ((Sint32) SDL_SwapBE32(src[4]));
  5963     Sint32 sample5 = ((Sint32) SDL_SwapBE32(src[5]));
  5964     Sint32 last_sample0 = sample0;
  5965     Sint32 last_sample1 = sample1;
  5966     Sint32 last_sample2 = sample2;
  5967     Sint32 last_sample3 = sample3;
  5968     Sint32 last_sample4 = sample4;
  5969     Sint32 last_sample5 = sample5;
  5970     while (dst != target) {
  5971         src += 6;
  5972         eps += dstsize;
  5973         if ((eps << 1) >= srcsize) {
  5974             dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  5975             dst[1] = ((Sint32) SDL_SwapBE32(sample1));
  5976             dst[2] = ((Sint32) SDL_SwapBE32(sample2));
  5977             dst[3] = ((Sint32) SDL_SwapBE32(sample3));
  5978             dst[4] = ((Sint32) SDL_SwapBE32(sample4));
  5979             dst[5] = ((Sint32) SDL_SwapBE32(sample5));
  5980             dst += 6;
  5981             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  5982             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  5983             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  5984             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  5985             sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
  5986             sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
  5987             last_sample0 = sample0;
  5988             last_sample1 = sample1;
  5989             last_sample2 = sample2;
  5990             last_sample3 = sample3;
  5991             last_sample4 = sample4;
  5992             last_sample5 = sample5;
  5993             eps -= srcsize;
  5994         }
  5995     }
  5996     cvt->len_cvt = dstsize;
  5997     if (cvt->filters[++cvt->filter_index]) {
  5998         cvt->filters[cvt->filter_index] (cvt, format);
  5999     }
  6000 }
  6001 
  6002 static void SDLCALL
  6003 SDL_Upsample_S32MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6004 {
  6005 #if DEBUG_CONVERT
  6006     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32MSB, 8 channels.\n", cvt->rate_incr);
  6007 #endif
  6008 
  6009     const int srcsize = cvt->len_cvt - 512;
  6010     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  6011     register int eps = 0;
  6012     Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 8;
  6013     const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 8;
  6014     const Sint32 *target = ((const Sint32 *) cvt->buf) - 8;
  6015     Sint32 sample7 = ((Sint32) SDL_SwapBE32(src[7]));
  6016     Sint32 sample6 = ((Sint32) SDL_SwapBE32(src[6]));
  6017     Sint32 sample5 = ((Sint32) SDL_SwapBE32(src[5]));
  6018     Sint32 sample4 = ((Sint32) SDL_SwapBE32(src[4]));
  6019     Sint32 sample3 = ((Sint32) SDL_SwapBE32(src[3]));
  6020     Sint32 sample2 = ((Sint32) SDL_SwapBE32(src[2]));
  6021     Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
  6022     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  6023     Sint32 last_sample7 = sample7;
  6024     Sint32 last_sample6 = sample6;
  6025     Sint32 last_sample5 = sample5;
  6026     Sint32 last_sample4 = sample4;
  6027     Sint32 last_sample3 = sample3;
  6028     Sint32 last_sample2 = sample2;
  6029     Sint32 last_sample1 = sample1;
  6030     Sint32 last_sample0 = sample0;
  6031     while (dst != target) {
  6032         dst[7] = ((Sint32) SDL_SwapBE32(sample7));
  6033         dst[6] = ((Sint32) SDL_SwapBE32(sample6));
  6034         dst[5] = ((Sint32) SDL_SwapBE32(sample5));
  6035         dst[4] = ((Sint32) SDL_SwapBE32(sample4));
  6036         dst[3] = ((Sint32) SDL_SwapBE32(sample3));
  6037         dst[2] = ((Sint32) SDL_SwapBE32(sample2));
  6038         dst[1] = ((Sint32) SDL_SwapBE32(sample1));
  6039         dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  6040         dst -= 8;
  6041         eps += srcsize;
  6042         if ((eps << 1) >= dstsize) {
  6043             src -= 8;
  6044             sample7 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[7]))) + ((Sint64) last_sample7)) >> 1);
  6045             sample6 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[6]))) + ((Sint64) last_sample6)) >> 1);
  6046             sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
  6047             sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
  6048             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  6049             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  6050             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  6051             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  6052             last_sample7 = sample7;
  6053             last_sample6 = sample6;
  6054             last_sample5 = sample5;
  6055             last_sample4 = sample4;
  6056             last_sample3 = sample3;
  6057             last_sample2 = sample2;
  6058             last_sample1 = sample1;
  6059             last_sample0 = sample0;
  6060             eps -= dstsize;
  6061         }
  6062     }
  6063     cvt->len_cvt = dstsize;
  6064     if (cvt->filters[++cvt->filter_index]) {
  6065         cvt->filters[cvt->filter_index] (cvt, format);
  6066     }
  6067 }
  6068 
  6069 static void SDLCALL
  6070 SDL_Downsample_S32MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6071 {
  6072 #if DEBUG_CONVERT
  6073     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32MSB, 8 channels.\n", cvt->rate_incr);
  6074 #endif
  6075 
  6076     const int srcsize = cvt->len_cvt - 512;
  6077     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  6078     register int eps = 0;
  6079     Sint32 *dst = (Sint32 *) cvt->buf;
  6080     const Sint32 *src = (Sint32 *) cvt->buf;
  6081     const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
  6082     Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
  6083     Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
  6084     Sint32 sample2 = ((Sint32) SDL_SwapBE32(src[2]));
  6085     Sint32 sample3 = ((Sint32) SDL_SwapBE32(src[3]));
  6086     Sint32 sample4 = ((Sint32) SDL_SwapBE32(src[4]));
  6087     Sint32 sample5 = ((Sint32) SDL_SwapBE32(src[5]));
  6088     Sint32 sample6 = ((Sint32) SDL_SwapBE32(src[6]));
  6089     Sint32 sample7 = ((Sint32) SDL_SwapBE32(src[7]));
  6090     Sint32 last_sample0 = sample0;
  6091     Sint32 last_sample1 = sample1;
  6092     Sint32 last_sample2 = sample2;
  6093     Sint32 last_sample3 = sample3;
  6094     Sint32 last_sample4 = sample4;
  6095     Sint32 last_sample5 = sample5;
  6096     Sint32 last_sample6 = sample6;
  6097     Sint32 last_sample7 = sample7;
  6098     while (dst != target) {
  6099         src += 8;
  6100         eps += dstsize;
  6101         if ((eps << 1) >= srcsize) {
  6102             dst[0] = ((Sint32) SDL_SwapBE32(sample0));
  6103             dst[1] = ((Sint32) SDL_SwapBE32(sample1));
  6104             dst[2] = ((Sint32) SDL_SwapBE32(sample2));
  6105             dst[3] = ((Sint32) SDL_SwapBE32(sample3));
  6106             dst[4] = ((Sint32) SDL_SwapBE32(sample4));
  6107             dst[5] = ((Sint32) SDL_SwapBE32(sample5));
  6108             dst[6] = ((Sint32) SDL_SwapBE32(sample6));
  6109             dst[7] = ((Sint32) SDL_SwapBE32(sample7));
  6110             dst += 8;
  6111             sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
  6112             sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
  6113             sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
  6114             sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
  6115             sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
  6116             sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
  6117             sample6 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[6]))) + ((Sint64) last_sample6)) >> 1);
  6118             sample7 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[7]))) + ((Sint64) last_sample7)) >> 1);
  6119             last_sample0 = sample0;
  6120             last_sample1 = sample1;
  6121             last_sample2 = sample2;
  6122             last_sample3 = sample3;
  6123             last_sample4 = sample4;
  6124             last_sample5 = sample5;
  6125             last_sample6 = sample6;
  6126             last_sample7 = sample7;
  6127             eps -= srcsize;
  6128         }
  6129     }
  6130     cvt->len_cvt = dstsize;
  6131     if (cvt->filters[++cvt->filter_index]) {
  6132         cvt->filters[cvt->filter_index] (cvt, format);
  6133     }
  6134 }
  6135 
  6136 static void SDLCALL
  6137 SDL_Upsample_F32LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6138 {
  6139 #if DEBUG_CONVERT
  6140     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_F32LSB, 1 channels.\n", cvt->rate_incr);
  6141 #endif
  6142 
  6143     const int srcsize = cvt->len_cvt - 64;
  6144     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  6145     register int eps = 0;
  6146     float *dst = ((float *) (cvt->buf + dstsize)) - 1;
  6147     const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 1;
  6148     const float *target = ((const float *) cvt->buf) - 1;
  6149     float sample0 = SDL_SwapFloatLE(src[0]);
  6150     float last_sample0 = sample0;
  6151     while (dst != target) {
  6152         dst[0] = SDL_SwapFloatLE(sample0);
  6153         dst--;
  6154         eps += srcsize;
  6155         if ((eps << 1) >= dstsize) {
  6156             src--;
  6157             sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
  6158             last_sample0 = sample0;
  6159             eps -= dstsize;
  6160         }
  6161     }
  6162     cvt->len_cvt = dstsize;
  6163     if (cvt->filters[++cvt->filter_index]) {
  6164         cvt->filters[cvt->filter_index] (cvt, format);
  6165     }
  6166 }
  6167 
  6168 static void SDLCALL
  6169 SDL_Downsample_F32LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6170 {
  6171 #if DEBUG_CONVERT
  6172     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_F32LSB, 1 channels.\n", cvt->rate_incr);
  6173 #endif
  6174 
  6175     const int srcsize = cvt->len_cvt - 64;
  6176     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  6177     register int eps = 0;
  6178     float *dst = (float *) cvt->buf;
  6179     const float *src = (float *) cvt->buf;
  6180     const float *target = (const float *) (cvt->buf + dstsize);
  6181     float sample0 = SDL_SwapFloatLE(src[0]);
  6182     float last_sample0 = sample0;
  6183     while (dst != target) {
  6184         src++;
  6185         eps += dstsize;
  6186         if ((eps << 1) >= srcsize) {
  6187             dst[0] = SDL_SwapFloatLE(sample0);
  6188             dst++;
  6189             sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
  6190             last_sample0 = sample0;
  6191             eps -= srcsize;
  6192         }
  6193     }
  6194     cvt->len_cvt = dstsize;
  6195     if (cvt->filters[++cvt->filter_index]) {
  6196         cvt->filters[cvt->filter_index] (cvt, format);
  6197     }
  6198 }
  6199 
  6200 static void SDLCALL
  6201 SDL_Upsample_F32LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6202 {
  6203 #if DEBUG_CONVERT
  6204     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_F32LSB, 2 channels.\n", cvt->rate_incr);
  6205 #endif
  6206 
  6207     const int srcsize = cvt->len_cvt - 128;
  6208     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  6209     register int eps = 0;
  6210     float *dst = ((float *) (cvt->buf + dstsize)) - 2;
  6211     const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 2;
  6212     const float *target = ((const float *) cvt->buf) - 2;
  6213     float sample1 = SDL_SwapFloatLE(src[1]);
  6214     float sample0 = SDL_SwapFloatLE(src[0]);
  6215     float last_sample1 = sample1;
  6216     float last_sample0 = sample0;
  6217     while (dst != target) {
  6218         dst[1] = SDL_SwapFloatLE(sample1);
  6219         dst[0] = SDL_SwapFloatLE(sample0);
  6220         dst -= 2;
  6221         eps += srcsize;
  6222         if ((eps << 1) >= dstsize) {
  6223             src -= 2;
  6224             sample1 = (float) ((((double) SDL_SwapFloatLE(src[1])) + ((double) last_sample1)) * 0.5);
  6225             sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
  6226             last_sample1 = sample1;
  6227             last_sample0 = sample0;
  6228             eps -= dstsize;
  6229         }
  6230     }
  6231     cvt->len_cvt = dstsize;
  6232     if (cvt->filters[++cvt->filter_index]) {
  6233         cvt->filters[cvt->filter_index] (cvt, format);
  6234     }
  6235 }
  6236 
  6237 static void SDLCALL
  6238 SDL_Downsample_F32LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6239 {
  6240 #if DEBUG_CONVERT
  6241     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_F32LSB, 2 channels.\n", cvt->rate_incr);
  6242 #endif
  6243 
  6244     const int srcsize = cvt->len_cvt - 128;
  6245     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  6246     register int eps = 0;
  6247     float *dst = (float *) cvt->buf;
  6248     const float *src = (float *) cvt->buf;
  6249     const float *target = (const float *) (cvt->buf + dstsize);
  6250     float sample0 = SDL_SwapFloatLE(src[0]);
  6251     float sample1 = SDL_SwapFloatLE(src[1]);
  6252     float last_sample0 = sample0;
  6253     float last_sample1 = sample1;
  6254     while (dst != target) {
  6255         src += 2;
  6256         eps += dstsize;
  6257         if ((eps << 1) >= srcsize) {
  6258             dst[0] = SDL_SwapFloatLE(sample0);
  6259             dst[1] = SDL_SwapFloatLE(sample1);
  6260             dst += 2;
  6261             sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
  6262             sample1 = (float) ((((double) SDL_SwapFloatLE(src[1])) + ((double) last_sample1)) * 0.5);
  6263             last_sample0 = sample0;
  6264             last_sample1 = sample1;
  6265             eps -= srcsize;
  6266         }
  6267     }
  6268     cvt->len_cvt = dstsize;
  6269     if (cvt->filters[++cvt->filter_index]) {
  6270         cvt->filters[cvt->filter_index] (cvt, format);
  6271     }
  6272 }
  6273 
  6274 static void SDLCALL
  6275 SDL_Upsample_F32LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6276 {
  6277 #if DEBUG_CONVERT
  6278     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_F32LSB, 4 channels.\n", cvt->rate_incr);
  6279 #endif
  6280 
  6281     const int srcsize = cvt->len_cvt - 256;
  6282     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  6283     register int eps = 0;
  6284     float *dst = ((float *) (cvt->buf + dstsize)) - 4;
  6285     const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 4;
  6286     const float *target = ((const float *) cvt->buf) - 4;
  6287     float sample3 = SDL_SwapFloatLE(src[3]);
  6288     float sample2 = SDL_SwapFloatLE(src[2]);
  6289     float sample1 = SDL_SwapFloatLE(src[1]);
  6290     float sample0 = SDL_SwapFloatLE(src[0]);
  6291     float last_sample3 = sample3;
  6292     float last_sample2 = sample2;
  6293     float last_sample1 = sample1;
  6294     float last_sample0 = sample0;
  6295     while (dst != target) {
  6296         dst[3] = SDL_SwapFloatLE(sample3);
  6297         dst[2] = SDL_SwapFloatLE(sample2);
  6298         dst[1] = SDL_SwapFloatLE(sample1);
  6299         dst[0] = SDL_SwapFloatLE(sample0);
  6300         dst -= 4;
  6301         eps += srcsize;
  6302         if ((eps << 1) >= dstsize) {
  6303             src -= 4;
  6304             sample3 = (float) ((((double) SDL_SwapFloatLE(src[3])) + ((double) last_sample3)) * 0.5);
  6305             sample2 = (float) ((((double) SDL_SwapFloatLE(src[2])) + ((double) last_sample2)) * 0.5);
  6306             sample1 = (float) ((((double) SDL_SwapFloatLE(src[1])) + ((double) last_sample1)) * 0.5);
  6307             sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
  6308             last_sample3 = sample3;
  6309             last_sample2 = sample2;
  6310             last_sample1 = sample1;
  6311             last_sample0 = sample0;
  6312             eps -= dstsize;
  6313         }
  6314     }
  6315     cvt->len_cvt = dstsize;
  6316     if (cvt->filters[++cvt->filter_index]) {
  6317         cvt->filters[cvt->filter_index] (cvt, format);
  6318     }
  6319 }
  6320 
  6321 static void SDLCALL
  6322 SDL_Downsample_F32LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6323 {
  6324 #if DEBUG_CONVERT
  6325     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_F32LSB, 4 channels.\n", cvt->rate_incr);
  6326 #endif
  6327 
  6328     const int srcsize = cvt->len_cvt - 256;
  6329     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  6330     register int eps = 0;
  6331     float *dst = (float *) cvt->buf;
  6332     const float *src = (float *) cvt->buf;
  6333     const float *target = (const float *) (cvt->buf + dstsize);
  6334     float sample0 = SDL_SwapFloatLE(src[0]);
  6335     float sample1 = SDL_SwapFloatLE(src[1]);
  6336     float sample2 = SDL_SwapFloatLE(src[2]);
  6337     float sample3 = SDL_SwapFloatLE(src[3]);
  6338     float last_sample0 = sample0;
  6339     float last_sample1 = sample1;
  6340     float last_sample2 = sample2;
  6341     float last_sample3 = sample3;
  6342     while (dst != target) {
  6343         src += 4;
  6344         eps += dstsize;
  6345         if ((eps << 1) >= srcsize) {
  6346             dst[0] = SDL_SwapFloatLE(sample0);
  6347             dst[1] = SDL_SwapFloatLE(sample1);
  6348             dst[2] = SDL_SwapFloatLE(sample2);
  6349             dst[3] = SDL_SwapFloatLE(sample3);
  6350             dst += 4;
  6351             sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
  6352             sample1 = (float) ((((double) SDL_SwapFloatLE(src[1])) + ((double) last_sample1)) * 0.5);
  6353             sample2 = (float) ((((double) SDL_SwapFloatLE(src[2])) + ((double) last_sample2)) * 0.5);
  6354             sample3 = (float) ((((double) SDL_SwapFloatLE(src[3])) + ((double) last_sample3)) * 0.5);
  6355             last_sample0 = sample0;
  6356             last_sample1 = sample1;
  6357             last_sample2 = sample2;
  6358             last_sample3 = sample3;
  6359             eps -= srcsize;
  6360         }
  6361     }
  6362     cvt->len_cvt = dstsize;
  6363     if (cvt->filters[++cvt->filter_index]) {
  6364         cvt->filters[cvt->filter_index] (cvt, format);
  6365     }
  6366 }
  6367 
  6368 static void SDLCALL
  6369 SDL_Upsample_F32LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6370 {
  6371 #if DEBUG_CONVERT
  6372     fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_F32LSB, 6 channels.\n", cvt->rate_incr);
  6373 #endif
  6374 
  6375     const int srcsize = cvt->len_cvt - 384;
  6376     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  6377     register int eps = 0;
  6378     float *dst = ((float *) (cvt->buf + dstsize)) - 6;
  6379     const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 6;
  6380     const float *target = ((const float *) cvt->buf) - 6;
  6381     float sample5 = SDL_SwapFloatLE(src[5]);
  6382     float sample4 = SDL_SwapFloatLE(src[4]);
  6383     float sample3 = SDL_SwapFloatLE(src[3]);
  6384     float sample2 = SDL_SwapFloatLE(src[2]);
  6385     float sample1 = SDL_SwapFloatLE(src[1]);
  6386     float sample0 = SDL_SwapFloatLE(src[0]);
  6387     float last_sample5 = sample5;
  6388     float last_sample4 = sample4;
  6389     float last_sample3 = sample3;
  6390     float last_sample2 = sample2;
  6391     float last_sample1 = sample1;
  6392     float last_sample0 = sample0;
  6393     while (dst != target) {
  6394         dst[5] = SDL_SwapFloatLE(sample5);
  6395         dst[4] = SDL_SwapFloatLE(sample4);
  6396         dst[3] = SDL_SwapFloatLE(sample3);
  6397         dst[2] = SDL_SwapFloatLE(sample2);
  6398         dst[1] = SDL_SwapFloatLE(sample1);
  6399         dst[0] = SDL_SwapFloatLE(sample0);
  6400         dst -= 6;
  6401         eps += srcsize;
  6402         if ((eps << 1) >= dstsize) {
  6403             src -= 6;
  6404             sample5 = (float) ((((double) SDL_SwapFloatLE(src[5])) + ((double) last_sample5)) * 0.5);
  6405             sample4 = (float) ((((double) SDL_SwapFloatLE(src[4])) + ((double) last_sample4)) * 0.5);
  6406             sample3 = (float) ((((double) SDL_SwapFloatLE(src[3])) + ((double) last_sample3)) * 0.5);
  6407             sample2 = (float) ((((double) SDL_SwapFloatLE(src[2])) + ((double) last_sample2)) * 0.5);
  6408             sample1 = (float) ((((double) SDL_SwapFloatLE(src[1])) + ((double) last_sample1)) * 0.5);
  6409             sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
  6410             last_sample5 = sample5;
  6411             last_sample4 = sample4;
  6412             last_sample3 = sample3;
  6413             last_sample2 = sample2;
  6414             last_sample1 = sample1;
  6415             last_sample0 = sample0;
  6416             eps -= dstsize;
  6417         }
  6418     }
  6419     cvt->len_cvt = dstsize;
  6420     if (cvt->filters[++cvt->filter_index]) {
  6421         cvt->filters[cvt->filter_index] (cvt, format);
  6422     }
  6423 }
  6424 
  6425 static void SDLCALL
  6426 SDL_Downsample_F32LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
  6427 {
  6428 #if DEBUG_CONVERT
  6429     fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_F32LSB, 6 channels.\n", cvt->rate_incr);
  6430 #endif
  6431 
  6432     const int srcsize = cvt->len_cvt - 384;
  6433     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
  6434     register int eps = 0;
  6435     float *dst = (float *) cvt->buf;
  6436     const float *src = (float *) cvt->buf;
  6437     const float *target = (const float *) (cvt->buf + dstsize);
  6438     float sample0 = SDL_SwapFloatLE(src[0]);
  6439     float sample1 = SDL_SwapFloatLE(src[1]);
  6440     float sample2 = SDL_SwapFloatLE(src[2]);
  6441     float sample3 = SDL_SwapFloatLE(src[3]);
  6442     float sample4 = SDL_SwapFloatLE(src[4]);
  6443     float sample5 = SDL_SwapFloatLE(src[5]);
  6444     float last_sample0 = sample0;
  6445     float last_sample1 = sample1;
  6446     float last_sample2 = sample2;
  6447     float last_sample3 = sample3;
  6448     float last_samp