view src/audio/SDL_audiotypecvt.c @ 1982:3b4ce57c6215

First shot at new audio data types (int32 and float32). Notable changes: - Converters between types are autogenerated. Instead of making multiple passes over the data with seperate filters for endianess, size, signedness, etc, converting between data types is always one specialized filter. This simplifies SDL_BuildAudioCVT(), which otherwise had a million edge cases with the new types, and makes the actually conversions more CPU cache friendly. Left a stub for adding specific optimized versions of these routines (SSE/MMX/Altivec, assembler, etc) - Autogenerated converters are built by SDL/src/audio/sdlgenaudiocvt.pl. This does not need to be run unless tweaking the code, and thus doesn't need integration into the build system. - Went through all the drivers and tried to weed out all the "Uint16" references that are better specified with the new SDL_AudioFormat typedef. - Cleaned out a bunch of hardcoded bitwise magic numbers and replaced them with new SDL_AUDIO_* macros. - Added initial float32 and int32 support code. Theoretically, existing drivers will push these through converters to get the data they want to feed to the hardware. Still TODO: - Optimize and debug new converters. - Update the CoreAudio backend to accept float32 data directly. - Other backends, too? - SDL_LoadWAV() needs to be updated to support int32 and float32 .wav files (both of which exist and can be generated by 'sox' for testing purposes). - Update the mixer to handle new datatypes. - Optionally update SDL_sound and SDL_mixer, etc.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 24 Aug 2006 12:10:46 +0000
parents
children 8055185ae4ed
line wrap: on
line source

/* DO NOT EDIT THIS FILE! It is generated code. */
/* Please modify SDL/src/audio/sdlgenaudiocvt.pl instead. */

/*
    SDL - Simple DirectMedia Layer
    Copyright (C) 1997-2006 Sam Lantinga

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

    Sam Lantinga
    slouken@libsdl.org
*/

#include "SDL_config.h"
#include "SDL_audio.h"
#include "SDL_audio_c.h"

/* Now the generated code... */

#define DIVBY127 0.0078740157480315f
#define DIVBY255 0.00392156862745098f
#define DIVBY32767 3.05185094759972e-05f
#define DIVBY65535 1.52590218966964e-05f
#define DIVBY2147483647 4.6566128752458e-10f

static void SDLCALL
SDL_Convert_U8_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint8 *src;
    Sint8 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S8.\n");
#endif

    src = (const Uint8 *) cvt->buf;
    dst = (Sint8 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, ++src, ++dst) {
        const Sint8 val = ((*src) ^ 0x80);
        *dst = ((Sint8) val);
    }

    format = AUDIO_S8;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U8_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint8 *src;
    Uint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U8 to AUDIO_U16LSB.\n");
#endif

    src = (const Uint8 *) (cvt->buf + cvt->len_cvt);
    dst = (Uint16 *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
        const Uint16 val = (((Uint16) *src) << 8);
        *dst = SDL_SwapLE16(val);
    }

    cvt->len_cvt *= 2;
    format = AUDIO_U16LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U8_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint8 *src;
    Sint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S16LSB.\n");
#endif

    src = (const Uint8 *) (cvt->buf + cvt->len_cvt);
    dst = (Sint16 *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
        const Sint16 val = (((Sint16) ((*src) ^ 0x80)) << 8);
        *dst = ((Sint16) SDL_SwapLE16(val));
    }

    cvt->len_cvt *= 2;
    format = AUDIO_S16LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U8_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint8 *src;
    Uint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U8 to AUDIO_U16MSB.\n");
#endif

    src = (const Uint8 *) (cvt->buf + cvt->len_cvt);
    dst = (Uint16 *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
        const Uint16 val = (((Uint16) *src) << 8);
        *dst = SDL_SwapBE16(val);
    }

    cvt->len_cvt *= 2;
    format = AUDIO_U16MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U8_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint8 *src;
    Sint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S16MSB.\n");
#endif

    src = (const Uint8 *) (cvt->buf + cvt->len_cvt);
    dst = (Sint16 *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
        const Sint16 val = (((Sint16) ((*src) ^ 0x80)) << 8);
        *dst = ((Sint16) SDL_SwapBE16(val));
    }

    cvt->len_cvt *= 2;
    format = AUDIO_S16MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U8_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint8 *src;
    Sint32 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S32LSB.\n");
#endif

    src = (const Uint8 *) (cvt->buf + cvt->len_cvt);
    dst = (Sint32 *) (cvt->buf + cvt->len_cvt * 4);
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
        const Sint32 val = (((Sint32) ((*src) ^ 0x80)) << 24);
        *dst = ((Sint32) SDL_SwapLE32(val));
    }

    cvt->len_cvt *= 4;
    format = AUDIO_S32LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U8_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint8 *src;
    Sint32 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S32MSB.\n");
#endif

    src = (const Uint8 *) (cvt->buf + cvt->len_cvt);
    dst = (Sint32 *) (cvt->buf + cvt->len_cvt * 4);
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
        const Sint32 val = (((Sint32) ((*src) ^ 0x80)) << 24);
        *dst = ((Sint32) SDL_SwapBE32(val));
    }

    cvt->len_cvt *= 4;
    format = AUDIO_S32MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U8_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint8 *src;
    float *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U8 to AUDIO_F32LSB.\n");
#endif

    src = (const Uint8 *) (cvt->buf + cvt->len_cvt);
    dst = (float *) (cvt->buf + cvt->len_cvt * 4);
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
        const float val = (((float) *src) * DIVBY255);
        *dst = SDL_SwapFloatLE(val);
    }

    cvt->len_cvt *= 4;
    format = AUDIO_F32LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U8_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint8 *src;
    float *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U8 to AUDIO_F32MSB.\n");
