src/audio/SDL_audiotypecvt.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 08 Apr 2011 13:03:26 -0700
changeset 5535 96594ac5fd1a
parent 5262 b530ef003506
child 5979 cf9884b08c6e
permissions -rw-r--r--
SDL 1.3 is now under the zlib license.
slouken@1985
     1
/* DO NOT EDIT!  This file is generated by sdlgenaudiocvt.pl */
icculus@1982
     2
/*
slouken@5535
     3
  Simple DirectMedia Layer
slouken@5535
     4
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
slouken@5535
     5
slouken@5535
     6
  This software is provided 'as-is', without any express or implied
slouken@5535
     7
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     8
  arising from the use of this software.
slouken@5535
     9
slouken@5535
    10
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    11
  including commercial applications, and to alter it and redistribute it
slouken@5535
    12
  freely, subject to the following restrictions:
slouken@5535
    13
slouken@5535
    14
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    15
     claim that you wrote the original software. If you use this software
slouken@5535
    16
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    17
     appreciated but is not required.
slouken@5535
    18
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    19
     misrepresented as being the original software.
slouken@5535
    20
  3. This notice may not be removed or altered from any source distribution.
icculus@1982
    21
*/
icculus@1982
    22
icculus@1982
    23
#include "SDL_config.h"
icculus@1982
    24
#include "SDL_audio.h"
icculus@1982
    25
#include "SDL_audio_c.h"
icculus@1982
    26
icculus@3021
    27
#ifndef DEBUG_CONVERT
icculus@3021
    28
#define DEBUG_CONVERT 0
icculus@3021
    29
#endif
icculus@3021
    30
icculus@3021
    31
icculus@3021
    32
/* If you can guarantee your data and need space, you can eliminate code... */
icculus@3021
    33
icculus@3021
    34
/* Just build the arbitrary resamplers if you're saving code space. */
icculus@3021
    35
#ifndef LESS_RESAMPLERS
icculus@3021
    36
#define LESS_RESAMPLERS 0
icculus@3021
    37
#endif
icculus@3021
    38
icculus@3021
    39
/* Don't build any resamplers if you're REALLY saving code space. */
icculus@3021
    40
#ifndef NO_RESAMPLERS
icculus@3021
    41
#define NO_RESAMPLERS 0
icculus@3021
    42
#endif
icculus@3021
    43
icculus@3021
    44
/* Don't build any type converters if you're saving code space. */
icculus@3021
    45
#ifndef NO_CONVERTERS
icculus@3021
    46
#define NO_CONVERTERS 0
icculus@3021
    47
#endif
icculus@3021
    48
icculus@3021
    49
slouken@1985
    50
/* *INDENT-OFF* */
icculus@1982
    51
icculus@1982
    52
#define DIVBY127 0.0078740157480315f
icculus@1982
    53
#define DIVBY32767 3.05185094759972e-05f
icculus@1982
    54
#define DIVBY2147483647 4.6566128752458e-10f
icculus@1982
    55
icculus@3021
    56
#if !NO_CONVERTERS
icculus@3021
    57
icculus@1982
    58
static void SDLCALL
icculus@1982
    59
SDL_Convert_U8_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
    60
{
icculus@1982
    61
    int i;
icculus@1982
    62
    const Uint8 *src;
icculus@1982
    63
    Sint8 *dst;
icculus@1982
    64
slouken@3032
    65
#if DEBUG_CONVERT
icculus@1982
    66
    fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S8.\n");
icculus@1982
    67
#endif
icculus@1982
    68
icculus@1982
    69
    src = (const Uint8 *) cvt->buf;
icculus@1982
    70
    dst = (Sint8 *) cvt->buf;
icculus@1982
    71
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, ++src, ++dst) {
icculus@1982
    72
        const Sint8 val = ((*src) ^ 0x80);
icculus@1982
    73
        *dst = ((Sint8) val);
icculus@1982
    74
    }
icculus@1982
    75
icculus@1982
    76
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
    77
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
icculus@1982
    78
    }
icculus@1982
    79
}
icculus@1982
    80
icculus@1982
    81
static void SDLCALL
icculus@1982
    82
SDL_Convert_U8_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
    83
{
icculus@1982
    84
    int i;
icculus@1982
    85
    const Uint8 *src;
icculus@1982
    86
    Uint16 *dst;
icculus@1982
    87
slouken@3032
    88
#if DEBUG_CONVERT
icculus@1982
    89
    fprintf(stderr, "Converting AUDIO_U8 to AUDIO_U16LSB.\n");
icculus@1982
    90
#endif
icculus@1982
    91
icculus@2956
    92
    src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
    93
    dst = ((Uint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
    94
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
icculus@1982
    95
        const Uint16 val = (((Uint16) *src) << 8);
icculus@1982
    96
        *dst = SDL_SwapLE16(val);
icculus@1982
    97
    }
icculus@1982
    98
icculus@1982
    99
    cvt->len_cvt *= 2;
icculus@1982
   100
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   101
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
icculus@1982
   102
    }
icculus@1982
   103
}
icculus@1982
   104
icculus@1982
   105
static void SDLCALL
icculus@1982
   106
SDL_Convert_U8_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   107
{
icculus@1982
   108
    int i;
icculus@1982
   109
    const Uint8 *src;
icculus@1982
   110
    Sint16 *dst;
icculus@1982
   111
slouken@3032
   112
#if DEBUG_CONVERT
icculus@1982
   113
    fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S16LSB.\n");
icculus@1982
   114
#endif
icculus@1982
   115
icculus@2956
   116
    src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   117
    dst = ((Sint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
   118
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
icculus@1982
   119
        const Sint16 val = (((Sint16) ((*src) ^ 0x80)) << 8);
icculus@1982
   120
        *dst = ((Sint16) SDL_SwapLE16(val));
icculus@1982
   121
    }
icculus@1982
   122
icculus@1982
   123
    cvt->len_cvt *= 2;
icculus@1982
   124
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   125
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
icculus@1982
   126
    }
icculus@1982
   127
}
icculus@1982
   128
icculus@1982
   129
static void SDLCALL
icculus@1982
   130
SDL_Convert_U8_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   131
{
icculus@1982
   132
    int i;
icculus@1982
   133
    const Uint8 *src;
icculus@1982
   134
    Uint16 *dst;
icculus@1982
   135
slouken@3032
   136
#if DEBUG_CONVERT
icculus@1982
   137
    fprintf(stderr, "Converting AUDIO_U8 to AUDIO_U16MSB.\n");
icculus@1982
   138
#endif
icculus@1982
   139
icculus@2956
   140
    src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   141
    dst = ((Uint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
   142
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
icculus@1982
   143
        const Uint16 val = (((Uint16) *src) << 8);
icculus@1982
   144
        *dst = SDL_SwapBE16(val);
icculus@1982
   145
    }
icculus@1982
   146
icculus@1982
   147
    cvt->len_cvt *= 2;
icculus@1982
   148
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   149
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
icculus@1982
   150
    }
icculus@1982
   151
}
icculus@1982
   152
icculus@1982
   153
static void SDLCALL
icculus@1982
   154
SDL_Convert_U8_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   155
{
icculus@1982
   156
    int i;
icculus@1982
   157
    const Uint8 *src;
icculus@1982
   158
    Sint16 *dst;
icculus@1982
   159
slouken@3032
   160
#if DEBUG_CONVERT
icculus@1982
   161
    fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S16MSB.\n");
icculus@1982
   162
#endif
icculus@1982
   163
icculus@2956
   164
    src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   165
    dst = ((Sint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
   166
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
icculus@1982
   167
        const Sint16 val = (((Sint16) ((*src) ^ 0x80)) << 8);
icculus@1982
   168
        *dst = ((Sint16) SDL_SwapBE16(val));
icculus@1982
   169
    }
icculus@1982
   170
icculus@1982
   171
    cvt->len_cvt *= 2;
icculus@1982
   172
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   173
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
icculus@1982
   174
    }
icculus@1982
   175
}
icculus@1982
   176
icculus@1982
   177
static void SDLCALL
icculus@1982
   178
SDL_Convert_U8_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   179
{
icculus@1982
   180
    int i;
icculus@1982
   181
    const Uint8 *src;
icculus@1982
   182
    Sint32 *dst;
icculus@1982
   183
slouken@3032
   184
#if DEBUG_CONVERT
icculus@1982
   185
    fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S32LSB.\n");
icculus@1982
   186
#endif
icculus@1982
   187
icculus@2956
   188
    src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   189
    dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 4)) - 1;
icculus@1982
   190
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
icculus@1982
   191
        const Sint32 val = (((Sint32) ((*src) ^ 0x80)) << 24);
icculus@1982
   192
        *dst = ((Sint32) SDL_SwapLE32(val));
icculus@1982
   193
    }
icculus@1982
   194
icculus@1982
   195
    cvt->len_cvt *= 4;
icculus@1982
   196
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   197
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
icculus@1982
   198
    }
icculus@1982
   199
}
icculus@1982
   200
icculus@1982
   201
static void SDLCALL
icculus@1982
   202
SDL_Convert_U8_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   203
{
icculus@1982
   204
    int i;
icculus@1982
   205
    const Uint8 *src;
icculus@1982
   206
    Sint32 *dst;
icculus@1982
   207
slouken@3032
   208
#if DEBUG_CONVERT
icculus@1982
   209
    fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S32MSB.\n");
icculus@1982
   210
#endif
icculus@1982
   211
icculus@2956
   212
    src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   213
    dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 4)) - 1;
icculus@1982
   214
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
icculus@1982
   215
        const Sint32 val = (((Sint32) ((*src) ^ 0x80)) << 24);
icculus@1982
   216
        *dst = ((Sint32) SDL_SwapBE32(val));
icculus@1982
   217
    }
icculus@1982
   218
icculus@1982
   219
    cvt->len_cvt *= 4;
icculus@1982
   220
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   221
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
icculus@1982
   222
    }
icculus@1982
   223
}
icculus@1982
   224
icculus@1982
   225
static void SDLCALL
icculus@1982
   226
SDL_Convert_U8_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   227
{
icculus@1982
   228
    int i;
icculus@1982
   229
    const Uint8 *src;
icculus@1982
   230
    float *dst;
icculus@1982
   231
slouken@3032
   232
#if DEBUG_CONVERT
icculus@1982
   233
    fprintf(stderr, "Converting AUDIO_U8 to AUDIO_F32LSB.\n");
icculus@1982
   234
#endif
icculus@1982
   235
icculus@2956
   236
    src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   237
    dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
icculus@1982
   238
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
icculus@2011
   239
        const float val = ((((float) *src) * DIVBY127) - 1.0f);
icculus@1982
   240
        *dst = SDL_SwapFloatLE(val);
icculus@1982
   241
    }
icculus@1982
   242
icculus@1982
   243
    cvt->len_cvt *= 4;
icculus@1982
   244
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   245
        cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
icculus@1982
   246
    }
icculus@1982
   247
}
icculus@1982
   248
icculus@1982
   249
static void SDLCALL
icculus@1982
   250
SDL_Convert_U8_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   251
{
icculus@1982
   252
    int i;
icculus@1982
   253
    const Uint8 *src;
icculus@1982
   254
    float *dst;
icculus@1982
   255
slouken@3032
   256
#if DEBUG_CONVERT
icculus@1982
   257
    fprintf(stderr, "Converting AUDIO_U8 to AUDIO_F32MSB.\n");
icculus@1982
   258
#endif
icculus@1982
   259
icculus@2956
   260
    src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   261
    dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
icculus@1982
   262
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
icculus@2011
   263
        const float val = ((((float) *src) * DIVBY127) - 1.0f);
icculus@1982
   264
        *dst = SDL_SwapFloatBE(val);
icculus@1982
   265
    }
icculus@1982
   266
icculus@1982
   267
    cvt->len_cvt *= 4;
icculus@1982
   268
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   269
        cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
icculus@1982
   270
    }
icculus@1982
   271
}
icculus@1982
   272
icculus@1982
   273
static void SDLCALL
icculus@1982
   274
SDL_Convert_S8_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   275
{
icculus@1982
   276
    int i;
icculus@1982
   277
    const Uint8 *src;
icculus@1982
   278
    Uint8 *dst;
icculus@1982
   279
slouken@3032
   280
#if DEBUG_CONVERT
icculus@1982
   281
    fprintf(stderr, "Converting AUDIO_S8 to AUDIO_U8.\n");
icculus@1982
   282
#endif
icculus@1982
   283
icculus@1982
   284
    src = (const Uint8 *) cvt->buf;
icculus@1982
   285
    dst = (Uint8 *) cvt->buf;
icculus@1982
   286
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, ++src, ++dst) {
icculus@1982
   287
        const Uint8 val = ((((Sint8) *src)) ^ 0x80);
icculus@1982
   288
        *dst = val;
icculus@1982
   289
    }
icculus@1982
   290
icculus@1982
   291
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   292
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
icculus@1982
   293
    }
icculus@1982
   294
}
icculus@1982
   295
icculus@1982
   296
static void SDLCALL
icculus@1982
   297
SDL_Convert_S8_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   298
{
icculus@1982
   299
    int i;
icculus@1982
   300
    const Uint8 *src;
icculus@1982
   301
    Uint16 *dst;
icculus@1982
   302
slouken@3032
   303
#if DEBUG_CONVERT
icculus@1982
   304
    fprintf(stderr, "Converting AUDIO_S8 to AUDIO_U16LSB.\n");
icculus@1982
   305
#endif
icculus@1982
   306
icculus@2956
   307
    src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   308
    dst = ((Uint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
   309
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
icculus@1982
   310
        const Uint16 val = (((Uint16) ((((Sint8) *src)) ^ 0x80)) << 8);
icculus@1982
   311
        *dst = SDL_SwapLE16(val);
icculus@1982
   312
    }
icculus@1982
   313
icculus@1982
   314
    cvt->len_cvt *= 2;
icculus@1982
   315
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   316
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
icculus@1982
   317
    }
icculus@1982
   318
}
icculus@1982
   319
icculus@1982
   320
static void SDLCALL
icculus@1982
   321
SDL_Convert_S8_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   322
{
icculus@1982
   323
    int i;
icculus@1982
   324
    const Uint8 *src;
icculus@1982
   325
    Sint16 *dst;
icculus@1982
   326
slouken@3032
   327
#if DEBUG_CONVERT
icculus@1982
   328
    fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S16LSB.\n");
icculus@1982
   329
#endif
icculus@1982
   330
icculus@2956
   331
    src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   332
    dst = ((Sint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
   333
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
icculus@1982
   334
        const Sint16 val = (((Sint16) ((Sint8) *src)) << 8);
icculus@1982
   335
        *dst = ((Sint16) SDL_SwapLE16(val));
icculus@1982
   336
    }
icculus@1982
   337
icculus@1982
   338
    cvt->len_cvt *= 2;
icculus@1982
   339
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   340
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
icculus@1982
   341
    }
icculus@1982
   342
}
icculus@1982
   343
icculus@1982
   344
static void SDLCALL
icculus@1982
   345
SDL_Convert_S8_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   346
{
icculus@1982
   347
    int i;
icculus@1982
   348
    const Uint8 *src;
icculus@1982
   349
    Uint16 *dst;
icculus@1982
   350
slouken@3032
   351
#if DEBUG_CONVERT
icculus@1982
   352
    fprintf(stderr, "Converting AUDIO_S8 to AUDIO_U16MSB.\n");
icculus@1982
   353
#endif
icculus@1982
   354
icculus@2956
   355
    src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   356
    dst = ((Uint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
   357
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
icculus@1982
   358
        const Uint16 val = (((Uint16) ((((Sint8) *src)) ^ 0x80)) << 8);
icculus@1982
   359
        *dst = SDL_SwapBE16(val);
icculus@1982
   360
    }
icculus@1982
   361
icculus@1982
   362
    cvt->len_cvt *= 2;
icculus@1982
   363
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   364
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
icculus@1982
   365
    }
icculus@1982
   366
}
icculus@1982
   367
icculus@1982
   368
static void SDLCALL
icculus@1982
   369
