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