#endif

    src = (const Uint8 *) (cvt->buf + cvt->len_cvt);
    dst = (float *) (cvt->buf + cvt->len_cvt * 4);
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
        const float val = (((float) *src) * DIVBY255);
        *dst = SDL_SwapFloatBE(val);
    }

    cvt->len_cvt *= 4;
    format = AUDIO_F32MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S8_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint8 *src;
    Uint8 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S8 to AUDIO_U8.\n");
#endif

    src = (const Uint8 *) cvt->buf;
    dst = (Uint8 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, ++src, ++dst) {
        const Uint8 val = ((((Sint8) *src)) ^ 0x80);
        *dst = val;
    }

    format = AUDIO_U8;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S8_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint8 *src;
    Uint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S8 to AUDIO_U16LSB.\n");
#endif

    src = (const Uint8 *) (cvt->buf + cvt->len_cvt);
    dst = (Uint16 *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
        const Uint16 val = (((Uint16) ((((Sint8) *src)) ^ 0x80)) << 8);
        *dst = SDL_SwapLE16(val);
    }

    cvt->len_cvt *= 2;
    format = AUDIO_U16LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S8_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint8 *src;
    Sint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S16LSB.\n");
#endif

    src = (const Uint8 *) (cvt->buf + cvt->len_cvt);
    dst = (Sint16 *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
        const Sint16 val = (((Sint16) ((Sint8) *src)) << 8);
        *dst = ((Sint16) SDL_SwapLE16(val));
    }

    cvt->len_cvt *= 2;
    format = AUDIO_S16LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S8_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint8 *src;
    Uint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S8 to AUDIO_U16MSB.\n");
#endif

    src = (const Uint8 *) (cvt->buf + cvt->len_cvt);
    dst = (Uint16 *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
        const Uint16 val = (((Uint16) ((((Sint8) *src)) ^ 0x80)) << 8);
        *dst = SDL_SwapBE16(val);
    }

    cvt->len_cvt *= 2;
    format = AUDIO_U16MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S8_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint8 *src;
    Sint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S16MSB.\n");
#endif

    src = (const Uint8 *) (cvt->buf + cvt->len_cvt);
    dst = (Sint16 *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
        const Sint16 val = (((Sint16) ((Sint8) *src)) << 8);
        *dst = ((Sint16) SDL_SwapBE16(val));
    }

    cvt->len_cvt *= 2;
    format = AUDIO_S16MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S8_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint8 *src;
    Sint32 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S32LSB.\n");
#endif

    src = (const Uint8 *) (cvt->buf + cvt->len_cvt);
    dst = (Sint32 *) (cvt->buf + cvt->len_cvt * 4);
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
        const Sint32 val = (((Sint32) ((Sint8) *src)) << 24);
        *dst = ((Sint32) SDL_SwapLE32(val));
    }

    cvt->len_cvt *= 4;
    format = AUDIO_S32LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S8_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint8 *src;
    Sint32 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S32MSB.\n");
#endif

    src = (const Uint8 *) (cvt->buf + cvt->len_cvt);
    dst = (Sint32 *) (cvt->buf + cvt->len_cvt * 4);
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
        const Sint32 val = (((Sint32) ((Sint8) *src)) << 24);
        *dst = ((Sint32) SDL_SwapBE32(val));
    }

    cvt->len_cvt *= 4;
    format = AUDIO_S32MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S8_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint8 *src;
    float *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S8 to AUDIO_F32LSB.\n");
#endif

    src = (const Uint8 *) (cvt->buf + cvt->len_cvt);
    dst = (float *) (cvt->buf + cvt->len_cvt * 4);
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
        const float val = (((float) ((Sint8) *src)) * DIVBY127);
        *dst = SDL_SwapFloatLE(val);
    }

    cvt->len_cvt *= 4;
    format = AUDIO_F32LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S8_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint8 *src;
    float *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S8 to AUDIO_F32MSB.\n");
#endif

    src = (const Uint8 *) (cvt->buf + cvt->len_cvt);
    dst = (float *) (cvt->buf + cvt->len_cvt * 4);
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
        const float val = (((float) ((Sint8) *src)) * DIVBY127);
        *dst = SDL_SwapFloatBE(val);
    }

    cvt->len_cvt *= 4;
    format = AUDIO_F32MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U16LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Uint8 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_U8.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Uint8 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Uint8 val = ((Uint8) (SDL_SwapLE16(*src) >> 8));
        *dst = val;
    }

    cvt->len_cvt /= 2;
    format = AUDIO_U8;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U16LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Sint8 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S8.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Sint8 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Sint8 val = ((Sint8) (((SDL_SwapLE16(*src)) ^ 0x8000) >> 8));
        *dst = ((Sint8) val);
    }

    cvt->len_cvt /= 2;
    format = AUDIO_S8;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U16LSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Sint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S16LSB.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Sint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Sint16 val = ((SDL_SwapLE16(*src)) ^ 0x8000);
        *dst = ((Sint16) SDL_SwapLE16(val));
    }

    format = AUDIO_S16LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U16LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Uint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_U16MSB.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Uint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Uint16 val = SDL_SwapLE16(*src);
        *dst = SDL_SwapBE16(val);
    }

    format = AUDIO_U16MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U16LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Sint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S16MSB.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Sint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Sint16 val = ((SDL_SwapLE16(*src)) ^ 0x8000);
        *dst = ((Sint16) SDL_SwapBE16(val));
    }

    format = AUDIO_S16MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U16LSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Sint32 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S32LSB.\n");