SDL_Convert_S8_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   370
{
icculus@1982
   371
    int i;
icculus@1982
   372
    const Uint8 *src;
icculus@1982
   373
    Sint16 *dst;
icculus@1982
   374
slouken@3032
   375
#if DEBUG_CONVERT
icculus@1982
   376
    fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S16MSB.\n");
icculus@1982
   377
#endif
icculus@1982
   378
icculus@2956
   379
    src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   380
    dst = ((Sint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
   381
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
icculus@1982
   382
        const Sint16 val = (((Sint16) ((Sint8) *src)) << 8);
icculus@1982
   383
        *dst = ((Sint16) SDL_SwapBE16(val));
icculus@1982
   384
    }
icculus@1982
   385
icculus@1982
   386
    cvt->len_cvt *= 2;
icculus@1982
   387
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   388
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
icculus@1982
   389
    }
icculus@1982
   390
}
icculus@1982
   391
icculus@1982
   392
static void SDLCALL
icculus@1982
   393
SDL_Convert_S8_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   394
{
icculus@1982
   395
    int i;
icculus@1982
   396
    const Uint8 *src;
icculus@1982
   397
    Sint32 *dst;
icculus@1982
   398
slouken@3032
   399
#if DEBUG_CONVERT
icculus@1982
   400
    fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S32LSB.\n");
icculus@1982
   401
#endif
icculus@1982
   402
icculus@2956
   403
    src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   404
    dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 4)) - 1;
icculus@1982
   405
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
icculus@1982
   406
        const Sint32 val = (((Sint32) ((Sint8) *src)) << 24);
icculus@1982
   407
        *dst = ((Sint32) SDL_SwapLE32(val));
icculus@1982
   408
    }
icculus@1982
   409
icculus@1982
   410
    cvt->len_cvt *= 4;
icculus@1982
   411
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   412
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
icculus@1982
   413
    }
icculus@1982
   414
}
icculus@1982
   415
icculus@1982
   416
static void SDLCALL
icculus@1982
   417
SDL_Convert_S8_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   418
{
icculus@1982
   419
    int i;
icculus@1982
   420
    const Uint8 *src;
icculus@1982
   421
    Sint32 *dst;
icculus@1982
   422
slouken@3032
   423
#if DEBUG_CONVERT
icculus@1982
   424
    fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S32MSB.\n");
icculus@1982
   425
#endif
icculus@1982
   426
icculus@2956
   427
    src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   428
    dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 4)) - 1;
icculus@1982
   429
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
icculus@1982
   430
        const Sint32 val = (((Sint32) ((Sint8) *src)) << 24);
icculus@1982
   431
        *dst = ((Sint32) SDL_SwapBE32(val));
icculus@1982
   432
    }
icculus@1982
   433
icculus@1982
   434
    cvt->len_cvt *= 4;
icculus@1982
   435
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   436
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
icculus@1982
   437
    }
icculus@1982
   438
}
icculus@1982
   439
icculus@1982
   440
static void SDLCALL
icculus@1982
   441
SDL_Convert_S8_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   442
{
icculus@1982
   443
    int i;
icculus@1982
   444
    const Uint8 *src;
icculus@1982
   445
    float *dst;
icculus@1982
   446
slouken@3032
   447
#if DEBUG_CONVERT
icculus@1982
   448
    fprintf(stderr, "Converting AUDIO_S8 to AUDIO_F32LSB.\n");
icculus@1982
   449
#endif
icculus@1982
   450
icculus@2956
   451
    src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   452
    dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
icculus@1982
   453
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
icculus@1982
   454
        const float val = (((float) ((Sint8) *src)) * DIVBY127);
icculus@1982
   455
        *dst = SDL_SwapFloatLE(val);
icculus@1982
   456
    }
icculus@1982
   457
icculus@1982
   458
    cvt->len_cvt *= 4;
icculus@1982
   459
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   460
        cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
icculus@1982
   461
    }
icculus@1982
   462
}
icculus@1982
   463
icculus@1982
   464
static void SDLCALL
icculus@1982
   465
SDL_Convert_S8_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   466
{
icculus@1982
   467
    int i;
icculus@1982
   468
    const Uint8 *src;
icculus@1982
   469
    float *dst;
icculus@1982
   470
slouken@3032
   471
#if DEBUG_CONVERT
icculus@1982
   472
    fprintf(stderr, "Converting AUDIO_S8 to AUDIO_F32MSB.\n");
icculus@1982
   473
#endif
icculus@1982
   474
icculus@2956
   475
    src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   476
    dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
icculus@1982
   477
    for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
icculus@1982
   478
        const float val = (((float) ((Sint8) *src)) * DIVBY127);
icculus@1982
   479
        *dst = SDL_SwapFloatBE(val);
icculus@1982
   480
    }
icculus@1982
   481
icculus@1982
   482
    cvt->len_cvt *= 4;
icculus@1982
   483
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   484
        cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
icculus@1982
   485
    }
icculus@1982
   486
}
icculus@1982
   487
icculus@1982
   488
static void SDLCALL
icculus@1982
   489
SDL_Convert_U16LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   490
{
icculus@1982
   491
    int i;
icculus@1982
   492
    const Uint16 *src;
icculus@1982
   493
    Uint8 *dst;
icculus@1982
   494
slouken@3032
   495
#if DEBUG_CONVERT
icculus@1982
   496
    fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_U8.\n");
icculus@1982
   497
#endif
icculus@1982
   498
icculus@1982
   499
    src = (const Uint16 *) cvt->buf;
icculus@1982
   500
    dst = (Uint8 *) cvt->buf;
icculus@1982
   501
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
   502
        const Uint8 val = ((Uint8) (SDL_SwapLE16(*src) >> 8));
icculus@1982
   503
        *dst = val;
icculus@1982
   504
    }
icculus@1982
   505
icculus@1982
   506
    cvt->len_cvt /= 2;
icculus@1982
   507
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   508
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
icculus@1982
   509
    }
icculus@1982
   510
}
icculus@1982
   511
icculus@1982
   512
static void SDLCALL
icculus@1982
   513
SDL_Convert_U16LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   514
{
icculus@1982
   515
    int i;
icculus@1982
   516
    const Uint16 *src;
icculus@1982
   517
    Sint8 *dst;
icculus@1982
   518
slouken@3032
   519
#if DEBUG_CONVERT
icculus@1982
   520
    fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S8.\n");
icculus@1982
   521
#endif
icculus@1982
   522
icculus@1982
   523
    src = (const Uint16 *) cvt->buf;
icculus@1982
   524
    dst = (Sint8 *) cvt->buf;
icculus@1982
   525
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
   526
        const Sint8 val = ((Sint8) (((SDL_SwapLE16(*src)) ^ 0x8000) >> 8));
icculus@1982
   527
        *dst = ((Sint8) val);
icculus@1982
   528
    }
icculus@1982
   529
icculus@1982
   530
    cvt->len_cvt /= 2;
icculus@1982
   531
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   532
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
icculus@1982
   533
    }
icculus@1982
   534
}
icculus@1982
   535
icculus@1982
   536
static void SDLCALL
icculus@1982
   537
SDL_Convert_U16LSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   538
{
icculus@1982
   539
    int i;
icculus@1982
   540
    const Uint16 *src;
icculus@1982
   541
    Sint16 *dst;
icculus@1982
   542
slouken@3032
   543
#if DEBUG_CONVERT
icculus@1982
   544
    fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S16LSB.\n");
icculus@1982
   545
#endif
icculus@1982
   546
icculus@1982
   547
    src = (const Uint16 *) cvt->buf;
icculus@1982
   548
    dst = (Sint16 *) cvt->buf;
icculus@1982
   549
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
   550
        const Sint16 val = ((SDL_SwapLE16(*src)) ^ 0x8000);
icculus@1982
   551
        *dst = ((Sint16) SDL_SwapLE16(val));
icculus@1982
   552
    }
icculus@1982
   553
icculus@1982
   554
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   555
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
icculus@1982
   556
    }
icculus@1982
   557
}
icculus@1982
   558
icculus@1982
   559
static void SDLCALL
icculus@1982
   560
SDL_Convert_U16LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   561
{
icculus@1982
   562
    int i;
icculus@1982
   563
    const Uint16 *src;
icculus@1982
   564
    Uint16 *dst;
icculus@1982
   565
slouken@3032
   566
#if DEBUG_CONVERT
icculus@1982
   567
    fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_U16MSB.\n");
icculus@1982
   568
#endif
icculus@1982
   569
icculus@1982
   570
    src = (const Uint16 *) cvt->buf;
icculus@1982
   571
    dst = (Uint16 *) cvt->buf;
icculus@1982
   572
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
   573
        const Uint16 val = SDL_SwapLE16(*src);
icculus@1982
   574
        *dst = SDL_SwapBE16(val);
icculus@1982
   575
    }
icculus@1982
   576
icculus@1982
   577
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   578
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
icculus@1982
   579
    }
icculus@1982
   580
}
icculus@1982
   581
icculus@1982
   582
static void SDLCALL
icculus@1982
   583
SDL_Convert_U16LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   584
{
icculus@1982
   585
    int i;
icculus@1982
   586
    const Uint16 *src;
icculus@1982
   587
    Sint16 *dst;
icculus@1982
   588
slouken@3032
   589
#if DEBUG_CONVERT
icculus@1982
   590
    fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S16MSB.\n");
icculus@1982
   591
#endif
icculus@1982
   592
icculus@1982
   593
    src = (const Uint16 *) cvt->buf;
icculus@1982
   594
    dst = (Sint16 *) cvt->buf;
icculus@1982
   595
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
   596
        const Sint16 val = ((SDL_SwapLE16(*src)) ^ 0x8000);
icculus@1982
   597
        *dst = ((Sint16) SDL_SwapBE16(val));
icculus@1982
   598
    }
icculus@1982
   599
icculus@1982
   600
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   601
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
icculus@1982
   602
    }
icculus@1982
   603
}
icculus@1982
   604
icculus@1982
   605
static void SDLCALL
icculus@1982
   606
SDL_Convert_U16LSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   607
{
icculus@1982
   608
    int i;
icculus@1982
   609
    const Uint16 *src;
icculus@1982
   610
    Sint32 *dst;
icculus@1982
   611
slouken@3032
   612
#if DEBUG_CONVERT
icculus@1982
   613
    fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S32LSB.\n");
icculus@1982
   614
#endif
icculus@1982
   615
icculus@2956
   616
    src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   617
    dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
   618
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
icculus@1982
   619
        const Sint32 val = (((Sint32) ((SDL_SwapLE16(*src)) ^ 0x8000)) << 16);
icculus@1982
   620
        *dst = ((Sint32) SDL_SwapLE32(val));
icculus@1982
   621
    }
icculus@1982
   622
icculus@1982
   623
    cvt->len_cvt *= 2;
icculus@1982
   624
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   625
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
icculus@1982
   626
    }
icculus@1982
   627
}
icculus@1982
   628
icculus@1982
   629
static void SDLCALL
icculus@1982
   630
SDL_Convert_U16LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   631
{
icculus@1982
   632
    int i;
icculus@1982
   633
    const Uint16 *src;
icculus@1982
   634
    Sint32 *dst;
icculus@1982
   635
slouken@3032
   636
#if DEBUG_CONVERT
icculus@1982
   637
    fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S32MSB.\n");
icculus@1982
   638
#endif
icculus@1982
   639
icculus@2956
   640
    src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   641
    dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
   642
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
icculus@1982
   643
        const Sint32 val = (((Sint32) ((SDL_SwapLE16(*src)) ^ 0x8000)) << 16);
icculus@1982
   644
        *dst = ((Sint32) SDL_SwapBE32(val));
icculus@1982
   645
    }
icculus@1982
   646
icculus@1982
   647
    cvt->len_cvt *= 2;
icculus@1982
   648
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   649
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
icculus@1982
   650
    }
icculus@1982
   651
}
icculus@1982
   652
icculus@1982
   653
static void SDLCALL
icculus@1982
   654
SDL_Convert_U16LSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   655
{
icculus@1982
   656
    int i;
icculus@1982
   657
    const Uint16 *src;
icculus@1982
   658
    float *dst;
icculus@1982
   659
slouken@3032
   660
#if DEBUG_CONVERT
icculus@1982
   661
    fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_F32LSB.\n");
icculus@1982
   662
#endif
icculus@1982
   663
icculus@2956
   664
    src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   665
    dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
   666
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
icculus@2011
   667
        const float val = ((((float) SDL_SwapLE16(*src)) * DIVBY32767) - 1.0f);
icculus@1982
   668
        *dst = SDL_SwapFloatLE(val);
icculus@1982
   669
    }
icculus@1982
   670
icculus@1982
   671
    cvt->len_cvt *= 2;
icculus@1982
   672
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   673
        cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
icculus@1982
   674
    }
icculus@1982
   675
}
icculus@1982
   676
icculus@1982
   677
static void SDLCALL
icculus@1982
   678
SDL_Convert_U16LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   679
{
icculus@1982
   680
    int i;
icculus@1982
   681
    const Uint16 *src;
icculus@1982
   682
    float *dst;
icculus@1982
   683
slouken@3032
   684
#if DEBUG_CONVERT
icculus@1982
   685
    fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_F32MSB.\n");
icculus@1982
   686
#endif
icculus@1982
   687
icculus@2956
   688
    src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   689
    dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
   690
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
icculus@2011
   691
        const float val = ((((float) SDL_SwapLE16(*src)) * DIVBY32767) - 1.0f);
icculus@1982
   692
        *dst = SDL_SwapFloatBE(val);
icculus@1982
   693
    }
icculus@1982
   694
icculus@1982
   695
    cvt->len_cvt *= 2;
icculus@1982
   696
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   697
        cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
icculus@1982
   698
    }
icculus@1982
   699
}
icculus@1982
   700
icculus@1982
   701
static void SDLCALL
icculus@1982
   702
SDL_Convert_S16LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   703
{
icculus@1982
   704
    int i;
icculus@1982
   705
    const Uint16 *src;
icculus@1982
   706
    Uint8 *dst;
icculus@1982
   707
slouken@3032
   708
#if DEBUG_CONVERT
icculus@1982
   709
    fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_U8.\n");
icculus@1982
   710
#endif
icculus@1982
   711
icculus@1982
   712
    src = (const Uint16 *) cvt->buf;
icculus@1982
   713
    dst = (Uint8 *) cvt->buf;
icculus@1982
   714
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
   715
        const Uint8 val = ((Uint8) (((((Sint16) SDL_SwapLE16(*src))) ^ 0x8000) >> 8));
icculus@1982
   716
        *dst = val;
icculus@1982
   717
    }
icculus@1982
   718
icculus@1982
   719
    cvt->len_cvt /= 2;
icculus@1982
   720
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   721
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
icculus@1982
   722
    }
icculus@1982
   723
}
icculus@1982
   724
icculus@1982
   725
static void SDLCALL
icculus@1982
   726
SDL_Convert_S16LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   727
{
icculus@1982
   728
    int i;
icculus@1982
   729
    const Uint16 *src;
icculus@1982
   730
    Sint8 *dst;
icculus@1982
   731
slouken@3032
   732
#if DEBUG_CONVERT
icculus@1982
   733
    fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S8.\n");
icculus@1982
   734
#endif
icculus@1982
   735
icculus@1982
   736
    src = (const Uint16 *) cvt->buf;
icculus@1982
   737
    dst = (Sint8 *) cvt->buf;
icculus@1982
   738
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
   739
        const Sint8 val = ((Sint8) (((Sint16) SDL_SwapLE16(*src)) >> 8));
icculus@1982
   740
        *dst = ((Sint8) val);
icculus@1982
   741
    }
icculus@1982
   742
icculus@1982
   743
    cvt->len_cvt /= 2;
icculus@1982
   744
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   745
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
icculus@1982
   746
    }
icculus@1982
   747
}
icculus@1982
   748
icculus@1982
   749
static void SDLCALL
icculus@1982
   750