#endif

    src = (const Uint16 *) (cvt->buf + cvt->len_cvt);
    dst = (Sint32 *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
        const Sint32 val = (((Sint32) ((SDL_SwapLE16(*src)) ^ 0x8000)) << 16);
        *dst = ((Sint32) SDL_SwapLE32(val));
    }

    cvt->len_cvt *= 2;
    format = AUDIO_S32LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U16LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Sint32 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S32MSB.\n");
#endif

    src = (const Uint16 *) (cvt->buf + cvt->len_cvt);
    dst = (Sint32 *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
        const Sint32 val = (((Sint32) ((SDL_SwapLE16(*src)) ^ 0x8000)) << 16);
        *dst = ((Sint32) SDL_SwapBE32(val));
    }

    cvt->len_cvt *= 2;
    format = AUDIO_S32MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U16LSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    float *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_F32LSB.\n");
#endif

    src = (const Uint16 *) (cvt->buf + cvt->len_cvt);
    dst = (float *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
        const float val = (((float) SDL_SwapLE16(*src)) * DIVBY65535);
        *dst = SDL_SwapFloatLE(val);
    }

    cvt->len_cvt *= 2;
    format = AUDIO_F32LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U16LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    float *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_F32MSB.\n");
#endif

    src = (const Uint16 *) (cvt->buf + cvt->len_cvt);
    dst = (float *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
        const float val = (((float) SDL_SwapLE16(*src)) * DIVBY65535);
        *dst = SDL_SwapFloatBE(val);
    }

    cvt->len_cvt *= 2;
    format = AUDIO_F32MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S16LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Uint8 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_U8.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Uint8 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Uint8 val = ((Uint8) (((((Sint16) SDL_SwapLE16(*src))) ^ 0x8000) >> 8));
        *dst = val;
    }

    cvt->len_cvt /= 2;
    format = AUDIO_U8;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S16LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Sint8 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S8.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Sint8 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Sint8 val = ((Sint8) (((Sint16) SDL_SwapLE16(*src)) >> 8));
        *dst = ((Sint8) val);
    }

    cvt->len_cvt /= 2;
    format = AUDIO_S8;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S16LSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Uint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_U16LSB.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Uint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Uint16 val = ((((Sint16) SDL_SwapLE16(*src))) ^ 0x8000);
        *dst = SDL_SwapLE16(val);
    }

    format = AUDIO_U16LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S16LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Uint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_U16MSB.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Uint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Uint16 val = ((((Sint16) SDL_SwapLE16(*src))) ^ 0x8000);
        *dst = SDL_SwapBE16(val);
    }

    format = AUDIO_U16MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S16LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Sint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S16MSB.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Sint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Sint16 val = ((Sint16) SDL_SwapLE16(*src));
        *dst = ((Sint16) SDL_SwapBE16(val));
    }

    format = AUDIO_S16MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S16LSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Sint32 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S32LSB.\n");
#endif

    src = (const Uint16 *) (cvt->buf + cvt->len_cvt);
    dst = (Sint32 *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
        const Sint32 val = (((Sint32) ((Sint16) SDL_SwapLE16(*src))) << 16);
        *dst = ((Sint32) SDL_SwapLE32(val));
    }

    cvt->len_cvt *= 2;
    format = AUDIO_S32LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S16LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Sint32 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S32MSB.\n");
#endif

    src = (const Uint16 *) (cvt->buf + cvt->len_cvt);
    dst = (Sint32 *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
        const Sint32 val = (((Sint32) ((Sint16) SDL_SwapLE16(*src))) << 16);
        *dst = ((Sint32) SDL_SwapBE32(val));
    }

    cvt->len_cvt *= 2;
    format = AUDIO_S32MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S16LSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    float *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_F32LSB.\n");
#endif

    src = (const Uint16 *) (cvt->buf + cvt->len_cvt);
    dst = (float *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
        const float val = (((float) ((Sint16) SDL_SwapLE16(*src))) * DIVBY32767);
        *dst = SDL_SwapFloatLE(val);
    }

    cvt->len_cvt *= 2;
    format = AUDIO_F32LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S16LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    float *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_F32MSB.\n");
#endif

    src = (const Uint16 *) (cvt->buf + cvt->len_cvt);
    dst = (float *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
        const float val = (((float) ((Sint16) SDL_SwapLE16(*src))) * DIVBY32767);
        *dst = SDL_SwapFloatBE(val);
    }

    cvt->len_cvt *= 2;
    format = AUDIO_F32MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U16MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Uint8 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_U8.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Uint8 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Uint8 val = ((Uint8) (SDL_SwapBE16(*src) >> 8));
        *dst = val;
    }

    cvt->len_cvt /= 2;
    format = AUDIO_U8;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U16MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Sint8 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S8.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Sint8 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Sint8 val = ((Sint8) (((SDL_SwapBE16(*src)) ^ 0x8000) >> 8));
        *dst = ((Sint8) val);
    }

    cvt->len_cvt /= 2;
    format = AUDIO_S8;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U16MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Uint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_U16LSB.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Uint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Uint16 val = SDL_SwapBE16(*src);
        *dst = SDL_SwapLE16(val);
    }

    format = AUDIO_U16LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U16MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Sint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S16LSB.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Sint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Sint16 val = ((SDL_SwapBE16(*src)) ^ 0x8000);
        *dst = ((Sint16) SDL_SwapLE16(val));
    }

    format = AUDIO_S16LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U16MSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Sint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S16MSB.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Sint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Sint16 val = ((SDL_SwapBE16(*src)) ^ 0x8000);
        *dst = ((Sint16) SDL_SwapBE16(val));
    }

    format = AUDIO_S16MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U16MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Sint32 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S32LSB.\n");
#endif

    src = (const Uint16 *) (cvt->buf + cvt->len_cvt);
    dst = (Sint32 *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
        const Sint32 val = (((Sint32) ((SDL_SwapBE16(*src)) ^ 0x8000)) << 16);
        *dst = ((Sint32) SDL_SwapLE32(val));
    }

    cvt->len_cvt *= 2;
    format = AUDIO_S32LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U16MSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Sint32 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S32MSB.\n");
#endif

    src = (const Uint16 *) (cvt->buf + cvt->len_cvt);
    dst = (Sint32 *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
        const Sint32 val = (((Sint32) ((SDL_SwapBE16(*src)) ^ 0x8000)) << 16);
        *dst = ((Sint32) SDL_SwapBE32(val));
    }

    cvt->len_cvt *= 2;
    format = AUDIO_S32MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U16MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    float *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_F32LSB.\n");
#endif

    src = (const Uint16 *) (cvt->buf + cvt->len_cvt);
    dst = (float *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
        const float val = (((float) SDL_SwapBE16(*src)) * DIVBY65535);
        *dst = SDL_SwapFloatLE(val);
    }

    cvt->len_cvt *= 2;
    format = AUDIO_F32LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_U16MSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    float *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_F32MSB.\n");
#endif

    src = (const Uint16 *) (cvt->buf + cvt->len_cvt);
    dst = (float *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
        const float val = (((float) SDL_SwapBE16(*src)) * DIVBY65535);
        *dst = SDL_SwapFloatBE(val);
    }

    cvt->len_cvt *= 2;
    format = AUDIO_F32MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S16MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Uint8 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_U8.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Uint8 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Uint8 val = ((Uint8) (((((Sint16) SDL_SwapBE16(*src))) ^ 0x8000) >> 8));
        *dst = val;
    }

    cvt->len_cvt /= 2;
    format = AUDIO_U8;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S16MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Sint8 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S8.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Sint8 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Sint8 val = ((Sint8) (((Sint16) SDL_SwapBE16(*src)) >> 8));
        *dst = ((Sint8) val);
    }

    cvt->len_cvt /= 2;
    format = AUDIO_S8;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S16MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Uint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_U16LSB.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Uint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Uint16 val = ((((Sint16) SDL_SwapBE16(*src))) ^ 0x8000);
        *dst = SDL_SwapLE16(val);
    }

    format = AUDIO_U16LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S16MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Sint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S16LSB.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Sint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Sint16 val = ((Sint16) SDL_SwapBE16(*src));
        *dst = ((Sint16) SDL_SwapLE16(val));
    }

    format = AUDIO_S16LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S16MSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Uint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_U16MSB.\n");
#endif

    src = (const Uint16 *) cvt->buf;
    dst = (Uint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
        const Uint16 val = ((((Sint16) SDL_SwapBE16(*src))) ^ 0x8000);
        *dst = SDL_SwapBE16(val);
    }

    format = AUDIO_U16MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S16MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Sint32 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S32LSB.\n");
#endif

    src = (const Uint16 *) (cvt->buf + cvt->len_cvt);
    dst = (Sint32 *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
        const Sint32 val = (((Sint32) ((Sint16) SDL_SwapBE16(*src))) << 16);
        *dst = ((Sint32) SDL_SwapLE32(val));
    }

    cvt->len_cvt *= 2;
    format = AUDIO_S32LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S16MSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    Sint32 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S32MSB.\n");
#endif

    src = (const Uint16 *) (cvt->buf + cvt->len_cvt);
    dst = (Sint32 *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
        const Sint32 val = (((Sint32) ((Sint16) SDL_SwapBE16(*src))) << 16);
        *dst = ((Sint32) SDL_SwapBE32(val));
    }

    cvt->len_cvt *= 2;
    format = AUDIO_S32MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S16MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    float *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_F32LSB.\n");
#endif

    src = (const Uint16 *) (cvt->buf + cvt->len_cvt);
    dst = (float *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
        const float val = (((float) ((Sint16) SDL_SwapBE16(*src))) * DIVBY32767);
        *dst = SDL_SwapFloatLE(val);
    }

    cvt->len_cvt *= 2;
    format = AUDIO_F32LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S16MSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint16 *src;
    float *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_F32MSB.\n");
#endif

    src = (const Uint16 *) (cvt->buf + cvt->len_cvt);
    dst = (float *) (cvt->buf + cvt->len_cvt * 2);
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
        const float val = (((float) ((Sint16) SDL_SwapBE16(*src))) * DIVBY32767);
        *dst = SDL_SwapFloatBE(val);
    }

    cvt->len_cvt *= 2;
    format = AUDIO_F32MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S32LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint32 *src;
    Uint8 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_U8.\n");
#endif

    src = (const Uint32 *) cvt->buf;
    dst = (Uint8 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
        const Uint8 val = ((Uint8) (((((Sint32) SDL_SwapLE32(*src))) ^ 0x80000000) >> 24));
        *dst = val;
    }

    cvt->len_cvt /= 4;
    format = AUDIO_U8;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S32LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint32 *src;
    Sint8 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S8.\n");
#endif

    src = (const Uint32 *) cvt->buf;
    dst = (Sint8 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
        const Sint8 val = ((Sint8) (((Sint32) SDL_SwapLE32(*src)) >> 24));
        *dst = ((Sint8) val);
    }

    cvt->len_cvt /= 4;
    format = AUDIO_S8;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S32LSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint32 *src;
    Uint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_U16LSB.\n");
#endif

    src = (const Uint32 *) cvt->buf;
    dst = (Uint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
        const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapLE32(*src))) ^ 0x80000000) >> 16));
        *dst = SDL_SwapLE16(val);
    }

    cvt->len_cvt /= 2;
    format = AUDIO_U16LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S32LSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint32 *src;
    Sint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S16LSB.\n");