SDL_Convert_S16LSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   751
{
icculus@1982
   752
    int i;
icculus@1982
   753
    const Uint16 *src;
icculus@1982
   754
    Uint16 *dst;
icculus@1982
   755
slouken@3032
   756
#if DEBUG_CONVERT
icculus@1982
   757
    fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_U16LSB.\n");
icculus@1982
   758
#endif
icculus@1982
   759
icculus@1982
   760
    src = (const Uint16 *) cvt->buf;
icculus@1982
   761
    dst = (Uint16 *) cvt->buf;
icculus@1982
   762
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
   763
        const Uint16 val = ((((Sint16) SDL_SwapLE16(*src))) ^ 0x8000);
icculus@1982
   764
        *dst = SDL_SwapLE16(val);
icculus@1982
   765
    }
icculus@1982
   766
icculus@1982
   767
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   768
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
icculus@1982
   769
    }
icculus@1982
   770
}
icculus@1982
   771
icculus@1982
   772
static void SDLCALL
icculus@1982
   773
SDL_Convert_S16LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   774
{
icculus@1982
   775
    int i;
icculus@1982
   776
    const Uint16 *src;
icculus@1982
   777
    Uint16 *dst;
icculus@1982
   778
slouken@3032
   779
#if DEBUG_CONVERT
icculus@1982
   780
    fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_U16MSB.\n");
icculus@1982
   781
#endif
icculus@1982
   782
icculus@1982
   783
    src = (const Uint16 *) cvt->buf;
icculus@1982
   784
    dst = (Uint16 *) cvt->buf;
icculus@1982
   785
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
   786
        const Uint16 val = ((((Sint16) SDL_SwapLE16(*src))) ^ 0x8000);
icculus@1982
   787
        *dst = SDL_SwapBE16(val);
icculus@1982
   788
    }
icculus@1982
   789
icculus@1982
   790
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   791
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
icculus@1982
   792
    }
icculus@1982
   793
}
icculus@1982
   794
icculus@1982
   795
static void SDLCALL
icculus@1982
   796
SDL_Convert_S16LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   797
{
icculus@1982
   798
    int i;
icculus@1982
   799
    const Uint16 *src;
icculus@1982
   800
    Sint16 *dst;
icculus@1982
   801
slouken@3032
   802
#if DEBUG_CONVERT
icculus@1982
   803
    fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S16MSB.\n");
icculus@1982
   804
#endif
icculus@1982
   805
icculus@1982
   806
    src = (const Uint16 *) cvt->buf;
icculus@1982
   807
    dst = (Sint16 *) cvt->buf;
icculus@1982
   808
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
   809
        const Sint16 val = ((Sint16) SDL_SwapLE16(*src));
icculus@1982
   810
        *dst = ((Sint16) SDL_SwapBE16(val));
icculus@1982
   811
    }
icculus@1982
   812
icculus@1982
   813
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   814
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
icculus@1982
   815
    }
icculus@1982
   816
}
icculus@1982
   817
icculus@1982
   818
static void SDLCALL
icculus@1982
   819
SDL_Convert_S16LSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   820
{
icculus@1982
   821
    int i;
icculus@1982
   822
    const Uint16 *src;
icculus@1982
   823
    Sint32 *dst;
icculus@1982
   824
slouken@3032
   825
#if DEBUG_CONVERT
icculus@1982
   826
    fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S32LSB.\n");
icculus@1982
   827
#endif
icculus@1982
   828
icculus@2956
   829
    src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   830
    dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
   831
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
icculus@1982
   832
        const Sint32 val = (((Sint32) ((Sint16) SDL_SwapLE16(*src))) << 16);
icculus@1982
   833
        *dst = ((Sint32) SDL_SwapLE32(val));
icculus@1982
   834
    }
icculus@1982
   835
icculus@1982
   836
    cvt->len_cvt *= 2;
icculus@1982
   837
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   838
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
icculus@1982
   839
    }
icculus@1982
   840
}
icculus@1982
   841
icculus@1982
   842
static void SDLCALL
icculus@1982
   843
SDL_Convert_S16LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   844
{
icculus@1982
   845
    int i;
icculus@1982
   846
    const Uint16 *src;
icculus@1982
   847
    Sint32 *dst;
icculus@1982
   848
slouken@3032
   849
#if DEBUG_CONVERT
icculus@1982
   850
    fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S32MSB.\n");
icculus@1982
   851
#endif
icculus@1982
   852
icculus@2956
   853
    src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   854
    dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
   855
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
icculus@1982
   856
        const Sint32 val = (((Sint32) ((Sint16) SDL_SwapLE16(*src))) << 16);
icculus@1982
   857
        *dst = ((Sint32) SDL_SwapBE32(val));
icculus@1982
   858
    }
icculus@1982
   859
icculus@1982
   860
    cvt->len_cvt *= 2;
icculus@1982
   861
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   862
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
icculus@1982
   863
    }
icculus@1982
   864
}
icculus@1982
   865
icculus@1982
   866
static void SDLCALL
icculus@1982
   867
SDL_Convert_S16LSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   868
{
icculus@1982
   869
    int i;
icculus@1982
   870
    const Uint16 *src;
icculus@1982
   871
    float *dst;
icculus@1982
   872
slouken@3032
   873
#if DEBUG_CONVERT
icculus@1982
   874
    fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_F32LSB.\n");
icculus@1982
   875
#endif
icculus@1982
   876
icculus@2956
   877
    src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   878
    dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
   879
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
icculus@1982
   880
        const float val = (((float) ((Sint16) SDL_SwapLE16(*src))) * DIVBY32767);
icculus@1982
   881
        *dst = SDL_SwapFloatLE(val);
icculus@1982
   882
    }
icculus@1982
   883
icculus@1982
   884
    cvt->len_cvt *= 2;
icculus@1982
   885
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   886
        cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
icculus@1982
   887
    }
icculus@1982
   888
}
icculus@1982
   889
icculus@1982
   890
static void SDLCALL
icculus@1982
   891
SDL_Convert_S16LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   892
{
icculus@1982
   893
    int i;
icculus@1982
   894
    const Uint16 *src;
icculus@1982
   895
    float *dst;
icculus@1982
   896
slouken@3032
   897
#if DEBUG_CONVERT
icculus@1982
   898
    fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_F32MSB.\n");
icculus@1982
   899
#endif
icculus@1982
   900
icculus@2956
   901
    src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
   902
    dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
   903
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
icculus@1982
   904
        const float val = (((float) ((Sint16) SDL_SwapLE16(*src))) * DIVBY32767);
icculus@1982
   905
        *dst = SDL_SwapFloatBE(val);
icculus@1982
   906
    }
icculus@1982
   907
icculus@1982
   908
    cvt->len_cvt *= 2;
icculus@1982
   909
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   910
        cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
icculus@1982
   911
    }
icculus@1982
   912
}
icculus@1982
   913
icculus@1982
   914
static void SDLCALL
icculus@1982
   915
SDL_Convert_U16MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   916
{
icculus@1982
   917
    int i;
icculus@1982
   918
    const Uint16 *src;
icculus@1982
   919
    Uint8 *dst;
icculus@1982
   920
slouken@3032
   921
#if DEBUG_CONVERT
icculus@1982
   922
    fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_U8.\n");
icculus@1982
   923
#endif
icculus@1982
   924
icculus@1982
   925
    src = (const Uint16 *) cvt->buf;
icculus@1982
   926
    dst = (Uint8 *) cvt->buf;
icculus@1982
   927
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
   928
        const Uint8 val = ((Uint8) (SDL_SwapBE16(*src) >> 8));
icculus@1982
   929
        *dst = val;
icculus@1982
   930
    }
icculus@1982
   931
icculus@1982
   932
    cvt->len_cvt /= 2;
icculus@1982
   933
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   934
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
icculus@1982
   935
    }
icculus@1982
   936
}
icculus@1982
   937
icculus@1982
   938
static void SDLCALL
icculus@1982
   939
SDL_Convert_U16MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   940
{
icculus@1982
   941
    int i;
icculus@1982
   942
    const Uint16 *src;
icculus@1982
   943
    Sint8 *dst;
icculus@1982
   944
slouken@3032
   945
#if DEBUG_CONVERT
icculus@1982
   946
    fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S8.\n");
icculus@1982
   947
#endif
icculus@1982
   948
icculus@1982
   949
    src = (const Uint16 *) cvt->buf;
icculus@1982
   950
    dst = (Sint8 *) cvt->buf;
icculus@1982
   951
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
   952
        const Sint8 val = ((Sint8) (((SDL_SwapBE16(*src)) ^ 0x8000) >> 8));
icculus@1982
   953
        *dst = ((Sint8) val);
icculus@1982
   954
    }
icculus@1982
   955
icculus@1982
   956
    cvt->len_cvt /= 2;
icculus@1982
   957
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   958
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
icculus@1982
   959
    }
icculus@1982
   960
}
icculus@1982
   961
icculus@1982
   962
static void SDLCALL
icculus@1982
   963
SDL_Convert_U16MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   964
{
icculus@1982
   965
    int i;
icculus@1982
   966
    const Uint16 *src;
icculus@1982
   967
    Uint16 *dst;
icculus@1982
   968
slouken@3032
   969
#if DEBUG_CONVERT
icculus@1982
   970
    fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_U16LSB.\n");
icculus@1982
   971
#endif
icculus@1982
   972
icculus@1982
   973
    src = (const Uint16 *) cvt->buf;
icculus@1982
   974
    dst = (Uint16 *) cvt->buf;
icculus@1982
   975
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
   976
        const Uint16 val = SDL_SwapBE16(*src);
icculus@1982
   977
        *dst = SDL_SwapLE16(val);
icculus@1982
   978
    }
icculus@1982
   979
icculus@1982
   980
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
   981
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
icculus@1982
   982
    }
icculus@1982
   983
}
icculus@1982
   984
icculus@1982
   985
static void SDLCALL
icculus@1982
   986
SDL_Convert_U16MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
   987
{
icculus@1982
   988
    int i;
icculus@1982
   989
    const Uint16 *src;
icculus@1982
   990
    Sint16 *dst;
icculus@1982
   991
slouken@3032
   992
#if DEBUG_CONVERT
icculus@1982
   993
    fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S16LSB.\n");
icculus@1982
   994
#endif
icculus@1982
   995
icculus@1982
   996
    src = (const Uint16 *) cvt->buf;
icculus@1982
   997
    dst = (Sint16 *) cvt->buf;
icculus@1982
   998
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
   999
        const Sint16 val = ((SDL_SwapBE16(*src)) ^ 0x8000);
icculus@1982
  1000
        *dst = ((Sint16) SDL_SwapLE16(val));
icculus@1982
  1001
    }
icculus@1982
  1002
icculus@1982
  1003
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1004
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
icculus@1982
  1005
    }
icculus@1982
  1006
}
icculus@1982
  1007
icculus@1982
  1008
static void SDLCALL
icculus@1982
  1009
SDL_Convert_U16MSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1010
{
icculus@1982
  1011
    int i;
icculus@1982
  1012
    const Uint16 *src;
icculus@1982
  1013
    Sint16 *dst;
icculus@1982
  1014
slouken@3032
  1015
#if DEBUG_CONVERT
icculus@1982
  1016
    fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S16MSB.\n");
icculus@1982
  1017
#endif
icculus@1982
  1018
icculus@1982
  1019
    src = (const Uint16 *) cvt->buf;
icculus@1982
  1020
    dst = (Sint16 *) cvt->buf;
icculus@1982
  1021
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
  1022
        const Sint16 val = ((SDL_SwapBE16(*src)) ^ 0x8000);
icculus@1982
  1023
        *dst = ((Sint16) SDL_SwapBE16(val));
icculus@1982
  1024
    }
icculus@1982
  1025
icculus@1982
  1026
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1027
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
icculus@1982
  1028
    }
icculus@1982
  1029
}
icculus@1982
  1030
icculus@1982
  1031
static void SDLCALL
icculus@1982
  1032
SDL_Convert_U16MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1033
{
icculus@1982
  1034
    int i;
icculus@1982
  1035
    const Uint16 *src;
icculus@1982
  1036
    Sint32 *dst;
icculus@1982
  1037
slouken@3032
  1038
#if DEBUG_CONVERT
icculus@1982
  1039
    fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S32LSB.\n");
icculus@1982
  1040
#endif
icculus@1982
  1041
icculus@2956
  1042
    src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
  1043
    dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
  1044
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
icculus@1982
  1045
        const Sint32 val = (((Sint32) ((SDL_SwapBE16(*src)) ^ 0x8000)) << 16);
icculus@1982
  1046
        *dst = ((Sint32) SDL_SwapLE32(val));
icculus@1982
  1047
    }
icculus@1982
  1048
icculus@1982
  1049
    cvt->len_cvt *= 2;
icculus@1982
  1050
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1051
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
icculus@1982
  1052
    }
icculus@1982
  1053
}
icculus@1982
  1054
icculus@1982
  1055
static void SDLCALL
icculus@1982
  1056
SDL_Convert_U16MSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1057
{
icculus@1982
  1058
    int i;
icculus@1982
  1059
    const Uint16 *src;
icculus@1982
  1060
    Sint32 *dst;
icculus@1982
  1061
slouken@3032
  1062
#if DEBUG_CONVERT
icculus@1982
  1063
    fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S32MSB.\n");
icculus@1982
  1064
#endif
icculus@1982
  1065
icculus@2956
  1066
    src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
  1067
    dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
  1068
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
icculus@1982
  1069
        const Sint32 val = (((Sint32) ((SDL_SwapBE16(*src)) ^ 0x8000)) << 16);
icculus@1982
  1070
        *dst = ((Sint32) SDL_SwapBE32(val));
icculus@1982
  1071
    }
icculus@1982
  1072
icculus@1982
  1073
    cvt->len_cvt *= 2;
icculus@1982
  1074
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1075
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
icculus@1982
  1076
    }
icculus@1982
  1077
}
icculus@1982
  1078
icculus@1982
  1079
static void SDLCALL
icculus@1982
  1080
SDL_Convert_U16MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1081
{
icculus@1982
  1082
    int i;
icculus@1982
  1083
    const Uint16 *src;
icculus@1982
  1084
    float *dst;
icculus@1982
  1085
slouken@3032
  1086
#if DEBUG_CONVERT
icculus@1982
  1087
    fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_F32LSB.\n");
icculus@1982
  1088
#endif
icculus@1982
  1089
icculus@2956
  1090
    src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
  1091
    dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
  1092
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
icculus@2011
  1093
        const float val = ((((float) SDL_SwapBE16(*src)) * DIVBY32767) - 1.0f);
icculus@1982
  1094
        *dst = SDL_SwapFloatLE(val);
icculus@1982
  1095
    }
icculus@1982
  1096
icculus@1982
  1097
    cvt->len_cvt *= 2;
icculus@1982
  1098
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1099
        cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
icculus@1982
  1100
    }
icculus@1982
  1101
}
icculus@1982
  1102
icculus@1982
  1103
static void SDLCALL
icculus@1982
  1104
SDL_Convert_U16MSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1105
{
icculus@1982
  1106
    int i;
icculus@1982
  1107
    const Uint16 *src;
icculus@1982
  1108
    float *dst;
icculus@1982
  1109
slouken@3032
  1110
#if DEBUG_CONVERT
icculus@1982
  1111
    fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_F32MSB.\n");
icculus@1982
  1112
#endif
icculus@1982
  1113
icculus@2956
  1114
    src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
  1115
    dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
  1116
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
icculus@2011
  1117
        const float val = ((((float) SDL_SwapBE16(*src)) * DIVBY32767) - 1.0f);
icculus@1982
  1118
        *dst = SDL_SwapFloatBE(val);
icculus@1982
  1119
    }
icculus@1982
  1120
icculus@1982
  1121
    cvt->len_cvt *= 2;
icculus@1982
  1122
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1123
        cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
icculus@1982
  1124
    }
icculus@1982
  1125
}
icculus@1982
  1126
icculus@1982
  1127
static void SDLCALL
icculus@1982
  1128