#endif

    src = (const Uint32 *) cvt->buf;
    dst = (Sint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
        const Sint16 val = ((Sint16) (((Sint32) SDL_SwapLE32(*src)) >> 16));
        *dst = ((Sint16) SDL_SwapLE16(val));
    }

    cvt->len_cvt /= 2;
    format = AUDIO_S16LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S32LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint32 *src;
    Uint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_U16MSB.\n");
#endif

    src = (const Uint32 *) cvt->buf;
    dst = (Uint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
        const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapLE32(*src))) ^ 0x80000000) >> 16));
        *dst = SDL_SwapBE16(val);
    }

    cvt->len_cvt /= 2;
    format = AUDIO_U16MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S32LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint32 *src;
    Sint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S16MSB.\n");
#endif

    src = (const Uint32 *) cvt->buf;
    dst = (Sint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
        const Sint16 val = ((Sint16) (((Sint32) SDL_SwapLE32(*src)) >> 16));
        *dst = ((Sint16) SDL_SwapBE16(val));
    }

    cvt->len_cvt /= 2;
    format = AUDIO_S16MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S32LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint32 *src;
    Sint32 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S32MSB.\n");
#endif

    src = (const Uint32 *) cvt->buf;
    dst = (Sint32 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
        const Sint32 val = ((Sint32) SDL_SwapLE32(*src));
        *dst = ((Sint32) SDL_SwapBE32(val));
    }

    format = AUDIO_S32MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S32LSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint32 *src;
    float *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_F32LSB.\n");
#endif

    src = (const Uint32 *) cvt->buf;
    dst = (float *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
        const float val = (((float) ((Sint32) SDL_SwapLE32(*src))) * DIVBY2147483647);
        *dst = SDL_SwapFloatLE(val);
    }

    format = AUDIO_F32LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S32LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint32 *src;
    float *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_F32MSB.\n");
#endif

    src = (const Uint32 *) cvt->buf;
    dst = (float *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
        const float val = (((float) ((Sint32) SDL_SwapLE32(*src))) * DIVBY2147483647);
        *dst = SDL_SwapFloatBE(val);
    }

    format = AUDIO_F32MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S32MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint32 *src;
    Uint8 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_U8.\n");
#endif

    src = (const Uint32 *) cvt->buf;
    dst = (Uint8 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
        const Uint8 val = ((Uint8) (((((Sint32) SDL_SwapBE32(*src))) ^ 0x80000000) >> 24));
        *dst = val;
    }

    cvt->len_cvt /= 4;
    format = AUDIO_U8;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S32MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint32 *src;
    Sint8 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S8.\n");
#endif

    src = (const Uint32 *) cvt->buf;
    dst = (Sint8 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
        const Sint8 val = ((Sint8) (((Sint32) SDL_SwapBE32(*src)) >> 24));
        *dst = ((Sint8) val);
    }

    cvt->len_cvt /= 4;
    format = AUDIO_S8;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S32MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint32 *src;
    Uint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_U16LSB.\n");
#endif

    src = (const Uint32 *) cvt->buf;
    dst = (Uint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
        const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapBE32(*src))) ^ 0x80000000) >> 16));
        *dst = SDL_SwapLE16(val);
    }

    cvt->len_cvt /= 2;
    format = AUDIO_U16LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S32MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint32 *src;
    Sint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S16LSB.\n");
#endif

    src = (const Uint32 *) cvt->buf;
    dst = (Sint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
        const Sint16 val = ((Sint16) (((Sint32) SDL_SwapBE32(*src)) >> 16));
        *dst = ((Sint16) SDL_SwapLE16(val));
    }

    cvt->len_cvt /= 2;
    format = AUDIO_S16LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S32MSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint32 *src;
    Uint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_U16MSB.\n");
#endif

    src = (const Uint32 *) cvt->buf;
    dst = (Uint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
        const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapBE32(*src))) ^ 0x80000000) >> 16));
        *dst = SDL_SwapBE16(val);
    }

    cvt->len_cvt /= 2;
    format = AUDIO_U16MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S32MSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint32 *src;
    Sint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S16MSB.\n");
#endif

    src = (const Uint32 *) cvt->buf;
    dst = (Sint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
        const Sint16 val = ((Sint16) (((Sint32) SDL_SwapBE32(*src)) >> 16));
        *dst = ((Sint16) SDL_SwapBE16(val));
    }

    cvt->len_cvt /= 2;
    format = AUDIO_S16MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S32MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint32 *src;
    Sint32 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S32LSB.\n");
#endif

    src = (const Uint32 *) cvt->buf;
    dst = (Sint32 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
        const Sint32 val = ((Sint32) SDL_SwapBE32(*src));
        *dst = ((Sint32) SDL_SwapLE32(val));
    }

    format = AUDIO_S32LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S32MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint32 *src;
    float *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_F32LSB.\n");
#endif

    src = (const Uint32 *) cvt->buf;
    dst = (float *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
        const float val = (((float) ((Sint32) SDL_SwapBE32(*src))) * DIVBY2147483647);
        *dst = SDL_SwapFloatLE(val);
    }

    format = AUDIO_F32LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_S32MSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const Uint32 *src;
    float *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_F32MSB.\n");
#endif

    src = (const Uint32 *) cvt->buf;
    dst = (float *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
        const float val = (((float) ((Sint32) SDL_SwapBE32(*src))) * DIVBY2147483647);
        *dst = SDL_SwapFloatBE(val);
    }

    format = AUDIO_F32MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_F32LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const float *src;
    Uint8 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_U8.\n");
#endif

    src = (const float *) cvt->buf;
    dst = (Uint8 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
        const Uint8 val = ((Uint8) (SDL_SwapFloatLE(*src) * 255.0f));
        *dst = val;
    }

    cvt->len_cvt /= 4;
    format = AUDIO_U8;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_F32LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const float *src;
    Sint8 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S8.\n");
#endif

    src = (const float *) cvt->buf;
    dst = (Sint8 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
        const Sint8 val = ((Sint8) (SDL_SwapFloatLE(*src) * 127.0f));
        *dst = ((Sint8) val);
    }

    cvt->len_cvt /= 4;
    format = AUDIO_S8;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_F32LSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const float *src;
    Uint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_U16LSB.\n");
#endif

    src = (const float *) cvt->buf;
    dst = (Uint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
        const Uint16 val = ((Uint16) (SDL_SwapFloatLE(*src) * 65535.0f));
        *dst = SDL_SwapLE16(val);
    }

    cvt->len_cvt /= 2;
    format = AUDIO_U16LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_F32LSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const float *src;
    Sint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S16LSB.\n");
#endif

    src = (const float *) cvt->buf;
    dst = (Sint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
        const Sint16 val = ((Sint16) (SDL_SwapFloatLE(*src) * 32767.0f));
        *dst = ((Sint16) SDL_SwapLE16(val));
    }

    cvt->len_cvt /= 2;
    format = AUDIO_S16LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_F32LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const float *src;
    Uint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_U16MSB.\n");
#endif

    src = (const float *) cvt->buf;
    dst = (Uint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
        const Uint16 val = ((Uint16) (SDL_SwapFloatLE(*src) * 65535.0f));
        *dst = SDL_SwapBE16(val);
    }

    cvt->len_cvt /= 2;
    format = AUDIO_U16MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_F32LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const float *src;
    Sint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S16MSB.\n");
#endif

    src = (const float *) cvt->buf;
    dst = (Sint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
        const Sint16 val = ((Sint16) (SDL_SwapFloatLE(*src) * 32767.0f));
        *dst = ((Sint16) SDL_SwapBE16(val));
    }

    cvt->len_cvt /= 2;
    format = AUDIO_S16MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_F32LSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const float *src;
    Sint32 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S32LSB.\n");
#endif

    src = (const float *) cvt->buf;
    dst = (Sint32 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
        const Sint32 val = ((Sint32) (SDL_SwapFloatLE(*src) * 2147483647.0));
        *dst = ((Sint32) SDL_SwapLE32(val));
    }

    format = AUDIO_S32LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_F32LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const float *src;
    Sint32 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S32MSB.\n");
#endif

    src = (const float *) cvt->buf;
    dst = (Sint32 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
        const Sint32 val = ((Sint32) (SDL_SwapFloatLE(*src) * 2147483647.0));
        *dst = ((Sint32) SDL_SwapBE32(val));
    }

    format = AUDIO_S32MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_F32LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const float *src;
    float *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_F32MSB.\n");
#endif

    src = (const float *) cvt->buf;
    dst = (float *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
        const float val = SDL_SwapFloatLE(*src);
        *dst = SDL_SwapFloatBE(val);
    }

    format = AUDIO_F32MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_F32MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const float *src;
    Uint8 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_U8.\n");
#endif

    src = (const float *) cvt->buf;
    dst = (Uint8 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
        const Uint8 val = ((Uint8) (SDL_SwapFloatBE(*src) * 255.0f));
        *dst = val;
    }

    cvt->len_cvt /= 4;
    format = AUDIO_U8;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_F32MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const float *src;
    Sint8 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S8.\n");
#endif

    src = (const float *) cvt->buf;
    dst = (Sint8 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
        const Sint8 val = ((Sint8) (SDL_SwapFloatBE(*src) * 127.0f));
        *dst = ((Sint8) val);
    }

    cvt->len_cvt /= 4;
    format = AUDIO_S8;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_F32MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const float *src;
    Uint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_U16LSB.\n");
#endif

    src = (const float *) cvt->buf;
    dst = (Uint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
        const Uint16 val = ((Uint16) (SDL_SwapFloatBE(*src) * 65535.0f));
        *dst = SDL_SwapLE16(val);
    }

    cvt->len_cvt /= 2;
    format = AUDIO_U16LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_F32MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const float *src;
    Sint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S16LSB.\n");
#endif

    src = (const float *) cvt->buf;
    dst = (Sint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
        const Sint16 val = ((Sint16) (SDL_SwapFloatBE(*src) * 32767.0f));
        *dst = ((Sint16) SDL_SwapLE16(val));
    }

    cvt->len_cvt /= 2;
    format = AUDIO_S16LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_F32MSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const float *src;
    Uint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_U16MSB.\n");
#endif

    src = (const float *) cvt->buf;
    dst = (Uint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
        const Uint16 val = ((Uint16) (SDL_SwapFloatBE(*src) * 65535.0f));
        *dst = SDL_SwapBE16(val);
    }

    cvt->len_cvt /= 2;
    format = AUDIO_U16MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_F32MSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const float *src;
    Sint16 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S16MSB.\n");
#endif

    src = (const float *) cvt->buf;
    dst = (Sint16 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
        const Sint16 val = ((Sint16) (SDL_SwapFloatBE(*src) * 32767.0f));
        *dst = ((Sint16) SDL_SwapBE16(val));
    }

    cvt->len_cvt /= 2;
    format = AUDIO_S16MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_F32MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const float *src;
    Sint32 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S32LSB.\n");
#endif

    src = (const float *) cvt->buf;
    dst = (Sint32 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
        const Sint32 val = ((Sint32) (SDL_SwapFloatBE(*src) * 2147483647.0));
        *dst = ((Sint32) SDL_SwapLE32(val));
    }

    format = AUDIO_S32LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_F32MSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const float *src;
    Sint32 *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S32MSB.\n");