SDL_Convert_S16MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1129
{
icculus@1982
  1130
    int i;
icculus@1982
  1131
    const Uint16 *src;
icculus@1982
  1132
    Uint8 *dst;
icculus@1982
  1133
slouken@3032
  1134
#if DEBUG_CONVERT
icculus@1982
  1135
    fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_U8.\n");
icculus@1982
  1136
#endif
icculus@1982
  1137
icculus@1982
  1138
    src = (const Uint16 *) cvt->buf;
icculus@1982
  1139
    dst = (Uint8 *) cvt->buf;
icculus@1982
  1140
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
  1141
        const Uint8 val = ((Uint8) (((((Sint16) SDL_SwapBE16(*src))) ^ 0x8000) >> 8));
icculus@1982
  1142
        *dst = val;
icculus@1982
  1143
    }
icculus@1982
  1144
icculus@1982
  1145
    cvt->len_cvt /= 2;
icculus@1982
  1146
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1147
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
icculus@1982
  1148
    }
icculus@1982
  1149
}
icculus@1982
  1150
icculus@1982
  1151
static void SDLCALL
icculus@1982
  1152
SDL_Convert_S16MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1153
{
icculus@1982
  1154
    int i;
icculus@1982
  1155
    const Uint16 *src;
icculus@1982
  1156
    Sint8 *dst;
icculus@1982
  1157
slouken@3032
  1158
#if DEBUG_CONVERT
icculus@1982
  1159
    fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S8.\n");
icculus@1982
  1160
#endif
icculus@1982
  1161
icculus@1982
  1162
    src = (const Uint16 *) cvt->buf;
icculus@1982
  1163
    dst = (Sint8 *) cvt->buf;
icculus@1982
  1164
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
  1165
        const Sint8 val = ((Sint8) (((Sint16) SDL_SwapBE16(*src)) >> 8));
icculus@1982
  1166
        *dst = ((Sint8) val);
icculus@1982
  1167
    }
icculus@1982
  1168
icculus@1982
  1169
    cvt->len_cvt /= 2;
icculus@1982
  1170
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1171
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
icculus@1982
  1172
    }
icculus@1982
  1173
}
icculus@1982
  1174
icculus@1982
  1175
static void SDLCALL
icculus@1982
  1176
SDL_Convert_S16MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1177
{
icculus@1982
  1178
    int i;
icculus@1982
  1179
    const Uint16 *src;
icculus@1982
  1180
    Uint16 *dst;
icculus@1982
  1181
slouken@3032
  1182
#if DEBUG_CONVERT
icculus@1982
  1183
    fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_U16LSB.\n");
icculus@1982
  1184
#endif
icculus@1982
  1185
icculus@1982
  1186
    src = (const Uint16 *) cvt->buf;
icculus@1982
  1187
    dst = (Uint16 *) cvt->buf;
icculus@1982
  1188
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
  1189
        const Uint16 val = ((((Sint16) SDL_SwapBE16(*src))) ^ 0x8000);
icculus@1982
  1190
        *dst = SDL_SwapLE16(val);
icculus@1982
  1191
    }
icculus@1982
  1192
icculus@1982
  1193
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1194
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
icculus@1982
  1195
    }
icculus@1982
  1196
}
icculus@1982
  1197
icculus@1982
  1198
static void SDLCALL
icculus@1982
  1199
SDL_Convert_S16MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1200
{
icculus@1982
  1201
    int i;
icculus@1982
  1202
    const Uint16 *src;
icculus@1982
  1203
    Sint16 *dst;
icculus@1982
  1204
slouken@3032
  1205
#if DEBUG_CONVERT
icculus@1982
  1206
    fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S16LSB.\n");
icculus@1982
  1207
#endif
icculus@1982
  1208
icculus@1982
  1209
    src = (const Uint16 *) cvt->buf;
icculus@1982
  1210
    dst = (Sint16 *) cvt->buf;
icculus@1982
  1211
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
  1212
        const Sint16 val = ((Sint16) SDL_SwapBE16(*src));
icculus@1982
  1213
        *dst = ((Sint16) SDL_SwapLE16(val));
icculus@1982
  1214
    }
icculus@1982
  1215
icculus@1982
  1216
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1217
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
icculus@1982
  1218
    }
icculus@1982
  1219
}
icculus@1982
  1220
icculus@1982
  1221
static void SDLCALL
icculus@1982
  1222
SDL_Convert_S16MSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1223
{
icculus@1982
  1224
    int i;
icculus@1982
  1225
    const Uint16 *src;
icculus@1982
  1226
    Uint16 *dst;
icculus@1982
  1227
slouken@3032
  1228
#if DEBUG_CONVERT
icculus@1982
  1229
    fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_U16MSB.\n");
icculus@1982
  1230
#endif
icculus@1982
  1231
icculus@1982
  1232
    src = (const Uint16 *) cvt->buf;
icculus@1982
  1233
    dst = (Uint16 *) cvt->buf;
icculus@1982
  1234
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
icculus@1982
  1235
        const Uint16 val = ((((Sint16) SDL_SwapBE16(*src))) ^ 0x8000);
icculus@1982
  1236
        *dst = SDL_SwapBE16(val);
icculus@1982
  1237
    }
icculus@1982
  1238
icculus@1982
  1239
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1240
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
icculus@1982
  1241
    }
icculus@1982
  1242
}
icculus@1982
  1243
icculus@1982
  1244
static void SDLCALL
icculus@1982
  1245
SDL_Convert_S16MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1246
{
icculus@1982
  1247
    int i;
icculus@1982
  1248
    const Uint16 *src;
icculus@1982
  1249
    Sint32 *dst;
icculus@1982
  1250
slouken@3032
  1251
#if DEBUG_CONVERT
icculus@1982
  1252
    fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S32LSB.\n");
icculus@1982
  1253
#endif
icculus@1982
  1254
icculus@2956
  1255
    src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
  1256
    dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
  1257
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
icculus@1982
  1258
        const Sint32 val = (((Sint32) ((Sint16) SDL_SwapBE16(*src))) << 16);
icculus@1982
  1259
        *dst = ((Sint32) SDL_SwapLE32(val));
icculus@1982
  1260
    }
icculus@1982
  1261
icculus@1982
  1262
    cvt->len_cvt *= 2;
icculus@1982
  1263
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1264
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
icculus@1982
  1265
    }
icculus@1982
  1266
}
icculus@1982
  1267
icculus@1982
  1268
static void SDLCALL
icculus@1982
  1269
SDL_Convert_S16MSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1270
{
icculus@1982
  1271
    int i;
icculus@1982
  1272
    const Uint16 *src;
icculus@1982
  1273
    Sint32 *dst;
icculus@1982
  1274
slouken@3032
  1275
#if DEBUG_CONVERT
icculus@1982
  1276
    fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S32MSB.\n");
icculus@1982
  1277
#endif
icculus@1982
  1278
icculus@2956
  1279
    src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
  1280
    dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
  1281
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
icculus@1982
  1282
        const Sint32 val = (((Sint32) ((Sint16) SDL_SwapBE16(*src))) << 16);
icculus@1982
  1283
        *dst = ((Sint32) SDL_SwapBE32(val));
icculus@1982
  1284
    }
icculus@1982
  1285
icculus@1982
  1286
    cvt->len_cvt *= 2;
icculus@1982
  1287
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1288
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
icculus@1982
  1289
    }
icculus@1982
  1290
}
icculus@1982
  1291
icculus@1982
  1292
static void SDLCALL
icculus@1982
  1293
SDL_Convert_S16MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1294
{
icculus@1982
  1295
    int i;
icculus@1982
  1296
    const Uint16 *src;
icculus@1982
  1297
    float *dst;
icculus@1982
  1298
slouken@3032
  1299
#if DEBUG_CONVERT
icculus@1982
  1300
    fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_F32LSB.\n");
icculus@1982
  1301
#endif
icculus@1982
  1302
icculus@2956
  1303
    src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
  1304
    dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
  1305
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
icculus@1982
  1306
        const float val = (((float) ((Sint16) SDL_SwapBE16(*src))) * DIVBY32767);
icculus@1982
  1307
        *dst = SDL_SwapFloatLE(val);
icculus@1982
  1308
    }
icculus@1982
  1309
icculus@1982
  1310
    cvt->len_cvt *= 2;
icculus@1982
  1311
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1312
        cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
icculus@1982
  1313
    }
icculus@1982
  1314
}
icculus@1982
  1315
icculus@1982
  1316
static void SDLCALL
icculus@1982
  1317
SDL_Convert_S16MSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1318
{
icculus@1982
  1319
    int i;
icculus@1982
  1320
    const Uint16 *src;
icculus@1982
  1321
    float *dst;
icculus@1982
  1322
slouken@3032
  1323
#if DEBUG_CONVERT
icculus@1982
  1324
    fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_F32MSB.\n");
icculus@1982
  1325
#endif
icculus@1982
  1326
icculus@2956
  1327
    src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@2956
  1328
    dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
icculus@1982
  1329
    for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
icculus@1982
  1330
        const float val = (((float) ((Sint16) SDL_SwapBE16(*src))) * DIVBY32767);
icculus@1982
  1331
        *dst = SDL_SwapFloatBE(val);
icculus@1982
  1332
    }
icculus@1982
  1333
icculus@1982
  1334
    cvt->len_cvt *= 2;
icculus@1982
  1335
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1336
        cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
icculus@1982
  1337
    }
icculus@1982
  1338
}
icculus@1982
  1339
icculus@1982
  1340
static void SDLCALL
icculus@1982
  1341
SDL_Convert_S32LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1342
{
icculus@1982
  1343
    int i;
icculus@1982
  1344
    const Uint32 *src;
icculus@1982
  1345
    Uint8 *dst;
icculus@1982
  1346
slouken@3032
  1347
#if DEBUG_CONVERT
icculus@1982
  1348
    fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_U8.\n");
icculus@1982
  1349
#endif
icculus@1982
  1350
icculus@1982
  1351
    src = (const Uint32 *) cvt->buf;
icculus@1982
  1352
    dst = (Uint8 *) cvt->buf;
icculus@1982
  1353
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
icculus@1982
  1354
        const Uint8 val = ((Uint8) (((((Sint32) SDL_SwapLE32(*src))) ^ 0x80000000) >> 24));
icculus@1982
  1355
        *dst = val;
icculus@1982
  1356
    }
icculus@1982
  1357
icculus@1982
  1358
    cvt->len_cvt /= 4;
icculus@1982
  1359
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1360
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
icculus@1982
  1361
    }
icculus@1982
  1362
}
icculus@1982
  1363
icculus@1982
  1364
static void SDLCALL
icculus@1982
  1365
SDL_Convert_S32LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1366
{
icculus@1982
  1367
    int i;
icculus@1982
  1368
    const Uint32 *src;
icculus@1982
  1369
    Sint8 *dst;
icculus@1982
  1370
slouken@3032
  1371
#if DEBUG_CONVERT
icculus@1982
  1372
    fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S8.\n");
icculus@1982
  1373
#endif
icculus@1982
  1374
icculus@1982
  1375
    src = (const Uint32 *) cvt->buf;
icculus@1982
  1376
    dst = (Sint8 *) cvt->buf;
icculus@1982
  1377
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
icculus@1982
  1378
        const Sint8 val = ((Sint8) (((Sint32) SDL_SwapLE32(*src)) >> 24));
icculus@1982
  1379
        *dst = ((Sint8) val);
icculus@1982
  1380
    }
icculus@1982
  1381
icculus@1982
  1382
    cvt->len_cvt /= 4;
icculus@1982
  1383
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1384
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
icculus@1982
  1385
    }
icculus@1982
  1386
}
icculus@1982
  1387
icculus@1982
  1388
static void SDLCALL
icculus@1982
  1389
SDL_Convert_S32LSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1390
{
icculus@1982
  1391
    int i;
icculus@1982
  1392
    const Uint32 *src;
icculus@1982
  1393
    Uint16 *dst;
icculus@1982
  1394
slouken@3032
  1395
#if DEBUG_CONVERT
icculus@1982
  1396
    fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_U16LSB.\n");
icculus@1982
  1397
#endif
icculus@1982
  1398
icculus@1982
  1399
    src = (const Uint32 *) cvt->buf;
icculus@1982
  1400
    dst = (Uint16 *) cvt->buf;
icculus@1982
  1401
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
icculus@1982
  1402
        const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapLE32(*src))) ^ 0x80000000) >> 16));
icculus@1982
  1403
        *dst = SDL_SwapLE16(val);
icculus@1982
  1404
    }
icculus@1982
  1405
icculus@1982
  1406
    cvt->len_cvt /= 2;
icculus@1982
  1407
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1408
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
icculus@1982
  1409
    }
icculus@1982
  1410
}
icculus@1982
  1411
icculus@1982
  1412
static void SDLCALL
icculus@1982
  1413
SDL_Convert_S32LSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1414
{
icculus@1982
  1415
    int i;
icculus@1982
  1416
    const Uint32 *src;
icculus@1982
  1417
    Sint16 *dst;
icculus@1982
  1418
slouken@3032
  1419
#if DEBUG_CONVERT
icculus@1982
  1420
    fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S16LSB.\n");
icculus@1982
  1421
#endif
icculus@1982
  1422
icculus@1982
  1423
    src = (const Uint32 *) cvt->buf;
icculus@1982
  1424
    dst = (Sint16 *) cvt->buf;
icculus@1982
  1425
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
icculus@1982
  1426
        const Sint16 val = ((Sint16) (((Sint32) SDL_SwapLE32(*src)) >> 16));
icculus@1982
  1427
        *dst = ((Sint16) SDL_SwapLE16(val));
icculus@1982
  1428
    }
icculus@1982
  1429
icculus@1982
  1430
    cvt->len_cvt /= 2;
icculus@1982
  1431
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1432
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
icculus@1982
  1433
    }
icculus@1982
  1434
}
icculus@1982
  1435
icculus@1982
  1436
static void SDLCALL
icculus@1982
  1437
SDL_Convert_S32LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1438
{
icculus@1982
  1439
    int i;
icculus@1982
  1440
    const Uint32 *src;
icculus@1982
  1441
    Uint16 *dst;
icculus@1982
  1442
slouken@3032
  1443
#if DEBUG_CONVERT
icculus@1982
  1444
    fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_U16MSB.\n");
icculus@1982
  1445
#endif
icculus@1982
  1446
icculus@1982
  1447
    src = (const Uint32 *) cvt->buf;
icculus@1982
  1448
    dst = (Uint16 *) cvt->buf;
icculus@1982
  1449
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
icculus@1982
  1450
        const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapLE32(*src))) ^ 0x80000000) >> 16));
icculus@1982
  1451
        *dst = SDL_SwapBE16(val);
icculus@1982
  1452
    }
icculus@1982
  1453
icculus@1982
  1454
    cvt->len_cvt /= 2;
icculus@1982
  1455
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1456
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
icculus@1982
  1457
    }
icculus@1982
  1458
}
icculus@1982
  1459
icculus@1982
  1460
static void SDLCALL
icculus@1982
  1461
SDL_Convert_S32LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1462
{
icculus@1982
  1463
    int i;
icculus@1982
  1464
    const Uint32 *src;
icculus@1982
  1465
    Sint16 *dst;
icculus@1982
  1466
slouken@3032
  1467
#if DEBUG_CONVERT
icculus@1982
  1468
    fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S16MSB.\n");
icculus@1982
  1469
#endif
icculus@1982
  1470
icculus@1982
  1471
    src = (const Uint32 *) cvt->buf;
icculus@1982
  1472
    dst = (Sint16 *) cvt->buf;
icculus@1982
  1473
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
icculus@1982
  1474
        const Sint16 val = ((Sint16) (((Sint32) SDL_SwapLE32(*src)) >> 16));
icculus@1982
  1475
        *dst = ((Sint16) SDL_SwapBE16(val));
icculus@1982
  1476
    }
icculus@1982
  1477
icculus@1982
  1478
    cvt->len_cvt /= 2;
icculus@1982
  1479
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1480
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
icculus@1982
  1481
    }
icculus@1982
  1482
}
icculus@1982
  1483
icculus@1982
  1484
static void SDLCALL
icculus@1982
  1485
SDL_Convert_S32LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1486
{
icculus@1982
  1487
    int i;
icculus@1982
  1488
    const Uint32 *src;
icculus@1982
  1489
    Sint32 *dst;
icculus@1982
  1490
slouken@3032
  1491
#if DEBUG_CONVERT
icculus@1982
  1492
    fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S32MSB.\n");
icculus@1982
  1493
#endif
icculus@1982
  1494
icculus@1982
  1495
    src = (const Uint32 *) cvt->buf;
icculus@1982
  1496
    dst = (Sint32 *) cvt->buf;
icculus@1982
  1497
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
icculus@1982
  1498
        const Sint32 val = ((Sint32) SDL_SwapLE32(*src));
icculus@1982
  1499
        *dst = ((Sint32) SDL_SwapBE32(val));
icculus@1982
  1500
    }
icculus@1982
  1501
icculus@1982
  1502
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1503
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
icculus@1982
  1504
    }
icculus@1982
  1505
}
icculus@1982
  1506
icculus@1982
  1507
static void SDLCALL
icculus@1982
  1508
SDL_Convert_S32LSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1509
{
icculus@1982
  1510
    int i;
icculus@1982
  1511
    const Uint32 *src;
icculus@1982
  1512
    float *dst;
icculus@1982
  1513
slouken@3032
  1514
#if DEBUG_CONVERT
icculus@1982
  1515
    fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_F32LSB.\n");
icculus@1982
  1516
#endif
icculus@1982
  1517
icculus@1982
  1518
    src = (const Uint32 *) cvt->buf;
icculus@1982
  1519
    dst = (float *) cvt->buf;
icculus@1982
  1520
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
icculus@1982
  1521
        const float val = (((float) ((Sint32) SDL_SwapLE32(*src))) * DIVBY2147483647);
icculus@1982
  1522
        *dst = SDL_SwapFloatLE(val);
icculus@1982
  1523
    }
icculus@1982
  1524
icculus@1982
  1525
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1526
        cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
icculus@1982
  1527
    }
icculus@1982
  1528
}
icculus@1982
  1529
icculus@1982
  1530
static void SDLCALL
icculus@1982
  1531
SDL_Convert_S32LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1532
{
icculus@1982
  1533
    int i;
icculus@1982
  1534
    const Uint32 *src;
icculus@1982
  1535
    float *dst;
icculus@1982
  1536
slouken@3032
  1537
#if DEBUG_CONVERT
icculus@1982
  1538
    fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_F32MSB.\n");
icculus@1982
  1539
#endif
icculus@1982
  1540
icculus@1982
  1541
    src = (const Uint32 *) cvt->buf;
icculus@1982
  1542
    dst = (float *) cvt->buf;
icculus@1982
  1543
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
icculus@1982
  1544
        const float val = (((float) ((Sint32) SDL_SwapLE32(*src))) * DIVBY2147483647);
icculus@1982
  1545
        *dst = SDL_SwapFloatBE(val);
icculus@1982
  1546
    }
icculus@1982
  1547
icculus@1982
  1548
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1549
        cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
icculus@1982
  1550
    }
icculus@1982
  1551
}
icculus@1982
  1552
icculus@1982
  1553
static void SDLCALL
icculus@1982
  1554
SDL_Convert_S32MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1555
{
icculus@1982
  1556
    int i;
icculus@1982
  1557
    const Uint32 *src;
icculus@1982
  1558
    Uint8 *dst;
icculus@1982
  1559
slouken@3032
  1560
#if DEBUG_CONVERT
icculus@1982
  1561
    fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_U8.\n");
icculus@1982
  1562
#endif
icculus@1982
  1563
icculus@1982
  1564
    src = (const Uint32 *) cvt->buf;
icculus@1982
  1565
    dst = (Uint8 *) cvt->buf;
icculus@1982
  1566
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
icculus@1982
  1567
        const Uint8 val = ((Uint8) (((((Sint32) SDL_SwapBE32(*src))) ^ 0x80000000) >> 24));
icculus@1982
  1568
        *dst = val;
icculus@1982
  1569
    }
icculus@1982
  1570
icculus@1982
  1571
    cvt->len_cvt /= 4;
icculus@1982
  1572
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1573
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
icculus@1982
  1574
    }
icculus@1982
  1575
}
icculus@1982
  1576
icculus@1982
  1577
static void SDLCALL
icculus@1982
  1578
SDL_Convert_S32MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1579
{
icculus@1982
  1580
    int i;
icculus@1982
  1581
    const Uint32 *src;
icculus@1982
  1582
    Sint8 *dst;
icculus@1982
  1583
slouken@3032
  1584
#if DEBUG_CONVERT
icculus@1982
  1585
    fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S8.\n");
icculus@1982
  1586
#endif
icculus@1982
  1587
icculus@1982
  1588
    src = (const Uint32 *) cvt->buf;
icculus@1982
  1589
    dst = (Sint8 *) cvt->buf;
icculus@1982
  1590
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
icculus@1982
  1591
        const Sint8 val = ((Sint8) (((Sint32) SDL_SwapBE32(*src)) >> 24));
icculus@1982
  1592
        *dst = ((Sint8) val);
icculus@1982
  1593
    }
icculus@1982
  1594
icculus@1982
  1595
    cvt->len_cvt /= 4;
icculus@1982
  1596
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1597
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
icculus@1982
  1598
    }
icculus@1982
  1599
}
icculus@1982
  1600
icculus@1982
  1601
static void SDLCALL
icculus@1982
  1602
SDL_Convert_S32MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1603
{
icculus@1982
  1604
    int i;
icculus@1982
  1605
    const Uint32 *src;
icculus@1982
  1606
    Uint16 *dst;
icculus@1982
  1607
slouken@3032
  1608
#if DEBUG_CONVERT
icculus@1982
  1609
    fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_U16LSB.\n");
icculus@1982
  1610
#endif
icculus@1982
  1611
icculus@1982
  1612
    src = (const Uint32 *) cvt->buf;
icculus@1982
  1613
    dst = (Uint16 *) cvt->buf;
icculus@1982
  1614
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
icculus@1982
  1615
        const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapBE32(*src))) ^ 0x80000000) >> 16));
icculus@1982
  1616
        *dst = SDL_SwapLE16(val);
icculus@1982
  1617
    }
icculus@1982
  1618
icculus@1982
  1619
    cvt->len_cvt /= 2;
icculus@1982
  1620
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1621
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
icculus@1982
  1622
    }
icculus@1982
  1623
}
icculus@1982
  1624
icculus@1982
  1625
static void SDLCALL
icculus@1982
  1626
SDL_Convert_S32MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1627
{
icculus@1982
  1628
    int i;
icculus@1982
  1629
    const Uint32 *src;
icculus@1982
  1630
    Sint16 *dst;
icculus@1982
  1631
slouken@3032
  1632
#if DEBUG_CONVERT
icculus@1982
  1633
    fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S16LSB.\n");
icculus@1982
  1634
#endif
icculus@1982
  1635
icculus@1982
  1636
    src = (const Uint32 *) cvt->buf;
icculus@1982
  1637
    dst = (Sint16 *) cvt->buf;
icculus@1982
  1638
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
icculus@1982
  1639
        const Sint16 val = ((Sint16) (((Sint32) SDL_SwapBE32(*src)) >> 16));
icculus@1982
  1640
        *dst = ((Sint16) SDL_SwapLE16(val));
icculus@1982
  1641
    }
icculus@1982
  1642
icculus@1982
  1643
    cvt->len_cvt /= 2;
icculus@1982
  1644
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1645
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
icculus@1982
  1646
    }
icculus@1982
  1647
}
icculus@1982
  1648
icculus@1982
  1649
static void SDLCALL
icculus@1982
  1650
SDL_Convert_S32MSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1651
{
icculus@1982
  1652
    int i;
icculus@1982
  1653
    const Uint32 *src;
icculus@1982
  1654
    Uint16 *dst;
icculus@1982
  1655
slouken@3032
  1656
#if DEBUG_CONVERT
icculus@1982
  1657
    fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_U16MSB.\n");
icculus@1982
  1658
#endif
icculus@1982
  1659
icculus@1982
  1660
    src = (const Uint32 *) cvt->buf;
icculus@1982
  1661
    dst = (Uint16 *) cvt->buf;
icculus@1982
  1662
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
icculus@1982
  1663
        const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapBE32(*src))) ^ 0x80000000) >> 16));
icculus@1982
  1664
        *dst = SDL_SwapBE16(val);
icculus@1982
  1665
    }
icculus@1982
  1666
icculus@1982
  1667
    cvt->len_cvt /= 2;
icculus@1982
  1668
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1669
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
icculus@1982
  1670
    }
icculus@1982
  1671
}
icculus@1982
  1672
icculus@1982
  1673
static void SDLCALL
icculus@1982
  1674
SDL_Convert_S32MSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1675
{
icculus@1982
  1676
    int i;
icculus@1982
  1677
    const Uint32 *src;
icculus@1982
  1678
    Sint16 *dst;
icculus@1982
  1679
slouken@3032
  1680
#if DEBUG_CONVERT
icculus@1982
  1681
    fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S16MSB.\n");
icculus@1982
  1682
#endif
icculus@1982
  1683
icculus@1982
  1684
    src = (const Uint32 *) cvt->buf;
icculus@1982
  1685
    dst = (Sint16 *) cvt->buf;
icculus@1982
  1686
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
icculus@1982
  1687
        const Sint16 val = ((Sint16) (((Sint32) SDL_SwapBE32(*src)) >> 16));
icculus@1982
  1688
        *dst = ((Sint16) SDL_SwapBE16(val));
icculus@1982
  1689
    }
icculus@1982
  1690
icculus@1982
  1691
    cvt->len_cvt /= 2;
icculus@1982
  1692
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1693
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
icculus@1982
  1694
    }
icculus@1982
  1695
}
icculus@1982
  1696
icculus@1982
  1697
static void SDLCALL
icculus@1982
  1698
SDL_Convert_S32MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1699
{
icculus@1982
  1700
    int i;
icculus@1982
  1701
    const Uint32 *src;
icculus@1982
  1702
    Sint32 *dst;
icculus@1982
  1703
slouken@3032
  1704
#if DEBUG_CONVERT
icculus@1982
  1705
    fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S32LSB.\n");
icculus@1982
  1706
#endif
icculus@1982
  1707
icculus@1982
  1708
    src = (const Uint32 *) cvt->buf;
icculus@1982
  1709
    dst = (Sint32 *) cvt->buf;
icculus@1982
  1710
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
icculus@1982
  1711
        const Sint32 val = ((Sint32) SDL_SwapBE32(*src));
icculus@1982
  1712
        *dst = ((Sint32) SDL_SwapLE32(val));
icculus@1982
  1713
    }
icculus@1982
  1714
icculus@1982
  1715
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1716
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
icculus@1982
  1717
    }
icculus@1982
  1718
}
icculus@1982
  1719
icculus@1982
  1720
static void SDLCALL
icculus@1982
  1721
SDL_Convert_S32MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1722
{
icculus@1982
  1723
    int i;
icculus@1982
  1724
    const Uint32 *src;
icculus@1982
  1725
    float *dst;
icculus@1982
  1726
slouken@3032
  1727
#if DEBUG_CONVERT
icculus@1982
  1728
    fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_F32LSB.\n");
icculus@1982
  1729
#endif
icculus@1982
  1730
icculus@1982
  1731
    src = (const Uint32 *) cvt->buf;
icculus@1982
  1732
    dst = (float *) cvt->buf;
icculus@1982
  1733
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
icculus@1982
  1734
        const float val = (((float) ((Sint32) SDL_SwapBE32(*src))) * DIVBY2147483647);
icculus@1982
  1735
        *dst = SDL_SwapFloatLE(val);
icculus@1982
  1736
    }
icculus@1982
  1737
icculus@1982
  1738
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1739
        cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
icculus@1982
  1740
    }
icculus@1982
  1741
}
icculus@1982
  1742
icculus@1982
  1743
static void SDLCALL
icculus@1982
  1744
SDL_Convert_S32MSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1745
{
icculus@1982
  1746
    int i;
icculus@1982
  1747
    const Uint32 *src;
icculus@1982
  1748
    float *dst;
icculus@1982
  1749
slouken@3032
  1750
#if DEBUG_CONVERT
icculus@1982
  1751
    fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_F32MSB.\n");
icculus@1982
  1752
#endif
icculus@1982
  1753
icculus@1982
  1754
    src = (const Uint32 *) cvt->buf;
icculus@1982
  1755
    dst = (float *) cvt->buf;
icculus@1982
  1756
    for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
icculus@1982
  1757
        const float val = (((float) ((Sint32) SDL_SwapBE32(*src))) * DIVBY2147483647);
icculus@1982
  1758
        *dst = SDL_SwapFloatBE(val);
icculus@1982
  1759
    }
icculus@1982
  1760
icculus@1982
  1761
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1762
        cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
icculus@1982
  1763
    }
icculus@1982
  1764
}
icculus@1982
  1765
icculus@1982
  1766
static void SDLCALL
icculus@1982
  1767
SDL_Convert_F32LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1768
{
icculus@1982
  1769
    int i;
icculus@1982
  1770
    const float *src;
icculus@1982
  1771
    Uint8 *dst;
icculus@1982
  1772
slouken@3032
  1773
#if DEBUG_CONVERT
icculus@1982
  1774
    fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_U8.\n");
icculus@1982
  1775
#endif
icculus@1982
  1776
icculus@1982
  1777
    src = (const float *) cvt->buf;
icculus@1982
  1778
    dst = (Uint8 *) cvt->buf;
icculus@1982
  1779
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
icculus@2011
  1780
        const Uint8 val = ((Uint8) ((SDL_SwapFloatLE(*src) + 1.0f) * 127.0f));
icculus@1982
  1781
        *dst = val;
icculus@1982
  1782
    }
icculus@1982
  1783
icculus@1982
  1784
    cvt->len_cvt /= 4;
icculus@1982
  1785
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1786
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
icculus@1982
  1787
    }
icculus@1982
  1788
}
icculus@1982
  1789
icculus@1982
  1790
static void SDLCALL
icculus@1982
  1791
SDL_Convert_F32LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1792
{
icculus@1982
  1793
    int i;
icculus@1982
  1794
    const float *src;
icculus@1982
  1795
    Sint8 *dst;
icculus@1982
  1796
slouken@3032
  1797
#if DEBUG_CONVERT
icculus@1982
  1798
    fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S8.\n");
icculus@1982
  1799
#endif
icculus@1982
  1800
icculus@1982
  1801
    src = (const float *) cvt->buf;
icculus@1982
  1802
    dst = (Sint8 *) cvt->buf;
icculus@1982
  1803
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
icculus@1982
  1804
        const Sint8 val = ((Sint8) (SDL_SwapFloatLE(*src) * 127.0f));
icculus@1982
  1805
        *dst = ((Sint8) val);
icculus@1982
  1806
    }
icculus@1982
  1807
icculus@1982
  1808
    cvt->len_cvt /= 4;
icculus@1982
  1809
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1810
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
icculus@1982
  1811
    }
icculus@1982
  1812
}
icculus@1982
  1813
icculus@1982
  1814
static void SDLCALL
icculus@1982
  1815
SDL_Convert_F32LSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1816
{
icculus@1982
  1817
    int i;
icculus@1982
  1818
    const float *src;
icculus@1982
  1819
    Uint16 *dst;
icculus@1982
  1820
slouken@3032
  1821
#if DEBUG_CONVERT
icculus@1982
  1822
    fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_U16LSB.\n");
icculus@1982
  1823
#endif
icculus@1982
  1824
icculus@1982
  1825
    src = (const float *) cvt->buf;
icculus@1982
  1826
    dst = (Uint16 *) cvt->buf;
icculus@1982
  1827
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
icculus@2011
  1828
        const Uint16 val = ((Uint16) ((SDL_SwapFloatLE(*src) + 1.0f) * 32767.0f));
icculus@1982
  1829
        *dst = SDL_SwapLE16(val);
icculus@1982
  1830
    }
icculus@1982
  1831
icculus@1982
  1832
    cvt->len_cvt /= 2;