#endif

    src = (const float *) cvt->buf;
    dst = (Sint32 *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
        const Sint32 val = ((Sint32) (SDL_SwapFloatBE(*src) * 2147483647.0));
        *dst = ((Sint32) SDL_SwapBE32(val));
    }

    format = AUDIO_S32MSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

static void SDLCALL
SDL_Convert_F32MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
{
    int i;
    const float *src;
    float *dst;

#ifdef DEBUG_CONVERT
    fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_F32LSB.\n");
#endif

    src = (const float *) cvt->buf;
    dst = (float *) cvt->buf;
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
        const float val = SDL_SwapFloatBE(*src);
        *dst = SDL_SwapFloatLE(val);
    }

    format = AUDIO_F32LSB;
    if (cvt->filters[++cvt->filter_index]) {
        cvt->filters[cvt->filter_index] (cvt, format);
    }
}

const SDL_AudioTypeFilters sdl_audio_type_filters[] =
{
    { AUDIO_U8, AUDIO_S8, SDL_Convert_U8_to_S8 },
    { AUDIO_U8, AUDIO_U16LSB, SDL_Convert_U8_to_U16LSB },
    { AUDIO_U8, AUDIO_S16LSB, SDL_Convert_U8_to_S16LSB },
    { AUDIO_U8, AUDIO_U16MSB, SDL_Convert_U8_to_U16MSB },
    { AUDIO_U8, AUDIO_S16MSB, SDL_Convert_U8_to_S16MSB },
    { AUDIO_U8, AUDIO_S32LSB, SDL_Convert_U8_to_S32LSB },
    { AUDIO_U8, AUDIO_S32MSB, SDL_Convert_U8_to_S32MSB },
    { AUDIO_U8, AUDIO_F32LSB, SDL_Convert_U8_to_F32LSB },
    { AUDIO_U8, AUDIO_F32MSB, SDL_Convert_U8_to_F32MSB },
    { AUDIO_S8, AUDIO_U8, SDL_Convert_S8_to_U8 },
    { AUDIO_S8, AUDIO_U16LSB, SDL_Convert_S8_to_U16LSB },
    { AUDIO_S8, AUDIO_S16LSB, SDL_Convert_S8_to_S16LSB },
    { AUDIO_S8, AUDIO_U16MSB, SDL_Convert_S8_to_U16MSB },
    { AUDIO_S8, AUDIO_S16MSB, SDL_Convert_S8_to_S16MSB },
    { AUDIO_S8, AUDIO_S32LSB, SDL_Convert_S8_to_S32LSB },
    { AUDIO_S8, AUDIO_S32MSB, SDL_Convert_S8_to_S32MSB },
    { AUDIO_S8, AUDIO_F32LSB, SDL_Convert_S8_to_F32LSB },
    { AUDIO_S8, AUDIO_F32MSB, SDL_Convert_S8_to_F32MSB },
    { AUDIO_U16LSB, AUDIO_U8, SDL_Convert_U16LSB_to_U8 },
    { AUDIO_U16LSB, AUDIO_S8, SDL_Convert_U16LSB_to_S8 },
    { AUDIO_U16LSB, AUDIO_S16LSB, SDL_Convert_U16LSB_to_S16LSB },
    { AUDIO_U16LSB, AUDIO_U16MSB, SDL_Convert_U16LSB_to_U16MSB },
    { AUDIO_U16LSB, AUDIO_S16MSB, SDL_Convert_U16LSB_to_S16MSB },
    { AUDIO_U16LSB, AUDIO_S32LSB, SDL_Convert_U16LSB_to_S32LSB },
    { AUDIO_U16LSB, AUDIO_S32MSB, SDL_Convert_U16LSB_to_S32MSB },
    { AUDIO_U16LSB, AUDIO_F32LSB, SDL_Convert_U16LSB_to_F32LSB },
    { AUDIO_U16LSB, AUDIO_F32MSB, SDL_Convert_U16LSB_to_F32MSB },
    { AUDIO_S16LSB, AUDIO_U8, SDL_Convert_S16LSB_to_U8 },
    { AUDIO_S16LSB, AUDIO_S8, SDL_Convert_S16LSB_to_S8 },
    { AUDIO_S16LSB, AUDIO_U16LSB, SDL_Convert_S16LSB_to_U16LSB },
    { AUDIO_S16LSB, AUDIO_U16MSB, SDL_Convert_S16LSB_to_U16MSB },
    { AUDIO_S16LSB, AUDIO_S16MSB, SDL_Convert_S16LSB_to_S16MSB },
    { AUDIO_S16LSB, AUDIO_S32LSB, SDL_Convert_S16LSB_to_S32LSB },
    { AUDIO_S16LSB, AUDIO_S32MSB, SDL_Convert_S16LSB_to_S32MSB },
    { AUDIO_S16LSB, AUDIO_F32LSB, SDL_Convert_S16LSB_to_F32LSB },
    { AUDIO_S16LSB, AUDIO_F32MSB, SDL_Convert_S16LSB_to_F32MSB },
    { AUDIO_U16MSB, AUDIO_U8, SDL_Convert_U16MSB_to_U8 },
    { AUDIO_U16MSB, AUDIO_S8, SDL_Convert_U16MSB_to_S8 },
    { AUDIO_U16MSB, AUDIO_U16LSB, SDL_Convert_U16MSB_to_U16LSB },
    { AUDIO_U16MSB, AUDIO_S16LSB, SDL_Convert_U16MSB_to_S16LSB },
    { AUDIO_U16MSB, AUDIO_S16MSB, SDL_Convert_U16MSB_to_S16MSB },
    { AUDIO_U16MSB, AUDIO_S32LSB, SDL_Convert_U16MSB_to_S32LSB },
    { AUDIO_U16MSB, AUDIO_S32MSB, SDL_Convert_U16MSB_to_S32MSB },
    { AUDIO_U16MSB, AUDIO_F32LSB, SDL_Convert_U16MSB_to_F32LSB },
    { AUDIO_U16MSB, AUDIO_F32MSB, SDL_Convert_U16MSB_to_F32MSB },
    { AUDIO_S16MSB, AUDIO_U8, SDL_Convert_S16MSB_to_U8 },
    { AUDIO_S16MSB, AUDIO_S8, SDL_Convert_S16MSB_to_S8 },
    { AUDIO_S16MSB, AUDIO_U16LSB, SDL_Convert_S16MSB_to_U16LSB },
    { AUDIO_S16MSB, AUDIO_S16LSB, SDL_Convert_S16MSB_to_S16LSB },
    { AUDIO_S16MSB, AUDIO_U16MSB, SDL_Convert_S16MSB_to_U16MSB },
    { AUDIO_S16MSB, AUDIO_S32LSB, SDL_Convert_S16MSB_to_S32LSB },
    { AUDIO_S16MSB, AUDIO_S32MSB, SDL_Convert_S16MSB_to_S32MSB },
    { AUDIO_S16MSB, AUDIO_F32LSB, SDL_Convert_S16MSB_to_F32LSB },
    { AUDIO_S16MSB, AUDIO_F32MSB, SDL_Convert_S16MSB_to_F32MSB },
    { AUDIO_S32LSB, AUDIO_U8, SDL_Convert_S32LSB_to_U8 },
    { AUDIO_S32LSB, AUDIO_S8, SDL_Convert_S32LSB_to_S8 },
    { AUDIO_S32LSB, AUDIO_U16LSB, SDL_Convert_S32LSB_to_U16LSB },
    { AUDIO_S32LSB, AUDIO_S16LSB, SDL_Convert_S32LSB_to_S16LSB },
    { AUDIO_S32LSB, AUDIO_U16MSB, SDL_Convert_S32LSB_to_U16MSB },
    { AUDIO_S32LSB, AUDIO_S16MSB, SDL_Convert_S32LSB_to_S16MSB },
    { AUDIO_S32LSB, AUDIO_S32MSB, SDL_Convert_S32LSB_to_S32MSB },
    { AUDIO_S32LSB, AUDIO_F32LSB, SDL_Convert_S32LSB_to_F32LSB },
    { AUDIO_S32LSB, AUDIO_F32MSB, SDL_Convert_S32LSB_to_F32MSB },
    { AUDIO_S32MSB, AUDIO_U8, SDL_Convert_S32MSB_to_U8 },
    { AUDIO_S32MSB, AUDIO_S8, SDL_Convert_S32MSB_to_S8 },
    { AUDIO_S32MSB, AUDIO_U16LSB, SDL_Convert_S32MSB_to_U16LSB },
    { AUDIO_S32MSB, AUDIO_S16LSB, SDL_Convert_S32MSB_to_S16LSB },
    { AUDIO_S32MSB, AUDIO_U16MSB, SDL_Convert_S32MSB_to_U16MSB },
    { AUDIO_S32MSB, AUDIO_S16MSB, SDL_Convert_S32MSB_to_S16MSB },
    { AUDIO_S32MSB, AUDIO_S32LSB, SDL_Convert_S32MSB_to_S32LSB },
    { AUDIO_S32MSB, AUDIO_F32LSB, SDL_Convert_S32MSB_to_F32LSB },
    { AUDIO_S32MSB, AUDIO_F32MSB, SDL_Convert_S32MSB_to_F32MSB },
    { AUDIO_F32LSB, AUDIO_U8, SDL_Convert_F32LSB_to_U8 },
    { AUDIO_F32LSB, AUDIO_S8, SDL_Convert_F32LSB_to_S8 },
    { AUDIO_F32LSB, AUDIO_U16LSB, SDL_Convert_F32LSB_to_U16LSB },
    { AUDIO_F32LSB, AUDIO_S16LSB, SDL_Convert_F32LSB_to_S16LSB },
    { AUDIO_F32LSB, AUDIO_U16MSB, SDL_Convert_F32LSB_to_U16MSB },
    { AUDIO_F32LSB, AUDIO_S16MSB, SDL_Convert_F32LSB_to_S16MSB },
    { AUDIO_F32LSB, AUDIO_S32LSB, SDL_Convert_F32LSB_to_S32LSB },
    { AUDIO_F32LSB, AUDIO_S32MSB, SDL_Convert_F32LSB_to_S32MSB },
    { AUDIO_F32LSB, AUDIO_F32MSB, SDL_Convert_F32LSB_to_F32MSB },
    { AUDIO_F32MSB, AUDIO_U8, SDL_Convert_F32MSB_to_U8 },
    { AUDIO_F32MSB, AUDIO_S8, SDL_Convert_F32MSB_to_S8 },
    { AUDIO_F32MSB, AUDIO_U16LSB, SDL_Convert_F32MSB_to_U16LSB },
    { AUDIO_F32MSB, AUDIO_S16LSB, SDL_Convert_F32MSB_to_S16LSB },
    { AUDIO_F32MSB, AUDIO_U16MSB, SDL_Convert_F32MSB_to_U16MSB },
    { AUDIO_F32MSB, AUDIO_S16MSB, SDL_Convert_F32MSB_to_S16MSB },
    { AUDIO_F32MSB, AUDIO_S32LSB, SDL_Convert_F32MSB_to_S32LSB },
    { AUDIO_F32MSB, AUDIO_S32MSB, SDL_Convert_F32MSB_to_S32MSB },
    { AUDIO_F32MSB, AUDIO_F32LSB, SDL_Convert_F32MSB_to_F32LSB },
};