icculus@1982
  1833
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1834
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
icculus@1982
  1835
    }
icculus@1982
  1836
}
icculus@1982
  1837
icculus@1982
  1838
static void SDLCALL
icculus@1982
  1839
SDL_Convert_F32LSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1840
{
icculus@1982
  1841
    int i;
icculus@1982
  1842
    const float *src;
icculus@1982
  1843
    Sint16 *dst;
icculus@1982
  1844
slouken@3032
  1845
#if DEBUG_CONVERT
icculus@1982
  1846
    fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S16LSB.\n");
icculus@1982
  1847
#endif
icculus@1982
  1848
icculus@1982
  1849
    src = (const float *) cvt->buf;
icculus@1982
  1850
    dst = (Sint16 *) cvt->buf;
icculus@1982
  1851
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
icculus@1982
  1852
        const Sint16 val = ((Sint16) (SDL_SwapFloatLE(*src) * 32767.0f));
icculus@1982
  1853
        *dst = ((Sint16) SDL_SwapLE16(val));
icculus@1982
  1854
    }
icculus@1982
  1855
icculus@1982
  1856
    cvt->len_cvt /= 2;
icculus@1982
  1857
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1858
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
icculus@1982
  1859
    }
icculus@1982
  1860
}
icculus@1982
  1861
icculus@1982
  1862
static void SDLCALL
icculus@1982
  1863
SDL_Convert_F32LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1864
{
icculus@1982
  1865
    int i;
icculus@1982
  1866
    const float *src;
icculus@1982
  1867
    Uint16 *dst;
icculus@1982
  1868
slouken@3032
  1869
#if DEBUG_CONVERT
icculus@1982
  1870
    fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_U16MSB.\n");
icculus@1982
  1871
#endif
icculus@1982
  1872
icculus@1982
  1873
    src = (const float *) cvt->buf;
icculus@1982
  1874
    dst = (Uint16 *) cvt->buf;
icculus@1982
  1875
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
icculus@2011
  1876
        const Uint16 val = ((Uint16) ((SDL_SwapFloatLE(*src) + 1.0f) * 32767.0f));
icculus@1982
  1877
        *dst = SDL_SwapBE16(val);
icculus@1982
  1878
    }
icculus@1982
  1879
icculus@1982
  1880
    cvt->len_cvt /= 2;
icculus@1982
  1881
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1882
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
icculus@1982
  1883
    }
icculus@1982
  1884
}
icculus@1982
  1885
icculus@1982
  1886
static void SDLCALL
icculus@1982
  1887
SDL_Convert_F32LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1888
{
icculus@1982
  1889
    int i;
icculus@1982
  1890
    const float *src;
icculus@1982
  1891
    Sint16 *dst;
icculus@1982
  1892
slouken@3032
  1893
#if DEBUG_CONVERT
icculus@1982
  1894
    fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S16MSB.\n");
icculus@1982
  1895
#endif
icculus@1982
  1896
icculus@1982
  1897
    src = (const float *) cvt->buf;
icculus@1982
  1898
    dst = (Sint16 *) cvt->buf;
icculus@1982
  1899
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
icculus@1982
  1900
        const Sint16 val = ((Sint16) (SDL_SwapFloatLE(*src) * 32767.0f));
icculus@1982
  1901
        *dst = ((Sint16) SDL_SwapBE16(val));
icculus@1982
  1902
    }
icculus@1982
  1903
icculus@1982
  1904
    cvt->len_cvt /= 2;
icculus@1982
  1905
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1906
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
icculus@1982
  1907
    }
icculus@1982
  1908
}
icculus@1982
  1909
icculus@1982
  1910
static void SDLCALL
icculus@1982
  1911
SDL_Convert_F32LSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1912
{
icculus@1982
  1913
    int i;
icculus@1982
  1914
    const float *src;
icculus@1982
  1915
    Sint32 *dst;
icculus@1982
  1916
slouken@3032
  1917
#if DEBUG_CONVERT
icculus@1982
  1918
    fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S32LSB.\n");
icculus@1982
  1919
#endif
icculus@1982
  1920
icculus@1982
  1921
    src = (const float *) cvt->buf;
icculus@1982
  1922
    dst = (Sint32 *) cvt->buf;
icculus@1982
  1923
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
icculus@1982
  1924
        const Sint32 val = ((Sint32) (SDL_SwapFloatLE(*src) * 2147483647.0));
icculus@1982
  1925
        *dst = ((Sint32) SDL_SwapLE32(val));
icculus@1982
  1926
    }
icculus@1982
  1927
icculus@1982
  1928
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1929
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
icculus@1982
  1930
    }
icculus@1982
  1931
}
icculus@1982
  1932
icculus@1982
  1933
static void SDLCALL
icculus@1982
  1934
SDL_Convert_F32LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1935
{
icculus@1982
  1936
    int i;
icculus@1982
  1937
    const float *src;
icculus@1982
  1938
    Sint32 *dst;
icculus@1982
  1939
slouken@3032
  1940
#if DEBUG_CONVERT
icculus@1982
  1941
    fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S32MSB.\n");
icculus@1982
  1942
#endif
icculus@1982
  1943
icculus@1982
  1944
    src = (const float *) cvt->buf;
icculus@1982
  1945
    dst = (Sint32 *) cvt->buf;
icculus@1982
  1946
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
icculus@1982
  1947
        const Sint32 val = ((Sint32) (SDL_SwapFloatLE(*src) * 2147483647.0));
icculus@1982
  1948
        *dst = ((Sint32) SDL_SwapBE32(val));
icculus@1982
  1949
    }
icculus@1982
  1950
icculus@1982
  1951
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1952
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
icculus@1982
  1953
    }
icculus@1982
  1954
}
icculus@1982
  1955
icculus@1982
  1956
static void SDLCALL
icculus@1982
  1957
SDL_Convert_F32LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1958
{
icculus@1982
  1959
    int i;
icculus@1982
  1960
    const float *src;
icculus@1982
  1961
    float *dst;
icculus@1982
  1962
slouken@3032
  1963
#if DEBUG_CONVERT
icculus@1982
  1964
    fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_F32MSB.\n");
icculus@1982
  1965
#endif
icculus@1982
  1966
icculus@1982
  1967
    src = (const float *) cvt->buf;
icculus@1982
  1968
    dst = (float *) cvt->buf;
icculus@1982
  1969
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
icculus@1982
  1970
        const float val = SDL_SwapFloatLE(*src);
icculus@1982
  1971
        *dst = SDL_SwapFloatBE(val);
icculus@1982
  1972
    }
icculus@1982
  1973
icculus@1982
  1974
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1975
        cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
icculus@1982
  1976
    }
icculus@1982
  1977
}
icculus@1982
  1978
icculus@1982
  1979
static void SDLCALL
icculus@1982
  1980
SDL_Convert_F32MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  1981
{
icculus@1982
  1982
    int i;
icculus@1982
  1983
    const float *src;
icculus@1982
  1984
    Uint8 *dst;
icculus@1982
  1985
slouken@3032
  1986
#if DEBUG_CONVERT
icculus@1982
  1987
    fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_U8.\n");
icculus@1982
  1988
#endif
icculus@1982
  1989
icculus@1982
  1990
    src = (const float *) cvt->buf;
icculus@1982
  1991
    dst = (Uint8 *) cvt->buf;
icculus@1982
  1992
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
icculus@2011
  1993
        const Uint8 val = ((Uint8) ((SDL_SwapFloatBE(*src) + 1.0f) * 127.0f));
icculus@1982
  1994
        *dst = val;
icculus@1982
  1995
    }
icculus@1982
  1996
icculus@1982
  1997
    cvt->len_cvt /= 4;
icculus@1982
  1998
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  1999
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
icculus@1982
  2000
    }
icculus@1982
  2001
}
icculus@1982
  2002
icculus@1982
  2003
static void SDLCALL
icculus@1982
  2004
SDL_Convert_F32MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  2005
{
icculus@1982
  2006
    int i;
icculus@1982
  2007
    const float *src;
icculus@1982
  2008
    Sint8 *dst;
icculus@1982
  2009
slouken@3032
  2010
#if DEBUG_CONVERT
icculus@1982
  2011
    fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S8.\n");
icculus@1982
  2012
#endif
icculus@1982
  2013
icculus@1982
  2014
    src = (const float *) cvt->buf;
icculus@1982
  2015
    dst = (Sint8 *) cvt->buf;
icculus@1982
  2016
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
icculus@1982
  2017
        const Sint8 val = ((Sint8) (SDL_SwapFloatBE(*src) * 127.0f));
icculus@1982
  2018
        *dst = ((Sint8) val);
icculus@1982
  2019
    }
icculus@1982
  2020
icculus@1982
  2021
    cvt->len_cvt /= 4;
icculus@1982
  2022
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  2023
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
icculus@1982
  2024
    }
icculus@1982
  2025
}
icculus@1982
  2026
icculus@1982
  2027
static void SDLCALL
icculus@1982
  2028
SDL_Convert_F32MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  2029
{
icculus@1982
  2030
    int i;
icculus@1982
  2031
    const float *src;
icculus@1982
  2032
    Uint16 *dst;
icculus@1982
  2033
slouken@3032
  2034
#if DEBUG_CONVERT
icculus@1982
  2035
    fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_U16LSB.\n");
icculus@1982
  2036
#endif
icculus@1982
  2037
icculus@1982
  2038
    src = (const float *) cvt->buf;
icculus@1982
  2039
    dst = (Uint16 *) cvt->buf;
icculus@1982
  2040
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
icculus@2011
  2041
        const Uint16 val = ((Uint16) ((SDL_SwapFloatBE(*src) + 1.0f) * 32767.0f));
icculus@1982
  2042
        *dst = SDL_SwapLE16(val);
icculus@1982
  2043
    }
icculus@1982
  2044
icculus@1982
  2045
    cvt->len_cvt /= 2;
icculus@1982
  2046
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  2047
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
icculus@1982
  2048
    }
icculus@1982
  2049
}
icculus@1982
  2050
icculus@1982
  2051
static void SDLCALL
icculus@1982
  2052
SDL_Convert_F32MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  2053
{
icculus@1982
  2054
    int i;
icculus@1982
  2055
    const float *src;
icculus@1982
  2056
    Sint16 *dst;
icculus@1982
  2057
slouken@3032
  2058
#if DEBUG_CONVERT
icculus@1982
  2059
    fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S16LSB.\n");
icculus@1982
  2060
#endif
icculus@1982
  2061
icculus@1982
  2062
    src = (const float *) cvt->buf;
icculus@1982
  2063
    dst = (Sint16 *) cvt->buf;
icculus@1982
  2064
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
icculus@1982
  2065
        const Sint16 val = ((Sint16) (SDL_SwapFloatBE(*src) * 32767.0f));
icculus@1982
  2066
        *dst = ((Sint16) SDL_SwapLE16(val));
icculus@1982
  2067
    }
icculus@1982
  2068
icculus@1982
  2069
    cvt->len_cvt /= 2;
icculus@1982
  2070
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  2071
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
icculus@1982
  2072
    }
icculus@1982
  2073
}
icculus@1982
  2074
icculus@1982
  2075
static void SDLCALL
icculus@1982
  2076
SDL_Convert_F32MSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  2077
{
icculus@1982
  2078
    int i;
icculus@1982
  2079
    const float *src;
icculus@1982
  2080
    Uint16 *dst;
icculus@1982
  2081
slouken@3032
  2082
#if DEBUG_CONVERT
icculus@1982
  2083
    fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_U16MSB.\n");
icculus@1982
  2084
#endif
icculus@1982
  2085
icculus@1982
  2086
    src = (const float *) cvt->buf;
icculus@1982
  2087
    dst = (Uint16 *) cvt->buf;
icculus@1982
  2088
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
icculus@2011
  2089
        const Uint16 val = ((Uint16) ((SDL_SwapFloatBE(*src) + 1.0f) * 32767.0f));
icculus@1982
  2090
        *dst = SDL_SwapBE16(val);
icculus@1982
  2091
    }
icculus@1982
  2092
icculus@1982
  2093
    cvt->len_cvt /= 2;
icculus@1982
  2094
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  2095
        cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
icculus@1982
  2096
    }
icculus@1982
  2097
}
icculus@1982
  2098
icculus@1982
  2099
static void SDLCALL
icculus@1982
  2100
SDL_Convert_F32MSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  2101
{
icculus@1982
  2102
    int i;
icculus@1982
  2103
    const float *src;
icculus@1982
  2104
    Sint16 *dst;
icculus@1982
  2105
slouken@3032
  2106
#if DEBUG_CONVERT
icculus@1982
  2107
    fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S16MSB.\n");
icculus@1982
  2108
#endif
icculus@1982
  2109
icculus@1982
  2110
    src = (const float *) cvt->buf;
icculus@1982
  2111
    dst = (Sint16 *) cvt->buf;
icculus@1982
  2112
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
icculus@1982
  2113
        const Sint16 val = ((Sint16) (SDL_SwapFloatBE(*src) * 32767.0f));
icculus@1982
  2114
        *dst = ((Sint16) SDL_SwapBE16(val));
icculus@1982
  2115
    }
icculus@1982
  2116
icculus@1982
  2117
    cvt->len_cvt /= 2;
icculus@1982
  2118
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  2119
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
icculus@1982
  2120
    }
icculus@1982
  2121
}
icculus@1982
  2122
icculus@1982
  2123
static void SDLCALL
icculus@1982
  2124
SDL_Convert_F32MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  2125
{
icculus@1982
  2126
    int i;
icculus@1982
  2127
    const float *src;
icculus@1982
  2128
    Sint32 *dst;
icculus@1982
  2129
slouken@3032
  2130
#if DEBUG_CONVERT
icculus@1982
  2131
    fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S32LSB.\n");
icculus@1982
  2132
#endif
icculus@1982
  2133
icculus@1982
  2134
    src = (const float *) cvt->buf;
icculus@1982
  2135
    dst = (Sint32 *) cvt->buf;
icculus@1982
  2136
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
icculus@1982
  2137
        const Sint32 val = ((Sint32) (SDL_SwapFloatBE(*src) * 2147483647.0));
icculus@1982
  2138
        *dst = ((Sint32) SDL_SwapLE32(val));
icculus@1982
  2139
    }
icculus@1982
  2140
icculus@1982
  2141
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  2142
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
icculus@1982
  2143
    }
icculus@1982
  2144
}
icculus@1982
  2145
icculus@1982
  2146
static void SDLCALL
icculus@1982
  2147
SDL_Convert_F32MSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  2148
{
icculus@1982
  2149
    int i;
icculus@1982
  2150
    const float *src;
icculus@1982
  2151
    Sint32 *dst;
icculus@1982
  2152
slouken@3032
  2153
#if DEBUG_CONVERT
icculus@1982
  2154
    fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S32MSB.\n");
icculus@1982
  2155
#endif
icculus@1982
  2156
icculus@1982
  2157
    src = (const float *) cvt->buf;
icculus@1982
  2158
    dst = (Sint32 *) cvt->buf;
icculus@1982
  2159
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
icculus@1982
  2160
        const Sint32 val = ((Sint32) (SDL_SwapFloatBE(*src) * 2147483647.0));
icculus@1982
  2161
        *dst = ((Sint32) SDL_SwapBE32(val));
icculus@1982
  2162
    }
icculus@1982
  2163
icculus@1982
  2164
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  2165
        cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
icculus@1982
  2166
    }
icculus@1982
  2167
}
icculus@1982
  2168
icculus@1982
  2169
static void SDLCALL
icculus@1982
  2170
SDL_Convert_F32MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@1982
  2171
{
icculus@1982
  2172
    int i;
icculus@1982
  2173
    const float *src;
icculus@1982
  2174
    float *dst;
icculus@1982
  2175
slouken@3032
  2176
#if DEBUG_CONVERT
icculus@1982
  2177
    fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_F32LSB.\n");
icculus@1982
  2178
#endif
icculus@1982
  2179
icculus@1982
  2180
    src = (const float *) cvt->buf;
icculus@1982
  2181
    dst = (float *) cvt->buf;
icculus@1982
  2182
    for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
icculus@1982
  2183
        const float val = SDL_SwapFloatBE(*src);
icculus@1982
  2184
        *dst = SDL_SwapFloatLE(val);
icculus@1982
  2185
    }
icculus@1982
  2186
icculus@1982
  2187
    if (cvt->filters[++cvt->filter_index]) {
icculus@2955
  2188
        cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
icculus@1982
  2189
    }
icculus@1982
  2190
}
icculus@1982
  2191
icculus@3021
  2192
#endif  /* !NO_CONVERTERS */
icculus@3021
  2193
icculus@3021
  2194
icculus@1982
  2195
const SDL_AudioTypeFilters sdl_audio_type_filters[] =
icculus@1982
  2196
{
icculus@3021
  2197
#if !NO_CONVERTERS
icculus@1982
  2198
    { AUDIO_U8, AUDIO_S8, SDL_Convert_U8_to_S8 },
icculus@1982
  2199
    { AUDIO_U8, AUDIO_U16LSB, SDL_Convert_U8_to_U16LSB },
icculus@1982
  2200
    { AUDIO_U8, AUDIO_S16LSB, SDL_Convert_U8_to_S16LSB },
icculus@1982
  2201
    { AUDIO_U8, AUDIO_U16MSB, SDL_Convert_U8_to_U16MSB },
icculus@1982
  2202
    { AUDIO_U8, AUDIO_S16MSB, SDL_Convert_U8_to_S16MSB },
icculus@1982
  2203
    { AUDIO_U8, AUDIO_S32LSB, SDL_Convert_U8_to_S32LSB },
icculus@1982
  2204
    { AUDIO_U8, AUDIO_S32MSB, SDL_Convert_U8_to_S32MSB },
icculus@1982
  2205
    { AUDIO_U8, AUDIO_F32LSB, SDL_Convert_U8_to_F32LSB },
icculus@1982
  2206
    { AUDIO_U8, AUDIO_F32MSB, SDL_Convert_U8_to_F32MSB },
icculus@1982
  2207
    { AUDIO_S8, AUDIO_U8, SDL_Convert_S8_to_U8 },
icculus@1982
  2208
    { AUDIO_S8, AUDIO_U16LSB, SDL_Convert_S8_to_U16LSB },
icculus@1982
  2209
    { AUDIO_S8, AUDIO_S16LSB, SDL_Convert_S8_to_S16LSB },
icculus@1982
  2210
    { AUDIO_S8, AUDIO_U16MSB, SDL_Convert_S8_to_U16MSB },
icculus@1982
  2211
    { AUDIO_S8, AUDIO_S16MSB, SDL_Convert_S8_to_S16MSB },
icculus@1982
  2212
    { AUDIO_S8, AUDIO_S32LSB, SDL_Convert_S8_to_S32LSB },
icculus@1982
  2213
    { AUDIO_S8, AUDIO_S32MSB, SDL_Convert_S8_to_S32MSB },
icculus@1982
  2214
    { AUDIO_S8, AUDIO_F32LSB, SDL_Convert_S8_to_F32LSB },
icculus@1982
  2215
    { AUDIO_S8, AUDIO_F32MSB, SDL_Convert_S8_to_F32MSB },
icculus@1982
  2216
    { AUDIO_U16LSB, AUDIO_U8, SDL_Convert_U16LSB_to_U8 },
icculus@1982
  2217
    { AUDIO_U16LSB, AUDIO_S8, SDL_Convert_U16LSB_to_S8 },
icculus@1982
  2218
    { AUDIO_U16LSB, AUDIO_S16LSB, SDL_Convert_U16LSB_to_S16LSB },
icculus@1982
  2219
    { AUDIO_U16LSB, AUDIO_U16MSB, SDL_Convert_U16LSB_to_U16MSB },
icculus@1982
  2220
    { AUDIO_U16LSB, AUDIO_S16MSB, SDL_Convert_U16LSB_to_S16MSB },
icculus@1982
  2221
    { AUDIO_U16LSB, AUDIO_S32LSB, SDL_Convert_U16LSB_to_S32LSB },
icculus@1982
  2222
    { AUDIO_U16LSB, AUDIO_S32MSB, SDL_Convert_U16LSB_to_S32MSB },
icculus@1982
  2223
    { AUDIO_U16LSB, AUDIO_F32LSB, SDL_Convert_U16LSB_to_F32LSB },
icculus@1982
  2224
    { AUDIO_U16LSB, AUDIO_F32MSB, SDL_Convert_U16LSB_to_F32MSB },
icculus@1982
  2225
    { AUDIO_S16LSB, AUDIO_U8, SDL_Convert_S16LSB_to_U8 },
icculus@1982
  2226
    { AUDIO_S16LSB, AUDIO_S8, SDL_Convert_S16LSB_to_S8 },
icculus@1982
  2227
    { AUDIO_S16LSB, AUDIO_U16LSB, SDL_Convert_S16LSB_to_U16LSB },
icculus@1982
  2228
    { AUDIO_S16LSB, AUDIO_U16MSB, SDL_Convert_S16LSB_to_U16MSB },
icculus@1982
  2229
    { AUDIO_S16LSB, AUDIO_S16MSB, SDL_Convert_S16LSB_to_S16MSB },
icculus@1982
  2230
    { AUDIO_S16LSB, AUDIO_S32LSB, SDL_Convert_S16LSB_to_S32LSB },
icculus@1982
  2231
    { AUDIO_S16LSB, AUDIO_S32MSB, SDL_Convert_S16LSB_to_S32MSB },
icculus@1982
  2232
    { AUDIO_S16LSB, AUDIO_F32LSB, SDL_Convert_S16LSB_to_F32LSB },
icculus@1982
  2233
    { AUDIO_S16LSB, AUDIO_F32MSB, SDL_Convert_S16LSB_to_F32MSB },
icculus@1982
  2234
    { AUDIO_U16MSB, AUDIO_U8, SDL_Convert_U16MSB_to_U8 },
icculus@1982
  2235
    { AUDIO_U16MSB, AUDIO_S8, SDL_Convert_U16MSB_to_S8 },
icculus@1982
  2236
    { AUDIO_U16MSB, AUDIO_U16LSB, SDL_Convert_U16MSB_to_U16LSB },
icculus@1982
  2237
    { AUDIO_U16MSB, AUDIO_S16LSB, SDL_Convert_U16MSB_to_S16LSB },
icculus@1982
  2238
    { AUDIO_U16MSB, AUDIO_S16MSB, SDL_Convert_U16MSB_to_S16MSB },
icculus@1982
  2239
    { AUDIO_U16MSB, AUDIO_S32LSB, SDL_Convert_U16MSB_to_S32LSB },
icculus@1982
  2240
    { AUDIO_U16MSB, AUDIO_S32MSB, SDL_Convert_U16MSB_to_S32MSB },
icculus@1982
  2241
    { AUDIO_U16MSB, AUDIO_F32LSB, SDL_Convert_U16MSB_to_F32LSB },
icculus@1982
  2242
    { AUDIO_U16MSB, AUDIO_F32MSB, SDL_Convert_U16MSB_to_F32MSB },
icculus@1982
  2243
    { AUDIO_S16MSB, AUDIO_U8, SDL_Convert_S16MSB_to_U8 },
icculus@1982
  2244
    { AUDIO_S16MSB, AUDIO_S8, SDL_Convert_S16MSB_to_S8 },
icculus@1982
  2245
    { AUDIO_S16MSB, AUDIO_U16LSB, SDL_Convert_S16MSB_to_U16LSB },
icculus@1982
  2246
    { AUDIO_S16MSB, AUDIO_S16LSB, SDL_Convert_S16MSB_to_S16LSB },
icculus@1982
  2247
    { AUDIO_S16MSB, AUDIO_U16MSB, SDL_Convert_S16MSB_to_U16MSB },
icculus@1982
  2248
    { AUDIO_S16MSB, AUDIO_S32LSB, SDL_Convert_S16MSB_to_S32LSB },
icculus@1982
  2249
    { AUDIO_S16MSB, AUDIO_S32MSB, SDL_Convert_S16MSB_to_S32MSB },
icculus@1982
  2250
    { AUDIO_S16MSB, AUDIO_F32LSB, SDL_Convert_S16MSB_to_F32LSB },
icculus@1982
  2251
    { AUDIO_S16MSB, AUDIO_F32MSB, SDL_Convert_S16MSB_to_F32MSB },
icculus@1982
  2252
    { AUDIO_S32LSB, AUDIO_U8, SDL_Convert_S32LSB_to_U8 },
icculus@1982
  2253
    { AUDIO_S32LSB, AUDIO_S8, SDL_Convert_S32LSB_to_S8 },
icculus@1982
  2254
    { AUDIO_S32LSB, AUDIO_U16LSB, SDL_Convert_S32LSB_to_U16LSB },
icculus@1982
  2255
    { AUDIO_S32LSB, AUDIO_S16LSB, SDL_Convert_S32LSB_to_S16LSB },
icculus@1982
  2256
    { AUDIO_S32LSB, AUDIO_U16MSB, SDL_Convert_S32LSB_to_U16MSB },
icculus@1982
  2257
    { AUDIO_S32LSB, AUDIO_S16MSB, SDL_Convert_S32LSB_to_S16MSB },
icculus@1982
  2258
    { AUDIO_S32LSB, AUDIO_S32MSB, SDL_Convert_S32LSB_to_S32MSB },
icculus@1982
  2259
    { AUDIO_S32LSB, AUDIO_F32LSB, SDL_Convert_S32LSB_to_F32LSB },
icculus@1982
  2260
    { AUDIO_S32LSB, AUDIO_F32MSB, SDL_Convert_S32LSB_to_F32MSB },
icculus@1982
  2261
    { AUDIO_S32MSB, AUDIO_U8, SDL_Convert_S32MSB_to_U8 },
icculus@1982
  2262
    { AUDIO_S32MSB, AUDIO_S8, SDL_Convert_S32MSB_to_S8 },
icculus@1982
  2263
    { AUDIO_S32MSB, AUDIO_U16LSB, SDL_Convert_S32MSB_to_U16LSB },
icculus@1982
  2264
    { AUDIO_S32MSB, AUDIO_S16LSB, SDL_Convert_S32MSB_to_S16LSB },
icculus@1982
  2265
    { AUDIO_S32MSB, AUDIO_U16MSB, SDL_Convert_S32MSB_to_U16MSB },
icculus@1982
  2266
    { AUDIO_S32MSB, AUDIO_S16MSB, SDL_Convert_S32MSB_to_S16MSB },
icculus@1982
  2267
    { AUDIO_S32MSB, AUDIO_S32LSB, SDL_Convert_S32MSB_to_S32LSB },
icculus@1982
  2268
    { AUDIO_S32MSB, AUDIO_F32LSB, SDL_Convert_S32MSB_to_F32LSB },
icculus@1982
  2269
    { AUDIO_S32MSB, AUDIO_F32MSB, SDL_Convert_S32MSB_to_F32MSB },
icculus@1982
  2270
    { AUDIO_F32LSB, AUDIO_U8, SDL_Convert_F32LSB_to_U8 },
icculus@1982
  2271
    { AUDIO_F32LSB, AUDIO_S8, SDL_Convert_F32LSB_to_S8 },
icculus@1982
  2272
    { AUDIO_F32LSB, AUDIO_U16LSB, SDL_Convert_F32LSB_to_U16LSB },
icculus@1982
  2273
    { AUDIO_F32LSB, AUDIO_S16LSB, SDL_Convert_F32LSB_to_S16LSB },
icculus@1982
  2274
    { AUDIO_F32LSB, AUDIO_U16MSB, SDL_Convert_F32LSB_to_U16MSB },
icculus@1982
  2275
    { AUDIO_F32LSB, AUDIO_S16MSB, SDL_Convert_F32LSB_to_S16MSB },
icculus@1982
  2276
    { AUDIO_F32LSB, AUDIO_S32LSB, SDL_Convert_F32LSB_to_S32LSB },
icculus@1982
  2277
    { AUDIO_F32LSB, AUDIO_S32MSB, SDL_Convert_F32LSB_to_S32MSB },
icculus@1982
  2278
    { AUDIO_F32LSB, AUDIO_F32MSB, SDL_Convert_F32LSB_to_F32MSB },
icculus@1982
  2279
    { AUDIO_F32MSB, AUDIO_U8, SDL_Convert_F32MSB_to_U8 },
icculus@1982
  2280
    { AUDIO_F32MSB, AUDIO_S8, SDL_Convert_F32MSB_to_S8 },
icculus@1982
  2281
    { AUDIO_F32MSB, AUDIO_U16LSB, SDL_Convert_F32MSB_to_U16LSB },
icculus@1982
  2282
    { AUDIO_F32MSB, AUDIO_S16LSB, SDL_Convert_F32MSB_to_S16LSB },
icculus@1982
  2283
    { AUDIO_F32MSB, AUDIO_U16MSB, SDL_Convert_F32MSB_to_U16MSB },
icculus@1982
  2284
    { AUDIO_F32MSB, AUDIO_S16MSB, SDL_Convert_F32MSB_to_S16MSB },
icculus@1982
  2285
    { AUDIO_F32MSB, AUDIO_S32LSB, SDL_Convert_F32MSB_to_S32LSB },
icculus@1982
  2286
    { AUDIO_F32MSB, AUDIO_S32MSB, SDL_Convert_F32MSB_to_S32MSB },
icculus@1982
  2287
    { AUDIO_F32MSB, AUDIO_F32LSB, SDL_Convert_F32MSB_to_F32LSB },
icculus@3021
  2288
#endif  /* !NO_CONVERTERS */
icculus@3021
  2289
    { 0, 0, NULL }
icculus@1982
  2290
};
icculus@1982
  2291
icculus@1982
  2292
icculus@3021
  2293
#if !NO_RESAMPLERS
icculus@3021
  2294
icculus@3021
  2295
static void SDLCALL
icculus@3021
  2296
SDL_Upsample_U8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@3021
  2297
{
slouken@3032
  2298
#if DEBUG_CONVERT
icculus@3021
  2299
    fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U8, 1 channels.\n", cvt->rate_incr);
icculus@3021
  2300
#endif
icculus@3021
  2301
icculus@3021
  2302
    const int srcsize = cvt->len_cvt - 16;
icculus@3021
  2303
    const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
icculus@3021
  2304
    register int eps = 0;
icculus@3021
  2305
    Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 1;
icculus@3021
  2306
    const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
icculus@3021
  2307
    const Uint8 *target = ((const Uint8 *) cvt->buf) - 1;
icculus@3021
  2308
    Uint8 sample0 = src[0];
icculus@3021
  2309
    Uint8 last_sample0 = sample0;
slouken@4889
  2310
    while (dst > target) {
icculus@3021
  2311
        dst[0] = sample0;
icculus@3021
  2312
        dst--;
icculus@3021
  2313
        eps += srcsize;
icculus@3021
  2314
        if ((eps << 1) >= dstsize) {
icculus@3021
  2315
            src--;
icculus@3021
  2316
            sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
icculus@3021
  2317
            last_sample0 = sample0;
icculus@3021
  2318
            eps -= dstsize;
icculus@3021
  2319
        }
icculus@3021
  2320
    }
icculus@3021
  2321
    cvt->len_cvt = dstsize;
icculus@3021
  2322
    if (cvt->filters[++cvt->filter_index]) {
icculus@3021
  2323
        cvt->filters[cvt->filter_index] (cvt, format);
icculus@3021
  2324
    }
icculus@3021
  2325
}
icculus@3021
  2326
icculus@3021
  2327
static void SDLCALL
icculus@3021
  2328
SDL_Downsample_U8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@3021
  2329
{
slouken@3032
  2330
#if DEBUG_CONVERT
icculus@3021
  2331
    fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 1 channels.\n", cvt->rate_incr);
icculus@3021
  2332
#endif
icculus@3021
  2333
icculus@3021
  2334
    const int srcsize = cvt->len_cvt - 16;
icculus@3021
  2335
    const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
icculus@3021
  2336
    register int eps = 0;
icculus@3021
  2337
    Uint8 *dst = (Uint8 *) cvt->buf;
icculus@3021
  2338
    const Uint8 *src = (Uint8 *) cvt->buf;
icculus@3021
  2339
    const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
icculus@3021
  2340
    Uint8 sample0 = src[0];
icculus@3021
  2341
    Uint8 last_sample0 = sample0;
slouken@4889
  2342
    while (dst < target) {
icculus@3021
  2343
        src++;
icculus@3021
  2344
        eps += dstsize;
icculus@3021
  2345
        if ((eps << 1) >= srcsize) {
icculus@3021
  2346
            dst[0] = sample0;
icculus@3021
  2347
            dst++;
icculus@3021
  2348
            sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
icculus@3021
  2349
            last_sample0 = sample0;
icculus@3021
  2350
            eps -= srcsize;
icculus@3021
  2351
        }
icculus@3021
  2352
    }
icculus@3021
  2353
    cvt->len_cvt = dstsize;
icculus@3021
  2354
    if (cvt->filters[++cvt->filter_index]) {
icculus@3021
  2355
        cvt->filters[cvt->filter_index] (cvt, format);
icculus@3021
  2356
    }
icculus@3021
  2357
}
icculus@3021
  2358
icculus@3021
  2359
static void SDLCALL
icculus@3021
  2360
SDL_Upsample_U8_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@3021
  2361
{
slouken@3032
  2362
#if DEBUG_CONVERT
icculus@3021
  2363
    fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U8, 2 channels.\n", cvt->rate_incr);
icculus@3021
  2364
#endif
icculus@3021
  2365
icculus@3021
  2366
    const int srcsize = cvt->len_cvt - 32;
icculus@3021
  2367
    const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
icculus@3021
  2368
    register int eps = 0;
icculus@3021
  2369
    Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 2;
icculus@3021
  2370
    const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 2;
icculus@3021
  2371
    const Uint8 *target = ((const Uint8 *) cvt->buf) - 2;
icculus@3021
  2372
    Uint8 sample1 = src[1];
icculus@3021
  2373
    Uint8 sample0 = src[0];
icculus@3021
  2374
    Uint8 last_sample1 = sample1;
icculus@3021
  2375
    Uint8 last_sample0 = sample0;
slouken@4889
  2376
    while (dst > target) {
icculus@3021
  2377
        dst[1] = sample1;
icculus@3021
  2378
        dst[0] = sample0;
icculus@3021
  2379
        dst -= 2;
icculus@3021
  2380
        eps += srcsize;
icculus@3021
  2381
        if ((eps << 1) >= dstsize) {
icculus@3021
  2382
            src -= 2;
icculus@3021
  2383
            sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
icculus@3021
  2384
            sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
icculus@3021
  2385
            last_sample1 = sample1;
icculus@3021
  2386
            last_sample0 = sample0;
icculus@3021
  2387
            eps -= dstsize;
icculus@3021
  2388
        }
icculus@3021
  2389
    }
icculus@3021
  2390
    cvt->len_cvt = dstsize;
icculus@3021
  2391
    if (cvt->filters[++cvt->filter_index]) {
icculus@3021
  2392
        cvt->filters[cvt->filter_index] (cvt, format);
icculus@3021
  2393
    }
icculus@3021
  2394
}
icculus@3021
  2395
icculus@3021
  2396
static void SDLCALL
icculus@3021
  2397
SDL_Downsample_U8_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@3021
  2398
{
slouken@3032
  2399
#if DEBUG_CONVERT
icculus@3021
  2400
    fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 2 channels.\n", cvt->rate_incr);
icculus@3021
  2401
#endif
icculus@3021
  2402
icculus@3021
  2403
    const int srcsize = cvt->len_cvt - 32;
icculus@3021
  2404
    const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
icculus@3021
  2405
    register int eps = 0;
icculus@3021
  2406
    Uint8 *dst = (Uint8 *) cvt->buf;
icculus@3021
  2407
    const Uint8 *src = (Uint8 *) cvt->buf;
icculus@3021
  2408
    const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
icculus@3021
  2409
    Uint8 sample0 = src[0];
icculus@3021
  2410
    Uint8 sample1 = src[1];
icculus@3021
  2411
    Uint8 last_sample0 = sample0;
icculus@3021
  2412
    Uint8 last_sample1 = sample1;
slouken@4889
  2413
    while (dst < target) {
icculus@3021
  2414
        src += 2;
icculus@3021
  2415
        eps += dstsize;
icculus@3021
  2416
        if ((eps << 1) >= srcsize) {
icculus@3021
  2417
            dst[0] = sample0;
icculus@3021
  2418
            dst[1] = sample1;
icculus@3021
  2419
            dst += 2;
icculus@3021
  2420
            sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
icculus@3021
  2421
            sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
icculus@3021
  2422
            last_sample0 = sample0;
icculus@3021
  2423
            last_sample1 = sample1;
icculus@3021
  2424
            eps -= srcsize;
icculus@3021
  2425
        }
icculus@3021
  2426
    }
icculus@3021
  2427
    cvt->len_cvt = dstsize;
icculus@3021
  2428
    if (cvt->filters[++cvt->filter_index]) {
icculus@3021
  2429
        cvt->filters[cvt->filter_index] (cvt, format);
icculus@3021
  2430
    }
icculus@3021
  2431
}
icculus@3021
  2432
icculus@3021
  2433
static void SDLCALL
icculus@3021
  2434
SDL_Upsample_U8_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@3021
  2435
{
slouken@3032
  2436
#if DEBUG_CONVERT
icculus@3021
  2437
    fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U8, 4 channels.\n", cvt->rate_incr);
icculus@3021
  2438
#endif
icculus@3021
  2439
icculus@3021
  2440
    const int srcsize = cvt->len_cvt - 64;
icculus@3021
  2441
    const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
icculus@3021
  2442
    register int eps = 0;
icculus@3021
  2443
    Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 4;
icculus@3021
  2444
    const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 4;
icculus@3021
  2445
    const Uint8 *target = ((const Uint8 *) cvt->buf) - 4;
icculus@3021
  2446
    Uint8 sample3 = src[3];
icculus@3021
  2447
    Uint8 sample2 = src[2];
icculus@3021
  2448
    Uint8 sample1 = src[1];
icculus@3021
  2449
    Uint8 sample0 = src[0];
icculus@3021
  2450
    Uint8 last_sample3 = sample3;
icculus@3021
  2451
    Uint8 last_sample2 = sample2;
icculus@3021
  2452
    Uint8 last_sample1 = sample1;
icculus@3021
  2453
    Uint8 last_sample0 = sample0;
slouken@4889
  2454
    while (dst > target) {
icculus@3021
  2455
        dst[3] = sample3;
icculus@3021
  2456
        dst[2] = sample2;
icculus@3021
  2457
        dst[1] = sample1;
icculus@3021
  2458
        dst[0] = sample0;
icculus@3021
  2459
        dst -= 4;
icculus@3021
  2460
        eps += srcsize;
icculus@3021
  2461
        if ((eps << 1) >= dstsize) {
icculus@3021
  2462
            src -= 4;
icculus@3021
  2463
            sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
icculus@3021
  2464
            sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
icculus@3021
  2465
            sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
icculus@3021
  2466
            sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
icculus@3021
  2467
            last_sample3 = sample3;
icculus@3021
  2468
            last_sample2 = sample2;
icculus@3021
  2469
            last_sample1 = sample1;
icculus@3021
  2470
            last_sample0 = sample0;
icculus@3021
  2471
            eps -= dstsize;
icculus@3021
  2472
        }
icculus@3021
  2473
    }
icculus@3021
  2474
    cvt->len_cvt = dstsize;
icculus@3021
  2475
    if (cvt->filters[++cvt->filter_index]) {
icculus@3021
  2476
        cvt->filters[cvt->filter_index] (cvt, format);
icculus@3021
  2477
    }
icculus@3021
  2478
}
icculus@3021
  2479
icculus@3021
  2480
static void SDLCALL
icculus@3021
  2481
SDL_Downsample_U8_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@3021
  2482
{
slouken@3032
  2483
#if DEBUG_CONVERT
icculus@3021
  2484
    fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 4 channels.\n", cvt->rate_incr);
icculus@3021
  2485
#endif
icculus@3021
  2486
icculus@3021
  2487
    const int srcsize = cvt->len_cvt - 64;
icculus@3021
  2488
    const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
icculus@3021
  2489
    register int eps = 0;
icculus@3021
  2490
    Uint8 *dst = (Uint8 *) cvt->buf;
icculus@3021
  2491
    const Uint8 *src = (Uint8 *) cvt->buf;
icculus@3021
  2492
    const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
icculus@3021
  2493
    Uint8 sample0 = src[0];
icculus@3021
  2494
    Uint8 sample1 = src[1];
icculus@3021
  2495
    Uint8 sample2 = src[2];
icculus@3021
  2496
    Uint8 sample3 = src[3];
icculus@3021
  2497
    Uint8 last_sample0 = sample0;
icculus@3021
  2498
    Uint8 last_sample1 = sample1;
icculus@3021
  2499
    Uint8 last_sample2 = sample2;
icculus@3021
  2500
    Uint8 last_sample3 = sample3;
slouken@4889
  2501
    while (dst < target) {
icculus@3021
  2502
        src += 4;
icculus@3021
  2503
        eps += dstsize;
icculus@3021
  2504
        if ((eps << 1) >= srcsize) {
icculus@3021
  2505
            dst[0] = sample0;
icculus@3021
  2506
            dst[1] = sample1;
icculus@3021
  2507
            dst[2] = sample2;
icculus@3021
  2508
            dst[3] = sample3;
icculus@3021
  2509
            dst += 4;
icculus@3021
  2510
            sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
icculus@3021
  2511
            sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
icculus@3021
  2512
            sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
icculus@3021
  2513
            sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
icculus@3021
  2514
            last_sample0 = sample0;
icculus@3021
  2515
            last_sample1 = sample1;
icculus@3021
  2516
            last_sample2 = sample2;
icculus@3021
  2517
            last_sample3 = sample3;
icculus@3021
  2518
            eps -= srcsize;
icculus@3021
  2519
        }
icculus@3021
  2520
    }
icculus@3021
  2521
    cvt->len_cvt = dstsize;
icculus@3021
  2522
    if (cvt->filters[++cvt->filter_index]) {
icculus@3021
  2523
        cvt->filters[cvt->filter_index] (cvt, format);
icculus@3021
  2524
    }
icculus@3021
  2525
}
icculus@3021
  2526
icculus@3021
  2527
static void SDLCALL
icculus@3021
  2528
SDL_Upsample_U8_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@3021
  2529
{
slouken@3032
  2530
#if DEBUG_CONVERT
icculus@3021
  2531
    fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U8, 6 channels.\n", cvt->rate_incr);
icculus@3021
  2532
#endif
icculus@3021
  2533
icculus@3021
  2534
    const int srcsize = cvt->len_cvt - 96;
icculus@3021
  2535
    const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
icculus@3021
  2536
    register int eps = 0;
icculus@3021
  2537
    Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 6;
icculus@3021
  2538
    const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 6;
icculus@3021
  2539
    const Uint8 *target = ((const Uint8 *) cvt->buf) - 6;
icculus@3021
  2540
    Uint8 sample5 = src[5];
icculus@3021
  2541
    Uint8 sample4 = src[4];
icculus@3021
  2542
    Uint8 sample3 = src[3];
icculus@3021
  2543
    Uint8 sample2 = src[2];
icculus@3021
  2544
    Uint8 sample1 = src[1];
icculus@3021
  2545
    Uint8 sample0 = src[0];
icculus@3021
  2546
    Uint8 last_sample5 = sample5;
icculus@3021
  2547
    Uint8 last_sample4 = sample4;
icculus@3021
  2548
    Uint8 last_sample3 = sample3;
icculus@3021
  2549
    Uint8 last_sample2 = sample2;
icculus@3021
  2550
    Uint8 last_sample1 = sample1;
icculus@3021
  2551
    Uint8 last_sample0 = sample0;
slouken@4889
  2552
    while (dst > target) {
icculus@3021
  2553
        dst[5] = sample5;
icculus@3021
  2554
        dst[4] = sample4;
icculus@3021
  2555
        dst[3] = sample3;
icculus@3021
  2556
        dst[2] = sample2;
icculus@3021
  2557
        dst[1] = sample1;
icculus@3021
  2558
        dst[0] = sample0;
icculus@3021
  2559
        dst -= 6;
icculus@3021
  2560
        eps += srcsize;
icculus@3021
  2561
        if ((eps << 1) >= dstsize) {
icculus@3021
  2562
            src -= 6;
icculus@3021
  2563
            sample5 = (Uint8) ((((Sint16) src[5]) + ((Sint16) last_sample5)) >> 1);
icculus@3021
  2564
            sample4 = (Uint8) ((((Sint16) src[4]) + ((Sint16) last_sample4)) >> 1);
icculus@3021
  2565
            sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
icculus@3021
  2566
            sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
icculus@3021
  2567
            sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
icculus@3021
  2568
            sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
icculus@3021
  2569
            last_sample5 = sample5;
icculus@3021
  2570
            last_sample4 = sample4;
icculus@3021
  2571
            last_sample3 = sample3;
icculus@3021
  2572
            last_sample2 = sample2;
icculus@3021
  2573
            last_sample1 = sample1;
icculus@3021
  2574
            last_sample0 = sample0;
icculus@3021
  2575
            eps -= dstsize;
icculus@3021
  2576
        }
icculus@3021
  2577
    }
icculus@3021
  2578
    cvt->len_cvt = dstsize;
icculus@3021
  2579
    if (cvt->filters[++cvt->filter_index]) {
icculus@3021
  2580
        cvt->filters[cvt->filter_index] (cvt, format);
icculus@3021
  2581
    }
icculus@3021
  2582
}
icculus@3021
  2583
icculus@3021
  2584
static void SDLCALL
icculus@3021
  2585
SDL_Downsample_U8_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
icculus@3021
  2586
{
slouken@3032
  2587
#if DEBUG_CONVERT
icculus@3021
  2588
    fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 6 channels.\n", cvt->rate_incr);
icculus@3021
  2589
#endif
icculus@3021
  2590
icculus@3021
  2591
    const int srcsize = cvt->len_cvt - 96;
icculus@3021
  2592
    const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
icculus@3021
  2593
    register int eps = 0;
icculus@3021
  2594
    Uint8 *dst = (Uint8 *) cvt->buf;
icculus@3021
  2595
    const Uint8 *src = (Uint8 *) cvt->buf;
icculus@3021
  2596
    const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
icculus@3021
  2597
    Uint8 sample0 = src[0];
icculus@3021
  2598
    Uint8 sample1 = src[1];
icculus@3021
  2599
    Uint8 sample2 = src[2];
icculus@3021
  2600
    Uint8 sample3 = src[3];
icculus@3021
  2601
    Uint8 sample4 = src[4];
icculus@3021
  2602
    Uint8 sample5 = src[5];
icculus@3021
  2603
    Uint8 last_sample0 = sample0;
icculus@3021
  2604
    Uint8 last_sample1 = sample1;
icculus@3021
  2605
    Uint8 last_sample2 = sample2;
icculus@3021
  2606
    Uint8 last_sample3 = sample3;
icculus@3021
  2607
    Uint8 last_sample4 = sample4;
icculus@3021
  2608
    Uint8 last_sample5 = sample5;
slouken@4889
  2609
    while (dst < target) {
icculus@3021
  2610
        src += 6;
icculus@3021
  2611
        eps += dstsize;
icculus@3021
  2612
        if ((eps << 1) >= srcsize) {
icculus@3021
  2613
            dst[0] = sample0;
icculus@3021
  2614
            dst[1] = sample1;
icculus@3021
  2615
            dst[2] = sample2;
icculus@3021
  2616
            dst[3] = sample3;
icculus@3021
  2617
            dst[4] = sample4;
icculus@3021
  2618
            dst[5] = sample5;
icculus@3021
  2619
            dst += 6;
icculus@3021
  2620
            sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
icculus@3021
  2621
            sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
icculus@3021
  2622
            sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);